/** * Initializes the URI object based on the url set on the object */ public function init() { $grav = Grav::instance(); $config = $grav['config']; $language = $grav['language']; // resets $this->paths = []; $this->params = []; $this->query = []; // get any params and remove them $uri = str_replace($this->root, '', $this->url); // process params $uri = $this->processParams($uri, $config->get('system.param_sep')); // set active language $uri = $language->setActiveFromUri($uri); // redirect to language specific homepage if configured to do so if ($uri == '/' && $language->enabled()) { if ($config->get('system.languages.home_redirect.include_route', true)) { $prefix = $config->get('system.languages.home_redirect.include_lang', true) ? $language->getLanguage() . '/' : ''; $grav->redirect($prefix . Pages::getHomeRoute()); } elseif ($config->get('system.languages.home_redirect.include_lang', true)) { $grav->redirect($language->getLanguage() . '/'); } } // split the URL and params $bits = parse_url($uri); // process query string if (isset($bits['query'])) { parse_str($bits['query'], $this->query); $uri = $bits['path']; } // remove the extension if there is one set $parts = pathinfo($uri); // set the original basename $this->basename = $parts['basename']; $valid_page_types = implode('|', $config->get('system.pages.types')); if (preg_match("/\\.(" . $valid_page_types . ")\$/", $parts['basename'])) { $uri = rtrim(str_replace(DIRECTORY_SEPARATOR, DS, $parts['dirname']), DS) . '/' . $parts['filename']; $this->extension = $parts['extension']; } // set the new url $this->url = $this->root . $uri; $this->path = $uri; $this->content_path = trim(str_replace($this->base, '', $this->path), '/'); if ($this->content_path != '') { $this->paths = explode('/', $this->content_path); } }
/** * Initializes the URI object based on the url set on the object */ public function init() { $grav = Grav::instance(); $config = $grav['config']; $language = $grav['language']; // resets $this->paths = []; $this->params = []; $this->query = []; // get any params and remove them $uri = str_replace($this->root, '', $this->url); // remove the setup.php based base if set: $setup_base = $grav['pages']->base(); if ($setup_base) { $uri = str_replace($setup_base, '', $uri); } // If configured to, redirect trailing slash URI's with a 301 redirect if ($config->get('system.pages.redirect_trailing_slash', false) && $uri != '/' && Utils::endsWith($uri, '/')) { $grav->redirect(rtrim($uri, '/'), 301); } // process params $uri = $this->processParams($uri, $config->get('system.param_sep')); // set active language $uri = $language->setActiveFromUri($uri); // redirect to language specific homepage if configured to do so if ($uri == '/' && $language->enabled()) { if ($config->get('system.languages.home_redirect.include_route', true)) { $prefix = $config->get('system.languages.home_redirect.include_lang', true) ? $language->getLanguage() . '/' : ''; $grav->redirect($prefix . Pages::getHomeRoute()); } elseif ($config->get('system.languages.home_redirect.include_lang', true)) { $grav->redirect($language->getLanguage() . '/'); } } // split the URL and params $bits = parse_url($uri); // process query string if (isset($bits['query'])) { $this->query = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); $uri = $bits['path']; } // remove the extension if there is one set $parts = pathinfo($uri); // set the original basename $this->basename = $parts['basename']; $valid_page_types = implode('|', $config->get('system.pages.types')); if (preg_match("/\\.(" . $valid_page_types . ")\$/", $parts['basename'])) { $uri = rtrim(str_replace(DIRECTORY_SEPARATOR, DS, $parts['dirname']), DS) . '/' . $parts['filename']; $this->extension = $parts['extension']; } // set the new url $this->url = $this->root . $uri; $this->path = $uri; $this->content_path = trim(str_replace($this->base, '', $this->path), '/'); if ($this->content_path != '') { $this->paths = explode('/', $this->content_path); } }