コード例 #1
0
 public function view()
 {
     $this->requireAsset('javascript', 'jquery');
     $ml = Section::getList();
     $c = \Page::getCurrentPage();
     $al = Section::getBySectionOfSite($c);
     $languages = [];
     $locale = null;
     if ($al !== null) {
         $locale = $al->getLanguage();
     }
     if (!$locale) {
         $locale = \Localization::activeLocale();
         $al = Section::getByLocale($locale);
     }
     foreach ($ml as $m) {
         $languages[$m->getCollectionID()] = $m->getLanguageText($m->getLocale());
     }
     $this->set('languages', $languages);
     $this->set('languageSections', $ml);
     $this->set('activeLanguage', $al ? $al->getCollectionID() : null);
     $dl = $this->app->make('multilingual/detector');
     $this->set('defaultLocale', $dl->getPreferredSection());
     $this->set('locale', $locale);
     $this->set('cID', $c->getCollectionID());
 }
コード例 #2
0
ファイル: Flag.php プロジェクト: krsreenatha/concrete5-1
 public static function getDashboardSitemapIconSRC($page)
 {
     if ($page->getPageTypeHandle() == STACK_CATEGORY_PAGE_TYPE) {
         $section = Section::getByLocale($page->getCollectionName());
         if (is_object($section)) {
             return self::getSectionFlagIcon($section, true);
         }
     }
     $ids = Section::getIDList();
     if (in_array($page->getCollectionID(), $ids)) {
         return self::getSectionFlagIcon($page, true);
     }
 }
コード例 #3
0
ファイル: Detector.php プロジェクト: ppiedaderawnet/concrete5
 /**
  * Returns the preferred section based on session, cookie,
  * user object, default browser (if allowed), and finally
  * site preferences.
  * Since the user's language is not a locale but a language,
  * attempts to determine best section for the given language.
  *
  * @return Section
  */
 public static function getPreferredSection()
 {
     $site = \Site::getSite();
     $locale = false;
     $app = Facade::getFacadeApplication();
     // they have a language in a certain session going already
     $session = $app->make('session');
     if ($session->has('multilingual_default_locale')) {
         $locale = $session->get('multilingual_default_locale');
     } else {
         $cookie = $app->make('cookie');
         if ($cookie->has('multilingual_default_locale')) {
             $locale = $cookie->get('multilingual_default_locale');
         }
     }
     if ($locale) {
         $home = Section::getByLocale($locale);
         if ($home) {
             return $home;
         }
     }
     $u = new \User();
     if ($u->isRegistered()) {
         $userDefaultLanguage = $u->getUserDefaultLanguage();
         if ($userDefaultLanguage) {
             $home = Section::getByLocaleOrLanguage($userDefaultLanguage);
             if ($home) {
                 return $home;
             }
         }
     }
     $config = $site->getConfigRepository();
     if ($config->get('multilingual.use_browser_detected_locale')) {
         $home = false;
         $locales = \Punic\Misc::getBrowserLocales();
         foreach (array_keys($locales) as $locale) {
             $home = Section::getByLocaleOrLanguage($locale);
             if ($home) {
                 break;
             }
         }
         if ($home) {
             return $home;
         }
     }
     $site = \Site::getSite();
     return Section::getByLocale($site->getDefaultLocale());
 }
コード例 #4
0
ファイル: Detector.php プロジェクト: ngreimel/kovent
 /**
  *
  * Returns the preferred section based on session, cookie,
  * user object, default browser (if allowed), and finally
  * site preferences. 
  * Since the user's language is not a locale but a language,
  * attempts to determine best section for the given language.
  * @return Section
  */
 public static function getPreferredSection()
 {
     $locale = false;
     // they have a language in a certain session going already
     if (Session::has('multilingual_default_locale')) {
         $locale = Session::get('multilingual_default_locale');
     } else {
         if (Cookie::has('multilingual_default_locale')) {
             $locale = Cookie::get('multilingual_default_locale');
         }
     }
     if ($locale) {
         $home = Section::getByLocale($locale);
         if ($home) {
             return $home;
         }
     }
     $u = new \User();
     if ($u->isRegistered()) {
         $userDefaultLanguage = $u->getUserDefaultLanguage();
         if ($userDefaultLanguage) {
             $home = Section::getByLocaleOrLanguage($userDefaultLanguage);
             if ($home) {
                 return $home;
             }
         }
     }
     if (Config::get('concrete.multilingual.use_browser_detected_locale')) {
         $home = false;
         $locales = \Punic\Misc::getBrowserLocales();
         foreach (array_keys($locales) as $locale) {
             $home = Section::getByLocaleOrLanguage($locale);
             if ($home) {
                 break;
             }
         }
         if ($home) {
             return $home;
         }
     }
     return Section::getByLocale(Config::get('concrete.multilingual.default_locale'));
 }
