Example #1
0
function shInitializePlugin($lang, &$shLangName, &$shLangIso, $option)
{
    global $shMosConfig_lang, $shMosConfig_locale;
    $conf =& JFactory::getConfig();
    $configDefaultLanguage = $conf->getValue('config.language');
    $shLangName = empty($lang) ? $shMosConfig_locale : shGetNameFromIsoCode($lang);
    $shLangIso = shTranslateUrl($option, $shLangName) ? isset($lang) ? $lang : shGetIsoCodeFromName($shMosConfig_locale) : (isset($configDefaultLanguage) ? shGetIsoCodeFromName($configDefaultLanguage) : shGetIsoCodeFromName($shMosConfig_locale));
    if (strpos($shLangIso, '_') !== false) {
        //11/08/2007 14:30:16 mambo compat
        $shTemp = explode('_', $shLangIso);
        $shLangIso = $shTemp[0];
    }
    // reset pageid creation : the plugin must turn it on by itself
    shMustCreatePageId('set', false);
    // added protection : do not SEF if component is not installed. Do not attempt to build SEF URL
    // if component is not installed, or else plugin may try to read from comp DB tables. This will cause DB table names
    // to be displayed
    return !sh404SEF_CHECK_COMP_IS_INSTALLED || sh404SEF_CHECK_COMP_IS_INSTALLED && shFileExists(sh404SEF_ABS_PATH . 'components/' . $option . '/' . str_replace('com_', '', $option) . '.php');
}
 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
$shPageInfo =& Sh404sefFactory::getPageInfo();
// get page details gathered by system plugin
$sefConfig =& Sh404sefFactory::getConfig();
$database = ShlDbHelper::getDb();
$view = JREQUEST::getCmd('view', null);
$catid = JREQUEST::getInt('catid', null);
$id = JREQUEST::getInt('id', null);
$limit = JREQUEST::getInt('limit', null);
$limitstart = JREQUEST::getInt('limitstart', null);
$layout = JREQUEST::getCmd('layout', null);
$showall = JREQUEST::getInt('showall', null);
$format = JREQUEST::getCmd('format', null);
$print = JREQUEST::getInt('print', null);
$tmpl = JREQUEST::getCmd('tmpl', null);
$lang = JREQUEST::getString('lang', null);
$shLangName = empty($lang) ? $shPageInfo->currentLanguageTag : shGetNameFromIsoCode($lang);
$shLangIso = isset($lang) ? $lang : shGetIsoCodeFromName($shPageInfo->currentLanguageTag);
$shLangIso = shLoadPluginLanguage('com_content', $shLangIso, 'COM_SH404SEF_CREATE_NEW');
//-------------------------------------------------------------
global $shCustomTitleTag, $shCustomDescriptionTag, $shCustomKeywordsTag, $shCustomLangTag, $shCustomRobotsTag, $shCanonicalTag;
// special case for 404
if (!empty($shPageInfo->httpStatus) && $shPageInfo->httpStatus == 404) {
    $shCustomTitleTag = '404';
    $shCustomRobotsTag = 'noindex, follow';
    return;
}
// add no follow to print pages
$shCustomRobotsTag = $tmpl == 'component' && !empty($print) ? 'noindex, nofollow' : $shCustomRobotsTag;
// calculate page title
$title = array();
switch ($view) {
Example #4
0
$shPageInfo =& Sh404sefFactory::getPageInfo();
// get page details gathered by system plugin
$sefConfig =& Sh404sefFactory::getConfig();
$database =& JFactory::getDBO();
$view = JREQUEST::getCmd('view', null);
$catid = JREQUEST::getInt('catid', null);
$id = JREQUEST::getInt('id', null);
$limit = JREQUEST::getInt('limit', null);
$limitstart = JREQUEST::getInt('limitstart', null);
$layout = JREQUEST::getCmd('layout', null);
$showall = JREQUEST::getInt('showall', null);
$format = JREQUEST::getCmd('format', null);
$print = JREQUEST::getInt('print', null);
$tmpl = JREQUEST::getCmd('tmpl', null);
$lang = JREQUEST::getString('lang', null);
$shLangName = empty($lang) ? $shPageInfo->shMosConfig_locale : shGetNameFromIsoCode($lang);
$shLangIso = isset($lang) ? $lang : shGetIsoCodeFromName($shPageInfo->shMosConfig_locale);
$shLangIso = shLoadPluginLanguage('com_content', $shLangIso, 'COM_SH404SEF_CREATE_NEW');
//-------------------------------------------------------------
global $shCustomTitleTag, $shCustomDescriptionTag, $shCustomKeywordsTag, $shCustomLangTag, $shCustomRobotsTag, $shCanonicalTag;
// special case for 404
if (!empty($shPageInfo->httpStatus) && $shPageInfo->httpStatus == 404) {
    $shCustomTitleTag = '404';
    $shCustomRobotsTag = 'noindex, follow';
    return;
}
// add no follow to print pages
$shCustomRobotsTag = $tmpl == 'component' && !empty($print) ? 'noindex, nofollow' : $shCustomRobotsTag;
// calculate page title
$title = array();
switch ($view) {
Example #5
0
             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);
                 shRedirect($shSefUrl);
             }
         }
     }
 }
 // Loging module has a bug : action for logging out is a realtive url !!!
 if (isset($_POST['option']) && ($_POST['option'] == 'com_user' && isset($_POST['task']) && $_POST['task'] == 'logout')) {
     // we must preserve $option no matter what
     $_SERVER['QUERY_STRING'] = '';
     $REQUEST_URI = $shPageInfo->base . 'index.php';
     $_SERVER['REQUEST_URI'] = $REQUEST_URI;
     $uri = shRouter::build($GLOBALS['shConfigLiveSite'] . '/index.php');
     $shPageInfo->shCurrentPageNonSef = 'index.php';
Example #6
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);
             }
         }
     }
 }