]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Text/BBCode.php
Code is reformatted
[friendica.git] / src / Content / Text / BBCode.php
index 9651e91cfce50f9b81dd4f0d775274cad5f03845..f072e59c9dbcb0c147288765814cbb179fdf42e4 100644 (file)
@@ -191,7 +191,8 @@ class BBCode
         */
        public static function replaceAttachment(string $body, bool $no_link_desc = false): string
        {
-               return preg_replace_callback("/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
+               return preg_replace_callback(
+                       "/\s*\[attachment (.*?)\](.*?)\[\/attachment\]\s*/ism",
                        function ($match) use ($body, $no_link_desc) {
                                $attach_data = self::getAttachmentData($match[0]);
                                if (empty($attach_data['url'])) {
@@ -203,7 +204,9 @@ class BBCode
                                } else {
                                        return " \n[url=" . $attach_data['url'] . ']' . $attach_data['title'] . "[/url]\n";
                                }
-               }, $body);
+                       },
+                       $body
+               );
        }
 
        /**
@@ -708,8 +711,11 @@ class BBCode
                        // 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="' . self::proxyUrl($image, self::INTERNAL, $uriid) . '" alt="' . DI::l10n()->t('Image/photo') . '" />', $newbody);
+                       $newbody = str_replace(
+                               '[$#saved_image' . $cnt . '#$]',
+                               '<img src="' . self::proxyUrl($image, self::INTERNAL, $uriid) . '" alt="' . DI::l10n()->t('Image/photo') . '" />',
+                               $newbody
+                       );
                        $cnt++;
                }
 
@@ -865,7 +871,7 @@ class BBCode
                                }
 
                                $img_str = '<img src="' .
-                               self::proxyUrl($match[2], $simplehtml, $uriid) . '"';
+                                       self::proxyUrl($match[2], $simplehtml, $uriid) . '"';
                                foreach ($attributes as $key => $value) {
                                        if (!empty($value)) {
                                                $img_str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT) . '"';
@@ -902,13 +908,13 @@ class BBCode
                switch ($simplehtml) {
                        case self::MASTODON_API:
                        case self::TWITTER_API:
-                               $text = ($is_quote_share? '<br>' : '') .
-                               '<b><a href="' . $attributes['link'] . '">' . html_entity_decode('&#x2672;', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . "</a>:</b><br>\n" .
-                               '<blockquote class="shared_content" dir="auto">' . $content . '</blockquote>';
+                               $text = ($is_quote_share ? '<br>' : '') .
+                                       '<b><a href="' . $attributes['link'] . '">' . html_entity_decode('&#x2672;', ENT_QUOTES, 'UTF-8') . ' ' . $author_contact['addr'] . "</a>:</b><br>\n" .
+                                       '<blockquote class="shared_content" dir="auto">' . $content . '</blockquote>';
                                break;
                        case self::DIASPORA:
                                if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0) {
-                                       $text = ($is_quote_share? '<hr />' : '') . '<p><a href="' . $attributes['link'] . '">' . $attributes['link'] . '</a></p>' . "\n";
+                                       $text = ($is_quote_share ? '<hr />' : '') . '<p><a href="' . $attributes['link'] . '">' . $attributes['link'] . '</a></p>' . "\n";
                                } else {
                                        $headline = '<p><b>♲ <a href="' . $attributes['profile'] . '">' . $attributes['author'] . '</a>:</b></p>' . "\n";
 
@@ -916,7 +922,7 @@ class BBCode
                                                $headline = '<p><b>♲ <a href="' . $attributes['profile'] . '">' . $attributes['author'] . '</a></b> - <a href="' . $attributes['link'] . '">' . $attributes['posted'] . ' GMT</a></p>' . "\n";
                                        }
 
-                                       $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\n";
+                                       $text = ($is_quote_share ? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\n";
 
                                        if (empty($attributes['posted']) && !empty($attributes['link'])) {
                                                $text .= '<p><a href="' . $attributes['link'] . '">[Source]</a></p>' . "\n";
@@ -929,18 +935,18 @@ class BBCode
                                $headline .= DI::l10n()->t('<a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s</a> %3$s', $attributes['link'], $mention, $attributes['posted']);
                                $headline .= ':</b></p>' . "\n";
 
-                               $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote class="shared_content" dir="auto">' . trim($content) . '</blockquote>' . "\n";
+                               $text = ($is_quote_share ? '<hr />' : '') . $headline . '<blockquote class="shared_content" dir="auto">' . trim($content) . '</blockquote>' . "\n";
 
                                break;
                        case self::OSTATUS:
-                               $text = ($is_quote_share? '<br>' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' @' . $author_contact['addr'] . ': ' . $content . '</p>' . "\n";
+                               $text = ($is_quote_share ? '<br>' : '') . '<p>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . ' @' . $author_contact['addr'] . ': ' . $content . '</p>' . "\n";
                                break;
                        case self::ACTIVITYPUB:
                                $author = '@<span class="vcard"><a href="' . $author_contact['url'] . '" class="url u-url mention" title="' . $author_contact['addr'] . '"><span class="fn nickname mention">' . $author_contact['addr'] . '</span></a>:</span>';
                                $text = '<div><a href="' . $attributes['link'] . '">' . html_entity_decode('&#x2672;', ENT_QUOTES, 'UTF-8') . '</a> ' . $author . '<blockquote>' . $content . '</blockquote></div>' . "\n";
                                break;
                        default:
-                               $text = ($is_quote_share? "\n" : '');
+                               $text = ($is_quote_share ? "\n" : '');
 
                                $contact = Contact::getByURL($attributes['profile'], false, ['network']);
                                $network = $contact['network'] ?? Protocol::PHANTOM;
@@ -1252,8 +1258,7 @@ class BBCode
                                 * $match[1] = $url
                                 * $match[2] = $title or absent
                                 */
