From: Marcel Werk Date: Tue, 14 Jun 2016 09:29:56 +0000 (+0200) Subject: Added hreflang-tags to other (language) versions of a page X-Git-Tag: 3.0.0_Beta_1~1456 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=28468c30e5d028799044f8c5631c90709362cb03;p=GitHub%2FWoltLab%2FWCF.git Added hreflang-tags to other (language) versions of a page --- diff --git a/com.woltlab.wcf/templates/cms.tpl b/com.woltlab.wcf/templates/cms.tpl index 6d9651ea4e..55111b784a 100644 --- a/com.woltlab.wcf/templates/cms.tpl +++ b/com.woltlab.wcf/templates/cms.tpl @@ -1,5 +1,13 @@ {capture assign='headContent'} + + {if $page->isMultilingual} + {foreach from=$page->getPageLanguages() item='pageLanguage'} + {if $pageLanguage->getLanguage()} + + {/if} + {/foreach} + {/if} {/capture} {include file='header'} diff --git a/wcfsetup/install/files/lib/data/page/Page.class.php b/wcfsetup/install/files/lib/data/page/Page.class.php index 8ed5c581e4..6f172b556d 100644 --- a/wcfsetup/install/files/lib/data/page/Page.class.php +++ b/wcfsetup/install/files/lib/data/page/Page.class.php @@ -297,6 +297,27 @@ class Page extends DatabaseObject implements ILinkableObject, ITitledObject { return ''; } + /** + * Returns the languages of this page. + * + * @return PageLanguage[] + */ + public function getPageLanguages() { + $pageLanguages = []; + if ($this->isMultilingual) { + $sql = "SELECT languageID + FROM wcf" . WCF_N . "_page_content + WHERE pageID = ?"; + $statement = WCF::getDB()->prepareStatement($sql); + $statement->execute([$this->pageID]); + while ($languageID = $statement->fetchColumn()) { + $pageLanguages[] = new PageLanguage($this->pageID, $languageID); + } + } + + return $pageLanguages; + } + /** * Returns the page with the given identifier. * diff --git a/wcfsetup/install/files/lib/data/page/PageLanguage.class.php b/wcfsetup/install/files/lib/data/page/PageLanguage.class.php new file mode 100644 index 0000000000..1c85cdf4b7 --- /dev/null +++ b/wcfsetup/install/files/lib/data/page/PageLanguage.class.php @@ -0,0 +1,59 @@ + + * @package com.woltlab.wcf + * @subpackage data.page + * @category Community Framework + * @since 2.2 + */ +class PageLanguage { + /** + * language id + * @var integer + */ + protected $languageID; + + /** + * page id + * @var integer + */ + protected $pageID; + + /** + * Creates a new PageLanguage object. + * + * @param integer $pageID + * @param integer $languageID + */ + public function __construct($pageID, $languageID) { + $this->pageID = $pageID; + $this->languageID = $languageID; + } + + /** + * Returns the link to this version of the page. + * + * @return string + */ + public function getLink() { + return LinkHandler::getInstance()->getCmsLink($this->pageID, $this->languageID); + } + + /** + * Returns the language of this version of the page. + * + * @return Language + */ + public function getLanguage() { + return LanguageFactory::getInstance()->getLanguage($this->languageID); + } +}