]> git.mxchange.org Git - friendica.git/commitdiff
Simplify code in Content\Text\BBCode::convert
authorHypolite Petovan <hypolite@mrpetovan.com>
Mon, 9 Nov 2020 04:25:46 +0000 (23:25 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 9 Nov 2020 04:25:46 +0000 (23:25 -0500)
- Use performWithEscapedTags instead of custom solution

src/Content/Text/BBCode.php

index 831d6cf34cc65110d11976fa465dbc7cdad27f5e..b1cfff0a426304b8c725a63a2f8bfbcc642ed3ff 100644 (file)
@@ -1509,29 +1509,9 @@ class BBCode
                                $text = str_replace('[hr]', '<hr />', $text);
 
                                if (!$for_plaintext) {
-                                       $escaped = [];
-
-                                       // Escaping BBCodes susceptible to contain rogue URL we don'' want the autolinker to catch
-                                       $text = preg_replace_callback('#\[(url|img|audio|video|youtube|vimeo|share|attachment|iframe|bookmark).+?\[/\1\]#ism',
-                                               function ($matches) use (&$escaped) {
-                                                       $return = '{escaped-' . count($escaped) . '}';
-                                                       $escaped[] = $matches[0];
-
-                                                       return $return;
-                                               },
-                                               $text
-                                       );
-
-                                       // Autolinker for isolated URLs
-                                       $text = preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
-
-                                       // Restoring escaped blocks
-                                       $text = preg_replace_callback('/{escaped-([0-9]+)}/iU',
-                                               function ($matches) use ($escaped) {
-                                                       return $escaped[intval($matches[1])] ?? $matches[0];
-                                               },
-                                               $text
-                                       );
+                                       $text = self::performWithEscapedTags($text, ['url', 'img', 'audio', 'video', 'youtube', 'vimeo', 'share', 'attachment', 'iframe', 'bookmark'], function ($text) {
+                                               return preg_replace(Strings::autoLinkRegEx(), '[url]$1[/url]', $text);
+                                       });
                                }
 
                                // This is actually executed in Item::prepareBody()