From 6ff9c6f9b19c3833a915fd988b1ee4aefb5818df Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 18 Jul 2020 15:26:50 +0200 Subject: [PATCH] Force wsm images to be placed outside of inline elements Fixes #3410 --- .../input/node/HtmlInputNodeImg.class.php | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php index 9e8feb8324..898482b39b 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php @@ -3,6 +3,7 @@ namespace wcf\system\html\input\node; use wcf\data\smiley\Smiley; use wcf\data\smiley\SmileyCache; use wcf\system\bbcode\BBCodeHandler; +use wcf\system\bbcode\HtmlBBCodeParser; use wcf\system\html\node\AbstractHtmlNodeProcessor; use wcf\util\DOMUtil; use wcf\util\JSON; @@ -153,6 +154,39 @@ class HtmlInputNodeImg extends AbstractHtmlInputNode { $newElement->setAttribute('data-name', 'wsm'); $newElement->setAttribute('data-attributes', base64_encode(JSON::encode($attributes))); DOMUtil::replaceElement($element, $newElement, false); + + // The media bbcode is a block element that may not be placed inside inline elements. + $parent = $newElement; + $blockLevelParent = null; + $blockElements = HtmlBBCodeParser::getInstance()->getBlockBBCodes(); + while ($parent = $parent->parentNode) { + switch ($parent->nodeName) { + case 'blockquote': + case 'body': + case 'code': + case 'div': + case 'p': + case 'td': + case 'woltlab-quote': + case 'woltlab-spoiler': + $blockLevelParent = $parent; + break 2; + + case 'woltlab-metacode': + if (in_array($parent->getAttribute('data-name'), $blockElements)) { + $blockLevelParent = $parent; + break 2; + } + break; + } + } + + if ($blockLevelParent !== null) { + $element = DOMUtil::splitParentsUntil($newElement, $parent); + if ($element !== $newElement) { + DOMUtil::insertBefore($newElement, $element); + } + } } /** -- 2.20.1