function _parseRawRoute(&$uri) { $sefConfig =& SEFConfig::getConfig(); // Make sure that Itemid is numeric $Itemid = $uri->getVar('Itemid'); if (!empty($Itemid)) { $uri->setVar('Itemid', intval($Itemid)); } // Redirect to correct language if set to if ($sefConfig->langEnable && $sefConfig->mismatchedLangHandling == _COM_SEF_MISMATCHED_LANG_FIX && count($_POST) == 0) { $langVar = $uri->getVar('lang'); $itemidVar = $uri->getVar('Itemid'); if (!empty($langVar) && !empty($itemidVar)) { // Get menu item language $menu = JFactory::getApplication()->getMenu('site'); $item = $menu->getItem($itemidVar); if (is_object($item) && !empty($item->language) && $item->language != '*') { $langsCode = JLanguageHelper::getLanguages('lang_code'); if ($langsCode[$item->language]->sef != $langVar) { // Redirect to correct language $curUri = JURI::getInstance(); $curUri->setVar('lang', $langsCode[$item->language]->sef); SEFTools::redirect($curUri->toString(), true); } } } } if (is_null($uri->getVar('option'))) { // Set the URI from Itemid $menu = JFactory::getApplication()->getMenu('site'); $item = $menu->getItem($uri->getVar('Itemid')); if (!is_null($item)) { $uri->setQuery($item->query); $uri->setVar('Itemid', $item->id); } } $extAuto = 2; if (isset($params)) { $extAuto = $params->get('autoCanonical', 2); } $autoCanonical = $extAuto == 2 ? $sefConfig->autoCanonical : $extAuto; if ($sefConfig->nonSefRedirect && count($_POST) == 0 || $autoCanonical) { // Try to find the non-SEF URL in the database - don't create new! $oldDisable = $sefConfig->disableNewSEF; $sefConfig->disableNewSEF = true; $uri->setPath('index.php'); $url = $uri->toString(array('path', 'query', 'fragment')); $sef = JRoute::_($url); // Revert, otherwise Joomla in its router thinks this is SEF URL, // because its path is not empty! $uri->setPath(''); // Restore the configuration $sefConfig->disableNewSEF = $oldDisable; if ($sefConfig->nonSefRedirect && count($_POST) == 0) { // Non-SEF redirect if (strpos($sef, 'index.php?') === false) { // Check if it's different from current URL $curUri = JURI::getInstance(); if ($sef[0] == '/') { $curUrl = $curUri->toString(array('path', 'query', 'fragment')); } else { $curUrl = JoomSefUri::getUri($curUri); } // Fix the & characters $sef = str_replace('&', '&', $sef); if ($sef != $curUrl) { // Seems the URL is SEF, let's redirect SEFTools::redirect($sef, true); } } } else { if ($autoCanonical) { // Only set canonical URL $mainframe =& JFactory::getApplication(); // Remove the query part from SEF URL $pos = strpos($sef, '?'); if ($pos !== false) { $sef = substr($sef, 0, $pos); } JoomSEF::set('sef.link.canonical', $sef); } } } return $uri->getQuery(true); }
function revert($route, &$disabled) { $sefConfig =& SEFConfig::getConfig(); $cache =& SEFCache::getInstance(); $vars = array(); $route = html_entity_decode(urldecode($route)); $routeNoSlash = rtrim($route, '/'); // try to use cache $row = null; if ($sefConfig->useCache) { // There can be multiple non-SEF URLs for the same SEF URL $rows = $cache->getNonSefUrl($route); if ($rows) { // If there is a language from domain, try to find the correct URL $lang = JoomSEF::get('domain_lang'); if (!empty($lang)) { $row = $this->findUrlForLanguage($rows, $lang); } else { $row = reset($rows); } } } // cache worked if ($row) { $fromCache = true; } else { // URL isn't in cache or cache disabled $fromCache = false; if ($sefConfig->transitSlash) { $where = "(`sefurl` = " . $this->_db->Quote($routeNoSlash) . ") OR (`sefurl` = " . $this->_db->Quote($routeNoSlash . '/') . ")"; } else { $where = "`sefurl` = " . $this->_db->Quote($route); } $sql = "SELECT * FROM #__sefurls WHERE ({$where}) AND (`origurl` != '') ORDER BY `priority`"; // Try to find URL with correct language if using domains $lang = JoomSEF::get('domain_lang'); if (!empty($lang)) { // Get all SEF URLs $row = null; $this->_db->setQuery($sql); $rows = $this->_db->loadObjectList(); // Try to find the URL with correct language if (is_array($rows) && count($rows) > 0) { $pattern = "#[?&]lang={$lang}(&|\$)#i"; foreach ($rows as $item) { if (preg_match($pattern, $item->origurl)) { $row = $item; break; } } // No URL with correct language found, use the first one if (is_null($row)) { $row = reset($rows); } } } else { // Find the first matching URL $sql .= ' LIMIT 1'; $this->_db->setQuery($sql); $row = $this->_db->loadObject(); } } if ($row) { // Search in database is not case-sensitive, but URLs are case-sensitive so we should check // if the found route really matches the searched one and redirect if necessary to avoid duplicate content if ($sefConfig->transitSlash && $row->sefurl != $routeNoSlash && $row->sefurl != $routeNoSlash . '/' || !$sefConfig->transitSlash && $row->sefurl != $route) { // Redirect if possible if (empty($_POST)) { $redir = JURI::getInstance(); $redir->setPath('/' . ltrim($row->sefurl, '/')); SEFTools::redirect($redir->toString(), true); } } // Set the disabled flag (old cache records don't need to have enabled set) if (!isset($row->enabled)) { $row->enabled = 1; } if ($row->enabled) { $disabled = false; } else { $disabled = true; } // Use the already created URL $string = $row->origurl; if (isset($row->Itemid) && $row->Itemid != '') { $string .= (strpos($string, '?') ? '&' : '?') . 'Itemid=' . $row->Itemid; } // update the hits count if needed if (!$fromCache || $sefConfig->cacheRecordHits) { $where = ''; if (!empty($row->id)) { $where = " WHERE `id` = '{$row->id}'"; } else { $where = " WHERE `sefurl` = '{$row->sefurl}' AND `origurl` != ''"; } $this->_db->setQuery("UPDATE #__sefurls SET cpt=(cpt+1)" . $where); $this->_db->query(); } $string = str_replace('&', '&', $string); $QUERY_STRING = str_replace('index.php?', '', $string); parse_str($QUERY_STRING, $vars); // Moved to JoomSEF::_parseSefUrl() /* if ($sefConfig->setQueryString) { $_SERVER['QUERY_STRING'] = $QUERY_STRING; } */ // prepare the meta tags array for MetaBot // only if URL is not disabled if (!$disabled) { $mainframe =& JFactory::getApplication(); if (!empty($row->metatitle)) { JoomSEF::set('sef.meta.title', $row->metatitle); } if (!empty($row->metadesc)) { JoomSEF::set('sef.meta.desc', $row->metadesc); } if (!empty($row->metakey)) { JoomSEF::set('sef.meta.key', $row->metakey); } if (!empty($row->metalang)) { JoomSEF::set('sef.meta.lang', $row->metalang); } if (!empty($row->metarobots)) { JoomSEF::set('sef.meta.robots', $row->metarobots); } if (!empty($row->metagoogle)) { JoomSEF::set('sef.meta.google', $row->metagoogle); } if (!empty($row->canonicallink)) { JoomSEF::set('sef.link.canonical', $row->canonicallink); } if (!empty($row->metaauthor)) { JoomSEF::set('sef.meta.author', $row->metaauthor); } if (isset($row->showsitename)) { JoomSEF::set('sef.meta.showsitename', $row->showsitename); } if (!empty($row->metacustom)) { $metacustom = @unserialize($row->metacustom); if (!empty($metacustom)) { JoomSEF::set('sef.meta.custom', $metacustom); } } } // If cache is enabled but URL isn't in cache yet, add it if ($sefConfig->useCache && !$fromCache) { $cache->addUrl($row->id, $row->origurl, $row->sefurl, $row->cpt + 1, $row->Itemid, $row->metatitle, $row->metadesc, $row->metakey, $row->metalang, $row->metarobots, $row->metagoogle, $row->metaauthor, $row->canonicallink, $row->metacustom, $row->enabled, $row->sef, false, $row->host, $row->showsitename); } } elseif ($sefConfig->useMoved) { // URL not found, let's try the Moved Permanently table $where = ''; if ($sefConfig->transitSlash) { $where = "(`old` = " . $this->_db->quote($routeNoSlash) . ") OR (`old` = " . $this->_db->quote($routeNoSlash . '/') . ")"; } else { $where = "`old` = " . $this->_db->quote($route); } $this->_db->setQuery("SELECT * FROM `#__sefmoved` WHERE {$where}"); $row = $this->_db->loadObject(); if ($row) { // URL found, let's update the lastHit in table and redirect $this->_db->setQuery("UPDATE `#__sefmoved` SET `lastHit` = NOW() WHERE `id` = '{$row->id}'"); $this->_db->query(); // Let's build absolute URL from our link $root = JURI::root(); if (strstr($row->new, $root) === false) { $url = $root; if (substr($url, -1) != '/') { $url .= '/'; } if (substr($row->new, 0, 1) == '/') { $row->new = substr($row->new, 1); } $url .= $row->new; } else { $url = $row->new; } // Use the link to redirect SEFTools::redirect($url, true); } } return $vars; }