]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
The url detection in BBCode is too greedy
[friendica.git] / include / bbcode.php
index a6ffc39c18744c4dd999d994766aede3ae4c1841..cad7ddc9251df74ca149e7713efcf341c5d541f2 100644 (file)
@@ -3,6 +3,7 @@
 use Friendica\App;
 use Friendica\Content\Smilies;
 use Friendica\Content\OEmbed;
+use Friendica\Core\Addon;
 use Friendica\Core\Cache;
 use Friendica\Core\System;
 use Friendica\Core\Config;
@@ -968,12 +969,11 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
 
        // if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
        if (!$forplaintext) {
-               // Autolink feature
-               if ($simplehtml != 7) {
-                       $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text);
-               } else {
-                       $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\@]+)/ism", '$1[url]$2[/url]', $Text);
-
+               // Autolink feature (thanks to http://code.seebz.net/p/autolink-php/)
+               $autolink_regex = "`([^\]\=\"']|^)(https?\://[^\s<]+[^\s<\.\)])`ism";
+               $autolink_regex = "/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism";
+               $Text = preg_replace($autolink_regex, '$1[url]$2[/url]', $Text);
+               if ($simplehtml == 7) {
                        $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
                        $Text = preg_replace_callback("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", 'bb_style_url', $Text);
                }
@@ -1045,7 +1045,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        $Text = preg_replace($expression, System::baseUrl()."/display/$1", $Text);
 
        if ($tryoembed) {
-               $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $tryoembed_callback, $Text);
+       //      $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism", $tryoembed_callback, $Text);
        }
 
        $Text = preg_replace("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
@@ -1400,7 +1400,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        //$Text = str_replace('<br /><li>', '<li>', $Text);
        //$Text = str_replace('<br /><ul', '<ul ', $Text);
 
-       call_hooks('bbcode', $Text);
+       Addon::callHooks('bbcode', $Text);
 
        return trim($Text);
 }