コード例 #1
0
ファイル: Lang.class.php プロジェクト: ZeoNish/altocms
 /**
  * Инициализация модуля
  *
  */
 public function Init()
 {
     E::ModuleHook()->Run('lang_init_start');
     $this->sDefaultLang = Config::Get('lang.default');
     $this->aLangPaths = F::File_NormPath(Config::Get('lang.paths'));
     // Проверку на языки делаем, только если сайт мультиязычный
     if (Config::Get('lang.multilang')) {
         // Время хранение языка в куках
         $nSavePeriod = F::ToSeconds(Config::Get('lang.save'));
         $sLangKey = is_string(Config::Get('lang.in_get')) ? Config::Get('lang.in_get') : 'lang';
         // Получаем язык, если он был задан в URL
         $this->sCurrentLang = R::GetLang();
         // Проверка куки, если требуется
         if (!$this->sCurrentLang && $nSavePeriod) {
             $sLang = (string) E::ModuleSession()->GetCookie($sLangKey);
             if ($sLang) {
                 $this->sCurrentLang = $sLang;
             }
         }
         if (!$this->sCurrentLang) {
             $this->sCurrentLang = Config::Get('lang.current');
         }
     } else {
         $this->sCurrentLang = Config::Get('lang.current');
     }
     // Проверяем на случай старого обозначения языков
     $this->sDefaultLang = $this->_checkLang($this->sDefaultLang);
     $this->sCurrentLang = $this->_checkLang($this->sCurrentLang);
     if ($this->sCurrentLang && Config::Get('lang.multilang') && $nSavePeriod) {
         // Пишем в куки, если требуется
         E::ModuleSession()->SetCookie($sLangKey, $this->sCurrentLang, $nSavePeriod);
     }
     $this->InitLang();
 }
コード例 #2
0
ファイル: Lang.class.php プロジェクト: anp135/altocms
 /**
  * Инициализация модуля
  *
  */
 public function Init()
 {
     E::ModuleHook()->Run('lang_init_start');
     $this->sDefaultLang = Config::Get('lang.default');
     $this->aLangPaths = F::File_NormPath(Config::Get('lang.paths'));
     $this->bDeleteUndefinedVars = Config::Get('module.lang.delete_undefined');
     // Allowed languages
     $aLangsAllow = (array) Config::Get('lang.allow');
     // Проверку на языки делаем, только если сайт мультиязычный
     if (Config::Get('lang.multilang')) {
         // Время хранение языка в куках
         $iSavePeriod = F::ToSeconds(Config::Get('lang.save'));
         $sLangKey = is_string(Config::Get('lang.in_get')) ? Config::Get('lang.in_get') : 'lang';
         // Получаем язык, если он был задан в URL
         $this->sCurrentLang = R::GetLang();
         // Проверка куки, если требуется
         if (!$this->sCurrentLang && $iSavePeriod) {
             $sLang = (string) E::ModuleSession()->GetCookie($sLangKey);
             if ($sLang) {
                 $this->sCurrentLang = $sLang;
             }
         }
         if (!$this->sCurrentLang) {
             $this->sCurrentLang = Config::Get('lang.current');
         }
     } else {
         $this->sCurrentLang = Config::Get('lang.current');
         $iSavePeriod = 0;
         $sLangKey = null;
     }
     // Current language must be in allowed languages
     if (!in_array($this->sCurrentLang, $aLangsAllow)) {
         $this->sCurrentLang = reset($aLangsAllow);
     }
     // Проверяем на случай старого обозначения языков
     $this->sDefaultLang = $this->_checkLang($this->sDefaultLang);
     $this->sCurrentLang = $this->_checkLang($this->sCurrentLang);
     if ($this->sCurrentLang && Config::Get('lang.multilang') && $iSavePeriod) {
         // Пишем в куки, если требуется
         E::ModuleSession()->SetCookie($sLangKey, $this->sCurrentLang, $iSavePeriod);
     }
     $this->InitLang();
 }
