{capture assign='headContent'}
<link rel="canonical" href="{$canonicalURL}">
+
+ {if $page->isMultilingual}
+ {foreach from=$page->getPageLanguages() item='pageLanguage'}
+ {if $pageLanguage->getLanguage()}
+ <link rel="alternate" hreflang="{$pageLanguage->getLanguage()->languageCode}" href="{$pageLanguage->getLink()}">
+ {/if}
+ {/foreach}
+ {/if}
{/capture}
{include file='header'}
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.
*
--- /dev/null
+<?php
+namespace wcf\data\page;
+use wcf\data\language\Language;
+use wcf\system\language\LanguageFactory;
+use wcf\system\request\LinkHandler;
+
+/**
+ * Represents a page language.
+ *
+ * @author Marcel Werk
+ * @copyright 2001-2016 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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);
+ }
+}