Example #1
0
 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('&amp;', '&', $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;
 }
Example #2
0
 function shDoTitleTags(&$buffer)
 {
     // Replace TITLE and DESCRIPTION and KEYWORDS
     if (empty($buffer)) {
         return;
     }
     global $shCustomTitleTag, $shCustomDescriptionTag, $shCustomKeywordsTag, $shCustomRobotsTag, $shCustomLangTag, $shCanonicalTag;
     $database = ShlDbHelper::getDb();
     $shPageInfo =& Sh404sefFactory::getPageInfo();
     $sefConfig =& Sh404sefFactory::getConfig();
     $document = JFactory::getDocument();
     $headData = $document->getHeadData();
     // V 1.2.4.t protect against error if using shCustomtags without sh404SEF activated
     // this should not happen, so we simply do nothing
     if (!isset($sefConfig) || empty($shPageInfo->currentNonSefUrl)) {
         return;
     }
     // check if there is a manually created set of tags from tags file
     // need to get them from DB
     if ($sefConfig->shMetaManagementActivated) {
         shIncludeMetaPlugin();
         // is this homepage ? set flag for future use
         // V 1.2.4.t make sure we have lang info and properly sorted params
         if (!preg_match('/(&|\\?)lang=[a-zA-Z]{2,3}/iuU', $shPageInfo->currentNonSefUrl)) {
             // no lang string, let's add default
             $shTemp = explode('-', $shPageInfo->currentLanguageTag);
             $shLangTemp = $shTemp[0] ? $shTemp[0] : 'en';
             $shPageInfo->currentNonSefUrl .= '&lang=' . $shLangTemp;
         }
         $nonSef = shGetCurrentNonSef();
         $isHome = $nonSef == shSortUrl(shCleanUpAnchor(Sh404sefFactory::getPageInfo()->homeLink));
         $shCustomTags = shGetCustomMetaData($isHome ? sh404SEF_HOMEPAGE_CODE : $nonSef);
         // J! 2.5 finder canonical handling/hack
         $highlight = shGetURLVar($nonSef, 'highlight', null);
         if (!empty($highlight) && empty($shCanonicalTag)) {
             $searchCanoNonSef = str_replace('?highlight=' . $highlight, '', $nonSef);
             $searchCanoNonSef = str_replace('&highlight=' . $highlight, '', $searchCanoNonSef);
             $shCanonicalTag = JRoute::_($searchCanoNonSef);
         }
         $tagsToInsert = '';
         // group new tags insertion, better perf
         if (!empty($shCustomTags)) {
             $shCustomTitleTag = !empty($shCustomTags->metatitle) ? $shCustomTags->metatitle : $shCustomTitleTag;
             $shCustomDescriptionTag = !empty($shCustomTags->metadesc) ? $shCustomTags->metadesc : $shCustomDescriptionTag;
             $shCustomKeywordsTag = !empty($shCustomTags->metakey) ? $shCustomTags->metakey : $shCustomKeywordsTag;
             $shCustomRobotsTag = !empty($shCustomTags->metarobots) ? $shCustomTags->metarobots : $shCustomRobotsTag;
             $shCustomLangTag = !empty($shCustomTags->metalang) ? $shCustomTags->metalang : $shCustomLangTag;
             $shCanonicalTag = !empty($shCustomTags->canonical) ? $shCustomTags->canonical : $shCanonicalTag;
         }
         // then insert them in page
         if (empty($shCustomTitleTag)) {
             $shCustomTitleTag = $document->getTitle();
         }
         if (!empty($shCustomTitleTag)) {
             $prepend = $isHome ? '' : $sefConfig->prependToPageTitle;
             $append = $isHome ? '' : $sefConfig->appendToPageTitle;
             $shPageInfo->pageTitle = htmlspecialchars(shCleanUpTitle($prepend . $shCustomTitleTag . $append), ENT_COMPAT, 'UTF-8');
             $buffer = ShlSystem_Strings::pr('/\\<\\s*title\\s*\\>.*\\<\\s*\\/title\\s*\\>/isuU', '<title>' . $shPageInfo->pageTitle . '</title>', $buffer);
             $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"title.*\\/\\>/isuU', '', $buffer);
             // remove any title meta
         }
         if (!is_null($shCustomDescriptionTag)) {
             $t = htmlspecialchars(shCleanUpDesc($shCustomDescriptionTag), ENT_COMPAT, 'UTF-8');
             $shPageInfo->pageDescription = ShlSystem_Strings::pr('#\\$([0-9]*)#u', '\\\\$${1}', $t);
             if (strpos($buffer, '<meta name="description" content=') !== false) {
                 $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"description.*\\/\\>/isUu', '<meta name="description" content="' . $shPageInfo->pageDescription . '" />', $buffer);
             } else {
                 $tagsToInsert .= "\n" . '<meta name="description" content="' . $shPageInfo->pageDescription . '" />';
             }
         } else {
             // read Joomla! description if none set by us
             if (empty($shPageInfo->pageDescription)) {
                 $shPageInfo->pageDescription = empty($headData['description']) ? '' : htmlspecialchars(shCleanUpDesc($headData['description']), ENT_COMPAT, 'UTF-8');
             }
         }
         if (!is_null($shCustomKeywordsTag)) {
             $t = htmlspecialchars(shCleanUpDesc($shCustomKeywordsTag), ENT_COMPAT, 'UTF-8');
             $shPageInfo->pageKeywords = ShlSystem_Strings::pr('#\\$([0-9]*)#u', '\\\\$${1}', $t);
             if (strpos($buffer, '<meta name="keywords" content=') !== false) {
                 $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"keywords.*\\/\\>/isUu', '<meta name="keywords" content="' . $shPageInfo->pageKeywords . '" />', $buffer);
             } else {
                 $tagsToInsert .= "\n" . '<meta name="keywords" content="' . $shPageInfo->pageKeywords . '" />';
             }
         } else {
             // read Joomla! description if none set by us
             if (empty($shPageInfo->pageKeywords)) {
                 $shPageInfo->pageKeywords = empty($headData['metaTags']['standard']['keywords']) ? '' : htmlspecialchars(shCleanUpDesc($headData['metaTags']['standard']['keywords']), ENT_COMPAT, 'UTF-8');
             }
         }
         if (!is_null($shCustomRobotsTag)) {
             $shPageInfo->pageRobotsTag = $shCustomRobotsTag;
             if (strpos($buffer, '<meta name="robots" content="') !== false) {
                 $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+name\\s*=\\s*"robots.*\\/\\>/isUu', '<meta name="robots" content="' . $shCustomRobotsTag . '" />', $buffer);
             } else {
                 if (!empty($shCustomRobotsTag)) {
                     $tagsToInsert .= "\n" . '<meta name="robots" content="' . $shCustomRobotsTag . '" />';
                 }
             }
         } else {
             // read Joomla! description if none set by us
             if (empty($shPageInfo->pageRobotsTag)) {
                 $shPageInfo->pageRobotsTag = empty($headData['metaTags']['standard']['robots']) ? '' : htmlspecialchars(shCleanUpDesc($headData['metaTags']['standard']['robots']), ENT_COMPAT, 'UTF-8');
             }
         }
         if (!is_null($shCustomLangTag)) {
             $shLang = $shCustomLangTag;
             $shPageInfo->pageLangTag = $shCustomLangTag;
             if (strpos($buffer, '<meta http-equiv="Content-Language"') !== false) {
                 $buffer = ShlSystem_Strings::pr('/\\<\\s*meta\\s+http-equiv\\s*=\\s*"Content-Language".*\\/\\>/isUu', '<meta http-equiv="Content-Language" content="' . $shCustomLangTag . '" />', $buffer);
             } else {
                 $tagsToInsert .= "\n" . '<meta http-equiv="Content-Language" content="' . $shCustomLangTag . '" />';
             }
         }
         // custom handling of canonical
         $canonicalPattern = '/\\<\\s*link[^>]+rel\\s*=\\s*"canonical[^>]+\\/\\>/isUu';
         $matches = array();
         $canonicalCount = preg_match_all($canonicalPattern, $buffer, $matches);
         // more than one canonical already: kill them all
         if ($canonicalCount > 1 && Sh404sefFactory::getConfig()->removeOtherCanonicals) {
             $buffer = ShlSystem_Strings::pr($canonicalPattern, '', $buffer);
             $canonicalCount = 0;
         }
         // more than one and J3: must be the one inserted by J3 SEF plugin
         if ($canonicalCount > 0 && Sh404sefFactory::getConfig()->removeOtherCanonicals && version_compare(JVERSION, '3.0', 'ge')) {
             // kill it, if asked to
             $buffer = ShlSystem_Strings::pr($canonicalPattern, '', $buffer);
             $canonicalCount = 0;
         }
         // if there' a custom canonical for that page, insert it, or replace any existing ones
         if (!empty($shCanonicalTag) && $canonicalCount == 0) {
             // insert a new canonical
             $tagsToInsert .= "\n" . '<link href="' . htmlspecialchars($shCanonicalTag, ENT_COMPAT, 'UTF-8') . '" rel="canonical" />' . "\n";
         } else {
             if (!empty($shCanonicalTag)) {
                 // replace existing canonical
                 $buffer = ShlSystem_Strings::pr($canonicalPattern, '<link href="' . htmlspecialchars($shCanonicalTag, ENT_COMPAT, 'UTF-8') . '" rel="canonical" />', $buffer);
             }
         }
         // insert all tags in one go
         if (!empty($tagsToInsert)) {
             $buffer = shInsertCustomTagInBuffer($buffer, '<head>', 'after', $tagsToInsert, 'first');
         }
         // remove Generator tag
         if ($sefConfig->shRemoveGeneratorTag) {
             $buffer = ShlSystem_Strings::pr('/<meta\\s*name="generator"\\s*content=".*\\/>/isUu', '', $buffer);
         }
         // put <h1> tags around content elements titles
         if ($sefConfig->shPutH1Tags) {
             if (strpos($buffer, 'class="componentheading') !== false) {
                 $buffer = ShlSystem_Strings::pr('/<div class="componentheading([^>]*)>\\s*(.*)\\s*<\\/div>/isUu', '<div class="componentheading$1><h1>$2</h1></div>', $buffer);
                 $buffer = ShlSystem_Strings::pr('/<td class="contentheading([^>]*)>\\s*(.*)\\s*<\\/td>/isUu', '<td class="contentheading$1><h2>$2</h2></td>', $buffer);
             } else {
                 // replace contentheading by h1
                 $buffer = ShlSystem_Strings::pr('/<td class="contentheading([^>]*)>\\s*(.*)\\s*<\\/td>/isUu', '<td class="contentheading$1><h1>$2</h1></td>', $buffer);
             }
         }
         // version x : if multiple h1 headings, replace them by h2
         if ($sefConfig->shMultipleH1ToH2 && substr_count(JString::strtolower($buffer), '<h1>') > 1) {
             $buffer = str_replace('<h1>', '<h2>', $buffer);
             $buffer = str_replace('<H1>', '<h2>', $buffer);
             $buffer = str_replace('</h1>', '</h2>', $buffer);
             $buffer = str_replace('</H1>', '</h2>', $buffer);
         }
         // V 1.3.1 : replace outbounds links by internal redirects
         if (sh404SEF_REDIRECT_OUTBOUND_LINKS) {
             $tmp = preg_replace_callback('/<\\s*a\\s*href\\s*=\\s*"(.*)"/isUu', 'shDoRedirectOutboundLinksCallback', $buffer);
             if (empty($tmp)) {
                 ShlSystem_Log::error('shlib', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, 'RegExp failed: invalid character on page ' . Sh404sefFactory::getPageInfo()->currentSefUrl);
             } else {
                 $buffer = $tmp;
             }
         }
         // V 1.3.1 : add symbol to outbounds links
         if ($sefConfig->shInsertOutboundLinksImage) {
             $tmp = preg_replace_callback("/<\\s*a\\s*href\\s*=\\s*(\"|').*(\"|')\\s*>.*<\\/a>/isUu", 'shDoInsertOutboundLinksImageCallback', $buffer);
             if (empty($tmp)) {
                 ShlSystem_Log::error('shlib', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, 'RegExp failed: invalid character on page ' . Sh404sefFactory::getPageInfo()->currentSefUrl);
             } else {
                 $buffer = $tmp;
             }
         }
         // fix homepage link when using Joomfish in non default languages, error in joomla mainmenu helper
         /*
         if (sh404SEF_PROTECT_AGAINST_BAD_NON_DEFAULT_LANGUAGE_MENU_HOMELINK && !shIsDefaultLang( $shPageInfo->currentLanguageTag)) {
         			$badHomeLink = preg_quote(JURI::base());
         			$targetLang = explode( '-', $shPageInfo->currentLanguageTag);
         			$goodHomeLink = rtrim(JURI::base(), '/') . $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode] . $targetLang[0] . '/';
         			$buffer = preg_replace( '#<div class="module_menu(.*)href="' . $badHomeLink . '"#isU',
            '<div class="module_menu$1href="' . $goodHomeLink . '"', $buffer);
         			$buffer = preg_replace( '#<div class="moduletable_menu(.*)href="' . $badHomeLink . '"#isU',
            '<div class="moduletable_menu$1href="' . $goodHomeLink . '"', $buffer);
         			}
         */
         // all done
         return $buffer;
     }
 }
