Source for file site.php
Documentation is available at site.php
 * @package     Joomla.Libraries  
 * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.  
 * @license     GNU General Public License version 2 or later; see LICENSE.txt  
 * Class to create and parse routes for the site application  
 * @package     Joomla.Libraries  
     * Function to convert a route to an internal URI  
     * @param   JUri  &$uri  The uri.  
    public function parse(&$uri)  
        if ($app->getCfg('force_ssl') == 
2 && 
strtolower($uri->getScheme()) != 
'https')  
            $uri->setScheme('https');  
            $app->redirect((string) 
$uri);  
        // Decode URL to convert punycode to unicode so that strings match when routing.  
        // Remove the base URI path.  
        // Check to see if a request to a specific entry point has been made.  
            // Get the current entry point path relative to the site path.  
            $scriptPath = 
realpath($_SERVER['SCRIPT_FILENAME'] ? 
$_SERVER['SCRIPT_FILENAME'] : 
str_replace('\\\\', '\\', $_SERVER['PATH_TRANSLATED']));  
            // If a php file has been found in the request path, check to see if it is a valid file.  
            // Also verify that it represents the same file from the server variable for entry script.  
                // Remove the entry point segments from the request path for proper routing.  
        if ($this->_mode == 
JROUTER_MODE_SEF)  
            if ($app->getCfg('sef_suffix') && 
!(substr($path, -
9) == 
'index.php' || 
substr($path, -
1) == 
'/'))  
                if ($suffix = 
pathinfo($path, PATHINFO_EXTENSION))  
                    $vars['format'] = 
$suffix;  
        $uri->setPath(trim($path, '/'));  
        $vars += 
parent::parse($uri);  
     * Function to convert an internal URI to a route  
     * @param   string  $url  The internal URL  
     * @return  string  The absolute search engine friendly URL  
    public function build($url)  
        $uri = 
parent::build($url);  
        $route = 
$uri->getPath();  
        // Add the suffix to the uri  
        if ($this->_mode == 
JROUTER_MODE_SEF && 
$route)  
            if ($app->getCfg('sef_suffix') && 
!(substr($route, -
9) == 
'index.php' || 
substr($route, -
1) == 
'/'))  
                if ($format = 
$uri->getVar('format', 'html'))  
            if ($app->getCfg('sef_rewrite'))  
                if ($route == 
'index.php')  
        // Add basepath to the uri  
        $uri->setPath(JUri::base(true) . 
'/' . 
$route);  
     * Function to convert a raw route to an internal URI  
     * @param   JUri  &$uri  The raw route  
        // Handle an empty URL (special case)  
        if (!$uri->getVar('Itemid') && 
!$uri->getVar('option'))  
            // Set the information in the request  
            $vars['Itemid'] = 
$item->id;  
            // Set the active menu item  
            $menu->setActive($vars['Itemid']);  
        // Get the variables from the uri  
        $this->setVars($uri->getQuery(true));  
        // Get the itemid, if it hasn't been set force it to null  
        $this->setVar('Itemid', $app->input->getInt('Itemid', null));  
        // Only an Itemid  OR if filter language plugin set? Get the full information from the itemid  
            $item = 
$menu->getItem($this->getVar('Itemid'));  
            if ($item !== 
null && 
is_array($item->query))  
                $vars = 
$vars + 
$item->query;  
        // Set the active menu item  
        $menu->setActive($this->getVar('Itemid'));  
     * Function to convert a sef route to an internal URI  
     * @param   JUri  &$uri  The sef URI  
     * @return  string  Internal URI  
        $route = 
$uri->getPath();  
        if ($this->_mode == 
JROUTER_MODE_SEF)  
            if ($app->getCfg('sef_suffix'))  
                if ($suffix = 
pathinfo($route, PATHINFO_EXTENSION))  
        // Get the variables from the uri  
        $vars = 
$uri->getQuery(true);  
        // Handle an empty URL (special case)  
            // If route is empty AND option is set in the query, assume it's non-sef url, and parse apropriately  
            if (isset
($vars['option']) || isset
($vars['Itemid']))  
            // If user not allowed to see default menu item then avoid notices  
                // Set the information in the request  
                $vars['Itemid'] = 
$item->id;  
                // Set the active menu item  
                $menu->setActive($vars['Itemid']);  
        // Parse the application route  
        if (count($segments) > 
1 && 
$segments[0] == 
'component')  
            $vars['option'] = 
'com_' . 
$segments[1];  
            // Need to reverse the array (highest sublevels first)  
            foreach ($items as $item)  
                if (isset
($item->language))  
                    $item->language = 
trim($item->language);  
                // Get the length of the route  
                $length = 
strlen($item->route);  
                if ($length > 
0 && 
JString::strpos($route_lowercase . 
'/', $item->route . 
'/') === 
0  
                    && 
$item->type != 
'menulink' && 
(!$app->getLanguageFilter() || 
$item->language == 
'*' 
                    || 
$item->language == 
$lang_tag)) 
                    // We have exact item for this language  
                    if ($item->language == 
$lang_tag)  
                    // Or let's remember an item for all languages  
                $found = 
