getActiveLanguages() public static method

Get the active languages
public static getActiveLanguages ( ) : array
return array
Example #1
0
 /**
  * Process the query string
  */
 private function processQueryString()
 {
     // store the query string local, so we don't alter it.
     $queryString = trim($this->request->getPathInfo(), '/');
     // split into chunks
     $chunks = (array) explode('/', $queryString);
     $hasMultiLanguages = $this->getContainer()->getParameter('site.multilanguage');
     // single language
     if (!$hasMultiLanguages) {
         // set language id
         $language = $this->get('fork.settings')->get('Core', 'default_language', SITE_DEFAULT_LANGUAGE);
     } else {
         // multiple languages
         // default value
         $mustRedirect = false;
         // get possible languages
         $possibleLanguages = (array) Language::getActiveLanguages();
         $redirectLanguages = (array) Language::getRedirectLanguages();
         // the language is present in the URL
         if (isset($chunks[0]) && in_array($chunks[0], $possibleLanguages)) {
             // define language
             $language = (string) $chunks[0];
             // try to set a cookie with the language
             try {
                 // set cookie
                 CommonCookie::set('frontend_language', $language);
             } catch (\SpoonCookieException $e) {
                 // settings cookies isn't allowed, because this isn't a real problem we ignore the exception
             }
             // set sessions
             \SpoonSession::set('frontend_language', $language);
             // remove the language part
             array_shift($chunks);
         } elseif (CommonCookie::exists('frontend_language') && in_array(CommonCookie::get('frontend_language'), $redirectLanguages)) {
             // set languageId
             $language = (string) CommonCookie::get('frontend_language');
             // redirect is needed
             $mustRedirect = true;
         } else {
             // default browser language
             // set languageId & abbreviation
             $language = Language::getBrowserLanguage();
             // try to set a cookie with the language
             try {
                 // set cookie
                 CommonCookie::set('frontend_language', $language);
             } catch (\SpoonCookieException $e) {
                 // settings cookies isn't allowed, because this isn't a real problem we ignore the exception
             }
             // redirect is needed
             $mustRedirect = true;
         }
         // redirect is required
         if ($mustRedirect) {
             // build URL
             // trim the first / from the query string to prevent double slashes
             $url = rtrim('/' . $language . '/' . trim($this->getQueryString(), '/'), '/');
             // when we are just adding the language to the domain, it's a temporary redirect because
             // Safari keeps the 301 in cache, so the cookie to switch language doesn't work any more
             $redirectCode = $url == '/' . $language ? 302 : 301;
             // set header & redirect
             throw new RedirectException('Redirect', new RedirectResponse($url, $redirectCode));
         }
     }
     // define the language
     defined('FRONTEND_LANGUAGE') || define('FRONTEND_LANGUAGE', $language);
     defined('LANGUAGE') || define('LANGUAGE', $language);
     // sets the locale file
     Language::setLocale($language);
     // list of pageIds & their full URL
     $keys = Navigation::getKeys();
     // rebuild our URL, but without the language parameter. (it's tripped earlier)
     $url = implode('/', $chunks);
     $startURL = $url;
     // loop until we find the URL in the list of pages
     while (!in_array($url, $keys)) {
         // remove the last chunk
         array_pop($chunks);
         // redefine the URL
         $url = implode('/', $chunks);
     }
     // remove language from query string
     if ($hasMultiLanguages) {
         $queryString = trim(mb_substr($queryString, mb_strlen($language)), '/');
     }
     // if it's the homepage AND parameters were given (not allowed!)
     if ($url == '' && $queryString != '') {
         // get 404 URL
         $url = Navigation::getURL(404);
         // remove language
         if ($hasMultiLanguages) {
             $url = str_replace('/' . $language, '', $url);
         }
     }
     // set pages
     $url = trim($url, '/');
     // currently not in the homepage
     if ($url != '') {
         // explode in pages
         $pages = explode('/', $url);
         // reset pages
         $this->setPages($pages);
         // reset parameters
         $this->setParameters(array());
     }
     // set parameters
     $parameters = trim(mb_substr($startURL, mb_strlen($url)), '/');
     // has at least one parameter
     if ($parameters != '') {
         // parameters will be separated by /
         $parameters = explode('/', $parameters);
         // set parameters
         $this->setParameters($parameters);
     }
     // pageId, parentId & depth
     $pageId = Navigation::getPageId(implode('/', $this->getPages()));
     $pageInfo = Navigation::getPageInfo($pageId);
     // invalid page, or parameters but no extra
     if ($pageInfo === false || !empty($parameters) && !$pageInfo['has_extra']) {
         // get 404 URL
         $url = Navigation::getURL(404);
         // remove language
         if ($hasMultiLanguages) {
             $url = str_replace('/' . $language, '', $url);
         }
         // remove the first slash
         $url = trim($url, '/');
         // currently not in the homepage
         if ($url != '') {
             // explode in pages
             $pages = explode('/', $url);
             // reset pages
             $this->setPages($pages);
             // reset parameters
             $this->setParameters(array());
         }
     }
     // is this an internal redirect?
     if (isset($pageInfo['redirect_page_id']) && $pageInfo['redirect_page_id'] != '') {
         // get url for item
         $newPageURL = Navigation::getURL((int) $pageInfo['redirect_page_id']);
         $errorURL = Navigation::getURL(404);
         // not an error?
         if ($newPageURL != $errorURL) {
             // redirect
             throw new RedirectException('Redirect', new RedirectResponse($newPageURL, $pageInfo['redirect_code']));
         }
     }
     // is this an external redirect?
     if (isset($pageInfo['redirect_url']) && $pageInfo['redirect_url'] != '') {
         // redirect
         throw new RedirectException('Redirect', new RedirectResponse($pageInfo['redirect_url'], $pageInfo['redirect_code']));
     }
 }
