Fix handling of different media links in frontend and ACP
authorMatthias Schmidt <gravatronics@live.com>
Sun, 11 Sep 2016 13:21:31 +0000 (15:21 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 11 Sep 2016 13:21:31 +0000 (15:21 +0200)
… analogously to attachments

wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php

index d4f6a8f01440e0768903ec7156da2cf1242ba9ad..e08490332c8139c21175b5dbc82c55e9958faa91 100644 (file)
@@ -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=(?P<thumbnail>tiny|small|large|medium)\b~', $element->getAttribute('src'), $matches)) {
+                       $thumbnail = $matches['thumbnail'];
+               }
+               
+               if (preg_match('~\bmessageFloatObject(?P<float>Left|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');