Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
drupal.org
link
Commits
06615319
Commit
06615319
authored
Jun 29, 2008
by
Nathan Haug
Browse files
#273969 by crackerjackmack. Adding "local" domain and allowing single word local domains.
parent
19ce4754
Changes
1
Hide whitespace changes
Inline
Side-by-side
link.module
View file @
06615319
...
...
@@ -10,7 +10,7 @@ define('LINK_EXTERNAL', 'external');
define
(
'LINK_INTERNAL'
,
'internal'
);
define
(
'LINK_FRONT'
,
'front'
);
define
(
'LINK_EMAIL'
,
'email'
);
define
(
'LINK_DOMAINS'
,
'aero|arpa|biz|com|cat|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|mobi'
);
define
(
'LINK_DOMAINS'
,
'aero|arpa|biz|com|cat|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|mobi
|local
'
);
/**
* Implementation of hook_field_info().
...
...
@@ -649,13 +649,13 @@ function link_validate_url($text) {
$protocol
=
'(('
.
implode
(
"|"
,
$allowed_protocols
)
.
'):\/\/)'
;
$authentication
=
'([a-z0-9]+(:[a-z0-9]+)?@)'
;
$domain
=
'((
(
[a-z0-9]([a-z0-9\-_\[\]]
*\.))+)
('
.
LINK_DOMAINS
.
'|[a-z]{2}))'
;
$domain
=
'(([a-z0-9]([a-z0-9\-_\[\]]
)*)(\.(([a-z0-9\-_\[\]])+\.)*
('
.
LINK_DOMAINS
.
'|[a-z]{2}))
?)
'
;
$ipv4
=
'([0-9]{1,3}(\.[0-9]{1,3}){3})'
;
$ipv6
=
'([0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})'
;
$port
=
'(:([0-9]{1,5}))'
;
// Pattern specific to eternal links.
$external_pattern
=
'/^'
.
$protocol
.
'?'
.
$authentication
.
'?'
.
'('
.
$domain
.
'|'
.
$ipv4
.
'|'
.
$ipv6
.
' |localhost)'
.
$port
.
'?'
;
$external_pattern
=
'/^'
.
$protocol
.
'?'
.
$authentication
.
'?'
.
'('
.
$domain
.
'|'
.
$ipv4
.
'|'
.
$ipv6
.
' |localhost)'
.
$port
.
'?'
;
// Pattern specific to internal links.
$internal_pattern
=
"/^([a-z0-9_\-+\[\]]+)"
;
...
...
@@ -671,17 +671,18 @@ function link_validate_url($text) {
$user
=
'[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\'\[\]]+'
;
$email_pattern
=
'/^mailto:'
.
$user
.
'@'
.
'('
.
$domain
.
'|'
.
$ipv4
.
'|'
.
$ipv6
.
'|localhost)'
.
$query
.
'$/'
;
if
(
preg_match
(
$external_pattern
.
$end
,
$text
))
{
return
LINK_EXTERNAL
;
}
elseif
(
preg_match
(
$internal_pattern
.
$end
,
$text
))
{
return
LINK_INTERNAL
;
if
(
strpos
(
$text
,
'<front>'
)
===
0
)
{
return
LINK_FRONT
;
}
else
if
(
in_array
(
'mailto'
,
$allowed_protocols
)
&&
preg_match
(
$email_pattern
,
$text
))
{
if
(
in_array
(
'mailto'
,
$allowed_protocols
)
&&
preg_match
(
$email_pattern
,
$text
))
{
return
LINK_EMAIL
;
}
elseif
(
strpos
(
$text
,
'<front>'
)
===
0
)
{
return
LINK_
FRONT
;
if
(
preg_match
(
$internal_pattern
.
$end
,
$text
)
)
{
return
LINK_
INTERNAL
;
}
if
(
preg_match
(
$external_pattern
.
$end
,
$text
))
{
return
LINK_EXTERNAL
;
}
return
FALSE
;
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment