Ejemplo n.º 1
0
 public function getUrlsCount($which = 'auto')
 {
     switch (strtolower($which)) {
         // we want to read all automatic urls (include duplicates)
         case 'auto':
             $numberOfUrls = ShlDbHelper::count($this->_getTableName(), '*', array('dateadd' => '0000-00-00'));
             break;
             // we want to read urls as per current selection input fields
             // ie : component, language, custom, ...
         // we want to read urls as per current selection input fields
         // ie : component, language, custom, ...
         case 'selected':
             $numberOfUrls = $this->getTotal();
             break;
         case 'view404':
         case '404':
             $query = 'select count(*) from ' . $this->_db->quoteName($this->_getTableName()) . ' where ' . $this->_db->quoteName('dateadd') . '!=' . $this->_db->Quote('0000-00-00') . ' and ' . $this->_db->quoteName('newurl') . '=' . $this->_db->Quote('');
             try {
                 $this->_db->setQuery($query);
                 $numberOfUrls = $this->_db->shlLoadResult();
             } catch (Exception $e) {
                 ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
                 $numberOfUrls = 0;
             }
             break;
         default:
             $numberOfUrls = 0;
             break;
     }
     return intval($numberOfUrls);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 public function getAliasesCount($which = 'auto')
 {
     switch (strtolower($which)) {
         // we want to read all automatic urls (include duplicates)
         case 'auto':
             try {
                 $numberOfUrls = ShlDbHelper::count($this->_getTableName(), '*', array('type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_ALIAS));
             } catch (Exception $e) {
                 $numberofUrls = 0;
             }
             break;
             // we want to read urls as per current selection input fields
             // ie : component, language, custom, ...
         // we want to read urls as per current selection input fields
         // ie : component, language, custom, ...
         case 'selected':
             $numberOfUrls = $this->getTotal();
             break;
         default:
             $numberOfUrls = 0;
             break;
     }
     return intval($numberOfUrls);
 }
Ejemplo n.º 4
0
 private function _buildPageId()
 {
     $shURL = '';
     $nextId = $this->_getNextDBId($this->_db->getPrefix() . 'sh404sef_pageids');
     if ($nextId !== false) {
         $nextId = base_convert(18 + $nextId, 10, 18);
         for ($c = 0; $c < strlen($nextId); ++$c) {
             $char = base_convert($nextId[$c], 18, 10);
             $shURL .= self::$_regular[$char];
         }
     }
     // now check if this shurl is not an existing
     // SEF or alias. If so, use the alternate char set
     // to create a new shurl, and try again.
     // using alternate char set (instead of simply increasing nextId)
     // makes sure that next time we try to create a shurl (for next URL)
     // we won't try something we've already used, making the number of attempts
     // for each shurl creation grows each time there is a collision
     try {
         $attempts = 0;
         $maxAttempts = 8;
         // don't need to check for collisions with existing shurls
         // as we use the next insert id, and code that using a unique char set
         //however, if we need to modify the shurl because it collides with
         // an existing SEF url or an alias, we will do so using the alternate
         // character set, so the new shurl don't risk collision with a regular
         // shurl but it may then collide with another, previously modified shurl
         // and so we need to check for shurl collisions when this happens
         $doneShurl = true;
         // however, need to check for collisions with regular sef urls and aliases
         $doneSef = false;
         $doneAlias = false;
         // and for bad language
         $doneClean = false;
         // prepare user set bad language/exclusion list
         $sefConfig =& Sh404sefFactory::getConfig();
         $sefConfig->shurlBlackList = JString::trim($sefConfig->shurlBlackList);
         if (empty($sefConfig->shurlBlackList)) {
             $blackList = array();
         } else {
             if (strpos($sefConfig->shurlBlackList, '|') !== false) {
                 $blackList = explode('|', $sefConfig->shurlBlackList);
             } else {
                 $blackList = array($sefConfig->shurlBlackList);
             }
         }
         $doneBlackList = false;
         do {
             // clean word check
             if (!$doneClean) {
                 if (in_array($shURL, self::$_badWords)) {
                     // bad language
                     $attempts++;
                     // build a new shurl, by changing a character
                     // with one from the alternate set
                     $shURL = $this->_getModifiedShurl($shURL);
                     // invalidate shurl and alias check flag, to check again with this new shurl
                     $doneShurl = false;
                     $doneAlias = false;
                     $doneSef = false;
                     $doneBlackList = false;
                 } else {
                     $doneClean = true;
                 }
             }
             // user word black list
             if (!$doneBlackList) {
                 if (in_array($shURL, $blackList)) {
                     // bad language
                     $attempts++;
                     // build a new shurl, by changing a character
                     // with one from the alternate set
                     $shURL = $this->_getModifiedShurl($shURL);
                     // invalidate shurl and alias check flag, to check again with this new shurl
                     $doneShurl = false;
                     $doneAlias = false;
                     $doneSef = false;
                     $doneClean = false;
                 } else {
                     $doneBlackList = true;
                 }
             }
             // regular SEF url collision check
             if (!$doneSef) {
                 $isSEF = (int) ShlDbHelper::count('#__sh404sef_urls', '*', $this->_db->quoteName('oldurl') . ' = ? and ' . $this->_db->quoteName('newurl') . ' <> ?', array($shURL, ''));
                 if (!empty($isSEF)) {
                     // there is already a SEF url like that
                     $attempts++;
                     // build a new shurl, by changing a character
                     // with one from the alternate set
                     $shURL = $this->_getModifiedShurl($shURL);
                     // invalidate shurl and alias check flag, to check again with this new shurl
                     $doneShurl = false;
                     $doneAlias = false;
                     $doneClean = false;
                     $doneBlackList = false;
                 } else {
                     $doneSef = true;
                 }
             }
             // previous shurl check
             if (!$doneShurl) {
                 $isShurl = (int) ShlDbHelper::count('#__sh404sef_pageids', '*', array('pageid' => $shURL, 'type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_PAGEID));
                 if (!empty($isShurl)) {
                     // there is already a shurl like that
                     $attempts++;
                     // build a new shurl, by changing a character
                     // with one from the alternate set
                     $shURL = $this->_getModifiedShurl($shURL);
                     // invalidate regular sef and alias check flag, to check again with this new shurl
                     $doneSef = false;
                     $doneAlias = false;
                     $doneClean = false;
                     $doneBlackList = false;
                 } else {
                     $doneShurl = true;
                 }
             }
             // alias collision check
             if (!$doneAlias) {
                 $isAlias = (int) ShlDbHelper::count('#__sh404sef_aliases', '*', array('alias' => $shURL, 'type' => Sh404sefHelperGeneral::COM_SH404SEF_URLTYPE_ALIAS));
                 if (!empty($isAlias)) {
                     // there is already an alias like that
                     $attempts++;
                     // build a new shurl, by changing a character
                     // with one from the alternate set
                     $shURL = $this->_getModifiedShurl($shURL);
                     // invalidate regular sef and shurl check flag, to check again with this new shurl
                     $doneSef = false;
                     $doneShurl = false;
                     $doneClean = false;
                     $doneBlackList = false;
                 } else {
                     $doneAlias = true;
                 }
             }
         } while ((!$doneSef || !$doneAlias || !$doneShurl || !$doneClean || !$doneBlackList) && $attempts < $maxAttempts);
     } catch (Exception $e) {
     }
     return $shURL;
 }
Ejemplo n.º 5
0
 /**
  * Count meta data records
  * either all of them or the currently selected set
  * as per user filter settings in meta manager
  *
  * @param string $type either 'all' or 'selected'
  */
 public function getMetaRecordsCount($type)
 {
     switch (strtolower($type)) {
         // we want to read all automatic urls (include duplicates)
         case 'all':
             try {
                 $numberOfMetaRecords = ShlDbHelper::count($this->_getTableName(), '*');
             } catch (Exception $e) {
                 $numberOfMetaRecords = 0;
                 ShlSystem_Log::error('sh404sef', '%s::%s::%d: %s', __CLASS__, __METHOD__, __LINE__, $e->getMessage());
             }
             break;
             // we want to read urls as per current selection input fields
             // ie : component, language, custom, ...
         // we want to read urls as per current selection input fields
         // ie : component, language, custom, ...
         case 'selected':
             // get model and update context with current
             $model = ShlMvcModel_Base::getInstance('urls', 'Sh404sefModel');
             // use current filters for default layout of metas manager
             $context = $model->updateContext($this->_context . '.' . 'default');
             // read url data from model
             $list = $model->getList((object) array('layout' => 'default', 'getMetaData' => true));
             $numberOfMetaRecords = 0;
             // just count urls with some meta data
             if (!empty($list)) {
                 foreach ($list as $urlRecord) {
                     if (!empty($urlRecord->metas)) {
                         $numberOfMetaRecords++;
                     }
                 }
             }
             break;
         default:
             $numberOfMetaRecords = 0;
             break;
     }
     return intval($numberOfMetaRecords);
 }