コード例 #3
0
ファイル: Viewer.class.php プロジェクト: anp135/altocms
 /**
  * Set templator options
  *
  * @param array $aOptions
  */
 protected function _tplSetOptions($aOptions)
 {
     self::$_renderOptionsStack[] = array('caching' => $this->oSmarty->caching, 'cache_lifetime' => $this->oSmarty->cache_lifetime);
     if (isset($aOptions['cache'])) {
         $this->oSmarty->caching = Smarty::CACHING_LIFETIME_SAVED;
         if ($aOptions['cache'] === false) {
             // Отключаем кеширование
             $this->oSmarty->cache_lifetime = 0;
         } elseif (isset($aOptions['cache']['time'])) {
             if ($aOptions['cache']['time'] == -1) {
                 // Задаем бессрочное кеширование
                 $this->oSmarty->cache_lifetime = -1;
             } elseif ($aOptions['cache']['time']) {
                 // Задаем время кеширования
                 $this->oSmarty->cache_lifetime = F::ToSeconds($aOptions['cache']['time']);
             } else {
                 // Отключаем кеширование
                 $this->oSmarty->cache_lifetime = 0;
             }
         }
     }
 }
コード例 #4
0
ファイル: Cache.class.php プロジェクト: AlexSSN/altocms
 /**
  * Записать значение в кеш
  *
  * The following life time periods are recognized:
  * <pre>
  * Time interval    | Number of seconds
  * ----------------------------------------------------
  * 3600             | 3600 seconds
  * 2 hours          | Two hours = 60 * 60 * 2 = 7200 seconds
  * 1 day + 12 hours | One day and 12 hours = 60 * 60 * 24 + 60 * 60 * 12 = 129600 seconds
  * 3 months         | Three months = 3 * 30 days = 3 * (60 * 60 * 24 * 30) = 7776000 seconds
  * PT3600S          | 3600 seconds
  * P1DT12H          | One day and 12 hours = 60 * 60 * 24 + 60 * 60 * 12 = 129600 seconds
  * P3M              | Three months = 3 * 30 days = 3 * (60 * 60 * 24 * 30) = 7776000 seconds
  * ----------------------------------------------------
  * Full ISO 8601 interval format: PnYnMnDTnHnMnS
  * </pre>
  *
  * @param   mixed               $xData      - Данные для хранения в кеше
  * @param   string              $sCacheKey  - Имя ключа кеширования
  * @param   array               $aTags      - Список тегов, для возможности удалять сразу несколько кешей по тегу
  * @param   string|int|bool     $nTimeLife  - Время жизни кеша (в секундах или в строковом интервале)
  * @param   string|bool|null    $sCacheType - Тип используемого кеша
  *
  * @return  bool
  */
 public function Set($xData, $sCacheKey, $aTags = array(), $nTimeLife = false, $sCacheType = null)
 {
     if ($sCacheType && strpos($sCacheType, ',') !== false) {
         $aCacheTypes = explode(',', $sCacheType);
         $bResult = false;
         foreach ($aCacheTypes as $sCacheType) {
             if (!$sCacheType && in_array($this->sCacheType, $aCacheTypes)) {
                 // skip double cache
                 continue;
             }
             $bResult = $bResult || $this->Set($xData, $sCacheKey, $aTags, $nTimeLife, $sCacheType ? $sCacheType : null);
         }
         return $bResult;
     }
     // Проверяем возможность кеширования
     $nMode = $this->_cacheOn($sCacheType);
     if (!$nMode) {
         return false;
     }
     /*
     // Если модуль завершил свою работу и не включено принудительное кеширование, то ничего не кешируется
     if ($this->isDone() && ($nMode != self::CACHE_MODE_FORCE)) {
         return false;
     }
     */
     if ($this->iDisabled & self::DISABLED_SET && $nMode != self::CACHE_MODE_FORCE) {
         return false;
     }
     // Теги - это массив строковых значений
     $aTags = $this->_prepareTags($aTags);
     if (is_string($nTimeLife)) {
         $nTimeLife = F::ToSeconds($nTimeLife);
     } else {
         $nTimeLife = intval($nTimeLife);
     }
     if (!$sCacheType) {
         $sCacheType = $this->sCacheType;
     }
     // Если необходимо разрешение конкурирующих запросов к кешу, то реальное время жизни кеша увеличиваем
     if ($nTimeLife && ($nConcurrentDaley = $this->_backendIsConcurrent($sCacheType))) {
         $aData = array('time' => time() + $nTimeLife, 'tags' => $aTags, 'data' => $xData);
         $nTimeLife += $nConcurrentDaley;
     } else {
         $aData = array('time' => false, 'tags' => $aTags, 'data' => $xData);
     }
     return $this->_backendSave($sCacheType, $aData, $this->_hash($sCacheKey), $aTags, $nTimeLife);
 }
