summaryrefslogtreecommitdiff
path: root/lib/util.php
diff options
context:
space:
mode:
authorCraig Andrews <candrews@integralblue.com>2009-08-21 20:01:33 -0400
committerCraig Andrews <candrews@integralblue.com>2009-08-21 20:01:33 -0400
commit0615fda25e81d686c7d7a67b4d0674716eeb5929 (patch)
treedb613abad730d4ed276abc94a4062dd5b2447122 /lib/util.php
parent8246977ef00970f76da28500e40f170e68544bf9 (diff)
URLs surrounded by (),{}, and [] are correctly handled now!
Diffstat (limited to 'lib/util.php')
-rw-r--r--lib/util.php20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/util.php b/lib/util.php
index 4e809029f..575e796f1 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -412,13 +412,13 @@ function common_render_text($text)
function common_replace_urls_callback($text, $callback, $notice_id = null) {
// Start off with a regex
$regex = '#'.
- '(?:^|\s+)('.
+ '(?:^|[\s\(\)\[\]\{\}]+)('.
'(?:'. //Known protocols
'(?:'.
'(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|irc)://'.
'|'.
'(?:mailto|aim|tel|xmpp):'.
- ')\S+'.
+ ')[^\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
@@ -442,25 +442,23 @@ function common_replace_urls_callback($text, $callback, $notice_id = null) {
')|(?:'. //DNS
'\S+\.(?:museum|travel|onion|local|[a-z]{2,4})'.
')'.
- '(?:[:/]\S*)?'.
- ')(?:$|\s+)'.
+ '([^\s\(\)\[\]\{\}]*)'.
+ ')'.
'#ix';
-
-//preg_match_all($regex,$text,$matches);
-//print_r($matches);
-//die("here");
return preg_replace_callback($regex, curry(callback_helper,$callback,$notice_id) ,$text);
}
function callback_helper($matches, $callback, $notice_id) {
- $spaces_left = (strlen($matches[0]) - strlen(ltrim($matches[0])));
- $spaces_right = (strlen($matches[0]) - strlen(rtrim($matches[0])));
+ $pos = strpos($matches[0],$matches[1]);
+ $left = substr($matches[0],0,$pos);
+ $right = substr($matches[0],$pos+strlen($matches[1]));
+
if(empty($notice_id)){
$result = call_user_func_array($callback,$matches[1]);
}else{
$result = call_user_func_array($callback, array($matches[1],$notice_id) );
}
- return str_repeat(' ',$spaces_left) . $result . str_repeat(' ',$spaces_right);
+ return $left . $result . $right;
}
function curry($fn) {