Add UGC tag only for user generated content
authorjoshuaruesweg <ruesweg@woltlab.com>
Sat, 20 Mar 2021 11:36:16 +0000 (12:36 +0100)
committerjoshuaruesweg <ruesweg@woltlab.com>
Sat, 20 Mar 2021 11:36:43 +0000 (12:36 +0100)
com.woltlab.wcf/templates/unfurlUrl.tpl
wcfsetup/install/files/lib/data/unfurl/url/UnfurlUrl.class.php
wcfsetup/install/files/lib/system/html/output/node/HtmlOutputUnfurlUrlNode.class.php

index 02e81c7243b09400ee4b808c78c810d22ecfe80f..dc0ed1d4bc85ee766c338e8c753e829552b28946 100644 (file)
@@ -1,6 +1,6 @@
 {if $object->status == "SUCCESSFUL"}
        {if $object->isPlainUrl()}
-               <a {anchorAttributes url=$object->url isUgc=true}>{$object->title}</a>
+               <a {anchorAttributes url=$object->url isUgc=$enableUgc}>{$object->title}</a>
        {else}
                <div class="
                        unfurlUrlCard
@@ -14,9 +14,9 @@
                                <div class="unfurlUrlDescription">{$object->description}</div>
                                <div class="unfurlUrlHost">{$object->getHost()}</div>
                        </div>
-                       <a class="unfurlUrlLinkShadow" {anchorAttributes url=$object->url appendClassname=false isUgc=true}></a>
+                       <a class="unfurlUrlLinkShadow" {anchorAttributes url=$object->url appendClassname=false isUgc=$enableUgc}></a>
                </div>
        {/if}
 {else}
-       <a {anchorAttributes url=$object->url isUgc=true}>{$object->url}</a>
+       <a {anchorAttributes url=$object->url isUgc=$enableUgc}>{$object->url}</a>
 {/if}
\ No newline at end of file
index e3c8ebc6dfc90b6c4a247a02f06a08e8df52cd2a..f86230330ab94ba5d0739e3b1c14cd9080e4e603 100644 (file)
@@ -78,10 +78,11 @@ class UnfurlUrl extends DatabaseObject
     /**
      * Renders the unfurl url card and returns the template.
      */
-    public function render(): string
+    public function render(bool $enableUgc = true): string
     {
         return WCF::getTPL()->fetch('unfurlUrl', 'wcf', [
             'object' => $this,
+            'enableUgc' => $enableUgc,
         ]);
     }
 
index cc48a352cde1f0012dc5358ee46c6a9108d4911b..632a0e04e4a094c657905a982e61776ae0c764b4 100644 (file)
@@ -4,6 +4,7 @@ namespace wcf\system\html\output\node;
 
 use wcf\system\html\node\AbstractHtmlNodeProcessor;
 use wcf\system\html\node\HtmlNodeUnfurlLink;
+use wcf\system\html\output\HtmlOutputProcessor;
 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
 use wcf\util\StringUtil;
 
@@ -36,8 +37,17 @@ class HtmlOutputUnfurlUrlNode extends AbstractHtmlOutputNode
                 && !empty($attribute)
                 && MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $attribute) !== null
             ) {
+                $enableUgc = true;
+                $processor = $htmlNodeProcessor->getHtmlProcessor();
+                if ($processor instanceof HtmlOutputProcessor) {
+                    $enableUgc = $processor->enableUgc;
+                }
+
                 $nodeIdentifier = StringUtil::getRandomID();
-                $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, ['urlId' => $attribute]);
+                $htmlNodeProcessor->addNodeData($this, $nodeIdentifier, [
+                    'urlId' => $attribute,
+                    'enableUgc' => $enableUgc,
+                ]);
 
                 $htmlNodeProcessor->renameTag($element, 'wcfNode-' . $nodeIdentifier);
             }
@@ -49,6 +59,8 @@ class HtmlOutputUnfurlUrlNode extends AbstractHtmlOutputNode
      */
     public function replaceTag(array $data)
     {
-        return MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $data['urlId'])->render();
+        /** @var \wcf\data\unfurl\url\UnfurlUrl $object */
+        $object = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.unfurlUrl', $data['urlId']);
+        return $object->render($data['enableUgc']);
     }
 }