-                               $try_oembed_callback = function (array $match)
-                               {
+                               $try_oembed_callback = function (array $match) {
                                        $url = $match[1];
                                        $title = $match[2] ?? '';
 
@@ -1306,18 +1311,22 @@ class BBCode
                                }
 
                                // Remove linefeeds inside of the table elements. See issue #6799
-                               $search = ["\n[th]", "[th]\n", " [th]", "\n[/th]", "[/th]\n", "[/th] ",
+                               $search = [
+                                       "\n[th]", "[th]\n", " [th]", "\n[/th]", "[/th]\n", "[/th] ",
                                        "\n[td]", "[td]\n", " [td]", "\n[/td]", "[/td]\n", "[/td] ",
                                        "\n[tr]", "[tr]\n", " [tr]", "[tr] ", "\n[/tr]", "[/tr]\n", " [/tr]", "[/tr] ",
                                        "\n[hr]", "[hr]\n", " [hr]", "[hr] ",
                                        "\n[attachment ", " [attachment ", "\n[/attachment]", "[/attachment]\n", " [/attachment]", "[/attachment] ",
-                                       "[table]\n", "[table] ", " [table]", "\n[/table]", " [/table]", "[/table] "];
-                               $replace = ["[th]", "[th]", "[th]", "[/th]", "[/th]", "[/th]",
+                                       "[table]\n", "[table] ", " [table]", "\n[/table]", " [/table]", "[/table] "
+                               ];
+                               $replace = [
+                                       "[th]", "[th]", "[th]", "[/th]", "[/th]", "[/th]",
                                        "[td]", "[td]", "[td]", "[/td]", "[/td]", "[/td]",
                                        "[tr]", "[tr]", "[tr]", "[tr]", "[/tr]", "[/tr]", "[/tr]", "[/tr]",
                                        "[hr]", "[hr]", "[hr]", "[hr]",
                                        "[attachment ", "[attachment ", "[/attachment]", "[/attachment]", "[/attachment]", "[/attachment]",
-                                       "[table]", "[table]", "[table]", "[/table]", "[/table]", "[/table]"];
+                                       "[table]", "[table]", "[table]", "[/table]", "[/table]", "[/table]"
+                               ];
                                do {
                                        $oldtext = $text;
                                        $text = str_replace($search, $replace, $text);
@@ -1333,10 +1342,14 @@ class BBCode
 
                                // removing multiplicated newlines
                                if (DI::config()->get('system', 'remove_multiplicated_lines')) {
-                                       $search = ["\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[*]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n",
-                                                       "\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n"];
-                                       $replace = ["\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[*]", "[ul]", "[/ul]", "\n[share ", "[/attachment]",
-                                                       "[h1]", "[/h1]", "[h2]", "[/h2]", "[h3]", "[/h3]", "[h4]", "[/h4]", "[h5]", "[/h5]", "[h6]", "[/h6]"];
+                                       $search = [
+                                               "\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[*]", "\n[ul]", "[/ul]\n", "\n\n[share ", "[/attachment]\n",
+                                               "\n[h1]", "[/h1]\n", "\n[h2]", "[/h2]\n", "\n[h3]", "[/h3]\n", "\n[h4]", "[/h4]\n", "\n[h5]", "[/h5]\n", "\n[h6]", "[/h6]\n"
+                                       ];
+                                       $replace = [
+                                               "\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[*]", "[ul]", "[/ul]", "\n[share ", "[/attachment]",
+                                               "[h1]", "[/h1]", "[h2]", "[/h2]", "[h3]", "[/h3]", "[h4]", "[/h4]", "[h5]", "[/h5]", "[h6]", "[/h6]"
+                                       ];
                                        do {
                                                $oldtext = $text;
                                                $text = str_replace($search, $replace, $text);
@@ -1454,9 +1467,9 @@ class BBCode
                                $endlessloop = 0;
 
                                while ((((strpos($text, "[/list]") !== false) && (strpos($text, "[list") !== false)) ||
-                                               ((strpos($text, "[/ol]") !== false) && (strpos($text, "[ol]") !== false)) ||
-                                               ((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) ||
-                                               ((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) {
+                                       ((strpos($text, "[/ol]") !== false) && (strpos($text, "[ol]") !== false)) ||
+                                       ((strpos($text, "[/ul]") !== false) && (strpos($text, "[ul]") !== false)) ||
+                                       ((strpos($text, "[/li]") !== false) && (strpos($text, "[li]") !== false))) && (++$endlessloop < 20)) {
                                        $text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>', $text);
                                        $text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>', $text);
                                        $text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>', $text);
@@ -1502,10 +1515,12 @@ class BBCode
 
                                // handle nested quotes
                                $endlessloop = 0;
-                               while ((strpos($text, "[/spoiler]")!== false)  && (strpos($text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
-                                       $text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
+                               while ((strpos($text, "[/spoiler]") !== false)  && (strpos($text, "[spoiler=") !== false) && (++$endlessloop < 20)) {
+                                       $text = preg_replace(
+                                               "/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
                                                '<details class="spoiler"><summary>$1</summary>$2</details>',
-                                               $text);
+                                               $text
+                                       );
                                }
 
                                // Declare the format for [quote] layout
@@ -1524,10 +1539,12 @@ class BBCode
 
                                // handle nested quotes
                                $endlessloop = 0;
-                               while ((strpos($text, "[/quote]")!== false)  && (strpos($text, "[quote=") !== false) && (++$endlessloop < 20)) {
-                                       $text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism",
-                                               "<p><strong class=".'"author"'.">" . $t_wrote . "</strong></p><blockquote>$2</blockquote>",
-                                               $text);
+                               while ((strpos($text, "[/quote]") !== false)  && (strpos($text, "[quote=") !== false) && (++$endlessloop < 20)) {
+                                       $text = preg_replace(
+                                               "/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism",
+                                               "<p><strong class=" . '"author"' . ">" . $t_wrote . "</strong></p><blockquote>$2</blockquote>",
+                                               $text
+                                       );
                                }
 
 
@@ -1548,13 +1565,15 @@ class BBCode
                                $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '<img src="$3" style="width: $1px;" >', $text);
                                $text = preg_replace("/\[zmg\=([0-9]*)x([0-9]*)\](.*?)\[\/zmg\]/ism", '<img class="zrl" src="$3" style="width: $1px;" >', $text);
 
-                               $text = preg_replace_callback("/\[img\=(.*?)\](.*?)\[\/img\]/ism",
+                               $text = preg_replace_callback(
+                                       "/\[img\=(.*?)\](.*?)\[\/img\]/ism",
                                        function ($matches) use ($simple_html, $uriid) {
                                                $matches[1] = self::proxyUrl($matches[1], $simple_html, $uriid);
                                                $matches[2] = htmlspecialchars($matches[2], ENT_COMPAT);
                                                return '<img src="' . $matches[1] . '" alt="' . $matches[2] . '" title="' . $matches[2] . '">';
                                        },
-                                       $text);
+                                       $text
+                               );
 
                                // Images
                                // [img]pathtoimage[/img]
@@ -1576,8 +1595,8 @@ class BBCode
 
                                $text = self::convertImages($text, $simple_html, $uriid);
 
-                               $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
-                               $text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . '$1' . ' ' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
+                               $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '<br><img src="' . DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
+                               $text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '<br><img src="' . DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . '$1' . ' ' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
                                //$text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism", '<br><img src="' .DI::baseUrl() . '/images/lock_icon.gif" alt="' . DI::l10n()->t('Encrypted content') . '" title="' . '$1' . ' ' . DI::l10n()->t('Encrypted content') . '" /><br>', $text);
 
                                // Simplify "video" element
@@ -1585,20 +1604,32 @@ class BBCode
 
                                if ($try_oembed) {
                                        // html5 video and audio
-                                       $text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4).*?)\[\/video\]/ism",
-                                               '<video src="$1" controls width="100%" height="auto"><a href="$1">$1</a></video>', $text);
+                                       $text = preg_replace(
+                                               "/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4).*?)\[\/video\]/ism",
+                                               '<video src="$1" controls width="100%" height="auto"><a href="$1">$1</a></video>',
+                                               $text
+                                       );
 
                                        $text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", $try_oembed_callback, $text);
                                        $text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", $try_oembed_callback, $text);
 
-                                       $text = preg_replace("/\[video\](.*?)\[\/video\]/ism",
-                                               '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
+                                       $text = preg_replace(
+                                               "/\[video\](.*?)\[\/video\]/ism",
+                                               '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>',
+                                               $text
+                                       );
                                        $text = preg_replace("/\[audio\](.*?)\[\/audio\]/ism", '<audio src="$1" controls><a href="$1">$1</a></audio>', $text);
                                } else {
-                                       $text = preg_replace("/\[video\](.*?)\[\/video\]/ism",
-                                               '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
-                                       $text = preg_replace("/\[audio\](.*?)\[\/audio\]/ism",
-                                               '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
+                                       $text = preg_replace(
+                                               "/\[video\](.*?)\[\/video\]/ism",
+                                               '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>',
+                                               $text
+                                       );
+                                       $text = preg_replace(
+                                               "/\[audio\](.*?)\[\/audio\]/ism",
+                                               '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>',
+                                               $text
+                                       );
                                }
 
                                // Backward compatibility, [iframe] support has been removed in version 2020.12
@@ -1620,8 +1651,11 @@ class BBCode
                                if ($try_oembed) {
                                        $text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="' . $a->getThemeInfoValue('videowidth') . '" height="' . $a->getThemeInfoValue('videoheight') . '" src="https://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $text);
                                } else {
-                                       $text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism",
-                                               '<a href="https://www.youtube.com/watch?v=$1" target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=$1</a>', $text);
+                                       $text = preg_replace(
+                                               "/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism",
+                                               '<a href="https://www.youtube.com/watch?v=$1" target="_blank" rel="noopener noreferrer">https://www.youtube.com/watch?v=$1</a>',
+                                               $text
+                                       );
                                }
 
                                if ($try_oembed) {
@@ -1635,8 +1669,11 @@ class BBCode
                                if ($try_oembed) {
                                        $text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '<iframe width="' . $a->getThemeInfoValue('videowidth') . '" height="' . $a->getThemeInfoValue('videoheight') . '" src="https://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $text);
                                } else {
-                                       $text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
-                                               '<a href="https://vimeo.com/$1" target="_blank" rel="noopener noreferrer">https://vimeo.com/$1</a>', $text);
+                                       $text = preg_replace(
+                                               "/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism",
+                                               '<a href="https://vimeo.com/$1" target="_blank" rel="noopener noreferrer">https://vimeo.com/$1</a>',
+                                               $text
+                                       );
                                }
 
                                // oembed tag
@@ -1672,27 +1709,39 @@ class BBCode
                                // Handle mentions and hashtag links
                                if ($simple_html == self::DIASPORA) {
                                        // The ! is converted to @ since Diaspora only understands the @
-                                       $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                       $text = preg_replace(
+                                               "/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '@<a href="$2">$3</a>',
-                                               $text);
+                                               $text
+                                       );
                                } elseif (in_array($simple_html, [self::OSTATUS, self::ACTIVITYPUB])) {
-                                       $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                       $text = preg_replace(
+                                               "/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<span class="h-card"><a href="$2" class="u-url mention">$1<span>$3</span></a></span>',
-                                               $text);
-                                       $text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                               $text
+                                       );
+                                       $text = preg_replace(
+                                               "/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<a href="$2" class="mention hashtag" rel="tag">$1<span>$3</span></a>',
-                                               $text);
+                                               $text
+                                       );
                                } elseif (in_array($simple_html, [self::INTERNAL, self::EXTERNAL, self::TWITTER_API])) {
-                                       $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                       $text = preg_replace(
+                                               "/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<bdi>$1<a href="$2" class="userinfo mention" title="$3">$3</a></bdi>',
-                                               $text);
+                                               $text
+                                       );
                                } elseif ($simple_html == self::MASTODON_API) {
-                                       $text = preg_replace("/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                       $text = preg_replace(
+                                               "/([@!])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<a class="u-url mention status-link" href="$2" rel="nofollow noopener noreferrer" target="_blank" title="$3">$1<span>$3</span></a>',
-                                               $text);
-                                       $text = preg_replace("/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
+                                               $text
+                                       );
+                                       $text = preg_replace(
+                                               "/([#])\[url\=(.*?)\](.*?)\[\/url\]/ism",
                                                '<a class="mention hashtag status-link" href="$2" rel="tag">$1<span>$3</span></a>',
-                                               $text);
+                                               $text
+                                       );
                                } else {
                                        $text = preg_replace("/([#@!])\[url\=(.*?)\](.*?)\[\/url\]/ism", '$1$3', $text);
                                }
@@ -1710,8 +1759,11 @@ class BBCode
                                // Bookmarks in red - will be converted to bookmarks in friendica
                                $text = preg_replace("/#\^\[url\](.*?)\[\/url\]/ism", '[bookmark=$1]$1[/bookmark]', $text);
                                $text = preg_replace("/#\^\[url\=(.*?)\](.*?)\[\/url\]/ism", '[bookmark=$1]$2[/bookmark]', $text);
-                               $text = preg_replace("/#\[url\=.*?\]\^\[\/url\]\[url\=(.*?)\](.*?)\[\/url\]/i",
-                                                       "[bookmark=$1]$2[/bookmark]", $text);
+                               $text = preg_replace(
+                                       "/#\[url\=.*?\]\^\[\/url\]\[url\=(.*?)\](.*?)\[\/url\]/i",
+                                       "[bookmark=$1]$2[/bookmark]",
+                                       $text
+                               );
 
                                if (in_array($simple_html, [self::OSTATUS, self::TWITTER])) {
                                        $text = preg_replace_callback("/([^#@!])\[url\=([^\]]*)\](.*?)\[\/url\]/ism", [self::class, 'expandLinksCallback'], $text);
@@ -1731,20 +1783,22 @@ class BBCode
                                        "&\[url=/?posts/([^\[\]]*)\](.*)\[\/url\]&Usi",
                                        function ($match) {
                                                return "[url=" . DI::baseUrl() . "/display/" . $match[1] . "]" . $match[2] . "[/url]";
-                                       }, $text
+                                       },
+                                       $text
                                );
 
                                $text = preg_replace_callback(
                                        "&\[url=/people\?q\=(.*)\](.*)\[\/url\]&Usi",
                                        function ($match) {
                                                return "[url=" . DI::baseUrl() . "/search?search=%40" . $match[1] . "]" . $match[2] . "[/url]";
-                                       }, $text
+                                       },
+                                       $text
                                );
 
                                // Server independent link to posts and comments
                                // See issue: https://github.com/diaspora/diaspora_federation/issues/75
                                $expression = "=diaspora://.*?/post/([0-9A-Za-z\-_@.:]{15,254}[0-9A-Za-z])=ism";
-                               $text = preg_replace($expression, DI::baseUrl()."/display/$1", $text);
+                               $text = preg_replace($expression, DI::baseUrl() . "/display/$1", $text);
 
                                /* Tag conversion
                                 * Supports:
@@ -1752,7 +1806,7 @@ class BBCode
                                 * - [url=<anything>]#<term>[/url]
                                 */
                                self::performWithEscapedTags($text, ['url', 'share'], function ($text) use ($simple_html) {
-                                       $text = preg_replace_callback("/(?:#\[url\=[^\[\]]*\]|\[url\=[^\[\]]*\]#)(.*?)\[\/url\]/ism", function($matches) use ($simple_html) {
+                                       $text = preg_replace_callback("/(?:#\[url\=[^\[\]]*\]|\[url\=[^\[\]]*\]#)(.*?)\[\/url\]/ism", function ($matches) use ($simple_html) {
                                                if ($simple_html == self::ACTIVITYPUB) {
                                                        return '<a href="' . DI::baseUrl() . '/search?tag=' . rawurlencode($matches[1])
                                                                . '" data-tag="' . XML::escape($matches[1]) . '" rel="tag ugc">#'
@@ -1769,8 +1823,8 @@ class BBCode
                                // We need no target="_blank" rel="noopener noreferrer" for local links
                                // convert links start with DI::baseUrl() as local link without the target="_blank" rel="noopener noreferrer" attribute
                                $escapedBaseUrl = preg_quote(DI::baseUrl(), '/');
-                               $text = preg_replace("/\[url\](".$escapedBaseUrl.".*?)\[\/url\]/ism", '<a href="$1">$1</a>', $text);
-                               $text = preg_replace("/\[url\=(".$escapedBaseUrl.".*?)\](.*?)\[\/url\]/ism", '<a href="$1">$2</a>', $text);
+                               $text = preg_replace("/\[url\](" . $escapedBaseUrl . ".*?)\[\/url\]/ism", '<a href="$1">$1</a>', $text);
+                               $text = preg_replace("/\[url\=(" . $escapedBaseUrl . ".*?)\](.*?)\[\/url\]/ism", '<a href="$1">$2</a>', $text);
 
                                $text = preg_replace("/\[url\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank" rel="noopener noreferrer">$1</a>', $text);
                                $text = preg_replace("/\[url\=(.*?)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank" rel="noopener noreferrer">$2</a>', $text);
@@ -1801,10 +1855,15 @@ class BBCode
                                // sanitizes src attributes (http and redir URLs for displaying in a web page, cid used for inline images in emails)
                                $allowed_src_protocols = ['//', 'http://', 'https://', 'contact/redir/', 'cid:'];
 
-                               array_walk($allowed_src_protocols, function(&$value) { $value = preg_quote($value, '#');});
+                               array_walk($allowed_src_protocols, function (&$value) {
+                                       $value = preg_quote($value, '#');
+                               });
 
-                               $text = preg_replace('#<([^>]*?)(src)="(?!' . implode('|', $allowed_src_protocols) . ')(.*?)"(.*?)>#ism',
-                                                        '<$1$2=""$4 data-original-src="$3" class="invalid-src" title="' . DI::l10n()->t('Invalid source protocol') . '">', $text);
+                               $text = preg_replace(
+                                       '#<([^>]*?)(src)="(?!' . implode('|', $allowed_src_protocols) . ')(.*?)"(.*?)>#ism',
+                                       '<$1$2=""$4 data-original-src="$3" class="invalid-src" title="' . DI::l10n()->t('Invalid source protocol') . '">',
+                                       $text
+                               );
 
                                // sanitize href attributes (only allowlisted protocols URLs)
                                // default value for backward compatibility
@@ -1816,7 +1875,9 @@ class BBCode
                                $allowed_link_protocols[] = 'https://';
                                $allowed_link_protocols[] = 'contact/redir/';
 
-                               array_walk($allowed_link_protocols, function(&$value) { $value = preg_quote($value, '#');});
+                               array_walk($allowed_link_protocols, function (&$value) {
+                                       $value = preg_quote($value, '#');
+                               });
 
                                $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="' . DI::l10n()->t('Invalid link protocol') . '">', $text);
@@ -1826,7 +1887,8 @@ class BBCode
                                        $text,
                                        function (array $attributes, array $author_contact, $content, $is_quote_share) use ($simple_html) {
                                                return self::convertShareCallback($attributes, $author_contact, $content, $is_quote_share, $simple_html);
-                                       }, $uriid
+                                       },
+                                       $uriid
                                );
 
                                $text = self::interpolateSavedImagesIntoItemBody($uriid, $text, $saved_image);
@@ -1841,13 +1903,14 @@ class BBCode
 
                        // Additionally, [pre] tags preserve spaces
                        $text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", function ($match) {
-                               return str_replace([' ', "\n"], ['&nbsp;', "<br>"], htmlentities($match[1], ENT_NOQUOTES,'UTF-8'));
+                               return str_replace([' ', "\n"], ['&nbsp;', "<br>"], htmlentities($match[1], ENT_NOQUOTES, 'UTF-8'));
                        }, $text);
 
                        return $text;
                }); // Escaped code
 
-               $text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#ism",
+               $text = preg_replace_callback(
+                       "#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#ism",
                        function ($matches) {
                                if (strpos($matches[2], "\n") !== false) {
                                        $return = '<pre><code class="language-' . trim($matches[1]) . '">' . htmlentities(trim($matches[2], "\n\r"), ENT_NOQUOTES, 'UTF-8') . '</code></pre>';
@@ -1863,8 +1926,8 @@ class BBCode
                // Default iframe allowed domains/path
                $allowedIframeDomains = [
                        DI::baseUrl()->getHost()
-                       . (DI::baseUrl()->getPath() ? '/' . DI::baseUrl()->getPath() : '')
-                       . '/oembed/', # The path part has to change with the source in Content\Oembed::iframe
+                               . (DI::baseUrl()->getPath() ? '/' . DI::baseUrl()->getPath() : '')
+                               . '/oembed/', # The path part has to change with the source in Content\Oembed::iframe
                        'www.youtube.com/embed/',
                        'player.vimeo.com/video/',
                ];
@@ -1977,7 +2040,8 @@ class BBCode
                 * Transform #tags, strip off the [url] and replace spaces with underscore
                 */
                $url_search_string = "^\[\]";
-               $text = preg_replace_callback("/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/i",
+               $text = preg_replace_callback(
+                       "/#\[url\=([$url_search_string]*)\](.*?)\[\/url\]/i",
                        function ($matches) {
                                return '#' . str_replace(' ', '_', $matches[2]);
                        },
@@ -2112,7 +2176,8 @@ class BBCode
         */
        public static function expandTags(string $body): string
        {
-               return preg_replace_callback("/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
+               return preg_replace_callback(
+                       "/(?<=\W|^)([!#@])([^\^ \x0D\x0A,;:?'\"]*[^\^ \x0D\x0A,;:?!'\".])/",
                        function (array $match) {
                                switch ($match[1]) {
                                        case '!':
@@ -2129,7 +2194,9 @@ class BBCode
                                        default:
                                                return $match[1] . '[url=' . DI::baseUrl() . '/search?tag=' . $match[2] . ']' . $match[2] . '[/url]';
                                }
-                       }, $body);
+                       },
+                       $body
+               );
        }
 
        /**