コード例 #1
0
ファイル: sh404sef.class.php プロジェクト: sangkasi/joomla
function getMenuTitle($option, $task, $id = null, $string = null, $shLanguage = null)
{
    global $shHomeLink;
    $sefConfig =& shRouter::shGetConfig();
    $database =& JFactory::getDBO();
    $shLanguage = empty($shLanguage) ? $GLOBALS['shMosConfig_locale'] : $shLanguage;
    // V 1.2.4.q must also check if homepage, in any language. If homepage, must return $title[]='/'
    // language info and limit/limistart pagination will be added at final stage by sefGetLocation()
    // V 1.2.4.t must also check that menu item is published !!
    $nameField = $sefConfig->useMenuAlias ? 'alias' : 'name';
    if (!empty($string)) {
        // V 1.2.4.q replaced isset by empty
        $sql = "SELECT " . $nameField . ", link,id FROM #__menu WHERE link = " . $database->Quote($string) . " AND published = '1'";
    } elseif (!empty($id)) {
        $sql = "SELECT " . $nameField . ", link,id FROM #__menu WHERE id = " . intval($id) . " AND published='1'";
    } elseif (!empty($option)) {
        $sql = 'SELECT ' . $nameField . ', link,id FROM #__menu WHERE published=\'1\' AND link LIKE \'index.php?option=' . $database->getEscaped($option) . '%\'';
    } else {
        return '/';
        // don't know what else we could do, just go home
    }
    $database->setQuery($sql);
    if (isset($shLanguage) && shIsMultilingual()) {
        $rows = @$database->loadObjectList('', true, $shLanguage);
    } else {
        $rows = @$database->loadObjectList();
    }
    if ($database->getErrorNum()) {
        die($database->stderr());
    } elseif (@count($rows) > 0) {
        $shLink = shSortUrl($rows[0]->link . ($rows[0]->link == 'index.php' ? '?' : '&') . 'Itemid=' . $rows[0]->id);
        if (!shIsHomepage($shLink)) {
            // V1.2.4.q homepage detection
            if (!empty($rows[0]->{$nameField})) {
                $title = $rows[0]->{$nameField};
            }
        } else {
            $title = '/';
        }
        // this is homepage
    } else {
        $title = str_replace('com_', '', $option);
    }
    return $title;
}
コード例 #2
0
ファイル: sef_ext.php プロジェクト: sangkasi/joomla
 /**
  * Vul in de array $title de onderdelen waaruit de link moet bestaan
  * Bijvoorbeeld: menuitem, categorie, itemnaam
  * Deze functie last de boel aan elkaar
  *
  * @param  string $url
  * @param  array $title
  * @param  string $task
  * @param  int $limit
  * @param  int $limitstart
  * @return sefurl
  */
 function sefGetLocation($url, &$title, $task = null, $limit = null, $limitstart = null, $langParam = null, $showall = null)
 {
     global $shMosConfig_locale, $option, $shHomeLink;
     $sefConfig =& shRouter::shGetConfig();
     // get DB
     $database =& JFactory::getDBO();
     $lang = empty($langParam) ? $shMosConfig_locale : $langParam;
     // V 1.2.4.k added homepage check : needed in case homepage is not com_frontpage
     if (empty($shHomeLink)) {
         $menu =& shRouter::shGetMenu();
         $shHomePage =& $menu->getDefault();
         if ($shHomePage) {
             if (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;
             //$shHomeLink = 'index.php';
             if (!strpos($shHomeLink, 'lang=')) {
                 $shDefaultIso = shGetIsoCodeFromName(shGetDefaultLang());
                 $shSepString = substr($shHomeLink, -9) == 'index.php' ? '?' : '&';
                 $shHomeLink .= $shSepString . 'lang=' . $shDefaultIso;
             }
             $shHomeLink = shSortUrl($shHomeLink);
             // $homeLink has lang info, whereas $homepage->link may or may not
         }
     }
     // 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('&', '&', $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 #__redirection 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($GLOBALS['shConfigLiveSite'] . '/', '', $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($shHomeLink);
                 // 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 {
                     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 #__redirection 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 #__redirection 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 #__redirection 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;
 }
コード例 #3
0
 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);
             }
         }
     }
 }
