public function getTranslatedPages($page = false, $sans = false)
 {
     $langms = new MultilingualSection();
     if ($page) {
         $ms = MultilingualSection::getByID($page->getCollectionID());
     } else {
         $page = Page::getCurrentPage();
         $ms = MultilingualSection::getCurrentSection();
     }
     if (is_object($ms)) {
         $lang = $ms->getLocale();
     }
     if ($sans) {
         $locales = self::getLocales($sans);
     } else {
         $locales = self::getLocales($lang);
     }
     $tpages = array();
     foreach ($locales as $locale) {
         $langms->msLocale = $locale;
         $id = $langms->getTranslatedPageID($page);
         $transPage = Page::getByID($id);
         $transPage->locale = $locale;
         if ($id > 0) {
             $tpages[$locale] = $transPage;
         }
     }
     return $tpages;
 }
Exemple #2
0
 /** Returns the page in a specific language related to the specified page, with support to aliased pages.
  * @param Page $page The page for which you want the translated page.
  * @param MultilingualSection $lang The language of the translated page.
  * @param bool $fallbackToHome Set to true (default) if you want to fallback to the homepage of $lang if there's no translation for $page. If false you'll get null.
  * @return Page|null
  */
 public function getTranslatedPageWithAliasSupport($page, $lang, $fallbackToHome = true)
 {
     // Is the page already under $lang (in the same locale)?
     $pageLang = MultilingualSection::getBySectionOfSite($page);
     if ($pageLang && $pageLang->msLocale === $lang->msLocale) {
         return $page;
     }
     // Let's determine the original cID (differs from $page->cID if $page is an alias).
     $original_cID = self::getOriginal_cID($page, $aliasLevel);
     // Let's determine the aliases of the page (if there are some).
     if (!is_array(self::$_pageAliasesOf)) {
         self::$_pageAliasesOf = array();
     }
     if (!array_key_exists($original_cID, self::$_pageAliasesOf)) {
         self::$_pageAliasesOf[$original_cID] = self::getAliasesOf($original_cID);
     }
     // If we're querying an alias of $page, return it.
     foreach (self::$_pageAliasesOf[$original_cID] as $alias) {
         if ($alias['Lang'] && $alias['Lang']->msLocale === $lang->msLocale) {
             return $alias['Page'];
         }
     }
     // Let's check if we're wanting the page itself.
     if ($aliasLevel == 2) {
         $originalPage = Page::getByID($original_cID);
         $originalLanguage = MultilingualSection::getBySectionOfSite($originalPage);
         if ($originalLanguage && $originalLanguage->msLocale === $lang->msLocale) {
             return $originalPage;
         }
     }
     // Let's check if we've got a translated page of this page
     $relatedID = $lang->getTranslatedPageID($page);
     if ($relatedID) {
         return Page::getByID($relatedID);
     }
     // Let's see if we can point to an alias of another translated page
     if (!is_array(self::$_allLanguages)) {
         self::$_allLanguages = MultilingualSection::getList();
     }
     foreach (self::$_allLanguages as $allLanguage) {
         $translatedTo_cID = $allLanguage->getTranslatedPageID($page);
         if ($translatedTo_cID) {
             $translatedTo_Page = Page::getByID($translatedTo_cID);
             $translatedTo_cID = self::getOriginal_cID($translatedTo_Page, $aliasLevel);
             if (!$aliasLevel) {
                 if (!array_key_exists($translatedTo_cID, self::$_pageAliasesOf)) {
                     self::$_pageAliasesOf[$translatedTo_cID] = self::getAliasesOf($translatedTo_cID);
                 }
                 foreach (self::$_pageAliasesOf[$translatedTo_cID] as $alias) {
                     if ($alias['Lang'] && $alias['Lang']->msLocale === $lang->msLocale) {
                         return $alias['Page'];
                     }
                 }
             }
         }
     }
     // Fallback_ let's return the $lang homepage
     return $fallbackToHome ? $lang : null;
 }