From d96ddb28d419931f9c5a3e27039861f0377aa8c2 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 11 Jul 2016 00:09:57 +0200 Subject: [PATCH] Added `[url]` metacode converter --- .../converter/UrlMetacodeConverter.class.php | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/html/metacode/converter/UrlMetacodeConverter.class.php 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 index 0000000000..88e518e0ba --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/metacode/converter/UrlMetacodeConverter.class.php @@ -0,0 +1,41 @@ +`. + * + * @author Alexander Ebert + * @copyright 2001-2016 WoltLab GmbH + * @license GNU Lesser General Public License + * @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; + } +} -- 2.20.1