]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Merge commit 'upstream/0.7.x' into 0.7.x
[quix0rs-gnu-social.git] / lib / util.php
index 0655ebf276e4677ad9852b47a000bf6cd58b0a91..be92f422fbb507d5657c81d0e3fe809afc32028f 100644 (file)
@@ -394,12 +394,26 @@ function common_render_text($text)
 
 function common_replace_urls_callback($text, $callback) {
     // Start off with a regex
-        preg_match_all('#(?:(?:(?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://|(?:mailto|aim|tel):)[^.\s]+\.[^\s]+|(?:[^.\s/]+\.)+(?:museum|travel|[a-z]{2,4})(?:[:/][^\s]*)?)#i', $text, $matches);
+    $regex = '#
+    (?:
+        (?:
+            (?:https?|ftps?|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://
+            |
+            (?:mailto|aim|tel):
+        )
+        [^.\s]+\.[^\s]+
+        |
+        (?:[^.\s/:]+\.)+
+        (?:museum|travel|[a-z]{2,4})
+        (?:[:/][^\s]*)?
+    )
+    #ix';
+    preg_match_all($regex, $text, $matches);
 
     // 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;
@@ -442,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);
 
@@ -464,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)