Added `[url]` metacode converter
authorAlexander Ebert <ebert@woltlab.com>
Sun, 10 Jul 2016 22:09:57 +0000 (00:09 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 10 Jul 2016 22:10:03 +0000 (00:10 +0200)
wcfsetup/install/files/lib/system/html/metacode/converter/UrlMetacodeConverter.class.php [new file with mode: 0644]

diff --git a/wcfsetup/install/files/lib/system/html/metacode/converter/UrlMetacodeConverter.class.php b/wcfsetup/install/files/lib/system/html/metacode/converter/UrlMetacodeConverter.class.php
new file mode 100644 (file)
index 0000000..88e518e
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+namespace wcf\system\html\metacode\converter;
+
+/**
+ * Converts url bbcode into `<a>`.
+ * 
+ * @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 UrlMetacodeConverter extends AbstractMetacodeConverter {
+       /**
+        * @inheritDoc
+        */
+       public function convert(\DOMDocumentFragment $fragment, array $attributes) {
+               $element = $fragment->ownerDocument->createElement('a');
+               
+               $href = (!empty($attributes[0])) ? $attributes[0] : '';
+               if (empty($href)) {
+                       $href = $fragment->textContent;
+               }
+               
+               $element->setAttribute('href', $href);
+               $element->appendChild($fragment);
+               
+               return $element;
+       }
+       
+       /**
+        * @inheritDoc
+        */
+       public function validateAttributes(array $attributes) {
+               if (count($attributes) > 1) {
+                       return false;
+               }
+               
+               return true;
+       }
+}