]> git.mxchange.org Git - friendica.git/blobdiff - include/bbcode.php
Remove library/jgrowl
[friendica.git] / include / bbcode.php
index ffc2387c3b5a2277aa747df9e634b936fdee834c..dfaed8ef78233c5df79f07301534ff246c9e1038 100644 (file)
@@ -1,9 +1,14 @@
 <?php
-
+/**
+ * @file include/bbcode.php
+ */
 use Friendica\App;
 use Friendica\Content\Smilies;
 use Friendica\Content\OEmbed;
+use Friendica\Content\Text\BBCode;
+use Friendica\Core\Addon;
 use Friendica\Core\Cache;
+use Friendica\Core\L10n;
 use Friendica\Core\System;
 use Friendica\Core\Config;
 use Friendica\Model\Contact;
@@ -11,7 +16,6 @@ use Friendica\Util\Map;
 
 require_once 'include/event.php';
 require_once 'mod/proxy.php';
-require_once 'include/plaintext.php';
 
 function bb_PictureCacheExt($matches) {
        if (strpos($matches[3], "data:image/") === 0) {
@@ -53,7 +57,7 @@ function bb_map_location($match) {
  */
 function bb_attachment($return, $simplehtml = false, $tryoembed = true)
 {
-       $data = get_attachment_data($return);
+       $data = BBCode::getAttachmentData($return);
        if (!$data) {
                return $return;
        }
@@ -102,7 +106,7 @@ function bb_attachment($return, $simplehtml = false, $tryoembed = true)
                        }
 
                        if ($data["type"] == "link") {
-                               $return .= sprintf('<h5><a href="%s">%s</a></h5>', $data['url'], parse_url($data['url'], PHP_URL_HOST));
+                               $return .= sprintf('<sup><a href="%s">%s</a></sup>', $data['url'], parse_url($data['url'], PHP_URL_HOST));
                        }
 
                        if ($simplehtml != 4) {
@@ -116,7 +120,7 @@ function bb_attachment($return, $simplehtml = false, $tryoembed = true)
 
 function bb_remove_share_information($Text, $plaintext = false, $nolink = false) {
 
-       $data = get_attachment_data($Text);
+       $data = BBCode::getAttachmentData($Text);
 
        if (!$data) {
                return $Text;
@@ -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]);
@@ -969,12 +973,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 (thanks to http://code.seebz.net/p/autolink-php/)
-               $autolink_regex = "`([^\]\=\"']|^)(https?\://[^\s<]+[^\s<\.\)])`ism";
-               if ($simplehtml != 7) {
-                       $Text = preg_replace($autolink_regex, '$1<a href="$2" target="_blank">$2</a>', $Text);
-               } else {
-                       $Text = preg_replace($autolink_regex, '$1[url]$2[/url]', $Text);
-
+               // 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);
                }
@@ -1045,12 +1048,11 @@ 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);
+                               '$1<a href="' . System::baseUrl() . '/search?tag=$3" class="tag" title="$3">$3</a>', $Text);
+
+       $Text = preg_replace("/\[url\=([$URLSearchString]*)\]#(.*?)\[\/url\]/ism",
+                               '#<a href="' . System::baseUrl() . '/search?tag=$2" class="tag" title="$2">$2</a>', $Text);
 
        $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $Text);
        $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
@@ -1184,7 +1186,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;
@@ -1206,7 +1208,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;
@@ -1227,8 +1229,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",
@@ -1236,9 +1238,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) {
@@ -1356,7 +1358,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
@@ -1367,7 +1369,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);
@@ -1401,7 +1403,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);
 }