コード例 #5
0
ファイル: ActionSearch.class.php プロジェクト: Azany/altocms
 protected function _checkLimits()
 {
     $iLimitQueries = intval(C::Get('module.search.limit.queries'));
     $iLimitPeriod = F::ToSeconds(C::Get('module.search.limit.period'));
     $iLimitInterval = F::ToSeconds(C::Get('module.search.limit.interval'));
     if (!F::GetRequest('q') || !$iLimitQueries || !$iLimitPeriod) {
         return true;
     }
     $sLastSearchQueries = E::ModuleSession()->Get('last_search_queries');
     if (empty($sLastSearchQueries)) {
         $aLastSearchQueries = array();
     } else {
         $aLastSearchQueries = F::Unserialize($sLastSearchQueries);
     }
     $iCount = 0;
     if (!empty($aLastSearchQueries)) {
         $iTimeLimit = time() - $iLimitPeriod;
         //echo date('H:i:s', time()), '--', date('H:i:s', $iTimeLimit), '<br>';
         foreach ($aLastSearchQueries as $iIndex => $aQuery) {
             //echo $iIndex, ' - ', date('H:i:s', $aQuery['time']);
             if ($aQuery['time'] >= $iTimeLimit) {
                 $iCount += 1;
                 //echo ' * ';
             }
             //echo '<br>';
         }
         $aLastQuery = end($aLastSearchQueries);
     } else {
         $aLastQuery = null;
     }
     if (count($aLastSearchQueries) > $iLimitQueries) {
         $aLastSearchQueries = array_slice($aLastSearchQueries, -$iLimitQueries);
     }
     $aLastSearchQueries[] = array('time' => time(), 'query' => F::GetRequest('q'));
     E::ModuleSession()->Set('last_search_queries', F::Serialize($aLastSearchQueries));
     //die('iCount:' . $iCount);
     if ($iCount > $iLimitQueries) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('search_err_frequency', array('num' => $iLimitQueries, 'sec' => $iLimitPeriod)));
         return false;
     }
     if (!empty($aLastQuery['time']) && $iLimitInterval && $aLastQuery['time'] > time() - $iLimitInterval) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('search_err_interval', array('sec' => $iLimitInterval)));
         return false;
     }
     return true;
 }
