/** * 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; }
public function onFilter_DropdownPages($output, $r, $pages) { if (!StrataRouter::isFrontendAjax()) { $currentLocale = Strata::i18n()->getCurrentLocale(); if ($currentLocale->isDefault()) { $selectAsArray = explode("\n", $output); foreach ($pages as $idx => $page) { $translation = $currentLocale->getTranslatedPost($page->ID); if (is_null($translation) || (int) $translation->ID !== (int) $page->ID) { $output = preg_replace('/<option.+?value="' . $page->ID . '".+?<\\/option>/', '', $output); } } return $output; } return __("Parent page is determined by the default locale.", "polyglot"); } return $output; }
/** * 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(); } }
/** * Wordpress callback that attemps to register additional * administration links in Wordpress's backend based on the * attached model. */ public function action_addAdminMenus() { // Default to the model's likely controller. $defaultController = Controller::generateClassName($this->model->getShortName()); $parentSlug = 'edit.php?post_type=' . $this->model->getWordpressKey(); foreach ($this->getConfiguration() as $func => $config) { $config += array('title' => ucfirst($func), 'menu-title' => ucfirst($func), 'capability' => "manage_options", 'icon' => null, 'route' => array($defaultController, $func), 'position' => null); // This is to circumvent how Wordpress doesn't let you pass arguments to // callbacks so we can send the controller and function to the router. // We dont want people to have to specify that odd function name. // Allow them to send the controller string name and take care of the rest. if (is_string($config['route'])) { $route = Router::callback($config['route'], $func); } else { $route = Router::callback($config['route'][0], $config['route'][1]); } $uniquePage = $this->model->getWordpressKey() . "_" . $func; add_submenu_page($parentSlug, $config['title'], $config['menu-title'], $config['capability'], $uniquePage, $route, $config['icon'], $config['position']); } }
/** * @expectedException Exception */ public function testInvalidCallbackDestination() { $invalidCallback = Router::callback("InvalidController", "invalid"); call_user_func($invalidCallback); }
/** * 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); }
/** * Returns the localization key in the session array. * @return string */ private function getSessionKey() { if (is_admin() && !Router::isFrontendAjax()) { return self::DOMAIN . "_admin"; } return self::DOMAIN . "_front"; }
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; }
/** * {@inheritdoc} */ public function run($url = null) { $this->route->arguments = func_get_args(); return parent::run(); }
/** * Configures the default router object. */ protected function setupUrlRouting() { $rewriter = new Rewriter(); $rewriter->initialize(); $router = Router::urlRouting(); $this->setConfig("runtime.rewriter_reference", $rewriter); $this->setConfig("runtime.router_reference", $router); }
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; } }