Example #3
0
 public static function extractTrackingVarsFromNonSef($url, &$existingVars, $keepThem = false)
 {
     $trackingVars = self::_getTrackingVars();
     foreach ($trackingVars as $var) {
         // collect existing value, if any
         $value = shGetURLVar($url, $var, null);
         if (!is_null($value)) {
             // store extracted value into passed array
             $existingVars[$var] = $value;
         }
         // still remove var from url
         if (!$keepThem) {
             $url = shCleanUpVar($url, $var);
         }
     }
     return $url;
 }
Example #4
0
function shSefRelToAbs($string, $shLanguageParam, &$uri, &$originalUri)
{
    global $_SEF_SPACE, $shMosConfig_lang, $shMosConfig_locale, $mainframe, $shGETVars, $shRebuildNonSef, $shHomeLink;
    _log('Entering shSefRelToAbs with ' . $string . ' | Lang = ' . $shLanguageParam);
    // if superadmin, display non-sef URL, for testing/setting up purposes
    if (sh404SEF_NON_SEF_IF_SUPERADMIN) {
        $user = JFactory::getUser();
        if ($user->usertype == 'Super Administrator') {
            _log('Returning non-sef because superadmin said so.');
            return 'index.php';
        }
    }
    // return unmodified anchors
    if (JString::substr($string, 0, 1) == '#') {
        // V 1.2.4.t
        return $string;
    }
    $sefConfig =& shRouter::shGetConfig();
    $shPageInfo =& shRouter::shPageInfo();
    // Quick fix for shared SSL server : if https, switch to non sef
    $id = shGetURLVar($string, 'Itemid', JRequest::getInt('Itemid'));
    $secure = !empty($shPageInfo->shHttpsSave) || 'yes' == shGetMenuItemSsl($id);
    if ($secure && $sefConfig->shForceNonSefIfHttps) {
        _log('Returning shSefRelToAbs : Forced non sef if https');
        return shFinalizeURL($string);
    }
    $database =& JFactory::getDBO();
    $shOrigString = $string;
    $shMosMsg = shGetMosMsg($string);
    // V x 01/09/2007 22:45:52
    $string = shCleanUpMosMsg($string);
    // V x 01/09/2007 22:45:52
    // V x : removed shJoomfish module. Now we set $mosConfi_lang here
    $shOrigLang = $shMosConfig_locale;
    // save current language
    $shLanguage = shGetURLLang($string);
    // target language in URl is always first choice
    if (empty($shLanguage)) {
        $shLanguage = !empty($shLanguageParam) ? $shLanguageParam : $shMosConfig_locale;
    }
    // V 1.3.1 protect against those drop down lists
    if (strpos($string, 'this.options[selectedIndex].value') !== false) {
        $string .= '&amp;lang=' . shGetIsoCodeFromName($shLanguage);
        return $string;
    }
    $shMosConfig_locale = $shLanguage;
    _log('Language used : ' . $shLanguage);
    // V 1.2.4.t workaround for old links like option=compName instead of option=com_compName
    if (strpos(strtolower($string), 'option=login') === false && strpos(strtolower($string), 'option=logout') === false && strpos(strtolower($string), 'option=&') === false && JString::substr(strtolower($string), -7) != 'option=' && strpos(strtolower($string), 'option=cookiecheck') === false && strpos(strtolower($string), 'option=') !== false && strpos(strtolower($string), 'option=com_') === false) {
        $string = str_replace('option=', 'option=com_', $string);
    }
    // V 1.2.4.k added homepage check : needed in case homepage is not com_frontpage
    if (empty($shHomeLink)) {
        // first, find out about homepage link, from DB. homepage is not always /index.php or similar
        // it can be a link to anything, a page, a component,...
        $menu =& shRouter::shGetMenu();
        $shHomePage =& $menu->getDefault();
        if ($shHomePage) {
            if (JString::substr($shHomePage->link, 0, 9) == 'index.php' && !preg_match('/Itemid=[0-9]*/', $shHomePage->link)) {
                // and it does not have an Itemid
                $shHomePage->link .= ($shHomePage->link == 'index.php' ? '?' : '&') . 'Itemid=' . $shHomePage->id;
                // then add itemid
            }
            $shHomeLink = $shHomePage->link;
            if (!strpos($shHomeLink, 'lang=')) {
                // V 1.2.4.q protect against not existing
                $shDefaultIso = shGetIsoCodeFromName(shGetDefaultLang());
                $shSepString = JString::substr($shHomeLink, -9) == 'index.php' ? '?' : '&';
                $shHomeLink .= $shSepString . 'lang=' . $shDefaultIso;
            }
            $shHomeLink = shSortUrl($shHomeLink);
            // $shHomeLink has lang info, whereas $homepage->link may or may not
        }
        _log('HomeLink = ' . $shHomeLink);
    }
    // V 1.2.4.j string to be appended to URL, but not saved to DB
    $shAppendString = '';
    $shRebuildNonSef = array();
    $shComponentType = '';
    // V w initialize var to avoid notices
    if ($shHomeLink) {
        // now check URL against our homepage, so as to always return / if homepage
        $v1 = JString::ltrim(str_replace($GLOBALS['shConfigLiveSite'], '', $string), '/');
        // V 1.2.4.m : remove anchor if any
        $v2 = explode('#', $v1);
        $v1 = $v2[0];
        $shAnchor = isset($v2[1]) ? '#' . $v2[1] : '';
        $shSepString = JString::substr($v1, -9) == 'index.php' ? '?' : '&';
        $shLangString = $shSepString . 'lang=' . shGetIsoCodeFromName($shLanguage);
        if (!strpos($v1, 'lang=')) {
            $v1 .= $shLangString;
        }
        $v1 = str_replace('&amp;', '&', shSortURL($v1));
        // V 1.2.4.t check also without pagination info
        if (strpos($v1, 'limitstart=0') !== false) {
            // the page has limitstart=0
            $stringNoPag = shCleanUpPag($v1);
            // remove paging info to be sure this is not homepage
        } else {
            $stringNoPag = null;
        }
        if ($v1 == $shHomeLink || $v1 == 'index.php' . $shLangString || $stringNoPag == $shHomeLink) {
            // V 1.2.4.t 24/08/2007 11:07:49
            $shTemp = $v1 == $shHomeLink || shIsDefaultLang($shLanguage) ? '' : shGetIsoCodeFromName($shLanguage) . '/';
            //10/08/2007 17:28:14
            if (!empty($shMosMsg)) {
                // V x 01/09/2007 22:48:01
                $shTemp .= '?' . $shMosMsg;
            }
            if (!empty($sefConfig->shForcedHomePage)) {
                // V 1.2.4.t
                $shTmp = $shTemp . $shAnchor;
                $ret = shFinalizeURL($sefConfig->shForcedHomePage . (empty($shTmp) ? '' : '/' . $shTmp));
                if (empty($uri)) {
                    // if no URI, append remaining vars directly to the string
                    $ret .= $shAppendString;
                } else {
                    shRebuildVars($shAppendString, $uri);
                }
                $shMosConfig_locale = $shOrigLang;
                _log('Returning shSefRelToAbs 1 with ' . $ret);
                return $ret;
            } else {
                $shRewriteBit = shIsDefaultLang($shLanguage) ? '/' : $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode];
                $ret = shFinalizeURL($GLOBALS['shConfigLiveSite'] . $shRewriteBit . $shTemp . $shAnchor);
                if (empty($uri)) {
                    // if no URI, append remaining vars directly to the string
                    $ret .= $shAppendString;
                } else {
                    shRebuildVars($shAppendString, $uri);
                }
                $shMosConfig_locale = $shOrigLang;
                _log('Returning shSefRelToAbs 2 with ' . $ret);
                return $ret;
            }
        }
    }
    $newstring = str_replace($GLOBALS['shConfigLiveSite'] . '/', '', $string);
    // check for url to same site, but with SSL : Joomla 1.5 does not allow it yet
    //$liveSiteSsl = str_replace('http://', 'https://', $GLOBALS['shConfigLiveSite']);
    //$newStringSsl = str_replace($liveSiteSsl.'/', '', $string);
    $letsGo = JString::substr($newstring, 0, 9) == 'index.php' && strpos($newstring, 'this.options[selectedIndex\\].value') === false;
    $letsGoSsl = false;
    if ($letsGo || $letsGoSsl) {
        // Replace & character variations.
        $string = str_replace(array('&amp;', '&#38;'), array('&', '&'), $letsGo ? $newstring : $newStringSsl);
        $newstring = $string;
        // V 1.2.4.q
        $shSaveString = $string;
        // warning : must add &lang=xx (only if it does not exists already), so as to be able to recognize the SefURL in the db if it's there
        if (!strpos($string, 'lang=')) {
            $shSepString = JString::substr($string, -9) == 'index.php' ? '?' : '&';
            $anchorTable = explode('#', $string);
            // V 1.2.4.m remove anchor before adding language
            $string = $anchorTable[0];
            $string .= $shSepString . 'lang=' . shGetIsoCodeFromName($shLanguage) . (!empty($anchorTable[1]) ? '#' . $anchorTable[1] : '');
            // V 1.2.4.m then stitch back anchor
        }
        $URI = new sh_Net_URL($string);
        // V 1.2.4.l need to save unsorted URL
        if (count($URI->querystring) > 0) {
            // Import new vars here.
            $option = null;
            $task = null;
            //$sid = null;  V 1.2.4.s
            // sort GET parameters to avoid some issues when same URL is produced with options not
            // in the same order, ie index.php?option=com_virtuemart&category_id=3&Itemid=2&lang=fr
            // Vs index.php?category_id=3&option=com_virtuemart&Itemid=2&lang=fr
            ksort($URI->querystring);
            // sort URL array
            $string = shSortUrl($string);
            // now we are ready to extract vars
            $shGETVars = $URI->querystring;
            extract($URI->querystring, EXTR_REFS);
        }
        if (empty($option)) {
            // V 1.2.4.r protect against empty $option : we won't know what to do
            $shMosConfig_locale = $shOrigLang;
            _log('Returning shSefRelToAbs 3 with ' . $shOrigString);
            return $shOrigString;
        }
        // get plugin associated with the extension
        $extPlugin =& Sh404sefFactory::getExtensionPlugin($option);
        // get component type
        $shComponentType = $extPlugin->getComponentType();
        $shOption = str_replace('com_', '', $option);
        //list of extension we always skip
        $alwaysSkip = array('jce', 'akeeba');
        if (in_array($shOption, $alwaysSkip)) {
            $shComponentType = Sh404sefClassBaseextplugin::TYPE_SKIP;
        }
        // V 1.2.4.s : fallback to to JoomlaSEF if no extension available
        // V 1.2.4.t : this is too early ; it prevents manual custom redirect to be checked agains the requested non-sef URL
        _log('Component type = ' . $shComponentType);
        // is there a named anchor attached to $string? If so, strip it off, we'll put it back later.
        if ($URI->anchor) {
            $string = str_replace('#' . $URI->anchor, '', $string);
        }
        // V 1.2.4.m
        // shumisha special homepage processing (in other than default language)
        if (shIsHomePage($string) || $string == 'index.php') {
            $sefstring = '';
            $urlType = shGetSefURLFromCacheOrDB($string, $sefstring);
            // still use it so we need it both ways
            if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty($showall) && (!empty($limit) || !isset($limit) && !empty($limitstart))) {
                $urlType = shGetSefURLFromCacheOrDB(shCleanUpPag($string), $sefstring);
                // V 1.2.4.t check also without page info
                //to be able to add pagination on custom
                //redirection or multi-page homepage
                if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) {
                    $sefstring = shAddPaginationInfo(@$limit, @$limitstart, @showall, 1, $string, $sefstring, null);
                    // a special case : com_content  does not calculate pagination right
                    // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
                    // For instance, with joomla sample data, the frontpage has only 5 articles
                    // but the view sets $limit to 9 !!!
                    if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'frontpage') {
                        $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
                        $string = shSetURLVar($string, 'limit', $listLimit);
                        $string = shSortUrl($string);
                    }
                    // that's a new URL, so let's add it to DB and cache
                    shAddSefUrlToDBAndCache($string, $sefstring, 0, $urlType);
                    // created url must be of same type as original
                }
                if ($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) {
                    require_once sh404SEF_FRONT_ABS_PATH . 'sef_ext.php';
                    $sef_ext = new sef_404();
                    // Rewrite the URL now.
                    // a special case : com_content  does not calculate pagination right
                    // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
                    // For instance, with joomla sample data, the frontpage has only 5 articles
                    // but the view sets $limit to 9 !!!
                    if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'frontpage') {
                        $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
                        $string = shSetURLVar($string, 'limit', $listLimit);
                        $string = shSortUrl($string);
                        //$URI->addQueryString( 'limit', $listLimit);
                    }
                    $urlVars = is_array($URI->querystring) ? array_map('urldecode', $URI->querystring) : $URI->querystring;
                    $sefstring = $sef_ext->create($string, $urlVars, $shAppendString, $shLanguage, $shOrigString, $originalUri);
                    // V 1.2.4.s added original string
                }
            } else {
                if ($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) {
                    // not found but no $limit or $limitstart
                    $sefstring = shGetIsoCodeFromName($shLanguage) . '/';
                    shAddSefUrlToDBAndCache($string, $sefstring, 0, sh404SEF_URLTYPE_AUTO);
                    // create it
                }
            }
            // V 1.2.4.j : added $shAppendString to pass non sef parameters. For use with parameters that won't be stored in DB
            $ret = $GLOBALS['shConfigLiveSite'] . (empty($sefstring) ? '' : $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode] . $sefstring);
            // not valid with 1.5 anymore                       ;
            //if (!empty($shMosMsg)) // V x 01/09/2007 22:48:01
            //  $ret .= (empty($shAppendString) || $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode] == '/index.php?/' ? '?':'&').$shMosMsg;
            $ret = shFinalizeURL($ret);
            if (empty($uri)) {
                // if no URI, append remaining vars directly to the string
                $ret .= $shAppendString;
            } else {
                shRebuildVars($shAppendString, $uri);
            }
            $shMosConfig_locale = $shOrigLang;
            _log('Returning shSefRelToAbs 4 with ' . $ret);
            return $ret;
        }
        if (isset($option) && !($option == 'com_content' && @$task == 'edit') && strtolower($option) != 'com_sh404sef') {
            // V x 29/08/2007 23:19:48
            // check also that option = com_content, otherwise, breaks some comp
            switch ($shComponentType) {
                case Sh404sefClassBaseextplugin::TYPE_SKIP:
                    $sefstring = $shSaveString;
                    // V 1.2.4.q : restore untouched URL, except anchor
                    // which will be added later
                    break;
                case Sh404sefClassBaseextplugin::TYPE_SIMPLE:
                    /* case 'sh404SEFFallback': // v 1.2.4.t*/
                    // check for custom urls
                    $sefstring = '';
                    $urlType = shGetSefURLFromCacheOrDB($string, $sefstring);
                    // if no custom found, then build default url
                    if ($urlType != sh404SEF_URLTYPE_CUSTOM) {
                        // if not found then fall back to Joomla! SEF
                        if (isset($URI)) {
                            unset($URI);
                        }
                        $sefstring = 'component/';
                        $URI = new sh_Net_URL(shSortUrl($shSaveString));
                        if (count($URI->querystring) > 0) {
                            foreach ($URI->querystring as $key => $value) {
                                if (is_array($value)) {
                                    foreach ($value as $k => $v) {
                                        // fix for arrays, thanks doorknob
                                        $sefstring .= $key . '[' . $k . '],' . $v . '/';
                                    }
                                } else {
                                    $sefstring .= $key . ',' . $value . '/';
                                }
                            }
                            $sefstring = str_replace('option/', '', $sefstring);
                        }
                    }
                    break;
                default:
                    $sefstring = '';
                    // base case:
                    $urlType = shGetSefURLFromCacheOrDB($string, $sefstring);
                    // first special case. User may have customized paginated urls
                    // this will be picked up by the line above, except if we're talking about
                    // a category or section blog layout, where Joomla does not uses the correct
                    // value for limit
                    if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty($showall) && (!empty($limit) || !isset($limit) && !empty($limitstart))) {
                        if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'frontpage') {
                            $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
                            $tmpString = shSetURLVar($string, 'limit', $listLimit);
                            $tmpString = shSortUrl($tmpString);
                            $urlType = shGetSefURLFromCacheOrDB($tmpString, $sefstring);
                            if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) {
                                // we found a match with pagination info!
                                $string = $tmpString;
                            }
                        }
                    }
                    // now let's try again without any pagination at all
                    if (($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) && empty($showall) && (!empty($limit) || !isset($limit) && !empty($limitstart))) {
                        $urlType = shGetSefURLFromCacheOrDB(shCleanUpPag($string), $sefstring);
                        // search without pagination info
                        if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) {
                            $sefstring = shAddPaginationInfo(@$limit, @$limitstart, @showall, 1, $string, $sefstring, null);
                            // a special case : com_content  does not calculate pagination right
                            // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
                            // For instance, with joomla sample data, the frontpage has only 5 articles
                            // but the view sets $limit to 9 !!!
                            if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'frontpage') {
                                $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
                                $string = shSetURLVar($string, 'limit', $listLimit);
                                $string = shSortUrl($string);
                            }
                            // that's a new URL, so let's add it to DB and cache
                            _log('Created url based on non paginated base url:' . $string);
                            shAddSefUrlToDBAndCache($string, $sefstring, 0, $urlType);
                        }
                    }
                    if ($urlType == sh404SEF_URLTYPE_NONE) {
                        // If component has its own sef_ext plug-in included.
                        $shDoNotOverride = in_array($shOption, $sefConfig->shDoNotOverrideOwnSef);
                        if (shFileExists(sh404SEF_ABS_PATH . 'components/' . $option . '/sef_ext.php') && ($shDoNotOverride || !$shDoNotOverride && (!shFileExists(sh404SEF_ABS_PATH . 'components/com_sh404sef/sef_ext/' . $option . '.php') && !shFileExists(sh404SEF_ABS_PATH . 'components/' . $option . '/sef_ext/' . $option . '.php')))) {
                            // Load the plug-in file. V 1.2.4.s changed require_once to include
                            include_once sh404SEF_ABS_PATH . 'components/' . $option . '/sef_ext.php';
                            $_SEF_SPACE = $sefConfig->replacement;
                            $comp_name = str_replace('com_', '', $option);
                            $className = 'sef_' . $comp_name;
                            $sef_ext = new $className();
                            // V x : added default string in params
                            if (empty($sefConfig->defaultComponentStringList[$comp_name])) {
                                $title[] = getMenuTitle($option, null, isset($Itemid) ? @$Itemid : null, null, $shLanguage);
                            } else {
                                $title[] = $sefConfig->defaultComponentStringList[$comp_name];
                            }
                            // V 1.2.4.r : clean up URL BEFORE sending it to sef_ext files, to have control on what they do
                            // remove lang information, we'll put it back ourselves later
                            //$shString = preg_replace( '/(&|\?)lang=[a-zA-Z]{2,3}/iU' ,'', $string);
                            // V 1.2.4.t use original non-sef string. Some sef_ext files relies on order of params, which may
                            // have been changed by sh404SEF
                            $shString = preg_replace('/(&|\\?)lang=[a-zA-Z]{2,3}/iU', '', $shSaveString);
                            $finalstrip = explode("|", $sefConfig->stripthese);
                            $shString = str_replace('&', '&amp;', $shString);
                            _log('Sending to own sef_ext.php plugin : ' . $shString);
                            $sefstring = $sef_ext->create($shString);
                            _log('Created by sef_ext.php plugin : ' . $sefstring);
                            $sefstring = str_replace("%10", "%2F", $sefstring);
                            $sefstring = str_replace("%11", $sefConfig->replacement, $sefstring);
                            $sefstring = rawurldecode($sefstring);
                            if ($sefstring == $string) {
                                if (!empty($shMosMsg)) {
                                    // V x 01/09/2007 22:48:01
                                    $string .= '?' . $shMosMsg;
                                }
                                $ret = shFinalizeURL($string);
                                $shMosConfig_locale = $shOrigLang;
                                _log('Returning shSefRelToAbs 5 with ' . $ret);
                                return $ret;
                            } else {
                                // V 1.2.4.p : sef_ext extensions for opensef/SefAdvance do not always replace '
                                $sefstring = str_replace('\'', $sefConfig->replacement, $sefstring);
                                // some ext. seem to html_special_chars URL ?
                                $sefstring = str_replace('&#039;', $sefConfig->replacement, $sefstring);
                                // V w 27/08/2007 13:23:56
                                $sefstring = str_replace(' ', $_SEF_SPACE, $sefstring);
                                $sefstring = str_replace(' ', '', (shInsertIsoCodeInUrl($option, $shLanguage) ? shGetIsoCodeFromName($shLanguage) . '/' : '') . titleToLocation($title[0]) . '/' . $sefstring . ($sefstring != '' ? $sefConfig->suffix : ''));
                                if (!empty($sefConfig->suffix)) {
                                    $sefstring = str_replace('/' . $sefConfig->suffix, $sefConfig->suffix, $sefstring);
                                }
                                //$finalstrip = explode("|", $sefConfig->stripthese);
                                $sefstring = str_replace($finalstrip, $sefConfig->replacement, $sefstring);
                                $sefstring = str_replace($sefConfig->replacement . $sefConfig->replacement . $sefConfig->replacement, $sefConfig->replacement, $sefstring);
                                $sefstring = str_replace($sefConfig->replacement . $sefConfig->replacement, $sefConfig->replacement, $sefstring);
                                $suffixthere = 0;
                                if (!empty($sefConfig->suffix) && strpos($sefstring, $sefConfig->suffix) !== false) {
                                    // V 1.2.4.s
                                    $suffixthere = strlen($sefConfig->suffix);
                                }
                                $takethese = str_replace("|", "", $sefConfig->friendlytrim);
                                $sefstring = JString::trim(JString::substr($sefstring, 0, strlen($sefstring) - $suffixthere), $takethese);
                                $sefstring .= $suffixthere == 0 ? '' : $sefConfig->suffix;
                                // version u 26/08/2007 17:27:16
                                // V 1.2.4.m store it in DB so as to be able to use sef_ext plugins really !
                                $string = str_replace('&amp;', '&', $string);
                                // V 1.2.4.r without mod_rewrite
                                $shSefString = shAdjustToRewriteMode($sefstring);
                                // V 1.2.4.p check for various URL for same content
                                $dburl = '';
                                // V 1.2.4.t prevent notice error
                                $urlType = sh404SEF_URLTYPE_NONE;
                                if ($sefConfig->shUseURLCache) {
                                    $urlType = Sh404sefHelperCache::getNonSefUrlFromCache($shSefString, $dburl);
                                }
                                $newMaxRank = 0;
                                // V 1.2.4.s
                                $shDuplicate = false;
                                if ($sefConfig->shRecordDuplicates || $urlType == sh404SEF_URLTYPE_NONE) {
                                    // V 1.2.4.q + V 1.2.4.s+t
                                    $sql = "SELECT newurl, rank, dateadd FROM #__redirection WHERE oldurl = " . $database->Quote($shSefString) . " ORDER BY rank ASC";
                                    $database->setQuery($sql);
                                    $dbUrlList = $database->loadObjectList();
                                    if (count($dbUrlList) > 0) {
                                        $dburl = $dbUrlList[0]->newurl;
                                        $newMaxRank = $dbUrlList[count($dbUrlList) - 1]->rank + 1;
                                        $urlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM;
                                    }
                                }
                                if ($urlType != sh404SEF_URLTYPE_NONE && $dburl != $string) {
                                    $shDuplicate = true;
                                }
                                $urlType = $urlType == sh404SEF_URLTYPE_NONE ? sh404SEF_URLTYPE_AUTO : $urlType;
                                _log('Adding from sef_ext to DB : ' . $shSefString . ' | rank = ' . ($shDuplicate ? $newMaxRank : 0));
                                shAddSefUrlToDBAndCache($string, $shSefString, $shDuplicate ? $newMaxRank : 0, $urlType);
                            }
                        } else {
                            $string = JString::trim($string, "&?");
                            // V 1.2.4.q a trial in better handling homepage articles
                            if (shIsCurrentPageHome() && $option == 'com_content' && isset($task) && $task == 'view' && $sefConfig->guessItemidOnHomepage) {
                                $string = preg_replace('/(&|\\?)Itemid=[^&]*/i', '', $string);
                                // we remove Itemid, as com_content plugin
                                $Itemid = null;
                                // will hopefully do a better job at finding the right one
                                unset($URI->querystring['Itemid']);
                                unset($shGETVars['Itemid']);
                            }
                            require_once sh404SEF_FRONT_ABS_PATH . 'sef_ext.php';
                            $sef_ext = new sef_404();
                            // Rewrite the URL now. // V 1.2.4.s added original string
                            // a special case : com_content  does not calculate pagination right
                            // for frontpage and blog, they include links shown at the bottom in the calculation of number of items
                            // For instance, with joomla sample data, the frontpage has only 5 articles
                            // but the view sets $limit to 9 !!!
                            if ($option == 'com_content' && isset($layout) && $layout == 'blog' || $option == 'com_content' && isset($view) && $view == 'frontpage') {
                                $listLimit = shGetDefaultDisplayNumFromURL($string, $includeBlogLinks = true);
                                $string = shSetURLVar($string, 'limit', $listLimit);
                                $string = shSortUrl($string);
                                //$URI->addQueryString( 'limit', $listLimit);
                            }
                            $sefstring = $sef_ext->create($string, $URI->querystring, $shAppendString, $shLanguage, $shOrigString, $originalUri);
                            _log('Created sef url from default plugin: ' . $sefstring);
                        }
                    }
            }
            // end of cache check shumisha
            if (isset($sef_ext)) {
                unset($sef_ext);
            }
            // V 1.2.4.j
            // V 1.2.4.r : checked for double //
            // V 1.2.4.r try sef without mod_rewrite
            $shRewriteBit = $shComponentType == Sh404sefClassBaseextplugin::TYPE_SKIP ? '/' : $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode];
            if (strpos($sefstring, 'index.php') === 0) {
                $shRewriteBit = '/';
            }
            // V 1.2.4.t bug #119
            $string = $GLOBALS['shConfigLiveSite'] . $shRewriteBit . JString::ltrim($sefstring, '/') . ($URI->anchor ? "#" . $URI->anchor : '');
        } else {
            // V x 03/09/2007 13:47:37 editing content
            $shComponentType = Sh404sefClassBaseextplugin::TYPE_SKIP;
            // will prevent turning & into &amp;
            _log('shSefrelfToAbs: option not set, skipping');
        }
        $ret = $string;
        // $ret = str_replace('itemid', 'Itemid', $ret); // V 1.2.4.t bug #125
        _log('(1) Setting shSefRelToAbs return string as: ' . $ret);
    }
    if (!isset($ret)) {
        $ret = $string;
        _log('(2) Setting shSefRelToAbs return string as: ' . $ret);
    }
    //if (!empty($shMosMsg) && strpos($ret, $shMosMsg) === false) // V x 01/09/2007 23:02:00
    //   $ret .= (strpos( $ret, '?') === false  || $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode] == '/index.php?/'? '?':'&').$shMosMsg;
    $ret = $shComponentType == Sh404sefClassBaseextplugin::TYPE_DEFAULT ? shFinalizeURL($ret) : $ret;
    // V w 27/08/2007 13:21:28
    _log('(3) shSefRelToAbs return string after shFinalize: ' . $ret);
    if (empty($uri) || $shComponentType == Sh404sefClassBaseextplugin::TYPE_SKIP) {
        // we don't have a uri : we must be doing a redirect from non-sef to sef or similar
        $ret .= $shAppendString;
        // append directly to url
        _log('(4) shSefRelToAbs return string after appendString: ' . $ret);
    } else {
        if (empty($sefstring) || !empty($sefstring) && strpos($sefstring, 'index.php') !== 0) {
            shRebuildVars($shAppendString, $uri);
            // instead, add to uri. Joomla will put everything together. Only do this if we have a sef url, and not if we have a non-sef
            _log('(5) shSefRelToAbs no sefstring, adding rebuild vars : ' . $shAppendString);
        }
    }
    $shMosConfig_locale = $shOrigLang;
    _log('shSefRelToAbs: finally returning: ' . $ret);
    return $ret;
}
Example #5
0
 // of just assuming 0
 if (!empty($originalVars['view']) && $originalVars['view'] == 'category') {
     if (!isset($originalVars['limitstart'])) {
         $limitstart = 0;
         shAddToGETVarsList('limitstart', $limitstart);
         shRemoveFromGETVarsList('limitstart');
         // router.php expects this to be start, not limitstart
         $originalVars['start'] = $limitstart;
     } else {
         $originalVars['start'] = $originalVars['limitstart'];
         unset($originalVars['limitstart']);
     }
 }
 $hasCategoryId = !empty($originalVars['view']) && $originalVars['view'] == 'category' && !empty($originalVars['virtuemart_category_id']);
 $originalUrl = $originalUri->get('_uri');
 $nonSefItemid = shGetURLVar($originalUrl, 'Itemid');
 // have router.php build url
 $title = $functionName($originalVars);
 // VM router set the Itemid for category links!!!!
 // instead of doing the routing
 if ($hasCategoryId) {
     // if no Itemid in the original non-sef url, but we have one now
     if (empty($nonSefItemid) && !empty($vars['Itemid']) && $vars['Itemid'] != $nonSefItemid) {
         $validItemid = empty($helper->menu['virtuemart_category_id'][$vars['virtuemart_category_id']]) ? 0 : $helper->menu['virtuemart_category_id'][$vars['virtuemart_category_id']];
     } else {
         $validItemid = empty($vars['Itemid']) ? 0 : $vars['Itemid'];
     }
     if (!empty($validItemid)) {
         // we now use the calculated Itemid, either the original one
         // or the one that was swapped in by Virtuemart router.php
         $Itemid = $validItemid;
Example #6
0
 function &_createURI($url)
 {
     // prevent double Itemid param
     $itemid = shGetURLVar($url, 'Itemid');
     $i = intval($itemid);
     if (!empty($itemid) && (string) $i != $itemid) {
         $tmp = '?Itemid=' . $i;
         $url = str_replace($tmp . $tmp, $tmp, $url);
     }
     //Create the URI
     $uri =& parent::_createURI($url);
     // Get the itemid form the URI
     $itemid = $uri->getVar('Itemid');
     if (is_null($itemid)) {
         if ($option = $uri->getVar('option')) {
             $menu =& shRouter::shGetMenu();
             $item = $menu->getItem($itemid);
             if (isset($item) && $item->component == $option) {
                 $uri->setVar('Itemid', $item->id);
             }
         } else {
             if ($option = $this->getVar('option')) {
                 $uri->setVar('option', $option);
             }
             if ($itemid = $this->getVar('Itemid')) {
                 $uri->setVar('Itemid', $itemid);
             }
         }
     } else {
         if (!$uri->getVar('option')) {
             $menu =& shRouter::shGetMenu();
             $item = $menu->getItem($itemid);
             $uri->setVar('option', $item->component);
         }
     }
     return $uri;
 }
Example #7
0
 public static function extractTrackingVarsFromNonSef($url, &$existingVars, $keepThem = false)
 {
     $remoteConfig = Sh404sefHelperUpdates::getRemoteConfig($forced = false);
     // hardcoded default tracking vars
     $defaultTrackingVars = array('utm_source', 'utm_medium', 'utm_term', 'utm_content', 'utm_campaign');
     // try to read from remote, central, configuration file
     $remoteTrackingVars = empty($remoteConfig->config['trackingvars']) ? array() : $remoteConfig->config['trackingvars'];
     foreach ($remoteTrackingVars as $var) {
         // collect existing value, if any
         $value = shGetURLVar($url, $var, null);
         if (!is_null($value)) {
             // store extracted value into passed array
             $existingVars[$var] = $value;
         }
         // still remove var from url
         if (!$keepThem) {
             $url = shCleanUpVar($url, $var);
         }
     }
     return $url;
 }
Example #8
0
 /**
  *
  * @param  string $url
  * @param  array $title
  * @param  string $task
  * @param  int $limit
  * @param  int $limitstart
  * @return sefurl
  */
 public static function sefGetLocation($nonSefUrl, &$title, $task = null, $limit = null, $limitstart = null, $langParam = null, $showall = null, $suppressPagination = false)
 {
     try {
         $shPageInfo =& Sh404sefFactory::getPageInfo();
         $sefConfig =& Sh404sefFactory::getConfig();
         $lang = empty($langParam) ? $shPageInfo->currentLanguageTag : $langParam;
         // shumisha : try to avoid duplicate content on multilingual sites by always adding &lang=xx to url (stored in DB).
         // warning : must add &lang=xx only if it does not exists already
         if (!strpos($nonSefUrl, 'lang=')) {
             $shSepString = substr($nonSefUrl, -9) == 'index.php' ? '?' : '&';
             $nonSefUrl .= $shSepString . 'lang=' . shGetIsoCodeFromName($lang);
         }
         // make sure url is consistent
         $nonSefUrl = str_replace('&amp;', '&', $nonSefUrl);
         // detect multipage homepage
         $shMultiPageHomePageFlag = shIsHomepage($nonSefUrl);
         // get all the slugs ready for being urls bits
         $tempSefUrl = array();
         foreach ($title as $titlestring) {
             $decodedTitletring = urldecode($titlestring);
             $tempSefUrl[] = titleToLocation($decodedTitletring);
         }
         // now build the URL
         $tempSefUrl = implode("/", $tempSefUrl);
         // remove duplicate /
         $tempSefUrl = ShlSystem_Strings::pr('/\\/{2,}/u', '/', $tempSefUrl);
         // and truncate to max length, according to param
         $tempSefUrl = JString::substr($tempSefUrl, 0, sh404SEF_MAX_SEF_URL_LENGTH);
         // trim to max length V 1.2.4.t
         // if URL is empty, and unless this is a paginated home page, or home page in non-default language, stop there
         if (empty($tempSefUrl)) {
             if ((!shIsMultilingual() || shIsMultilingual() && shIsDefaultlang($lang)) && !$sefConfig->addFile && !$shMultiPageHomePageFlag) {
                 //
                 return '';
             }
             // if location is empty, and not multilingual site, or multilingual, but this is default language, then there is nothing to add to url
         }
         // we have a valid SEF url, built with the data ($title) sent
         // by plugin. Now we want to check if it's already in the db
         // and add it if not
         // first, we search the memory cache for the non-sef url
         // as it is faster than looking up the db
         $finalSefUrl = '';
         $sefUrlType = Sh404sefHelperCache::getSefUrlFromCache($nonSefUrl, $finalSefUrl);
         // if non-sef was not found in cache - or found, but it was a 404 last time we saw it -
         // we should continue and try adding it
         if ($sefUrlType == sh404SEF_URLTYPE_NONE || $sefUrlType == sh404SEF_URLTYPE_404) {
             $finalSefUrl = false;
             // non-sef was not found in cache, let's look up the database
             if ($sefUrlType == sh404SEF_URLTYPE_NONE) {
                 $finalSefUrl = ShlDbHelper::selectResult('#__sh404sef_urls', 'oldurl', array('newurl' => $nonSefUrl));
             }
             // we found the sef url in database, we're done
             if (!empty($finalSefUrl)) {
                 return $finalSefUrl;
             }
             // the non-sef url is not in memory cache, nor in database
             // that's a new one, we need to finalize its sef (add pagination and language information)
             // After finalizing it, we'll also check that sef is not in the db
             // as it can already be there, associated with another non-sef (ie: a duplicate)
             // Either way we'll add it in the db, but mark it as a duplicate if needed
             // add pagination information, unless we were instructed by extension plugin not to
             // find if we should separate pagination info from sef with a / or not
             if (!empty($tempSefUrl)) {
                 $shSeparator = JString::substr($tempSefUrl, -1) == '/' ? '' : '/';
             } else {
                 $shSeparator = '';
             }
             $finalSefUrl = $suppressPagination ? $tempSefUrl : shAddPaginationInfo($limit, $limitstart, $showall, 1, $nonSefUrl, $tempSefUrl, $shSeparator);
             // v 1.2.4.t
             // if home page, we don't record anything, just return "home page"
             if ($shMultiPageHomePageFlag && '/' . $finalSefUrl == $tempSefUrl && (!shIsMultilingual() || shIsMultilingual() && shIsDefaultLang($lang))) {
                 // but this is default language
                 // this is start page of multipage homepage, return home or forced home
                 if (!empty($sefConfig->shForcedHomePage)) {
                     return str_replace($shPageInfo->getDefaultFrontLiveSite() . '/', '', $sefConfig->shForcedHomePage);
                 } else {
                     return '';
                 }
             }
             // add language information
             // first, remove languages in non-sef, to see if we're on homepage
             // as handling is sligthly different for homepage
             $v1 = shCleanUpLang($nonSefUrl);
             $v2 = shCleanUpLang($shPageInfo->homeLink);
             if ($v1 == $v2 || $v1 == 'index.php') {
                 // check if this is homepage
                 if (shIsMultilingual() && !shIsDefaultLang($lang)) {
                     // if homepage in not-default-language, then add language code regardless of user settings
                     // as we otherwise would not be able to switch language on the frontpage
                     $finalSefUrl = shGetIsoCodeFromName($lang) . '/';
                 } else {
                     $finalSefUrl = '';
                 }
             } else {
                 // not on homepage, insert lang code based on user setting
                 $option = shGetURLVar($nonSefUrl, 'option', '');
                 if (shInsertIsoCodeInUrl($option, $lang)) {
                     // insert language code based on param
                     // pass URL lang info, as may not be current lang
                     $finalSefUrl = shGetIsoCodeFromName($lang) . '/' . $finalSefUrl;
                     //  must be forced lang, not default
                 }
             }
             // after adding pagination part of SEF, and adding language code
             // the new SEF url is now complete and we can try adding to it cache and db
             if ($finalSefUrl != '') {
                 $dburl = null;
                 $dbUrlId = null;
                 $nonSefUrlType = sh404SEF_URLTYPE_NONE;
                 // search the memory cache for this new sef
                 if ($sefConfig->shUseURLCache) {
                     $nonSefUrlType = Sh404sefHelperCache::getNonSefUrlFromCache($finalSefUrl, $dburl);
                 }
                 $newMaxRank = 0;
                 // if the new SEF was not found in memory cache, or if it was found but
                 // we're set to record duplicates, we search for it in the database
                 if ($sefConfig->shRecordDuplicates || $nonSefUrlType == sh404SEF_URLTYPE_NONE) {
                     $dbUrlList = ShlDbHelper::selectObjectList('#__sh404sef_urls', array('id', 'newurl', 'rank', 'dateadd'), array('oldurl' => $finalSefUrl), $aWhereData = array(), $orderBy = array('rank'));
                     if (count($dbUrlList) > 0) {
                         $dburl = $dbUrlList[0]->newurl;
                         $dbUrlId = $dbUrlList[0]->id;
                         if (empty($dburl)) {
                             // V 1.2.4.t url was found in DB, but was a 404
                             $nonSefUrlType = sh404SEF_URLTYPE_404;
                         } else {
                             $newMaxRank = $dbUrlList[count($dbUrlList) - 1]->rank + 1;
                             $nonSefUrlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM;
                         }
                     }
                 }
                 if ($nonSefUrlType != sh404SEF_URLTYPE_NONE && $nonSefUrlType != sh404SEF_URLTYPE_404) {
                     // we found the SEF, one or more times in the db, in records which do have a non-sef attached
                     $isDuplicate = $dburl != $nonSefUrl;
                     // This is a duplicate so we must indert it with incremented rank;
                     if (is_null($dburl) || $isDuplicate && $sefConfig->shRecordDuplicates) {
                         // shAddSefUrlToDBAndCache( $nonSefUrl, $finalSefUrl, ($isDuplicate ? $newMaxRank : 0), $nonSefUrlType);
                         $dateAdd = $nonSefUrlType == sh404SEF_URLTYPE_AUTO ? '0000-00-00' : date("Y-m-d");
                         ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => $isDuplicate ? $newMaxRank : 0, 'dateadd' => $dateAdd));
                         // store new sef/non-sef pair in memory cache
                         Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, $nonSefUrlType);
                         // create shURL : get a shURL model, and ask url creation
                         $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel');
                         $model->createPageId($finalSefUrl, $nonSefUrl);
                     }
                 } else {
                     // we haven't found the non-sef/sef pair, but maybe there is a record for
                     // a 404 with that SEF. If so, we will "upgrade" the 404 record to a
                     // normal non-sef/sef pair
                     $dbUrlId = empty($dbUrlId) ? 0 : intval($dbUrlId);
                     if ($sefConfig->shLog404Errors) {
                         if ($nonSefUrlType == sh404SEF_URLTYPE_404 && !empty($dbUrlId)) {
                             // we already have seen that it is a 404
                             $id = $dbUrlId;
                         } elseif ($nonSefUrlType == sh404SEF_URLTYPE_404) {
                             $id = ShlDbHelper::selectResult('#__sh404sef_urls', 'id', array('oldurl' => $finalSefUrl, 'newurl' => ''));
                         } else {
                             $id = null;
                         }
                     } else {
                         $id = null;
                         // if we are not logging 404 errors, then no need to check for
                     }
                     // previous hit of this page.
                     if (!empty($id)) {
                         // we found a 404 record matching the SEF url just created. We'll update that record
                         // instead of creating a new one
                         // need to update dateadd to 0, as otherwise this sef/non-sef pair will be seen as custom
                         // this makes all such 404 errors 'disappear' from the 404 log, but no other solution
                         ShlDbHelper::updateIn('#__sh404sef_urls', array('newurl' => $nonSefUrl, 'dateadd' => '0000-00-00'), 'id', array($id));
                         Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO);
                     } else {
                         // standard case: creation of a totally new sef/non-sef pair
                         ShlDbHelper::insert('#__sh404sef_urls', array('oldurl' => $finalSefUrl, 'newurl' => $nonSefUrl, 'rank' => 0, 'dateadd' => '0000-00-00'));
                         // store new sef/non-sef pair in memory cache
                         Sh404sefHelperCache::addSefUrlToCache($nonSefUrl, $finalSefUrl, sh404SEF_URLTYPE_AUTO);
                         // create shURL : get a shURL model, and ask url creation
                         $model = ShlMvcModel_Base::getInstance('pageids', 'Sh404sefModel');
                         $model->createPageId($finalSefUrl, $nonSefUrl);
                     }
                 }
             }
         }
     } catch (Exception $e) {
         $finalSefUrl = '';
         ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
     }
     return $finalSefUrl;
 }
