function parse(&$uri) { $mainframe =& JFactory::getApplication(); // test for the backlink plugin to work correctly if (JPluginHelper::isEnabled('system', 'backlink')) { // && $uri->getQuery() ) { // commented out - causing problems $joomlaRequest = urldecode($_SERVER['REQUEST_URI']); $realRequest = $uri->toString(array('path', 'query')); if ($realRequest != $joomlaRequest) { $uri = new JURI($joomlaRequest); } } // store the old URI before we change it in case we will need it // for default Joomla SEF $oldUri = new JURI($uri->toString()); if (!SEFTools::JoomFishInstalled()) { $url_query = $uri->getQuery(); $host = explode(".", $uri->getHost()); $subdomain = array_shift($host); $db = JFactory::getDBO(); // Subdomain titlepage if ($uri->getPath() == '/' && empty($url_query) && empty($_POST)) { $query = "SELECT Itemid_titlepage FROM #__sef_subdomains WHERE subdomain = " . $db->quote($subdomain) . " LIMIT 1"; $db->setQuery($query); $Itemid = $db->loadResult(); if ($Itemid > 0) { $uri->setVar('Itemid', $Itemid); JoomSEF::set('real_domain', JFactory::getUri()->getHost()); JFactory::getUri()->setHost(implode(".", $host)); } } else { $query = "SELECT COUNT(*) FROM #__sef_subdomains WHERE subdomain = " . $db->quote($subdomain); $db->setQuery($query); $cnt = $db->loadResult(); if ($cnt) { JoomSEF::set('real_domain', JFactory::getUri()->getHost()); JFactory::getUri()->setHost(implode(".", $host)); } } } $sefConfig =& SEFConfig::getConfig(); // load patches JPluginHelper::importPlugin('sefpatch'); // trigger onSefLoad patches $mainframe->triggerEvent('onSefLoad'); // get path $path = $uri->getPath(); // remove basepath $path = substr_replace($path, '', 0, strlen(JURI::base(true))); // remove slashes $path = ltrim($path, '/'); // Redirect URL with / on the end to URL without / on the end if ($sefConfig->redirectSlash) { $request = $_SERVER["REQUEST_URI"]; $noBase = substr_replace($request, '', 0, strlen(JURI::base(true))); if ($request != "/" && $noBase != "/" && substr($request, -1) == '/') { $mainframe->redirect(rtrim($request, "/"), '', 'message'); JFactory::getApplication()->close(); } } // Redirect the index.php (need to check this before index.php removal) if ($sefConfig->fixIndexPhp && $path == 'index.php' && count($_POST) == 0) { $q = $uri->getQuery(true); if (count($q) == 0) { $newUrl = JURI::root(); if (substr($newUrl, -1) != '/') { $newUrl .= '/'; } $mainframe->redirect($newUrl, '', 'message', true); exit; } } // Try the 301 Alias redirect if (count($_POST) == 0) { JoomSEF::_parseAlias($path, $uri->getQuery(true)); } // Disable non-SEF redirect for index2.php links // EDIT: don't even parse index2.php links! if (substr($path, 0, 10) == 'index2.php') { //$sefConfig->nonSefRedirect = false; return $uri->getQuery(true); } // Redirect old /index.php/ links if set to if ($sefConfig->fixIndexPhp && substr($path, 0, 10) == 'index.php/' && count($_POST) == 0) { $newUrl = JURI::root(); if (substr($newUrl, -1) != '/') { $newUrl .= '/'; } $newUrl .= substr($path, 10); $mainframe->redirect($newUrl, '', 'message', true); exit; } // remove prefix (both index.php and index2.php) $path = preg_replace('/^index2?.php/i', '', $path); // remove slashes again to be sure there aren't any left $path = ltrim($path, '/'); // replace spaces with our replacement character // (mainly for '+' handling, but may be useful in some other situations too) $path = str_replace(' ', $sefConfig->replacement, $path); // set the route $uri->setPath($path); // host name handling if (SEFTools::JoomFishInstalled() && $sefConfig->langPlacement == _COM_SEF_LANG_DOMAIN && !JPluginHelper::isEnabled('system', 'jfrouter')) { // different domains for languages handling $host = $uri->toString(array('host')); $host = trim($host, '/'); $code = null; foreach ($sefConfig->jfSubDomains as $langCode => $domain) { if ($host == $domain) { // if main language is not selected, use the first corresponding domain if ($sefConfig->mainLanguage == '0') { $code = $langCode; break; } else { if ($langCode == $sefConfig->mainLanguage) { $code = $langCode; break; } else { if (is_null($code)) { $code = $langCode; } } } } } // we found a matching domain if (!is_null($code)) { JRequest::setVar('lang', $code); $config =& JFactory::getConfig(); $config->set('joomsef.domain_lang', $code); } } // parse the url $vars = JoomSEF::_parseSefUrl($uri, $oldUri); // handle custom site name for extensions if (isset($vars['option'])) { $params =& SEFTools::getExtParams($vars['option']); $useSitename = $params->get('useSitename', '1'); $customSitename = trim($params->get('customSitename', '')); $config =& JFactory::getConfig(); if ($useSitename == '0') { // don't use site name $config->setValue('sitename', ''); } elseif (!empty($customSitename)) { // use custom site name $config->setValue('sitename', $customSitename); } } // trigger onSefUnload patches $mainframe->triggerEvent('onSefUnload'); return $vars; }