From e4609a9334275939b308462dc5a9d000320e252a Mon Sep 17 00:00:00 2001 From: joshuaruesweg Date: Tue, 23 Feb 2021 11:54:57 +0100 Subject: [PATCH] Add Unfurl Url Embedded Object --- com.woltlab.wcf/objectType.xml | 5 ++ .../UnfurlUrlEmbeddedObjectHandler.class.php | 49 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index f5e5569c74..78b99d56b6 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -1199,6 +1199,11 @@ com.woltlab.wcf.message.embeddedObject wcf\system\message\embedded\object\ArticleMessageEmbeddedObjectHandler + + com.woltlab.wcf.unfurlUrl + com.woltlab.wcf.message.embeddedObject + wcf\system\message\embedded\object\UnfurlUrlEmbeddedObjectHandler + com.woltlab.wcf.payment.method.paypal diff --git a/wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php b/wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php new file mode 100644 index 0000000000..b5c30ee503 --- /dev/null +++ b/wcfsetup/install/files/lib/system/message/embedded/object/UnfurlUrlEmbeddedObjectHandler.class.php @@ -0,0 +1,49 @@ + + * @package WoltLabSuite\Core\System\Message\Embedded\Object + * @since 5.4 + */ +class UnfurlUrlEmbeddedObjectHandler extends AbstractMessageEmbeddedObjectHandler +{ + /** + * @inheritDoc + */ + public function loadObjects(array $objectIDs) + { + $urlList = new UnfurlUrlList(); + $urlList->getConditionBuilder()->add('unfurl_url.urlID IN (?)', [$objectIDs]); + $urlList->readObjects(); + + return $urlList->getObjects(); + } + + /** + * @inheritDoc + */ + public function parse(HtmlInputProcessor $htmlInputProcessor, array $embeddedData) + { + $unfurlUrlIDs = []; + foreach ($htmlInputProcessor->getHtmlInputNodeProcessor()->getDocument()->getElementsByTagName('a') as $element) { + /** @var \DOMElement $element */ + $id = intval($element->getAttribute(HtmlNodeUnfurlLink::UNFURL_URL_ID_ATTRIBUTE_NAME)); + + if (!empty($id)) { + $unfurlUrlIDs[] = $id; + } + } + + return $unfurlUrlIDs; + } +} -- 2.20.1