From 6285c3c9035ce3fdbe49b2b2a7e3accb005dcc5c Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Fri, 26 Feb 2021 16:16:03 +0100 Subject: [PATCH] Add unfurl url output classes --- .../node/HtmlOutputNodeProcessor.class.php | 2 + .../node/HtmlOutputUnfurlUrlNode.class.php | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php index 8025476188..e8c13dc5ea 100644 --- a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputNodeProcessor.class.php @@ -94,6 +94,8 @@ class HtmlOutputNodeProcessor extends AbstractHtmlNodeProcessor $this->invokeHtmlNode(new HtmlOutputNodeWoltlabMetacode()); + $this->invokeHtmlNode(new HtmlOutputUnfurlUrlNode()); + // dynamic node handlers $this->invokeNodeHandlers('wcf\system\html\output\node\HtmlOutputNode', ['woltlab-metacode']); diff --git a/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php new file mode 100644 index 0000000000..4a82c63b62 --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php @@ -0,0 +1,52 @@ + + * @package WoltLabSuite\Core\System\Html\Output\Node + * @since 5.4 + */ +class HtmlOutputUnfurlUrlNode extends AbstractHtmlOutputNode +{ + /** + * @inheritDoc + */ + protected $tagName = 'a'; + + /** + * @inheritDoc + */ + public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProcessor) + { + /** @var \DOMElement $element */ + foreach ($elements as $element) { + $attribute = $element->getAttribute(HtmlNodeUnfurlLink::UNFURL_URL_ID_ATTRIBUTE_NAME); + if ($this->outputType === 'text/html' + && !empty($attribute) + && MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $attribute) !== null) { + $nodeIdentifier = StringUtil::getRandomID(); + $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, ['urlId' => $attribute]); + + $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier); + } + } + } + + /** + * @inheritDoc + */ + public function replaceTag(array $data) + { + return MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $data['urlId'])->render(); + } +} -- 2.20.1