Пример #1
0
 private function checkActions()
 {
     if ($this->request["ENTITY_XML_ID"] !== $this->feed->getEntity()->getXmlId()) {
         return null;
     }
     $post = array_merge($this->request->getQueryList()->toArray(), $this->request->getPostList()->toArray());
     $action = strtolower($post["comment_review"] == "Y" ? strtolower($post['REVIEW_ACTION']) == "edit" ? "edit" : "add" : $post['REVIEW_ACTION']);
     if (!in_array($action, array("add", 'del', 'hide', 'show', 'edit'))) {
         return null;
     }
     $actionErrors = new ErrorCollection();
     $arPost = array();
     if (!check_bitrix_sessid()) {
         $actionErrors->addOne(new Error(Loc::getMessage("F_ERR_SESSION_TIME_IS_UP"), self::ERROR_ACTION));
     } else {
         if (!$this->checkCaptcha($actionErrors)) {
             $actionErrors->addOne(new Error(Loc::getMessage("POSTM_CAPTCHA"), self::ERROR_ACTION));
         } else {
             if ($post["AJAX_POST"] == "Y") {
                 CUtil::decodeURIComponent($post);
             }
             if ($action == "add" || $action == "edit") {
                 $arPost = array("POST_MESSAGE" => $post["REVIEW_TEXT"], "AUTHOR_NAME" => $this->getUser()->isAuthorized() ? $this->getUserName() : (empty($post["REVIEW_AUTHOR"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $post["REVIEW_AUTHOR"]), "AUTHOR_EMAIL" => $post["REVIEW_EMAIL"], "USE_SMILES" => $post["REVIEW_USE_SMILES"]);
                 foreach (GetModuleEvents('forum', 'OnCommentAdd', true) as $arEvent) {
                     if (ExecuteModuleEventEx($arEvent, array($this->feed->getEntity()->getType(), $this->feed->getEntity()->getId(), &$arPost)) === false) {
                         $actionErrors->addOne(new Error(isset($arPost['ERROR']) ? $arPost['ERROR'] : Loc::getMessage("F_ERR_DURING_ACTIONS") . print_r($arEvent, true), self::ERROR_ACTION));
                     }
                 }
             }
         }
     }
     if (!$actionErrors->hasErrors()) {
         if ($action == "add" || $action == "edit") {
             $message = $action == "add" ? $this->feed->add($arPost) : $this->feed->edit($this->request["MID"], $arPost);
             if ($message && $this->request["TOPIC_SUBSCRIBE"] == "Y") {
                 ForumSubscribeNewMessagesEx($this->arParams["FORUM_ID"], $message["TOPIC_ID"], "N", $strErrorMessage, $strOKMessage);
                 BXClearCache(true, "/bitrix/forum/user/" . $this->getUser()->getId() . "/subscribe/");
             }
         } elseif ($action == "show" || $action == "hide") {
             $message = $this->feed->moderate($this->request["MID"], $action == "show");
         } else {
             $message = $this->feed->delete($this->request["MID"]);
         }
         if ($this->feed->hasErrors()) {
             $actionErrors->add($this->feed->getErrors());
         } else {
             if ($this->request["NOREDIRECT"] != "Y" && !$this->isAjaxRequest()) {
                 $strURL = $this->request["back_page"] ?: $this->getApplication()->GetCurPageParam("", array("MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result", "sessid", "bxajaxid"));
                 $strURL = ForumAddPageParams($strURL, array("MID" => $message["ID"], "result" => $message["APPROVED"] == "Y" ? "reply" : "not_approved"));
                 LocalRedirect($strURL);
             } else {
                 $this->arResult['RESULT'] = $message["ID"];
                 if ($action == "add") {
                     $this->arResult['OK_MESSAGE'] = $message["APPROVED"] == "Y" ? GetMessage("COMM_COMMENT_OK") : GetMessage("COMM_COMMENT_OK_AND_NOT_APPROVED");
                 } else {
                     if ($action == "edit") {
                         $this->arResult['OK_MESSAGE'] = Loc::getMessage("COMM_COMMENT_UPDATED");
                     } else {
                         if ($action == "show") {
                             $this->arResult['OK_MESSAGE'] = Loc::getMessage("COMM_COMMENT_SHOWN");
                         } else {
                             if ($action == "hide") {
                                 $this->arResult['OK_MESSAGE'] = Loc::getMessage("COMM_COMMENT_HIDDEN");
                             } else {
                                 $this->arResult['OK_MESSAGE'] = Loc::getMessage("COMM_COMMENT_DELETED");
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($actionErrors->hasErrors()) {
         /** @var $error Error */
         $this->arResult["RESULT"] = false;
         $this->arResult["OK_MESSAGE"] = '';
         foreach ($actionErrors->toArray() as $error) {
             $this->arResult['ERROR_MESSAGE'] .= $error->getMessage();
         }
         return false;
     }
     return true;
 }
Пример #2
0
 /**
  * Creates new
  * @param Feed $feed
  * @param $id
  * @return Comment
  */
 public static function create(Feed $feed)
 {
     $forum = $feed->getForum();
     return new Comment($forum["ID"], $feed->getEntity()->getFullId());
 }
Пример #3
0
 /**
  * Creates new
  * @param Feed $feed
  * @param $id
  * @return Comment
  */
 public static function create(Feed $feed)
 {
     $forum = $feed->getForum();
     $comment = new Comment($forum["ID"], $feed->getEntity()->getFullId());
     $comment->getEntity()->setPermission($feed->getEntity()->getPermission());
     return $comment;
 }