From d58eaa13d16708bee10bef75302dbb238577d34c Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 27 Jul 2021 21:44:02 +0000 Subject: [PATCH 1/2] Issue 10545: Convert complex zmg BBCode elements --- src/Content/Text/BBCode.php | 39 +++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index cf609832bd..200c951de3 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1067,6 +1067,43 @@ class BBCode return $return; } + /** + * Convert complex IMG and ZMG elements + * + * @param [type] $text + * @param integer $simplehtml + * @param integer $uriid + * @return string + */ + private static function convertImages(string $text, int $simplehtml, int $uriid = 0):string + { + DI::profiler()->startRecording('rendering'); + $return = preg_replace_callback( + "/\[[zi]mg(.*?)\]([^\[\]]*)\[\/[zi]mg\]/ism", + function ($match) use ($simplehtml, $uriid) { + $attribute_string = $match[1]; + $attributes = []; + foreach (['alt', 'width', 'height'] as $field) { + preg_match("/$field=(['\"])(.+?)\\1/ism", $attribute_string, $matches); + $attributes[$field] = html_entity_decode($matches[2] ?? '', ENT_QUOTES, 'UTF-8'); + } + + $img_str = ' $value) { + if (!empty($value)) { + $img_str .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT) . '"'; + } + } + return $img_str . '>'; + }, + $text + ); + + DI::profiler()->stopRecording(); + return $return; + } + /** * Default [share] tag conversion callback * @@ -1729,6 +1766,8 @@ class BBCode $text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '' . DI::l10n()->t('Image/photo') . '', $text); $text = preg_replace("/\[zmg\](.*?)\[\/zmg\]/ism", '' . DI::l10n()->t('Image/photo') . '', $text); + + $text = self::convertImages($text, $simple_html, $uriid); $text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism", '
' . DI::l10n()->t('Encrypted content') . '
', $text); $text = preg_replace("/\[crypt(.*?)\](.*?)\[\/crypt\]/ism", '
' . DI::l10n()->t('Encrypted content') . '
', $text); From 6f40904ea104ec3e24d0d90d8a18b84c965155df Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 28 Jul 2021 10:18:34 +0000 Subject: [PATCH 2/2] Increased version --- src/Content/Text/BBCode.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 200c951de3..cd433bdbb8 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -51,7 +51,7 @@ use Friendica\Util\XML; class BBCode { // Update this value to the current date whenever changes are made to BBCode::convert - const VERSION = '2021-07-13'; + const VERSION = '2021-07-28'; const INTERNAL = 0; const EXTERNAL = 1;