Added missing img bbcode converter
authorAlexander Ebert <ebert@woltlab.com>
Fri, 7 Oct 2016 10:15:20 +0000 (12:15 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Fri, 7 Oct 2016 10:15:26 +0000 (12:15 +0200)
wcfsetup/install/files/lib/system/html/metacode/converter/ImgMetacodeConverter.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/html/metacode/converter/ImgMetacodeConverter.class.php b/wcfsetup/install/files/lib/system/html/metacode/converter/ImgMetacodeConverter.class.php
new file mode 100644 (file)
index 0000000..bf2528c
--- /dev/null
@@ -0,0 +1,35 @@
+<?php
+namespace wcf\system\html\metacode\converter;
+
+/**
+ * Converts img bbcode into `<img>`.
+ * 
+ * @author      Alexander Ebert
+ * @copyright   2001-2016 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package     WoltLabSuite\Core\System\Html\Metacode\Converter
+ * @since       3.0
+ */
+class ImgMetacodeConverter extends AbstractMetacodeConverter {
+       /**
+        * @inheritDoc
+        */
+       public function convert(\DOMDocumentFragment $fragment, array $attributes) {
+               $element = $fragment->ownerDocument->createElement('img');
+               $element->setAttribute('src', $attributes[0]);
+               
+               if (isset($attributes[1]) && in_array($attributes[1], ['left', 'right'])) {
+                       $element->setAttribute('class', 'messageFloatObject'.ucfirst($attributes[1]));
+               }
+               
+               return $element;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function validateAttributes(array $attributes) {
+               $count = count($attributes);
+               return ($count > 0 && $count < 4);
+       }
+}