/** * Redirects an action */ public function redirect() { if ($this->redirect) { $this->grav->redirect($this->redirect, $this->redirectCode); } else { if ($redirect = $this->grav['config']->get('plugins.login.redirect')) { $this->grav->redirect($redirect, $this->redirectCode); } } }
/** * Dispatch URI to a page. * * @param $url * @param bool $all * @return Page|null */ public function dispatch($url, $all = false) { // Fetch page if there's a defined route to it. $page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null; // If the page cannot be reached, look into site wide redirects, routes + wildcards if (!$all && (!$page || !$page->routable())) { /** @var Config $config */ $config = $this->grav['config']; // Try redirects $redirect = $config->get("site.redirects.{$url}"); if ($redirect) { $this->grav->redirect($redirect); } // See if route matches one in the site configuration $route = $config->get("site.routes.{$url}"); if ($route) { $page = $this->dispatch($route, $all); } else { // Try looking for wildcards foreach ($config->get("site.routes") as $alias => $route) { $match = rtrim($alias, '*'); if (strpos($alias, '*') !== false && strpos($url, $match) !== false) { $wildcard_url = str_replace('*', str_replace($match, '', $url), $route); $page = isset($this->routes[$wildcard_url]) ? $this->get($this->routes[$wildcard_url]) : null; if ($page) { return $page; } } } } } return $page; }
/** * Redirect to the route stored in $this->redirect */ public function redirect() { if (!$this->redirect) { return; } $base = $this->admin->base; $this->redirect = '/' . ltrim($this->redirect, '/'); $multilang = $this->isMultilang(); $redirect = ''; if ($multilang) { // if base path does not already contain the lang code, add it $langPrefix = '/' . $this->grav['session']->admin_lang; if (!Utils::startsWith($base, $langPrefix . '/')) { $base = $langPrefix . $base; } // now the first 4 chars of base contain the lang code. // if redirect path already contains the lang code, and is != than the base lang code, then use redirect path as-is if (Utils::pathPrefixedByLangCode($base) && Utils::pathPrefixedByLangCode($this->redirect) && substr($base, 0, 4) != substr($this->redirect, 0, 4)) { $redirect = $this->redirect; } else { if (!Utils::startsWith($this->redirect, $base)) { $this->redirect = $base . $this->redirect; } } } else { if (!Utils::startsWith($this->redirect, $base)) { $this->redirect = $base . $this->redirect; } } if (!$redirect) { $redirect = $this->redirect; } $this->grav->redirect($redirect, $this->redirectCode); }
/** * Redirect to the route stored in $this->redirect */ public function redirect() { if (!$this->redirect) { return; } $base = $this->admin->base; $path = trim(substr($this->redirect, 0, strlen($base)) == $base ? substr($this->redirect, strlen($base)) : $this->redirect, '/'); $this->grav->redirect($base . '/' . preg_replace('|/+|', '/', $path), $this->redirectCode); }
/** * Redirects an action */ public function redirect() { $redirect = $this->grav['config']->get('plugins.newsletter.admin.subscriber.enable.redirect'); if (!$redirect) { $this->grav->redirect($redirect, $this->redirectCode); } else { if ($this->redirect) { $this->grav->redirect($this->redirect, $this->redirectCode); } } }
/** * Dispatch URI to a page. * * @param $url * @param bool $all * @return Page|null */ public function dispatch($url, $all = false) { // Fetch page if there's a defined route to it. $page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null; // If the page cannot be reached, look into site wide redirects, routes + wildcards if (!$all && (!$page || !$page->routable())) { /** @var Config $config */ $config = $this->grav['config']; // See if route matches one in the site configuration $route = $config->get("site.routes.{$url}"); if ($route) { $page = $this->dispatch($route, $all); } else { // Try Regex style redirects foreach ((array) $config->get("site.redirects") as $pattern => $replace) { $pattern = '#' . $pattern . '#'; try { $found = preg_replace($pattern, $replace, $url); if ($found != $url) { $this->grav->redirect($found); } } catch (ErrorException $e) { $this->grav['log']->error('site.redirects: ' . $pattern . '-> ' . $e->getMessage()); } } // Try Regex style routes foreach ((array) $config->get("site.routes") as $pattern => $replace) { $pattern = '#' . $pattern . '#'; try { $found = preg_replace($pattern, $replace, $url); if ($found != $url) { $page = $this->dispatch($found, $all); } } catch (ErrorException $e) { $this->grav['log']->error('site.routes: ' . $pattern . '-> ' . $e->getMessage()); } } } } return $page; }
/** * Redirects an action */ public function redirect() { if ($this->redirect) { $this->grav->redirect($this->redirect, $this->redirectCode); } }