コード例 #1
0
 public function Execute()
 {
     if (!CModule::IncludeModule("forum")) {
         return CBPActivityExecutionStatus::Closed;
     }
     if (!CModule::IncludeModule("iblock")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $forumId = intval($this->ForumId);
     if ($forumId <= 0) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $iblockId = $this->IBlockId;
     $dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID"));
     $arResult = $dbResult->Fetch();
     if (!$arResult) {
         $obProperty = new CIBlockProperty();
         $obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum topic", "CODE" => "FORUM_TOPIC_ID"));
         $obProperty->Add(array("IBLOCK_ID" => $iblockId, "ACTIVE" => "Y", "PROPERTY_TYPE" => "N", "MULTIPLE" => "N", "NAME" => "Forum message count", "CODE" => "FORUM_MESSAGE_CNT"));
         $dbResult = CIBlockElement::GetProperty($iblockId, $documentId[2], false, false, array("CODE" => "FORUM_TOPIC_ID"));
         $arResult = $dbResult->Fetch();
     }
     $forumTopicId = intval($arResult["VALUE"]);
     $arForumUserTmp = $this->ForumUser;
     $arForumUser = CBPHelper::ExtractUsers($arForumUserTmp, $documentId, true);
     $forumUserId = 1;
     $forumUserName = "******";
     if ($arForumUser != null) {
         $forumUserId = $arForumUser;
         $dbResult = CUser::GetByID($forumUserId);
         if ($arResult = $dbResult->Fetch()) {
             $forumUserName = CUser::FormatName(COption::GetOptionString("bizproc", "name_template", CSite::GetNameFormat(false), SITE_ID), $arResult, true);
         }
     }
     $newTopic = "N";
     if ($forumTopicId <= 0) {
         $documentService = $this->workflow->GetService("DocumentService");
         $document = $documentService->GetDocument($documentId);
         $newTopic = "Y";
         $arFields = array("TITLE" => $document["NAME"], "FORUM_ID" => $forumId, "USER_START_ID" => $forumUserId, "USER_START_NAME" => $forumUserName, "LAST_POSTER_NAME" => $forumUserName, "APPROVED" => "Y");
         $forumTopicId = CForumTopic::Add($arFields);
         CIBlockElement::SetPropertyValues($documentId[2], $iblockId, $forumTopicId, "FORUM_TOPIC_ID");
     }
     $arFields = array("POST_MESSAGE" => $this->ForumPostMessage, "AUTHOR_ID" => $forumUserId, "AUTHOR_NAME" => $forumUserName, "FORUM_ID" => $forumId, "TOPIC_ID" => $forumTopicId, "APPROVED" => "Y", "NEW_TOPIC" => $newTopic, "PARAM2" => $documentId[2]);
     $forumMessageId = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
     return CBPActivityExecutionStatus::Closed;
 }
コード例 #2
0
 function SocnetEMailMessageAdd($arMessageFields, $ACTION_VARS)
 {
     if (!is_array($arMessageFields["FORUM_EMAIL_FILTER"])) {
         return false;
     }
     if (!CModule::IncludeModule("socialnetwork")) {
         return false;
     }
     $arParams = $arMessageFields["FORUM_EMAIL_FILTER"];
     if (!CSocNetFeatures::IsActiveFeature(SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum")) {
         return false;
     }
     // Найдем кто отправитель
     $message_email = strlen($arMessageFields["FIELD_REPLY_TO"]) > 0 ? $arMessageFields["FIELD_REPLY_TO"] : $arMessageFields["FIELD_FROM"];
     $message_email_addr = strtolower(CMailUtil::ExtractMailAddress($message_email));
     $o = "LAST_LOGIN";
     $b = "DESC";
     $res = CUser::GetList($o, $b, array("ACTIVE" => "Y", "EMAIL" => $message_email_addr));
     if (($arUser = $res->Fetch()) && strtolower(CMailUtil::ExtractMailAddress($arUser["EMAIL"])) == $message_email_addr) {
         $AUTHOR_USER_ID = $arUser["ID"];
     } elseif ($arParams["NOT_MEMBER_POST"] == "Y") {
         $AUTHOR_USER_ID = false;
     } else {
         CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR1") . ": " . $message_email_addr));
         return false;
     }
     if ($arParams["NOT_MEMBER_POST"] != "Y") {
         // Проверим права доступа
         if (CSocNetFeaturesPerms::CanPerformOperation($AUTHOR_USER_ID, SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum", "full")) {
             $PERMISSION = "Y";
         } elseif (CSocNetFeaturesPerms::CanPerformOperation($AUTHOR_USER_ID, SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum", "newtopic")) {
             $PERMISSION = "M";
         } elseif (CSocNetFeaturesPerms::CanPerformOperation($AUTHOR_USER_ID, SONET_ENTITY_GROUP, $arParams["SOCNET_GROUP_ID"], "forum", "answer")) {
             $PERMISSION = "I";
         } else {
             CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR2") . " " . $arUser["LOGIN"] . " [" . $AUTHOR_USER_ID . "] (" . $message_email_addr . ")"));
             return false;
         }
     }
     $body = $arMessageFields["BODY"];
     //$body = preg_replace("/(\r\n)+/", "\r\n", $body);
     $p = strpos($body, "\r\nFrom:");
     if ($p > 0) {
         $body = substr($body, 0, $p) . "\r\n[CUT]" . substr($body, $p) . "[/CUT]";
     }
     $subject = $arMessageFields["SUBJECT"];
     // обрежем все RE и FW
     $subject = trim(preg_replace('#^\\s*((RE[0-9\\[\\]]*:\\s*)|(FW:\\s*))+(.*)$#i', '\\4', $subject));
     if ($subject == '') {
         $subject = GetMessage("FORUM_MAIL_EMPTY_TOPIC_TITLE") . " " . rand();
     }
     // Найдем какая тема
     $arFields = array();
     $FORUM_ID = IntVal($arParams["FORUM_ID"]);
     $SOCNET_GROUP_ID = IntVal($arParams["SOCNET_GROUP_ID"]);
     $TOPIC_ID = 0;
     global $DB;
     if ($arMessageFields["IN_REPLY_TO"] != '') {
         $dbTopic = $DB->Query("SELECT FT.ID FROM b_forum_topic FT INNER JOIN b_forum_message FM ON FM.TOPIC_ID=FT.ID WHERE FM.XML_ID='" . $DB->ForSQL($arMessageFields["IN_REPLY_TO"], 255) . "' AND FT.FORUM_ID=" . $FORUM_ID . " AND FT.SOCNET_GROUP_ID=" . $SOCNET_GROUP_ID);
         if ($arTopic = $dbTopic->Fetch()) {
             $TOPIC_ID = $arTopic["ID"];
         }
     }
     if ($arParams["USE_SUBJECT"] == "Y" && $TOPIC_ID <= 0) {
         $dbTopic = $DB->Query("SELECT ID FROM b_forum_topic WHERE TITLE='" . $DB->ForSQL($subject, 255) . "' AND FORUM_ID=" . $FORUM_ID . " AND SOCNET_GROUP_ID=" . $SOCNET_GROUP_ID);
         // ограничить по старости?
         if ($arTopic = $dbTopic->Fetch()) {
             $TOPIC_ID = $arTopic["ID"];
         }
     }
     if ($AUTHOR_USER_ID > 0) {
         if ($TOPIC_ID < 0 && $PERMISSION <= "I") {
             CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR3") . " " . $arUser["LOGIN"] . " [" . $AUTHOR_USER_ID . "] (" . $message_email_addr . ")"));
             return false;
         }
         $bSHOW_NAME = true;
         $res = CForumUser::GetByUSER_ID($AUTHOR_USER_ID);
         if ($res) {
             $bSHOW_NAME = $res["SHOW_NAME"] == "Y";
         }
         if ($bSHOW_NAME) {
             $AUTHOR_NAME = $arUser["NAME"] . (strlen($arUser["NAME"]) <= 0 || strlen($arUser["LAST_NAME"]) <= 0 ? "" : " ") . $arUser["LAST_NAME"];
         }
         if (strlen(Trim($AUTHOR_NAME)) <= 0) {
             $AUTHOR_NAME = $arUser["LOGIN"];
         }
     } else {
         $AUTHOR_NAME = $arMessageFields["FIELD_FROM"];
         $arFields["AUTHOR_EMAIL"] = $arMessageFields["FIELD_FROM"];
     }
     $arFields["NEW_TOPIC"] = "N";
     if ($PERMISSION >= "Q") {
         $arFields["APPROVED"] = "Y";
     } else {
         $arFields["APPROVED"] = $arParams["MODERATION"] == "Y" ? "N" : "Y";
     }
     // Добавим новую тему
     if ($TOPIC_ID <= 0) {
         $arTopicFields = array("TITLE" => $subject, "FORUM_ID" => $FORUM_ID, "USER_START_ID" => $AUTHOR_USER_ID, "OWNER_ID" => $AUTHOR_USER_ID, "SOCNET_GROUP_ID" => $SOCNET_GROUP_ID);
         $arTopicFields["XML_ID"] = $arMessageFields["MSG_ID"];
         $arTopicFields["APPROVED"] = $arFields['APPROVED'];
         $arTopicFields["USER_START_NAME"] = $AUTHOR_NAME;
         $arTopicFields["LAST_POSTER_NAME"] = $AUTHOR_NAME;
         $TOPIC_ID = CForumTopic::Add($arTopicFields);
         if (IntVal($TOPIC_ID) <= 0) {
             CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR4")));
             return false;
         }
         $arFields["NEW_TOPIC"] = "Y";
     }
     // Добавим сообщение
     $arFields["POST_MESSAGE"] = $body;
     // Аттаченные файлы
     $arFILES = array();
     $rsAttach = CMailAttachment::GetList(array(), array("MESSAGE_ID" => $arMessageFields["ID"]));
     while ($arAttach = $rsAttach->Fetch()) {
         $filename = CTempFile::GetFileName(md5(uniqid("")) . ".tmp");
         CheckDirPath($filename);
         if (file_put_contents($filename, $arAttach["FILE_DATA"]) !== false) {
             $arFile = array("name" => $arAttach["FILE_NAME"], "type" => $arAttach["CONTENT_TYPE"], "size" => @filesize($filename), "tmp_name" => $filename, "MODULE_ID" => "forum");
             $arFilter = array("FORUM_ID" => $FORUM_ID);
             $arFiles = array($arFile);
             if (CForumFiles::CheckFields($arFiles, $arFilter)) {
                 $arFILES[] = $arFiles[0];
             } else {
                 $oError = $GLOBALS["APPLICATION"]->GetException();
                 CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR6") . " (" . $arAttach["FILE_NAME"] . "): " . ($oError && $oError->GetString() ? $oError->GetString() : "")));
             }
         }
     }
     if (count($arFILES) > 0) {
         $arFields["FILES"] = $arFILES;
     }
     $arFields["AUTHOR_NAME"] = $AUTHOR_NAME;
     $arFields["AUTHOR_ID"] = $AUTHOR_USER_ID;
     $arFields["FORUM_ID"] = $FORUM_ID;
     $arFields["TOPIC_ID"] = $TOPIC_ID;
     $arFields["XML_ID"] = $arMessageFields["MSG_ID"];
     $arFields["SOURCE_ID"] = "EMAIL";
     $arRes = array();
     if (!empty($arMessageFields["FIELD_FROM"])) {
         $arRes[] = "From: " . $arMessageFields["FIELD_FROM"];
     }
     if (!empty($arMessageFields["FIELD_TO"])) {
         $arRes[] = "To: " . $arMessageFields["FIELD_TO"];
     }
     if (!empty($arMessageFields["FIELD_CC"])) {
         $arRes[] = "Cc: " . $arMessageFields["FIELD_CC"];
     }
     if (!empty($arMessageFields["FIELD_BCC"])) {
         $arRes[] = "Bcc: " . $arMessageFields["FIELD_BCC"];
     }
     $arRes[] = "Subject: " . $arMessageFields["SUBJECT"];
     $arRes[] = "Date: " . $arMessageFields["FIELD_DATE"];
     $arFields["MAIL_HEADER"] = implode("\r\n", $arRes);
     preg_match_all('#Received:\\s+from\\s+(.*)by.*#i', $arMessageFields["HEADER"], $regs);
     if (is_array($regs) && is_array($regs[1])) {
         $arFields["AUTHOR_IP"] = $arFields["AUTHOR_REAL_IP"] = '<email: ' . $regs[1][count($regs[1]) - 1] . '>';
     } else {
         $arFields["AUTHOR_IP"] = $arFields["AUTHOR_REAL_IP"] = '<email: no address>';
     }
     /*
     
     $AUTHOR_IP = ForumGetRealIP();
     $AUTHOR_IP_tmp = $AUTHOR_IP;
     $AUTHOR_REAL_IP = $_SERVER['REMOTE_ADDR'];
     if (COption::GetOptionString("forum", "FORUM_GETHOSTBYADDR", "N") == "Y")
     {
     	$AUTHOR_IP = @gethostbyaddr($AUTHOR_IP);
     
     	if ($AUTHOR_IP_tmp==$AUTHOR_REAL_IP)
     		$AUTHOR_REAL_IP = $AUTHOR_IP;
     	else
     		$AUTHOR_REAL_IP = @gethostbyaddr($AUTHOR_REAL_IP);
     }
     
     $arFields["AUTHOR_IP"] = ($AUTHOR_IP!==False) ? $AUTHOR_IP : "<no address>";
     $arFields["AUTHOR_REAL_IP"] = ($AUTHOR_REAL_IP!==False) ? $AUTHOR_REAL_IP : "<no address>";
     */
     $strErrorMessage = '';
     $MESSAGE_ID = CForumMessage::Add($arFields, false);
     if (intVal($MESSAGE_ID) <= 0) {
         $str = $GLOBALS['APPLICATION']->GetException();
         if ($str && $str->GetString()) {
             $strErrorMessage .= "[" . $str->GetString() . "]";
         }
         if ($arFields["NEW_TOPIC"] == 'Y') {
             CForumTopic::Delete($TOPIC_ID);
         }
         CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_ERROR", "MESSAGE" => GetMessage("FORUM_MAIL_ERROR5") . " " . $strErrorMessage));
     }
     if ($MESSAGE_ID > 0) {
         CMailLog::AddMessage(array("MAILBOX_ID" => $arMessageFields["MAILBOX_ID"], "MESSAGE_ID" => $arMessageFields["ID"], "FILTER_ID" => $arParams["MAIL_FILTER_ID"], "LOG_TYPE" => "FILTER_COMPLETE", "MESSAGE" => GetMessage("FORUM_MAIL_OK") . " " . $MESSAGE_ID . " (TID#" . $TOPIC_ID . ")"));
         CForumMessage::SendMailMessage($MESSAGE_ID, array(), false, "NEW_FORUM_MESSAGE");
         $dbSite = CSite::GetById($arMessageFields["LID"]);
         if ($arSite = $dbSite->Fetch()) {
             $lang = $arSite['LANGUAGE_ID'];
         } else {
             $lang = $LANGUAGE_ID;
         }
         $parser = new forumTextParser();
         $arForum = CForumNew::GetByID($FORUM_ID);
         $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "LIST" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => "N", "TABLE" => "N", "ALIGN" => "N");
         if ($arFields["NEW_TOPIC"] == "Y") {
             $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_GROUP, "ENTITY_ID" => $SOCNET_GROUP_ID, "EVENT_ID" => "forum", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $AUTHOR_NAME, CForumEmail::GetLangMessage("FORUM_MAIL_SOCNET_TITLE_TOPIC", $lang)), "TITLE" => $subject, "MESSAGE" => $parser->convert($body, $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($body), "URL" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("UID" => $AUTHOR_USER_ID, "FID" => $FORUM_ID, "TID" => $TOPIC_ID, "MID" => $MESSAGE_ID)), "PARAMS" => serialize(array("PATH_TO_MESSAGE" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("TID" => $TOPIC_ID)))), "MODULE_ID" => false, "CALLBACK_FUNC" => false, "SOURCE_ID" => $MESSAGE_ID, "RATING_TYPE_ID" => "FORUM_TOPIC", "RATING_ENTITY_ID" => intval($TOPIC_ID));
             if (intVal($AUTHOR_USER_ID) > 0) {
                 $arFieldsForSocnet["USER_ID"] = $AUTHOR_USER_ID;
             }
             $logID = CSocNetLog::Add($arFieldsForSocnet, false);
             if (intval($logID) > 0) {
                 CSocNetLog::Update($logID, array("TMP_ID" => $logID));
                 CSocNetLogRights::SetForSonet($logID, $arFieldsForSocnet["ENTITY_TYPE"], $arFieldsForSocnet["ENTITY_ID"], "forum", "view", true);
                 CSocNetLog::SendEvent($logID, "SONET_NEW_EVENT", $logID);
             }
         } else {
             $dbForumMessage = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID));
             if ($arForumMessage = $dbForumMessage->Fetch()) {
                 $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "forum", "SOURCE_ID" => $arForumMessage["ID"]), false, false, array("ID", "TMP_ID"));
                 if ($arRes = $dbRes->Fetch()) {
                     $log_id = $arRes["TMP_ID"];
                 } else {
                     $dbFirstMessage = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $arForumMessage["TOPIC_ID"]), false, 1);
                     if ($arFirstMessage = $dbFirstMessage->Fetch()) {
                         $arTopic = CForumTopic::GetByID($arFirstMessage["TOPIC_ID"]);
                         $sFirstMessageText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arFirstMessage["POST_MESSAGE_FILTER"] : $arFirstMessage["POST_MESSAGE"];
                         $sFirstMessageURL = CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("UID" => $arFirstMessage["AUTHOR_ID"], "FID" => $arFirstMessage["FORUM_ID"], "TID" => $arFirstMessage["TOPIC_ID"], "MID" => $arFirstMessage["ID"]));
                         $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_GROUP, "ENTITY_ID" => $SOCNET_GROUP_ID, "EVENT_ID" => "forum", "LOG_DATE" => $arFirstMessage["POST_DATE"], "LOG_UPDATE" => $arFirstMessage["POST_DATE"], "TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $arFirstMessage["AUTHOR_NAME"], GetMessage("SONET_FORUM_LOG_TOPIC_TEMPLATE")), "TITLE" => $arTopic["TITLE"], "MESSAGE" => $parser->convert($sFirstMessageText, $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($sFirstMessageText), "URL" => $sFirstMessageURL, "PARAMS" => serialize(array("PATH_TO_MESSAGE" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("TID" => $arFirstMessage["TOPIC_ID"])))), "MODULE_ID" => false, "CALLBACK_FUNC" => false, "SOURCE_ID" => $arFirstMessage["ID"], "RATING_TYPE_ID" => "FORUM_TOPIC", "RATING_ENTITY_ID" => intval($arFirstMessage["TOPIC_ID"]));
                         if (intVal($arFirstMessage["AUTHOR_ID"]) > 0) {
                             $arFieldsForSocnet["USER_ID"] = $arFirstMessage["AUTHOR_ID"];
                         }
                         $log_id = CSocNetLog::Add($arFieldsForSocnet, false);
                         if (intval($log_id) > 0) {
                             CSocNetLog::Update($log_id, array("TMP_ID" => $log_id));
                             CSocNetLogRights::SetForSonet($log_id, $arFieldsForSocnet["ENTITY_TYPE"], $arFieldsForSocnet["ENTITY_ID"], "forum", "view", true);
                         }
                     }
                 }
                 if (intval($log_id) > 0) {
                     $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_GROUP, "ENTITY_ID" => $SOCNET_GROUP_ID, "EVENT_ID" => "forum", "LOG_ID" => $log_id, "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $parser->convert($body, $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($body), "URL" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("UID" => $AUTHOR_USER_ID, "FID" => $FORUM_ID, "TID" => $TOPIC_ID, "MID" => $MESSAGE_ID)), "MODULE_ID" => false, "SOURCE_ID" => $MESSAGE_ID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => intval($MESSAGE_ID));
                     if (intVal($AUTHOR_USER_ID) > 0) {
                         $arFieldsForSocnet["USER_ID"] = $AUTHOR_USER_ID;
                     }
                     CSocNetLogComments::Add($arFieldsForSocnet);
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: comment.php プロジェクト: rasuldev/torino
 /**
  * Adds new comment
  * @param array $params
  * @return array|false
  */
 public function add(array $params)
 {
     $params = array("POST_MESSAGE" => trim($params["POST_MESSAGE"]), "AUTHOR_ID" => $this->getUser()->getId(), "AUTHOR_NAME" => trim($params["AUTHOR_NAME"]), "AUTHOR_EMAIL" => trim($params["AUTHOR_EMAIL"]), "USE_SMILES" => $params["USE_SMILES"], "FILES" => $params["FILES"]);
     if ($this->prepareFields($params, $this->errorCollection)) {
         $AUTHOR_IP = $AUTHOR_IP_tmp = \ForumGetRealIP();
         $AUTHOR_REAL_IP = $_SERVER['REMOTE_ADDR'];
         if (\COption::GetOptionString("forum", "FORUM_GETHOSTBYADDR", "N") == "Y") {
             $AUTHOR_IP = @gethostbyaddr($AUTHOR_IP);
             $AUTHOR_REAL_IP = $AUTHOR_IP_tmp == $AUTHOR_REAL_IP ? $AUTHOR_IP : @gethostbyaddr($AUTHOR_REAL_IP);
         }
         $params["AUTHOR_IP"] = $AUTHOR_IP !== False ? $AUTHOR_IP : "<no address>";
         $params["AUTHOR_REAL_IP"] = $AUTHOR_REAL_IP !== False ? $AUTHOR_REAL_IP : "<no address>";
         $params["GUEST_ID"] = $_SESSION["SESS_GUEST_ID"];
         if (!(($mid = \CForumMessage::Add($params, false)) > 0)) {
             $text = Loc::getMessage("ADDMESS_ERROR_ADD_MESSAGE");
             if (($str = $this->getApplication()->getException()) && $str) {
                 $text = $str->getString();
             }
             $this->errorCollection->addOne(new Error($text, self::ERROR_PARAMS_MESSAGE));
         } else {
             $this->updateStatisticModule($mid);
             \CForumMessage::SendMailMessage($mid, array(), false, "NEW_FORUM_MESSAGE");
             $this->setComment($mid);
             $event = new Event("forum", "OnAfterCommentAdd", array($this->entity->getType(), $this->entity->getId(), array("TOPIC_ID" => $this->topic["ID"], "MESSAGE_ID" => $mid, "PARAMS" => $params, "MESSAGE" => $this->getComment())));
             $event->send();
             return $this->getComment();
         }
     }
     return false;
 }
コード例 #4
0
ファイル: include.php プロジェクト: mrdeadmouse/u136006
 function AddComment_News($arFields)
 {
     if (!CModule::IncludeModule("forum")) {
         return false;
     }
     if (!CModule::IncludeModule("iblock")) {
         return false;
     }
     if (!CModule::IncludeModule("socialnetwork")) {
         return false;
     }
     $dbResult = CSocNetLog::GetList(array("ID" => "DESC"), array("TMP_ID" => $arFields["LOG_ID"]), false, false, array("ID", "SOURCE_ID", "PARAMS"));
     $bFound = false;
     if ($arLog = $dbResult->Fetch()) {
         if (intval($arLog["SOURCE_ID"]) > 0) {
             $arFilter = array("ID" => $arLog["SOURCE_ID"]);
             $arSelectedFields = array("IBLOCK_ID", "ID", "CREATED_BY", "NAME", "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;
                 $val = COption::GetOptionString("intranet", "sonet_log_news_iblock_forum");
                 if (strlen($val) > 0) {
                     $arIBlockForum = unserialize($val);
                 } else {
                     $arIBlockForum = array();
                 }
                 if (array_key_exists($arElement["IBLOCK_ID"], $arIBlockForum)) {
                     $FORUM_ID = $arIBlockForum[$arElement["IBLOCK_ID"]];
                 }
                 if (intval($FORUM_ID) > 0) {
                     CSocNetLogTools::AddComment_Review_CheckIBlock($arElement);
                     $dbMessage = CForumMessage::GetList(array(), array("PARAM2" => $arElement["ID"]));
                     if (!($arMessage = $dbMessage->Fetch())) {
                         // Add Topic
                         $TOPIC_ID = CSocNetLogTools::AddComment_Review_CreateRoot($arElement, $FORUM_ID);
                         $bNewTopic = true;
                     } else {
                         $TOPIC_ID = $arMessage["TOPIC_ID"];
                     }
                     if (intval($TOPIC_ID) > 0) {
                         // Add comment
                         $messageID = false;
                         $bError = false;
                         if (CForumMessage::CanUserAddMessage($TOPIC_ID, $GLOBALS["USER"]->GetUserGroupArray(), $GLOBALS["USER"]->GetID(), false)) {
                             $bSHOW_NAME = true;
                             $res = CForumUser::GetByUSER_ID($GLOBALS["USER"]->GetID());
                             if ($res) {
                                 $bSHOW_NAME = $res["SHOW_NAME"] == "Y";
                             }
                             if ($bSHOW_NAME) {
                                 $AUTHOR_NAME = $GLOBALS["USER"]->GetFullName();
                             }
                             if (strlen(Trim($AUTHOR_NAME)) <= 0) {
                                 $AUTHOR_NAME = $GLOBALS["USER"]->GetLogin();
                             }
                             if (strlen($AUTHOR_NAME) <= 0) {
                                 $bError = true;
                             }
                         }
                         if (!$bError) {
                             $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "APPROVED" => "Y", "PARAM2" => $arElement["ID"], "AUTHOR_NAME" => $AUTHOR_NAME, "AUTHOR_ID" => IntVal($GLOBALS["USER"]->GetParam("USER_ID")), "FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_ID, "NEW_TOPIC" => "N", "GUEST_ID" => $_SESSION["SESS_GUEST_ID"], "ADD_TO_LOG" => "N");
                             $AUTHOR_IP = ForumGetRealIP();
                             $AUTHOR_IP_tmp = $AUTHOR_IP;
                             $AUTHOR_REAL_IP = $_SERVER['REMOTE_ADDR'];
                             if (COption::GetOptionString("forum", "FORUM_GETHOSTBYADDR", "N") == "Y") {
                                 $AUTHOR_IP = @gethostbyaddr($AUTHOR_IP);
                                 if ($AUTHOR_IP_tmp == $AUTHOR_REAL_IP) {
                                     $AUTHOR_REAL_IP = $AUTHOR_IP;
                                 } else {
                                     $AUTHOR_REAL_IP = @gethostbyaddr($AUTHOR_REAL_IP);
                                 }
                             }
                             $arFieldsMessage["AUTHOR_IP"] = $AUTHOR_IP !== False ? $AUTHOR_IP : "<no address>";
                             $arFieldsMessage["AUTHOR_REAL_IP"] = $AUTHOR_REAL_IP !== False ? $AUTHOR_REAL_IP : "<no address>";
                             $messageID = CForumMessage::Add($arFieldsMessage, false);
                             if (intVal($messageID) <= 0) {
                                 $bError = true;
                             } else {
                                 if (CModule::IncludeModule("statistic")) {
                                     $arForum = CForumNew::GetByID($FORUM_ID);
                                     $F_EVENT1 = $arForum["EVENT1"];
                                     $F_EVENT2 = $arForum["EVENT2"];
                                     $F_EVENT3 = $arForum["EVENT3"];
                                     if (strlen($F_EVENT3) <= 0) {
                                         $arForumSite_tmp = CForumNew::GetSites($FORUM_ID);
                                         $F_EVENT3 = CForumNew::PreparePath2Message($arForumSite_tmp[SITE_ID], array("FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_ID, "MESSAGE_ID" => $messageID));
                                     }
                                     CStatistic::Set_Event($F_EVENT1, $F_EVENT2, $F_EVENT3);
                                 }
                                 CForumMessage::SendMailMessage($messageID, array(), false, "NEW_FORUM_MESSAGE");
                                 CSocNetLogTools::AddComment_Review_UpdateElement($arElement, $TOPIC_ID, $bNewTopic);
                             }
                         }
                     }
                 }
             }
         }
     }
     if (intval($messageID) <= 0) {
         $strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
     }
     return array("SOURCE_ID" => $messageID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $strError, "NOTES" => "");
 }
コード例 #5
0
ファイル: livefeed.php プロジェクト: DarneoStudio/bitrix
 public static function AddCrmActivityComment($arFields)
 {
     if (!CModule::IncludeModule("forum")) {
         return false;
     }
     $ufFileID = array();
     $ufDocID = array();
     $messageID = false;
     $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array('ID', 'ENTITY_ID', 'SOURCE_ID', 'SITE_ID', 'TITLE', 'PARAMS'));
     if ($arLog = $dbResult->Fetch()) {
         $dbCrmActivity = CCrmActivity::GetList(array(), array('ID' => $arLog['ENTITY_ID'], 'CHECK_PERMISSIONS' => 'N'));
         if ($arCrmActivity = $dbCrmActivity->Fetch()) {
             if ($arCrmActivity['TYPE_ID'] == CCrmActivityType::Task && CModule::IncludeModule('tasks')) {
                 $userID = $GLOBALS["USER"]->GetID();
                 $dbTask = CTasks::GetByID($arCrmActivity["ASSOCIATED_ENTITY_ID"], false);
                 if ($arTaskFields = $dbTask->Fetch()) {
                     if (!($userName = trim($GLOBALS["USER"]->GetFormattedName(false)))) {
                         $userName = $GLOBALS["USER"]->GetLogin();
                     }
                     $FORUM_ID = CTasksTools::GetForumIdForIntranet();
                     if (!$arTaskFields["FORUM_TOPIC_ID"]) {
                         $arTopicFields = array("TITLE" => $arTaskFields["TITLE"], "USER_START_ID" => $arFields["USER_ID"], "STATE" => "Y", "FORUM_ID" => $FORUM_ID, "USER_START_NAME" => $userName, "START_DATE" => ConvertTimeStamp(time(), "FULL"), "POSTS" => 0, "VIEWS" => 0, "APPROVED" => "Y", "LAST_POSTER_NAME" => $userName, "LAST_POST_DATE" => ConvertTimeStamp(time(), "FULL"), "LAST_MESSAGE_ID" => 0, "XML_ID" => 'TASK_' . $arTaskFields['ID']);
                         $TOPIC_ID = CForumTopic::Add($arTopicFields);
                         if ($TOPIC_ID) {
                             $arFieldsFirstMessage = array("POST_MESSAGE" => $arTopicFields["XML_ID"], "AUTHOR_ID" => $arTopicFields["USER_START_ID"], "AUTHOR_NAME" => $arTopicFields["USER_START_NAME"], "FORUM_ID" => $arTopicFields["FORUM_ID"], "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => 'TK', "PARAM2" => $arTaskFields['ID'], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E');
                             CForumMessage::Add($arFieldsFirstMessage, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
                             $oTask = new CTasks();
                             $oTask->Update($arTaskFields["ID"], array("FORUM_TOPIC_ID" => $TOPIC_ID));
                         }
                     } else {
                         $TOPIC_ID = $arTaskFields["FORUM_TOPIC_ID"];
                     }
                     if ($TOPIC_ID) {
                         $arFieldsP = array("AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $userName, "POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_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)) {
                                 $arFieldsP["FILES"] = array();
                                 foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) {
                                     $arFieldsP["FILES"][] = array("FILE_ID" => $file_id);
                                 }
                             }
                         }
                         $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $arFieldsP);
                         $messageID = CForumMessage::Add($arFieldsP);
                         // get UF DOC value and FILE_ID there
                         if ($messageID > 0) {
                             $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);
                         }
                     }
                 }
             } else {
                 return array("NO_SOURCE" => "Y");
             }
         } else {
             $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
         }
     } else {
         $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
     }
     return array("SOURCE_ID" => $messageID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $sError, "NOTES" => $sNote, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID));
 }
