From 108aee8084eb6eb77e8237ad39913e3130fba1f2 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sun, 11 Sep 2016 15:21:31 +0200 Subject: [PATCH] Fix handling of different media links in frontend and ACP MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … analogously to attachments --- .../input/node/HtmlInputNodeImg.class.php | 32 +++++++++++++++++++ 1 file changed, 32 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 d4f6a8f014..e08490332c 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 @@ -39,6 +39,9 @@ class HtmlInputNodeImg extends AbstractHtmlInputNode { if (preg_match('~\bwoltlabAttachment\b~', $class)) { $this->handleAttachment($element, $class); } + else if (preg_match('~\bwoltlabSuiteMedia\b~', $class)) { + $this->handleMedium($element, $class); + } else if (preg_match('~\bsmiley\b~', $class)) { $this->handleSmiley($element); } @@ -74,6 +77,35 @@ class HtmlInputNodeImg extends AbstractHtmlInputNode { DOMUtil::replaceElement($element, $newElement, false); } + protected function handleMedium(\DOMElement $element, $class) { + $mediumID = intval($element->getAttribute('data-media-id')); + if (!$mediumID) { + return; + } + + $float = 'none'; + $thumbnail = null; + + if (preg_match('~thumbnail=(?Ptiny|small|large|medium)\b~', $element->getAttribute('src'), $matches)) { + $thumbnail = $matches['thumbnail']; + } + + if (preg_match('~\bmessageFloatObject(?PLeft|Right)\b~', $class, $matches)) { + $float = ($matches['float'] === 'Left') ? 'left' : 'right'; + } + + $attributes = [ + $mediumID, + $thumbnail, + $float + ]; + + $newElement = $element->ownerDocument->createElement('woltlab-metacode'); + $newElement->setAttribute('data-name', 'wsm'); + $newElement->setAttribute('data-attributes', base64_encode(JSON::encode($attributes))); + DOMUtil::replaceElement($element, $newElement, false); + } + protected function handleSmiley(\DOMElement $element) { $code = $element->getAttribute('alt'); -- 2.20.1