Merge pull request #12471 from MrPetovan/bug/12468-bbcode-img-code

Skip literal text in ActivityPub\Transmitter::removePictures
This commit is contained in:
Tobias Diekershoff 2022-12-19 07:03:31 +01:00 committed by GitHub
commit 9d38671ec9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 20 deletions

View File

@ -1477,28 +1477,28 @@ class Transmitter
*/ */
private static function removePictures(string $body): string private static function removePictures(string $body): string
{ {
// Simplify image codes return BBCode::performWithEscapedTags($body, ['code', 'noparse', 'nobb', 'pre'], function ($text) {
$body = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $body); // Simplify image codes
$body = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $body); $text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '[img]$3[/img]', $text);
$text = preg_replace("/\[img\=(.*?)\](.*?)\[\/img\]/ism", '[img]$1[/img]', $text);
// Now remove local links // Now remove local links
$body = preg_replace_callback( $text = preg_replace_callback(
'/\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]/Usi', '/\[url=([^\[\]]*)\]\[img\](.*)\[\/img\]\[\/url\]/Usi',
function ($match) { function ($match) {
// We remove the link when it is a link to a local photo page // We remove the link when it is a link to a local photo page
if (Photo::isLocalPage($match[1])) { if (Photo::isLocalPage($match[1])) {
return ''; return '';
} }
// otherwise we just return the link // otherwise we just return the link
return '[url]' . $match[1] . '[/url]'; return '[url]' . $match[1] . '[/url]';
}, },
$body $text
); );
// Remove all pictures // Remove all pictures
$body = preg_replace("/\[img\]([^\[\]]*)\[\/img\]/Usi", '', $body); return preg_replace("/\[img\]([^\[\]]*)\[\/img\]/Usi", '', $text);
});
return $body;
} }
/** /**