mirror of
https://github.com/friendica/friendica
synced 2024-12-23 09:20:17 +00:00
Simplify code in Content\Text\BBCode::convert
- Use performWithEscapedTags instead of custom solution
This commit is contained in:
parent
5ca90e5a74
commit
edd439cfab
1 changed files with 3 additions and 23 deletions
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue