Commit 06615319 authored by Nathan Haug's avatar Nathan Haug
Browse files

#273969 by crackerjackmack. Adding "local" domain and allowing single word local domains.

parent 19ce4754
......@@ -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;
}
elseif (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;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment