当前位置: 首页>>代码示例>>PHP>>正文


PHP OutputPage::getLanguageLinks方法代码示例

本文整理汇总了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;
 }
开发者ID:kolzchut,项目名称:mediawiki-extensions-AltLangRelLinks,代码行数:18,代码来源:AltLangRelLinks.php

示例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));
     }
 }
开发者ID:smalyshev,项目名称:Hreflang-extension,代码行数:42,代码来源:Hreflang.hooks.php


注:本文中的OutputPage::getLanguageLinks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。