function Fetch() { global $DB; $arFields = array(); if ($res = parent::Fetch()) { if (COption::GetOptionString("forum", "MESSAGE_HTML", "N") == "Y" || COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $res["POST_MESSAGE_HTML"] = trim($res["POST_MESSAGE_HTML"]); $res["POST_MESSAGE_FILTER"] = trim($res["POST_MESSAGE_FILTER"]); if (empty($res["POST_MESSAGE_HTML"]) && COption::GetOptionString("forum", "MESSAGE_HTML", "N") == "Y" || empty($res["POST_MESSAGE_FILTER"]) && COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $arForum = CForumNew::GetByID($res["FORUM_ID"]); if (COption::GetOptionString("forum", "FILTER", "Y") == "Y" && empty($res["POST_MESSAGE_FILTER"])) { $arFields["POST_MESSAGE_FILTER"] = CFilterUnquotableWords::Filter($res["POST_MESSAGE"]); $arFields["POST_MESSAGE_FILTER"] = empty($arFields["POST_MESSAGE_FILTER"]) ? "*" : $arFields["POST_MESSAGE_FILTER"]; } if (COption::GetOptionString("forum", "MESSAGE_HTML", "N") == "Y" && empty($res["POST_MESSAGE_HTML"])) { /* Info about one file is saved in old table field ATTACH_IMG */ $arFiles = false; if (intval($res["ATTACH_IMG"]) > 0) { $arFiles = array(); $db_files = CForumFiles::GetList(array("MESSAGE_ID" => "ASC"), array("MESSAGE_ID" => $res["ID"])); if ($db_files && ($res_file = $db_files->Fetch())) { do { $res_file["SRC"] = CFile::GetFileSRC($res); $arFiles[$res_file["ID"]] = $res_file; } while ($res_file = $db_files->Fetch()); } } $parser = new forumTextParser(LANGUAGE_ID); $allow = forumTextParser::GetFeatures($arForum); $allow['SMILES'] = $res["USE_SMILES"] == "Y" ? $allow['SMILES'] : "N"; $POST_MESSAGE_HTML = is_set($arFields, "POST_MESSAGE_FILTER") ? $arFields["POST_MESSAGE_FILTER"] : $res["POST_MESSAGE"]; $arFields["POST_MESSAGE_HTML"] = $parser->convert($POST_MESSAGE_HTML, $allow, "html", $arFiles); } $strUpdate = $DB->PrepareUpdate("b_forum_message", $arFields); $strSql = "UPDATE b_forum_message SET " . $strUpdate . " WHERE ID = " . intVal($res["ID"]); if ($DB->QueryBind($strSql, $arFields, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) { foreach ($arFields as $key => $val) { $res[$key] = $val; } } } } if (COption::GetOptionString("forum", "FILTER", "Y") == "Y") { if (is_set($res, "HTML") || is_set($res, "FM_HTML")) { $arr = @unserialize(is_set($res, "HTML") ? $res["HTML"] : $res["FM_HTML"]); if (empty($arr) || !is_array($arr)) { $arr = array("AUTHOR_NAME" => $res["AUTHOR_NAME"], "AUTHOR_EMAIL" => $res["AUTHOR_EMAIL"], "EDITOR_NAME" => $res["EDITOR_NAME"], "EDITOR_EMAIL" => $res["EDITOR_EMAIL"], "EDIT_REASON" => $res["EDIT_REASON"]); foreach ($arr as $key => $val) { if (!empty($val)) { $val = CFilterUnquotableWords::Filter($val); $arr[$key] = empty($val) ? "*" : $val; } else { $arr[$key] = ''; } } $arFields = array("HTML" => serialize($arr)); $strUpdate = $DB->PrepareUpdate("b_forum_message", $arFields); $strSql = "UPDATE b_forum_message SET " . $strUpdate . " WHERE ID = " . intVal($res["ID"]); $DB->QueryBind($strSql, $arFields, false, "File: " . __FILE__ . "<br>Line: " . __LINE__); } foreach ($arr as $key => $val) { $res["~" . $key] = $res[$key]; $res["" . $key] = $val; } } if (!empty($res["FT_HTML"])) { $arr = @unserialize($res["FT_HTML"]); if (is_array($arr) && !empty($arr["TITLE"])) { foreach ($arr as $key => $val) { $res["~FT_" . $key] = $res["FT_" . $key]; $res["FT_" . $key] = $val; } } } if (!empty($res["F_HTML"])) { $arr = @unserialize($res["F_HTML"]); if (is_array($arr)) { foreach ($arr as $key => $val) { $res["~F_" . $key] = $res["F_" . $key]; $res["F_" . $key] = $val; } } if (!empty($res["FT_TITLE"])) { $res["F_TITLE"] = $res["FT_TITLE"]; } } } if (!empty($this->sNameTemplate)) { $arTmp = array(); foreach (array("AUTHOR_ID" => "AUTHOR_NAME", "EDITOR_ID" => "EDITOR_NAME", "USER_START_ID" => "USER_START_NAME") as $id => $name) { if (array_key_exists($id, $res)) { $tmp = ""; if (!empty($res[$id])) { if (in_array($res[$id], $arTmp)) { $tmp = $arTmp[$res[$id]]; } else { $arTmp[$res[$id]] = $tmp = !empty($res[$name . "_FRMT"]) ? $res[$name . "_FRMT"] : CForumUser::GetFormattedNameByUserID($res[$id], $this->sNameTemplate, $id == "AUTHOR_ID" ? $res : array()); } } $res[$name] = !empty($tmp) ? $tmp : $res[$name]; unset($res[$name . "_FRMT"]); } } } if ($this->checkUserFields) { $arUF = array_intersect_key($res, $this->arUserFields); if (empty($arUF)) { $this->checkUserFields = false; } else { foreach ($arUF as $k => $v) { $res[$k] = $this->arUserFields[$k]; $res[$k]["ENTITY_VALUE_ID"] = $res["ID"]; $res[$k]["VALUE"] = $v; } } } } return $res; }
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; }
public static function AddComment_Photo_Forum($arFields, $FORUM_ID, $arLog) { if (!CModule::IncludeModule("forum")) { return false; } if (!CModule::IncludeModule("iblock")) { return false; } $ufFileID = array(); $ufDocID = array(); $arElement = false; $arFilteredText = array(); $arFilter = array("ID" => $arLog["SOURCE_ID"]); $arSelectedFields = array("IBLOCK_ID", "ID", "NAME", "TAGS", "CODE", "IBLOCK_SECTION_ID", "DETAIL_PAGE_URL", "CREATED_BY", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PROPERTY_FORUM_TOPIC_ID", "PROPERTY_FORUM_MESSAGE_CNT"); $db_res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelectedFields); if ($db_res && ($res = $db_res->GetNext())) { $arElement = $res; } if ($arElement) { // check iblock properties CSocNetLogTools::AddComment_Review_CheckIBlock_Forum($arElement); $dbMessage = CForumMessage::GetList(array(), array("PARAM2" => $arElement["ID"])); if (!($arMessage = $dbMessage->Fetch())) { // Add Topic $TOPIC_ID = CSocNetLogTools::AddComment_Review_CreateRoot_Forum($arElement, $FORUM_ID); $bNewTopic = true; } else { $TOPIC_ID = $arMessage["TOPIC_ID"]; } if (intval($TOPIC_ID) > 0) { if (COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $arFields["TEXT_MESSAGE"] = $arFilteredText["TEXT_MESSAGE"] = CFilterUnquotableWords::Filter($arFields["TEXT_MESSAGE"]); $arFilteredText["MESSAGE"] = CFilterUnquotableWords::Filter($arFields["MESSAGE"]); } // Add comment $messageID = false; $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PARAM2" => $arElement["ID"], "APPROVED" => "Y"); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsMessage["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id); } } } $messageID = ForumAddMessage("REPLY", $FORUM_ID, $TOPIC_ID, 0, $arFieldsMessage, $sError, $sNote); if (!$messageID) { $strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } else { // get UF DOC value and FILE_ID there $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID); CSocNetLogTools::AddComment_Review_UpdateElement_Forum($arElement, $TOPIC_ID, $bNewTopic); } } else { $strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } } else { $strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } return array_merge($arFilteredText, array("SOURCE_ID" => $messageID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $strError, "NOTES" => "", "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID), "IM_MESSAGE" => $messageID ? $arFields["TEXT_MESSAGE"] : false)); }
function CheckFields($ACTION, &$arFields) { $aMsg = array(); if (is_set($arFields, "NAME") || $ACTION == "ADD") { $arFields["NAME"] = trim($arFields["NAME"]); if (empty($arFields["NAME"])) { $aMsg[] = array("id" => "NAME", "text" => GetMessage("F_ERROR_EMPTY_NAME")); } } if (!is_set($arFields, "SITES") && is_set($arFields, "LID")) { if (is_set($arFields, "PATH2FORUM_MESSAGE")) { $arFields["SITES"] = array($arFields["LID"] => $arFields["PATH2FORUM_MESSAGE"]); } else { $sPath = "/"; $db_res = CSite::GetByID($arFields["LID"]); if ($db_res && ($res = $db_res->Fetch())) { $sPath = $res["DIR"]; } $arFields["SITES"] = array($arFields["LID"] => $sPath . COption::GetOptionString("forum", "REL_FPATH", "") . "forum/read.php?FID=#FORUM_ID#&TID=#TOPIC_ID#&MID=#MESSAGE_ID##message#MESSAGE_ID#"); } } if (is_set($arFields, "SITES") || $ACTION == "ADD") { if (is_array($arFields["SITES"]) && !empty($arFields["SITES"])) { $db_res = CSite::GetList($sBy = "sort", $sOrder = "asc"); $arSites = array(); while ($res = $db_res->Fetch()) { if (is_set($arFields["SITES"], $res["LID"])) { if (strLen($arFields["SITES"][$res["LID"]]) > 0) { $arSites[$res["LID"]] = $arFields["SITES"][$res["LID"]]; } else { $aMsg[] = array("id" => "SITE_PATH[" . $res["LID"] . "]", "text" => GetMessage("F_ERROR_EMPTY_SITE_PATH", array("#SITE_ID#" => $res["LID"], "#SITE_NAME#" => $res["NAME"]))); } } } $arFields["SITES"] = $arSites; } if (!is_array($arFields["SITES"]) || empty($arFields["SITES"])) { $aMsg[] = array("id" => "SITES", "text" => GetMessage("F_ERROR_EMPTY_SITES")); } } if (!empty($aMsg)) { $e = new CAdminException(array_reverse($aMsg)); $GLOBALS["APPLICATION"]->ThrowException($e); return false; } if (is_set($arFields, "SORT") || $ACTION == "ADD") { $arFields["SORT"] = intVal(intVal($arFields["SORT"]) <= 0 ? 100 : $arFields["SORT"]); } if (is_set($arFields, "FORUM_GROUP_ID") || $ACTION == "ADD") { $arFields["FORUM_GROUP_ID"] = intVal($arFields["FORUM_GROUP_ID"]) <= 0 ? false : intVal($arFields["FORUM_GROUP_ID"]); } if (is_set($arFields, "ACTIVE") || $ACTION == "ADD") { $arFields["ACTIVE"] = $arFields["ACTIVE"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "INDEXATION") || $ACTION == "ADD") { $arFields["INDEXATION"] = $arFields["INDEXATION"] == "N" ? "N" : "Y"; } if (is_set($arFields, "DEDUPLICATION") || $ACTION == "ADD") { $arFields["DEDUPLICATION"] = $arFields["DEDUPLICATION"] == "N" ? "N" : "Y"; } if (is_set($arFields, "MODERATION") || $ACTION == "ADD") { $arFields["MODERATION"] = $arFields["MODERATION"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "ALLOW_HTML") || $ACTION == "ADD") { $arFields["ALLOW_HTML"] = $arFields["ALLOW_HTML"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "ALLOW_ANCHOR") || $ACTION == "ADD") { $arFields["ALLOW_ANCHOR"] = $arFields["ALLOW_ANCHOR"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_BIU") || $ACTION == "ADD") { $arFields["ALLOW_BIU"] = $arFields["ALLOW_BIU"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_IMG") || $ACTION == "ADD") { $arFields["ALLOW_IMG"] = $arFields["ALLOW_IMG"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_VIDEO") || $ACTION == "ADD") { $arFields["ALLOW_VIDEO"] = $arFields["ALLOW_VIDEO"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_LIST") || $ACTION == "ADD") { $arFields["ALLOW_LIST"] = $arFields["ALLOW_LIST"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_QUOTE") || $ACTION == "ADD") { $arFields["ALLOW_QUOTE"] = $arFields["ALLOW_QUOTE"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_CODE") || $ACTION == "ADD") { $arFields["ALLOW_CODE"] = $arFields["ALLOW_CODE"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_FONT") || $ACTION == "ADD") { $arFields["ALLOW_FONT"] = $arFields["ALLOW_FONT"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_TABLE") || $ACTION == "ADD") { $arFields["ALLOW_TABLE"] = $arFields["ALLOW_TABLE"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_ALIGN") || $ACTION == "ADD") { $arFields["ALLOW_ALIGN"] = $arFields["ALLOW_ALIGN"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_SMILES") || $ACTION == "ADD") { $arFields["ALLOW_SMILES"] = $arFields["ALLOW_SMILES"] == "N" ? "N" : "Y"; } if (is_set($arFields, "ALLOW_UPLOAD") || $ACTION == "ADD") { $arFields["ALLOW_UPLOAD"] = in_array($arFields["ALLOW_UPLOAD"], array("Y", "F", "A")) ? $arFields["ALLOW_UPLOAD"] : "N"; } if (is_set($arFields, "ALLOW_NL2BR") || $ACTION == "ADD") { $arFields["ALLOW_NL2BR"] = $arFields["ALLOW_NL2BR"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "ALLOW_TOPIC_TITLED") || $ACTION == "ADD") { $arFields["ALLOW_TOPIC_TITLED"] = $arFields["ALLOW_TOPIC_TITLED"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "ALLOW_MOVE_TOPIC") || $ACTION == "ADD") { $arFields["ALLOW_MOVE_TOPIC"] = $arFields["ALLOW_MOVE_TOPIC"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "ALLOW_SIGNATURE") || $ACTION == "ADD") { $arFields["ALLOW_SIGNATURE"] = $arFields["ALLOW_SIGNATURE"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "ASK_GUEST_EMAIL") || $ACTION == "ADD") { $arFields["ASK_GUEST_EMAIL"] = $arFields["ASK_GUEST_EMAIL"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "ASK_GUEST_EMAIL") || $ACTION == "ADD") { $arFields["ASK_GUEST_EMAIL"] = $arFields["ASK_GUEST_EMAIL"] == "Y" ? "Y" : "N"; } if (is_set($arFields, "LAST_POSTER_NAME") && COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $arr = array("LAST_POSTER_NAME" => CFilterUnquotableWords::Filter($arFields["LAST_POSTER_NAME"])); $arr["LAST_POSTER_NAME"] = empty($arr["LAST_POSTER_NAME"]) ? "*" : $arr["LAST_POSTER_NAME"]; $arFields["HTML"] = serialize($arr); } return true; }
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; }
function AddComment_Review_CreateRoot_Forum($arElement, $forumID, $bPostFirstMessage = false, $strFirstMessage = "") { if (!CModule::IncludeModule("forum")) { return false; } if ($bPostFirstMessage && strlen($strFirstMessage) <= 0) { return false; } // Add Topic $arUserStart = array("ID" => intVal($arElement["~CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arElement["~CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arElement["~CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim($res["NAME"] . " " . $res["LAST_NAME"]) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $GLOBALS["DB"]->StartTransaction(); $arFields = array("TITLE" => $arElement["~NAME"], "TAGS" => $arElement["~TAGS"], "FORUM_ID" => $forumID, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "XML_ID" => "IBLOCK_" . $arElement["ID"]); if (isset($arElement["ENTITY_TYPE"]) && $arElement["ENTITY_TYPE"] == SONET_ENTITY_GROUP && isset($arElement["ENTITY_ID"]) && intval($arElement["ENTITY_ID"]) > 0) { $arFields["SOCNET_GROUP_ID"] = intval($arElement["ENTITY_ID"]); } $TOPIC_ID = CForumTopic::Add($arFields); if ($bPostFirstMessage && intVal($TOPIC_ID) > 0) { if (COption::GetOptionString("forum", "FILTER", "Y") == "Y") { $strFirstMessage = CFilterUnquotableWords::Filter($strFirstMessage); } // Add post as new message $arFields = array("POST_MESSAGE" => $strFirstMessage, "AUTHOR_ID" => $arUserStart["ID"], "AUTHOR_NAME" => $arUserStart["NAME"], "FORUM_ID" => $forumID, "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "IB", "PARAM2" => intVal($arElement["ID"])); $MID = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")); if (intVal($MID) <= 0) { $arError[] = array("code" => "message is not added 1", "title" => GetMessage("F_ERR_ADD_MESSAGE")); CForumTopic::Delete($TOPIC_ID); $TOPIC_ID = 0; } elseif ($arParams["SUBSCRIBE_AUTHOR_ELEMENT"] == "Y" && intVal($arResult["ELEMENT"]["~CREATED_BY"]) > 0) { if ($arUserStart["USER_PROFILE"] == "N") { $arUserStart["FORUM_USER_ID"] = CForumUser::Add(array("USER_ID" => $arResult["ELEMENT"]["~CREATED_BY"])); } if (intVal($arUserStart["FORUM_USER_ID"]) > 0) { CForumSubscribe::Add(array("USER_ID" => $arResult["ELEMENT"]["~CREATED_BY"], "FORUM_ID" => $arParams["FORUM_ID"], "SITE_ID" => SITE_ID, "TOPIC_ID" => $TID, "NEW_TOPIC_ONLY" => "N")); BXClearCache(true, "/bitrix/forum/user/" . $arResult["ELEMENT"]["~CREATED_BY"] . "/subscribe/"); // Sorry, Max. } } } elseif (intVal($TOPIC_ID) <= 0) { $GLOBALS["DB"]->Rollback(); return false; } $GLOBALS["DB"]->Commit(); return $TOPIC_ID; }