コード例 #6
0
ファイル: livefeed.php プロジェクト: DarneoStudio/bitrix
 public static function addCommentLists($fields)
 {
     if (!CModule::IncludeModule('forum') || !CModule::IncludeModule('bizproc')) {
         return false;
     }
     $ufFileId = array();
     $ufDocId = array();
     $fieldsMessage = array();
     $messageId = array();
     $error = array();
     $note = array();
     $sonetLogQuery = CSocNetLog::GetList(array(), array('ID' => $fields['LOG_ID']), false, false, array('ID', 'SOURCE_ID', 'SITE_ID', 'MESSAGE', 'USER_ID'));
     if ($sonetLog = $sonetLogQuery->fetch()) {
         $users = CBPTaskService::getWorkflowParticipants($sonetLog['MESSAGE'], CBPTaskUserStatus::Waiting);
         if (preg_match_all("/(?<=\\[USER=)(?P<id>[0-9]+)(?=\\])/", $fields['TEXT_MESSAGE'], $matches)) {
             $users = array_unique(array_merge($users, $matches['id']));
         }
         $users[] = $sonetLog['USER_ID'];
         self::setSocnetFollow($users, $sonetLog['ID'], 'Y', false, true);
         $forumId = CBPHelper::getForumId();
         if ($forumId) {
             $topicQuery = CForumTopic::GetList(array(), array('FORUM_ID' => $forumId, 'XML_ID' => 'WF_' . $sonetLog['MESSAGE']));
             if ($topicQuery && ($topic = $topicQuery->fetch())) {
                 $topicId = $topic['ID'];
             } else {
                 $arTopic = array('AUTHOR_ID' => 0, 'TITLE' => 'WF_' . $sonetLog['MESSAGE'], 'TAGS' => '', 'MESSAGE' => 'WF_' . $sonetLog['MESSAGE'], 'XML_ID' => 'WF_' . $sonetLog['MESSAGE']);
                 $arUserStart = array("ID" => $arTopic["AUTHOR_ID"], "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]);
                 $GLOBALS["DB"]->StartTransaction();
                 $arTopicFields = array("TITLE" => $arTopic["TITLE"], "TAGS" => $arTopic["TAGS"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "XML_ID" => $arTopic["XML_ID"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => 'Q', "PERMISSION" => 'Y');
                 $topicId = CForumTopic::Add($arTopicFields);
                 if (intval($topicId) > 0) {
                     $arTopic['MESSAGE'] = strip_tags($arTopic['MESSAGE']);
                     $arFields = array("POST_MESSAGE" => $arTopic['MESSAGE'], "AUTHOR_ID" => $arUserStart["ID"], "AUTHOR_NAME" => $arUserStart["NAME"], "FORUM_ID" => $forumId, "TOPIC_ID" => $topicId, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "WF", "PARAM2" => 0, "PERMISSION_EXTERNAL" => 'Q', "PERMISSION" => 'Y');
                     $startMessageId = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
                     if (intVal($startMessageId) <= 0) {
                         CForumTopic::Delete($topicId);
                         $topicId = 0;
                     }
                 }
                 if (intval($topicId) <= 0) {
                     $GLOBALS["DB"]->Rollback();
                 } else {
                     $GLOBALS["DB"]->Commit();
                 }
             }
             if ($topicId) {
                 $fieldsMessage = array('POST_MESSAGE' => $fields['TEXT_MESSAGE'], 'USE_SMILES' => 'Y', 'PERMISSION_EXTERNAL' => 'Q', 'PERMISSION' => 'Y', 'APPROVED' => 'Y');
                 $tmp = false;
                 $GLOBALS['USER_FIELD_MANAGER']->editFormAddFields('SONET_COMMENT', $tmp);
                 if (is_array($tmp)) {
                     if (array_key_exists('UF_SONET_COM_DOC', $tmp)) {
                         $GLOBALS['UF_FORUM_MESSAGE_DOC'] = $tmp['UF_SONET_COM_DOC'];
                     } elseif (array_key_exists('UF_SONET_COM_FILE', $tmp)) {
                         $fieldsMessage['FILES'] = array();
                         foreach ($tmp['UF_SONET_COM_FILE'] as $fileId) {
                             $fieldsMessage['FILES'][] = array('FILE_ID' => $fileId);
                         }
                     }
                     if (array_key_exists("UF_SONET_COM_URL_PRV", $tmp)) {
                         $GLOBALS["UF_FORUM_MES_URL_PRV"] = $tmp["UF_SONET_COM_URL_PRV"];
                     }
                 }
                 $messageId = ForumAddMessage("REPLY", $forumId, $topicId, 0, $fieldsMessage, $error, $note);
                 if ($messageId > 0) {
                     $addedMessageFilesQuery = CForumFiles::getList(array('ID' => 'ASC'), array('MESSAGE_ID' => $messageId));
                     while ($addedMessageFiles = $addedMessageFilesQuery->fetch()) {
                         $ufFileId[] = $addedMessageFiles['FILE_ID'];
                     }
                     $ufDocId = $GLOBALS['USER_FIELD_MANAGER']->getUserFieldValue('FORUM_MESSAGE', 'UF_FORUM_MESSAGE_DOC', $messageId, LANGUAGE_ID);
                     $ufUrlPreview = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MES_URL_PRV", $messageID, LANGUAGE_ID);
                 }
             }
         }
     }
     if (!$messageId) {
         $error = Loc::getMessage('LISTS_LF_ADD_COMMENT_SOURCE_ERROR');
     }
     return array('SOURCE_ID' => $messageId, 'MESSAGE' => $fieldsMessage ? $fieldsMessage['POST_MESSAGE'] : false, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => $messageId, 'ERROR' => $error, 'NOTES' => $note, 'UF' => array('FILE' => $ufFileId, 'DOC' => $ufDocId, 'URL_PREVIEW' => $ufUrlPreview));
 }
コード例 #7
0
         if (IntVal($TID1) <= 0) {
             $strErrorMessage .= GetMessage("ADDMESS_ERROR_ADD_TOPIC") . ". \n";
         }
     }
     if (strlen($strErrorMessage) <= 0) {
         $AUTHOR_IP = ForumGetRealIP();
         $AUTHOR_IP_tmp = $AUTHOR_IP;
         $AUTHOR_REAL_IP = $_SERVER['REMOTE_ADDR'];
         $AUTHOR_IP = @gethostbyaddr($AUTHOR_IP);
         if ($AUTHOR_IP_tmp == $AUTHOR_REAL_IP) {
             $AUTHOR_REAL_IP = $AUTHOR_IP;
         } else {
             $AUTHOR_REAL_IP = @gethostbyaddr($AUTHOR_REAL_IP);
         }
         $arFields = array("POST_MESSAGE" => $strDescription, "AUTHOR_NAME" => $_POST["comment_author"], "AUTHOR_EMAIL" => $_POST["comment_email"], "FORUM_ID" => $INQUERY_FORUM_ID, "TOPIC_ID" => $TID1, "AUTHOR_IP" => $AUTHOR_IP !== False ? $AUTHOR_IP : "<no address>", "AUTHOR_REAL_IP" => $AUTHOR_REAL_IP !== False ? $AUTHOR_REAL_IP : "<no address>", "NEW_TOPIC" => "Y", "GUEST_ID" => $_SESSION["SESS_GUEST_ID"]);
         $MID1 = CForumMessage::Add($arFields);
         if (IntVal($MID1) <= 0) {
             $strErrorMessage .= GetMessage("ADDMESS_ERROR_ADD_MESSAGE") . ". \n";
             CForumTopic::Delete($TID1);
             $TID1 = 0;
         }
     }
     if (strlen($strErrorMessage) <= 0) {
         $DB->Commit();
         $strOKMessage .= GetMessage("COMM_COMMENT_OK") . ". ";
     } else {
         if ($sTransStarted) {
             $DB->Rollback();
         }
     }
 }
コード例 #8
0
ファイル: tasks.php プロジェクト: DarneoStudio/bitrix
 function AddForumLog($taskId, $taskName, $arFields, &$arError)
 {
     $arError = array();
     $iblockId = COption::GetOptionInt("intranet", "iblock_tasks", 0);
     if ($iblockId <= 0) {
         return;
     }
     $taskId = intval($taskId);
     if ($taskId <= 0) {
         return;
     }
     $db = CIBlockElement::GetProperty($iblockId, $taskId, "", "", array("CODE" => "FORUM_TOPIC_ID"));
     $ar = $db->Fetch();
     $forumTopicId = intval($ar["VALUE"]);
     if ($forumTopicId <= 0) {
         $arFields = array("TITLE" => $taskName, "FORUM_ID" => $arFields["FORUM_ID"], "USER_START_ID" => $arFields["USER_ID"], "USER_START_NAME" => $arFields["USER_NAME"], "LAST_POSTER_NAME" => $arFields["USER_NAME"], "APPROVED" => "Y");
         $forumTopicId = CForumTopic::Add($arFields);
         CIBlockElement::SetPropertyValues($taskId, $iblockId, $forumTopicId, "FORUM_TOPIC_ID");
     }
     $arFields = array("POST_MESSAGE" => $arFields["POST_MESSAGE"], "AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $arFields["USER_NAME"], "FORUM_ID" => $arFields["FORUM_ID"], "TOPIC_ID" => $forumTopicId, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "IB", "PARAM2" => $taskId);
     CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
 }
コード例 #9
0
ファイル: index.php プロジェクト: webgksupport/alpina
if (in_array(GetMessage("F_FORUM_3_NAME"), $arForums)) {
    foreach ($arForums as $key => $val) {
        if ($val == GetMessage("F_FORUM_3_NAME")) {
            $arReplaceForums[] = $key;
        }
    }
} else {
    $arFields = array("NAME" => GetMessage("F_FORUM_3_NAME"), "DESCRIPTION" => GetMessage("F_FORUM_3_DECRIPTION"), "SORT" => 200, "ACTIVE" => "Y", "ALLOW_HTML" => "N", "ALLOW_ANCHOR" => "Y", "ALLOW_BIU" => "Y", "ALLOW_IMG" => "Y", "ALLOW_LIST" => "Y", "ALLOW_QUOTE" => "Y", "ALLOW_CODE" => "Y", "ALLOW_FONT" => "Y", "ALLOW_SMILES" => "Y", "ALLOW_UPLOAD" => "N", "ALLOW_NL2BR" => "N", "MODERATION" => "N", "ALLOW_MOVE_TOPIC" => "Y", "ORDER_BY" => "P", "ORDER_DIRECTION" => "DESC", "LID" => LANGUAGE_ID, "PATH2FORUM_MESSAGE" => "", "ALLOW_UPLOAD_EXT" => "", "FORUM_GROUP_ID" => $arGroup["PARTNER"], "ASK_GUEST_EMAIL" => "N", "USE_CAPTCHA" => "Y", "SITES" => array($SITE_ID => "/communication/forum/messages/forum#FID#/message#MID#/#TITLE_SEO#"), "EVENT1" => "forum", "EVENT2" => "message", "EVENT3" => "", "GROUP_ID" => array("2" => "M", "4" => "A", "5" => "A", "11" => "A", "15" => "A", "16" => "A", "17" => "A", "18" => "A", "19" => "Q", "20" => "A"));
    $FID = CForumNew::Add($arFields);
    if ($FID > 0) {
        $arReplaceForums[] = $FID;
        $arFields = array("FORUM_ID" => $FID, "TITLE" => GetMessage("F_FORUM_3_TOPIC_1_TITLE"), "DESCRIPTION" => GetMessage("F_FORUM_3_TOPIC_1_DESCRIPTION"), "ICON_ID" => 0, "TAGS" => GetMessage("F_FORUM_3_TOPIC_1_TAGS"), "USER_START_ID" => 1, "USER_START_NAME" => GetMessage("F_FORUM_3_TOPIC_1_AUTHOR"), "LAST_POSTER_NAME" => GetMessage("F_FORUM_3_TOPIC_1_AUTHOR"), "APPROVED" => "Y");
        $TID = intVal(CForumTopic::Add($arFields));
        if ($TID > 0) {
            $arFields = array("POST_MESSAGE" => GetMessage("F_FORUM_3_TOPIC_1_MESSAGE_1_POSTMESS"), "USE_SMILES" => "Y", "APPROVED" => "Y", "AUTHOR_NAME" => GetMessage("F_FORUM_3_TOPIC_1_AUTHOR"), "AUTHOR_EMAIL" => "", "AUTHOR_ID" => "1", "FORUM_ID" => $FID, "TOPIC_ID" => $TID, "AUTHOR_IP" => "SWAMP", "AUTHOR_REAL_IP" => "SWAMP", "NEW_TOPIC" => "Y", "GUEST_ID" => 58);
            $MID = CForumMessage::Add($arFields, false);
            if (IntVal($MID) <= 0) {
                CForumTopic::Delete($TID);
            }
        }
    }
}
//Copy public files with "on the fly" translation
$source = "/public/forum/";
$target = "/communication/forum/";
$source_base = dirname(__FILE__);
$source_abs = $source_base . $source;
$source_abs = str_replace(array("\\", "//"), "/", $source_base . $source . "/");
$target_abs = $_SERVER['DOCUMENT_ROOT'] . $target;
if (!empty($arReplaceForums)) {
    $tmp = array();
コード例 #10
0
 public static function AddCommentMessage($arFields, $FORUM_ID, $arLog)
 {
     global $USER, $DB;
     $dbRes = CTimeManEntry::GetList(array(), array('ID' => $arLog['SOURCE_ID']));
     $arEntry = $dbRes->Fetch();
     if ($arEntry && CModule::IncludeModule("forum")) {
         $ufFileID = array();
         $ufDocID = array();
         if (!($userName = trim($USER->GetFormattedName(false)))) {
             $userName = $USER->GetLogin();
         }
         if ($arEntry["FORUM_TOPIC_ID"] <= 0) {
             $t = ConvertTimeStamp(time(), "FULL");
             $arTopicFields = array("TITLE" => $arEntry["DATE_START"], "USER_START_ID" => $arFields["USER_ID"], "STATE" => "Y", "FORUM_ID" => $FORUM_ID, "USER_START_NAME" => $userName, "START_DATE" => $t, "POSTS" => 0, "VIEWS" => 0, "APPROVED" => "Y", "LAST_POSTER_NAME" => $userName, "LAST_POST_DATE" => $t, "LAST_MESSAGE_ID" => 0, "XML_ID" => "TIMEMAN_ENTRY_" . $arLog["SOURCE_ID"]);
             $TOPIC_ID = CForumTopic::Add($arTopicFields);
             if ($TOPIC_ID > 0) {
                 CTimeManEntry::Update($arLog['SOURCE_ID'], array("FORUM_TOPIC_ID" => $TOPIC_ID));
             }
         } else {
             $TOPIC_ID = $arEntry["FORUM_TOPIC_ID"];
         }
         if ($TOPIC_ID) {
             $arFieldsP = array("AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $userName, "POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "POST_DATE" => date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL")), time() - 1), "FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "PARAM2" => $arLog["SOURCE_ID"]);
             $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)) {
                     $arFieldsP["FILES"] = array();
                     foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) {
                         $arFieldsP["FILES"][] = array("FILE_ID" => $file_id);
                     }
                 }
             }
             $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $arFieldsP);
             $mess_id = CForumMessage::Add($arFieldsP);
             // get UF DOC value and FILE_ID there
             if ($mess_id > 0) {
                 $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $mess_id));
                 while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                     $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                 }
                 $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $mess_id, LANGUAGE_ID);
             }
             if (IsModuleInstalled("im")) {
                 CTimeManNotify::AddCommentToIM(array("USER_ID" => $arFieldsP["AUTHOR_ID"], "ENTRY_ID" => $arEntry["ID"], "LOG_ID" => $arLog["ID"], "MESSAGE" => $arFields["TEXT_MESSAGE"]));
             }
         }
         return array("SOURCE_ID" => $mess_id, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID));
     }
     return false;
 }
