コード例 #1
0
ファイル: ActionSearch.class.php プロジェクト: Azany/altocms
 /**
  * Протоколирование запросов
  *
  * @param array|null $aVars
  */
 public function OutLog($aVars = null)
 {
     if (!$this->bLogEnable) {
         return;
     }
     if (!($sLogFile = Config::Get('module.search.logs.file'))) {
         $sLogFile = 'search.log';
     }
     if (!$this->oUser) {
         if ($sUserId = E::ModuleSession()->Get('user_id')) {
             $this->oUser = E::ModuleUser()->GetUserById($sUserId);
         }
     }
     if (!$this->oUser) {
         $sUserLogin = '******';
     } else {
         $sUserLogin = $this->oUser->GetLogin();
     }
     $path = R::GetPathWebCurrent();
     $uri = $_SERVER['REQUEST_URI'];
     $sStrLog = 'user=>"' . $sUserLogin . '" ip=>"' . $_SERVER['REMOTE_ADDR'] . '"' . "\n" . str_repeat(' ', 22) . 'path=>' . $path . '"' . "\n" . str_repeat(' ', 22) . 'uri=>' . $uri . '"';
     if (is_array($aVars) && sizeof($aVars)) {
         foreach ($aVars as $key => $val) {
             $sStrLog .= "\n" . str_repeat(' ', 22) . $key . '=>"' . $val . '"';
         }
     }
     E::ModuleLogger()->Dump($sLogFile, $sStrLog);
 }
コード例 #2
0
ファイル: Viewer.class.php プロジェクト: anp135/altocms
 /**
  * Строит массив для подключения css и js,
  * преобразовывает их в строку для HTML
  *
  */
 protected function BuildHeadFiles()
 {
     $sPath = R::GetPathWebCurrent();
     $this->aFileRules = Config::Get('head.rules');
     foreach ((array) $this->aFileRules as $sName => $aRule) {
         if (!$aRule['path']) {
             continue;
         }
         foreach ((array) $aRule['path'] as $sRulePath) {
             $sPattern = "~" . str_replace(array('/', '*'), array('\\/', '\\w+'), $sRulePath) . "~";
             if (preg_match($sPattern, $sPath)) {
                 // * Преобразование JS
                 if (isset($aRule['js']['empty']) && $aRule['js']['empty']) {
                     E::ModuleViewerAsset()->ClearJs();
                 }
                 if (isset($aRule['js']['exclude']) && is_array($aRule['js']['exclude'])) {
                     E::ModuleViewerAsset()->ExcludeJs($aRule['js']['exclude']);
                 }
                 if (isset($aRule['js']['include']) && is_array($aRule['js']['include'])) {
                     E::ModuleViewerAsset()->AddJsFiles($aRule['js']['include']);
                 }
                 // * Преобразование CSS
                 if (isset($aRule['css']['empty']) && $aRule['css']['empty']) {
                     E::ModuleViewerAsset()->ClearCss();
                 }
                 if (isset($aRule['css']['exclude']) && is_array($aRule['css']['exclude'])) {
                     E::ModuleViewerAsset()->ExcludeCss($aRule['css']['exclude']);
                 }
                 if (isset($aRule['css']['include']) && is_array($aRule['css']['include'])) {
                     E::ModuleViewerAsset()->AddCssFiles($aRule['css']['include']);
                 }
                 // * Продолжаем поиск
                 if (isset($aRule['stop'])) {
                     break 2;
                 }
             }
         }
     }
     E::ModuleViewerAsset()->Prepare();
     // * Объединяем файлы в наборы
     $aHeadFiles = array('js' => array(), 'css' => array());
     // * Получаем HTML код
     $aHtmlHeadFiles = $this->BuildHtmlHeadFiles($aHeadFiles);
     $this->SetHtmlHeadFiles($aHtmlHeadFiles);
 }
