Пример #1
0
 /**
  * Возвращает похожие записи для объекта топика (по тегам)
  *
  * @param ModuleTopic_EntityTopic $oTopic
  *
  * @return array
  */
 public function getSimilarTopicsForTopic(ModuleTopic_EntityTopic $oTopic)
 {
     if ($oTopic == null) {
         return array();
     }
     //        Вытаскиваем переменные с файлов Config
     //        Максимальное количество топиков, которое выводится в блоке - iCountTopics
     //        По какому параметру сортировать записи - sOrderBy
     //        Как сортировать топики в выдаче
     $iCountTopics = Config::Get('plugin.similar.max_topics_count');
     $sOrderBy = Config::Get('plugin.similar.topics_order_by');
     $iOrderByDirection = Config::Get('plugin.similar.topics_order_by_direction');
     $sLang = null;
     if (in_array('l10n', $this->Plugin_GetActivePlugins())) {
         $sLang = $this->PluginL10n_L10n_GetLangForQuery();
     }
     // Генерируем ключ для кеша
     $key = "simular_topics_by_tags_for_" . $oTopic->getId() . ($sLang ? "_{$sLang}" : "") . "_{$iCountTopics}_{$sOrderBy}_{$iOrderByDirection}";
     if (!($aTopicIds = $this->Cache_Get($key))) {
         $aTopicIds = $this->oMapper->getTopicIdForTags($oTopic->getTagsArray(), $iCountTopics + 1, $sOrderBy, $iOrderByDirection, $sLang);
         unset($aTopicIds[array_search($oTopic->getId(), $aTopicIds)]);
         // Кешируем массив топиков на один час
         $this->Cache_Set($aTopicIds, $key, array('topic_update'), 60 * 10);
     }
     // Пытаемся вытянуть массив топиков из кеша
     // Массив id'шек топиков похожих на текущий
     // Достаем топики вместе с дополнительной информацией (автор, блог и т.д.)
     $aTopics = $this->Topic_GetTopicsAdditionalData($aTopicIds, array('user' => array(), 'blog' => array('owner' => array())));
     // Удаляем топики из недоступных для пользователя блогов
     $oUser = $this->User_GetUserCurrent();
     $aInaccessibleBlogIds = $this->Blog_GetInaccessibleBlogsByUser($oUser);
     foreach ($aTopics as $oTopic) {
         if (in_array($oTopic->getBlogId(), $aInaccessibleBlogIds)) {
             unset($aTopics[$oTopic->getTopicId()]);
         }
     }
     return $aTopics;
 }
Пример #2
0
 /**
  * Формирует и возвращает полный ЧПУ URL для топика
  *
  * @param ModuleTopic_EntityTopic $oTopic
  * @param bool $bAbsolute При false вернет относительный УРЛ
  * @return string
  */
 public function BuildUrlForTopic($oTopic, $bAbsolute = true)
 {
     $sUrlMask = Config::Get('module.topic.url');
     $iDateCreate = strtotime($oTopic->getDatePublish());
     $aReplace = array('%year%' => date("Y", $iDateCreate), '%month%' => date("m", $iDateCreate), '%day%' => date("d", $iDateCreate), '%hour%' => date("H", $iDateCreate), '%minute%' => date("i", $iDateCreate), '%second%' => date("s", $iDateCreate), '%login%' => '', '%blog%' => '', '%id%' => $oTopic->getId(), '%title%' => $oTopic->getSlug(), '%type%' => $oTopic->getType());
     /**
      * Получаем связанные данные только если в этом есть необходимость
      */
     if (strpos($sUrlMask, '%blog%') !== false) {
         if (!($oBlog = $oTopic->GetBlog())) {
             $oBlog = $this->Blog_GetBlogById($oTopic->getBlogId());
         }
         if ($oBlog) {
             if ($oBlog->getType() == 'personal') {
                 $sUrlMask = str_replace('%blog%', '%login%', $sUrlMask);
             } else {
                 $aReplace['%blog%'] = $oBlog->getUrl();
             }
         }
     }
     if (strpos($sUrlMask, '%login%') !== false) {
         if (!($oUser = $oTopic->GetUser())) {
             $oUser = $this->User_GetUserById($oTopic->getUserId());
         }
         if ($oUser) {
             $aReplace['%login%'] = $oUser->getLogin();
         }
     }
     $sUrl = strtr($sUrlMask, $aReplace);
     return $bAbsolute ? Router::GetPathRootWeb() . '/' . $sUrl : $sUrl;
 }
