Exemplo n.º 1
0
 protected function checkRequiredParams()
 {
     if (!CModule::IncludeModule("forum")) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_NO_MODULE'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (intval($this->arParams["FORUM_ID"]) <= 0) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_FID_EMPTY'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (empty($this->arParams["ENTITY_TYPE"])) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_ENT_EMPTY'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (strlen(trim($this->arParams["ENTITY_TYPE"])) !== 2) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_ENT_INVALID'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (empty($this->arParams["ENTITY_XML_ID"]) || intval($this->arParams['ENTITY_ID']) <= 0 && $this->arParams['ENTITY_ID'] !== 0) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_EID_EMPTY'), self::ERROR_REQUIRED_PARAMETER)));
     }
 }
Exemplo n.º 2
0
 protected function checkRequiredParams()
 {
     if (!CModule::IncludeModule("forum")) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_NO_MODULE'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (intval($this->arParams["FORUM_ID"]) <= 0) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_FID_EMPTY'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (empty($this->arParams["ENTITY_TYPE"])) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_ENT_EMPTY'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (strlen(trim($this->arParams["ENTITY_TYPE"])) !== 2) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_ENT_INVALID'), self::ERROR_REQUIRED_PARAMETER)));
     } elseif (empty($this->arParams["ENTITY_XML_ID"]) || intval($this->arParams['ENTITY_ID']) <= 0 && $this->arParams['ENTITY_ID'] !== 0) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('F_ERR_EID_EMPTY'), self::ERROR_REQUIRED_PARAMETER)));
     }
     $this->arParams["NAME_TEMPLATE"] = empty($this->arParams["NAME_TEMPLATE"]) ? \CSite::GetNameFormat() : $this->arParams["NAME_TEMPLATE"];
     $this->arParams["NAME_TEMPLATE"] = str_replace(array("#NOBR#", "#/NOBR#"), "", $this->arParams["NAME_TEMPLATE"]);
 }
Exemplo n.º 3
0
 private function prepareFields(array &$params, ErrorCollection $errorCollectionParam)
 {
     $result = array("FORUM_ID" => $this->topic["FORUM_ID"], "TOPIC_ID" => $this->topic["ID"], "POST_MESSAGE" => trim($params["POST_MESSAGE"]), "AUTHOR_ID" => $params["AUTHOR_ID"], "AUTHOR_NAME" => trim($params["AUTHOR_NAME"]), "AUTHOR_EMAIL" => trim($params["AUTHOR_EMAIL"]), "USE_SMILES" => $params["USE_SMILES"] == "Y" ? "Y" : "N", "APPROVED" => $this->topic["APPROVED"], "XML_ID" => $this->getEntity()->getXmlId());
     $errorCollection = new ErrorCollection();
     if (strlen($result["POST_MESSAGE"]) <= 0) {
         $errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_EMPTY_TEXT"), self::ERROR_PARAMS_MESSAGE));
     }
     if (strlen($result["AUTHOR_NAME"]) <= 0 && $result["AUTHOR_ID"] > 0) {
         $result["AUTHOR_NAME"] = self::getUserName($result["AUTHOR_ID"]);
     }
     if (strlen($result["AUTHOR_NAME"]) <= 0) {
         $errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_EMPTY_AUTHORS_NAME"), self::ERROR_PARAMS_MESSAGE));
     }
     if (is_array($params["FILES"]) && in_array($this->forum["ALLOW_UPLOAD"], array("Y", "F", "A"))) {
         $result["FILES"] = array();
         foreach ($params["FILES"] as $key => $val) {
             if (intval($val["FILE_ID"]) > 0) {
                 $val["del"] = $val["del"] == "Y" ? "Y" : "";
             }
             $result["FILES"][$key] = $val;
         }
         $res = array("FORUM_ID" => $this->forum["ID"], "TOPIC_ID" => $this->topic["ID"], "MESSAGE_ID" => 0, "USER_ID" => $result["AUTHOR_ID"], "FORUM" => $this->forum);
         if (!\CForumFiles::CheckFields($result["FILES"], $res, "NOT_CHECK_DB")) {
             $text = "File upload error.";
             if (($ex = $this->getApplication()->getException()) && $ex) {
                 $text = $ex->getString();
             }
             $errorCollection->addOne(new Error($text, self::ERROR_PARAMS_MESSAGE));
         }
     }
     if ($result["APPROVED"] != "N") {
         $result["APPROVED"] = $this->forum["MODERATION"] != "Y" || $this->getEntity()->canModerate() ? "Y" : "N";
     }
     if ($errorCollection->hasErrors()) {
         $errorCollectionParam->add($errorCollection->toArray());
         return false;
     } else {
         $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $result);
         $params = $result;
         return true;
     }
 }
Exemplo n.º 4
-1
 protected function createTopic()
 {
     $topic = array('TITLE' => $this->entity->getXmlId(), 'TAGS' => '', 'MESSAGE' => $this->entity->getXmlId(), 'AUTHOR_ID' => 0);
     /** @var $request \Bitrix\Main\HttpRequest */
     $request = \Bitrix\Main\Context::getCurrent()->getRequest();
     $post = array_merge($request->getQueryList()->toArray(), $request->getPostList()->toArray());
     $event = new Event("forum", "OnCommentTopicAdd", array($this->entity->getType(), $this->entity->getId(), $post, &$topic));
     $event->send();
     if (strlen($topic["AUTHOR_NAME"]) <= 0) {
         $topic["AUTHOR_NAME"] = $topic["AUTHOR_ID"] <= 0 ? Loc::getMessage("FORUM_USER_SYSTEM") : self::getUserName($topic["AUTHOR_ID"]);
     }
     $topic = array_merge($topic, array("FORUM_ID" => $this->forum["ID"], 'TITLE' => $topic["TITLE"], 'TAGS' => $topic["TAGS"], 'MESSAGE' => $topic["MESSAGE"], "USER_START_ID" => $topic["AUTHOR_ID"], "USER_START_NAME" => $topic["AUTHOR_NAME"], "LAST_POSTER_NAME" => $topic["AUTHOR_NAME"], "XML_ID" => $this->entity->getXmlId(), "APPROVED" => "Y"));
     if (($tid = \CForumTopic::add($topic)) > 0) {
         if ($this->forum["ALLOW_HTML"] != "Y") {
             $topic['MESSAGE'] = strip_tags($topic['MESSAGE']);
         }
         $fields = array("POST_MESSAGE" => $topic['MESSAGE'], "AUTHOR_ID" => $topic["AUTHOR_ID"], "AUTHOR_NAME" => $topic["AUTHOR_NAME"], "FORUM_ID" => $topic["FORUM_ID"], "TOPIC_ID" => $tid, "APPROVED" => $topic["APPROVED"], "NEW_TOPIC" => "Y", "PARAM1" => $this->entity->getType(), "PARAM2" => $this->entity->getId());
         if (\CForumMessage::Add($fields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")) > 0) {
             $event = new Event("forum", "OnAfterCommentTopicAdd", array($this->entity->getType(), $this->entity->getId(), $tid));
             $event->send();
             self::$topics[$this->entity->getXmlId()] = $topic + array("ID" => $tid);
             return self::$topics[$this->entity->getXmlId()];
         }
         \CForumTopic::Delete($tid);
     }
     $this->errorCollection->add(array(new Error(Loc::getMessage("FORUM_CM_TOPIC_IS_NOT_CREATED"), self::ERROR_PARAMS_TOPIC_ID)));
     return null;
 }