Example #9
0
 private function _mustCreatePageid($nonSefUrl)
 {
     // currently disabled by sef url plugin
     if (!self::$_mustCreate) {
         return false;
     }
     // if enabled at sef url plugin level, check configuration
     $sefConfig =& shRouter::shGetConfig();
     // check global flags
     if (!$sefConfig->enablePageId || $sefConfig->stopCreatingShurls) {
         return false;
     }
     // check at component level
     $option = shGetURLVar($nonSefUrl, 'option');
     $option = str_replace('com_', '', $option);
     $enable = !empty($option) && in_array($option, $sefConfig->compEnablePageId);
     // check non sef url content black list
     $sefConfig->shurlNonSefBlackList = JString::trim($sefConfig->shurlNonSefBlackList);
     if (empty($sefConfig->shurlNonSefBlackList)) {
         $blackList = array();
     } else {
         if (strpos($sefConfig->shurlNonSefBlackList, '|') !== false) {
             $blackList = explode('|', $sefConfig->shurlNonSefBlackList);
         } else {
             $blackList = array($sefConfig->shurlNonSefBlackList);
         }
     }
     if (!empty($blackList)) {
         foreach ($blackList as $bit) {
             if (!empty($bit) && strpos($nonSefUrl, $bit) !== false) {
                 // match, don't create a shurl for this non sef url
                 $enable = false;
                 break;
             }
         }
     }
     return $enable;
 }
