diff options
author | Sarven Capadisli <csarven@controlyourself.ca> | 2009-02-11 16:53:01 +0000 |
---|---|---|
committer | Sarven Capadisli <csarven@controlyourself.ca> | 2009-02-11 16:53:01 +0000 |
commit | 012288bdf6f4ad41c861504c05b2ac1cee834dd3 (patch) | |
tree | 39482829b98bcf1ac9e6e8b1ce74d8c80afc5a25 /lib/util.php | |
parent | fc293545be13473d992b512141be233c2963f6da (diff) | |
parent | 22b10399aaa97061ed940f92f5b15f6aacfb1093 (diff) |
Merge branch '0.7.x' of git@gitorious.org:laconica/dev into 0.7.x
Diffstat (limited to 'lib/util.php')
-rw-r--r-- | lib/util.php | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/util.php b/lib/util.php index 9b38b5596..c0c980111 100644 --- a/lib/util.php +++ b/lib/util.php @@ -412,14 +412,14 @@ function common_replace_urls_callback($text, $callback) { // Then clean up what the regex left behind $offset = 0; - foreach($matches[0] as $url) { - $url = htmlspecialchars_decode($url); + foreach($matches[0] as $orig_url) { + $url = htmlspecialchars_decode($orig_url); // Make sure we didn't pick up an email address if (preg_match('#^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$#i', $url)) continue; - // Remove trailing punctuation - $url = rtrim($url, '.?!,;:\'"`'); + // Remove surrounding punctuation + $url = trim($url, '.?!,;:\'"`([<'); // Remove surrounding parens and the like preg_match('/[)\]>]+$/', $url, $trailing); @@ -446,7 +446,7 @@ function common_replace_urls_callback($text, $callback) { // If the first part wasn't cap'd but the last part was, we captured too much if ((!$prev_part && $last_part)) { - $url = substr_replace($url, '', mb_strpos($url, '.'.$url_parts[2], 0)); + $url = mb_substr($url, 0 , mb_strpos($url, '.'.$url_parts['2'], 0)); } // Capture the new TLD @@ -456,6 +456,9 @@ function common_replace_urls_callback($text, $callback) { if (!in_array($url_parts[2], $tlds)) continue; + // Put the url back the way we found it. + $url = (mb_strpos($orig_url, htmlspecialchars($url)) === FALSE) ? $url:htmlspecialchars($url); + // Call user specified func $modified_url = $callback($url); |