]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Fixed 1174: schemeless URL auto-linking bug
[quix0rs-gnu-social.git] / lib / util.php
index 7ce4e229eb76f93a8a49568b2283f9fd95e33d4c..a130c7d49cc8d3d57a6e6a7b3ba6c26c68fb3564 100644 (file)
@@ -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);
 
@@ -478,7 +481,7 @@ function common_linkify($url) {
     }
     else $title = '';
 
-    return "<a href=\"$url\" $title class=\"extlink\">$display</a>";
+    return "<a href=\"$url\" $title rel=\"external\">$display</a>";
 }
 
 function common_longurl($short_url)