/** * Обработка добавление комментария к топику * */ 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(getRequestStr('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(getRequestStr('comment_text')); if (!func_check($sText, 'text', 2, 100000)) { $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')); } }
/** * Обработка добавление комментария к топику * */ protected function SubmitComment() { $oTopic = $this->Topic_GetTopicById(getRequestStr('comment_target_id')); $sText = getRequestStr('comment_text'); $sParentId = (int) getRequest('reply'); $oCommentParent = null; if (!$sParentId) { /** * Корневой комментарий */ $sParentId = null; } else { /** * Родительский комментарий */ $oCommentParent = $this->Comment_GetCommentById($sParentId); } /** * Проверка на соответсвие комментария требованиям безопасности */ if (!$this->CheckComment($oTopic, $sText)) { return; } /** * Проверка на соответсвие комментария родительскому коментарию */ if (!$this->CheckParentComment($oTopic, $sText, $oCommentParent)) { return; } /** * Создаём коммент */ $oCommentNew = Engine::GetEntity('Comment'); $oCommentNew->setTargetId($oTopic->getId()); $oCommentNew->setTargetType('topic'); $oCommentNew->setTargetParentId($oTopic->getBlog()->getId()); $oCommentNew->setUserId($this->oUserCurrent->getId()); $oCommentNew->setText($this->Text_Parser($sText)); $oCommentNew->setTextSource($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); /** * Фиксируем ID у media файлов комментария */ $this->Media_ReplaceTargetTmpById('comment', $oCommentNew->getId()); /** * Список емайлов на которые не нужно отправлять уведомление */ $aExcludeMail = array($this->oUserCurrent->getMail()); /** * Отправляем уведомление тому на чей коммент ответили */ if ($oCommentParent and $oCommentParent->getUserId() != $oTopic->getUserId() and $oCommentNew->getUserId() != $oCommentParent->getUserId()) { $oUserAuthorComment = $oCommentParent->getUser(); $aExcludeMail[] = $oUserAuthorComment->getMail(); $this->Topic_SendNotifyCommentReplyToAuthorParentComment($oUserAuthorComment, $oTopic, $oCommentNew, $this->oUserCurrent); } /** * Отправка уведомления автору топика */ $this->Subscribe_Send('topic_new_comment', $oTopic->getId(), 'comment_new.tpl', $this->Lang_Get('emails.comment_new.subject'), 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('common.error.system.base'), $this->Lang_Get('common.error.error')); } }
/** * Обработка добавление комментария * * @return bool */ protected function SubmitComment() { /** * Проверям авторизован ли пользователь */ if (!$this->User_IsAuthorization()) { $this->Message_AddErrorSingle($this->Lang_Get('need_authorization'), $this->Lang_Get('error')); return; } /* @var $oImage PluginLsgallery_ModuleImage_EntityImage */ if (!($oImage = $this->PluginLsgallery_Image_GetImageById(getRequest('cmt_target_id')))) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } /* @var $oAlbum PluginLsgallery_ModuleAlbum_EntityAlbum */ if (!($oAlbum = $this->PluginLsgallery_Album_GetAlbumById($oImage->getAlbumId()))) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } if (!$this->ACL_AllowViewAlbumImages($this->oUserCurrent, $oAlbum)) { $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; } /** * Проверяем текст комментария */ $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() != $oImage->getId()) { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); return; } } else { /** * Корневой комментарий */ $sParentId = null; } /** * Проверка на дублирующий коммент */ if ($this->Comment_GetCommentUnique($oImage->getId(), 'image', $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($oImage->getId()); $oCommentNew->setTargetType('image'); $oCommentNew->setTargetParentId($oImage->getAlbumId()); $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(1); /** * Добавляем коммент */ $this->Hook_Run('image_comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oImage' => $oImage)); if ($this->Comment_AddComment($oCommentNew)) { $this->Hook_Run('image_comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oImage' => $oImage)); $this->Viewer_AssignAjax('sCommentId', $oCommentNew->getId()); $this->PluginLsgallery_Image_IncreaseImageCountComment($oCommentNew->getTargetId()); $this->oUserCurrent->setDateCommentLast(date("Y-m-d H:i:s")); $this->User_Update($this->oUserCurrent); } else { $this->Message_AddErrorSingle($this->Lang_Get('system_error'), $this->Lang_Get('error')); } }
/** * Обработка добавление комментария к топику * */ protected function SubmitComment() { // * Проверям авторизован ли пользователь if (!E::ModuleUser()->IsAuthorization()) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('need_authorization'), E::ModuleLang()->Get('error')); return; } // * Проверяем топик if (!($oTopic = E::ModuleTopic()->GetTopicById(F::GetRequestStr('cmt_target_id')))) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } // * Возможность постить коммент в топик в черновиках if (!$oTopic->getPublish()) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } // * Проверяем разрешено ли постить комменты switch (E::ModuleACL()->CanPostComment($this->oUserCurrent, $oTopic)) { case ModuleACL::CAN_TOPIC_COMMENT_ERROR_BAN: E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_comment_banned'), E::ModuleLang()->Get('attention')); return; case ModuleACL::CAN_TOPIC_COMMENT_FALSE: E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_comment_acl'), E::ModuleLang()->Get('error')); return; } // * Проверяем разрешено ли постить комменты по времени if (!E::ModuleACL()->CanPostCommentTime($this->oUserCurrent)) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_comment_limit'), E::ModuleLang()->Get('error')); return; } // * Проверяем запрет на добавления коммента автором топика if ($oTopic->getForbidComment()) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_comment_notallow'), E::ModuleLang()->Get('error')); return; } // * Проверяем текст комментария $sText = E::ModuleText()->Parser(F::GetRequestStr('comment_text')); if (!F::CheckVal($sText, 'text', Config::Val('module.comment.min_length', 2), Config::Val('module.comment.max_length', 10000))) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_comment_text_len', array('min' => 2, 'max' => Config::Val('module.comment.max_length', 10000))), E::ModuleLang()->Get('error')); return; } $iMin = Config::Val('module.comment.min_length', 2); $iMax = Config::Val('module.comment.max_length', 0); if (!F::CheckVal($sText, 'text', $iMin, $iMax)) { if ($iMax) { $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_text_len', array('min' => $iMin, 'max' => $iMax)), $this->Lang_Get('error')); } else { $this->Message_AddErrorSingle($this->Lang_Get('topic_comment_text_min', array('min' => $iMin)), $this->Lang_Get('error')); } return; } // * Проверям на какой коммент отвечаем if (!$this->isPost('reply')) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } $oCommentParent = null; $iParentId = intval(F::GetRequest('reply')); if ($iParentId != 0) { // * Проверяем существует ли комментарий на который отвечаем if (!($oCommentParent = E::ModuleComment()->GetCommentById($iParentId))) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } // * Проверяем из одного топика ли новый коммент и тот на который отвечаем if ($oCommentParent->getTargetId() != $oTopic->getId()) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); return; } } else { // * Корневой комментарий $iParentId = null; } // * Проверка на дублирующий коммент if (E::ModuleComment()->GetCommentUnique($oTopic->getId(), 'topic', $this->oUserCurrent->getId(), $iParentId, md5($sText))) { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('topic_comment_spam'), E::ModuleLang()->Get('error')); return; } // * Создаём коммент /** @var ModuleComment_EntityComment $oCommentNew */ $oCommentNew = E::GetEntity('Comment'); $oCommentNew->setTargetId($oTopic->getId()); $oCommentNew->setTargetType('topic'); $oCommentNew->setTargetParentId($oTopic->getBlog()->getId()); $oCommentNew->setUserId($this->oUserCurrent->getId()); $oCommentNew->setText($sText); $oCommentNew->setDate(F::Now()); $oCommentNew->setUserIp(F::GetUserIp()); $oCommentNew->setPid($iParentId); $oCommentNew->setTextHash(md5($sText)); $oCommentNew->setPublish($oTopic->getPublish()); // * Добавляем коммент E::ModuleHook()->Run('comment_add_before', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic)); if (E::ModuleComment()->AddComment($oCommentNew)) { E::ModuleHook()->Run('comment_add_after', array('oCommentNew' => $oCommentNew, 'oCommentParent' => $oCommentParent, 'oTopic' => $oTopic)); E::ModuleViewer()->AssignAjax('sCommentId', $oCommentNew->getId()); if ($oTopic->getPublish()) { // * Добавляем коммент в прямой эфир если топик не в черновиках /** @var ModuleComment_EntityCommentOnline $oCommentOnline */ $oCommentOnline = E::GetEntity('Comment_CommentOnline'); $oCommentOnline->setTargetId($oCommentNew->getTargetId()); $oCommentOnline->setTargetType($oCommentNew->getTargetType()); $oCommentOnline->setTargetParentId($oCommentNew->getTargetParentId()); $oCommentOnline->setCommentId($oCommentNew->getId()); E::ModuleComment()->AddCommentOnline($oCommentOnline); } // * Сохраняем дату последнего коммента для юзера $this->oUserCurrent->setDateCommentLast(F::Now()); E::ModuleUser()->Update($this->oUserCurrent); // * Список емайлов на которые не нужно отправлять уведомление $aExcludeMail = array($this->oUserCurrent->getMail()); // * Отправляем уведомление тому на чей коммент ответили if ($oCommentParent && $oCommentParent->getUserId() != $oTopic->getUserId() && $oCommentNew->getUserId() != $oCommentParent->getUserId()) { $oUserAuthorComment = $oCommentParent->getUser(); $aExcludeMail[] = $oUserAuthorComment->getMail(); E::ModuleNotify()->SendCommentReplyToAuthorParentComment($oUserAuthorComment, $oTopic, $oCommentNew, $this->oUserCurrent); } // issue 131 (https://github.com/altocms/altocms/issues/131) // Не работает настройка уведомлений о комментариях к своим топикам // Уберём автора топика из рассылки /** @var ModuleTopic_EntityTopic $oTopic */ $aExcludeMail[] = $oTopic->getUser()->getMail(); // Отправим ему сообщение через отдельный метод, который проверяет эту настройку /** @var ModuleComment_EntityComment $oCommentNew */ E::ModuleNotify()->SendCommentNewToAuthorTopic($oTopic->getUser(), $oTopic, $oCommentNew, $this->oUserCurrent); // * Отправка уведомления всем, кто подписан на топик кроме автора E::ModuleSubscribe()->Send('topic_new_comment', $oTopic->getId(), 'comment_new.tpl', E::ModuleLang()->Get('notify_subject_comment_new'), array('oTopic' => $oTopic, 'oComment' => $oCommentNew, 'oUserComment' => $this->oUserCurrent), $aExcludeMail); // * Подписываем автора коммента на обновления в трекере $oTrack = E::ModuleSubscribe()->AddTrackSimple('topic_new_comment', $oTopic->getId(), $this->oUserCurrent->getId()); if ($oTrack) { //если пользователь не отписался от обновлений топика if (!$oTrack->getStatus()) { $oTrack->setStatus(1); E::ModuleSubscribe()->UpdateTrack($oTrack); } } // * Добавляем событие в ленту E::ModuleStream()->Write($oCommentNew->getUserId(), 'add_comment', $oCommentNew->getId(), $oTopic->getPublish() && !$oTopic->getBlog()->IsPrivate()); } else { E::ModuleMessage()->AddErrorSingle(E::ModuleLang()->Get('system_error'), E::ModuleLang()->Get('error')); } }