public function moderate($show) { if ($this->message === null) { $this->errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_COMMENT_IS_LOST3"), self::ERROR_MESSAGE_IS_NULL)); } else { $fields = array("APPROVED" => $show ? "Y" : "N"); if ($this->message["ID"] == $fields["APPROVED"] || ($mid = \CForumMessage::Update($this->message["ID"], $fields)) > 0) { $this->setComment($this->message["ID"]); /***************** Events ******************************************/ /***************** Event onMessageModerate *************************/ $event = new Event("forum", "onMessageModerate", array($this->message["ID"], $show ? "SHOW" : "HIDE", $this->message, $this->topic)); $event->send(); /***************** Events OnAfterCommentUpdate *********************/ $fields = array($this->entity->getType(), $this->entity->getId(), array("TOPIC_ID" => $this->topic["ID"], "MESSAGE_ID" => $this->message["ID"], "MESSAGE" => $this->getComment(), "ACTION" => $show ? "SHOW" : "HIDE", "PARAMS" => $fields)); $event = new Event("forum", "OnAfterCommentUpdate", $fields); $event->send(); /***************** Events OnCommentModerate ************************/ $event = new Event("forum", "OnCommentModerate", $fields); $event->send(); /***************** /Events *****************************************/ $res = serialize(array("ID" => $this->message["ID"], "AUTHOR_NAME" => $this->message["AUTHOR_NAME"], "POST_MESSAGE" => $this->message["POST_MESSAGE"], "TITLE" => $this->topic["TITLE"], "TOPIC_ID" => $this->topic["ID"], "FORUM_ID" => $this->topic["FORUM_ID"])); \CForumMessage::SendMailMessage($this->message["ID"], array(), false, $show ? "NEW_FORUM_MESSAGE" : "EDIT_FORUM_MESSAGE"); \CForumEventLog::Log("message", $show ? "approve" : "unapprove", $this->message["ID"], $res); return $this->getComment(); } else { $text = Loc::getMessage("FORUM_CM_ERR_MODERATE"); if (($ex = $this->getApplication()->getException()) && $ex) { $text = $ex->getString(); } $this->errorCollection->addOne(new Error($text, self::ERROR_PARAMS_MESSAGE)); } } return false; }
function ForumMoveMessage($FID, $TID, $Message, $NewTID = 0, $arFields, &$strErrorMessage, &$strOKMessage, $iFileSize = false) { global $USER, $DB; $arError = array(); $arOK = array(); $NewFID = 0; $arForum = array(); $arTopic = array(); $arNewForum = array(); $arNewTopic = array(); $arCurrUser = array(); $SendSubscribe = false; //************************* Input params ************************************************************************** $TID = IntVal($TID); $FID = IntVal($FID); $NewTID = IntVal($NewTID); $Message = ForumDataToArray($Message); if (empty($Message)) { $arError[] = GetMessage("FMM_NO_MESSAGE"); } if ($TID <= 0) { $arError[] = GetMessage("FMM_NO_TOPIC_SOURCE0"); } else { $arTopic = CForumTopic::GetByID($TID); if ($arTopic) { $FID = IntVal($arTopic["FORUM_ID"]); $arForum = CForumNew::GetByID($FID); } else { $arError[] = GetMessage("FMM_NO_TOPIC_SOURCE1"); } } if ($NewTID <= 0 && strLen(trim($arFields["TITLE"])) <= 0) { $arError[] = GetMessage("FMM_NO_TOPIC_RECIPIENT0"); } elseif ($NewTID > 0) { if ($NewTID == $TID) { $arError[] = GetMessage("FMM_NO_TOPIC_EQUAL"); } $arNewTopic = CForumTopic::GetByID($NewTID); if (!$arNewTopic) { $arError[] = GetMessage("FMM_NO_TOPIC_RECIPIENT1"); } elseif ($arNewTopic["STATE"] == "L") { $arError[] = GetMessage("FMM_TOPIC_IS_LINK"); } else { $NewFID = $arNewTopic["FORUM_ID"]; $arNewForum = CForumNew::GetByID($NewFID); } } //*************************/Input params ************************************************************************** //*************************!Proverka prav pol'zovatelya na forume-istochnike i forume-poluchatele********************* // Tak kak realizovan mehanizm peremeweniya tem s forumov, gde tekuwij pol'zovatel' yavlyaetsya moderatorom na forumy, // gde on moderatorov ne yavlyaetsya, to v dannom sluchae budet ispol'zovan tot zhe samyj shablon dejstvij. Isklyucheniem // yavlyaetsya to, chto esli pol'zovatel' na forume-poluchatele ne obladaet pravami moderirovaniya, tema budet neaktivna. //*************************!Proverka prav pol'zovatelya************************************************************* $arCurrUser["Perms"]["FID"] = ForumCurrUserPermissions($FID); $arCurrUser["Perms"]["NewFID"] = ForumCurrUserPermissions($NewFID); if ($arCurrUser["Perms"]["FID"] < "Q") { $arError[] = GetMessage("FMM_NO_MODERATE"); } //************************* Actions ******************************************************************************* $DB->StartTransaction(); if (count($arError) <= 0) { // Create topic if ($NewTID <= 0) { $arFields["APPROVED"] = $arNewForum["MODERATION"] == "Y" ? "N" : "Y"; if ($arCurrUser["Perms"]["NewFID"] >= "Q") { $arFields["APPROVED"] = "Y"; } $arRes = array("NAME" => GetMessage("FR_GUEST")); $ShowName = GetMessage("FR_GUEST"); $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("@ID" => implode(",", $Message), "TOPIC_ID" => $TID)); if ($db_res && ($res = $db_res->Fetch())) { $arRes["NAME"] = $res["AUTHOR_NAME"]; $arRes["ID"] = $res["AUTHOR_ID"]; } $arFieldsTopic = array("TITLE" => $arFields["TITLE"], "TITLE_SEO" => $arFields["TITLE_SEO"], "DESCRIPTION" => $arFields["DESCRIPTION"], "ICON" => $arFields["ICON"], "TAGS" => $arFields["TAGS"], "FORUM_ID" => $FID, "USER_START_ID" => $arRes["ID"], "USER_START_NAME" => $arRes["NAME"], "LAST_POSTER_NAME" => $arRes["NAME"], "LAST_POSTER_ID" => $arRes["ID"], "APPROVED" => $arFields["APPROVED"]); $NewTID = CForumTopic::Add($arFieldsTopic); if (IntVal($NewTID) <= 0) { $arError[] = GetMessage("FMM_NO_TOPIC_NOT_CREATED"); } else { $arNewTopic = CForumTopic::GetByID($NewTID); if ($arNewTopic) { $NewFID = $FID; $arNewForum = $arForum; $SendSubscribe = true; } else { $arError[] = GetMessage("FMM_NO_TOPIC_NOT_CREATED"); } } } } if (count($arError) <= 0) { // Move message $db_res = CForumMessage::GetList(array(), array("@ID" => implode(",", $Message), "TOPIC_ID" => $TID)); if ($db_res && ($res = $db_res->Fetch())) { do { // echo "NewFID: ".$NewFID." -- FID:".$FID."<br/>"; $arMessage = array(); if ($NewFID != $FID) { $arMessage["APPROVED"] = $arNewForum["MODERATION"] == "Y" ? "N" : "Y"; if ($arCurrUser["Perms"]["NewFID"] >= "Q") { $arMessage["APPROVED"] = "Y"; } $arMessage["FORUM_ID"] = $NewFID; $arMessage["POST_MESSAGE_HTML"] = ""; } if ($NewTID != $TID) { $arMessage["NEW_TOPIC"] = "N"; $arMessage["TOPIC_ID"] = $NewTID; } if (count($arMessage) > 0) { $MID = CForumMessage::Update($res["ID"], $arMessage, true); $res_log = $SendSubscribe == true ? GetMessage("F_MESSAGE_WAS_MOVED_TO_NEW") : GetMessage("F_MESSAGE_WAS_MOVED"); $res_log = str_replace(array("#ID#", "#TOPIC_TITLE#", "#TOPIC_ID#", "#NEW_TOPIC_TITLE#", "#NEW_TOPIC_ID#"), array($MID, $arTopic["TITLE"], $arTopic["ID"], $arNewTopic['TITLE'], $arNewTopic['ID']), $res_log); $res["TITLE"] = $arNewTopic['TITLE']; $res["TOPIC_ID"] = $arNewTopic['ID']; $res["beforeTITLE"] = $arTopic["TITLE"]; $res["DESCRIPTION"] = $res_log; CForumEventLog::Log("message", "move", $MID, serialize($res)); $db_res2 = CForumFiles::GetList(array(), array("FILE_MESSAGE_ID" => $res["ID"])); if ($db_res2 && ($res2 = $db_res2->Fetch())) { $arFiles = array(); do { $arFiles[] = $res2["FILE_ID"]; } while ($res2 = $db_res2->Fetch()); CForumFiles::UpdateByID($arFiles, $arMessage); } if (IntVal($MID) <= 0) { $arError[] = str_replace("##", $res["ID"], GetMessage("FMM_NO_MESSAGE_MOVE")); break; } } } while ($res = $db_res->Fetch()); } } if (count($arError) <= 0) { $db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $TID), false, 1); if (!($db_res && ($res = $db_res->Fetch()))) { CForumTopic::Delete($TID); } else { CForumTopic::SetStat($TID); } $db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $NewTID), false, 1); if (!($db_res && ($res = $db_res->Fetch()))) { CForumTopic::Delete($NewTID); } else { CForumTopic::SetStat($NewTID); } CForumNew::SetStat($FID); if ($NewFID != $FID) { CForumNew::SetStat($NewFID); } } if (count($arError) <= 0) { $DB->Commit(); } else { $DB->Rollback(); } if (count($arError) > 0) { $strErrorMessage .= implode(". \n", $arError) . ". \n"; } else { $strOKMessage .= GetMessage("FMM_YES_MESSAGE_MOVE"); if ($SendSubscribe) { foreach ($Message as $MID) { CForumMessage::SendMailMessage($MID, array(), false, "NEW_FORUM_MESSAGE"); } } return true; } return false; }
function Update($ID, $arFields, $skip_counts = False) { global $DB; $ID = intVal($ID); $arFields1 = array(); $arFieldsForFilter = array(); $bNeedFilter = false; if ($ID <= 0 || !CForumTopic::CheckFields("UPDATE", $arFields)) { return false; } /***************** Event onBeforeTopicUpdate **************************/ $events = GetModuleEvents("forum", "onBeforeTopicUpdate"); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$ID, &$arFields)) === false) { return false; } } /***************** /Event ******************************************/ if (empty($arFields)) { return false; } foreach ($arFields as $key => $value) { if (substr($key, 0, 1) == "=") { $arFields1[substr($key, 1)] = $value; unset($arFields[$key]); } } if (!$skip_counts && is_set($arFields, "FORUM_ID") || COption::GetOptionString("forum", "FILTER", "Y") == "Y" || (is_set($arFields, "TITLE") || is_set($arFields, "TAGS")) && IsModuleInstalled("search")) { $arTopic_prev = CForumTopic::GetByID($ID, array("NoFilter" => true)); } // Fields "HTML". if (COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $arFieldsForFilter = array("TITLE" => is_set($arFields, "TITLE") ? $arFields["TITLE"] : $arTopic_prev["TITLE"], "TAGS" => is_set($arFields, "TAGS") ? $arFields["TAGS"] : $arTopic_prev["TAGS"], "DESCRIPTION" => is_set($arFields, "DESCRIPTION") ? $arFields["DESCRIPTION"] : $arTopic_prev["DESCRIPTION"], "LAST_POSTER_NAME" => is_set($arFields, "LAST_POSTER_NAME") ? $arFields["LAST_POSTER_NAME"] : $arTopic_prev["LAST_POSTER_NAME"], "ABS_LAST_POSTER_NAME" => is_set($arFields, "ABS_LAST_POSTER_NAME") ? $arFields["ABS_LAST_POSTER_NAME"] : $arTopic_prev["ABS_LAST_POSTER_NAME"], "USER_START_NAME" => is_set($arFields, "USER_START_NAME") ? $arFields["USER_START_NAME"] : $arTopic_prev["USER_START_NAME"]); $bNeedFilter = false; foreach ($arFieldsForFilter as $key => $val) { if (is_set($arFields, $key)) { $bNeedFilter = true; break; } } if ($bNeedFilter) { foreach ($arFieldsForFilter as $key => $val) { $res = CFilterUnquotableWords::Filter($val); if (empty($res) && !empty($val)) { $res = "*"; } $arFieldsForFilter[$key] = $res; } $arFields["HTML"] = serialize($arFieldsForFilter); } } $strUpdate = $DB->PrepareUpdate("b_forum_topic", $arFields); foreach ($arFields1 as $key => $value) { if (strLen($strUpdate) > 0) { $strUpdate .= ", "; } $strUpdate .= $key . "=" . $value . " "; } if (!empty($strUpdate)) { $strSql = "UPDATE b_forum_topic SET " . $strUpdate . " WHERE ID = " . $ID; $DB->QueryBind($strSql, array("HTML" => $arFields["HTML"]), false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__); } $res = array_merge($arFields1, $arFields); if (count($res) == 1 && !empty($res["VIEWS"])) { if (intVal($res["VIEWS"]) <= 0) { $GLOBALS["FORUM_CACHE"]["TOPIC"][$ID]["VIEWS"]++; $GLOBALS["FORUM_CACHE"]["TOPIC_FILTER"][$ID]["VIEWS"]++; } else { $GLOBALS["FORUM_CACHE"]["TOPIC"][$ID]["VIEWS"] = intVal($res["VIEWS"]); $GLOBALS["FORUM_CACHE"]["TOPIC_FILTER"][$ID]["VIEWS"] = intVal($res["VIEWS"]); } } else { unset($GLOBALS["FORUM_CACHE"]["FORUM"][$arTopic_prev["FORUM_ID"]]); unset($GLOBALS["FORUM_CACHE"]["TOPIC"][$ID]); unset($GLOBALS["FORUM_CACHE"]["TOPIC_FILTER"][$ID]); if (intVal($arFields1["FORUM_ID"]) > 0) { unset($GLOBALS["FORUM_CACHE"]["FORUM"][intVal($arFields1["FORUM_ID"])]); } if (intVal($arFields["FORUM_ID"]) > 0) { unset($GLOBALS["FORUM_CACHE"]["FORUM"][intVal($arFields["FORUM_ID"])]); } } if (count($res) == 1 && !empty($res["VIEWS"])) { return $ID; } if (is_set($arFields, "FORUM_ID") && intVal($arFields["FORUM_ID"]) != intVal($arTopic_prev["FORUM_ID"])) { $arFiles = array(); $db_res = CForumFiles::GetList(array(), array("TOPIC_ID" => $ID)); if ($db_res && ($res = $db_res->Fetch())) { do { $arFiles[] = $res["ID"]; } while ($res = $db_res->Fetch()); } CForumFiles::UpdateByID($arFiles, array("FORUM_ID" => $arFields["FORUM_ID"])); } /***************** Event onAfterTopicUpdate ************************/ $events = GetModuleEvents("forum", "onAfterTopicUpdate"); if ($events->nSelectedCount > 0) { $arTopicFields = CForumTopic::GetByID($ID, array("NoFilter" => true)); } while ($arEvent = $events->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID, $arTopicFields)); } /***************** /Event ******************************************/ // recalc statistic if topic removed from another forum if (!$skip_counts && is_set($arFields, "FORUM_ID") && intVal($arFields["FORUM_ID"]) != intVal($arTopic_prev["FORUM_ID"])) { $DB->StartTransaction(); $db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $ID)); while ($ar_res = $db_res->Fetch()) { CForumMessage::Update($ar_res["ID"], array("FORUM_ID" => $arFields["FORUM_ID"]), true); } $db_res = CForumSubscribe::GetList(array(), array("TOPIC_ID" => $ID)); while ($ar_res = $db_res->Fetch()) { CForumSubscribe::Update($ar_res["ID"], array("FORUM_ID" => $arFields["FORUM_ID"])); } $DB->Commit(); CForumNew::SetStat($arFields["FORUM_ID"]); CForumNew::SetStat($arTopic_prev["FORUM_ID"]); } if (IsModuleInstalled("search")) { $bNeedDeleteIndex = false; if (is_set($arFields, "FORUM_ID") && intVal($arFields["FORUM_ID"]) != intVal($arTopic_prev["FORUM_ID"])) { $res = CForumNew::GetByID($arFields["FORUM_ID"]); $bNeedDeleteIndex = $res["INDEXATION"] != "Y" ? true : false; } if ($bNeedDeleteIndex) { CModule::IncludeModule("search"); CSearch::DeleteIndex("forum", false, $arTopic_prev["FORUM_ID"], $ID); } elseif (is_set($arFields, "TITLE") || is_set($arFields, "TAGS") || is_set($arFields, "DESCRIPTION")) { $arReindex = array(); $arFields["FORUM_ID"] = is_set($arFields, "FORUM_ID") ? $arFields["FORUM_ID"] : $arTopic_prev["FORUM_ID"]; if (is_set($arFields, "TITLE") && trim($arTopic_prev["TITLE"]) != trim($arFields["TITLE"])) { $arReindex["TITLE"] = $bNeedFilter ? $arFieldsForFilter["TITLE"] : $arFields["TITLE"]; } if (is_set($arFields, "DESCRIPTION") && trim($arTopic_prev["DESCRIPTION"]) != trim($arFields["DESCRIPTION"])) { $title = is_set($arReindex, "TITLE") ? $arReindex["TITLE"] : ($bNeedFilter ? $arFieldsForFilter["TITLE"] : $arTopic_prev["TITLE"]); $description = $bNeedFilter ? $arFieldsForFilter["DESCRIPTION"] : $arFields["DESCRIPTION"]; $arReindex["TITLE_FOR_FIRST_POST"] = $title . (!empty($description) ? ", " . $description : ""); } if (is_set($arFields, "TAGS") && trim($arTopic_prev["TAGS"]) != trim($arFields["TAGS"])) { $arReindex["TAGS"] = $bNeedFilter ? $arFieldsForFilter["TAGS"] : $arFields["TAGS"]; } if (!empty($arReindex)) { CModule::IncludeModule("search"); if (is_set($arReindex, "TITLE")) { $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("FORUM_ID" => $arFields["FORUM_ID"], "TOPIC_ID" => $ID, "NEW_TOPIC" => "Y")); if ($db_res) { while ($arMessage = $db_res->Fetch()) { CForumMessage::Reindex($arMessage['ID'], array_merge($arMessage, $arReindex)); } } } if (is_set($arReindex, "TITLE_FOR_FIRST_POST") || is_set($arReindex, "TAGS")) { unset($arReindex["TITLE"]); if (is_set($arReindex, "TITLE_FOR_FIRST_POST")) { $arReindex["TITLE"] = $arReindex["TITLE_FOR_FIRST_POST"]; unset($arReindex["TITLE_FOR_FIRST_POST"]); } $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $ID, "NEW_TOPIC" => "Y")); if ($db_res && ($arMessage = $db_res->Fetch())) { CForumMessage::Reindex($arMessage['ID'], array_merge($arMessage, $arReindex)); } } } } } return $ID; }
$lAdmin = new CAdminList($tableId, $sort); $lAdmin->bMultipart = true; $lAdmin->AddHeaders($headerList); if ($lAdmin->EditAction() && check_bitrix_sessid()) { $fieldList = []; foreach ($_REQUEST['FIELDS'] as $id => $field) { if ($field == $_REQUEST['FIELDS_OLD'][$id]) { continue; } foreach ($field as &$value) { $value = htmlspecialcharsEx($value); } $fieldList[$id] = $field; } foreach ($fieldList as $id => $fields) { if (!CForumMessage::Update($id, $fields)) { if ($exception = $APPLICATION->GetException()) { $lAdmin->AddGroupError($exception->GetString(), $id); } else { $lAdmin->AddGroupError('Ошибка редактирования отзывов', $id); } } } } if (($idList = $lAdmin->GroupAction()) && check_bitrix_sessid()) { foreach ($idList as $id) { if (!(int) $id) { continue; } switch ($_REQUEST['action']) { case 'delete':