コード例 #4
0
 function shInitLanguageList($currentList, $default, $defaultLangDefault)
 {
     $ret = array();
     $shKind = shIsMultilingual();
     $app = JFactory::getApplication();
     if (!$shKind && !$app->isAdmin()) {
         if (empty($currentList) || !isset($currentList[sh404sefFactory::getPageInfo()->shMosConfig_locale])) {
             $ret[sh404sefFactory::getPageInfo()->shMosConfig_locale] = $defaultLangDefault;
         } else {
             $ret[sh404sefFactory::getPageInfo()->shMosConfig_locale] = $currentList[sh404sefFactory::getPageInfo()->shMosConfig_locale];
         }
     } else {
         $activeLanguages = shGetActiveLanguages();
         if (empty($activeLanguages)) {
             if (empty($currentList) || !isset($currentList[sh404sefFactory::getPageInfo()->shMosConfig_locale])) {
                 $ret[sh404sefFactory::getPageInfo()->shMosConfig_locale] = $defaultLangDefault;
             } else {
                 $ret[sh404sefFactory::getPageInfo()->shMosConfig_locale] = $currentList[sh404sefFactory::getPageInfo()->shMosConfig_locale];
             }
         } else {
             foreach ($activeLanguages as $language) {
                 if (empty($currentList) || !isset($currentList[$language->code])) {
                     $ret[$language->code] = $language->code == sh404sefFactory::getPageInfo()->shMosConfig_locale ? $defaultLangDefault : $default;
                 } else {
                     $ret[$language->code] = $currentList[$language->code];
                 }
             }
         }
     }
     return $ret;
 }
