diff --git delicious.inc delicious.inc index a061b78..f99d4a8 100644 --- delicious.inc +++ delicious.inc @@ -214,10 +214,25 @@ function _delicious_term_link(&$node) { // smart-tagging support // function _delicious_tag_string($text, $tags, $username) { - if (!$tags) { return $text; } + + // Match absolute URLs. + $url_regex = '((http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))'; + // Match e-mail addresses. + $mail_regex = '([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\.[A-Za-z]{2,4})'; + // Match www domains/addresses. + $www_regex = '(www\.[a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+~#\&=/;-])'; + + // Replace all URLs, Domains, and e-mail address with tokens. + $i = 1; + $replacements = array(); + while (preg_match("`($url_regex|$mail_regex|$www_regex)`i", $text, $matches)) { + $token = '__delicious_processing_replacement_'. $i++; + $replacements[$token] = $matches[1]; + $text = str_replace($matches[1], $token, $text); + } // error, it must start with a tag... :-( foreach ($tags as $tag) { @@ -236,6 +251,11 @@ function _delicious_tag_string($text, $tags, $username) { } } + // Restore all URLs, Domains, and e-mail addresses. + foreach ($replacements as $token => $match) { + $text = str_replace($token, $match, $text); + } + return $text; }