コード例 #11
0
ファイル: log_tools.php プロジェクト: Satariall/izurit
 function AddComment_Tasks($arFields)
 {
     global $DB;
     if (!CModule::IncludeModule("forum")) {
         return false;
     }
     if (!CModule::IncludeModule("tasks")) {
         return false;
     }
     $ufFileID = array();
     $ufDocID = array();
     $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "SOURCE_ID", "SITE_ID"));
     if ($arLog = $dbResult->Fetch()) {
         $rsTask = CTasks::GetById($arLog["SOURCE_ID"]);
         if ($arTask = $rsTask->Fetch()) {
             // read shared cross-site FORUM_ID
             $forumID = COption::GetOptionString("tasks", "task_forum_id", 0, $siteId = '');
             if ($forumID) {
                 if (!$arTask["FORUM_TOPIC_ID"]) {
                     $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]);
                     if ($arUserStart["ID"] > 0) {
                         $res = array();
                         $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["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($arTask["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"];
                     $DB->StartTransaction();
                     $arTopicFields = array("TITLE" => $arTask["TITLE"], "FORUM_ID" => $forumID, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E', "APPROVED" => "Y", 'XML_ID' => 'TASK_' . $arTask['ID']);
                     $TID = CForumTopic::Add($arTopicFields);
                     if (intVal($TID) > 0) {
                         $arFieldsFirstMessage = array("POST_MESSAGE" => $arTopicFields['XML_ID'], "AUTHOR_ID" => $arTopicFields["USER_START_ID"], "AUTHOR_NAME" => $arTopicFields["USER_START_NAME"], "FORUM_ID" => $arTopicFields["FORUM_ID"], "TOPIC_ID" => $TID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => 'TK', "PARAM2" => $arTask['ID'], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E');
                         CForumMessage::Add($arFieldsFirstMessage, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
                         $arTask["FORUM_TOPIC_ID"] = $TID;
                         $arTaskFields = array("FORUM_TOPIC_ID" => $TID);
                         $task = new CTasks();
                         $task->Update($arTask["ID"], $arTaskFields);
                     }
                     if (!$arTask["FORUM_TOPIC_ID"]) {
                         $DB->Rollback();
                     } else {
                         $DB->Commit();
                     }
                 } else {
                     // override forumId by fact forum, attached to the task
                     if ($arTopic = CForumTopic::getByID($arTask['FORUM_TOPIC_ID'])) {
                         $forumID = $arTopic['FORUM_ID'];
                     }
                 }
                 if ($forumID && $arTask["FORUM_TOPIC_ID"]) {
                     $userID = $GLOBALS["USER"]->GetID();
                     $arLogSites = array();
                     $rsLogSite = CSocNetLog::GetSite($arLog["ID"]);
                     while ($arLogSite = $rsLogSite->Fetch()) {
                         $arLogSites[] = $arLogSite["LID"];
                     }
                     $bCurrentUserIsAdmin = CSocNetUser::IsCurrentUserModuleAdmin($arLogSites);
                     if ($arFields["ENTITY_TYPE"] == SONET_ENTITY_GROUP) {
                         if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) {
                             $strPermission = "I";
                         }
                     } else {
                         if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) {
                             $strPermission = "I";
                         }
                     }
                     $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PERMISSION_EXTERNAL" => "Q", "PERMISSION" => $strPermission, "APPROVED" => "Y");
                     $MESSAGE_TYPE = 'REPLY';
                     $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($MESSAGE_TYPE, $forumID, $arTask["FORUM_TOPIC_ID"], 0, $arFieldsMessage, $sError, $sNote);
                     // get UF DOC value and FILE_ID there
                     if ($messageID > 0) {
                         $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);
                     }
                     if ($messageID && ($arMessage = CForumMessage::GetByID($messageID))) {
                         $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $userID, "CREATED_DATE" => $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $messageID);
                         $log = new CTaskLog();
                         $log->Add($arLogFields);
                         // notification to IM
                         $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask);
                         $arUnFollowers = array();
                         $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arRecipientsIDs, "CODE" => "L" . $arFields["LOG_ID"], "TYPE" => "N"), array("USER_ID"));
                         while ($arUnFollower = $rsUnFollower->Fetch()) {
                             $arUnFollowers[] = $arUnFollower["USER_ID"];
                         }
                         $arRecipientsIDs = array_diff($arRecipientsIDs, $arUnFollowers);
                         if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) {
                             $extranetSiteId = false;
                             if (CModule::IncludeModule('extranet') && method_exists('CExtranet', 'GetExtranetSiteID')) {
                                 $extranetSiteId = CExtranet::GetExtranetSiteID();
                             }
                             foreach ($arRecipientsIDs as $recipientUserID) {
                                 $arFilter = array("UF_DEPARTMENT" => false, "ID" => $recipientUserID);
                                 $rsUser = CUser::GetList($by = "last_name", $order = "asc", $arFilter, array("SELECT" => array("UF_DEPARTMENT")));
                                 $isExtranetUser = false;
                                 if ($arUser = $rsUser->Fetch()) {
                                     $isExtranetUser = true;
                                 }
                                 if ($isExtranetUser && $extranetSiteId !== false) {
                                     if ($arTask["GROUP_ID"]) {
                                         $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/extranet/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $extranetSiteId));
                                         $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate);
                                     } else {
                                         $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/extranet/contacts/personal/user/#user_id#/tasks/task/view/#task_id#/", $extranetSiteId);
                                     }
                                 } else {
                                     if ($arTask["GROUP_ID"]) {
                                         $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"]));
                                         $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate);
                                     } else {
                                         $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"]);
                                     }
                                 }
                                 $messageUrl = CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $recipientUserID, "task_id" => $arTask["ID"], "action" => "view"));
                                 if (strpos($messageUrl, "?") === false) {
                                     $messageUrl .= "?";
                                 } else {
                                     $messageUrl .= "&";
                                 }
                                 $messageUrl .= "MID=" . $messageID;
                                 $MESSAGE_SITE = preg_replace(array('|\\[\\/USER\\]|', '|\\[USER=\\d+\\]|', '|\\[DISK\\sFILE\\sID=[n]*\\d+\\]|', '|\\[DOCUMENT\\sID=\\d+\\]|'), '', $arFields['TEXT_MESSAGE']);
                                 if (strlen($MESSAGE_SITE) >= 100) {
                                     $dot = '...';
                                     $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99);
                                     if (substr($MESSAGE_SITE, -1) === '[') {
                                         $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 98);
                                     }
                                     if (($lastLinkPosition = strrpos($MESSAGE_SITE, '[u')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'http://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'https://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftp://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftps://')) !== false) {
                                         if (strpos($MESSAGE_SITE, ' ', $lastLinkPosition) === false) {
                                             $MESSAGE_SITE = substr($MESSAGE_SITE, 0, $lastLinkPosition);
                                         }
                                     }
                                     $MESSAGE_SITE .= $dot;
                                 }
                                 $rsUser = CUser::GetList($by = 'id', $order = 'asc', array('ID_EQUAL_EXACT' => (int) $userID), array('FIELDS' => array('PERSONAL_GENDER')));
                                 $strMsgAddComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD");
                                 $strMsgEditComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT");
                                 if ($arUser = $rsUser->fetch()) {
                                     switch ($arUser['PERSONAL_GENDER']) {
                                         case "F":
                                         case "M":
                                             $strMsgAddComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD" . '_' . $arUser['PERSONAL_GENDER']);
                                             $strMsgEditComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT" . '_' . $arUser['PERSONAL_GENDER']);
                                             break;
                                         default:
                                             break;
                                     }
                                 }
                                 $arMessageFields = array("TO_USER_ID" => $recipientUserID, "FROM_USER_ID" => $userID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array('[URL=' . tasksServerName() . $messageUrl . "#message" . $messageID . ']' . htmlspecialcharsbx($arTask["TITLE"]) . '[/URL]', '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array(htmlspecialcharsbx($arTask["TITLE"]), $MESSAGE_SITE . ' #BR# ' . tasksServerName() . $messageUrl . "#message" . $messageID . ' '), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment) . "#BR##BR#" . $arFields["TEXT_MESSAGE"], "NOTIFY_TAG" => "TASKS|COMMENT|" . intval($arTask["ID"]) . "|" . intval($recipientUserID));
                                 CIMNotify::Add($arMessageFields);
                             }
                         }
                         CSocNetLog::Update($arFields["LOG_ID"], array('PARAMS' => serialize(array('TYPE' => 'comment'))));
                         $arFilesIds = array_merge($ufFileID, is_array($ufDocID) ? $ufDocID : array());
                         CTaskComments::fireOnAfterCommentAddEvent($messageID, $arTask['ID'], $arFields["TEXT_MESSAGE"], $arFilesIds);
                     }
                 }
             }
         }
     }
     if (!$messageID) {
         $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
     }
     return array("SOURCE_ID" => $messageID, "MESSAGE" => $arFieldsMessage ? $arFieldsMessage["POST_MESSAGE"] : false, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $sError, "NOTES" => $sNote, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID), "URL" => $messageUrl);
 }
