32 private $message =
null;
34 private function prepareFields(array &$params,
ErrorCollection $errorCollectionParam)
37 "FORUM_ID" => $this->topic[
"FORUM_ID"],
38 "TOPIC_ID" => $this->topic[
"ID"],
39 "POST_MESSAGE" => trim($params[
"POST_MESSAGE"]),
40 "AUTHOR_ID" => $params[
"AUTHOR_ID"],
41 "AUTHOR_NAME" => trim($params[
"AUTHOR_NAME"]),
42 "AUTHOR_EMAIL" => trim($params[
"AUTHOR_EMAIL"]),
43 "USE_SMILES" => ($params[
"USE_SMILES"] ==
"Y" ?
"Y" :
"N"),
44 "APPROVED" => $this->topic[
"APPROVED"],
45 "XML_ID" => $this->
getEntity()->getXmlId(),
46 "AUX" => ($params[
"AUX"] ??
'N'),
47 "AUX_DATA" => ($params[
"AUX_DATA"] ??
''),
48 ) + array_intersect_key($params, array_flip([
49 "POST_DATE",
"SOURCE_ID",
50 "AUTHOR_IP",
"AUTHOR_REAL_IP",
55 if (isset($params[
"SERVICE_TYPE"]))
57 if (!in_array($params[
"SERVICE_TYPE"], \
Bitrix\
Forum\Comments\Service\Manager::getTypesList()))
63 $result[
"SERVICE_TYPE"] = $params[
"SERVICE_TYPE"];
64 if (!isset($params[
"SERVICE_DATA"]))
66 if (($result[
"SERVICE_TYPE"] === \
Bitrix\
Forum\Comments\Service\Manager::TYPE_TASK_INFO ||
67 $result[
"SERVICE_TYPE"] === \
Bitrix\
Forum\Comments\Service\Manager::TYPE_TASK_CREATED)
68 && JSon::decode($result[
"POST_MESSAGE"]) == $params[
"AUX_DATA"])
70 $params[
"SERVICE_DATA"] = $result[
"POST_MESSAGE"];
71 $result[
"POST_MESSAGE"] =
"";
75 $params[
"SERVICE_DATA"] = Json::encode($params[
"AUX_DATA"] ?? []);
78 $result[
"SERVICE_DATA"] = $params[
"SERVICE_DATA"];
79 if ($result[
"POST_MESSAGE"] ==
"" &&
80 ($handler = \
Bitrix\
Forum\Comments\Service\Manager::find(
81 [
"SERVICE_TYPE" => $result[
"SERVICE_TYPE"]]
84 $result[
"POST_MESSAGE"] = $handler->getText($result[
"SERVICE_DATA"]);
88 if ($result[
"POST_MESSAGE"] ==
'')
93 if ($result[
"AUTHOR_NAME"] ==
'' && $result[
"AUTHOR_ID"] > 0)
95 if ($result[
"AUTHOR_NAME"] ==
'')
98 if (is_array($params[
"FILES"]) && in_array($this->forum[
"ALLOW_UPLOAD"], array(
"Y",
"F",
"A")))
100 $result[
"FILES"] = array();
101 foreach ($params[
"FILES"] as $key => $val)
103 if (intval($val[
"FILE_ID"]) > 0 && $val[
"del"] !==
"Y")
107 $result[
"FILES"][$key] = $val;
110 "FORUM_ID" => $this->forum[
"ID"],
111 "TOPIC_ID" => $this->topic[
"ID"],
113 "USER_ID" => $result[
"AUTHOR_ID"],
114 "FORUM" => $this->forum
116 if (!\CForumFiles::checkFields($result[
"FILES"], $res,
"NOT_CHECK_DB"))
118 $text =
"File upload error.";
120 $text = $ex->getString();
124 if ($result[
"APPROVED"] !=
"N")
126 $result[
"APPROVED"] = ($this->forum[
"MODERATION"] !=
"Y" || $this->
getEntity()->canModerate($this->
getUser()->getId())) ?
"Y" :
"N";
134 global $USER_FIELD_MANAGER;
135 if (!empty($result[
"SERVICE_TYPE"]))
137 $fields = $USER_FIELD_MANAGER->getUserFields(
"FORUM_MESSAGE");
138 if (($ufData = array_intersect_key($params, $fields)) && !empty($ufData))
140 $USER_FIELD_MANAGER->editFormAddFields(
"FORUM_MESSAGE", $result, [
"FORM" => $ufData]);
145 $USER_FIELD_MANAGER->editFormAddFields(
"FORUM_MESSAGE", $result);
151 private function updateStatisticModule($messageId)
153 if (Loader::includeModule(
"statistic"))
155 $forumEvent1 = $this->forum[
"EVENT1"];
156 $forumEvent2 = $this->forum[
"EVENT2"];
157 $forumEvent3 = $this->forum[
"EVENT3"];
158 if (empty($forumEvent3))
160 $site = (array) \CForumNew::getSites($this->forum[
"ID"]);
161 $forumEvent3 = \CForumNew::preparePath2Message((array_key_exists(SITE_ID, $site) ? $site[SITE_ID] : reset($site)),
163 "FORUM_ID" => $this->forum[
"ID"],
164 "TOPIC_ID" => $this->topic[
"ID"],
165 "MESSAGE_ID" => $messageId
169 \CStatistics::set_Event($forumEvent1, $forumEvent2, $forumEvent3);
178 public function add(array $params)
180 $aux = (isset($params[
'AUX']) && $params[
'AUX'] ===
"Y");
181 $auxData = ($params[
'AUX_DATA'] ??
'');
184 "SOURCE_ID" => $params[
"SOURCE_ID"] ?? 0,
186 "POST_DATE" => array_key_exists(
"POST_DATE", $params) ? $params[
"POST_DATE"] : new \Bitrix\Main\Type\DateTime(),
187 "POST_MESSAGE" => trim($params[
"POST_MESSAGE"]),
188 "FILES" => $params[
"FILES"] ??
null,
190 "USE_SMILES" => $params[
"USE_SMILES"],
192 "AUTHOR_ID" => $this->
getUser()->getId(),
193 "AUTHOR_NAME" => trim($params[
"AUTHOR_NAME"] ??
''),
194 "AUTHOR_EMAIL" => trim($params[
"AUTHOR_EMAIL"] ??
''),
196 "AUTHOR_IP" => $params[
"AUTHOR_IP"] ??
"<no address>",
197 "AUTHOR_REAL_IP" => $params[
"AUTHOR_REAL_IP"] ??
"<no address>",
198 "GUEST_ID" => $params[
"GUEST_ID"] ??
null,
200 "AUX" => $params[
"AUX"] ??
null,
201 "AUX_DATA" => $auxData,
202 "SERVICE_TYPE" => ($params[
"SERVICE_TYPE"] ??
null),
203 "SERVICE_DATA" => ($params[
"SERVICE_DATA"] ??
null),
205 "UF_TASK_COMMENT_TYPE" => ($params[
"UF_TASK_COMMENT_TYPE"] ??
null),
206 "UF_FORUM_MES_URL_PRV" => ($params[
"UF_FORUM_MES_URL_PRV"] ??
null),
209 if ($this->prepareFields($params, $this->errorCollection))
212 $event =
new Event(
"forum",
"OnBeforeCommentAdd", [
218 if($event->getResults())
220 foreach($event->getResults() as $eventResult)
222 if($eventResult->getType() != EventResult::SUCCESS)
231 $topic = \Bitrix\Forum\Topic::getById($params[
"TOPIC_ID"]);
232 $result = \Bitrix\Forum\Message::create(
$topic, $params);
234 if ($result->isSuccess())
236 $mid = $result->getId();
240 $this->updateStatisticModule($mid);
241 \CForumMessage::sendMailMessage($mid, array(),
false,
"NEW_FORUM_MESSAGE");
251 $event =
new Event(
"forum",
"OnAfterCommentAdd", array(
255 "TOPIC_ID" => $this->topic[
"ID"],
256 "MESSAGE_ID" => $mid,
259 "AUX_DATA" => $auxData
267 $this->errorCollection->addFromResult($result);
276 public function edit(array $params)
278 $paramsRaw = $params;
279 if ($this->message ===
null)
281 $this->errorCollection->addOne(
new Error(
Loc::getMessage(
"FORUM_CM_ERR_COMMENT_IS_LOST1"), self::ERROR_MESSAGE_IS_NULL));
290 "TOPIC_ID" => $this->topic[
"ID"],
291 "MESSAGE_ID" => $this->message[
"ID"],
292 "PARAMS" => &$paramsRaw,
298 $event =
new Event(
"forum",
"OnBeforeCommentUpdate", $fields);
300 if($event->getResults())
302 foreach($event->getResults() as $eventResult)
304 if($eventResult->getType() != EventResult::SUCCESS)
316 $text = $str->getString();
317 $this->errorCollection->addOne(
new Error($text, self::ERROR_PARAMS_MESSAGE));
319 else if (($params = array(
320 "POST_MESSAGE" => trim($params[
"POST_MESSAGE"]),
321 "AUTHOR_ID" => $this->message[
"AUTHOR_ID"],
322 "AUTHOR_NAME" => (array_key_exists(
"AUTHOR_NAME", $params) ? trim($params[
"AUTHOR_NAME"]) : $this->message[
"AUTHOR_NAME"]),
323 "AUTHOR_EMAIL" => (array_key_exists(
"AUTHOR_EMAIL", $params) ? trim($params[
"AUTHOR_EMAIL"]) : $this->message[
"AUTHOR_EMAIL"]),
324 "USE_SMILES" => $params[
"USE_SMILES"],
325 "FILES" => $params[
"FILES"],
326 "AUX" => $params[
"AUX"],
327 "AUX_DATA" => $params[
"AUX_DATA"],
328 )) && $this->prepareFields($params, $this->errorCollection))
330 if (array_key_exists(
"POST_DATE", $paramsRaw))
332 $params[
"POST_DATE"] = $paramsRaw[
"POST_DATE"];
334 if (array_key_exists(
"EDIT_REASON", $paramsRaw))
337 "EDITOR_ID" => $this->
getUser()->getId(),
338 "EDITOR_NAME" => trim($paramsRaw[
"EDITOR_NAME"]),
339 "EDITOR_EMAIL" => trim($paramsRaw[
"EDITOR_EMAIL"]),
340 "EDIT_REASON" => trim($paramsRaw[
"EDIT_REASON"]),
343 if ($params[
"EDITOR_NAME"] ==
'')
346 $result = \Bitrix\Forum\Message::getById($this->message[
"ID"])->edit($params);
347 if ($result->isSuccess())
349 $mid = $this->message[
"ID"];
350 unset(
$GLOBALS[
"FORUM_CACHE"][
"MESSAGE"][$mid]);
351 unset(
$GLOBALS[
"FORUM_CACHE"][
"MESSAGE_FILTER"][$mid]);
353 if ($params[
"AUTHOR_ID"] != $this->
getUser()->getId() || Option::get(
"forum",
"LOGS",
"Q") <
"U")
356 foreach ($paramsRaw as $key => $val)
358 if ($val == $this->message[$key])
360 else if ($key ==
"FILES")
361 $resLog[
"FILES"] = GetMessage(
"F_ATTACH_IS_MODIFIED");
363 $resLog[$key] = array(
364 "before" => $this->message[$key],
370 $resLog[
"FORUM_ID"] = $this->forum[
"ID"];
371 $resLog[
"TOPIC_ID"] = $this->topic[
"ID"];
372 $resLog[
"TITLE"] = $this->topic[
"TITLE"];
373 \CForumEventLog::log(
"message",
"edit", $this->message[
"ID"], serialize($resLog));
376 $this->updateStatisticModule($mid);
377 \CForumMessage::sendMailMessage($mid, array(),
false,
"EDIT_FORUM_MESSAGE");
380 $fields[
"PARAMS"] = $params;
382 $event =
new Event(
"forum",
"OnAfterCommentUpdate", $fields);
387 $this->errorCollection->addFromResult($result);
393 public function delete()
395 if ($this->message ===
null)
397 $this->errorCollection->addOne(
new Error(
Loc::getMessage(
"FORUM_CM_ERR_COMMENT_IS_LOST2"), self::ERROR_MESSAGE_IS_NULL));
406 "TOPIC_ID" => $this->topic[
"ID"],
407 "MESSAGE_ID" => $this->message[
"ID"],
412 $event =
new Event(
"forum",
"OnBeforeCommentDelete", $fields);
414 if($event->getResults())
416 foreach($event->getResults() as $eventResult)
418 if($eventResult->getType() != EventResult::SUCCESS)
426 if ($run && \CForumMessage::delete($this->message[
"ID"]))
428 \CForumEventLog::log(
"message",
"delete", $this->message[
"ID"], serialize($this->message + array(
"TITLE" => $this->topic[
"TITLE"])));
430 $event =
new Event(
"forum",
"OnCommentDelete", $fields);
433 $event =
new Event(
"forum",
"OnAfterCommentUpdate", $fields);
441 $text = $ex->getString();
442 $this->errorCollection->addOne(
new Error($text, self::ERROR_PARAMS_MESSAGE));
450 if ($this->message ===
null)
452 $this->errorCollection->addOne(
new Error(
Loc::getMessage(
"FORUM_CM_ERR_COMMENT_IS_LOST3"), self::ERROR_MESSAGE_IS_NULL));
461 "TOPIC_ID" => $this->topic[
"ID"],
462 "MESSAGE_ID" => $this->message[
"ID"],
464 "ACTION" => $show ?
"SHOW" :
"HIDE",
465 "PARAMS" => array(
"APPROVED" => ($show ?
"Y" :
"N"))
468 $event =
new Event(
"forum",
"OnBeforeCommentModerate", $fields);
470 if($event->getResults())
472 foreach($event->getResults() as $eventResult)
474 if($eventResult->getType() != EventResult::SUCCESS)
482 if ($run && $this->message[
"APPROVED"] == $fields[2][
"PARAMS"][
"APPROVED"] || ($mid = \CForumMessage::update($this->message[
"ID"], $fields[2][
"PARAMS"])) > 0)
486 $event =
new Event(
"forum",
"onMessageModerate", array($this->message[
"ID"], ($show ?
"SHOW" :
"HIDE"), $this->message, $this->topic));
489 $event =
new Event(
"forum",
"OnCommentModerate", $fields);
492 $event =
new Event(
"forum",
"OnAfterCommentUpdate", $fields);
495 $res = serialize(array(
496 "ID" => $this->message[
"ID"],
497 "AUTHOR_NAME" => $this->message[
"AUTHOR_NAME"],
498 "POST_MESSAGE" => $this->message[
"POST_MESSAGE"],
499 "TITLE" => $this->topic[
"TITLE"],
500 "TOPIC_ID" => $this->topic[
"ID"],
501 "FORUM_ID" => $this->topic[
"FORUM_ID"]));
502 \CForumMessage::sendMailMessage($this->message[
"ID"], array(),
false, ($show ?
"NEW_FORUM_MESSAGE" :
"EDIT_FORUM_MESSAGE"));
503 \CForumEventLog::log(
"message", ($show ?
"approve" :
"unapprove"), $this->message[
"ID"], $res);
510 $text = $ex->getString();
511 $this->errorCollection->addOne(
new Error($text, self::ERROR_PARAMS_MESSAGE));
520 if ($this->message ===
null)
522 $this->errorCollection->addOne(
new Error(
Loc::getMessage(
"FORUM_CM_ERR_COMMENT_IS_LOST4"), self::ERROR_MESSAGE_IS_NULL));
527 ((int) $this->message[
"AUTHOR_ID"] > 0) &&
528 ((int) $this->message[
"AUTHOR_ID"] == (
int) $this->
getUser()->getId()) &&
554 $message = ($id > 0 ? \CForumMessage::getById($id) :
null);
555 if (!empty($message))
557 if ($message[
"TOPIC_ID"] != $this->topic[
"ID"])
562 $this->message = $message;
568 return $this->message;
581 $comment->getEntity()->setPermission($feed->
getUser()->getId(), $feed->
getEntity()->getPermission($feed->
getUser()->getId()));
582 $comment->setComment($id);
594 $comment->getEntity()->setPermission($feed->
getUser()->getId(), $feed->
getEntity()->getPermission($feed->
getUser()->getId()));
static loadMessages($file)
static getMessage($code, $replace=null, $language=null)
$GLOBALS['____1444769544']