static function _15($url, $xhtml, $ssl) { global $FSTRoute_debug; global $FSTRoute_menus; // get any menu items for fst FST_Helper::GetRouteMenus(); $FSTRoute_debug[] = "<h1>Start URL : {$url}</h1>"; // Get the router $app =& JFactory::getApplication(); $router =& $app->getRouter(); // Make sure that we have our router if (!$router) { return null; } if (strpos($url, '&') !== 0 && strpos($url, 'index.php') !== 0) { return $url; } /* Into JRouter::build */ //Create the URI object $uri =& $router->_createURI($url); //Process the uri information based on custom defined rules $router->_processBuildRules($uri); // Build RAW URL if ($router->_mode == JROUTER_MODE_RAW) { $router->_buildRawRoute($uri); } /* Custom part of JRouter::build */ // split out parts of the url for //$parts = FSTRoute::SplitURL($menu->link); //$FSTRoute_debug[] = "URI : <pre>" . print_r($uri,true). "</pre>"; // work out is we are in an Itemid already, if so, set it as the best match if (array_key_exists('Itemid', $uri->_vars)) { $bestmatch = $uri->_vars['Itemid']; } else { $bestmatch = ''; } $bestcount = 0; $urivars = $uri->_vars; // find all the vars in the new url $sourcevars = FSTRoute::SplitURL($url); //$addedvars = array(); //$FSTRoute_debug[] = "Source Vars from calling url, to save and emptied fields : <pre>" . print_r($sourcevars,true). "</pre>"; //$FSTRoute_debug[] = "Initial URI Vars : <pre>" . print_r($urivars,true). "</pre>"; // check through the menu item for the current url, and add any items to the new url that are missing if ($bestmatch && array_key_exists($bestmatch, $FSTRoute_menus)) { foreach ($FSTRoute_menus[$bestmatch] as $key => $value) { if (!array_key_exists($key, $urivars) && !array_key_exists($key, $sourcevars)) { //$FSTRoute_debug[] = "<span style='color:red; font-size:150%'>Adding source var $key => $value</span><br>"; $urivars[$key] = $value; //$addedvars[$key] = $value; } } } //$FSTRoute_debug[] = "Source Vars Added : <pre>" . print_r($addedvars,true). "</pre>"; //$FSTRoute_debug[] = "URI Vars after adding any missing bits : <pre>" . print_r($urivars,true). "</pre>"; foreach ($FSTRoute_menus as $id => $vars) { $count = FSTRoute::MatchVars($urivars, $vars); //$FSTRoute_debug[] = "Match against $id => $count<br>"; if ($count > $bestcount) { $bestcount = $count; $bestmatch = $id; } } // if no match found, and we are in groups, try to link to admin if ($bestcount == 0 && array_key_exists('view', $sourcevars) && $sourcevars['view'] == "groups") { // no match found, try to fallback on the main support menu id foreach ($FSTRoute_menus as $id => $item) { if ($item['view'] == "admin" && (!array_key_exists('layout', $item) || $item['layout'] == "default")) { $bestcount = 1; $bestmatch = $id; } } } if ($bestcount == 0) { // no match found, try to fallback on the main support menu id foreach ($FSTRoute_menus as $id => $item) { if ($item['view'] == "main") { $bestcount = 1; $bestmatch = $id; } } } if ($bestcount == 0) { // still no match found, use any fst menu if (count($FSTRoute_menus) > 0) { foreach ($FSTRoute_menus as $id => $item) { $bestcount = 1; $bestmatch = $id; break; } } } if ($bestcount > 0) { //$FSTRoute_debug[] = "Best Match $bestmatch => $bestcount<br>"; $uri->setVar('Itemid', $bestmatch); /*foreach($addedvars as $key => $value) unset($uri->_vars[$key]);*/ if ($bestmatch && array_key_exists($bestmatch, $FSTRoute_menus)) { foreach ($FSTRoute_menus[$bestmatch] as $key => $value) { if (array_key_exists($key, $uri->_vars) && $uri->_vars[$key] == $value) { if ($router->_mode == JROUTER_MODE_SEF) { //$FSTRoute_debug[] = "<span style='color:red; font-size:150%'>Removing var $key, its part of the menu definition</span><br>"; $uri->delVar($key); } } } } } else { //$FSTRoute_debug[] = "No Match found, leaving as is<br>"; } /* End custom part */ // Build SEF URL : mysite/route/index.php?var=x //$FSTRoute_debug[] = "Pre SEF URL : {$uri->toString(array('path', 'query', 'fragment'))}<Br>"; if ($router->_mode == JROUTER_MODE_SEF) { $router->_buildSefRoute($uri); } //$FSTRoute_debug[] = "Post SEF URL : {$uri->toString(array('path', 'query', 'fragment'))}<Br>"; /* End JRoute::build */ /* Stuff From JRouterSite */ // Get the path data $route = $uri->getPath(); //Add the suffix to the uri if ($router->_mode == JROUTER_MODE_SEF && $route) { $app =& JFactory::getApplication(); if ($app->getCfg('sef_suffix') && !(substr($route, -9) == 'index.php' || substr($route, -1) == '/')) { if ($format = $uri->getVar('format', 'html')) { $route .= '.' . $format; $uri->delVar('format'); } } if ($app->getCfg('sef_rewrite')) { //Transform the route $route = str_replace('index.php/', '', $route); } } //Add basepath to the uri $uri->setPath(JURI::base(true) . '/' . $route); /* End Stuff From JRouterSite */ /* Back into FSTRoute::x */ $url = $uri->toString(array('path', 'query', 'fragment')); // Replace spaces $url = preg_replace('/\\s/u', '%20', $url); //$FSTRoute_debug[] = "pre ssl $url</br>"; /* * 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. */ $ssl = (int) $ssl; if ($ssl) { $uri =& JURI::getInstance(); // Get additional parts static $prefix; if (!$prefix) { $prefix = $uri->toString(array('host', 'port')); //$prefix .= JURI::base(true); } // Determine which scheme we want $scheme = $ssl === 1 ? 'https' : 'http'; // Make sure our url path begins with a slash if (!preg_match('#^/#', $url)) { $url = '/' . $url; } // Build the URL $url = $scheme . '://' . $prefix . $url; } if ($xhtml) { $url = str_replace('&', '&', $url); } /* End FSTRoute::x */ //$FSTRoute_debug[] = "returning $url<Br>"; return $url; }