예제 #1
0
 /**
  * @param string                $sTargetType
  * @param int                   $iTargetId
  * @param ModuleUser_EntityUser $oCurrentUser
  */
 public function DeleteImage($sTargetType, $iTargetId, $oCurrentUser)
 {
     if ($sTargetType == 'profile_avatar') {
         if ($oCurrentUser && $oCurrentUser->getid() == $iTargetId) {
             $oUser = $oCurrentUser;
         } else {
             $oUser = E::ModuleUser()->GetUserById($iTargetId);
         }
         E::ModuleUser()->DeleteAvatar($oUser);
     } elseif ($sTargetType == 'profile_photo') {
         if ($oCurrentUser && $oCurrentUser->getid() == $iTargetId) {
             $oUser = $oCurrentUser;
         } else {
             $oUser = E::ModuleUser()->GetUserById($iTargetId);
         }
         E::ModuleUser()->DeletePhoto($oUser);
     } elseif ($sTargetType == 'blog_avatar') {
         /** @var ModuleBlog_EntityBlog $oBlog */
         $oBlog = E::ModuleBlog()->GetBlogById($iTargetId);
         E::ModuleBlog()->DeleteAvatar($oBlog);
     }
     E::ModuleMresource()->UnlinkFile($sTargetType, $iTargetId, $oCurrentUser ? $oCurrentUser->getId() : 0);
 }
예제 #2
0
 /**
  * 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;
 }