コード例 #3
0
ファイル: ActionBlog.class.php プロジェクト: anp135/altocms
 /**
  * Show topic
  *
  * @return string|null
  */
 protected function EventShowTopic()
 {
     $this->sMenuHeadItemSelect = 'index';
     $sBlogUrl = '';
     $sTopicUrlMask = R::GetTopicUrlMask();
     if ($this->oCurrentTopic) {
         $this->oCurrentBlog = $this->oCurrentTopic->getBlog();
         if ($this->oCurrentBlog) {
             $sBlogUrl = $this->oCurrentBlog->getUrl();
         }
         $this->sMenuItemSelect = 'blog';
     } else {
         if ($this->GetParamEventMatch(0, 1)) {
             // из коллективного блога
             $sBlogUrl = $this->sCurrentEvent;
             $iTopicId = $this->GetParamEventMatch(0, 1);
             $this->sMenuItemSelect = 'blog';
         } else {
             // из персонального блога
             $iTopicId = $this->GetEventMatch(1);
             $this->sMenuItemSelect = 'log';
         }
         // * Проверяем есть ли такой топик
         if (!$iTopicId || !($this->oCurrentTopic = E::ModuleTopic()->GetTopicById($iTopicId))) {
             return parent::EventNotFound();
         }
     }
     if (!$this->oCurrentTopic->getBlog()) {
         // Этого быть не должно, но если вдруг, то надо отработать
         return parent::EventNotFound();
     }
     $this->sMenuSubItemSelect = '';
     // Trusted user is admin or owner of topic
     if ($this->oUserCurrent && ($this->oUserCurrent->isAdministrator() || $this->oUserCurrent->isModerator() || $this->oUserCurrent->getId() == $this->oCurrentTopic->getUserId())) {
         $bTrustedUser = true;
     } else {
         $bTrustedUser = false;
     }
     if (!$bTrustedUser) {
         // Topic with future date
         if ($this->oCurrentTopic->getDate() > date('Y-m-d H:i:s')) {
             return parent::EventNotFound();
         }
         // * Проверяем права на просмотр топика-черновика
         if (!$this->oCurrentTopic->getPublish()) {
             if (!Config::Get('module.topic.draft_link')) {
                 return parent::EventNotFound();
             } else {
                 // Если режим просмотра по прямой ссылке включен, то проверяем параметры
                 $bOk = false;
                 if ($sDraftCode = F::GetRequestStr('draft', null, 'get')) {
                     if (strpos($sDraftCode, ':')) {
                         list($nUser, $sHash) = explode(':', $sDraftCode);
                         if ($this->oCurrentTopic->GetUserId() == $nUser && $this->oCurrentTopic->getTextHash() == $sHash) {
                             $bOk = true;
                         }
                     }
                 }
                 if (!$bOk) {
                     return parent::EventNotFound();
                 }
             }
         }
     }
     // Если номер топика правильный, но URL блога неверный, то корректируем его и перенаправляем на нужный адрес
     if ($sBlogUrl !== '' && $this->oCurrentTopic->getBlog()->getUrl() !== $sBlogUrl) {
         R::Location($this->oCurrentTopic->getUrl());
     }
     // Если запросили топик с определенной маской, не указаным названием блога,
     // но ссылка на топик и ЧПУ url разные, и это не запрос RSS
     // то перенаправляем на страницу для вывода топика (во избежание дублирования контента по разным URL)
     if ($sTopicUrlMask && $sBlogUrl == '' && $this->oCurrentTopic->getUrl() != R::GetPathWebCurrent() . (substr($this->oCurrentTopic->getUrl(), -1) === '/' ? '/' : '') && substr(R::RealUrl(true), 0, 4) !== 'rss/') {
         R::Location($this->oCurrentTopic->getUrl());
     }
     // Checks rights to show content from the blog
     if (!$this->oCurrentTopic->getBlog()->CanReadBy($this->oUserCurrent)) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('acl_cannot_show_content'), E::ModuleLang()->Get('not_access'));
         return R::Action('error');
     }
     // Обрабатываем добавление коммента
     if (isset($_REQUEST['submit_comment'])) {
         $this->SubmitComment();
     }
     // Достаём комменты к топику
     if (!Config::Get('module.comment.nested_page_reverse') && Config::Get('module.comment.use_nested') && Config::Get('module.comment.nested_per_page')) {
         $iPageDef = ceil(E::ModuleComment()->GetCountCommentsRootByTargetId($this->oCurrentTopic->getId(), 'topic') / Config::Get('module.comment.nested_per_page'));
     } else {
         $iPageDef = 1;
     }
     $iPage = intval(F::GetRequest('cmtpage', 0));
     if ($iPage < 1) {
         $iPage = $iPageDef;
     }
     $aReturn = E::ModuleComment()->GetCommentsByTargetId($this->oCurrentTopic, 'topic', $iPage, Config::Get('module.comment.nested_per_page'));
     $iMaxIdComment = $aReturn['iMaxIdComment'];
     /** @var ModuleComment_EntityComment[] $aComments */
     $aComments = $aReturn['comments'];
     if ($aComments && $iMaxIdComment && isset($aComments[$iMaxIdComment])) {
         $sLastCommentDate = $aComments[$iMaxIdComment]->getDate();
     } else {
         $sLastCommentDate = null;
     }
     // Если используется постраничность для комментариев - формируем ее
     if (Config::Get('module.comment.use_nested') && Config::Get('module.comment.nested_per_page')) {
         $aPaging = E::ModuleViewer()->MakePaging($aReturn['count'], $iPage, Config::Get('module.comment.nested_per_page'), Config::Get('pagination.pages.count'), '');
         if (!Config::Get('module.comment.nested_page_reverse') && $aPaging) {
             // переворачиваем страницы в обратном порядке
             $aPaging['aPagesLeft'] = array_reverse($aPaging['aPagesLeft']);
             $aPaging['aPagesRight'] = array_reverse($aPaging['aPagesRight']);
         }
         E::ModuleViewer()->Assign('aPagingCmt', $aPaging);
     }
     //      issue 253 {@link https://github.com/altocms/altocms/issues/253}
     //      Запрещаем оставлять комментарии к топику-черновику
     //      if ($this->oUserCurrent) {
     if ($this->oUserCurrent && (int) $this->oCurrentTopic->getPublish()) {
         $bAllowToComment = E::ModuleBlog()->GetBlogsAllowTo('comment', $this->oUserCurrent, $this->oCurrentTopic->getBlog()->GetId(), true);
     } else {
         $bAllowToComment = false;
     }
     // Отмечаем прочтение топика
     if ($this->oUserCurrent) {
         $oTopicRead = E::ModuleTopic()->GetTopicRead($this->oCurrentTopic->getId(), $this->oUserCurrent->getid());
         if (!$oTopicRead) {
             /** @var ModuleTopic_EntityTopicRead $oTopicRead */
             $oTopicRead = E::GetEntity('Topic_TopicRead');
             $oTopicRead->setTopicId($this->oCurrentTopic->getId());
             $oTopicRead->setUserId($this->oUserCurrent->getId());
             $oTopicRead->setCommentCountLast($this->oCurrentTopic->getCountComment());
             $oTopicRead->setCommentIdLast($iMaxIdComment);
             $oTopicRead->setDateRead(F::Now());
             E::ModuleTopic()->AddTopicRead($oTopicRead);
         } else {
             if ($oTopicRead->getCommentCountLast() != $this->oCurrentTopic->getCountComment() || $oTopicRead->getCommentIdLast() != $iMaxIdComment || !is_null($sLastCommentDate) && $oTopicRead->getDateRead() <= $sLastCommentDate) {
                 $oTopicRead->setCommentCountLast($this->oCurrentTopic->getCountComment());
                 $oTopicRead->setCommentIdLast($iMaxIdComment);
                 $oTopicRead->setDateRead(F::Now());
                 E::ModuleTopic()->UpdateTopicRead($oTopicRead);
             }
         }
     }
     // Выставляем SEO данные
     $sTextSeo = strip_tags($this->oCurrentTopic->getText());
     E::ModuleViewer()->SetHtmlDescription(F::CutText($sTextSeo, Config::Get('view.html.description_max_words')));
     E::ModuleViewer()->SetHtmlKeywords($this->oCurrentTopic->getTags());
     E::ModuleViewer()->SetHtmlCanonical($this->oCurrentTopic->getUrl());
     // Вызов хуков
     E::ModuleHook()->Run('topic_show', array('oTopic' => $this->oCurrentTopic));
     // Загружаем переменные в шаблон
     E::ModuleViewer()->Assign('oTopic', $this->oCurrentTopic);
     E::ModuleViewer()->Assign('aComments', $aComments);
     E::ModuleViewer()->Assign('iMaxIdComment', $iMaxIdComment);
     E::ModuleViewer()->Assign('bAllowToComment', $bAllowToComment);
     // Устанавливаем title страницы
     E::ModuleViewer()->AddHtmlTitle($this->oCurrentTopic->getBlog()->getTitle());
     E::ModuleViewer()->AddHtmlTitle($this->oCurrentTopic->getTitle());
     E::ModuleViewer()->SetHtmlRssAlternate(R::GetPath('rss') . 'comments/' . $this->oCurrentTopic->getId() . '/', $this->oCurrentTopic->getTitle());
     // Устанавливаем шаблон вывода
     $this->SetTemplateAction('topic');
     // Additional tags for <head>
     $aHeadTags = $this->_getHeadTags($this->oCurrentTopic);
     if ($aHeadTags) {
         E::ModuleViewer()->SetHtmlHeadTags($aHeadTags);
     }
     return null;
 }