コード例 #5
0
ファイル: StackList.php プロジェクト: jkoudys/concrete5
 public static function rescanMultilingualStacks()
 {
     $sl = new static();
     $stacks = $sl->get();
     foreach ($stacks as $stack) {
         $section = $stack->getMultilingualSection();
         if (!$section) {
             $section = false;
             $parent = \Page::getByID($stack->getCollectionParentID());
             if ($parent->getCollectionPath() == STACKS_PAGE_PATH) {
                 // this is the default
                 $section = Section::getDefaultSection();
             } else {
                 if ($parent->getPageTypeHandle() == STACK_CATEGORY_PAGE_TYPE) {
                     $locale = $parent->getCollectionHandle();
                     $section = Section::getByLocale($locale);
                 }
             }
             if ($section) {
                 $stack->updateMultilingualSection($section);
             }
         }
     }
 }
コード例 #6
0
 public function export_translations($localeCode)
 {
     $result = new EditResponse();
     try {
         if (!Core::make('token')->validate('export_translations')) {
             throw new \Exception(Core::make('token')->getErrorMessage());
         }
         $section = Section::getByLocale($localeCode);
         if (is_object($section) && !$section->isError()) {
             if ($section->getLocale() == Config::get('concrete.multilingual.default_source_locale')) {
                 $section = null;
             }
         } else {
             $section = null;
         }
         if (!isset($section)) {
             throw new \Exception(t('Invalid language identifier'));
         }
         $translations = $section->getSectionInterfaceTranslations();
         $extractor = Core::make('multilingual/extractor');
         $extractor->mergeTranslationsWithSectionFile($section, $translations);
         $extractor->saveSectionTranslationsToFile($section, $translations);
         \Localization::clearCache();
         $result->setAdditionalDataAttribute('newToken', Core::make('token')->generate('export_translations'));
         $result->message = t('The translations have been exported to file and will be used by the website.');
     } catch (\Exception $x) {
         $result->setError($x);
     }
     $result->outputJSON();
 }
コード例 #7
0
ファイル: setup.php プロジェクト: ngreimel/kovent
 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 = Section::getByID($this->post('pageID'));
             if (is_object($lc)) {
                 $this->error->add(t('A multilingual section page at this location already exists.'));
             }
         }
         if (!$this->error->has()) {
             if ($this->post('msLanguage')) {
                 $combination = $this->post('msLanguage') . '_' . $this->post('msCountry');
                 $locale = Section::getByLocale($combination);
                 if (is_object($locale)) {
                     $this->error->add(t('This language/region combination already exists.'));
                 }
             }
         }
         if (!$this->error->has()) {
             Section::assign($pc, $this->post('msLanguage'), $this->post('msCountry'));
             $this->redirect('/dashboard/system/multilingual/setup', 'multilingual_content_updated');
         }
     } else {
         $this->error->add(Loader::helper('validation/token')->getErrorMessage());
     }
     $this->view();
 }
コード例 #8
0
ファイル: Section.php プロジェクト: WillemAnchor/concrete5
 public static function relatePage($oldPage, $newPage, $locale)
 {
     $db = Database::get();
     $mpRelationID = self::getMultilingualPageRelationID($oldPage->getCollectionID());
     $section = Section::getByLocale($locale);
     if ($mpRelationID && $section) {
         $v = array($mpRelationID, $newPage->getCollectionID(), $section->getLocale(), $section->getLanguage());
         $db->Execute('delete from MultilingualPageRelations where mpRelationID = ? and mpLocale = ?', array($mpRelationID, $section->getLocale()));
         $db->Execute('delete from MultilingualPageRelations where cID = ?', array($newPage->getCollectionID()));
         $db->Execute('insert into MultilingualPageRelations (mpRelationID, cID, mpLocale, mpLanguage) values (?, ?, ?, ?)', $v);
         $pde = new Event($newPage);
         $pde->setLocale($locale);
         \Events::dispatch('on_multilingual_page_relate', $pde);
     }
 }