Example #10
0
 /**
  *
  * @param  string $url
  * @param  array $title
  * @param  string $task
  * @param  int $limit
  * @param  int $limitstart
  * @return sefurl
  */
 public static function sefGetLocation($url, &$title, $task = null, $limit = null, $limitstart = null, $langParam = null, $showall = null)
 {
     $shPageInfo =& Sh404sefFactory::getPageInfo();
     $sefConfig =& Sh404sefFactory::getConfig();
     // get DB
     $database =& JFactory::getDBO();
     $lang = empty($langParam) ? $shPageInfo->shMosConfig_locale : $langParam;
     // shumisha : try to avoid duplicate content when using Joomfish by always adding &lang=xx to url (stored in DB).
     // warning : must add &lang=xx only if it does not exists already, which happens for the joomfish language selection modules or search results
     if (!strpos($url, 'lang=')) {
         $shSepString = substr($url, -9) == 'index.php' ? '?' : '&';
         $url .= $shSepString . 'lang=' . shGetIsoCodeFromName($lang);
     }
     // shumisha end of fix
     //shorten the url for storage and for consistancy
     $url = str_replace('&amp;', '&', $url);
     // V 1.2.4.q detect multipage homepage
     $shMultiPageHomePageFlag = shIsHomepage($url);
     // get all the titles ready for urls
     $location = array();
     foreach ($title as $titlestring) {
         // V 1.2.4.t removed array_filter as it prevents '0' values in URL
         $location[] = titleToLocation(urldecode($titlestring));
     }
     $location = implode("/", $location);
     // V 1.2.4.t
     // V 1.2.4.t remove duplicate /
     $location = preg_replace('/\\/{2,}/', '/', $location);
     $location = JString::substr($location, 0, sh404SEF_MAX_SEF_URL_LENGTH);
     // trim to max length V 1.2.4.t
     // shumisha protect against querying for empty location
     if (empty($location)) {
         // V 1.2.4.t
         if ((!shIsMultilingual() || shIsMultilingual() && shIsDefaultlang($lang)) && !$sefConfig->addFile && !$shMultiPageHomePageFlag) {
             // V 1.2.4.q : need to go further and add pagination
             return '';
         }
     }
     // if location is empty, and no Joomfish, or Joomfish but this is default language, then there is nothing to add to url before querying DB
     // shumisha end of change
     //check for non-sef url first and avoid repeative lookups
     //we only want to look for title variations when adding new
     //this should also help eliminate duplicates.
     // shumisha 2003-03-13 added URL Caching
     $realloc = '';
     $urlType = Sh404sefHelperCache::getSefUrlFromCache($url, $realloc);
     if ($urlType == sh404SEF_URLTYPE_NONE || $urlType == sh404SEF_URLTYPE_404) {
         // V 1.2.4.t
         // shumisha end of addition
         $realloc = false;
         if ($urlType == sh404SEF_URLTYPE_NONE) {
             $query = "SELECT oldurl from #__sh404sef_urls WHERE newurl = " . $database->Quote($url);
             $database->setQuery($query);
             //if ($realloc = $database->loadResult()) {
             if ($shTemp = $database->loadObject()) {
                 $realloc = $shTemp->oldurl;
             }
         }
         if ($realloc) {
             // found a match, so we aredone
             //Dat betekent dus, dat de functie create(), slecht gekozen is
             // shumisha : removed this die() that I do not understand!
             //die('regel292 in sef_ext.php');
             // shumisha end of removal
         } else {
             // this is new, so we need to insert the new title.
             //Hier worden eindelijk de nieuwe links gemaakt
             $iteration = 1;
             $realloc = false;
             $prev_temploc = '';
             do {
                 // temploc is $location, unless we're on a second or greater iteration,
                 // then its $location.$iteration
                 if (!empty($location)) {
                     $shSeparator = JString::substr($location, -1) == '/' ? '' : '/';
                 } else {
                     $shSeparator = '';
                 }
                 $temploc = shAddPaginationInfo($limit, $limitstart, $showall, $iteration, $url, $location, $shSeparator);
                 // v 1.2.4.t
                 // V 1.2.4.t
                 if ($shMultiPageHomePageFlag && '/' . $temploc == $location && (!shIsMultilingual() || shIsMultilingual() && shIsDefaultLang($lang))) {
                     // but this is default language
                     // this is start page of multipage homepage, return home or forced home
                     if (!empty($sefConfig->shForcedHomePage)) {
                         // V 1.2.4.t
                         return str_replace($shPageInfo->getDefaultLiveSite() . '/', '', $sefConfig->shForcedHomePage);
                     } else {
                         return '';
                     }
                 }
                 // V 1.2.4.k here we need to check for other-than-default-language homepage
                 // remove lang
                 $v1 = shCleanUpLang($url);
                 // V 1.2.4.t
                 $v2 = shCleanUpLang($shPageInfo->homeLink);
                 // V 1.24.t
                 if ($v1 == $v2 || $v1 == 'index.php') {
                     // check if this is homepage
                     if (shIsMultilingual() && !shIsDefaultLang($lang)) {
                         // V 1.2.4.m : insert language code based on param
                         $temploc = shGetIsoCodeFromName($lang) . '/';
                     } else {
                         $temploc = '';
                         // if homepage in not-default-language, then add language code even if param says opposite
                     }
                     // as we otherwise would not be able to switch language on the frontpage
                 } else {
                     $option = shGetURLVar($url, 'option', '');
                     if (shInsertIsoCodeInUrl($option, $lang)) {
                         // V 1.2.4.m : insert language code based on param
                         // V 1.2.4.q : pass URL lang info, as may not be current lang
                         $temploc = shGetIsoCodeFromName($lang) . '/' . $temploc;
                         // V 1.2.4.q  must be forced lang, not default
                     }
                 }
                 if ($temploc != '') {
                     // see if we have a result for this location
                     // V 1.2.4.r without mod_rewrite
                     $temploc = shAdjustToRewriteMode($temploc);
                     $sql = "SELECT id, newurl, rank, dateadd FROM #__sh404sef_urls WHERE oldurl = " . $database->Quote($temploc) . " ORDER BY rank ASC";
                     // V 1.2.4.q
                     $database->setQuery($sql);
                     if ($iteration > 9999) {
                         //var_dump($sql);
                         JError::raiseError(500, 'Too many pages :' . $temploc . '##');
                     }
                     $dburl = null;
                     // V 1.2.4.t initialize $dburl to avoid notices error if cache disabled
                     $dbUrlId = null;
                     // V 1.2.4.t
                     $urlType = sh404SEF_URLTYPE_NONE;
                     // shumisha 2007-03-13 added URL caching, check for various URL for same content
                     if ($sefConfig->shUseURLCache) {
                         $urlType = Sh404sefHelperCache::getNonSefUrlFromCache($temploc, $dburl);
                     }
                     $newMaxRank = 0;
                     $shDuplicate = false;
                     if ($sefConfig->shRecordDuplicates || $urlType == sh404SEF_URLTYPE_NONE) {
                         // V 1.2.4.s
                         $dbUrlList = $database->loadObjectList();
                         if (count($dbUrlList) > 0) {
                             $dburl = $dbUrlList[0]->newurl;
                             $dbUrlId = $dbUrlList[0]->id;
                             if (empty($dburl)) {
                                 // V 1.2.4.t url was found in DB, but was a 404
                                 $urlType = sh404SEF_URLTYPE_404;
                             } else {
                                 $newMaxRank = $dbUrlList[count($dbUrlList) - 1]->rank + 1;
                                 $urlType = $dbUrlList[0]->dateadd == '0000-00-00' ? sh404SEF_URLTYPE_AUTO : sh404SEF_URLTYPE_CUSTOM;
                             }
                         }
                     }
                     if ($urlType != sh404SEF_URLTYPE_NONE && $urlType != sh404SEF_URLTYPE_404) {
                         if ($dburl == $url) {
                             // found the matching object
                             // it probably should have been found sooner
                             // but is checked again here just for CYA purposes
                             // and to end the loop
                             $realloc = $temploc;
                         } else {
                             $shDuplicate = true;
                         }
                         // else, didn't find it, increment and try again
                         // shumisha added this to close the loop if working on frontpage
                         // as domain.tld/index.php?lang=xx and domain.tld/index.php?option=com_frontpage&Itemid=1&lang=xx both must end up in domain.tld/xx/ (if xx is not default language of course - in that case, they must endup in domain.tld)
                         // this is true also if Joomfish is not installed and there is no language information in the url
                         // V 1.2.4.q  this is a duplicate so we must indert it with incremented rank;
                         if ($shDuplicate && $sefConfig->shRecordDuplicates) {
                             shAddSefUrlToDBAndCache($url, $temploc, $shDuplicate ? $newMaxRank : 0, $urlType);
                         }
                         $realloc = $temploc;
                         // to close the loop
                         // shumisha end of addition
                     } else {
                         //title not found, chechk 404
                         $dbUrlId = empty($dbUrlId) ? 0 : intval($dbUrlId);
                         if ($sefConfig->shLog404Errors) {
                             // V 1.2.4.m
                             if ($urlType == sh404SEF_URLTYPE_404 && !empty($dbUrlId)) {
                                 // we already have seen that it is a 404
                                 $id = $dbUrlId;
                                 // V 1.2.4.t
                             } elseif ($urlType == sh404SEF_URLTYPE_404) {
                                 $query = "SELECT `id` FROM #__sh404sef_urls WHERE `oldurl` = " . $database->Quote($temploc) . " AND `newurl` = ''";
                                 $database->setQuery($query);
                                 $id = $database->loadResult();
                             } else {
                                 $id = null;
                             }
                         } else {
                             $id = null;
                         }
                         // V 1.2.4.m if we are not logging 404 errors, then no need to check for
                         // previous hit of this page.
                         if (!empty($id)) {
                             // V 1.2.4.q : need to update dateadd to 0, as otherwise this redir will be seen as a custom redir
                             // this makes all such 404 errors 'disappear' from the 404 log, but no other solution
                             $query = "UPDATE #__sh404sef_urls SET `newurl` = " . $database->Quote($url) . ",`dateadd` = '0000-00-00' WHERE `id` = '{$id}'";
                             $database->setQuery($query);
                             if (!$database->query()) {
                                 _log('error adding new sef url to db:' . $database->getErrorMsg());
                                 //var_dump($query);
                             } else {
                                 Sh404sefHelperCache::addSefUrlToCache($url, $temploc, sh404SEF_URLTYPE_AUTO);
                                 // v 1.2.4.t
                             }
                         } else {
                             /* put it in the database */
                             shAddSefUrlToDBAndCache($url, $temploc, 0, sh404SEF_URLTYPE_AUTO);
                         }
                         $realloc = $temploc;
                     }
                 }
                 $prev_temploc = $temploc;
                 $iteration++;
                 // shumisha allow loop exit if $temploc = '' (homepage)
                 //} while (!$realloc);
             } while (!$realloc && $temploc != '');
         }
     }
     // shumisha : enf of check if URL is in cache
     return $realloc;
 }
