function _parseRawRoute(&$uri) { $sefConfig =& SEFConfig::getConfig(); if (is_null($uri->getVar('option'))) { // Set the URI from Itemid $menu =& JSite::getMenu(true); $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 = urldecode(JRoute::_($url)); // 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 = $curUri->_uri; } if ($sef != $curUrl) { // Seems the URL is SEF, let's redirect $f = $l = ''; if (!headers_sent($f, $l)) { $mainframe =& JFactory::getApplication(); $mainframe->redirect($sef, '', 'message', true); exit; } else { JoomSEF::_headers_sent_error($f, $l, __FILE__, __LINE__); } } } } 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) { $db =& JFactory::getDBO(); $sefConfig =& SEFConfig::getConfig(); $cache =& SEFCache::getInstance(); $vars = array(); $route = html_entity_decode(urldecode($route)); $route = str_replace(' ', $sefConfig->replacement, $route); $routeNoSlash = rtrim($route, '/'); // try to use cache if ($sefConfig->useCache) { $row = $cache->getNonSefUrl($route); } else { $row = null; } // cache worked if ($row) { $fromCache = true; } else { // URL isn't in cache or cache disabled $fromCache = false; if ($sefConfig->transitSlash) { $where = "(`sefurl` = " . $db->Quote($routeNoSlash) . ") OR (`sefurl` = " . $db->Quote($routeNoSlash . '/') . ")"; } else { $where = "`sefurl` = " . $db->Quote($route); } $sql = "SELECT * FROM `#__sefurls` WHERE ({$where}) AND (`origurl` != '') AND (`trashed` = '0') ORDER BY `priority` LIMIT 1"; $db->setQuery($sql); $row = $db->loadObject(); } if ($row) { // 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` = " . $db->Quote($row->sefurl) . " AND `origurl` != '' AND `trashed` = '0'"; } $db->setQuery("UPDATE `#__sefurls` SET `cpt` = (`cpt` + 1)" . $where); $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->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->origurl, $row->sefurl, $row->cpt + 1, $row->Itemid, $row->metatitle, $row->metadesc, $row->metakey, $row->metalang, $row->metarobots, $row->metagoogle, $row->canonicallink, $row->metacustom, $row->enabled, $row->sef); } } elseif ($sefConfig->useMoved) { // URL not found, let's try the Moved Permanently table $where = ''; if ($sefConfig->transitSlash) { $where = '(`old` = ' . $db->Quote($routeNoSlash) . ') OR (`old` = ' . $db->Quote($routeNoSlash . '/') . ')'; } else { $where = '`old` = ' . $db->Quote($route); } $db->setQuery("SELECT * FROM `#__sefmoved` WHERE {$where}"); $row = $db->loadObject(); if ($row) { // URL found, let's update the lastHit in table and redirect $db->setQuery("UPDATE `#__sefmoved` SET `lastHit` = NOW() WHERE `id` = '{$row->id}'"); $db->query(); $root = JURI::root(); $f = $l = ''; if (!headers_sent($f, $l)) { // Let's build absolute URL from our link 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 header('HTTP/1.1 301 Moved Permanently'); header('Location: ' . $url); header('Connection: close'); exit; } else { JoomSEF::_headers_sent_error($f, $l, __FILE__, __LINE__); } } } return $vars; }