PageRenderTime 55ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/packages/multilingual/blocks/switch_language/tools/switch.php

https://bitbucket.org/selfeky/xclusivescardwebsite
PHP | 43 lines | 34 code | 7 blank | 2 comment | 9 complexity | fbbecb3973530f69ee2de510422ada3a MD5 | raw file
  1. <?php defined('C5_EXECUTE') or die(_("Access Denied."));
  2. Loader::model('section', 'multilingual');
  3. // first we get the selected language
  4. if (isset($_POST['ccmMultilingualSiteDefaultLanguage'])) {
  5. // this is coming from "set default" custom template
  6. if (isset($_POST['ccmMultilingualSiteRememberDefault']) && $_POST['ccmMultilingualSiteRememberDefault']) {
  7. setcookie('DEFAULT_LOCALE', $_POST['ccmMultilingualSiteDefaultLanguage'], time()+60*60*24*365, DIR_REL . '/');
  8. }
  9. if (empty($_POST['ccmMultilingualSiteRememberDefault'])) {
  10. setcookie('DEFAULT_LOCALE', '', time() - 3600, DIR_REL . '/');
  11. }
  12. $lang = MultilingualSection::getByLocale($_REQUEST['ccmMultilingualSiteDefaultLanguage']);
  13. } else {
  14. $lang = MultilingualSection::getByID($_REQUEST['ccmMultilingualChooseLanguage']);
  15. }
  16. if (is_object($lang)) {
  17. if (isset($_REQUEST['ccmMultilingualCurrentPageID'])) {
  18. $page = Page::getByID($_REQUEST['ccmMultilingualCurrentPageID']);
  19. if (!$page->isError()) {
  20. $relatedID = $lang->getTranslatedPageID($page);
  21. if ($relatedID) {
  22. $pc = Page::getByID($relatedID);
  23. header('Location: ' . Loader::helper('navigation')->getLinkToCollection($pc, true));
  24. exit;
  25. } elseif($page->isGeneratedCollection()) {
  26. $_SESSION['DEFAULT_LOCALE'] = (string) $lang->getLocale();
  27. header('Location: ' . Loader::helper('navigation')->getLinkToCollection($page, true));
  28. exit;
  29. }
  30. }
  31. }
  32. header('Location: ' . Loader::helper('navigation')->getLinkToCollection($lang, true));
  33. exit;
  34. }
  35. header('Location: ' . BASE_URL . DIR_REL . '/');
  36. exit;