Example #1
0
 // and are set to auto-redirect to SEF URLs
 // try fetching from DB
 $shSefUrl = null;
 $nonSefURL = 'index.php?' . $shPageInfo->QUERY_STRING;
 if (strpos($nonSefURL, 'lang=') === false) {
     $nonSefURL = shSetURLVar($nonSefURL, 'lang', shGetIsoCodeFromName($GLOBALS['shMosConfig_locale']));
 }
 $urlType = shGetSefURLFromCacheOrDB(shSortURL($nonSefURL), $shSefUrl);
 if ($urlType == sh404SEF_URLTYPE_AUTO || $urlType == sh404SEF_URLTYPE_CUSTOM) {
     // found a match
     $shRewriteBit = $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode];
     $shSefUrl = (empty($shPageInfo->shHttpsSave) ? $GLOBALS['shConfigLiveSite'] : $shPageInfo->shHttpsSave) . $shRewriteBit . JString::ltrim($shSefUrl, '/') . ($shPageInfo->URI->anchor ? "#" . $shPageInfo->URI->anchor : '');
     _log('Redirecting J! sef URl to existing SEF URL : ' . $shSefUrl);
     shRedirect($shSefUrl);
 }
 if (!shIsMultilingual() || shIsMultilingual() == 'joomfish' && shGetNameFromIsoCode(shDecideRequestLanguage()) == $GLOBALS['shMosConfig_locale']) {
     $shSefUrl = (empty($shPageInfo->shHttpsSave) ? $GLOBALS['shConfigLiveSite'] : $shPageInfo->shHttpsSave) . '/index.php?' . $shPageInfo->QUERY_STRING;
     $GLOBALS['mosConfig_defaultLang'] = $shMosConfig_locale;
     // V x 01/09/2007 22:05:11 joomfish not initialised so we must do
     // this otherwise shGetDefaultLanguage will not work
     // check if language in URL
     $shIsoCode = '';
     $shTemp = explode('lang,', $shSefUrl);
     if (!empty($shTemp[1])) {
         $shIsoCode = explode('&', $shTemp[1]);
     }
     $shUri = null;
     $shOriginalUri = null;
     $shSefUrl = shSefRelToAbs($shSefUrl, shGetNameFromIsoCode($shIsoCode), $shUri, $shOriginalUri);
     if (strpos($shSefUrl, '/content/findkey') === false && strpos($shSefUrl, '/content/view') === false && strpos($shSefUrl, '/content/section') === false && strpos($shSefUrl, '/content/category') === false && strpos($shSefUrl, '/content/blogsection') === false && strpos($shSefUrl, '/content/blogcategory') === false && strpos($shSefUrl, '/content/archivesection') === false && strpos($shSefUrl, '/content/archivecategory') === false && strpos($shSefUrl, '/content/new') === false && strpos($shSefUrl, '/content/vote') === false && strpos($shSefUrl, '/component/option') === false && strpos($shSefUrl, '/content/view') === false && strpos($shSefUrl, 'task=view') === false && strpos($shSefUrl, 'task=section') === false && strpos($shSefUrl, 'task=category') === false && strpos($shSefUrl, 'task=blogsection') === false && strpos($shSefUrl, 'task=blogcategory') === false && strpos($shSefUrl, 'task=archivesection') === false && strpos($shSefUrl, 'task=archivecategory') === false) {
         _log('Redirecting J! sef URl to newly created SEF URL : ' . $shSefUrl);
 protected function _redirectNonSef($uri)
 {
     if (!$this->_canRedirectFromNonSef($uri)) {
         return;
     }
     // search cache and db for a sef url
     $nonSefUrl = shSortURL('index.php?' . $uri->getQuery());
     $targetSefUrl = '';
     $urlType = JModel::getInstance('Sefurls', 'Sh404sefModel')->getSefURLFromCacheOrDB($nonSefUrl, $targetSefUrl);
     $pageInfo =& Sh404sefFactory::getPageInfo();
     // found a match : redirect
     if ($urlType == sh404SEF_URLTYPE_AUTO || $urlType == sh404SEF_URLTYPE_CUSTOM) {
         $tmpUri = new JURI($uri->base() . $targetSefUrl);
         $targetSefUrl = $tmpUri->toString();
         if ($targetSefUrl != $pageInfo->shCurrentPageURL) {
             _log('redirecting non-sef to existing SEF : ' . $targetSefUrl);
             shRedirect($targetSefUrl);
         }
     }
     // haven't found a SEF in the cache or DB, maybe we can just create it on the fly ?
     if (!empty($nonSefUrl) && (!shIsMultilingual() || shIsMultilingual() == 'joomla' || shIsMultilingual() == 'joomfish' && shGetNameFromIsoCode(shDecideRequestLanguage()) == Sh404sefFactory::getPageInfo()->shMosConfig_locale)) {
         // $shMosConfig_locale is still deafult lang, as language has not been discovered yet
         $GLOBALS['mosConfig_defaultLang'] = Sh404sefFactory::getPageInfo()->shMosConfig_locale;
         // V 1.2.4.t joomfish not initialised so we must do
         // this otherwise shGetDefaultLanguage will not work
         $shUri = new JUri($nonSefUrl);
         $shOriginalUri = new JURI($nonSefUrl);
         $targetSefUrl = shSefRelToAbs($nonSefUrl, $uri->getVar('lang'), $shUri, $shOriginalUri);
         if ($targetSefUrl != $pageInfo->shCurrentPageURL) {
             if (strpos($targetSefUrl, 'option=com') === false && $targetSefUrl != $nonSefUrl) {
                 _log(__METHOD__ . '/' . __LINE__ . ': redirecting non-sef to newly created SEF : ' . $targetSefUrl . ' from ' . $nonSefUrl);
                 shRedirect($targetSefUrl);
             }
         }
     }
 }
Example #3
0
 /**
  *
  * Performs various seo redirect checks, in case where the request is
  * for the home page. A home page request only means the request path is empty;
  * such request may have query vars - ie site.com/index.php?option=com_content&id=12&view=article
  * is still a home page request
  *
  * Include redirecting site.com/index.php to site.com and, in the future
  * site.com/index.php?lang=xx to site.com/xx or the correct sef url for that language
  *
  * @param JURI object $uri
  */
 protected function _checkHomepageRedirects($uri)
 {
     if (self::$requestParsed || !$this->_canRedirectFromNonSef($uri)) {
         return;
     }
     // check if we already did all the redirections we can
     $pageInfo = Sh404sefFactory::getPageInfo();
     // basic data
     $sefConfig = Sh404sefFactory::getConfig();
     $path = $uri->getPath();
     $url = $uri->get('_uri');
     $vars = $uri->getQuery(true);
     // 1 - check index.php on home page
     $indexString = explode('?', $url);
     $indexString = JString::substr($indexString[0], -9);
     // IIS sometimes adds index.php to uri, even if user did not request it.
     $IIS = !empty($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false;
     if (sh404SEF_REDIRECT_IF_INDEX_PHP && !$IIS && empty($path) && empty($vars) && JString::substr($url, -9) == 'index.php') {
         // redirect to home page
         $targetUrl = JString::substr($url, 0, JString::strlen($url) - 9);
         _log('Redirecting home page request with index.php to home page: ' . $targetUrl);
         shRedirect($targetUrl);
     }
     // 2 - Home page, some query vars, but we don't have an option var, ie dunno what component to go to
     // just drop the index.php
     if (empty($path) && !empty($vars) && empty($vars['option']) && empty($vars['lang']) && $indexString == 'index.php') {
         $query = $uri->getQuery();
         $targetUrl = $uri->base() . (empty($query) ? '' : '?' . $query);
         _log('Redirecting home page request with index.php and query vars to home page: ' . $targetUrl);
         shRedirect($targetUrl);
     }
     // 3 - request for home page with a language element
     if (empty($path) && !empty($vars) && empty($vars['option']) && !empty($vars['lang']) && $indexString == 'index.php') {
         $query = $uri->getQuery();
         $targetUrl = $uri->base() . (empty($query) ? '' : '?' . $query);
         _log('Redirecting home page request to non-default language home page: ' . $targetUrl);
         shRedirect($targetUrl);
     }
     // 4 - Still home page, ie empty path, but some query vars, lookup db to find it
     if (empty($path) && !empty($vars) && !empty($vars['option'])) {
         // need an url model
         $urlModel =& JModel::getInstance('Sefurls', 'Sh404sefModel');
         // rebuild the non-sef url requested
         $nonSefUrl = 'index.php' . $uri->toString(array('query'));
         $sefUrl = '';
         // try to get it from our url store
         $urlType = shGetSefURLFromCacheOrDB($nonSefUrl, $sefUrl);
         if ($urlType == sh404SEF_URLTYPE_AUTO || $urlType == sh404SEF_URLTYPE_CUSTOM) {
             // found a match in database
             $sefUrl = $uri->base() . $sefUrl;
             _log('redirecting non-sef to existing SEF : ' . $sefUrl);
             shRedirect($sefUrl);
         }
         // 5 - no success yet, we'll try SEF-y the non-sef url
         if ($sefConfig->shRedirectNonSefToSef && !empty($nonSefUrl) && (!shIsMultilingual() || shIsMultilingual() !== false && shGetNameFromIsoCode(shDecideRequestLanguage()) == $pageInfo->shMosConfig_locale)) {
             $sefUrl = $uri->toString(array('scheme', 'host', 'port')) . JRoute::_($nonSefUrl, $xhtml = false);
             if (!shIsHomepage($sefUrl) && strpos($sefUrl, 'option=com') === false && $sefUrl != $url) {
                 _log('Homepage redirect to newly created SEF : ' . $sefUrl . ' from ' . $url);
                 shRedirect($sefUrl);
             }
         }
     }
 }