Remove styling elements for unfurled urls
authorjoshuaruesweg <ruesweg@woltlab.com>
Fri, 12 Mar 2021 16:39:29 +0000 (17:39 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Tue, 16 Mar 2021 15:19:16 +0000 (16:19 +0100)
wcfsetup/install/files/lib/system/html/node/HtmlNodeUnfurlLink.class.php

index 50242896e7166559d8d5319a63e7cfe97f53e21b..1cec6f161744d32cd5be19a812c48cc1ca85b44a 100644 (file)
@@ -3,6 +3,7 @@
 namespace wcf\system\html\node;
 
 use wcf\data\unfurl\url\UnfurlUrlAction;
+use wcf\util\DOMUtil;
 use wcf\util\Url;
 
 /**
@@ -16,7 +17,7 @@ use wcf\util\Url;
  */
 class HtmlNodeUnfurlLink extends HtmlNodePlainLink
 {
-    public const UNFURL_URL_ID_ATTRIBUTE_NAME = "unfurl-url-id";
+    public const UNFURL_URL_ID_ATTRIBUTE_NAME = "data-unfurl-url-id";
 
     /**
      * Marks a link element with the UnfurlUrlID.
@@ -24,13 +25,25 @@ class HtmlNodeUnfurlLink extends HtmlNodePlainLink
     public static function setUnfurl(HtmlNodePlainLink $link): void
     {
         if ($link->isStandalone() && Url::is($link->href)) {
+            self::removeStyling($link);
+
             $object = new UnfurlUrlAction([], 'findOrCreate', [
                 'data' => [
                     'url' => $link->href,
                 ],
             ]);
             $returnValues = $object->executeAction();
-            $link->topLevelParent->firstChild->setAttribute(self::UNFURL_URL_ID_ATTRIBUTE_NAME, $returnValues['returnValues']->urlID);
+
+            $link->link->setAttribute(self::UNFURL_URL_ID_ATTRIBUTE_NAME, $returnValues['returnValues']->urlID);
         }
     }
+
+    private static function removeStyling(HtmlNodePlainLink $element): void
+    {
+        foreach ($element->topLevelParent->childNodes as $child) {
+            DOMUtil::removeNode($child);
+        }
+
+        $element->topLevelParent->appendChild($element->link);
+    }
 }