本文整理汇总了PHP中OutputPage::getLanguageLinks方法的典型用法代码示例。如果您正苦于以下问题:PHP OutputPage::getLanguageLinks方法的具体用法?PHP OutputPage::getLanguageLinks怎么用?PHP OutputPage::getLanguageLinks使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OutputPage
的用法示例。
在下文中一共展示了OutputPage::getLanguageLinks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onBeforePageDisplay
static function onBeforePageDisplay(OutputPage &$out, Skin &$skin)
{
$languageLinks = $out->getLanguageLinks();
if (empty($languageLinks)) {
return true;
}
// this is partly a ripoff from SkinTemplate::getLanguages()
foreach ($languageLinks as $langLink) {
$languageLinkTitle = Title::newFromText($langLink);
$interwikiCode = $languageLinkTitle->getInterwiki();
$out->addLink(array('rel' => 'alternate', 'hreflang' => wfBCP47($interwikiCode), 'href' => wfExpandIRI($languageLinkTitle->getFullURL())));
}
// We also must add the current language
$currentPageLangCode = $out->getLanguage()->getCode();
$currentPageTitle = $out->getTitle();
$out->addLink(array('rel' => 'alternate', 'hreflang' => wfBCP47($currentPageLangCode), 'href' => wfExpandIRI($currentPageTitle->getFullURL())));
return true;
}
示例2: onBeforePageDisplay
public static function onBeforePageDisplay(OutputPage $out, SkinTemplate $sk)
{
$config = $out->getConfig();
if (self::canOutputHreflang($config)) {
# Generate hreflang tags
$languageLinks = $out->getLanguageLinks();
if (empty($languageLinks)) {
// shortcut - if we don't have any language links, don't bother
return;
}
$addedLink = false;
$pages = $config->get("HreflangPages");
if (!$pages) {
$pages = array();
$foundPage = true;
} else {
$pages = array_flip($pages);
$pageName = $out->getLanguage()->getHtmlCode() . ":" . $out->getTitle()->getBaseText();
$foundPage = isset($pages[$pageName]);
}
foreach ($languageLinks as $languageLinkText) {
$languageLinkTitle = Title::newFromText($languageLinkText);
if (!$languageLinkTitle) {
continue;
}
$ilInterwikiCode = $languageLinkTitle->getInterwiki();
if (!Language::isKnownLanguageTag($ilInterwikiCode)) {
continue;
}
$foundPage = $foundPage || isset($pages[$languageLinkText]);
$tags[] = Html::element('link', array('rel' => 'alternate', 'hreflang' => wfBCP47($ilInterwikiCode), 'href' => $languageLinkTitle->getFullURL()));
$addedLink = true;
}
// Only add current language link if we had any other links
if ($addedLink) {
$tags[] = Html::element('link', array('rel' => 'alternate', 'hreflang' => $out->getLanguage()->getHtmlCode(), 'href' => $out->getTitle()->getFullURL()));
}
}
if ($foundPage && $tags) {
$out->addHeadItem("hreflang:tags", join("\n", $tags));
}
}