コード例 #1
0
 /**
  * Обработка добавление комментария к топику
  *
  * @return bool
  */
 protected function SubmitComment()
 {
     /**
      * Проверям авторизован ли пользователь
      */
     if (!$this->User_IsAuthorization()) {
         $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем топик
      */
     if (!($oTopic = $this->Topic_GetTopicById(getRequest('cmt_target_id')))) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Возможность постить коммент в топик в черновиках
      */
     if (!$oTopic->getPublish() and $this->oUserCurrent->getId() != $oTopic->getUserId() and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты
      */
     if (!$this->ACL_CanPostComment($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_acl'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем разрешено ли постить комменты по времени
      */
     if (!$this->ACL_CanPostCommentTime($this->oUserCurrent) and !$this->oUserCurrent->isAdministrator()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем запрет на добавления коммента автором топика
      */
     if ($oTopic->getForbidComment()) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_notallow'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверяем текст комментария
      */
     $sText = $this->Text_Parser(getRequest('comment_text'));
     if (!func_check($sText, 'text', 2, 10000)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_add_text_error'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Проверям на какой коммент отвечаем
      */
     $sParentId = (int) getRequest('reply');
     if (!func_check($sParentId, 'id')) {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
         return;
     }
     $oCommentParent = null;
     if ($sParentId != 0) {
         /**
          * Проверяем существует ли комментарий на который отвечаем
          */
         if (!($oCommentParent = $this->Comment_GetCommentById($sParentId))) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
         /**
          * Проверяем из одного топика ли новый коммент и тот на который отвечаем
          */
         if ($oCommentParent->getTargetId() != $oTopic->getId()) {
             $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
             return;
         }
     } else {
         /**
          * Корневой комментарий
          */
         $sParentId = null;
     }
     /**
      * Проверка на дублирующий коммент
      */
     if ($this->Comment_GetCommentUnique($oTopic->getId(), 'topic', $this->oUserCurrent->getId(), $sParentId, md5($sText))) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_spam'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Создаём коммент
      */
     $oCommentNew = Engine::GetEntity('Comment');
     $oCommentNew->setTargetId($oTopic->getId());
     $oCommentNew->setTargetType('topic');
     $oCommentNew->setTargetParentId($oTopic->getBlog()->getId());
     $oCommentNew->setUserId($this->oUserCurrent->getId());
     $oCommentNew->setText($sText);
     $oCommentNew->setDate(date("Y-m-d H:i:s"));
     $oCommentNew->setUserIp(func_getIp());
     $oCommentNew->setPid($sParentId);
     $oCommentNew->setTextHash(md5($sText));
     $oCommentNew->setPublish($oTopic->getPublish());
     /**
      * Добавляем коммент
      */
     $this->Hook_Run('comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
     if ($this->Comment_AddComment($oCommentNew)) {
         $this->Hook_Run('comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic));
         $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId());
         if ($oTopic->getPublish()) {
             /**
              * Добавляем коммент в прямой эфир если топик не в черновиках
              */
             $oCommentOnline = Engine::GetEntity('Comment_CommentOnline');
             $oCommentOnline->setTargetId($oCommentNew->getTargetId());
             $oCommentOnline->setTargetType($oCommentNew->getTargetType());
             $oCommentOnline->setTargetParentId($oCommentNew->getTargetParentId());
             $oCommentOnline->setCommentId($oCommentNew->getId());
             $this->Comment_AddCommentOnline($oCommentOnline);
         }
         /**
          * Сохраняем дату последнего коммента для юзера
          */
         $this->oUserCurrent->setDateCommentLast(date("Y-m-d H:i:s"));
         $this->User_Update($this->oUserCurrent);
         /**
          * Список емайлов на которые не нужно отправлять уведомление
          */
         $aExcludeMail = array($this->oUserCurrent->getMail());
         /**
          * Отправляем уведомление тому на чей коммент ответили
          */
         if ($oCommentParent and $oCommentParent->getUserId() != $oTopic->getUserId() and $oCommentNew->getUserId() != $oCommentParent->getUserId()) {
             $oUserAuthorComment = $oCommentParent->getUser();
             $aExcludeMail[] = $oUserAuthorComment->getMail();
             $this->Notify_SendCommentReplyToAuthorParentComment($oUserAuthorComment, $oTopic, $oCommentNew, $this->oUserCurrent);
         }
         /**
          * Отправка уведомления автору топика
          */
         $this->Subscribe_Send('topic_new_comment', $oTopic->getId(), 'notify.comment_new.tpl', $this->Lang_Get('notify_subject_comment_new'), array('oTopic' => $oTopic, 'oComment' => $oCommentNew, 'oUserComment' => $this->oUserCurrent), $aExcludeMail);
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oCommentNew->getUserId(), 'add_comment', $oCommentNew->getId(), $oTopic->getPublish() && $oTopic->getBlog()->getType() != 'close');
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error'));
     }
 }
コード例 #2
0
 /**
  * Обработка добавлени топика
  *
  * @return unknown
  */
 protected function SubmitAdd()
 {
     /**
      * Проверяем отправлена ли форма с данными(хотяб одна кнопка)
      */
     if (!isPost('submit_topic_publish') and !isPost('submit_topic_save')) {
         return false;
     }
     /**
      * Проверка корректности полей формы
      */
     if (!$this->checkTopicFields()) {
         return false;
     }
     /**
      * Определяем в какой блог делаем запись
      */
     $iBlogId = getRequest('blog_id');
     if ($iBlogId == 0) {
         $oBlog = $this->Blog_GetPersonalBlogByUserId($this->oUserCurrent->getId());
     } 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 !$this->ACL_CanPostTopicTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_time_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Теперь можно смело добавлять топик к блогу
      */
     $oTopic = Engine::GetEntity('Topic');
     $oTopic->setBlogId($oBlog->getId());
     $oTopic->setUserId($this->oUserCurrent->getId());
     $oTopic->setType('question');
     $oTopic->setTitle(getRequest('topic_title'));
     $oTopic->setText(htmlspecialchars(getRequest('topic_text')));
     $oTopic->setTextShort(htmlspecialchars(getRequest('topic_text')));
     $oTopic->setTextSource(getRequest('topic_text'));
     $oTopic->setTags(getRequest('topic_tags'));
     $oTopic->setDateAdd(date("Y-m-d H:i:s"));
     $oTopic->setUserIp(func_getIp());
     $oTopic->setCutText(null);
     $oTopic->setTextHash(md5($oTopic->getType() . $oTopic->getText() . $oTopic->getTitle()));
     /**
      * Проверяем топик на уникальность
      */
     if ($oTopicEquivalent = $this->Topic_GetTopicUnique($this->oUserCurrent->getId(), $oTopic->getTextHash())) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_text_error_unique'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Варианты ответов
      */
     $oTopic->clearQuestionAnswer();
     foreach (getRequest('answer', array()) as $sAnswer) {
         $oTopic->addQuestionAnswer($sAnswer);
     }
     /**
      * Публикуем или сохраняем
      */
     if (isset($_REQUEST['submit_topic_publish'])) {
         $oTopic->setPublish(1);
         $oTopic->setPublishDraft(1);
     } else {
         $oTopic->setPublish(0);
         $oTopic->setPublishDraft(0);
     }
     /**
      * Принудительный вывод на главную
      */
     $oTopic->setPublishIndex(0);
     if ($this->ACL_IsAllowPublishIndex($this->oUserCurrent)) {
         if (getRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         }
     }
     /**
      * Запрет на комментарии к топику
      */
     $oTopic->setForbidComment(0);
     if (getRequest('topic_forbid_comment')) {
         $oTopic->setForbidComment(1);
     }
     /**
      * Запускаем выполнение хуков
      */
     $this->Hook_Run('topic_add_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     /**
      * Добавляем топик
      */
     if ($this->Topic_AddTopic($oTopic)) {
         $this->Hook_Run('topic_add_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
         /**
          * Получаем топик, чтоб подцепить связанные данные
          */
         $oTopic = $this->Topic_GetTopicById($oTopic->getId());
         /**
          * Обновляем количество топиков в блоге
          */
         $this->Blog_RecalculateCountTopicByBlogId($oTopic->getBlogId());
         /**
          * Добавляем автора топика в подписчики на новые комментарии к этому топику
          */
         $this->Subscribe_AddSubscribeSimple('topic_new_comment', $oTopic->getId(), $this->oUserCurrent->getMail());
         //Делаем рассылку спама всем, кто состоит в этом блоге
         if ($oTopic->getPublish() == 1 and $oBlog->getType() != 'personal') {
             $this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $this->oUserCurrent);
         }
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && $oBlog->getType() != 'close');
         Router::Location($oTopic->getUrl());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }
コード例 #3
0
 /**
  * Обработка добавлени топика
  *
  * @return unknown
  */
 protected function SubmitAdd()
 {
     /**
      * Проверяем отправлена ли форма с данными(хотяб одна кнопка)
      */
     if (!isPost('submit_topic_publish') and !isPost('submit_topic_save')) {
         return false;
     }
     /**
      * Проверка корректности полей формы
      */
     if (!$this->checkTopicFields()) {
         return false;
     }
     /**
      * Определяем в какой блог делаем запись
      */
     $iBlogId = getRequest('blog_id');
     if ($iBlogId == 0) {
         $oBlog = $this->Blog_GetPersonalBlogByUserId($this->oUserCurrent->getId());
     } 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 !$this->ACL_CanPostTopicTime($this->oUserCurrent)) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_time_limit'), $this->Lang_Get('error'));
         return;
     }
     /**
      * Теперь можно смело добавлять топик к блогу
      */
     $oTopic = Engine::GetEntity('Topic');
     $oTopic->setBlogId($oBlog->getId());
     $oTopic->setUserId($this->oUserCurrent->getId());
     $oTopic->setType('photoset');
     $oTopic->setTitle(getRequest('topic_title'));
     /**
      * Получаемый и устанавливаем разрезанный текст по тегу <cut>
      */
     list($sTextShort, $sTextNew, $sTextCut) = $this->Text_Cut(getRequest('topic_text'));
     $oTopic->setCutText($sTextCut);
     $oTopic->setText($this->Text_Parser($sTextNew));
     $oTopic->setTextShort($this->Text_Parser($sTextShort));
     $oTopic->setTextSource(getRequest('topic_text'));
     $oTopic->setTags(getRequest('topic_tags'));
     $oTopic->setDateAdd(date("Y-m-d H:i:s"));
     $oTopic->setUserIp(func_getIp());
     $oTopic->setTextHash(md5($oTopic->getType() . $oTopic->getText() . $oTopic->getTitle()));
     $sTargetTmp = $_COOKIE['ls_photoset_target_tmp'];
     $aPhotos = $this->Topic_getPhotosByTargetTmp($sTargetTmp);
     if (!($oPhotoMain = $this->Topic_getTopicPhotoById(getRequest('topic_main_photo')) and $oPhotoMain->getTargetTmp() == $sTargetTmp)) {
         $oPhotoMain = $aPhotos[0];
     }
     $oTopic->setPhotosetMainPhotoId($oPhotoMain->getId());
     $oTopic->setPhotosetCount(count($aPhotos));
     /**
      * Проверяем топик на уникальность
      */
     if ($oTopicEquivalent = $this->Topic_GetTopicUnique($this->oUserCurrent->getId(), $oTopic->getTextHash())) {
         $this->Message_AddErrorSingle($this->Lang_Get('topic_create_text_error_unique'), $this->Lang_Get('error'));
         return false;
     }
     /**
      * Публикуем или сохраняем
      */
     if (isset($_REQUEST['submit_topic_publish'])) {
         $oTopic->setPublish(1);
         $oTopic->setPublishDraft(1);
     } else {
         $oTopic->setPublish(0);
         $oTopic->setPublishDraft(0);
     }
     /**
      * Принудительный вывод на главную
      */
     $oTopic->setPublishIndex(0);
     if ($this->ACL_IsAllowPublishIndex($this->oUserCurrent)) {
         if (getRequest('topic_publish_index')) {
             $oTopic->setPublishIndex(1);
         }
     }
     /**
      * Запрет на комментарии к топику
      */
     $oTopic->setForbidComment(0);
     if (getRequest('topic_forbid_comment')) {
         $oTopic->setForbidComment(1);
     }
     /**
      * Запускаем выполнение хуков
      */
     $this->Hook_Run('topic_add_before', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
     /**
      * Добавляем топик
      */
     if ($this->Topic_AddTopic($oTopic)) {
         $this->Hook_Run('topic_add_after', array('oTopic' => $oTopic, 'oBlog' => $oBlog));
         /**
          * Получаем топик, чтоб подцепить связанные данные
          */
         $oTopic = $this->Topic_GetTopicById($oTopic->getId());
         /**
          * Обновляем количество топиков в блоге
          */
         $this->Blog_RecalculateCountTopicByBlogId($oTopic->getBlogId());
         /**
          * Добавляем автора топика в подписчики на новые комментарии к этому топику
          */
         $this->Subscribe_AddSubscribeSimple('topic_new_comment', $oTopic->getId(), $this->oUserCurrent->getMail());
         //Делаем рассылку спама всем, кто состоит в этом блоге
         if ($oTopic->getPublish() == 1 and $oBlog->getType() != 'personal') {
             $this->Topic_SendNotifyTopicNew($oBlog, $oTopic, $this->oUserCurrent);
         }
         /**
          * Привязываем фото к id топика
          * здесь нужно это делать одним запросом, а не перебором сущностей
          */
         if (count($aPhotos)) {
             foreach ($aPhotos as $oPhoto) {
                 $oPhoto->setTargetTmp(null);
                 $oPhoto->setTopicId($oTopic->getId());
                 $this->Topic_updateTopicPhoto($oPhoto);
             }
         }
         /**
          * Удаляем временную куку
          */
         setcookie('ls_photoset_target_tmp', null);
         /**
          * Добавляем событие в ленту
          */
         $this->Stream_write($oTopic->getUserId(), 'add_topic', $oTopic->getId(), $oTopic->getPublish() && $oBlog->getType() != 'close');
         Router::Location($oTopic->getUrl());
     } else {
         $this->Message_AddErrorSingle($this->Lang_Get('system_error'));
         return Router::Action('error');
     }
 }