$menu->getDefault($lang_tag);  
            $vars['Itemid'] = 
$found->id;  
            $vars['option'] = 
$found->component;  
        // Set the active menu item  
        if (isset
($vars['Itemid']))  
            $menu->setActive($vars['Itemid']);  
        // Parse the component route  
        if (!empty($route) && isset
($this->_vars['option']))  
            // Handle component    route  
            // Use the component routing handler if it exists  
            $path = 
JPATH_SITE . 
'/components/' . 
$component . 
'/router.php';  
                if ($component != 
'com_search')  
                    // Decode the route segments  
                    $total = 
count($segments);  
                    for ($i = 
0; $i < 
$total; $i++
)  
                        // Urldecode twice because it is encoded twice  
                $function = 
substr($component, 4) . 
'ParseRoute';  
                $function = 
str_replace(array("-", "."), "", $function);  
                $vars = 
$function($segments);  
            if ($item = 
$menu->getActive())  
     * Function to build a sef route  
     * @param   JUri  &$uri  The internal URL  
     * @deprecated  4.0  Use buildSefRoute() instead  
     * Function to build a sef route  
     * @param   JUri  &$uri  The uri  
        $route = 
$uri->getPath();  
        $query = 
$uri->getQuery(true);  
        if (!isset
($query['option']))  
        // Build the component route  
        $component = 
preg_replace('/[^A-Z0-9_\.-]/i', '', $query['option']);  
        $itemID    = 
!empty($query['Itemid']) ? 
$query['Itemid'] : 
null;  
        // Use the component routing handler if it exists  
        $path = 
JPATH_SITE . 
'/components/' . 
$component . 
'/router.php';  
        // Use the custom routing handler if it exists  
            $function = 
substr($component, 4) . 
'BuildRoute';  
            $function = 
str_replace(array("-", "."), "", $function);  
            $parts    = 
$function($query);  
            // Encode the route segments  
            if ($component != 
'com_search')  
                for ($i = 
0; $i < 
$total; $i++
)  
                    // Urlencode twice because it is decoded once after redirect  
            $tmp    = 
($result != 
"") ? 
$result : 
'';  
        // Build the application route  
        if (!empty($query['Itemid']))  
            $item = 
$menu->getItem($query['Itemid']);  
            if (is_object($item) && 
$query['option'] == 
$item->component)  
                if (!$item->home || 
$item->language != 
'*')  
                    $tmp = 
!empty($tmp) ? 
$item->route . 
'/' . 
$tmp : 
$item->route;  
        if (empty($query['Itemid']) && 
!empty($itemID))  
            $query['Itemid'] = 
$itemID;  
            $tmp = 
'component/' . 
substr($query['option'], 4) . 
'/' . 
$tmp;  
        elseif ($route == 
'index.php')  
        // Unset unneeded query information  
        if (isset
($item) && 
$query['option'] == 
$item->component)  
        // Set query again in the URI  
     * Process the parsed router variables based on custom defined rules  
     * @param   JUri  &$uri  The URI to parse  
     * @return  array  The array of processed URI variables  
        // Process the attached parse rules  
        // Process the pagination support  
        if ($this->_mode == 
JROUTER_MODE_SEF)  
            if ($start = 
$uri->getVar('start'))  
                $vars['limitstart'] = 
$start;  
     * Process the build uri query data based on custom defined rules  
     * @param   JUri  &$uri  The URI  
        // Make sure any menu vars are used if no others are specified  
        if (($this->_mode != 
JROUTER_MODE_SEF) && 
$uri->getVar('Itemid') && 
count($uri->getQuery(true)) == 
2)  
            // Get the active menu item  
            $itemid = 
$uri->getVar('Itemid');  
            $item = 
$menu->getItem($itemid);  
                $uri->setQuery($item->query);  
            $uri->setVar('Itemid', $itemid);  
        // Process the attached build rules  
        $route = 
$uri->getPath();  
        if ($this->_mode == 
JROUTER_MODE_SEF && 
$route)  
            if ($limitstart = 
$uri->getVar('limitstart'))  
                $uri->setVar('start', (int) 
$limitstart);  
                $uri->delVar('limitstart');  
     * Create a uri based on a full or partial url string  
     * @param   string  $url  The URI  
        // Get the itemid form the URI  
        $itemid = 
$uri->getVar('Itemid');  
            if ($option = 
$uri->getVar('option'))  
                $item  = 
$menu->getItem($this->getVar('Itemid'));  
                if (isset
($item) && 
$item->component == 
$option)  
                    $uri->setVar('Itemid', $item->id);  
                if ($option = 
$this->getVar('option'))  
                    $uri->setVar('option', $option);  
                if ($itemid = 
$this->getVar('Itemid'))  
                    $uri->setVar('Itemid', $itemid);  
            if (!$uri->getVar('option'))  
                if ($item = 
$menu->getItem($itemid))  
                    $uri->setVar('option', $item->component);  
 
 
	
		Documentation generated on Tue, 19 Nov 2013 15:13:52 +0100 by phpDocumentor 1.4.3