Example #2
0
 /**
  * Set the language
  *
  * @param string $value The (interface-)language, will be used to parse labels.
  *
  * @throws Exception
  */
 public function setLanguage($value)
 {
     // get the possible languages
     $possibleLanguages = Language::getActiveLanguages();
     // validate
     if (!in_array($value, $possibleLanguages)) {
         // only 1 active language?
         if (!Model::getContainer()->getParameter('site.multilanguage') && count($possibleLanguages) == 1) {
             $this->language = array_shift($possibleLanguages);
         } else {
             // multiple languages available but none selected
             throw new Exception('Language invalid.');
         }
     } else {
         // language is valid: set property
         $this->language = (string) $value;
     }
     // define constant
     defined('FRONTEND_LANGUAGE') || define('FRONTEND_LANGUAGE', $this->language);
     defined('LANGUAGE') || define('LANGUAGE', $this->language);
     // set the locale (we need this for the labels)
     Language::setLocale($this->language);
 }
Example #3
0
 /**
  * Parse the languages
  */
 protected function parseLanguages()
 {
     // just execute if the site is multi-language
     if ($this->getContainer()->getParameter('site.multilanguage')) {
         // get languages
         $activeLanguages = Language::getActiveLanguages();
         // init var
         $languages = array();
         // loop active languages
         foreach ($activeLanguages as $language) {
             // build temp array
             $temp = array();
             $temp['url'] = '/' . $language;
             $temp['label'] = $language;
             $temp['name'] = Language::msg(mb_strtoupper($language));
             $temp['current'] = (bool) ($language == LANGUAGE);
             // add
             $languages[] = $temp;
         }
         // assign
         if (count($languages) > 1) {
             $this->tpl->addGlobal('languages', $languages);
         }
     }
 }
Example #4
0
 /**
  * Get the active languages
  *
  * @return array
  */
 public static function getActiveLanguages()
 {
     trigger_error('Frontend\\Core\\Engine\\Language is deprecated.
          It has been moved to Frontend\\Core\\Language\\Language', E_USER_DEPRECATED);
     return parent::getActiveLanguages();
 }
Example #5
0
 /**
  * This method exists because the service container needs to be set before
  * the page's functionality gets loaded.
  */
 public function initialize()
 {
     // because some cronjobs will be run on the command line we should pass parameters
     if (isset($_SERVER['argv'])) {
         // init var
         $first = true;
         // loop all passes arguments
         foreach ($_SERVER['argv'] as $parameter) {
             // ignore first, because this is the scripts name.
             if ($first) {
                 // reset
                 $first = false;
                 // skip
                 continue;
             }
             // split into chunks
             $chunks = explode('=', $parameter, 2);
             // valid parameters?
             if (count($chunks) == 2) {
                 // build key and value
                 $key = trim($chunks[0], '--');
                 $value = $chunks[1];
                 // set in GET
                 if ($key != '' && $value != '') {
                     $_GET[$key] = $value;
                 }
             }
         }
     }
     // define the Named Application
     if (!defined('NAMED_APPLICATION')) {
         define('NAMED_APPLICATION', 'Backend');
     }
     // set the module
     $this->setModule(\SpoonFilter::toCamelCase(\SpoonFilter::getGetValue('module', null, '')));
     // set the requested file
     $this->setAction(\SpoonFilter::toCamelCase(\SpoonFilter::getGetValue('action', null, '')));
     // set the language
     $this->setLanguage(\SpoonFilter::getGetValue('language', FrontendLanguage::getActiveLanguages(), SITE_DEFAULT_LANGUAGE));
     // mark cronjob as run
     $cronjobs = (array) $this->get('fork.settings')->get('Core', 'cronjobs');
     $cronjobs[] = $this->getModule() . '.' . $this->getAction();
     $this->get('fork.settings')->set('Core', 'cronjobs', array_unique($cronjobs));
     $this->execute();
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 protected function getPossibleLanguages()
 {
     return array_flip(Language::getActiveLanguages());
 }