public function parse(Library\HttpUrl $url) { $vars = array(); $path = trim($url->getPath(), '/'); //Remove base path $path = substr_replace($path, '', 0, strlen($this->getObject('request')->getBaseUrl()->getPath())); // Set the format if (!empty($url->format)) { $url->query['format'] = $url->format; } //Parse site route $url->query['site'] = $this->getObject('application')->getSite(); $path = str_replace($url->query['site'], '', $path); $path = ltrim($path, '/'); //Parse component route if (!empty($path)) { $segments = explode('/', $path); if (isset($segments[0])) { $vars['option'] = 'com_' . $segments[0]; if (isset($segments[1])) { $vars['view'] = $segments[1]; } else { $vars['view'] = $segments[0]; } } } $url->query = array_merge($url->query, $vars); $url->path = ''; return true; }
public function parse(Library\HttpUrl $url) { // Get the path $path = trim($url->getPath(), '/'); //Remove base path $path = substr_replace($path, '', 0, strlen($this->getObject('request')->getBaseUrl()->getPath())); // Set the format if (!empty($url->format)) { $url->query['format'] = $url->format; } //Set the route $url->path = trim($path, '/'); return $this->_parseRoute($url); }
public function parse(Library\HttpUrl $url) { $vars = array(); $path =& $url->path; $page = $this->getObject('application.pages')->getActive(); $query = $page->getLink()->query; if ($path[0] === 'file') { // file view $vars['view'] = array_shift($path); $vars['name'] = array_pop($path) . '.' . $url->getFormat(); $vars['folder'] = $query['folder'] ? $query['folder'] . '/' : ''; $vars['folder'] .= implode('/', $path); } else { // directory view $vars['view'] = 'directory'; $vars['layout'] = $query['layout']; $vars['folder'] = $query['folder'] . '/' . implode('/', $path); } $vars['folder'] = str_replace('%2E', '.', $vars['folder']); $vars['layout'] = $query['layout']; return $vars; }
public function build(Library\HttpUrl $url) { $query = $url->query; $segments = array(); //Build site route $site = $this->getObject('application')->getSite(); if ($site != 'default' && $site != $this->getObject('application')->getRequest()->getUrl()->toString(Library\HttpUrl::HOST)) { $segments[] = $site; } //Build language route $languages = $this->getObject('application.languages'); if (count($languages) > 1) { if (isset($query['language'])) { $language = $query['language']; unset($query['language']); } else { $language = $languages->getActive()->slug; } $segments[] = $language; } //Build component route if (isset($query['option'])) { $segments[] = substr($query['option'], 4); unset($query['option']); if (isset($query['view'])) { if ($query['view'] != $segments[0]) { $segments[] = $query['view']; } unset($query['view']); } } $url->query = $query; //Add the format to the uri if (isset($url->query['format'])) { $format = $url->query['format']; if ($format != 'html') { $url->format = $format; } unset($url->query['format']); } //Build the route $url->setPath($this->getObject('request')->getBaseUrl()->getPath() . '/' . implode('/', $segments)); // Removed unused query variables unset($url->query['Itemid']); unset($url->query['option']); return true; }
/** * Attempts to parse a request object and determine its execution details. * * @param object $request A Library\HttpUrl object * containing the details of the request to be routed. * @param array $options Used to determine the operation of the method, and override certain * values in the `Request` object: * - `'url'` _string_: If present, will be used to match in place of the `$url` * property of `$request`. * @return mixed If this route matches `$request`, returns an array of the execution details * contained in the route, otherwise returns false. */ public function parse(Library\HttpUrl $request, array $options = array()) { $defaults = array('url' => $request->toString(Library\HttpUrl::PATH)); $options += $defaults; $url = '/' . trim($options['url'], '/'); $pattern = $this->_pattern; //Run regex template match against url if (!preg_match($pattern, $url, $match)) { return false; } //The meta array contains additional request meta data in the KRequest format (eg, request.varname) //The value of this key must match those present in the relevant global variable foreach ($this->_meta as $key => $compare) { $value = $request->query->get($key, 'raw'); if (!($compare == $value || is_array($compare) && in_array($value, $compare))) { return false; } } $result = array_intersect_key($match, $this->_keys) + $this->_params + $this->_defaults; $request->path = array(); $request->query = (array) $request->query + $result; //Merge the request query into the result if ($this->_handler) { call_user_func_array($this->_handler, array($request)); } return $request->query; }