コード例 #1
0
ファイル: editalias.php プロジェクト: alesconti/FF_2015
 /**
  * Get a list of aliases from their ids,
  * passed as params
  *
  * @param array of integer $ids the list of aliases id to fetch
  * @return array of objects as read from db
  */
 public function getByIds($ids = array())
 {
     $aliases = array();
     if (empty($ids)) {
         return $aliases;
     }
     // select element where id is in list supplied
     try {
         $aliases = ShlDbHelper::selectObjectList($this->_getTableName(), array('*'), $this->_db->quoteName('id') . ' in (?)', ShlDbHelper::arrayToQuotedList($ids));
     } catch (Exception $e) {
     }
     // return result
     return $aliases;
 }
コード例 #2
0
ファイル: basemodel.php プロジェクト: alesconti/FF_2015
 /**
  * Returns a list of items as objects
  * as selected in the db based on passed
  * options (ie $options = array( 'id' => 12);)
  *
  * Data is not cached!
  *
  * @param array $options an array of key/ value pairs representing select params
  * @param boolean if true, method will only count matching records
  *
  * @return array of objects
  */
 public function getByAttr($options, $countOnly = false)
 {
     try {
         if ($countOnly) {
             $list = ShlDbHelper::count($this->_getTableName(), '*', $options);
         } else {
             $list = ShlDbHelper::selectObjectList($this->_getTableName(), '*', $options);
         }
     } catch (Exception $e) {
         $list = $countOnly ? 0 : array();
         ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
     }
     return $list;
 }
コード例 #3
0
ファイル: editurl.php プロジェクト: alesconti/FF_2015
 /**
  * Get a list of urls from their ids,
  * passed as params
  *
  * @param array of integer $ids the list of url id to fetch
  * @return array of objects as read from db
  */
 public function getByIds($ids = array())
 {
     $urls = array();
     if (empty($ids)) {
         return $urls;
     }
     try {
         $whereIds = ShlDbHelper::arrayToIntValList($ids);
         $urls = ShlDbHelper::selectObjectList($this->_getTableName(), '*', $this->_db->quoteName('id') . ' in (' . $whereIds . ')');
     } catch (Exception $e) {
         ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
     }
     // return result
     return $urls;
 }
コード例 #4
0
ファイル: general.php プロジェクト: alesconti/FF_2015
 public static function getUserGroups($format = 'all')
 {
     static $_groups = null;
     if (is_null($_groups)) {
         $groups_['all'] = array();
         $groups_['id'] = array();
         $groups_['title'] = array();
         // read groups from DB
         $rawGroups = array();
         try {
             $rawGroups = ShlDbHelper::selectObjectList('#__usergroups', array('id', 'title'));
         } catch (Exception $e) {
             ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
         }
         // store groups by format: id&name, id only, names only
         foreach ($rawGroups as $group) {
             $_groups['all'][$group->id] = $group->title;
             $_groups['id'][] = $group->id;
             $_groups['title'][] = $group->title;
         }
     }
     return $_groups[$format];
 }
コード例 #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
ファイル: com_community.php プロジェクト: alesconti/FF_2015
 function shGetJSVideoCategoryTitle($id, $option, $shLangName)
 {
     static $cats = null;
     $sefConfig =& Sh404sefFactory::getConfig();
     if (is_null($cats)) {
         try {
             $cats = ShlDbHelper::selectObjectList('#__community_videos_category', array('id', 'name'), $mWhere = '', $aWhereData = array(), $orderBy = array(), $offset = 0, $lines = 0, $key = 'id');
         } catch (Exception $e) {
             ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
             $cats = array();
         }
     }
     $prefix = empty($cats[$id]) || $sefConfig->shJSInsertVideoCatId ? $id : '';
     $slug = empty($cats[$id]) ? '' : $cats[$id]->name;
     $slug = $prefix . (empty($slug) ? '' : $sefConfig->replacement) . $slug;
     return $slug;
 }
コード例 #7
0
ファイル: com_newsfeeds.php プロジェクト: alesconti/FF_2015
$view = isset($view) ? $view : null;
$slugsModel = Sh404sefModelSlugs::getInstance();
switch ($view) {
    case 'newsfeed':
        if (!empty($catid)) {
            // V 1.2.4.q
            try {
                $title = $slugsModel->getCategorySlugArray('com_newsfeeds', $catid, shSEFConfig::CAT_ALL_NESTED_CAT, $useAlias = false, $insertId = false, $menuItemTitle = '', $shLangName);
            } catch (Exception $e) {
                ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
                $dosef = false;
            }
        }
        if (!empty($id)) {
            try {
                $rows = ShlDbHelper::selectObjectList('#__newsfeeds', array('name', 'id'), array('id' => $id));
            } catch (Exception $e) {
                ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
                JError::raiseError(500, $e->getMessage());
            }
            if (@count($rows) > 0) {
                if (!empty($rows[0]->name)) {
                    $title[] = $rows[0]->name;
                }
            }
        } else {
            $title[] = '/';
        }
        // V 1.2.4.s
        break;
    case 'category':
コード例 #8
0
ファイル: com_kunena.php プロジェクト: alesconti/FF_2015
 function shKUCategoryName($catid, $option, $shLangIso, $shLangName)
 {
     global $sh_LANG;
     static $cats = null;
     $sefConfig =& Sh404sefFactory::getConfig();
     if (empty($catid) || !$sefConfig->shFbInsertCategoryName) {
         return '';
     }
     if (class_exists('KunenaForum')) {
         // Kunena 2.0 support
         $category = KunenaForumCategory::getInstance($catid);
         $catname = $category->name;
     } elseif (class_exists('KunenaRouter')) {
         if (KunenaRouter::$catidcache === null) {
             KunenaRouter::loadCategories();
         }
         // Kunena 1.6 support
         $catname = empty(KunenaRouter::$catidcache[$catid]) ? '' : KunenaRouter::$catidcache[$catid]['name'];
     } else {
         // Kunena 1.0 / 1.5 support
         if (is_null($cats)) {
             try {
                 $cats = ShlDbHelper::selectObjectList('#__fb_categories', array('id', 'name'));
             } catch (Exception $e) {
                 ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
             }
         }
         $catname = empty($cats[$catid]) ? null : $cats[$catid]->name;
     }
     $shCat = empty($catname) ? $sh_LANG[$shLangIso]['COM_SH404SEF_KU_CATEGORY'] . $sefConfig->replacement . $catid : ($sefConfig->shFbInsertCategoryId ? $catid . $sefConfig->replacement : '') . $catname;
     // if name, put ID only if requested
     return $shCat;
 }
コード例 #9
0
ファイル: com_mtree.php プロジェクト: alesconti/FF_2015
 function shMTGetCustomFieldById($cfId)
 {
     static $fields = null;
     if (is_null($fields)) {
         try {
             $fields = ShlDbHelper::selectObjectList('#__mt_customfields', array('cf_id', 'caption'), $mWhere = '', $aWhereData = array(), $orderBy = array(), $offset = 0, $lines = 0, $key = 'cf_id');
         } catch (Exception $e) {
             ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
         }
     }
     // check if we have this field
     $cfCaption = empty($fields[$cfId]) ? '' : $fields[$cfId]->caption;
     if (!empty($cfCaption)) {
         shRemoveFromGETVarsList('cf_id');
     }
     return $cfCaption;
 }