summaryrefslogtreecommitdiff
path: root/lib/util.php
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2009-08-21 21:11:23 -0400
committerCraig Andrews <candrews@integralblue.com>2009-08-21 21:11:23 -0400
commit579a41b56f3d11f77d837b286753fd7ac528590f (patch)
tree578686913710fe7d27c689173f10b78813da5a73 /lib/util.php
parent0615fda25e81d686c7d7a67b4d0674716eeb5929 (diff)
Improve url finding more. Properly end urls when a space is caught.
Diffstat (limited to 'lib/util.php')
-rw-r--r--lib/util.php65
1 files changed, 36 insertions, 29 deletions
diff --git a/lib/util.php b/lib/util.php
index 575e796f1..091533afb 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -412,37 +412,44 @@ function common_render_text($text)
function common_replace_urls_callback($text, $callback, $notice_id = null) {
// Start off with a regex
$regex = '#'.
- '(?:^|[\s\(\)\[\]\{\}]+)('.
- '(?:'. //Known protocols
- '(?:'.
- '(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'.
- '|'.
- '(?:mailto|aim|tel|xmpp):'.
- ')[^\s\(\)\[\]\{\}]+'.
+ '(?:^|[\s\(\)\[\]\{\}]+)'.
+ '('.
+ '(?:'.
+ '(?:'. //Known protocols
+ '(?:'.
+ '(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'.
+ '|'.
+ '(?:mailto|aim|tel|xmpp):'.
+ ')[^\s\/]+'.
+ ')'.
+ '|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)'. //IPv4
+ '|(?:'. //IPv6
+ '(?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,6}|'.
+ '(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,5}|'.
+ '(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,4}|'.
+ '(?:[0-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\d|[0-1]?\d?\d)){3}|'.
- '(?:[0-9a-f]{1,4}:){1,1}(?::[0-9a-f]{1,4}){1,4}:(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|'.
- '(?:[0-9a-f]{1,4}:){1,2}(?::[0-9a-f]{1,4}){1,3}:(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|'.
- '(?:[0-9a-f]{1,4}:){1,3}(?::[0-9a-f]{1,4}){1,2}:(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|'.
- '(?:[0-9a-f]{1,4}:){1,4}(?::[0-9a-f]{1,4}){1,1}:(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|'.
- '(?:(?:[0-9a-f]{1,4}:){1,5}|:):(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|'.
- ':(?::[0-9a-f]{1,4}){1,5}:(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}'.
- ')|(?:'. //DNS
- '\S+\.(?:museum|travel|onion|local|[a-z]{2,4})'.
+ '(?:'.
+ '$|(?:'.
+ '/[^\s\(\)\[\]\{\}]*'.
+ ')'.
')'.
- '([^\s\(\)\[\]\{\}]*)'.
')'.
'#ix';
return preg_replace_callback($regex, curry(callback_helper,$callback,$notice_id) ,$text);