function parse(&$uri) { $sefConfig =& SEFConfig::getConfig(); $langs = JLanguageHelper::getLanguages('sef'); // add base path, as Joomla does not send it but we count on it $uri->setPath(JURI::base(true) . '/' . $uri->getPath()); $url_query = $uri->getQuery(); $host = explode(".", $uri->getHost()); $subdomain = array_shift($host); $db = JFactory::getDBO(); // Subdomain titlepage if ($uri->getPath() == JURI::base(true) . '/' && empty($url_query) && empty($_POST)) { $query = $db->getQuery(true); $query->select('Itemid_titlepage')->from('#__sef_subdomains'); $query->where('subdomain=' . $db->quote($subdomain)); if ($sefConfig->langEnable) { $lang = JRequest::getVar('lang'); $query->where('lang=' . $db->quote($lang)); } $db->setQuery($query, 0, 1); $Itemid = $db->loadResult(); if ($sefConfig->langEnable == 1 && $sefConfig->alwaysUseLangHomeJoomla && $Itemid > 0) { SEFTools::redirect($uri->base(true) . '/' . $lang, true); } else { if ($Itemid > 0) { $uri->setVar('Itemid', $Itemid); JoomSEF::set('real_domain', JFactory::getUri()->getHost()); JFactory::getUri()->setHost(implode(".", $host)); } } } else { if (empty($url_query) && empty($_POST) && $sefConfig->langEnable) { $query = $db->getQuery(true); $query->select('Itemid_titlepage')->from('#__sef_subdomains'); $query->where('subdomain=' . $db->quote($subdomain)); $lang = JRequest::getVar('lang'); $query->where('lang=' . $db->quote($lang)); $db->setQuery($query, 0, 1); $Itemid = $db->loadResult(); if ($Itemid > 0) { $uri->setVar('Itemid', $Itemid); JoomSEF::set('real_domain', JFactory::getUri()->getHost()); JFactory::getUri()->setHost(implode(".", $host)); } } else { $query = $db->getQuery(true); $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)); } } } // Set Joomla's router so it doesn't process URL further $mainframe =& JFactory::getApplication(); $jRouter = $mainframe->getRouter(); $jRouter->SetMode(JROUTER_MODE_DONT_PARSE); // store the old URI before we change it in case we will need it // for default Joomla SEF $oldUri = clone $uri; // 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"]; if ($request != $uri->base(true) . "/" && substr($request, -1) == '/') { SEFTools::redirect(rtrim($request, '/'), true); } } $request = $_SERVER["REQUEST_URI"]; $route = str_replace($uri->getPath(), '', $request); $route = str_replace("?" . $uri->getQuery(), '', $route); // Redirect the index.php (need to check this before index.php removal) // 29.11.2012 dajo: Redirect only pure index.php if ($sefConfig->fixIndexPhp && $route == 'index.php' && count($uri->getQuery(true)) == 0 && count($_POST) == 0) { $newUrl = JURI::root(); if (substr($newUrl, -1) != '/') { $newUrl .= '/'; } $q = $uri->getQuery(); if (!empty($q)) { $newUrl .= '?' . $q; } SEFTools::redirect($newUrl, true); } // fix Joomla URLs with index.php/ $path = preg_replace('#^index\\.php\\/#i', '', $path); // Redirect root URL to URL with language code if ($sefConfig->langEnable) { if ($sefConfig->langPlacementJoomla == _COM_SEF_LANG_PATH && $sefConfig->alwaysUseLangHomeJoomla) { $query = $uri->getQuery(true); if (str_replace($uri->base(true), "", $uri->getPath()) == '/' && empty($query) && empty($_POST)) { $home_items = SEFTools::getHomeQueries(); $lang = $langs[JRequest::getVar('lang')]->lang_code; $uself = JPluginHelper::isEnabled('system', 'languagefilter'); $usefalang = JPluginHelper::isEnabled('system', 'falangdriver'); foreach ($home_items as $id => $item) { if ($usefalang) { if ($item->language == '*') { $Itemid = $item->id; $link = $item->link; break; } } else { if ($item->language == $lang || $langs[JRequest::getVar('lang')]->sef == $sefConfig->mainLanguageJoomla && $item->language == '*') { $Itemid = $item->id; $link = $item->link; // Don't break, we may find other item that fits better } } } // Add Itemid to link $link .= (strpos($link, '?') === false ? '?' : '&') . 'Itemid=' . $Itemid; SEFTools::redirect(JRoute::_($link), $sefConfig->rootLangRedirect303 ? false : true); } } } // Remove language code and redirect for main language if set to if ($sefConfig->langEnable && $sefConfig->langPlacementJoomla == _COM_SEF_LANG_PATH && (!$sefConfig->alwaysUseLangJoomla || !$sefConfig->alwaysUseLangHomeJoomla) && empty($_POST)) { $langSefLen = strlen($sefConfig->mainLanguageJoomla); if (substr($path, 0, $langSefLen) == $sefConfig->mainLanguageJoomla) { // Main language is in the path if (strlen($path) == $langSefLen) { // Root URL $query = $uri->getQuery(true); if (!$sefConfig->alwaysUseLangHomeJoomla && empty($query)) { // Redirect $link = JURI::root(true); SEFTools::redirect($link, true); } } else { // Not root URL if ($path[$langSefLen] == '/' && !$sefConfig->alwaysUseLangJoomla) { // Redirect $link = rtrim(JURI::root(true), '/') . substr($path, $langSefLen); $query = $uri->getQuery(); if (!empty($query)) { $link .= '?' . $query; } SEFTools::redirect($link, true); } } } } // Try the 301 Alias redirect if (count($_POST) == 0) { Joomsef::_parseAlias($path, $uri->getQuery(true)); } // remove prefix (both index.php and index2.php) //$path = eregi_replace('^index2?.php', '', $path); $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); // 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->set('sitename', ''); } elseif (!empty($customSitename)) { // use custom site name $config->set('sitename', $customSitename); } } // trigger onSefUnload patches $mainframe->triggerEvent('onSefUnload'); return $vars; }
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; }