/** * Registers the Wordpress action required to * handle the routing at the correct timing. */ protected function registerWordpressAction() { if (function_exists('add_action')) { if (Router::isAjax() || is_admin()) { add_action('init', array($this, "onWordpressEarlyInit")); } else { add_action('wp', array($this, "onWordpressInit"), 10); } } $this->registered = true; }
/** * 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(); } }
/** * Returns the list of default view configuration values. * @return array */ protected function getDefaultConfiguration() { return array("Content-type" => "text/html", "Content-disposition" => null, "content" => "", "end" => is_admin() && !Router::isAjax() ? false : true, "allow_debug" => true, "layout" => null); }
/** * 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()); } }
private function canCatchTheError($triggerFilePath = '') { if (function_exists("is_admin") && is_admin()) { if (!class_exists("\\Strata\\Router\\Router")) { return false; } if (!Router::isAjax()) { return false; } } if (strstr($triggerFilePath, Strata::getPluginsPath()) || strstr($triggerFilePath, Strata::getWordpressPath())) { return false; } if (!function_exists('get_template_directory')) { return false; } return true; }
public function enforceLocale($locale = null) { // The current locale gets lost in metabox queries. // in the admin if (is_null($locale) && is_admin() && !Router::isAjax()) { $context = new ContextualManager(); $locale = $context->getByAdminContext(); } if (!is_null($locale)) { $this->currentLocale = $locale; } }