Added handling of attachment images in editor
authorAlexander Ebert <ebert@woltlab.com>
Fri, 27 May 2016 23:10:13 +0000 (01:10 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 27 May 2016 23:10:20 +0000 (01:10 +0200)
wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php

index 3c212884e519240d8b2d775a370362a9c35df3f0..49627f2735a9d3c412bc624e5c311219a4e23431 100644 (file)
@@ -52,5 +52,8 @@ class MessageHtmlInputFilter implements IHtmlInputFilter {
                        'data-name' => 'Text',
                        'data-uuid' => 'Text'
                ]);
+               
+               // add data-attachment-id="" for <img>
+               $definition->addAttribute('img', 'data-attachment-id', 'Number');
        }
 }
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
new file mode 100644 (file)
index 0000000..1d4da85
--- /dev/null
@@ -0,0 +1,34 @@
+<?php
+namespace wcf\system\html\input\node;
+use wcf\system\html\node\AbstractHtmlNode;
+use wcf\system\html\node\HtmlNodeProcessor;
+use wcf\util\DOMUtil;
+use wcf\util\JSON;
+
+/**
+ * TOOD documentation
+ * @since      2.2
+ */
+class HtmlInputNodeImg extends AbstractHtmlNode {
+       protected $tagName = 'img';
+       
+       public function process(array $elements, HtmlNodeProcessor $htmlNodeProcessor) {
+               /** @var \DOMElement $element */
+               foreach ($elements as $element) {
+                       $class = $element->getAttribute('class');
+                       if ($class !== 'woltlabAttachment') {
+                               continue;
+                       }
+                       
+                       $attachmentID = intval($element->getAttribute('data-attachment-id'));
+                       if (!$attachmentID) {
+                               continue;
+                       }
+                       
+                       $newElement = $element->ownerDocument->createElement('woltlab-metacode');
+                       $newElement->setAttribute('data-name', 'attach');
+                       $newElement->setAttribute('data-attributes', base64_encode(JSON::encode([$attachmentID])));
+                       DOMUtil::replaceElement($element, $newElement, false);
+               }
+       }
+}
index a1d6ae62219c60452032e251be794cc0533cc6d1..35a8485d40d5f5ee44bb24757d8c1e11f90d1819 100644 (file)
@@ -27,6 +27,7 @@ class HtmlInputNodeProcessor extends HtmlNodeProcessor implements IHtmlInputNode
                
                // handle static converters
                $this->invokeHtmlNode(new HtmlInputNodeWoltlabMetacode());
+               $this->invokeHtmlNode(new HtmlInputNodeImg());
                
                // extract embedded content
                $this->parseEmbeddedContent();