From b54037e53b37e7d761dcee6d45b5b00c3c71d50f Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Tue, 23 Feb 2021 11:56:01 +0100 Subject: [PATCH] Unfurl standalone Urls --- .../node/HtmlInputNodeProcessor.class.php | 8 +++++ .../html/node/HtmlNodeUnfurlLink.class.php | 35 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php 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 87723fa8ad..9ac6dbba61 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 @@ -2,10 +2,12 @@ namespace wcf\system\html\input\node; +use wcf\data\unfurl\url\UnfurlUrlAction; use wcf\system\bbcode\BBCodeHandler; use wcf\system\event\EventHandler; use wcf\system\html\node\AbstractHtmlNodeProcessor; use wcf\system\html\node\HtmlNodePlainLink; +use wcf\system\html\node\HtmlNodeUnfurlLink; use wcf\system\html\node\IHtmlNode; use wcf\util\DOMUtil; use wcf\util\StringUtil; @@ -742,5 +744,11 @@ class HtmlInputNodeProcessor extends AbstractHtmlNodeProcessor } EventHandler::getInstance()->fireAction($this, 'convertPlainLinks'); + + foreach ($this->plainLinks as $plainLink) { + if ($plainLink->isPristine()) { + HtmlNodeUnfurlLink::setUnfurl($plainLink); + } + } } } diff --git a/wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php b/wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php new file mode 100644 index 0000000000..74ff262b9d --- /dev/null +++ b/wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php @@ -0,0 +1,35 @@ + + * @package WoltLabSuite\Core\System\Html\Node + * @since 5.4 + */ +class HtmlNodeUnfurlLink extends HtmlNodePlainLink +{ + public const UNFURL_URL_ID_ATTRIBUTE_NAME = "unfurl-url-id"; + + /** + * Marks a link element with the UnfurlUrlID. + */ + public static function setUnfurl(HtmlNodePlainLink $link): void + { + if ($link->isStandalone()) { + $object = new UnfurlUrlAction([], 'findOrCreate', [ + 'data' => [ + 'url' => $link->href, + ], + ]); + $returnValues = $object->executeAction(); + $link->topLevelParent->firstChild->setAttribute(self::UNFURL_URL_ID_ATTRIBUTE_NAME, $returnValues['returnValues']->urlID); + } + } +} -- 2.20.1