function shCheckRedirect($dest, $incomingUrl) { $sefConfig =& shRouter::shGetConfig(); if (!empty($dest) && $dest != $incomingUrl) { // redirect to alias if ($dest == sh404SEF_HOMEPAGE_CODE) { if (!empty($sefConfig->shForcedHomePage)) { $dest = shFinalizeURL($sefConfig->shForcedHomePage); } else { $dest = shFinalizeURL($GLOBALS['shConfigLiveSite']); } } else { $shUri = new JURI($dest); $shOriginalUri = clone $shUri; $dest = shSefRelToAbs($dest, '', $shUri, $shOriginalUri) . $shUri->toString(array('query')); } if ($dest != $incomingUrl) { _log('Redirecting to ' . $dest . ' from alias ' . $incomingUrl); shRedirect($dest); } } }
function revert(&$url_array, $pos) { $sefConfig =& shRouter::shGetConfig(); // get DB $database =& JFactory::getDBO(); $QUERY_STRING = ''; $req = implode('/', $url_array); if ($req != '/') { $req = JString::ltrim($req, '/'); } // V x $req = str_replace("//", "/", $req); _log('sef404 reverting URL : ' . $req); // read from db $sql = "SELECT oldurl, newurl FROM #__redirection WHERE oldurl = " . $database->Quote($req) . " ORDER BY rank ASC LIMIT 1"; // V 1.2.4.q $database->setQuery($sql); $row = $database->loadObject(); if ($row) { // use the cached url $string = $row->newurl; // check for urls using wrong letter case, 301 redirect to correct url case $shPageInfo =& shRouter::shPageInfo(); if (empty($shPageInfo->autoRedirectsDisabled) && $sefConfig->redirectToCorrectCaseUrl) { // if initial query exactly matches oldurl found in db, then case is correct // else we redirect to the url found in db, but we also need to append query string to it ! if ($req != $row->oldurl) { // can only be different from case // what is the url we should redirect to ? $targetUrl = str_replace($req, $row->oldurl, $shPageInfo->shSaveRequestURI); $targetUrl = $shPageInfo->URI->protocol . '://' . $shPageInfo->URI->host . (!sh404SEF_USE_NON_STANDARD_PORT || empty($shPageInfo->URI->port) ? '' : ':' . $shPageInfo->URI->port) . $targetUrl . (empty($shPageInfo->URI->anchor) ? '' : '#' . $shPageInfo->URI->anchor); // perform redirect _log('Redirecting to correct url case : from ' . $req . ' to ' . $targetUrl); shRedirect($targetUrl); } } // keep going if we did not redirect to correct case _log('sef404 reverting URL : found : ' . $row->newurl); // update the count $database->setQuery("UPDATE #__redirection SET cpt=(cpt+1) WHERE `newurl` = " . $database->Quote($row->newurl) . " AND `oldurl` = " . $database->Quote($row->oldurl)); // V 1.2.4.q $database->query(); // now we must merge query string from request and POST data with that found in db // as there might be common variables. For instance, limit=5 in the DB // but limit=10 as been pass as POST DATA from a drop-down list item $otherVars = empty($shPageInfo->URI->querystring) ? array() : $shPageInfo->URI->querystring; $postVars = JRequest::get('post'); $otherVars = array_merge($otherVars, $postVars); if (!empty($otherVars)) { foreach ($otherVars as $key => $value) { // if var exists in the incoming url, override it with querystring or post var value if (shGetURLVar($string, $key, null) !== null) { // if we change the value of limit, we must reset limitstart, or we may end up // with weird page number if ($key == 'limit') { $limit = shGetURLVar($string, 'limit', null); if (!is_null($limit) && $value != $limit) { // we are changing limit value : is there a limitstart ? $limitstart = shGetURLVar($string, 'limitstart', null); if (!is_null($limitstart)) { // calculate a new limitstart $limitstart = empty($limit) ? 0 : floor($limitstart / $limit) - 1; $limitstart = $limitstart < 0 ? 0 : $limitstart; // and set it $string = shSetURLVar($string, 'limitstart', $limitstart, $canBeEmpty = true); // kill any remaining limitstart value if (array_key_exists('limitstart', $otherVars)) { unset($otherVars['limitstart']); } } } } // now apply new value for the key $string = shSetURLVar($string, $key, $value); } } } $string = str_replace('&', '&', $string); $QUERY_STRING = str_replace('index.php?', '', $string); // so weird : because of how Joomla choose to not include $limit in urls, I must remove &limit=xx from the restored url // I do have to store it in db however, otherwise same sef will be associated with same non-sef, and then // Joomla content views will be screwed up also as they guess $limit and reset JRequest('limit'); if (!empty($QUERY_STRING)) { $QUERY_STRING = '&' . $QUERY_STRING; $option = shGetURLVar($QUERY_STRING, 'option'); $layout = shGetURLVar($QUERY_STRING, 'layout'); if (empty($layout)) { $layout = 'default'; } $view = shGetURLVar($QUERY_STRING, 'view'); if ($option == 'com_content' && $layout != 'blog' && ($view == 'category' || $view == 'section')) { $limit = shGetURLVar($QUERY_STRING, 'limit'); //$QUERY_STRING = shCleanUpVar( $QUERY_STRING, 'limit'); // but we need to keep it, because of a bug in Joomla, which I could not trace // whereby the user state limit value in com_content.default.limit is that of the blog instead of that of the current view global $mainframe; $mainframe->setUserState('com_content.sh.' . $view . '.' . $layout . '.limit', $limit); //_log( 'Removing limit from reverted url, to : ' . $QUERY_STRING); } $QUERY_STRING = JString::ltrim($QUERY_STRING, '&'); } } return $QUERY_STRING; }
protected function _checkTrailingSlash($uri) { if (!$this->_canRedirectFrom($uri)) { return; } // get config object $sefConfig = Sh404sefFactory::getConfig(); // get the url path and try add or remove a trailing slash $path = $uri->getPath(); // if path ends with current suffix, stop here if (JString::substr($path, -JString::strlen($sefConfig->suffix)) == $sefConfig->suffix) { return; } // same with optional index file if (JString::substr($path, -JString::strlen($sefConfig->addFile)) == $sefConfig->addFile) { return; } // now add or remove trailing slash. Must check existence of trailing slash // on the $uri->_uri, as J! always remove it from $uri->_path $trailingSlash = $this->_hasTrailingSlash($uri); if ($trailingSlash) { $path = JString::rtrim($path, '/'); } else { $path .= '/'; } // and check db again $vars = array(); // dummy, we don't care about the actual vars retrieved $lookUp = $this->_lookupSef($uri, $vars, $path); // if url exists with slash added or removed, 301 to that valid url if ($lookUp->urlType == sh404SEF_URLTYPE_AUTO || $lookUp->urlType == sh404SEF_URLTYPE_CUSTOM) { $query = $uri->getQuery(); $targetSefUrl = $uri->base() . $path . (empty($query) ? '' : '?' . $query); _log('Redirecting to same with trailing slash added: ' . $targetSefUrl); shRedirect($targetSefUrl); } }
<?php /** * SEF module for Joomla! * * @author $Author: shumisha $ * @copyright Yannick Gaultier - 2007-2010 * @package sh404SEF-15 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @version $Id: sh404sef.php 1188 2010-04-04 15:52:41Z silianacom-svn $ * */ // Security check to ensure this file is being included by a parent file. if (!defined('_JEXEC')) { die('Direct Access to this location is not allowed.'); } // no direct acccess shRedirect($GLOBALS['shConfigLiveSite']);
function shCheckRedirect ($dest, $incomingUrl) { $sefConfig = & Sh404sefFactory::getConfig(); if (!empty($dest) && $dest != $incomingUrl) { // redirect to alias if ($dest == sh404SEF_HOMEPAGE_CODE) { if (!empty($sefConfig->shForcedHomePage)) { $dest = shFinalizeURL($sefConfig->shForcedHomePage); } else { $dest = shFinalizeURL(Sh404sefFactory::getPageInfo()->getDefaultLiveSite()); } } else { $shUri = new JURI($dest); $shOriginalUri = clone( $shUri); $dest = shSefRelToAbs($dest, '', $shUri, $shOriginalUri) . $shUri->toString( array('query')); } if ($dest != $incomingUrl) { _log('Redirecting to '. $dest .' from alias '.$incomingUrl); shRedirect($dest); } } }
// set vars obtained from parsing the current request if (!empty($nonSefVars)) { foreach ($nonSefVars as $key => $value) { $jUri->setVar($key, $value); } } // have juri calculate the non-sef url $newNonSefUrl = $jUri->toString(array('path', 'query', 'fragment')); if (!empty($newNonSefUrl)) { $newNonSefUrl = 'index.php' . $newNonSefUrl; // have sh404sef calculate the new sef url $newSef = JRoute::_($newNonSefUrl); // try avoid looping, and redirect to sh404sef version if ($newNonSefUrl != $shPageInfo->URI->url) { _log('Redirecting joomla sef ' . $newNonSefUrl . ' to sh404sef sef ' . $newSef); shRedirect($newSef); } } } } // bad URL, so check to see if we've seen it before // V 1.2.4.k 404 errors logging is now optional if ($sefConfig->shLog404Errors) { $query = "SELECT * FROM #__redirection WHERE oldurl = '" . $path . "'"; $database->setQuery($query); $results = $database->loadObjectList(); if ($results) { // we have, so update counter //$database->setQuery("UPDATE #__redirection SET cpt=(cpt+1) WHERE oldurl = '".$path."'"); //$database->query(); } else {
<?php /** * SEF module for Joomla! * * @author $Author: shumisha $ * @copyright Yannick Gaultier - 2007-2011 * @package sh404SEF-16 * @license http://www.gnu.org/copyleft/gpl.html GNU/GPL * @version $Id: sh404sef.php 2050 2011-06-30 13:52:38Z silianacom-svn $ * */ // Security check to ensure this file is being included by a parent file. if (!defined('_JEXEC')) { die('Direct Access to this location is not allowed.'); } // no direct acccess shRedirect(Sh404sefFactory::getPageInfo()->getDefaultLiveSite());