Пример #3
0
 /**
  * Обновляет топик
  *
  * @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;
 }
Пример #4
0
 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;
 }
Пример #5
0
 /**
  * Обработка редактирования топика
  *
  * @param ModuleTopic_EntityTopic $oTopic
  * @return mixed
  */
 protected function SubmitEdit($oTopic)
 {
     $oTopic->_setValidateScenario('link');
     /**
      * Сохраняем старое значение идентификатора блога
      */
     $sBlogIdOld = $oTopic->getBlogId();
     /**
      * Заполняем поля для валидации
      */
     $oTopic->setBlogId(getRequestStr('blog_id'));
     $oTopic->setTitle(strip_tags(getRequestStr('topic_title')));
     $oTopic->setLinkUrl(getRequestStr('topic_link_url'));
     $oTopic->setTextSource(getRequestStr('topic_text'));
     $oTopic->setTags(getRequestStr('topic_tags'));
     $oTopic->setUserIp(func_getIp());
     /**
      * Проверка корректности полей формы
      */
     if (!$this->checkTopicFields($oTopic)) {
         return false;
     }
     /**
      * Определяем в какой блог делаем запись
      */
     $iBlogId = $oTopic->getBlogId();
     if ($iBlogId == 0) {
         $oBlog = $this->Blog_GetPersonalBlogByUserId($oTopic->getUserId());
     } else {
         $oBlog = $this->Blog_GetBlogById($iBlogId);
     }
     /**
      * Если блог не определен выдаем предупреждение
      */
     if (!$oBlog) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_unknown'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем права на постинг в блог
      */
     if (!$this->ACL_IsAllowBlog($oBlog, $this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_blog_error_noallow'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Проверяем разрешено ли постить топик по времени
      */
     if (isPost('submit_topic_publish') and !$oTopic->getPublishDraft() and !$this->ACL_CanPostTopicTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_time_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Теперь можно смело редактировать топик
      */
     $oTopic->setBlogId($oBlog->getId());
     $oTopic->setText($this->Text_Parser($oTopic->getTextSource()));
     $oTopic->setTextShort($oTopic->getText());
     /**
      * Публикуем или сохраняем в черновиках
      */
     $bSendNotify = false;
     if (isset($_REQUEST['submit_topic_publish'])) {
         $oTopic->setPublish(1);
         if ($oTopic->getPublishDraft() == 0) {
             $oTopic->setPublishDraft(1);
             $oTopic->setDateAdd(date("Y-m-d H:i:s"));
             $bSendNotify = true;
         }
     } else {
         $oTopic->setPublish(0);
     }
     /**
      * Принудительный вывод на главную
      */
     if ($this->ACL_IsAllowPublishIndex($this->oUserCurrent)) {
         if (getRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         } else {
             $oTopic->setPublishIndex(0);
         }
     }
     /**
      * Запрет на комментарии к топику
      */
     $oTopic->setForbidComment(0);
     if (getRequest('topic_forbid_comment')) {
         $oTopic->setForbidComment(1);
     }
     $this->Hook_Run('topic_edit_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     /**
      * Сохраняем топик
      */
     if ($this->Topic_UpdateTopic($oTopic)) {
         $this->Hook_Run('topic_edit_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog, 'bSendNotify' => &$bSendNotify));
         /**
          * Обновляем данные в комментариях, если топик был перенесен в новый блог
          */
         if ($sBlogIdOld != $oTopic->getBlogId()) {
             $this->Comment_UpdateTargetParentByTargetId($oTopic->getBlogId(), 'topic', $oTopic->getId());
             $this->Comment_UpdateTargetParentByTargetIdOnline($oTopic->getBlogId(), 'topic', $oTopic->getId());
         }
         /**
          * Обновляем количество топиков в блоге
          */
         if ($sBlogIdOld != $oTopic->getBlogId()) {
             $this->Blog_RecalculateCountTopicByBlogId($sBlogIdOld);
         }
         $this->Blog_RecalculateCountTopicByBlogId($oTopic->getBlogId());
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && $oBlog->getType() != 'close');
         /**
          * Рассылаем о новом топике подписчикам блога
          */
         if ($bSendNotify) {
             $this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $this->oUserCurrent);
         }
         if (!$oTopic->getPublish() and !$this->oUserCurrent->isAdministrator() and $this->oUserCurrent->getId() != $oTopic->getUserId()) {
             Router::Location($oBlog->getUrlFull());
         }
         Router::Location($oTopic->getUrl());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }
Пример #6
0
 /**
  * Обновляет топик
  *
  * @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;
 }
Пример #7
0
 /**
  * Обработка редактирования топика
  *
  * @param ModuleTopic_EntityTopic $oTopic
  *
  * @return mixed
  */
 protected function SubmitEdit($oTopic)
 {
     $oTopic->_setValidateScenario('topic');
     // * Сохраняем старое значение идентификатора блога
     $iBlogIdOld = $oTopic->getBlogId();
     // * Заполняем поля для валидации
     $iBlogId = F::GetRequestStr('blog_id');
     // if blog_id is empty then save blog not changed
     if (is_numeric($iBlogId)) {
         $oTopic->setBlogId($iBlogId);
     }
     // issue 151 (https://github.com/altocms/altocms/issues/151)
     // Некорректная обработка названия блога
     // $oTopic->setTitle(strip_tags(F::GetRequestStr('topic_title')));
     $oTopic->setTitle(E::ModuleTools()->RemoveAllTags(F::GetRequestStr('topic_title')));
     $oTopic->setTextSource(F::GetRequestStr('topic_text'));
     if ($this->oContentType->isAllow('link')) {
         $oTopic->setSourceLink(F::GetRequestStr('topic_field_link'));
     }
     $oTopic->setTags(F::GetRequestStr('topic_field_tags'));
     $oTopic->setUserIp(F::GetUserIp());
     if ($this->oUserCurrent && ($this->oUserCurrent->isAdministrator() || $this->oUserCurrent->isModerator())) {
         if (F::GetRequestStr('topic_url') && $oTopic->getTopicUrl() != F::GetRequestStr('topic_url')) {
             $sTopicUrl = E::ModuleTopic()->CorrectTopicUrl(F::TranslitUrl(F::GetRequestStr('topic_url')));
             $oTopic->setTopicUrl($sTopicUrl);
         }
     }
     // * Проверка корректности полей формы
     if (!$this->checkTopicFields($oTopic)) {
         return false;
     }
     // * Определяем в какой блог делаем запись
     $nBlogId = $oTopic->getBlogId();
     if ($nBlogId == 0) {
         $oBlog = E::ModuleBlog()->GetPersonalBlogByUserId($oTopic->getUserId());
     } else {
         $oBlog = E::ModuleBlog()->GetBlogById($nBlogId);
     }
     // * Если блог не определен выдаем предупреждение
     if (!$oBlog) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_create_blog_error_unknown'), E::ModuleLang()->Get('error'));
         return false;
     }
     // * Проверяем права на постинг в блог
     if (!E::ModuleACL()->IsAllowBlog($oBlog, $this->oUserCurrent)) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_create_blog_error_noallow'), E::ModuleLang()->Get('error'));
         return false;
     }
     // * Проверяем разрешено ли постить топик по времени
     if (isPost('submit_topic_publish') && !$oTopic->getPublishDraft() && !E::ModuleACL()->CanPostTopicTime($this->oUserCurrent)) {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_time_limit'), E::ModuleLang()->Get('error'));
         return;
     }
     $oTopic->setBlogId($oBlog->getId());
     // * Получаемый и устанавливаем разрезанный текст по тегу <cut>
     list($sTextShort, $sTextNew, $sTextCut) = E::ModuleText()->Cut($oTopic->getTextSource());
     $oTopic->setCutText($sTextCut);
     $oTopic->setText(E::ModuleText()->Parser($sTextNew));
     // Получаем ссылки, полученные при парсинге текста
     $oTopic->setTextLinks(E::ModuleText()->GetLinks());
     $oTopic->setTextShort(E::ModuleText()->Parser($sTextShort));
     // * Изменяем вопрос/ответы, только если еще никто не голосовал
     if ($this->oContentType->isAllow('poll') && F::GetRequestStr('topic_field_question') && F::GetRequest('topic_field_answers', array()) && $oTopic->getQuestionCountVote() == 0) {
         $oTopic->setQuestionTitle(strip_tags(F::GetRequestStr('topic_field_question')));
         $oTopic->clearQuestionAnswer();
         $aAnswers = F::GetRequest('topic_field_answers', array());
         foreach ($aAnswers as $sAnswer) {
             $sAnswer = trim((string) $sAnswer);
             if ($sAnswer) {
                 $oTopic->addQuestionAnswer($sAnswer);
             }
         }
     }
     $aPhotoSetData = E::ModuleMresource()->GetPhotosetData('photoset', $oTopic->getId());
     $oTopic->setPhotosetCount($aPhotoSetData['count']);
     $oTopic->setPhotosetMainPhotoId($aPhotoSetData['cover']);
     // * Publish or save as a draft
     $bSendNotify = false;
     if (isset($_REQUEST['submit_topic_publish'])) {
         // If the topic has not been published then sets date of show (publication date)
         if (!$oTopic->getPublish() && !$oTopic->getDateShow()) {
             $oTopic->setDateShow(F::Now());
         }
         $oTopic->setPublish(1);
         if ($oTopic->getPublishDraft() == 0) {
             $oTopic->setPublishDraft(1);
             $oTopic->setDateAdd(F::Now());
             $bSendNotify = true;
         }
     } else {
         $oTopic->setPublish(0);
     }
     // * Принудительный вывод на главную
     if (E::ModuleACL()->IsAllowPublishIndex($this->oUserCurrent)) {
         if (F::GetRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         } else {
             $oTopic->setPublishIndex(0);
         }
     }
     // * Запрет на комментарии к топику
     $oTopic->setForbidComment(F::GetRequest('topic_forbid_comment', 0));
     // Если запрет на индексацию не устанавливался вручную, то задаем, как у блога
     $oBlogType = $oBlog->GetBlogType();
     if ($oBlogType && !$oTopic->getIndexIgnoreLock()) {
         $oTopic->setTopicIndexIgnore($oBlogType->GetIndexIgnore());
     } else {
         $oTopic->setTopicIndexIgnore(false);
     }
     $oTopic->setShowPhotoset(F::GetRequest('topic_show_photoset', 0));
     E::ModuleHook()->Run('topic_edit_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     // * Сохраняем топик
     if ($this->_updateTopic($oTopic)) {
         E::ModuleHook()->Run('topic_edit_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog, 'bSendNotify' => &$bSendNotify));
         // * Обновляем данные в комментариях, если топик был перенесен в новый блог
         if ($iBlogIdOld != $oTopic->getBlogId()) {
             E::ModuleComment()->UpdateTargetParentByTargetId($oTopic->getBlogId(), 'topic', $oTopic->getId());
             E::ModuleComment()->UpdateTargetParentByTargetIdOnline($oTopic->getBlogId(), 'topic', $oTopic->getId());
         }
         // * Обновляем количество топиков в блоге
         if ($iBlogIdOld != $oTopic->getBlogId()) {
             E::ModuleBlog()->RecalculateCountTopicByBlogId($iBlogIdOld);
         }
         E::ModuleBlog()->RecalculateCountTopicByBlogId($oTopic->getBlogId());
         // * Добавляем событие в ленту
         E::ModuleStream()->Write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && (!$oBlogType || !$oBlog->getBlogType()->IsPrivate()));
         // * Рассылаем о новом топике подписчикам блога
         if ($bSendNotify) {
             E::ModuleTopic()->SendNotifyTopicNew($oBlog, $oTopic, $oTopic->getUser());
         }
         if (!$oTopic->getPublish() && !$this->oUserCurrent->isAdministrator() && !$this->oUserCurrent->isModerator() && $this->oUserCurrent->getId() != $oTopic->getUserId()) {
             R::Location($oBlog->getUrlFull());
         }
         R::Location($oTopic->getUrl());
     } else {
         E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'));
         F::SysWarning('System Error');
         return R::Action('error');
     }
 }
Пример #8
0
 /**
  * Проверяет можно или нет пользователю удалять данный топик
  *
  * @param ModuleTopic_EntityTopic $oTopic	Топик
  * @param ModuleUser_EntityUser $oUser	Пользователь
  * @return bool
  */
 public function IsAllowDeleteTopic($oTopic, $oUser)
 {
     /**
      * Разрешаем если это админ сайта или автор топика
      */
     if ($oTopic->getUserId() == $oUser->getId() or $oUser->isAdministrator()) {
         return true;
     }
     /**
      * Если автор(смотритель) блога
      */
     if ($oTopic->getBlog()->getOwnerId() == $oUser->getId()) {
         return true;
     }
     /**
      * Если модер или админ блога
      */
     if ($this->User_GetUserCurrent() and $this->User_GetUserCurrent()->getId() == $oUser->getId()) {
         /**
          * Для авторизованного пользователя данный код будет работать быстрее
          */
         if ($oTopic->getBlog()->getUserIsAdministrator() or $oTopic->getBlog()->getUserIsModerator()) {
             return true;
         }
     } else {
         $oBlogUser = $this->Blog_GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(), $oUser->getId());
         if ($oBlogUser and ($oBlogUser->getIsModerator() or $oBlogUser->getIsAdministrator())) {
             return true;
         }
     }
     return false;
 }
Пример #9
0
 /**
  * Проверяет можно или нет пользователю удалять данный топик
  *
  * @param ModuleTopic_EntityTopic $oTopic Топик
  * @param ModuleUser_EntityUser $oUser Пользователь
  * @return bool
  */
 public function IsAllowDeleteTopic($oTopic, $oUser)
 {
     $that = $this;
     // fix for PHP < 5.4
     return $this->Rbac_IsAllowUser($oUser, 'remove_topic', array('callback' => function ($oUser, $aParams) use($that, $oTopic) {
         if (!$oUser) {
             return false;
         }
         /**
          * Разрешаем если это админ сайта или автор топика
          */
         if ($oTopic->getUserId() == $oUser->getId() or $oUser->isAdministrator()) {
             return true;
         }
         /**
          * Если автор(смотритель) блога
          */
         if ($oTopic->getBlog()->getOwnerId() == $oUser->getId()) {
             return true;
         }
         /**
          * Если модер или админ блога
          */
         if ($that->User_GetUserCurrent() and $that->User_GetUserCurrent()->getId() == $oUser->getId()) {
             /**
              * Для авторизованного пользователя данный код будет работать быстрее
              */
             if ($oTopic->getBlog()->getUserIsAdministrator() or $oTopic->getBlog()->getUserIsModerator()) {
                 return true;
             }
         } else {
             $oBlogUser = $that->Blog_GetBlogUserByBlogIdAndUserId($oTopic->getBlogId(), $oUser->getId());
             if ($oBlogUser and ($oBlogUser->getIsModerator() or $oBlogUser->getIsAdministrator())) {
                 return true;
             }
         }
         return false;
     }));
 }