Example #11
0
 protected static function _createShurl($nonSefUrl)
 {
     if (empty($nonSefUrl)) {
         return '';
     }
     // only create a shURL if current page returns a 200
     $headers = JResponse::getHeaders();
     // check if we have a status
     foreach ($headers as $header) {
         if (strtolower($header['name']) == 'status' && $header['value'] != 200) {
             // error or redirection, don't shurl that
             return '';
         }
     }
     // check various conditions, to avoid overloading ourselves with shURL
     // not on homepage
     if (shIsHomepage($nonSefUrl)) {
         return '';
     }
     // not for format = raw, format = pdf or printing
     $format = shGetURLVar($nonSefUrl, 'format');
     if (in_array(strtolower($format), array('raw', 'pdf'))) {
         return '';
     }
     $print = shGetURLVar($nonSefUrl, 'print');
     if ($print == 1) {
         return '';
     }
     // not if tmpl not empty or not index
     $tmpl = shGetURLVar($nonSefUrl, 'tmpl');
     if (!empty($tmpl) && $tmpl != 'index') {
         return '';
     }
     // force global setting
     shMustCreatePageId('set', true);
     // get a model and create shURL
     $model =& JModel::getInstance('Pageids', 'Sh404sefModel');
     $shURL = $model->createPageId('', $nonSefUrl);
     return $shURL;
 }
