foreach ($arForum["TOPICS"] as $arTopic) { $arTopic["FORUM_ID"] = $forumID; $topicID = CForumTopic::Add($arTopic); if ($topicID < 1 || !isset($arTopic["MESSAGES"]) || !is_array($arTopic["MESSAGES"])) { continue; } foreach ($arTopic["MESSAGES"] as $arMessage) { $arMessage["FORUM_ID"] = $forumID; $arMessage["TOPIC_ID"] = $topicID; $messageID = CForumMessage::Add($arMessage, false); if ($messageID < 1) { CForumTopic::Delete($topicID); continue 2; } } CForumTopic::SetStat($topicID); } } $fidParameter = ""; $dbForum = CForumNew::GetList(array(), array("SITE_ID" => WIZARD_SITE_ID)); while ($arForum = $dbForum->Fetch()) { if ($arForum["FORUM_GROUP_ID"] != $arGroupID["HIDDEN"] && $arForum["FORUM_GROUP_ID"] != $arGroupID["COMMENTS"]) { $fidParameter .= $arForum["ID"] . ","; } } $fidParameter = rtrim($fidParameter, ","); $forum_theme = 'blue'; switch (WIZARD_THEME_ID) { case 'green': $forum_theme = "green"; break;
function Delete($ID) { global $DB; $ID = intVal($ID); $arMessage = array(); if ($ID > 0) { $arMessage = CForumMessage::GetByID($ID, array("FILTER" => "N")); } if (empty($arMessage)) { return false; } /***************** Event onBeforeMessageAdd ************************/ foreach (GetModuleEvents("forum", "onBeforeMessageDelete", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage)) === false) { return false; } } /***************** /Event ******************************************/ $AUTHOR_ID = intVal($arMessage["AUTHOR_ID"]); $TOPIC_ID = intVal($arMessage["TOPIC_ID"]); $FORUM_ID = intVal($arMessage["FORUM_ID"]); $DB->StartTransaction(); // delete votes if ($arMessage["PARAM1"] == "VT" && intVal($arMessage["PARAM2"]) > 0 && IsModuleInstalled("vote")) { CModule::IncludeModule("vote"); CVote::Delete($arMessage["PARAM2"]); } // delete files CForumFiles::Delete(array("MESSAGE_ID" => $ID), array("DELETE_MESSAGE_FILE" => "Y")); // delete message $DB->Query("DELETE FROM b_forum_message WHERE ID=" . $ID); // after delete $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID), false, 1); $res = false; if (!($db_res && ($res = $db_res->Fetch()))) { CForumTopic::Delete($TOPIC_ID); } else { // if deleted message was first if ($arMessage["NEW_TOPIC"] == "Y") { $DB->Update('b_forum_message', array('NEW_TOPIC' => '"Y"'), "WHERE ID=" . $res["ID"]); } CForumTopic::SetStat($TOPIC_ID); } $DB->Commit(); $GLOBALS["USER_FIELD_MANAGER"]->Delete("FORUM_MESSAGE", $ID); if ($AUTHOR_ID > 0) { CForumUser::SetStat($AUTHOR_ID); } CForumNew::SetStat($FORUM_ID); /***************** Event onBeforeMessageAdd ************************/ foreach (GetModuleEvents("forum", "onAfterMessageDelete", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array($ID, $arMessage)); } /***************** /Event ******************************************/ if (CModule::IncludeModule("search")) { CSearch::DeleteIndex("forum", $ID); if (is_array($res) && !empty($res)) { CForumMessage::Reindex($res["ID"], $res); } } return true; }
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 Add($arFields, $strUploadDir = false, $arParams = array()) { global $DB; $strUploadDir = ($strUploadDir === false ? "forum/upload" : $strUploadDir); if (!CForumMessage::CheckFields("ADD", $arFields)) return false; $arForum = CForumNew::GetByID($arFields["FORUM_ID"]); $arParams["SKIP_STATISTIC"] = ($arParams["SKIP_STATISTIC"] == "Y" ? "Y" : "N"); $arParams["SKIP_INDEXING"] = ($arParams["SKIP_INDEXING"] == "Y" || $arForum["INDEXATION"] != "Y" ? "Y" : "N"); $POST_MESSAGE = $arFields["POST_MESSAGE"]; $parser = new forumTextParser(LANGUAGE_ID); $allow = forumTextParser::GetFeatures($arForum); $allow['SMILES'] = (($arFields["USE_SMILES"] != "Y") ? 'N' : $allow['SMILES']); if (COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $POST_MESSAGE = CFilterUnquotableWords::Filter($POST_MESSAGE); $arFields["POST_MESSAGE_FILTER"] = (empty($POST_MESSAGE) ? "*" : $POST_MESSAGE); } /***************** Attach ******************************************/ $arFiles = array(); if (is_array($arFields["ATTACH_IMG"])) $arFields["FILES"] = array($arFields["ATTACH_IMG"]); unset($arFields["ATTACH_IMG"]); if (is_array($arFields["FILES"]) && !empty($arFields["FILES"])) { $res = array("FORUM_ID" => $arFields["FORUM_ID"], "USER_ID" => $arFields["AUTHOR_ID"], "upload_dir" => $strUploadDir); $arFiles = CForumFiles::Save($arFields["FILES"], $res, false); if (!empty($arFiles)) { $arFiles = array_keys($arFiles); sort($arFiles); $arFields["ATTACH_IMG"] = $arFiles[0]; $arFields["ATTACHED_FILES"] = $arFiles; } unset($arFields["FILES"]); } /***************** Attach/******************************************/ if (COption::GetOptionString("forum", "MESSAGE_HTML", "N") == "Y") $POST_MESSAGE = $parser->convert($POST_MESSAGE, $allow, "html", $arFiles); $arFields["POST_MESSAGE_HTML"] = $POST_MESSAGE; /***************** Event onBeforeMessageAdd ************************/ foreach(GetModuleEvents("forum", "onBeforeMessageAdd", true) as $arEvent) { if (ExecuteModuleEventEx($arEvent, array(&$arFields, &$strUploadDir)) === false) return false; } /***************** /Event ******************************************/ if (empty($arFields)) return false; $arInsert = $DB->PrepareInsert("b_forum_message", $arFields, $strUploadDir); $strDatePostField = ""; $strDatePostValue = ""; if (!is_set($arFields, "POST_DATE")) { $strDatePostField = ", POST_DATE"; $strDatePostValue = ", ".$DB->GetNowFunction().""; } $strSql = "INSERT INTO b_forum_message(".$arInsert[0].$strDatePostField.") VALUES(".$arInsert[1].$strDatePostValue.")"; $DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__); $ID = intVal($DB->LastID()); /***************** Attach ******************************************/ if (!empty($arFiles)) CForumFiles::UpdateByID($arFiles, array("FORUM_ID" => $arFields["FORUM_ID"], "TOPIC_ID" => $arFields["TOPIC_ID"], "MESSAGE_ID" => $ID)); /***************** Attach/******************************************/ /***************** Quota *******************************************/ $_SESSION["SESS_RECOUNT_DB"] = "Y"; $GLOBALS["USER_FIELD_MANAGER"]->Update("FORUM_MESSAGE", $ID, $arFields); if ($arParams["SKIP_STATISTIC"] == "Y" && $arParams["SKIP_INDEXING"] == "Y") return $ID; $arMessage = CForumMessage::GetByIDEx($ID, array("GET_FORUM_INFO" => "N", "GET_TOPIC_INFO" => "Y", "FILTER" => "Y")); if ($arParams["SKIP_STATISTIC"] != "Y") { if (intVal($arMessage["AUTHOR_ID"]) > 0) { CForumUser::SetStat($arMessage["AUTHOR_ID"], array("MESSAGE" => $arMessage)); } CForumTopic::SetStat($arMessage["TOPIC_ID"], array("MESSAGE" => $arMessage)); CForumNew::SetStat($arMessage["FORUM_ID"], array("MESSAGE" => $arMessage)); } /***************** Events onAfterMessageAdd ************************/ foreach(GetModuleEvents("forum", "onAfterMessageAdd", true) as $arEvent) ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage, $arMessage["TOPIC_INFO"], $arMessage["FORUM_INFO"], $arFields)); /***************** /Events *****************************************/ if ($arMessage["APPROVED"] == "Y") { if ($arParams["SKIP_INDEXING"] != "Y" && CModule::IncludeModule("search")) { $arMessage["POST_MESSAGE"] = (COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]); $arParams = array( "PERMISSION" => array(), "SITE" => CForumNew::GetSites($arMessage["FORUM_ID"]), "DEFAULT_URL" => "/"); $arGroups = CForumNew::GetAccessPermissions($arMessage["FORUM_ID"]); foreach($arGroups as $arGroup) { if ($arGroup[1] >= "E") { $arParams["PERMISSION"][] = $arGroup[0]; if ($arGroup[0] == 2) break; } } $arSearchInd = array( "LID" => array(), "LAST_MODIFIED" => $arMessage["POST_DATE"], "PARAM1" => $arMessage["FORUM_ID"], "PARAM2" => $arMessage["TOPIC_ID"], "ENTITY_TYPE_ID" => ($arMessage["NEW_TOPIC"] == "Y"? "FORUM_TOPIC": "FORUM_POST"), "ENTITY_ID" => ($arMessage["NEW_TOPIC"] == "Y"? $arMessage["TOPIC_ID"]: $ID), "USER_ID" => $arMessage["AUTHOR_ID"], "PERMISSIONS" => $arParams["PERMISSION"], "TITLE" => $arMessage["TOPIC_INFO"]["TITLE"].($arMessage["NEW_TOPIC"] == "Y" && !empty($arMessage["TOPIC_INFO"]["DESCRIPTION"]) ? ", ".$arMessage["TOPIC_INFO"]["DESCRIPTION"] : ""), "TAGS" => ($arMessage["NEW_TOPIC"] == "Y" ? $arMessage["TOPIC_INFO"]["TAGS"] : ""), "BODY" => GetMessage("AVTOR_PREF")." ".$arMessage["AUTHOR_NAME"].". ".(textParser::killAllTags($arMessage["POST_MESSAGE"])), "URL" => "", "INDEX_TITLE" => $arMessage["NEW_TOPIC"] == "Y", ); // get mentions $arMentionedUserID = CForumMessage::GetMentionedUserID($arMessage["POST_MESSAGE"]); if (!empty($arMentionedUserID)) { $arSearchInd["PARAMS"] = array( "mentioned_user_id" => $arMentionedUserID ); } $urlPatterns = array( "FORUM_ID" => $arMessage["FORUM_ID"], "TOPIC_ID" => $arMessage["TOPIC_ID"], "TITLE_SEO" => $arMessage["TOPIC_INFO"]["TITLE_SEO"], "MESSAGE_ID" => $arMessage["ID"], "SOCNET_GROUP_ID" => $arMessage["TOPIC_INFO"]["SOCNET_GROUP_ID"], "OWNER_ID" => $arMessage["TOPIC_INFO"]["OWNER_ID"], "PARAM1" => $arMessage["PARAM1"], "PARAM2" => $arMessage["PARAM2"]); foreach ($arParams["SITE"] as $key => $val) { $arSearchInd["LID"][$key] = CForumNew::PreparePath2Message($val, $urlPatterns); if (empty($arSearchInd["URL"]) && !empty($arSearchInd["LID"][$key])) $arSearchInd["URL"] = $arSearchInd["LID"][$key]; } if (empty($arSearchInd["URL"])) { foreach ($arParams["SITE"] as $key => $val): $db_lang = CLang::GetByID($key); if ($db_lang && $ar_lang = $db_lang->Fetch()): $arParams["DEFAULT_URL"] = $ar_lang["DIR"]; break; endif; endforeach; $arParams["DEFAULT_URL"] .= COption::GetOptionString("forum", "REL_FPATH", ""). "forum/read.php?FID=#FID#&TID=#TID#&MID=#MID##message#MID#"; $arSearchInd["URL"] = CForumNew::PreparePath2Message($arParams["DEFAULT_URL"], $urlPatterns); } CSearch::Index("forum", $ID, $arSearchInd); } } return $ID; }
/** * <p>Удаляет сообщение с кодом <i>ID</i>.</p> <p><b>Примечание</b>. Метод использует внутреннюю транзакцию. Если у вас используется <b>MySQL</b> и <b>InnoDB</b>, и ранее была открыта транзакция, то ее необходимо закрыть до подключения метода.</p> * * * * * @param int $ID Код сообщения, которое необходимо удалить. * * * * @return bool * * * <h4>See Also</h4> * <ul><li>Перед удалением сообщения следует проверить возможность * удаления методом <a * href="http://dev.1c-bitrix.ru/api_help/forum/developer/cforummessage/canuserdeletemessage.php">CForumMessage::CanUserDeleteMessage</a> * </li></ul> * * * @static * @link http://dev.1c-bitrix.ru/api_help/forum/developer/cforummessage/delete.php * @author Bitrix */ public static function Delete($ID) { global $DB; $ID = intVal($ID); $arMessage = array(); if ($ID > 0) $arMessage = CForumMessage::GetByID($ID, array("FILTER" => "N")); if (empty($arMessage)) return false; /***************** Event onBeforeMessageAdd ************************/ $events = GetModuleEvents("forum", "onBeforeMessageDelete"); while ($arEvent = $events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage)) === false) return false; } /***************** /Event ******************************************/ $AUTHOR_ID = intVal($arMessage["AUTHOR_ID"]); $TOPIC_ID = intVal($arMessage["TOPIC_ID"]); $FORUM_ID = intVal($arMessage["FORUM_ID"]); $DB->StartTransaction(); // delete votes if ($arMessage["PARAM1"] == "VT" && intVal($arMessage["PARAM2"]) > 0 && IsModuleInstalled("vote")): CModule::IncludeModule("vote"); CVote::Delete($arMessage["PARAM2"]); endif; // delete files CForumFiles::Delete(array("MESSAGE_ID" => $ID), array("DELETE_MESSAGE_FILE" => "Y")); // delete message $DB->Query("DELETE FROM b_forum_message WHERE ID=".$ID); // after delete $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID), false, 1); $res = false; if (!($db_res && $res = $db_res->Fetch())): CForumTopic::Delete($TOPIC_ID); else: // if deleted message was first if ($arMessage["NEW_TOPIC"] == "Y"): $DB->Query("UPDATE b_forum_message SET NEW_TOPIC='Y' WHERE ID=".$res["ID"]); endif; CForumTopic::SetStat($TOPIC_ID); endif; $DB->Commit(); $GLOBALS["USER_FIELD_MANAGER"]->Delete("FORUM_MESSAGE", $ID); if ($AUTHOR_ID > 0): CForumUser::SetStat($AUTHOR_ID); endif; CForumNew::SetStat($FORUM_ID); /***************** Event onBeforeMessageAdd ************************/ $events = GetModuleEvents("forum", "onAfterMessageDelete"); while ($arEvent = $events->Fetch()) ExecuteModuleEventEx($arEvent, array($ID, $arMessage)); /***************** /Event ******************************************/ if (CModule::IncludeModule("search")) { CSearch::DeleteIndex("forum", $ID); } return true; }