コード例 #12
0
ファイル: include.php プロジェクト: DarneoStudio/bitrix
function ForumAddMessage($MESSAGE_TYPE, $FID, $TID, $MID, $arFieldsG, &$strErrorMessage, &$strOKMessage, $iFileSize = false, $captcha_word = "", $captcha_sid = 0, $captcha_code = "")
{
    global $USER, $DB, $APPLICATION;
    $APPLICATION->ResetException();
    $aMsg = array();
    $bUpdateTopic = False;
    $bAddEditNote = $MESSAGE_TYPE == "EDIT";
    $arParams = array("PERMISSION" => false);
    $arUserGroups = $USER->GetUserGroupArray();
    // ************ External Permission *********************************
    if (!empty($arFieldsG["PERMISSION_EXTERNAL"])) {
        $arParams["PERMISSION"] = CForumNew::GetUserPermission($FID, $arUserGroups);
        $arParams["PERMISSION"] = $arParams["PERMISSION"] < "Q" ? $arFieldsG["PERMISSION_EXTERNAL"] : $arParams["PERMISSION"];
        unset($arFieldsG["PERMISSION_EXTERNAL"]);
    } elseif (!empty($arFieldsG["SONET_PERMS"])) {
        $arParams["PERMISSION"] = CForumNew::GetUserPermission($FID, $arUserGroups);
        if ($arParams["PERMISSION"] < "Q") {
            if ($arFieldsG["SONET_PERMS"]["bCanFull"] === true) {
                $arParams["PERMISSION"] = "Y";
            } elseif ($arFieldsG["SONET_PERMS"]["bCanNew"] === true) {
                $arParams["PERMISSION"] = "M";
            } elseif ($arFieldsG["SONET_PERMS"]["bCanWrite"] === true) {
                $arParams["PERMISSION"] = "I";
            } else {
                $arParams["PERMISSION"] = "A";
            }
        }
        unset($arFieldsG["SONET_PERMS"]);
    }
    $DB->StartTransaction();
    if (!in_array($MESSAGE_TYPE, array("NEW", "EDIT", "REPLY"))) {
        $aMsg[] = array("id" => "MESSAGE_TYPE", "text" => GetMessage("ADDMES_NO_TYPE") . ".");
    }
    $MID = intval($MID);
    $TID = intval($TID);
    $FID = intval($FID);
    $arFieldsG["EDIT_ADD_REASON"] = $arFieldsG["EDIT_ADD_REASON"] == "Y" ? "Y" : "N";
    if ($MID > 0) {
        $arMessage = CForumMessage::GetByID($MID, array("FILTER" => "N"));
        if ($arMessage) {
            $TID = IntVal($arMessage["TOPIC_ID"]);
            $FID = IntVal($arMessage["FORUM_ID"]);
        }
    }
    $arTopic = array();
    if ($TID > 0) {
        $arTopic = CForumTopic::GetByID($TID);
        if ($arTopic) {
            $FID = IntVal($arTopic["FORUM_ID"]);
        }
    }
    $arForum = CForumNew::GetByID($FID);
    //************************* Input params **************************************************************************
    if ($MESSAGE_TYPE == "NEW" && !CForumTopic::CanUserAddTopic($FID, $arUserGroups, $USER->GetID(), $arForum, $arParams["PERMISSION"])) {
        $aMsg[] = array("id" => "PERMISSION", "text" => GetMessage("ADDMESS_NO_PERMS2NEW") . ".");
    } elseif ($MESSAGE_TYPE == "EDIT" && !CForumMessage::CanUserUpdateMessage($MID, $arUserGroups, $USER->GetID(), $arParams["PERMISSION"])) {
        $aMsg[] = array("id" => "PERMISSION", "text" => GetMessage("ADDMESS_NO_PERMS2EDIT") . ".");
    } elseif ($MESSAGE_TYPE == "REPLY" && !CForumMessage::CanUserAddMessage($TID, $arUserGroups, $USER->GetID(), $arParams["PERMISSION"])) {
        $aMsg[] = array("id" => "PERMISSION", "text" => GetMessage("ADDMESS_NO_PERMS2REPLY") . ".");
    }
    if ($MESSAGE_TYPE == "NEW" || $MESSAGE_TYPE == "EDIT" && array_intersect_key($arFieldsG, array("TITLE" => "", "DESCRIPTION" => "", "ICON" => "", "TAGS" => "", "OWNER_ID" => "", "SOCNET_GROUP_ID" => "")) && CForumTopic::CanUserUpdateTopic($TID, $arUserGroups, $USER->GetID(), $arParams["PERMISSION"])) {
        $bUpdateTopic = True;
    }
    if ($MESSAGE_TYPE == "EDIT" && (ForumCurrUserPermissions($FID, $arParams) > "Q" && $arFieldsG["EDIT_ADD_REASON"] == "N")) {
        $bAddEditNote = false;
    }
    //*************************!CAPTCHA********************************************************************************
    if (!$USER->IsAuthorized() && $arForum["USE_CAPTCHA"] == "Y") {
        include_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/classes/general/captcha.php";
        $cpt = new CCaptcha();
        if (strlen($captcha_code) > 0) {
            $captchaPass = COption::GetOptionString("main", "captcha_password", "");
            if (!$cpt->CheckCodeCrypt($captcha_word, $captcha_code, $captchaPass)) {
                $aMsg[] = array("id" => "CAPTCHA", "text" => GetMessage("FORUM_POSTM_CAPTCHA") . ".");
            }
        } else {
            if (!$cpt->CheckCode($captcha_word, $captcha_sid)) {
                $aMsg[] = array("id" => "CAPTCHA", "text" => GetMessage("FORUM_POSTM_CAPTCHA") . ".");
            }
        }
    }
    //*************************!CAPTCHA********************************************************************************
    $arFieldsG["POST_MESSAGE"] = trim($arFieldsG["POST_MESSAGE"]);
    if (empty($arFieldsG["POST_MESSAGE"])) {
        $aMsg[] = array("id" => "POST_MESSAGE", "text" => GetMessage("ADDMESS_INPUT_MESSAGE") . ".");
    }
    if ($bUpdateTopic && is_set($arFieldsG, "TITLE")) {
        $arFieldsG["TITLE"] = trim($arFieldsG["TITLE"]);
        if (empty($arFieldsG["TITLE"])) {
            $aMsg[] = array("id" => "TITLE", "text" => GetMessage("ADDMESS_INPUT_TITLE") . ".");
        }
    }
    //*************************!QUOTA**********************************************************************************
    /*	if (empty($aMsg))
    	{
    		$quota = new CDiskQuota();
    		if ($MESSAGE_TYPE=="EDIT")
    		{
    			if (!$quota->checkDiskQuota(strLen($arFieldsG["POST_MESSAGE"]) - strLen($arMessage["POST_MESSAGE"])))
    			{
    				if (!$quota->LAST_ERROR)
    					$aMsg[] = array("id" => "QUOTA", "text" => GetMessage("MAIN_QUOTA_BAD")."( ".COption::GetOptionInt("main", "disk_space")." ).");
    				else
    					$aMsg[] = array("id" => "QUOTA", "text" => $quota->LAST_ERROR);
    			}
    		}
    		elseif (!$quota->checkDiskQuota($arFieldsG["POST_MESSAGE"]))
    		{
    			if (!$quota->LAST_ERROR)
    				$aMsg[] = array("id" => "QUOTA", "text" => GetMessage("MAIN_QUOTA_BAD")."( ".COption::GetOptionInt("main", "disk_space")." ).");
    			else
    				$aMsg[] = array("id" => "QUOTA", "text" => $quota->LAST_ERROR);
    		}
    	}*/
    //*************************!QUOTA**********************************************************************************
    if (empty($aMsg)) {
        //		*************************!ATTACH_IMG*****************************************************************************
        if (is_set($arFieldsG, "ATTACH_IMG") && empty($arFieldsG["ATTACH_IMG"]["name"]) && empty($arFieldsG["ATTACH_IMG"]["del"])) {
            unset($arFieldsG["ATTACH_IMG"]);
        }
        if (is_set($arFieldsG, "ATTACH_IMG")) {
            $arFieldsG["ATTACH_IMG"]["FILE_ID"] = $arMessage["ATTACH_IMG"];
            $arFieldsG["FILES"] = array($arFieldsG["ATTACH_IMG"]);
        }
        unset($arFieldsG["ATTACH_IMG"]);
        if (!empty($arFieldsG["FILES"]) && is_array($arFieldsG["FILES"])) {
            foreach ($arFieldsG["FILES"] as $key => $val) {
                if (intVal($val["FILE_ID"]) > 0) {
                    $arFieldsG["FILES"][$key]["del"] = $val["del"] == "Y" ? "Y" : "";
                }
            }
            $res = array("FORUM_ID" => $arForum["ID"], "TOPIC_ID" => 0, "MESSAGE_ID" => 0, "USER_ID" => $USER->GetID());
            if (!in_array($arForum["ALLOW_UPLOAD"], array("Y", "F", "A"))) {
                unset($arFieldsG["FILES"]);
            } elseif (!CForumFiles::CheckFields($arFieldsG["FILES"], $res, "NOT_CHECK_DB")) {
                if ($ex = $APPLICATION->GetException()) {
                    $aMsg[] = array("id" => "FILE", "text" => $ex->GetString());
                } else {
                    $aMsg[] = array("id" => "FILE", "text" => "File upload error.");
                }
            }
        }
    }
    //*************************/ATTACH_IMG*****************************************************************************
    if (empty($aMsg) && ($MESSAGE_TYPE == "NEW" || $MESSAGE_TYPE == "REPLY")) {
        $AUTHOR_ID = IntVal($USER->GetParam("USER_ID"));
        if ($USER->IsAuthorized()) {
            $res = CForumUser::GetByUSER_ID($USER->GetID());
            $bSHOW_NAME = !empty($res) ? $res["SHOW_NAME"] == "Y" : true;
            $arFieldsG["AUTHOR_NAME"] = $bSHOW_NAME ? trim($USER->GetFullName()) : "";
            $arFieldsG["AUTHOR_NAME"] = !empty($arFieldsG["AUTHOR_NAME"]) ? $arFieldsG["AUTHOR_NAME"] : $USER->GetLogin();
        }
        if (empty($arFieldsG["AUTHOR_NAME"])) {
            $aMsg[] = array("id" => "AUTHOR_NAME", "text" => GetMessage("ADDMESS_INPUT_AUTHOR") . ".");
        }
    } elseif (empty($aMsg) && $MESSAGE_TYPE == "EDIT") {
        $AUTHOR_ID = IntVal($arMessage["AUTHOR_ID"]);
        if (is_set($arFieldsG, "AUTHOR_NAME") && empty($arFieldsG["AUTHOR_NAME"])) {
            if ($AUTHOR_ID <= 0) {
                $aMsg[] = array("id" => "AUTHOR_NAME", "text" => GetMessage("ADDMESS_INPUT_AUTHOR") . ".");
            } else {
                $res = CForumUser::GetByUSER_ID($AUTHOR_ID);
                $bSHOW_NAME = !empty($res) ? $res["SHOW_NAME"] == "Y" : true;
                if ($USER->GetID() == $AUTHOR_ID) {
                    $arFieldsG["AUTHOR_NAME"] = $bSHOW_NAME ? trim($USER->GetFullName()) : "";
                    $arFieldsG["AUTHOR_NAME"] = !empty($arFieldsG["AUTHOR_NAME"]) ? $arFieldsG["AUTHOR_NAME"] : $USER->GetLogin();
                } else {
                    $res = CForumUser::GetByUSER_IDEx($AUTHOR_ID);
                    if ($res) {
                        $arFieldsG["AUTHOR_NAME"] = trim($bSHOW_NAME ? $res["NAME"] . " " . $res["LAST_NAME"] : "");
                        $arFieldsG["AUTHOR_NAME"] = !empty($arFieldsG["AUTHOR_NAME"]) ? $arFieldsG["AUTHOR_NAME"] : $res["LOGIN"];
                    } else {
                        unset($arFieldsG["AUTHOR_NAME"]);
                    }
                }
            }
        }
        if ($USER->IsAuthorized()) {
            $res = CForumUser::GetByUSER_ID($USER->GetID());
            $bSHOW_NAME = !empty($res) ? $res["SHOW_NAME"] == "Y" : true;
            $arFieldsG["EDITOR_NAME"] = $bSHOW_NAME ? trim($USER->GetFullName()) : "";
            $arFieldsG["EDITOR_NAME"] = !empty($arFieldsG["EDITOR_NAME"]) ? $arFieldsG["EDITOR_NAME"] : $USER->GetLogin();
        }
        if ($bAddEditNote && empty($arFieldsG["EDITOR_NAME"])) {
            $aMsg[] = array("id" => "EDITOR_NAME", "text" => GetMessage("ADDMESS_INPUT_EDITOR") . ".");
        }
    }
    //*************************/Input params ***************************************************************************
    //************************* Actions ********************************************************************************
    //************************* Add/edit topic *************************************************************************
    if (empty($aMsg)) {
        // The longest step by time. Actualization of topic, user and forum statistic info (~0.7-0.8 sec)
        if ($MESSAGE_TYPE == "EDIT" && ($arMessage["APPROVED"] == "Y" || $arMessage["APPROVED"] == "N")) {
            $arFieldsG["APPROVED"] = $arMessage["APPROVED"];
        } elseif (!empty($arTopic) && $arTopic["APPROVED"] != "Y") {
            $arFieldsG["APPROVED"] = "N";
        } else {
            $arFieldsG["APPROVED"] = $arForum["MODERATION"] == "Y" ? "N" : "Y";
            if (ForumCurrUserPermissions($FID, $arParams) >= "Q") {
                $arFieldsG["APPROVED"] = "Y";
            }
        }
        if ($bUpdateTopic) {
            $arFields = array();
            foreach (array("TITLE", "TITLE_SEO", "DESCRIPTION", "ICON", "TAGS") as $key) {
                if (is_set($arFieldsG, $key)) {
                    $arFields[$key] = $arFieldsG[$key];
                }
            }
            if ($MESSAGE_TYPE == "NEW") {
                $arFields["FORUM_ID"] = $FID;
                $arFields["USER_START_ID"] = $AUTHOR_ID;
                $arFields["USER_START_NAME"] = $arFieldsG["AUTHOR_NAME"];
                $arFields["LAST_POSTER_NAME"] = $arFieldsG["AUTHOR_NAME"];
                $arFields["APPROVED"] = $arFieldsG["APPROVED"];
                $arFields["OWNER_ID"] = $arFieldsG["OWNER_ID"];
                $arFields["SOCNET_GROUP_ID"] = $arFieldsG["SOCNET_GROUP_ID"];
                if (is_set($arFieldsG, "TOPIC_XML_ID")) {
                    $arFields["XML_ID"] = $arFieldsG["TOPIC_XML_ID"];
                }
                $TID = CForumTopic::Add($arFields);
                if (IntVal($TID) <= 0) {
                    $aMsg[] = array("id" => "TOPIC_ID", "text" => GetMessage("ADDMESS_ERROR_ADD_TOPIC") . ".");
                }
            } else {
                if (is_set($arFieldsG, "AUTHOR_NAME")) {
                    if ($arTopic["LAST_MESSAGE_ID"] == $MID && $arMessage["LAST_POSTER_NAME"] != $arFieldsG["AUTHOR_NAME"]) {
                        $arFields["LAST_POSTER_NAME"] = $arFieldsG["AUTHOR_NAME"];
                    }
                    if ($arTopic["ABS_LAST_MESSAGE_ID"] == $MID && $arMessage["ABS_LAST_POSTER_NAME"] != $arFieldsG["AUTHOR_NAME"]) {
                        $arFields["ABS_LAST_POSTER_NAME"] = $arFieldsG["AUTHOR_NAME"];
                    }
                    if ($arTopic["USER_START_NAME"] == $arMessage["USER_START_NAME"] && $arTopic["USER_START_NAME"] != $arFieldsG["AUTHOR_NAME"]) {
                        $arFields["USER_START_NAME"] = $arFieldsG["AUTHOR_NAME"];
                    }
                }
                if (!empty($arFields)) {
                    $TID1 = CForumTopic::Update($TID, $arFields);
                    if (intval($TID1) <= 0) {
                        $aMsg[] = array("id" => "TOPIC_ID", "text" => GetMessage("ADDMESS_ERROR_EDIT_TOPIC") . ".");
                    } else {
                        foreach ($arFields as $key => $val) {
                            if ($arFields[$key] != $arTopic[$key]) {
                                $res_log[$key] = $arFields[$key];
                                $res_log["before" . $key] = $arTopic[$key];
                            }
                        }
                        if (!empty($res_log)) {
                            $arTopic = CForumTopic::GetByID($TID);
                            $res_log['FORUM_ID'] = $arTopic['FORUM_ID'];
                            CForumEventLog::Log("topic", "edit", $TID, serialize($res_log));
                        }
                    }
                    if (is_set($arFieldsG, "AUTHOR_NAME") && $arForum["LAST_MESSAGE_ID"] == $MID && $arForum["LAST_POSTER_NAME"] != $arFieldsG["AUTHOR_NAME"]) {
                        $arFieldsForum = array("LAST_POSTER_NAME" => $arFieldsG["AUTHOR_NAME"]);
                        if ($arForum["ABS_LAST_MESSAGE_ID"] == $MID) {
                            $arFieldsForum["LAST_POSTER_NAME"] = $arFieldsG["AUTHOR_NAME"];
                        }
                        CForumNew::Update($arForum["ID"], $arFieldsForum);
                    }
                }
            }
        }
    }
    //*************************/Add/edit topic *************************************************************************
    //************************* Add/edit message ***********************************************************************
    if (empty($aMsg)) {
        $arFields = array("POST_MESSAGE" => $arFieldsG["POST_MESSAGE"], "USE_SMILES" => $arFieldsG["USE_SMILES"] == "Y" ? "Y" : "N", "APPROVED" => $arFieldsG["APPROVED"]);
        if (is_set($arFieldsG, "ATTACH_IMG")) {
            $arFields["ATTACH_IMG"] = $arFieldsG["ATTACH_IMG"];
        } elseif (is_set($arFieldsG, "FILES")) {
            $arFields["FILES"] = $arFieldsG["FILES"];
        }
        if (is_set($arFieldsG, "PARAM1")) {
            $arFields["PARAM1"] = $arFieldsG["PARAM1"];
        }
        if (is_set($arFieldsG, "PARAM2")) {
            $arFields["PARAM2"] = $arFieldsG["PARAM2"];
        }
        /*		elseif ($MESSAGE_TYPE != "NEW")
        		{
        			$db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $TID, "NEW_TOPIC" => "Y"));
        			if ($db_res && $res = $db_res->Fetch())
        				$res["PARAM2"] = $res["PARAM2"];
        		}*/
        $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $arFields);
        if ($MESSAGE_TYPE == "NEW" || $MESSAGE_TYPE == "REPLY") {
            $arFields["AUTHOR_NAME"] = $arFieldsG["AUTHOR_NAME"];
            $arFields["AUTHOR_EMAIL"] = $arFieldsG["AUTHOR_EMAIL"];
            $arFields["AUTHOR_ID"] = $AUTHOR_ID;
            $arFields["FORUM_ID"] = $FID;
            $arFields["TOPIC_ID"] = $TID;
            $AUTHOR_IP = ForumGetRealIP();
            $AUTHOR_IP_tmp = $AUTHOR_IP;
            $AUTHOR_REAL_IP = $_SERVER['REMOTE_ADDR'];
            if (COption::GetOptionString("forum", "FORUM_GETHOSTBYADDR", "N") == "Y") {
                $AUTHOR_IP = @gethostbyaddr($AUTHOR_IP);
                $AUTHOR_REAL_IP = $AUTHOR_IP_tmp == $AUTHOR_REAL_IP ? $AUTHOR_IP : @gethostbyaddr($AUTHOR_REAL_IP);
            }
            $arFields["AUTHOR_IP"] = $AUTHOR_IP !== False ? $AUTHOR_IP : "<no address>";
            $arFields["AUTHOR_REAL_IP"] = $AUTHOR_REAL_IP !== False ? $AUTHOR_REAL_IP : "<no address>";
            $arFields["NEW_TOPIC"] = $MESSAGE_TYPE == "NEW" ? "Y" : "N";
            $arFields["GUEST_ID"] = $_SESSION["SESS_GUEST_ID"];
            $MID = CForumMessage::Add($arFields, false);
            if (intVal($MID) <= 0) {
                $str = $APPLICATION->GetException();
                if ($str && $str->GetString()) {
                    $aMsg[] = array("id" => "MESSAGE_ID", "text" => $str->GetString());
                } else {
                    $aMsg[] = array("id" => "MESSAGE_ID", "text" => GetMessage("ADDMESS_ERROR_ADD_MESSAGE") . ".");
                }
                if ($MESSAGE_TYPE == "NEW") {
                    CForumTopic::Delete($TID);
                    $TID = 0;
                }
            }
        } else {
            if (empty($AUTHOR_ID)) {
                if (is_set($arFieldsG, "AUTHOR_NAME")) {
                    $arFields["AUTHOR_NAME"] = $arFieldsG["AUTHOR_NAME"];
                }
                if (is_set($arFieldsG, "AUTHOR_EMAIL")) {
                    $arFields["AUTHOR_EMAIL"] = $arFieldsG["AUTHOR_EMAIL"];
                }
            }
            if ($bAddEditNote) {
                $arFields["EDITOR_NAME"] = $arFieldsG["EDITOR_NAME"];
                $arFields["EDITOR_EMAIL"] = $arFieldsG["EDITOR_EMAIL"];
                $arFields["EDIT_REASON"] = $arFieldsG["EDIT_REASON"];
                $arFields["EDIT_DATE"] = "";
                if ($GLOBALS["USER"]->IsAuthorized()) {
                    $arFields["EDITOR_ID"] = $GLOBALS["USER"]->GetID();
                }
            }
            $MID1 = CForumMessage::Update($MID, $arFields);
            if (IntVal($MID1) <= 0) {
                $ex = $GLOBALS['APPLICATION']->GetException();
                if ($ex) {
                    $aMsg[] = array("id" => "MESSAGE_ID", "text" => $ex->GetString());
                } else {
                    $aMsg[] = array("id" => "MESSAGE_ID", "text" => GetMessage("ADDMESS_ERROR_EDIT_MESSAGE") . ".");
                }
            } elseif ($AUTHOR_ID == $GLOBALS["USER"]->GetId() && COption::GetOptionString("forum", "LOGS", "Q") < "U") {
            } else {
                $res_log = array();
                foreach ($arFields as $key => $val) {
                    if ($arFields[$key] != $arMessage[$key]) {
                        if ($key == "FILES" || $key == "ATTACH_IMG") {
                            $res_log[$key] = GetMessage("F_ATTACH_IS_MODIFIED");
                            continue;
                        }
                        $res_log["BeforeMessage"] = $arMessage[$key];
                        $res_log["AfterMessage"] = $arFields[$key];
                    }
                }
                if (!empty($res_log)) {
                    $arMessage = CForumMessage::GetByID($MID);
                    $TID = $arMessage['TOPIC_ID'];
                    $res_log['FORUM_ID'] = $arMessage['FORUM_ID'];
                    $arTopic = CForumTopic::GetByID($TID);
                    $res_log['TITLE'] = $arTopic['TITLE'];
                    $res_log['TOPIC_ID'] = $TID;
                    $res_log = serialize($res_log);
                    CForumEventLog::Log("message", "edit", $MID, $res_log);
                }
            }
        }
    }
    //*************************/Add/edit message ***********************************************************************
    if (empty($aMsg)) {
        $DB->Commit();
    } else {
        $DB->Rollback();
    }
    if (empty($aMsg) && CModule::IncludeModule("statistic")) {
        $F_EVENT1 = $arForum["EVENT1"];
        $F_EVENT2 = $arForum["EVENT2"];
        $F_EVENT3 = $arForum["EVENT3"];
        if (empty($F_EVENT3)) {
            $arForumSite_tmp = CForumNew::GetSites($FID);
            if (defined("ADMIN_SECTION") && ADMIN_SECTION === true) {
                $arForumSiteCode_tmp = array_keys($arForumSite_tmp);
                $F_EVENT3 = CForumNew::PreparePath2Message(empty($arForumSite_tmp[$arForumSiteCode_tmp[0]]) ? '' : $arForumSite_tmp[$arForumSiteCode_tmp[0]], array("FORUM_ID" => $FID, "TOPIC_ID" => $TID, "MESSAGE_ID" => $MID));
            } else {
                $F_EVENT3 = CForumNew::PreparePath2Message(empty($arForumSite_tmp[SITE_ID]) ? '' : $arForumSite_tmp[SITE_ID], array("FORUM_ID" => $FID, "TOPIC_ID" => $TID, "MESSAGE_ID" => $MID));
            }
        }
        CStatistics::Set_Event($F_EVENT1, $F_EVENT2, $F_EVENT3);
    }
    if (empty($aMsg)) {
        $arNote = array();
        if ($MESSAGE_TYPE == "NEW" || $MESSAGE_TYPE == "REPLY") {
            CForumMessage::SendMailMessage($MID, array(), false, "NEW_FORUM_MESSAGE");
            $arNote = array("id" => $MESSAGE_TYPE, "text" => GetMessage("ADDMESS_SUCCESS_ADD") . ". \n");
        } else {
            CForumMessage::SendMailMessage($MID, array(), false, "EDIT_FORUM_MESSAGE");
            $arNote = array("id" => "EDIT", "text" => GetMessage("ADDMESS_SUCCESS_EDIT") . ". \n");
        }
        if ($arFieldsG["APPROVED"] != "Y") {
            $arNote["id"] .= "_NOT_APPROVED";
            $arNote["text"] .= GetMessage("ADDMESS_AFTER_MODERATE") . ". \n";
        }
        if (is_array($strOKMessage)) {
            $strOKMessage[] = $arNote;
        } else {
            $strOKMessage .= $arNote["text"];
        }
        return $MID;
    }
    $e = new CAdminException($aMsg);
    $strErrorMessage = $e->GetString();
    return false;
}
コード例 #13
0
ファイル: action.php プロジェクト: k-kalashnikov/geekcon_new
             $arSection = $res;
         }
     }
     $url = str_replace(array("#ELEMENT_ID#", "#ID#", "#ELEMENT_CODE#", "#SECTION_ID#", "#SECTION_CODE#"), array($arResult["ELEMENT"]["ID"], $arResult["ELEMENT"]["ID"], $arResult["ELEMENT"]["CODE"], $arResult["ELEMENT"]["IBLOCK_SECTION_ID"], $arSection["CODE"]), $url);
     if (intVal($arResult["ELEMENT"]["PREVIEW_PICTURE"]) > 0) {
         $arImage = CFile::GetFileArray($arResult["ELEMENT"]["PREVIEW_PICTURE"]);
         if (!empty($arImage)) {
             $sImage = $arResult["FORUM"]["ALLOW_IMG"] == "Y" ? "[IMG]" . $arImage["SRC"] . "[/IMG]" : '';
         }
     }
     $sElementPreview = $arResult["ELEMENT"]["~PREVIEW_TEXT"];
     if ($arAllow["HTML"] != "Y") {
         $sElementPreview = strip_tags($sElementPreview);
     }
     $arFields = array("POST_MESSAGE" => str_replace(array("#IMAGE#", "#TITLE#", "#BODY#", "#LINK#"), array($sImage, $arResult["ELEMENT"]["~NAME"], $sElementPreview, $url), $arParams["POST_FIRST_MESSAGE_TEMPLATE"]), "AUTHOR_ID" => $arUserStart["ID"], "AUTHOR_NAME" => $arUserStart["NAME"], "FORUM_ID" => $arParams["FORUM_ID"], "TOPIC_ID" => $TID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "IB", "PARAM2" => intVal($arParams["ELEMENT_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($TID);
         $TID = 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.
         }
     }
 }
