]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
Security t()
[friendica.git] / include / bbcode.php
index a6ffc39c18744c4dd999d994766aede3ae4c1841..df883eed64aa79e100476252149edf4b50ad0011 100644 (file)
@@ -1,9 +1,13 @@
 <?php
-
+/**
+ * @file include/bbcode.php
+ */
 use Friendica\App;
 use Friendica\Content\Smilies;
 use Friendica\Content\OEmbed;
+use Friendica\Core\Addon;
 use Friendica\Core\Cache;
+use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Model\Contact;
@@ -410,7 +414,7 @@ function bb_replace_images($body, $images) {
                // We're depending on the property of 'foreach' (specified on the PHP website) that
                // it loops over the array starting from the first element and going sequentially
                // to the last element
-               $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '<img src="' . proxy_url($image) .'" alt="' . t('Image/photo') . '" />', $newbody);
+               $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '<img src="' . proxy_url($image) .'" alt="' . L10n::t('Image/photo') . '" />', $newbody);
                $cnt++;
        }
 
@@ -548,7 +552,7 @@ function bb_ShareAttributes($share, $simplehtml)
                        break;
                case 4:
                        $headline .= '<br /><b>' . html_entity_decode("&#x2672; ", ENT_QUOTES, 'UTF-8');
-                       $headline .= t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $link, $userid, $posted);
+                       $headline .= L10n::t('<a href="%1$s" target="_blank">%2$s</a> %3$s', $link, $userid, $posted);
                        $headline .= ":</b><br />";
 
                        $text = trim($share[1]);
@@ -968,12 +972,12 @@ 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/)
+               // Currently disabled, since the function is too greedy
+               // $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);
                }
@@ -1044,10 +1048,6 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        $expression = "=diaspora://.*?/post/([0-9A-Za-z\-_@.:]{15,254}[0-9A-Za-z])=ism";
        $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("/([#])\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism",
                                '$1<a href="$2" class="tag" title="$3">$3</a>', $Text);
 
@@ -1183,7 +1183,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
 
        // Check for [spoiler=Author] text
 
-       $t_wrote = t('$1 wrote:');
+       $t_wrote = L10n::t('$1 wrote:');
 
        // handle nested quotes
        $endlessloop = 0;
@@ -1205,7 +1205,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
 
        // Check for [quote=Author] text
 
-       $t_wrote = t('$1 wrote:');
+       $t_wrote = L10n::t('$1 wrote:');
 
        // handle nested quotes
        $endlessloop = 0;
@@ -1226,8 +1226,8 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        // [img]pathtoimage[/img]
        $Text = preg_replace_callback("/\[img\](.*?)\[\/img\]/ism", 'bb_PictureCache', $Text);
 
-       $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
-       $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
+       $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . L10n::t('Image/photo') . '" />', $Text);
+       $Text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '<img src="$1" alt="' . L10n::t('Image/photo') . '" />', $Text);
 
        // Shared content
        $Text = preg_replace_callback("/(.*?)\[share(.*?)\](.*?)\[\/share\]/ism",
@@ -1235,9 +1235,9 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
                        return bb_ShareAttributes($match, $simplehtml);
                }, $Text);
 
-       $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text);
-       $Text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);
-       //$Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);
+       $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . L10n::t('Encrypted content') . '" /><br />', $Text);
+       $Text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . '$1' . ' ' . L10n::t('Encrypted content') . '" /><br />', $Text);
+       //$Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism", '<br/><img src="' .System::baseUrl() . '/images/lock_icon.gif" alt="' . L10n::t('Encrypted content') . '" title="' . '$1' . ' ' . L10n::t('Encrypted content') . '" /><br />', $Text);
 
        // Try to Oembed
        if ($tryoembed) {
@@ -1355,7 +1355,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        // sanitizes src attributes (http and redir URLs for displaying in a web page, cid used for inline images in emails)
        static $allowed_src_protocols = ['http', 'redir', 'cid'];
        $Text = preg_replace('#<([^>]*?)(src)="(?!' . implode('|', $allowed_src_protocols) . ')(.*?)"(.*?)>#ism',
-                            '<$1$2=""$4 data-original-src="$3" class="invalid-src" title="' . t('Invalid source protocol') . '">', $Text);
+                            '<$1$2=""$4 data-original-src="$3" class="invalid-src" title="' . L10n::t('Invalid source protocol') . '">', $Text);
 
        // sanitize href attributes (only whitelisted protocols URLs)
        // default value for backward compatibility
@@ -1366,7 +1366,7 @@ function bbcode($Text, $preserve_nl = false, $tryoembed = true, $simplehtml = fa
        $allowed_link_protocols[] = 'redir/';
 
        $regex = '#<([^>]*?)(href)="(?!' . implode('|', $allowed_link_protocols) . ')(.*?)"(.*?)>#ism';
-       $Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 data-original-href="$3" class="invalid-href" title="' . t('Invalid link protocol') . '">', $Text);
+       $Text = preg_replace($regex, '<$1$2="javascript:void(0)"$4 data-original-href="$3" class="invalid-href" title="' . L10n::t('Invalid link protocol') . '">', $Text);
 
        if ($saved_image) {
                $Text = bb_replace_images($Text, $saved_image);
@@ -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);
 }