Example #1
0
 public function getSectionByLocale($locale = NULL)
 {
     if (!strlen($locale)) {
         $locale = self::getLocale();
     }
     return MultilingualSection::getByLocale($locale);
 }
Example #2
0
 public function create_page()
 {
     Loader::model('section', 'multilingual');
     if (Loader::helper('validation/token')->validate('create_page', $_POST['token'])) {
         $ms = MultilingualSection::getByLocale($_POST['locale']);
         $page = Page::getByID($_POST['sourceID']);
         if (is_object($page) && !$page->isError()) {
             // we get the related parent id
             $cParentID = $page->getCollectionParentID();
             $cParent = Page::getByID($cParentID);
             $cParentRelatedID = $ms->getTranslatedPageID($cParent);
             if ($cParentRelatedID > 0) {
                 // we copy the page underneath it and store it
                 $newParent = Page::getByID($cParentRelatedID);
                 $ct = CollectionType::getByID($page->getCollectionTypeID());
                 $cp = new Permissions($newParent);
                 if ($cp->canAddSubCollection($ct) && $page->canMoveCopyTo($newParent)) {
                     $newPage = $page->duplicate($newParent);
                     if (is_object($newPage)) {
                         print '<a href="' . Loader::helper("navigation")->getLinkToCollection($newPage) . '">' . $newPage->getCollectionName() . '</a>';
                     }
                 } else {
                     print '<span class="ccm-error">' . t("Insufficient permissions.") . '</span>';
                 }
             }
         }
     }
     exit;
 }
Example #3
0
 public function add_content_section()
 {
     if (Loader::helper('validation/token')->validate('add_content_section')) {
         if (!Loader::helper('validation/numbers')->integer($this->post('pageID')) || $this->post('pageID') < 1) {
             $this->error->add(t('You must specify a page for this multilingual content section.'));
         } else {
             $pc = Page::getByID($this->post('pageID'));
         }
         if (!$this->error->has()) {
             $lc = MultilingualSection::getByID($this->post('pageID'));
             if (is_object($lc)) {
                 $this->error->add(t('A language section page at this location already exists.'));
             }
         }
         if (!$this->error->has()) {
             if ($this->post('msIcon')) {
                 $combination = $this->post('msLanguage') . '_' . $this->post('msIcon');
                 $locale = MultilingualSection::getByLocale($combination);
                 if (is_object($locale)) {
                     $this->error->add(t('This language/region combination already exists.'));
                 }
             }
         }
         if (!$this->error->has()) {
             MultilingualSection::assign($pc, $this->post('msLanguage'), $this->post('msIcon'));
             $this->redirect('/dashboard/multilingual/setup', 'multilingual_content_updated');
         }
     } else {
         $this->error->add(Loader::helper('validation/token')->getErrorMessage());
     }
     $this->view();
 }
Example #4
0
<?php

defined('C5_EXECUTE') or die(_("Access Denied."));
Loader::model('section', 'multilingual');
// first we get the selected language
if (isset($_POST['ccmMultilingualSiteDefaultLanguage'])) {
    // this is coming from "set default" custom template
    if (isset($_POST['ccmMultilingualSiteRememberDefault']) && $_POST['ccmMultilingualSiteRememberDefault']) {
        setcookie('DEFAULT_LOCALE', $_POST['ccmMultilingualSiteDefaultLanguage'], time() + 60 * 60 * 24 * 365, DIR_REL . '/');
    }
    if (empty($_POST['ccmMultilingualSiteRememberDefault'])) {
        setcookie('DEFAULT_LOCALE', '', time() - 3600, DIR_REL . '/');
    }
    $lang = MultilingualSection::getByLocale($_REQUEST['ccmMultilingualSiteDefaultLanguage']);
} else {
    $lang = MultilingualSection::getByID($_REQUEST['ccmMultilingualChooseLanguage']);
}
if (is_object($lang)) {
    if (isset($_REQUEST['ccmMultilingualCurrentPageID'])) {
        $page = Page::getByID($_REQUEST['ccmMultilingualCurrentPageID']);
        if (!$page->isError()) {
            $relatedID = $lang->getTranslatedPageID($page);
            if ($relatedID) {
                $pc = Page::getByID($relatedID);
                header('Location: ' . Loader::helper('navigation')->getLinkToCollection($pc, true));
                exit;
            } elseif ($page->isGeneratedCollection()) {
                $_SESSION['DEFAULT_LOCALE'] = (string) $lang->getLocale();
                header('Location: ' . Loader::helper('navigation')->getLinkToCollection($page, true));
                exit;
            }
Example #5
0
 public static function setupSiteInterfaceLocalization()
 {
     // don't translate dashboard pages
     $c = Page::getCurrentPage();
     if ($c instanceof Page && Loader::helper('section', 'multilingual')->section('dashboard')) {
         return;
     }
     $ms = MultilingualSection::getCurrentSection();
     if (is_object($ms)) {
         $locale = $ms->getLocale();
     } else {
         $locale = DefaultLanguageHelper::getSessionDefaultLocale();
     }
     // change core language to translate e.g. core blocks/themes
     if (strlen($locale)) {
         Localization::changeLocale($locale);
     }
     // site translations
     if (is_dir(DIR_LANGUAGES_SITE_INTERFACE)) {
         if (file_exists(DIR_LANGUAGES_SITE_INTERFACE . '/' . $locale . '.mo')) {
             $loc = Localization::getInstance();
             $loc->addSiteInterfaceLanguage($locale);
         }
     }
     // add package translations
     if (strlen($locale)) {
         $ms = MultilingualSection::getByLocale($locale);
         if ($ms instanceof MultilingualSection) {
             $pl = PackageList::get();
             $installed = $pl->getPackages();
             foreach ($installed as $pkg) {
                 if ($pkg instanceof Package) {
                     $pkg->setupPackageLocalization($ms->getLocale());
                 }
             }
         }
     }
 }