/** * Обновляет топик * * @param ModuleTopic_EntityTopic $oTopic Объект топика * @return bool */ public function UpdateTopic(ModuleTopic_EntityTopic $oTopic) { $sql = "UPDATE " . Config::Get('db.table.topic') . "\n\t\t\tSET \n\t\t\t\tblog_id= ?d,\n\t\t\t\tblog_id2= ?d,\n\t\t\t\tblog_id3= ?d,\n\t\t\t\tblog_id4= ?d,\n\t\t\t\tblog_id5= ?d,\n\t\t\t\ttopic_title= ?,\n\t\t\t\ttopic_slug= ?,\n\t\t\t\ttopic_tags= ?,\n\t\t\t\ttopic_date_add = ?,\n\t\t\t\ttopic_date_edit = ?,\n\t\t\t\ttopic_date_edit_content = ?,\n\t\t\t\ttopic_date_publish = ?,\n\t\t\t\ttopic_user_ip= ?,\n\t\t\t\ttopic_publish= ?d ,\n\t\t\t\ttopic_publish_draft= ?d ,\n\t\t\t\ttopic_publish_index= ?d,\n\t\t\t\ttopic_skip_index= ?d,\n\t\t\t\ttopic_rating= ?f,\n\t\t\t\ttopic_count_vote= ?d,\n\t\t\t\ttopic_count_vote_up= ?d,\n\t\t\t\ttopic_count_vote_down= ?d,\n\t\t\t\ttopic_count_vote_abstain= ?d,\n\t\t\t\ttopic_count_read= ?d,\n\t\t\t\ttopic_count_comment= ?d, \n\t\t\t\ttopic_count_favourite= ?d,\n\t\t\t\ttopic_cut_text = ? ,\n\t\t\t\ttopic_forbid_comment = ? ,\n\t\t\t\ttopic_text_hash = ? \n\t\t\tWHERE\n\t\t\t\ttopic_id = ?d\n\t\t"; $res = $this->oDb->query($sql, $oTopic->getBlogId(), $oTopic->getBlogId2(), $oTopic->getBlogId3(), $oTopic->getBlogId4(), $oTopic->getBlogId5(), $oTopic->getTitle(), $oTopic->getSlug(), $oTopic->getTags(), $oTopic->getDateAdd(), $oTopic->getDateEdit(), $oTopic->getDateEditContent(), $oTopic->getDatePublish(), $oTopic->getUserIp(), $oTopic->getPublish(), $oTopic->getPublishDraft(), $oTopic->getPublishIndex(), $oTopic->getSkipIndex(), $oTopic->getRating(), $oTopic->getCountVote(), $oTopic->getCountVoteUp(), $oTopic->getCountVoteDown(), $oTopic->getCountVoteAbstain(), $oTopic->getCountRead(), $oTopic->getCountComment(), $oTopic->getCountFavourite(), $oTopic->getCutText(), $oTopic->getForbidComment(), $oTopic->getTextHash(), $oTopic->getId()); if ($res !== false and !is_null($res)) { $this->UpdateTopicContent($oTopic); return true; } return false; }
/** * Обновляет топик * * @param ModuleTopic_EntityTopic $oTopic Объект топика * * @return bool */ public function UpdateTopic(ModuleTopic_EntityTopic $oTopic) { $sql = "UPDATE ?_topic\n\t\t\tSET \n\t\t\t\tblog_id = ?d,\n\t\t\t\ttopic_title = ?,\n\t\t\t\ttopic_tags = ?,\n\t\t\t\ttopic_date_add = ?,\n\t\t\t\ttopic_date_edit = ?,\n\t\t\t\ttopic_date_show = ?,\n\t\t\t\ttopic_user_ip = ?,\n\t\t\t\ttopic_publish = ?d ,\n\t\t\t\ttopic_publish_draft = ?d ,\n\t\t\t\ttopic_publish_index = ?d,\n\t\t\t\ttopic_rating = ?f,\n\t\t\t\ttopic_count_vote = ?d,\n\t\t\t\ttopic_count_vote_up = ?d,\n\t\t\t\ttopic_count_vote_down = ?d,\n\t\t\t\ttopic_count_vote_abstain = ?d,\n\t\t\t\ttopic_count_read = ?d,\n\t\t\t\ttopic_count_comment = ?d,\n\t\t\t\ttopic_count_favourite = ?d,\n\t\t\t\ttopic_cut_text = ? ,\n\t\t\t\ttopic_forbid_comment = ? ,\n\t\t\t\ttopic_text_hash = ?,\n\t\t\t\ttopic_url = ?,\n\t\t\t\ttopic_index_ignore = ?d\n\t\t\tWHERE\n\t\t\t\ttopic_id = ?d\n\t\t"; $bResult = $this->oDb->query($sql, $oTopic->getBlogId(), $oTopic->getTitle(), $oTopic->getTags(), $oTopic->getDateAdd(), $oTopic->getDateEdit(), $oTopic->getDateShow(), $oTopic->getUserIp(), $oTopic->getPublish() ? 1 : 0, $oTopic->getPublishDraft() ? 1 : 0, $oTopic->getPublishIndex() ? 1 : 0, $oTopic->getRating(), $oTopic->getCountVote(), $oTopic->getCountVoteUp(), $oTopic->getCountVoteDown(), $oTopic->getCountVoteAbstain(), $oTopic->getCountRead(), $oTopic->getCountComment(), $oTopic->getCountFavourite(), $oTopic->getCutText(), $oTopic->getForbidComment(), $oTopic->getTextHash(), $oTopic->getTopicUrl(), $oTopic->getTopicIndexIgnore(), $oTopic->getId()); if ($bResult !== false) { $this->UpdateTopicContent($oTopic); return true; } return false; }
public function UpdateTopic(ModuleTopic_EntityTopic $oTopic) { $sql = "UPDATE " . Config::Get('db.table.topic') . " \n\t\t\tSET \n\t\t\t\tblog_id= ?d,\n\t\t\t\ttopic_title= ?,\t\t\t\t\n\t\t\t\ttopic_tags= ?,\n\t\t\t\ttopic_date_add = ?,\n\t\t\t\ttopic_date_edit = ?,\n\t\t\t\ttopic_user_ip= ?,\n\t\t\t\ttopic_publish= ?d ,\n\t\t\t\ttopic_publish_draft= ?d ,\n\t\t\t\ttopic_publish_index= ?d,\n\t\t\t\ttopic_rating= ?f,\n\t\t\t\ttopic_count_vote= ?d,\n\t\t\t\ttopic_count_read= ?d,\n\t\t\t\ttopic_count_comment= ?d, \n\t\t\t\ttopic_cut_text = ? ,\n\t\t\t\ttopic_forbid_comment = ? ,\n\t\t\t\ttopic_text_hash = ? \n\t\t\tWHERE\n\t\t\t\ttopic_id = ?d\n\t\t"; if ($this->oDb->query($sql, $oTopic->getBlogId(), $oTopic->getTitle(), $oTopic->getTags(), $oTopic->getDateAdd(), $oTopic->getDateEdit(), $oTopic->getUserIp(), $oTopic->getPublish(), $oTopic->getPublishDraft(), $oTopic->getPublishIndex(), $oTopic->getRating(), $oTopic->getCountVote(), $oTopic->getCountRead(), $oTopic->getCountComment(), $oTopic->getCutText(), $oTopic->getForbidComment(), $oTopic->getTextHash(), $oTopic->getId())) { $this->UpdateTopicContent($oTopic); return true; } return false; }
/** * 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; }