コード例 #6
0
ファイル: ActionAdmin.class.php プロジェクト: ZeoNish/altocms
 /**
  * Site settings > Edit
  */
 protected function _eventConfigEdit()
 {
     $aUnits = array('S' => array('name' => 'seconds'), 'M' => array('name' => 'minutes'), 'H' => array('name' => 'hours'), 'D' => array('name' => 'days'));
     if ($this->GetPost('submit_data_save')) {
         $aConfig = array();
         if ($this->GetPost('view--wysiwyg')) {
             $aConfig['view.wysiwyg'] = true;
         } else {
             $aConfig['view.wysiwyg'] = false;
         }
         if ($this->GetPost('view--noindex')) {
             $aConfig['view.noindex'] = true;
         } else {
             $aConfig['view.noindex'] = false;
         }
         //$aConfig['view.img_resize_width'] = intval($this->GetPost('view--img_resize_width'));
         //$aConfig['view.img_max_width'] = intval($this->GetPost('view--img_max_width'));
         //$aConfig['view.img_max_height'] = intval($this->GetPost('view--img_max_height'));
         $aConfig['module.uploader.images.default.max_width'] = intval($this->GetPost('view--img_max_width'));
         $aConfig['module.uploader.images.default.max_height'] = intval($this->GetPost('view--img_max_height'));
         if ($this->GetPost('tag_required')) {
             $aConfig['module.topic.allow_empty_tags'] = false;
         } else {
             $aConfig['module.topic.allow_empty_tags'] = true;
         }
         if ($nVal = intval($this->GetPost('module--topic--max_length'))) {
             $aConfig['module.topic.max_length'] = $nVal;
         }
         $aConfig['module.comment.edit.enable'] = false;
         if ($this->GetPost('edit_comment') == 'on') {
             $nEditTime = intval($this->GetPost('edit_comment_time'));
             if ($nEditTime) {
                 $sEditUnit = '';
                 if ($this->GetPost('edit_comment_unit')) {
                     foreach ($aUnits as $sKey => $sUnit) {
                         if ($sUnit['name'] == $this->GetPost('edit_comment_unit')) {
                             $sEditUnit = $sKey;
                             break;
                         }
                     }
                 }
                 if (!$sEditUnit) {
                     $sEditUnit = 'S';
                 }
                 if ($sEditUnit == 'D') {
                     $nEditTime = F::ToSeconds('P' . $nEditTime . 'D');
                 } else {
                     $nEditTime = F::ToSeconds('PT' . $nEditTime . $sEditUnit);
                 }
                 $aConfig['module.comment.edit.enable'] = $nEditTime;
             }
         }
         Config::WriteCustomConfig($aConfig);
         R::Location('admin/settings-site/');
         exit;
     }
     $this->SetTemplateAction('settings/edit');
     $nCommentEditTime = F::ToSeconds(Config::Get('module.comment.edit.enable'));
     if ($nCommentEditTime) {
         $sCommentEditUnit = $aUnits['S']['name'];
         if ($nCommentEditTime % 60 == 0) {
             $nCommentEditTime = $nCommentEditTime / 60;
             $sCommentEditUnit = $aUnits['M']['name'];
             if ($nCommentEditTime % 60 == 0) {
                 $nCommentEditTime = $nCommentEditTime / 60;
                 $sCommentEditUnit = $aUnits['H']['name'];
                 if ($nCommentEditTime % 24 == 0) {
                     $nCommentEditTime = $nCommentEditTime / 24;
                     $sCommentEditUnit = $aUnits['D']['name'];
                 }
             }
         }
     } else {
         $sCommentEditUnit = $aUnits['S']['name'];
     }
     E::ModuleViewer()->Assign('nCommentEditTime', $nCommentEditTime);
     E::ModuleViewer()->Assign('sCommentEditUnit', $sCommentEditUnit);
     E::ModuleViewer()->Assign('aTimeUnits', $aUnits);
 }
コード例 #7
0
ファイル: Admin.class.php プロジェクト: AntiqS/altocms
 /**
  * Генерация URL топиков. Процесс может быть долгим, поэтому стараемся предотвратить ошибку по таймауту
  */
 public function GenerateTopicsUrl()
 {
     $nRecLimit = 500;
     $nTimeLimit = F::ToSeconds(ini_get('max_execution_time')) * 0.8 - 5 + time();
     $nResult = -1;
     while (true) {
         $aData = $this->oMapper->GetTitleTopicsWithoutUrl($nRecLimit);
         if (!$aData) {
             $nResult = 0;
             break;
         }
         foreach ($aData as $nTopicId => $sTopicTitle) {
             $aData[$nTopicId]['topic_url'] = substr(F::TranslitUrl($aData[$nTopicId]['topic_title']), 0, 240);
         }
         if (!$this->oMapper->SaveTopicsUrl($aData)) {
             return -1;
         }
         // если время на исходе, то завершаем
         if (time() >= $nTimeLimit) {
             break;
         }
     }
     if ($nResult == 0) {
         // нужно ли проверять ссылки на дубликаты
         $iOnDuplicateUrl = Config::Val('module.topic.on_duplicate_url', 1);
         if ($iOnDuplicateUrl) {
             $this->CheckDuplicateTopicsUrl();
         }
     } else {
         $nResult = $this->GetNumTopicsWithoutUrl();
     }
     return $nResult;
 }
