Source code for file /joomla/application/router.php
Documentation is available at router.php
* @version $Id: pathway.php 6472 2007-02-03 10:47:26Z pasamio $
* @package Joomla.Framework
* @subpackage Application
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
// Check to ensure this file is within the rest of the framework
* @package Joomla.Framework
* @subpackage Application
* Translates an internal Joomla URL to a humanly readible URL.
* @param string $url Absolute or Relative URI to Joomla resource
* @param int $ssl Secure state for the resolved URI
* 1: Make URI secure using global secure site URI
* 0: Leave URI in the same secure state as it was passed to the function
* -1: Make URI unsecure using the global unsecure site URI
* @return The translated humanly readible URL
function _($url, $ssl =
0)
// If we are in the administrator application return
if($mainframe->isAdmin()) {
$router =
& $mainframe->getRouter();
$url =
$router->build($url);
* Get the secure/unsecure URLs.
* If the first 5 characters of the BASE are 'https', then we are on an ssl connection over
* https and need to set our secure URL to the current request URL, if not, and the scheme is
* 'http', then we need to do a quick string manipulation to switch schemes.
if ( substr( $base, 0, 5 ) ==
'https' )
$unsecure =
'http'.
substr( $base, 5 );
elseif ( substr( $base, 0, 4 ) ==
'http' )
$secure =
'https'.
substr( $base, 4 );
// Ensure that proper secure URL is used if ssl flag set secure
// Ensure that unsecure URL is used if ssl flag is set to unsecure
* Class to create and parse routes
* @package Joomla.Framework
* @subpackage Application
if(isset
($options['mode'])) {
$this->_mode =
$options['mode'];
* Returns a reference to the global Router object, only creating it
* if it doesn't already exist.
* This method must be invoked as:
* <pre> $router = &JRouter::getInstance();</pre>
* @return JRouter The Router object.
//Create the URI object based on the passed in URL
if($itemid =
$uri->getVar('Itemid'))
$menu->setActive($itemid);
$item =
$menu->getActive();
//Set request information
// Get the base and full URLs
$full =
$uri->toString( array('scheme', 'host', 'port', 'path'));
// Parse application route
* Function to convert an internal URI to a route
* @param string $string The internal URL
* @return string The absolute search engine friendly URL
global $mainframe, $Itemid, $option;
// Replace all & with & - ensures cache integrity
if (!isset
( $strings[$string] ))
// Decompose link into url component parts
// If the itemid isn't set in the URL use default
if(!$itemid =
$uri->getVar('Itemid')) {
$uri->setVar('Itemid', JRequest::getVar('Itemid', $menu->getDefault()));
// Get the active menu item
$item =
$menu->getItem($uri->getVar(('Itemid')));
// If the option isn't set in the URL use the itemid
if(!$option =
$uri->getVar('option')) {
$uri->setVar('option', $item->component);
$route =
''; //the route created
$query =
$uri->getQuery(true);
//Built application route
//Set query again in the URI
//Check if link contained fragment identifiers (ex. #foo)
if ($fragment =
$uri->getFragment())
// ensure fragment identifiers are compatible with HTML4
if (preg_match('@^[A-Za-z][A-Za-z0-9:_.-]*$@', $fragment)) {
$fragment =
'#'.
$fragment;
//Check if the component has left any query information unhandled
if($query =
$uri->getQuery()) {
$url =
$app_route.
$com_route.
$fragment.
$query;
//Prepend the base URI if we are not using mod_rewrite
$url =
'index.php/'.
$url;
$strings[$string] =
$url;
$strings[$string] =
$uri->toString();
* Parse a application specific route
if(substr($url, 0, 9) ==
'component')
$url =
str_replace('component/'.
$segments[1], '', $url);;
//Need to reverse the array (highest sublevels first)
foreach ($items as $item)
if(strpos($url, $item->route) ===
0)
$menu->setActive($itemid);
//Set request information
* Parse a component specific route
// Handle component route
// Use the component routing handler if it exists
$path =
JPATH_BASE.
DS.
'components'.
DS.
$component.
DS.
'router.php';
//decode the route segments
$function =
substr($component, 4).
'ParseRoute';
* Build the application specific route
$item =
$menu->getItem($query['Itemid']);
if($query['option'] ==
$item->component)
$route =
'component/'.
substr($query['option'], 4);
* Build the component specific route
$component =
$query['option'];
// Unset unneeded query information
// Use the component routing handler if it exists
$path =
JPATH_BASE.
DS.
'components'.
DS.
$component.
DS.
'router.php';
// Use the custom request handler if it exists
$function =
substr($component, 4).
'BuildRoute';
$parts =
$function($query);
if (isset
( $query['limitstart'] ))
$query['start'] = (int)
$query['limitstart'];
unset
($query['limitstart']);
//encode the route segments
$route =
($route) ?
'/'.
$route :
null;
$total =
count($segments);
for($i=
0; $i<
$total; $i++
) {
$total =
count($segments);
for($i=
0; $i<
$total; $i++
) {