From 562336f5ff04ba4813a87b06e8380b99025a5cfd Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 28 May 2016 01:10:13 +0200 Subject: [PATCH] Added handling of attachment images in editor --- .../filter/MessageHtmlInputFilter.class.php | 3 ++ .../input/node/HtmlInputNodeImg.class.php | 34 +++++++++++++++++++ .../node/HtmlInputNodeProcessor.class.php | 1 + 3 files changed, 38 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php diff --git a/wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php b/wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php index 3c212884e5..49627f2735 100644 --- a/wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php +++ b/wcfsetup/install/files/lib/system/html/input/filter/MessageHtmlInputFilter.class.php @@ -52,5 +52,8 @@ class MessageHtmlInputFilter implements IHtmlInputFilter { 'data-name' => 'Text', 'data-uuid' => 'Text' ]); + + // add data-attachment-id="" for + $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 index 0000000000..1d4da85b85 --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeImg.class.php @@ -0,0 +1,34 @@ +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); + } + } +} diff --git a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php index a1d6ae6221..35a8485d40 100644 --- a/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/input/node/HtmlInputNodeProcessor.class.php @@ -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(); -- 2.20.1