Add meta tags for trophy page
authorjoshuaruesweg <ruesweg@woltlab.com>
Sun, 4 Apr 2021 19:49:45 +0000 (21:49 +0200)
committerjoshuaruesweg <ruesweg@woltlab.com>
Sun, 4 Apr 2021 19:49:45 +0000 (21:49 +0200)
wcfsetup/install/files/lib/page/TrophyPage.class.php

index 312330c26e285d4927f894cb5d7f9373b5e16a0c..2bca822ec29d0983234f445384626a676e012fad 100644 (file)
@@ -13,9 +13,11 @@ use wcf\system\cache\runtime\UserProfileRuntimeCache;
 use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\IllegalLinkException;
 use wcf\system\exception\PermissionDeniedException;
+use wcf\system\MetaTagHandler;
 use wcf\system\page\PageLocationManager;
 use wcf\system\request\LinkHandler;
 use wcf\system\WCF;
+use wcf\util\StringUtil;
 
 /**
  * Represents a trophy page.
@@ -90,6 +92,33 @@ class TrophyPage extends MultipleLinkPage
             $this->trophy->getCategory()->getObjectID(),
             $this->trophy->getCategory()
         );
+
+        // Add meta tags.
+        MetaTagHandler::getInstance()->addTag(
+            'og:title',
+            'og:title',
+            $this->trophy->getTitle() . ' - ' . WCF::getLanguage()->get(PAGE_TITLE),
+            true
+        );
+        MetaTagHandler::getInstance()->addTag('og:url', 'og:url', $this->trophy->getLink(), true);
+
+        if ($this->trophy->getDescription()) {
+            MetaTagHandler::getInstance()->addTag(
+                'og:description',
+                'og:description',
+                StringUtil::decodeHTML(StringUtil::stripHTML($this->trophy->getDescription())),
+                true
+            );
+        }
+
+        if ($this->trophy->type == Trophy::TYPE_IMAGE) {
+            MetaTagHandler::getInstance()->addTag(
+                'og:image',
+                'og:image',
+                WCF::getPath() . 'images/trophy/' . $this->trophy->iconFile,
+                true
+            );
+        }
     }
 
     /**