コード例 #14
0
 public static function AddComment_Report_Forum($arFields, $FORUM_ID, $arLog)
 {
     global $USER, $DB;
     $mess_id = false;
     $dbReport = CTimeManReportFull::GetByID($arLog["SOURCE_ID"]);
     $arReport = $dbReport->Fetch();
     if (CModule::IncludeModule("forum") && $arReport) {
         $ufFileID = array();
         $ufDocID = array();
         if (!($userName = trim($USER->GetFormattedName(false)))) {
             $userName = $USER->GetLogin();
         }
         if (!$arReport["FORUM_TOPIC_ID"]) {
             $arTopicFields = array("TITLE" => $arReport["DATE_FROM"] . "-" . $arReport["DATE_TO"], "USER_START_ID" => $arFields["USER_ID"], "STATE" => "Y", "FORUM_ID" => $FORUM_ID, "USER_START_NAME" => $userName, "START_DATE" => ConvertTimeStamp(time(), "FULL"), "POSTS" => 0, "VIEWS" => 0, "APPROVED" => "Y", "LAST_POSTER_NAME" => $userName, "LAST_POST_DATE" => ConvertTimeStamp(time(), "FULL"), "LAST_MESSAGE_ID" => 0, "XML_ID" => "TIMEMAN_REPORT_" . $arLog["SOURCE_ID"]);
             $TOPIC_ID = CForumTopic::Add($arTopicFields);
             if ($TOPIC_ID) {
                 CTimeManReportFull::Update($arLog["SOURCE_ID"], array("FORUM_TOPIC_ID" => $TOPIC_ID));
             }
         } else {
             $TOPIC_ID = $arReport["FORUM_TOPIC_ID"];
         }
         if ($TOPIC_ID) {
             $arFieldsP = array("AUTHOR_ID" => $arFields["USER_ID"], "AUTHOR_NAME" => $userName, "POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "FORUM_ID" => $FORUM_ID, "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "PARAM2" => $arLog["SOURCE_ID"]);
             $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)) {
                     $arFieldsP["FILES"] = array();
                     foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) {
                         $arFieldsP["FILES"][] = array("FILE_ID" => $file_id);
                     }
                 }
             }
             $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $arFieldsP);
             $mess_id = CForumMessage::Add($arFieldsP);
             // get UF DOC value and FILE_ID there
             if ($mess_id > 0) {
                 $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $mess_id));
                 while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                     $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                 }
                 $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $mess_id, LANGUAGE_ID);
             }
         }
     }
     return array("SOURCE_ID" => $mess_id, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID));
 }
コード例 #15
0
ファイル: index.php プロジェクト: mrdeadmouse/u136006
        continue;
    }
    $forumID = CForumNew::Add($arForum);
    if ($forumID < 1 || !isset($arForum["TOPICS"]) || !is_array($arForum["TOPICS"])) {
        continue;
    }
    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"] . ",";
    }
}
コード例 #16
0
 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");
     $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($TID);
             $TID = 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;
 }
コード例 #17
-1
ファイル: baseobject.php プロジェクト: rasuldev/torino
 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;
 }