Example #12
0
function shGetDefaultDisplayNum($menuItemid, $url, $fromSession = false, $includeBlogLinks = false)
{
    global $mainframe;
    // default value is general configuration list length param
    $ret = $mainframe->getCfg('list_limit', 10);
    // get elements of the url
    $option = shGetURLVar($url, 'option');
    $layout = shGetURLVar($url, 'layout');
    if (empty($layout)) {
        $layout = 'default';
    }
    $view = shGetURLVar($url, 'view');
    // is this a sobi2 url ? we must read config from database
    if ($option == 'com_sobi2') {
        $itemsPerLine = (int) shGetSobi2Config('itemsInLine', 'frontpage');
        $linesPerPage = (int) shGetSobi2Config('lineOnSite', 'frontpage');
        return $itemsPerLine * $linesPerPage;
    }
    // if there is a menu item, we can try read more params
    if (!empty($menuItemid)) {
        // itemid, try read params from the menu item
        $menu =& shRouter::shGetMenu();
        $menuItem = $menu->getItem($menuItemid);
        // load menu item from DB
        if (empty($menuItem)) {
            return $ret;
        }
        // if none, default
        $params = new JParameter($menuItem->params);
        // get params from menu item
        // layout = blog and frontpage
        if ($option == 'com_content' && $layout == 'blog' || $option == 'com_content' && $view == 'frontpage') {
            $num_leading_articles = $params->get('num_leading_articles');
            $num_intro_articles = $params->get('num_intro_articles');
            //adjust limit and listLimit for page calculation as blog views include
            //# of links in the limit value, while it should not be included for
            // page number calculation
            $num_links = $includeBlogLinks ? $params->get('num_links') : 0;
            $ret = $num_leading_articles + $num_intro_articles + $num_links;
            // calculate how many items on a page
            return $ret;
        }
        // elements with a display_num parameter
        $displayNum = intval($params->get('display_num'));
        $ret = !empty($displayNum) ? $displayNum : $ret;
    }
    if ($fromSession) {
        // now handle special cases
        if ($option == 'com_content' && $layout != 'blog' && ($view == 'category' || $view == 'section')) {
            global $mainframe;
            $limit = $mainframe->getUserStateFromRequest('com_content.sh.' . $view . '.' . $layout . '.limit', 'limit', null);
            if (!is_null($limit)) {
                return $limit;
            }
        }
        if ($option == 'com_contact') {
            global $mainframe;
            $limit = $mainframe->getUserState($option . '.' . $view . '.limit');
            if (!is_null($limit)) {
                return $limit;
            }
        }
        if ($option == 'com_weblinks') {
            global $mainframe;
            $limit = $mainframe->getUserState($option . '.limit');
            if (!is_null($limit)) {
                return $limit;
            }
        }
    }
    // return calculated value
    return $ret;
}
Example #13
0
 private function _mustCreatePageid($nonSefUrl)
 {
     // currently disabled by sef url plugin
     if (!self::$_mustCreate) {
         return false;
     }
     // if enabled at sef url plugin level, check configuration
     $sefConfig =& Sh404sefFactory::getConfig();
     // check global flags
     if (!$sefConfig->enablePageId || $sefConfig->stopCreatingShurls) {
         return false;
     }
     // make sure we have a language
     $pageInfo =& Sh404sefFactory::getPageInfo();
     $nonSefUrl = shSetURLVar($nonSefUrl, 'lang', $pageInfo->shMosConfig_shortcode);
     // not on homepage
     if (shIsAnyHomepage($nonSefUrl)) {
         return '';
     }
     // check at component level
     $option = shGetURLVar($nonSefUrl, 'option');
     $option = str_replace('com_', '', $option);
     $enable = !empty($option) && in_array($option, $sefConfig->compEnablePageId);
     // check non sef url content black list
     $sefConfig->shurlNonSefBlackList = JString::trim($sefConfig->shurlNonSefBlackList);
     if (empty($sefConfig->shurlNonSefBlackList)) {
         $blackList = array();
     } else {
         if (strpos($sefConfig->shurlNonSefBlackList, '|') !== false) {
             $blackList = explode('|', $sefConfig->shurlNonSefBlackList);
         } else {
             $blackList = array($sefConfig->shurlNonSefBlackList);
         }
     }
     if (!empty($blackList)) {
         foreach ($blackList as $bit) {
             if (!empty($bit) && strpos($nonSefUrl, $bit) !== false) {
                 // match, don't create a shurl for this non sef url
                 $enable = false;
                 break;
             }
         }
     }
     return $enable;
 }
Example #14
0
 private function _mustCreatePageid($nonSefUrl)
 {
     // currently disabled by sef url plugin
     if (!self::$_mustCreate) {
         return false;
     }
     // if enabled at sef url plugin level, check configuration
     $sefConfig =& shRouter::shGetConfig();
     // check global flag
     if (!$sefConfig->enablePageId) {
         return false;
     }
     // last check at component level
     $option = shGetURLVar($nonSefUrl, 'option');
     $option = str_replace('com_', '', $option);
     $enable = !empty($option) && in_array($option, $sefConfig->compEnablePageId);
     return $enable;
 }
function shGetDefaultDisplayNumFromURL($url)
{
    $menuItemid = shGetURLVar($url, 'Itemid');
    return shGetDefaultDisplayNum($menuItemid, $url);
}