コード例 #8
0
ファイル: ActionSearch.class.php プロジェクト: anp135/altocms
 /**
  * @return bool
  */
 protected function _checkLimits()
 {
     $iLimitQueries = (int) C::Get('module.search.limit.queries');
     $iLimitPeriod = F::ToSeconds(C::Get('module.search.limit.period'));
     $iLimitInterval = F::ToSeconds(C::Get('module.search.limit.interval'));
     if (!F::GetRequest('q') || !$iLimitQueries || !$iLimitPeriod) {
         return true;
     }
     $aLastSearchQueries = $this->_statLoad();
     $iCount = 0;
     if (count($aLastSearchQueries) > 0) {
         $iTimeLimit = time() - $iLimitPeriod;
         foreach ($aLastSearchQueries as $iIndex => $aQuery) {
             if ($aQuery['time'] >= $iTimeLimit) {
                 ++$iCount;
             }
         }
         $aLastQuery = end($aLastSearchQueries);
     } else {
         $aLastQuery = null;
     }
     if (count($aLastSearchQueries) > $iLimitQueries) {
         $aLastSearchQueries = array_slice($aLastSearchQueries, -$iLimitQueries);
     }
     $aLastSearchQueries[] = array('time' => time(), 'query' => F::GetRequest('q'));
     $this->_statSave($aLastSearchQueries);
     if ($iCount > $iLimitQueries) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('search_err_frequency', array('num' => $iLimitQueries, 'sec' => $iLimitPeriod)));
         return false;
     }
     if (!empty($aLastQuery['time']) && $iLimitInterval && $aLastQuery['time'] > time() - $iLimitInterval) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('search_err_interval', array('sec' => $iLimitInterval)));
         return false;
     }
     return true;
 }
コード例 #9
0
 /**
  * Вышло ли время для голосования
  *
  * @return bool
  */
 public function isVoteExpired()
 {
     $nTimeLimit = Config::Get('acl.vote.comment.limit_time');
     if (!$nTimeLimit) {
         return false;
     }
     return strtotime($this->getDate()) < time() - F::ToSeconds($nTimeLimit);
 }
コード例 #10
0
ファイル: Session.class.php プロジェクト: hard990/altocms
 /**
  * Sets cookie
  *
  * @param   string          $sName
  * @param   string          $sValue
  * @param   int|string|null $xPeriod - period in seconds or in string like 'P<..>'
  * @param   bool            $bHttpOnly
  * @param   bool            $bSecure
  */
 public function SetCookie($sName, $sValue, $xPeriod = null, $bHttpOnly = true, $bSecure = false)
 {
     if ($xPeriod) {
         $nTime = time() + F::ToSeconds($xPeriod);
     } else {
         $nTime = 0;
     }
     setcookie($sName, $sValue, $nTime, Config::Get('sys.cookie.path'), Config::Get('sys.cookie.host'), $bSecure, $bHttpOnly);
 }
コード例 #11
0
ファイル: Session.class.php プロジェクト: AlexSSN/altocms
 /**
  * Sets cookie
  *
  * @param   string          $sName
  * @param   string          $sValue
  * @param   int|string|null $xPeriod - period in seconds or in string like 'P<..>'
  * @param   bool            $bHttpOnly
  * @param   bool            $bSecure
  *
  * @return bool
  */
 public function SetCookie($sName, $sValue, $xPeriod = null, $bHttpOnly = true, $bSecure = false)
 {
     if ($xPeriod) {
         $nTime = time() + F::ToSeconds($xPeriod);
     } else {
         $nTime = 0;
     }
     $bResult = setcookie($sName, $sValue, $nTime, Config::Get('sys.cookie.path'), Config::Get('sys.cookie.host'), $bSecure, $bHttpOnly);
     if (DEBUG) {
         if (!$bResult) {
             if (headers_sent($sFilename, $iLine)) {
                 F::SysWarning('Cannot set cookie "' . $sName . '" - header was sent in file ' . $sFilename . '(' . $iLine . ')');
             } else {
                 F::SysWarning('Cannot set cookie "' . $sName . '"');
             }
         }
     }
     return $bResult;
 }