public function autoroute() { $request = new Request(); if ($request->hasPost('polyglot_ajax_action')) { return $this->ajaxController($request->post('polyglot_ajax_action')); } if ($request->hasGet('polyglot_action')) { return $this->adminController($request->get('polyglot_action')); } return $this->adminController("index"); }
/** * Triggered in the backend to learn the locale based on the type * of object the user is browsing. Prevents a user from seeing * a object in another locale than the one the object is supposed to be in. * @return \Strata\i18n\Locale */ public function getByAdminContext() { $request = new Request(); if ($request->hasGet("post") && !is_array($request->get("post"))) { // trashing posts will generate an array return $this->getLocaleByPostId($request->get("post")); } if (!Router::isAjax() && $request->isPost() && $request->hasPost("post_ID")) { return $this->getLocaleByPostId($request->post("post_ID")); } if ($request->hasGet("taxonomy") && $request->hasGet("tag_ID")) { return $this->getLocaleByTaxonomyId($request->get("tag_ID"), $request->get("taxonomy")); } if ($request->hasGet("taxonomy") && !$request->hasGet("locale")) { return Strata::i18n()->getDefaultLocale(); } if ($request->hasGet("post_type") && !$request->hasGet("locale")) { return Strata::i18n()->getDefaultLocale(); } }
/** * Sets the current locale based on either a GET parameter or the Locale URL prefix. * If none is found it will return the default locale. * @return Locale * @filter strata_i18n_set_current_locale_by_context */ public function setCurrentLocaleByContext() { if (function_exists('apply_filters')) { // Give a chance for plugins to override this decision $locale = null; $locale = apply_filters('strata_i18n_set_current_locale_by_context', $locale); if (!is_null($locale)) { return $this->setLocale($locale); } } if (!is_null($this->currentLocale)) { return $this->currentLocale; } $request = new Request(); // Under ajax, one could post the value. if (Router::isAjax() && $request->hasPost("locale")) { $locale = $this->getLocaleByCode($request->post("locale")); if (!is_null($locale)) { return $this->setLocale($locale); } } if ($request->hasGet("locale")) { $locale = $this->getLocaleByCode($request->get("locale")); if (!is_null($locale)) { return $this->setLocale($locale); } } $inAdmin = function_exists('is_admin') ? is_admin() : false; if (!$inAdmin) { // This validates all locales but the default one $urls = implode('|', $this->getLocaleRegexUrls()); if (array_key_exists('REQUEST_URI', (array) $_SERVER)) { if (preg_match('/^\\/(' . $urls . ')\\//i', $_SERVER['REQUEST_URI'], $match)) { $locale = $this->getLocaleByUrl($match[1]); if (!is_null($locale)) { return $this->setLocale($locale); } // Also validates for lack of locale code, meaning // a possible default locale match when no ajax-ing. } elseif (preg_match('/^(?:(?!' . $urls . '))\\/?/i', $_SERVER['REQUEST_URI'])) { $locale = $this->getDefaultLocale(); if (!is_null($locale)) { return $this->setLocale($locale); } } } } if ($this->hasLocaleInSession()) { $locale = $this->getLocaleInSession(); if (!is_null($locale)) { return $this->setLocale($locale); } } if ($this->hasDefaultLocale()) { return $this->setLocale($this->getDefaultLocale()); } }