コード例 #5
0
ファイル: sef_ext.php プロジェクト: alesconti/FF_2015
 /**
  *
  * @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('&', '&', $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;
 }
コード例 #6
0
ファイル: shsef.php プロジェクト: sangkasi/joomla
 function _parseSefRoute(&$uri)
 {
     $vars = array();
     _log('_parseSefRoute, parsing _uri ' . $uri->_uri);
     _log('_parseSefRoute, parsing _host ' . $uri->_host);
     _log('_parseSefRoute, parsing _path ' . $uri->_path);
     include JPATH_ROOT . DS . 'components' . DS . 'com_sh404sef' . DS . 'sh404sef.inc.php';
     if (shIsMultilingual() == 'joomfish') {
         $currentLangShortCode = $GLOBALS['shMosConfig_shortcode'];
         $conf =& JFactory::getConfig();
         $configDefaultLanguage = $conf->getValue('config.language');
         $tmp = explode('-', str_replace('_', '-', $configDefaultLanguage));
         $defaultLangShortCode = $tmp[0];
     } else {
         $currentLang = '';
     }
     $jMenu = null;
     $shMenu = null;
     // set active menu if changed
     if (!empty($vars['Itemid'])) {
         $newItemid = intval($vars['Itemid']);
         if (!empty($newItemid)) {
             $jMenu =& JSite::getMenu();
             $jMenu->setActive($newItemid);
             $shMenu =& shRouter::shGetMenu();
             $shMenu->setActive($newItemid);
         }
     }
     //Set the variables
     $this->setVars($vars);
     // set language again, as Joomfish may have set it according to user cookie
     if (shIsMultilingual() == 'joomfish' && !empty($vars['lang']) && $vars['lang'] != $currentLangShortCode) {
         JRequest::setVar('lang', $vars['lang']);
         // we also need to fix the main menu, as joomfish has set it to the wrong language
         if (empty($shMenu) || empty($shMenu)) {
             $jMenu =& JSite::getMenu();
             $shMenu =& shRouter::shGetMenu();
         }
         $sefLang = TableJFLanguage::createByShortcode($vars['lang'], false);
         $jMenu->_items = shGetJFMenu($sefLang->code, false, $jMenu->_items);
         $shMenu->_items = shGetJFMenu($sefLang->code, false, $shMenu->_items);
         // and finally we can set new joomfish language
         shSetJfLanguage($vars['lang']);
     }
     // last fix is to remove the home flag if other than default language
     if (shIsMultilingual() == 'joomfish' && !empty($vars['lang']) && $vars['lang'] != $defaultLangShortCode) {
         if (empty($shMenu) || empty($shMenu)) {
             $jMenu =& JSite::getMenu();
             $shMenu =& shRouter::shGetMenu();
         }
         $jDefaultItem =& $jMenu->getDefault();
         $jDefaultItem->home = 0;
         $shDefaultItem =& $shMenu->getDefault();
         $shDefaultItem->home = 0;
     }
     // and finally we can set new joomfish language
     if (shIsMultilingual() == 'joomfish' && !empty($vars['lang']) && $vars['lang'] != $currentLangShortCode) {
         shSetJfLanguage($vars['lang']);
     }
     // real last fix is to fix the $uri object, which Joomfish broke as it intended the path to be
     // parsed by Joomla router, not ours
     if (shIsMultilingual() == 'joomfish') {
         $myUri =& JURI::getInstance();
         // fix the path
         if (!empty($sefConfig->shRewriteMode)) {
             $rewriteBit = JString::rtrim($sefConfig->shRewriteStrings[$sefConfig->shRewriteMode], '/');
         } else {
             $rewriteBit = '';
         }
         $path = rtrim($shPageInfo->base, '/') . $rewriteBit . $shPageInfo->shCurrentPagePath;
         $myUri->setPath($path);
         // remove the lang query that JF added to $uri
         $myUri->delVar('lang');
     }
     return $vars;
 }
コード例 #7
0
function shGetNameFromIsoCode($langCode) {

  static $shLangNameCache = null;
  global $shLangNameCache;

  if (empty( $shLangNameCache)) {
    $type = shIsMultilingual();
    if ($type !== false) {
      $languages = Sh404sefHelperGeneral::getInstalledLanguagesList();
      foreach ($languages as $language) {
        $jfIsoCode = empty($language->shortcode) ? $language->iso:$language->shortcode;
        $shLangNameCache[$jfIsoCode] = $language->code;
      }
      return empty($shLangNameCache[$langCode]) ? Sh404sefFactory::getPageInfo()->shMosConfig_locale : $shLangNameCache[$langCode];
    } else { // no joomfish, so it has to be default language
      return Sh404sefFactory::getPageInfo()->shMosConfig_locale;
    }
  } else return empty($shLangNameCache[$langCode]) ? Sh404sefFactory::getPageInfo()->shMosConfig_locale : $shLangNameCache[$langCode];
}
コード例 #8
0
ファイル: SEFConfig.class.php プロジェクト: justinlyon/scc
 function shInitLanguageList($currentList, $default, $defaultLangDefault)
 {
     global $mainframe;
     $ret = array();
     $shKind = shIsMultilingual();
     if (!$shKind && !$mainframe->isAdmin()) {
         if (empty($currentList) || !isset($currentList[$GLOBALS['shMosConfig_locale']])) {
             $ret[$GLOBALS['shMosConfig_locale']] = $defaultLangDefault;
         } else {
             $ret[$GLOBALS['shMosConfig_locale']] = $currentList[$GLOBALS['shMosConfig_locale']];
         }
     } else {
         $activeLanguages = shGetActiveLanguages();
         if (empty($activeLanguages)) {
             if (empty($currentList) || !isset($currentList[$GLOBALS['shMosConfig_locale']])) {
                 $ret[$GLOBALS['shMosConfig_locale']] = $defaultLangDefault;
             } else {
                 $ret[$GLOBALS['shMosConfig_locale']] = $currentList[$GLOBALS['shMosConfig_locale']];
             }
         } else {
             foreach ($activeLanguages as $language) {
                 if (empty($currentList) || !isset($currentList[$language->code])) {
                     $ret[$language->code] = $language->code == $GLOBALS['shMosConfig_locale'] ? $defaultLangDefault : $default;
                 } else {
                     $ret[$language->code] = $currentList[$language->code];
                 }
             }
         }
     }
     return $ret;
 }
コード例 #9
0
ファイル: pageinfo.php プロジェクト: lautarodragan/ideary
 public function loadHomepages()
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     // store default links in each language
     jimport('joomla.language.helper');
     $languages = JLanguageHelper::getLanguages();
     $this->isMultilingual = shIsMultilingual();
     $defaultLanguage = shGetDefaultLang();
     if ($this->isMultilingual === false || $this->isMultilingual == 'joomla') {
         $menu = JFactory::getApplication()->getMenu();
         foreach ($languages as $language) {
             $menuItem = $menu->getDefault($language->lang_code);
             if (!empty($menuItem)) {
                 $this->homeLinks[$language->lang_code] = $this->_prepareLink($menuItem);
                 if ($language->lang_code == $defaultLanguage) {
                     $this->homeLink = $this->homeLinks[$language->lang_code];
                     $this->homeItemid = $menuItem->id;
                 }
             }
         }
         // find about the "All" languages home link
         $menuItem = $menu->getDefault('*');
         if (!empty($menuItem)) {
             $this->allLangHomeLink = $this->_prepareLink($menuItem, $languages);
         }
     } else {
         // trouble starts
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('id,language,link');
         $query->from('#__menu');
         $query->where('home <> 0');
         $db->setQuery($query);
         $items = $db->loadObjectList('language');
         if (!empty($items)) {
             if (count($items) == 1) {
                 $tmp = array_values($items);
                 $defaultItem = $tmp[0];
             }
             if (empty($defaultItem)) {
                 $defaultItem = empty($items[$defaultLanguage]) ? null : $items[$defaultLanguage];
             }
             if (empty($defaultItem)) {
                 $defaultItem = empty($items['*']) ? null : $items['*'];
             }
             foreach ($languages as $language) {
                 if (!empty($items[$language->lang_code])) {
                     $this->homeLinks[$language->lang_code] = $this->_prepareLink($items[$language->lang_code]);
                 } else {
                     // no menu item for home link
                     // let's try to  build one
                     $this->homeLinks[$language->lang_code] = $this->_prepareLink($defaultItem, shGetIsoCodeFromName($language->lang_code));
                 }
                 if ($language->lang_code == $defaultLanguage) {
                     $this->homeLink = $this->homeLinks[$language->lang_code];
                     $this->homeItemid = $defaultItem->id;
                     $this->allLangHomeLink = shCleanUpLang($this->homeLinks[$language->lang_code]);
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: sh404sef.inc.php プロジェクト: justinlyon/scc
 // and are set to auto-redirect to SEF URLs
 // try fetching from DB
 $shSefUrl = null;
 $nonSefURL = 'index.php?' . $shPageInfo->QUERY_STRING;
 if (strpos($nonSefURL, 'lang=') === false) {
     $nonSefURL = shSetURLVar($nonSefURL, 'lang', shGetIsoCodeFromName($GLOBALS['shMosConfig_locale']));
 }
 $urlType = shGetSefURLFromCacheOrDB(shSortURL($nonSefURL), $shSefUrl);
 if ($urlType == sh404SEF_URLTYPE_AUTO || $urlType == sh404SEF_URLTYPE_CUSTOM) {
     // found a match
     $shRewriteBit = $sefConfig->shRewriteStrings[$sefConfig->shRewriteMode];
     $shSefUrl = (empty($shPageInfo->shHttpsSave) ? $GLOBALS['shConfigLiveSite'] : $shPageInfo->shHttpsSave) . $shRewriteBit . JString::ltrim($shSefUrl, '/') . ($shPageInfo->URI->anchor ? "#" . $shPageInfo->URI->anchor : '');
     _log('Redirecting J! sef URl to existing SEF URL : ' . $shSefUrl);
     shRedirect($shSefUrl);
 }
 if (!shIsMultilingual() || shIsMultilingual() == 'joomfish' && shGetNameFromIsoCode(shDecideRequestLanguage()) == $GLOBALS['shMosConfig_locale']) {
     $shSefUrl = (empty($shPageInfo->shHttpsSave) ? $GLOBALS['shConfigLiveSite'] : $shPageInfo->shHttpsSave) . '/index.php?' . $shPageInfo->QUERY_STRING;
     $GLOBALS['mosConfig_defaultLang'] = $shMosConfig_locale;
     // V x 01/09/2007 22:05:11 joomfish not initialised so we must do
     // this otherwise shGetDefaultLanguage will not work
     // check if language in URL
     $shIsoCode = '';
     $shTemp = explode('lang,', $shSefUrl);
     if (!empty($shTemp[1])) {
         $shIsoCode = explode('&', $shTemp[1]);
     }
     $shUri = null;
     $shOriginalUri = null;
     $shSefUrl = shSefRelToAbs($shSefUrl, shGetNameFromIsoCode($shIsoCode), $shUri, $shOriginalUri);
     if (strpos($shSefUrl, '/content/findkey') === false && strpos($shSefUrl, '/content/view') === false && strpos($shSefUrl, '/content/section') === false && strpos($shSefUrl, '/content/category') === false && strpos($shSefUrl, '/content/blogsection') === false && strpos($shSefUrl, '/content/blogcategory') === false && strpos($shSefUrl, '/content/archivesection') === false && strpos($shSefUrl, '/content/archivecategory') === false && strpos($shSefUrl, '/content/new') === false && strpos($shSefUrl, '/content/vote') === false && strpos($shSefUrl, '/component/option') === false && strpos($shSefUrl, '/content/view') === false && strpos($shSefUrl, 'task=view') === false && strpos($shSefUrl, 'task=section') === false && strpos($shSefUrl, 'task=category') === false && strpos($shSefUrl, 'task=blogsection') === false && strpos($shSefUrl, 'task=blogcategory') === false && strpos($shSefUrl, 'task=archivesection') === false && strpos($shSefUrl, 'task=archivecategory') === false) {
         _log('Redirecting J! sef URl to newly created SEF URL : ' . $shSefUrl);
コード例 #11
0
ファイル: router.php プロジェクト: lautarodragan/ideary
 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')) {
         // $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
         // create new sef url
         $targetSefUrl = $uri->toString(array('scheme', 'host', 'port')) . JRoute::_($nonSefUrl, $xhtml = false);
         if ($targetSefUrl != $pageInfo->shCurrentPageURL) {
             $sourceUrl = $uri->get('_uri');
             if (strpos($targetSefUrl, 'option=com') === false && $targetSefUrl != $sourceUrl) {
                 _log(__METHOD__ . '/' . __LINE__ . ': redirecting non-sef to newly created SEF : ' . $targetSefUrl . ' from ' . $nonSefUrl);
                 shRedirect($targetSefUrl);
             }
         }
     }
 }