/components/com_router/router.php
PHP | 1032 lines | 638 code | 194 blank | 200 comment | 159 complexity | 7287067c2065e35268827858cfa6a18d MD5 | raw file
- <?php
- /**
- * User: Oli Griffiths
- * Date: 14/10/2012
- * Time: 11:50
- */
- class ComRouterRouter extends ComApplicationRouter implements KServiceInstantiatable
- {
- /**
- * Holds the registry object
- * @var ComRouterRegistry
- */
- protected $_registry;
- protected $_cache;
- protected $_cache_identifier = 'koowa-route-cache';
- protected $_sef_suffix;
- protected $_sef_rewrite;
- protected $_build_modes = array();
- protected $_parse_modes = array();
- /**
- * Force creation of a singleton
- *
- * @param object An optional KConfig object with configuration options
- * @param object A KServiceInterface object
- * @return KDispatcherDefault
- */
- public static function getInstance( KConfigInterface $config, KServiceInterface $container )
- {
- // Check if an instance with this identifier already exists or not
- if (!$container->has($config->service_identifier)) {
- //Create the singleton
- $classname = $config->service_identifier->classname;
- $instance = new $classname($config);
- $container->set($config->service_identifier, $instance);
- }
- return $container->get($config->service_identifier);
- }
- /**
- * Object constructor
- * @param KConfig $config
- */
- public function __construct( KConfig $config = null )
- {
- parent::__construct($config);
- $this->_registry = $config->registry;
- $this->_cache = $config->cache;
- $this->_build_modes = $config->build_modes;
- $this->_parse_modes = $config->parse_modes;
- $this->_sef_suffix = $config->sef_suffix;
- $this->_sef_rewrite = $config->sef_rewrite;
- }
- /**
- * Initializes the config
- * @param KConfig $config
- */
- protected function _initialize( KConfig $config )
- {
- $config->append(
- array(
- 'cache' => false,
- 'build_modes' => array(
- 'db' => true,
- 'registry' => true,
- 'component' => true,
- 'page' => true
- ),
- 'parse_modes' => array(
- 'db' => true,
- 'registry' => true,
- 'component' => true,
- 'page' => true
- ),
- 'sef_suffix' => false,
- 'sef_rewrite' => true,
- 'registry_auto_load' => true,
- 'registry_auto_create' => true
- )
- )->append(
- array(
- 'registry' => $this->getService(
- 'com://site/router.registry', array(
- 'auto_load' => $config->registry_auto_load,
- 'auto_create' => $config->registry_auto_create
- )
- )
- )
- );
- parent::_initialize($config);
- }
- /**
- * Returns the registry object
- * @return ComRouterRegistry
- */
- public function getRegistry()
- {
- return $this->_registry;
- }
- /**
- * Cleans the APC cache
- * @param bool $mode - one of, build, parse, template
- * @param null $option
- * @param null $view
- */
- public function clearCache( $mode = 0, $option = null, $view = null )
- {
- if (extension_loaded('apc')) {
- if ($items = apc_cache_info('user')) {
- $query = $this->_cache_identifier . '-' . ($mode ? $mode . '-' . http_build_query(array('option' => $option, 'view' => $view)) : '');
- $length = strlen($query);
- foreach ($items['cache_list'] AS $item) {
- if (substr($item['info'], 0, $length) == $query) {
- apc_delete($item['info']);
- }
- }
- }
- }
- }
- /**
- * Parse attempts to match url against a pre-defined route
- * @param $url
- * @return bool|KHttpUrl
- */
- public function parse( KHttpUrl $url )
- {
- // Get the path
- $path = is_array($url->path) ? implode('/', array_filter($url->path)) : $url->path;
- //Remove base path
- $path = substr_replace($path, '', 0, strlen(KRequest::root()->getUrl(KHttpUrl::PATH)));
- // Set the format
- if (!empty($url->format)) {
- $url->query['format'] = $url->format;
- }
- //Remove the filename
- if (!$this->_sef_rewrite) {
- $path = preg_replace('#^index\.php#', '', $path);
- }
- //Set the route
- $url->path = trim($path, '/');
- $path = $url->getUrl(KHttpUrl::PATH + KHttpUrl::FORMAT);
- return ($path == 'index.php' || empty($path)) && isset($url->query['option']) ? false : $this->_parseRoute($url);
- }
- /**
- * Parses a route through 5 separate parsing methods in the following order
- * 1. APC cache - all parsed urls are stored in the cache
- * 2. DB routes - checks the DB for a matching route
- * 3. Registry - checks the route against the registered route templates
- * 4. Page - attempts to match the route against a page/menu item
- * 5. View - if page matching was successful, attempt to load component router
- * @param KHttpUrl $url
- * @return bool
- */
- protected function _parseRoute( KHttpUrl $url )
- {
- if ($this->_parseCacheRoute($url)) {
- return true;
- }
- $route = clone $url;
- $this->_parseSiteRoute($url);
- if (!$result = $this->_parseDbRoute($url)) {
- if (!$result = $this->_parseRegistryRoute($url)) {
- if ($result = $this->_parsePageRoute($url)) {
- $result = $this->_parseComponentRoute($url);
- }
- }
- }
- //Cache result
- if ($result) {
- //Find itemid
- if (!isset($url->query['Itemid'])) {
- $itemid = $this->findPageId($url->query);
- if ($itemid) {
- $url->query['Itemid'] = $itemid;
- }
- }
- //Set active page
- if (isset($url->query['Itemid'])) {
- $pages = $this->getService('application.pages');
- $pages->setActive($url->query['Itemid']);
- }
- $url->path = 'index';
- $url->format = 'php';
- $this->_storeRouteToCache($route, $url->query, 1);
- }
- return $result;
- }
- /**
- * Parses a route against the APC cache.
- * @param KHttpUrl $url
- * @return bool
- */
- protected function _parseCacheRoute( KHttpUrl $url )
- {
- if (extension_loaded('apc') && $this->_cache) {
- $route = $url->getUrl(KHttpUrl::PATH + KHttpUrl::FORMAT);
- if ($query = apc_fetch($this->_cache_identifier . '-parse-' . $route)) {
- if (!isset($query['format'])) {
- $query['format'] = $url->format ? $url->format : 'html';
- }
- $url->query = $query;
- $url->path = 'index';
- $url->format = 'php';
- return true;
- }
- }
- return false;
- }
- /**
- * Attempts to match a route that's been cached in the DB
- * @param KHttpUrl $url
- * @return bool
- */
- protected function _parseDbRoute( KHttpUrl $url )
- {
- if (!$this->_parse_modes->db) {
- return false;
- }
- $model = $this->getService('com://site/router.model.routes');
- if (!$model->getTable()) {
- return false;
- }
- $path = $url->getUrl(KHttpUrl::PATH);
- $item = $model->set('url', $path)->getItem();
- //If item was not found,
- if ($item->isNew()) {
- $alias = $this->getService('com://site/router.model.aliases')->set('url', $path)->getItem();
- if ($alias && !$alias->isNew()) {
- $item = $model->set('url', $alias->target)->getItem();
- }
- }
- //Parse & set matching route
- if (!$item->isNew()) {
- parse_str($item->route, $query);
- $url->query = array_merge($query, $url->query);
- if ($item->itemid && !isset($url->query['Itemid'])) {
- $url->query['Itemid'] = $item->itemid;
- }
- return true;
- }
- return false;
- }
- /**
- * Attempts to match the route against any registered routes in the registry
- * @param KHttpUrl $url
- * @return bool
- */
- protected function _parseRegistryRoute( KHttpUrl $url )
- {
- if (!$this->_parse_modes->registry) {
- return false;
- }
- //Check if a static route is defined for this url
- if ($parsed_url = $this->_registry->parse($url)) {
- if (isset($parsed_url->query['option'])) {
- $url->query = $url->query + $parsed_url->query;
- $url->path = $parsed_url->path;
- $url->format = $parsed_url->format;
- return true;
- }
- }
- return false;
- }
- /**
- * @param KHttpUrl $url
- * @return bool
- */
- protected function _parsePageRoute( KHttpUrl $url )
- {
- if (!$this->_parse_modes->page) {
- return false;
- }
- $route = $url->getUrl(KHttpUrl::PATH);
- $pages = $this->getService('application.pages');
- $result = false;
- if (substr($route, 0, 9) != 'component') {
- //Need to reverse the array (highest sublevels first)
- foreach (array_reverse($pages->id) as $id) {
- $page = $pages->getPage($id);
- $length = strlen($page->route);
- if ($length > 0 && strpos($route . '/', $page->route . '/') === 0 && $page->type != 'pagelink') {
- $route = substr($route, $length);
- if ($page->type != 'redirect') {
- $url->query += $page->link->query;
- $url->query['Itemid'] = $page->id;
- }
- $pages->setActive($page->id);
- $result = true;
- break;
- }
- }
- } else {
- $segments = explode('/', $route);
- $route = str_replace('component/' . $segments[1], '', $route);
- if (!isset($url->query['Itemid'])) {
- $url->query['Itemid'] = $pages->getHome()->id;
- }
- $url->query['option'] = 'com_' . $segments[1];
- $result = true;
- }
- $url->path = ltrim($route, '/');
- return $result;
- }
- /**
- * Passes the URL parsing to the relevant component
- * @param KHttpUrl $url
- * @return bool
- */
- protected function _parseComponentRoute( KHttpUrl $url )
- {
- if (!$this->_parse_modes->component) {
- return false;
- }
- $route = $url->path;
- if (isset($url->query['option'])) {
- if (!empty($route)) {
- try {
- //Get the router identifier
- $identifier = 'com://site/' . substr($url->query['option'], 4) . '.router';
- //Parse the view route
- $vars = KService::get($identifier)->parseRoute($route);
- //Merge default and vars
- $url->query = array_merge($url->query, $vars);
- return true;
- } catch ( KException $e ) {
- return false;
- }
- }
- }
- return true;
- }
- /**
- * Primary build method, routes are build according to 5 build methods.
- * 1. APC cache - all built urls are stored in the cache
- * 2. DB routes - checks the DB for an exact matching route
- * 3. Registry - checks the route against the registered route templates and attempts to build
- * 4. Component - if page matching was successful, attempt to load component router
- * 5. Page - attempts to match the route against a page/menu item
- * @param $url | KHttpUrl
- * @return bool - true/false if the route was built
- */
- public function build( KHttpUrl $url )
- {
- $result = false;
- if ($url->getUrl(KHttpUrl::PATH + KHttpUrl::FORMAT) == 'index.php') {
- static $site;
- $cached = false;
- $query = $url->query;
- if (!isset($site)) {
- $site = $this->_buildSiteRoute($url);
- }
- //Check cache for route first, then build if no match
- if (false !== $result = $this->_buildCacheRoute($url)) {
- $cached = true;
- } else {
- $result = $this->_buildRoute($url);
- }
- if ($result) {
- // Get the path data
- $path = $url->path;
- //Cache route
- if (!$cached) {
- $this->_storeRouteToCache($url, $query);
- }
- //Add site to route
- if (count($site)) {
- $path = array_merge($site, $url->path);
- }
- //Add root path
- if ($root = ltrim(KRequest::root()->getUrl(KHttpUrl::PATH), '/')) {
- array_unshift($path, $root);
- }
- //Ensure all routes start with /
- array_unshift($path, '');
- //Set path
- $url->path = $path;
- } else {
- if (!$cached) {
- //Cache failed route
- $this->_storeRouteToCache(null, $query);
- }
- }
- }
- return $result ? $url : false;
- }
- /**
- * Builds the route from an internal querystring route
- * @param KHttpUrl $url
- * @return bool
- */
- protected function _buildRoute( KHttpUrl $url )
- {
- $query = $url->query;
- $cache = false;
- //Attempt to set the url from pages if no option set
- if (!isset($url->query['option']) && isset($url->query['Itemid'])) {
- if ($page = $this->getService('application.pages')->getPage($url->query['Itemid'])) {
- $url->path = $page->link->path;
- $url->query = $page->link->query;
- $url->format = $page->link->format;
- }
- }
- //Build
- if (false === $segments = $this->_buildDbRoute($url)) {
- if (false === $segments = $this->_buildRegistryRoute($url)) {
- if (false !== $route = $this->_buildComponentRoute($url)) {
- $page = $route['page'] ? $this->_buildPageRoute($url, $query) : array();
- $segments = array_merge($page, $route['segments']);
- $cache = $route['cache'];
- } else {
- if ($route = $this->_buildPageRoute($url, $query)) {
- $segments = $route;
- }
- }
- }
- }
- $result = false;
- if ($segments !== false) {
- //Remove empty values
- $segments = array_filter($segments);
- //Format values
- array_walk($segments, array($this, '_encodeSegments'));
- //Set the path
- $url->path = $segments;
- //Remove Itemid if there is a DB override or it matches the id found from pages
- //also ensure the itemid hasnt been set by any router methods
- if (isset($url->query['Itemid']) && isset($query['Itemid']) && $url->query['Itemid'] == $query['Itemid']) {
- unset($query['Itemid']);
- if ($itemid = $this->findPageIdOverride($query)) {
- unset($url->query['Itemid']);
- } else {
- if ($url->query['Itemid'] == $this->findPageId($query)) {
- unset($url->query['Itemid']);
- }
- }
- }
- // Removed unused query variables
- unset($url->query['option']);
- //Add the format to the uri
- $format = isset($url->query['format']) ? $url->query['format'] : ($url->format == 'php' ? 'html' : $url->format);
- if ($this->_sef_suffix) {
- unset($url->query['format']);
- } else {
- if ($format == 'html') {
- unset($url->query['format']);
- $format = null;
- }
- }
- //Remove default layout
- if (isset($url->query['layout']) && $url->query['layout'] == 'default') {
- unset($url->query['layout']);
- }
- //Clear format for empty paths
- if (empty($url->path)) {
- $format = '';
- }
- //Transform the route
- if (!$this->_sef_rewrite) {
- $url->path = array_merge(array('index.php'), $url->path);
- $format = null;
- }
- $url->format = $format;
- $result = true;
- if ($cache && !empty($url->path)) {
- $this->_storeRouteToDb($url, $query);
- }
- }
- return $result;
- }
- /**
- * Builds a route from the APC cache if found
- * @param KHttpUrl $url
- * @return bool|mixed
- */
- protected function _buildCacheRoute( KHttpUrl $url )
- {
- if (extension_loaded('apc') && $this->_cache) {
- $query = $url->query;
- //Ensure option and query come first, required for clean cache
- $q = array();
- if (isset($query['option'])) {
- $q['option'] = $query['option'];
- unset($query['option']);
- }
- if (isset($query['view'])) {
- $q['view'] = $query['view'];
- unset($query['option']);
- }
- ksort($query);
- $query = http_build_query(array_merge($q, $query));
- if ($route = apc_fetch($this->_cache_identifier . '-build-' . $query)) {
- $url->query = array();
- $url->setUrl($route);
- return true;
- } else {
- return $route;
- }
- }
- return false;
- }
- /**
- * Builds a route from the DB table (router_routes)
- * @param KHttpUrl $url
- * @return mixed
- */
- protected function _buildDbRoute( KHttpUrl $url )
- {
- static $routes = array();
- if (!$this->_build_modes->db) {
- return false;
- }
- $query = $url->query;
- //Ensure option and query come first, required for clean cache
- $q = array();
- if (isset($query['option'])) {
- $q['option'] = $query['option'];
- unset($query['option']);
- }
- if (isset($query['view'])) {
- $q['view'] = $query['view'];
- unset($query['option']);
- }
- unset($query['Itemid']);
- ksort($query);
- $query = array_merge($q, $query);
- $querystring = http_build_query($query);
- if (!isset($routes[$querystring])) {
- $routes[$querystring] = false;
- if ($route = $this->getService('com://site/router.model.routes')->set('route', $querystring)->getItem()) {
- if (!$route->isNew()) {
- $tmp = $this->getService('koowa:http.url', array('url' => ltrim($route->url, '/')));
- $tmp->setPath($tmp->path); //forces path into an array
- $tmp->setQuery($route->route);
- if ($route->itemid) {
- $tmp->query['Itemid'] = $route->itemid;
- }
- $routes[$querystring] = $tmp;
- }
- }
- }
- if ($routes[$querystring]) {
- $route = $routes[$querystring];
- //Remove the querystring parts from the route
- $url->query = array_diff_key($url->query, $route->query);
- return $route->path;
- }
- return $routes[$querystring];
- }
- /**
- * Attempts to build a route from a connected route in the registry
- * @param KHttpUrl $url
- * @return mixed
- */
- protected function _buildRegistryRoute( KHttpUrl $url )
- {
- if (!$this->_build_modes->registry) {
- return false;
- }
- $route = $this->_registry->match($url);
- return $route ? $url->path : false;
- }
- /**
- * Builds a route using a components router.
- * If the router has a cache property that is set to true, this will cause the router to store the rout to the DB
- * @param KHttpUrl $url
- * @return array|bool
- */
- protected function _buildComponentRoute( KHttpUrl $url )
- {
- if (!$this->_build_modes->component) {
- return false;
- }
- // Use the custom routing handler if it exists
- if (isset($url->query['option'])) {
- //Get the router identifier
- $identifier = 'com://site/' . substr($url->query['option'], 4) . '.router';
- try {
- //Build the view route
- $router = KService::get($identifier, array('router' => $this));
- if (false !== $segments = $router->buildRoute($url->query, $url)) {
- return array(
- 'segments' => $segments,
- 'cache' => isset($router->cache) ? $router->cache : false,
- 'page' => isset($router->page) ? $router->page : true
- );
- }
- } catch ( KException $e ) {
- }
- }
- return false;
- }
- /**
- * Builds a route based on pages
- * @param KHttpUrl $url
- * @return array
- */
- protected function _buildPageRoute( KHttpUrl $url, &$query )
- {
- if (!$this->_build_modes->page) {
- return false;
- }
- $segments = '';
- if (!isset($url->query['Itemid'])) {
- //Find itemid and set
- if ($itemid = $this->findPageId($query)) {
- $url->query['Itemid'] = $itemid;
- $query['Itemid'] = $itemid;
- }
- //If not set, default to active menu item
- if (!isset($url->query['Itemid'])) {
- $page = $this->getService('application.pages')->getActive();
- if ($page) {
- $url->query['Itemid'] = $page->id;
- }
- }
- }
- //Get page route
- if (isset($url->query['Itemid'])) {
- $page = $this->getService('application.pages')->getPage($url->query['Itemid']);
- //@TODO: JPathway is currently modifying the url stored in the page, we need to reset it here
- if (!isset($page->link->query['option']) && strpos($page->link_url, 'option=') !== false) {
- $page->link = $this->getService('koowa:http.url', array('url' => $page->link_url));
- }
- if ($page->link->query['option'] == $url->query['option']) {
- $segments = $page->route;
- // anonymous functions only work 5.3+
- if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
- // remove empty keys from $page->link->query which are not empty in $url->query
- // otherwise stuff gets fucked up, like pagination on search loses query parameter
- array_walk(
- $page->link->query, function ( $value, $key ) use ( $url, $page ) {
- if (empty($value) && !empty($url->query[$key])) {
- unset($page->link->query[$key]);
- }
- }
- );
- }
- $url->query = array_diff_key($url->query, $page->link->query);
- } else {
- $segments = 'component/' . substr($url->query['option'], 4);
- }
- } else {
- $segments = 'component/' . substr($url->query['option'], 4);
- }
- $segments = explode('/', $segments);
- return $segments;
- }
- /**
- * Stores a URL and query to the cache.
- * @param KHttpUrl|null $url
- * @param array $query
- * @param bool $mode - 0 = build storage, 1 = parse storage
- * @return bool
- */
- protected function _storeRouteToCache( $url, array $query, $mode = 0 )
- {
- if (extension_loaded('apc') && $this->_cache) {
- if ($mode == 1) {
- return apc_store($this->_cache_identifier . '-parse-' . $url->getUrl(KHttpUrl::PATH + KHttpUrl::FORMAT), $query);
- } else {
- //Ensure option and query come first, required for clean cache
- $q = array();
- if (isset($query['option'])) {
- $q['option'] = $query['option'];
- unset($query['option']);
- }
- if (isset($query['view'])) {
- $q['view'] = $query['view'];
- unset($query['option']);
- }
- ksort($query);
- $query = http_build_query(array_merge($q, $query));
- return apc_store($this->_cache_identifier . '-build-' . $query, $url instanceof KHttpUrl ? $url->getUrl(KHttpUrl::PATH + KHttpUrl::FORMAT + KHttpUrl::QUERY) : $url);
- }
- }
- return false;
- }
- /**
- * Stores a route in the DB
- * @param KHttpUrl $url
- * @param $query
- * @return bool
- */
- protected function _storeRouteToDb( KHttpUrl $url, $query )
- {
- $extras = array_diff_key($url->query, $query);
- $query = array_diff_key($query, $url->query);
- $query = array_merge($query, $extras);
- //Ensure option and query come first, required for clean cache
- $q = array();
- $itemid = null;
- if (isset($query['option'])) {
- $q['option'] = $query['option'];
- unset($query['option']);
- unset($url->query['option']);
- }
- if (isset($query['view'])) {
- $q['view'] = $query['view'];
- unset($query['option']);
- unset($url->query['option']);
- }
- if (isset($query['Itemid']) || isset($url->query['Itemid'])) {
- $itemid = isset($url->query['Itemid']) ? $url->query['Itemid'] : $query['Itemid'];
- unset($url->query['Itemid']);
- }
- unset($query['Itemid']);
- ksort($query);
- $query = array_merge($q, $query);
- $querystring = http_build_query($query);
- $route = $url->getUrl(KHttpUrl::PATH);
- $item = $this->getService('com://site/router.model.routes')->set('url', $route)->getItem();
- if ($item && $item->isNew()) {
- try {
- $this->getService('com://site/router.controller.route')->save(array('url' => $route, 'route' => $querystring, 'itemid' => $itemid));
- return true;
- } catch ( KException $e ) {
- }
- }
- return true;
- }
- /**
- * Finds the itemid for a component & view pair
- * First looking in the DB table
- * @param $component
- * @param $view
- * @return mixed
- */
- public function findPageId( $query )
- {
- static $ids = array();
- $querystring = http_build_query($query);
- if (!isset($ids[$querystring])) {
- if ($id = $this->findPageIdOverride($query)) {
- $ids[$querystring] = $id;
- } else {
- $page = $this->findPage($query);
- $ids[$querystring] = $page ? $page->id : false;
- }
- }
- return $ids[$querystring];
- }
- /**
- * Finds the page for a component & view pair
- * @param $component
- * @param $view
- * @return mixed
- */
- public function findPage( $query )
- {
- static $ids = array();
- ksort($query);
- $querystring = http_build_query($query);
- if (!isset($ids[$querystring])) {
- $pages = $this->getService('application.pages');
- $view = isset($query['view']) ? $query['view'] : null;
- $itemid = isset($query['Itemid']) ? $query['Itemid'] : null;
- $match = null;
- $view_plural = KInflector::pluralize($view);
- if (!$match = $pages->find($itemid)) {
- //Need to reverse the array (highest sublevels first)
- foreach (array_reverse($pages->id) as $id) {
- $page = $pages->getPage($id);
- if (!$page->link) {
- $page->link = $this->getService('koowa:http.url', array('url' => $page->link_url));
- }
- if (count($page->link->query) && array_intersect_key($query, $page->link->query) == $page->link->query) {
- $match = $page;
- break;
- }
- }
- //Try plural views
- if (!$match && $view_plural != $view) {
- foreach (array_reverse($pages->id) as $id) {
- $page = $pages->getPage($id);
- $q = $query;
- $q['view'] = $view_plural;
- if (count($page->link->query) && array_intersect_key($q, $page->link->query) == $page->link->query) {
- $match = $page;
- break;
- }
- }
- }
- }
- $ids[$querystring] = $match;
- }
- return $ids[$querystring];
- }
- /**
- * Find an override Itemid. This can be set in the router_itemids table
- * If set, all routes that return an ID from this method have their Itemid removed on build/added on parse
- * @param $query
- * @return mixed
- */
- public function findPageIdOverride( $query )
- {
- static $ids = array();
- ksort($query);
- $option = isset($query['option']) ? $query['option'] : null;
- $view = isset($query['view']) ? $query['view'] : null;
- $querystring = http_build_query($query);
- if (!isset($ids[$querystring])) {
- $component = preg_replace('#^com_#', '', $option);
- $list = $this->getService('com://site/router.model.itemids')->set(
- array(
- 'component' => $component,
- 'view' => $view,
- 'sort' => 'view',
- 'direction' => 'DESC',
- 'limit' => 1
- )
- )->getList();
- if ($list) {
- $match = false;
- foreach ($list AS $item) {
- parse_str($item->params, $q);
- if (array_intersect_key($query, $q) == $q) {
- $match = $item;
- }
- }
- if (!$match && KInflector::isSingular($view)) {
- $query['view'] = KInflector::pluralize($view);
- if ($query['view'] != $view) {
- $ids[$querystring] = $this->findPageIdOverride($query);
- } else {
- $ids[$querystring] = false;
- }
- } else {
- $ids[$querystring] = $match ? $match->itemid : false;
- }
- } else {
- $ids[$querystring] = false;
- }
- }
- return $ids[$querystring];
- }
- protected function _encodeSegments( &$segment )
- {
- $segment = strtolower(rawurlencode(str_replace(' ', '-', $segment)));
- }
- }