Esempio n. 1
0
    $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"] . ",";
    }
}
$fidParameter = rtrim($fidParameter, ",");
$forum_theme = 'blue';
Esempio n. 2
0
 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));
 }
Esempio n. 3
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);
                 }
             }
         }
     }
 }
Esempio n. 4
0
        }
        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();
            }
        }
    }
    ?>

<br><a name="cm">
Esempio n. 5
0
 function Delete($ID)
 {
     global $DB;
     $ID = intVal($ID);
     $arMessage = array();
     if ($ID > 0) {
         $arMessage = CForumMessage::GetByID($ID, array("FILTER" => "N"));
     }
     if (empty($arMessage)) {
         return false;
     }
     /***************** Event onBeforeMessageAdd ************************/
     foreach (GetModuleEvents("forum", "onBeforeMessageDelete", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     $AUTHOR_ID = intVal($arMessage["AUTHOR_ID"]);
     $TOPIC_ID = intVal($arMessage["TOPIC_ID"]);
     $FORUM_ID = intVal($arMessage["FORUM_ID"]);
     $DB->StartTransaction();
     // delete votes
     if ($arMessage["PARAM1"] == "VT" && intVal($arMessage["PARAM2"]) > 0 && IsModuleInstalled("vote")) {
         CModule::IncludeModule("vote");
         CVote::Delete($arMessage["PARAM2"]);
     }
     // delete files
     CForumFiles::Delete(array("MESSAGE_ID" => $ID), array("DELETE_MESSAGE_FILE" => "Y"));
     // delete message
     $DB->Query("DELETE FROM b_forum_message WHERE ID=" . $ID);
     // after delete
     $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID), false, 1);
     $res = false;
     if (!($db_res && ($res = $db_res->Fetch()))) {
         CForumTopic::Delete($TOPIC_ID);
     } else {
         // if deleted message was first
         if ($arMessage["NEW_TOPIC"] == "Y") {
             $DB->Update('b_forum_message', array('NEW_TOPIC' => '"Y"'), "WHERE ID=" . $res["ID"]);
         }
         CForumTopic::SetStat($TOPIC_ID);
     }
     $DB->Commit();
     $GLOBALS["USER_FIELD_MANAGER"]->Delete("FORUM_MESSAGE", $ID);
     if ($AUTHOR_ID > 0) {
         CForumUser::SetStat($AUTHOR_ID);
     }
     CForumNew::SetStat($FORUM_ID);
     /***************** Event onBeforeMessageAdd ************************/
     foreach (GetModuleEvents("forum", "onAfterMessageDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID, $arMessage));
     }
     /***************** /Event ******************************************/
     if (CModule::IncludeModule("search")) {
         CSearch::DeleteIndex("forum", $ID);
         if (is_array($res) && !empty($res)) {
             CForumMessage::Reindex($res["ID"], $res);
         }
     }
     return true;
 }
Esempio n. 6
0
 public static function OnSocNetGroupDelete($group_id)
 {
     global $DB;
     $group_id = intVal($group_id);
     if ($group_id > 0) {
         if (CModule::IncludeModule("socialnetwork")) {
             $dbRes = $DB->Query("select ID from b_forum_topic where SOCNET_GROUP_ID=" . $group_id);
             while ($arRes = $dbRes->Fetch()) {
                 CForumTopic::Delete($arRes["ID"]);
             }
         }
     }
     return true;
 }
Esempio n. 7
0
 function OnBeforeIBlockElementDelete($ELEMENT_ID)
 {
     $ELEMENT_ID = intVal($ELEMENT_ID);
     if ($ELEMENT_ID > 0 && CModule::IncludeModule("iblock")) {
         $rsElement = CIBlockElement::GetList(array("ID" => "ASC"), array("ID" => $ELEMENT_ID, "SHOW_HISTORY" => "Y", "CHECK_PERMISSIONS" => "N"), false, false, array("ID", "WF_PARENT_ELEMENT_ID", "IBLOCK_ID"));
         $arElement = $rsElement->Fetch();
         if (is_array($arElement) && $arElement["WF_PARENT_ELEMENT_ID"] == 0) {
             $rsProperty = CIBlockElement::GetProperty($arElement["IBLOCK_ID"], $arElement["ID"], array(), array("CODE" => "FORUM_TOPIC_ID"));
             if ($rsProperty && ($arProperty = $rsProperty->Fetch())) {
                 if (is_array($arProperty) && $arProperty["VALUE"] > 0) {
                     CForumTopic::Delete($arProperty["VALUE"]);
                 }
             }
         }
     }
     return true;
 }
Esempio n. 8
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", "XML_ID" => "IBLOCK_" . $arElement["ID"]);
     if (isset($arElement["ENTITY_TYPE"]) && $arElement["ENTITY_TYPE"] == SONET_ENTITY_GROUP && isset($arElement["ENTITY_ID"]) && intval($arElement["ENTITY_ID"]) > 0) {
         $arFields["SOCNET_GROUP_ID"] = intval($arElement["ENTITY_ID"]);
     }
     $TOPIC_ID = CForumTopic::Add($arFields);
     if ($bPostFirstMessage && intVal($TOPIC_ID) > 0) {
         if (COption::GetOptionString("forum", "FILTER", "Y") == "Y") {
             $strFirstMessage = CFilterUnquotableWords::Filter($strFirstMessage);
         }
         // Add post as new message
         $arFields = array("POST_MESSAGE" => $strFirstMessage, "AUTHOR_ID" => $arUserStart["ID"], "AUTHOR_NAME" => $arUserStart["NAME"], "FORUM_ID" => $forumID, "TOPIC_ID" => $TOPIC_ID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => "IB", "PARAM2" => intVal($arElement["ID"]));
         $MID = CForumMessage::Add($arFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
         if (intVal($MID) <= 0) {
             $arError[] = array("code" => "message is not added 1", "title" => GetMessage("F_ERR_ADD_MESSAGE"));
             CForumTopic::Delete($TOPIC_ID);
             $TOPIC_ID = 0;
         } elseif ($arParams["SUBSCRIBE_AUTHOR_ELEMENT"] == "Y" && intVal($arResult["ELEMENT"]["~CREATED_BY"]) > 0) {
             if ($arUserStart["USER_PROFILE"] == "N") {
                 $arUserStart["FORUM_USER_ID"] = CForumUser::Add(array("USER_ID" => $arResult["ELEMENT"]["~CREATED_BY"]));
             }
             if (intVal($arUserStart["FORUM_USER_ID"]) > 0) {
                 CForumSubscribe::Add(array("USER_ID" => $arResult["ELEMENT"]["~CREATED_BY"], "FORUM_ID" => $arParams["FORUM_ID"], "SITE_ID" => SITE_ID, "TOPIC_ID" => $TID, "NEW_TOPIC_ONLY" => "N"));
                 BXClearCache(true, "/bitrix/forum/user/" . $arResult["ELEMENT"]["~CREATED_BY"] . "/subscribe/");
                 // Sorry, Max.
             }
         }
     } elseif (intVal($TOPIC_ID) <= 0) {
         $GLOBALS["DB"]->Rollback();
         return false;
     }
     $GLOBALS["DB"]->Commit();
     return $TOPIC_ID;
 }
Esempio n. 9
0
function ForumMoveMessage($FID, $TID, $Message, $NewTID = 0, $arFields, &$strErrorMessage, &$strOKMessage, $iFileSize = false)
{
    global $USER, $DB;
    $arError = array();
    $arOK = array();
    $NewFID = 0;
    $arForum = array();
    $arTopic = array();
    $arNewForum = array();
    $arNewTopic = array();
    $arCurrUser = array();
    $SendSubscribe = false;
    //************************* Input params **************************************************************************
    $TID = IntVal($TID);
    $FID = IntVal($FID);
    $NewTID = IntVal($NewTID);
    $Message = ForumDataToArray($Message);
    if (empty($Message)) {
        $arError[] = GetMessage("FMM_NO_MESSAGE");
    }
    if ($TID <= 0) {
        $arError[] = GetMessage("FMM_NO_TOPIC_SOURCE0");
    } else {
        $arTopic = CForumTopic::GetByID($TID);
        if ($arTopic) {
            $FID = IntVal($arTopic["FORUM_ID"]);
            $arForum = CForumNew::GetByID($FID);
        } else {
            $arError[] = GetMessage("FMM_NO_TOPIC_SOURCE1");
        }
    }
    if ($NewTID <= 0 && strLen(trim($arFields["TITLE"])) <= 0) {
        $arError[] = GetMessage("FMM_NO_TOPIC_RECIPIENT0");
    } elseif ($NewTID > 0) {
        if ($NewTID == $TID) {
            $arError[] = GetMessage("FMM_NO_TOPIC_EQUAL");
        }
        $arNewTopic = CForumTopic::GetByID($NewTID);
        if (!$arNewTopic) {
            $arError[] = GetMessage("FMM_NO_TOPIC_RECIPIENT1");
        } elseif ($arNewTopic["STATE"] == "L") {
            $arError[] = GetMessage("FMM_TOPIC_IS_LINK");
        } else {
            $NewFID = $arNewTopic["FORUM_ID"];
            $arNewForum = CForumNew::GetByID($NewFID);
        }
    }
    //*************************/Input params **************************************************************************
    //*************************!Proverka prav pol'zovatelya na forume-istochnike i forume-poluchatele*********************
    // Tak kak realizovan mehanizm peremeweniya tem s forumov, gde tekuwij pol'zovatel' yavlyaetsya moderatorom na forumy,
    // gde on moderatorov ne yavlyaetsya, to v dannom sluchae budet ispol'zovan tot zhe samyj shablon dejstvij. Isklyucheniem
    // yavlyaetsya to, chto esli pol'zovatel' na forume-poluchatele ne obladaet pravami moderirovaniya, tema budet neaktivna.
    //*************************!Proverka prav pol'zovatelya*************************************************************
    $arCurrUser["Perms"]["FID"] = ForumCurrUserPermissions($FID);
    $arCurrUser["Perms"]["NewFID"] = ForumCurrUserPermissions($NewFID);
    if ($arCurrUser["Perms"]["FID"] < "Q") {
        $arError[] = GetMessage("FMM_NO_MODERATE");
    }
    //************************* Actions *******************************************************************************
    $DB->StartTransaction();
    if (count($arError) <= 0) {
        // Create topic
        if ($NewTID <= 0) {
            $arFields["APPROVED"] = $arNewForum["MODERATION"] == "Y" ? "N" : "Y";
            if ($arCurrUser["Perms"]["NewFID"] >= "Q") {
                $arFields["APPROVED"] = "Y";
            }
            $arRes = array("NAME" => GetMessage("FR_GUEST"));
            $ShowName = GetMessage("FR_GUEST");
            $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("@ID" => implode(",", $Message), "TOPIC_ID" => $TID));
            if ($db_res && ($res = $db_res->Fetch())) {
                $arRes["NAME"] = $res["AUTHOR_NAME"];
                $arRes["ID"] = $res["AUTHOR_ID"];
            }
            $arFieldsTopic = array("TITLE" => $arFields["TITLE"], "TITLE_SEO" => $arFields["TITLE_SEO"], "DESCRIPTION" => $arFields["DESCRIPTION"], "ICON" => $arFields["ICON"], "TAGS" => $arFields["TAGS"], "FORUM_ID" => $FID, "USER_START_ID" => $arRes["ID"], "USER_START_NAME" => $arRes["NAME"], "LAST_POSTER_NAME" => $arRes["NAME"], "LAST_POSTER_ID" => $arRes["ID"], "APPROVED" => $arFields["APPROVED"]);
            $NewTID = CForumTopic::Add($arFieldsTopic);
            if (IntVal($NewTID) <= 0) {
                $arError[] = GetMessage("FMM_NO_TOPIC_NOT_CREATED");
            } else {
                $arNewTopic = CForumTopic::GetByID($NewTID);
                if ($arNewTopic) {
                    $NewFID = $FID;
                    $arNewForum = $arForum;
                    $SendSubscribe = true;
                } else {
                    $arError[] = GetMessage("FMM_NO_TOPIC_NOT_CREATED");
                }
            }
        }
    }
    if (count($arError) <= 0) {
        // Move message
        $db_res = CForumMessage::GetList(array(), array("@ID" => implode(",", $Message), "TOPIC_ID" => $TID));
        if ($db_res && ($res = $db_res->Fetch())) {
            do {
                //				echo "NewFID: ".$NewFID." -- FID:".$FID."<br/>";
                $arMessage = array();
                if ($NewFID != $FID) {
                    $arMessage["APPROVED"] = $arNewForum["MODERATION"] == "Y" ? "N" : "Y";
                    if ($arCurrUser["Perms"]["NewFID"] >= "Q") {
                        $arMessage["APPROVED"] = "Y";
                    }
                    $arMessage["FORUM_ID"] = $NewFID;
                    $arMessage["POST_MESSAGE_HTML"] = "";
                }
                if ($NewTID != $TID) {
                    $arMessage["NEW_TOPIC"] = "N";
                    $arMessage["TOPIC_ID"] = $NewTID;
                }
                if (count($arMessage) > 0) {
                    $MID = CForumMessage::Update($res["ID"], $arMessage, true);
                    $res_log = $SendSubscribe == true ? GetMessage("F_MESSAGE_WAS_MOVED_TO_NEW") : GetMessage("F_MESSAGE_WAS_MOVED");
                    $res_log = str_replace(array("#ID#", "#TOPIC_TITLE#", "#TOPIC_ID#", "#NEW_TOPIC_TITLE#", "#NEW_TOPIC_ID#"), array($MID, $arTopic["TITLE"], $arTopic["ID"], $arNewTopic['TITLE'], $arNewTopic['ID']), $res_log);
                    $res["TITLE"] = $arNewTopic['TITLE'];
                    $res["TOPIC_ID"] = $arNewTopic['ID'];
                    $res["beforeTITLE"] = $arTopic["TITLE"];
                    $res["DESCRIPTION"] = $res_log;
                    CForumEventLog::Log("message", "move", $MID, serialize($res));
                    $db_res2 = CForumFiles::GetList(array(), array("FILE_MESSAGE_ID" => $res["ID"]));
                    if ($db_res2 && ($res2 = $db_res2->Fetch())) {
                        $arFiles = array();
                        do {
                            $arFiles[] = $res2["FILE_ID"];
                        } while ($res2 = $db_res2->Fetch());
                        CForumFiles::UpdateByID($arFiles, $arMessage);
                    }
                    if (IntVal($MID) <= 0) {
                        $arError[] = str_replace("##", $res["ID"], GetMessage("FMM_NO_MESSAGE_MOVE"));
                        break;
                    }
                }
            } while ($res = $db_res->Fetch());
        }
    }
    if (count($arError) <= 0) {
        $db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $TID), false, 1);
        if (!($db_res && ($res = $db_res->Fetch()))) {
            CForumTopic::Delete($TID);
        } else {
            CForumTopic::SetStat($TID);
        }
        $db_res = CForumMessage::GetList(array(), array("TOPIC_ID" => $NewTID), false, 1);
        if (!($db_res && ($res = $db_res->Fetch()))) {
            CForumTopic::Delete($NewTID);
        } else {
            CForumTopic::SetStat($NewTID);
        }
        CForumNew::SetStat($FID);
        if ($NewFID != $FID) {
            CForumNew::SetStat($NewFID);
        }
    }
    if (count($arError) <= 0) {
        $DB->Commit();
    } else {
        $DB->Rollback();
    }
    if (count($arError) > 0) {
        $strErrorMessage .= implode(". \n", $arError) . ". \n";
    } else {
        $strOKMessage .= GetMessage("FMM_YES_MESSAGE_MOVE");
        if ($SendSubscribe) {
            foreach ($Message as $MID) {
                CForumMessage::SendMailMessage($MID, array(), false, "NEW_FORUM_MESSAGE");
            }
        }
        return true;
    }
    return false;
}
Esempio n. 10
0
	/**
	 * <p>Удаляет сообщение с кодом <i>ID</i>.</p> <p><b>Примечание</b>. Метод использует внутреннюю транзакцию. Если у вас используется <b>MySQL</b> и <b>InnoDB</b>, и ранее была открыта транзакция, то ее необходимо закрыть до подключения метода.</p>
	 *
	 *
	 *
	 *
	 * @param int $ID  Код сообщения, которое необходимо удалить.
	 *
	 *
	 *
	 * @return bool 
	 *
	 *
	 * <h4>See Also</h4> 
	 * <ul><li>Перед удалением сообщения следует проверить возможность
	 * удаления методом <a
	 * href="http://dev.1c-bitrix.ru/api_help/forum/developer/cforummessage/canuserdeletemessage.php">CForumMessage::CanUserDeleteMessage</a>
	 * </li></ul>
	 *
	 *
	 * @static
	 * @link http://dev.1c-bitrix.ru/api_help/forum/developer/cforummessage/delete.php
	 * @author Bitrix
	 */
	public static function Delete($ID)
	{
		global $DB;
		$ID = intVal($ID);
		$arMessage = array();
		if ($ID > 0)
			$arMessage = CForumMessage::GetByID($ID, array("FILTER" => "N"));
		if (empty($arMessage))
			return false;
/***************** Event onBeforeMessageAdd ************************/
		$events = GetModuleEvents("forum", "onBeforeMessageDelete");
		while ($arEvent = $events->Fetch())
		{
			if (ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage)) === false)
				return false;
		}
/***************** /Event ******************************************/
		$AUTHOR_ID = intVal($arMessage["AUTHOR_ID"]);
		$TOPIC_ID = intVal($arMessage["TOPIC_ID"]);
		$FORUM_ID = intVal($arMessage["FORUM_ID"]);

		$DB->StartTransaction();
		// delete votes
		if ($arMessage["PARAM1"] == "VT" && intVal($arMessage["PARAM2"]) > 0 && IsModuleInstalled("vote")):
			CModule::IncludeModule("vote");
			CVote::Delete($arMessage["PARAM2"]);
		endif;
		// delete files
		CForumFiles::Delete(array("MESSAGE_ID" => $ID), array("DELETE_MESSAGE_FILE" => "Y"));
		// delete message
		$DB->Query("DELETE FROM b_forum_message WHERE ID=".$ID);
		// after delete
		$db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $TOPIC_ID), false, 1);
		$res = false;
		if (!($db_res && $res = $db_res->Fetch())):
			CForumTopic::Delete($TOPIC_ID);
		else:
			// if deleted message was first
			if ($arMessage["NEW_TOPIC"] == "Y"):
				$DB->Query("UPDATE b_forum_message SET NEW_TOPIC='Y' WHERE ID=".$res["ID"]);
			endif;
			CForumTopic::SetStat($TOPIC_ID);
		endif;
		$DB->Commit();

		$GLOBALS["USER_FIELD_MANAGER"]->Delete("FORUM_MESSAGE", $ID);

		if ($AUTHOR_ID > 0):
			CForumUser::SetStat($AUTHOR_ID);
		endif;
		CForumNew::SetStat($FORUM_ID);
/***************** Event onBeforeMessageAdd ************************/
		$events = GetModuleEvents("forum", "onAfterMessageDelete");
		while ($arEvent = $events->Fetch())
			ExecuteModuleEventEx($arEvent, array($ID, $arMessage));
/***************** /Event ******************************************/
		if (CModule::IncludeModule("search"))
		{
			CSearch::DeleteIndex("forum", $ID);
		}
		return true;
	}
Esempio n. 11
0
 /**
  * This method is deprecated. Use CTaskItem::delete() instead.
  * @deprecated
  */
 public static function Delete($ID, $arParams = array())
 {
     global $DB, $CACHE_MANAGER, $USER;
     if (isset($USER) && is_object($USER)) {
         $actorUserId = (int) $USER->getId();
     } else {
         $actorUserId = 1;
     }
     if (isset($arParams['META::EVENT_GUID'])) {
         $eventGUID = $arParams['META::EVENT_GUID'];
         unset($arParams['META::EVENT_GUID']);
     } else {
         $eventGUID = sha1(uniqid('AUTOGUID', true));
     }
     $paramSkipExchangeSync = false;
     if (is_array($arParams)) {
         if (isset($arParams['skipExchangeSync']) && ($arParams['skipExchangeSync'] === 'Y' || $arParams['skipExchangeSync'] === true)) {
             $paramSkipExchangeSync = true;
         }
     }
     $ID = intval($ID);
     if ($ID < 1) {
         return false;
     }
     $rsTask = CTasks::GetByID($ID, false);
     if ($arTask = $rsTask->Fetch()) {
         foreach (GetModuleEvents('tasks', 'OnBeforeTaskDelete', true) as $arEvent) {
             if (ExecuteModuleEventEx($arEvent, array($ID, $arTask)) === false) {
                 return false;
             }
         }
         CTaskCountersProcessor::onBeforeTaskDelete($ID, $arTask);
         CTaskMembers::DeleteByTaskID($ID);
         CTaskFiles::DeleteByTaskID($ID);
         CTaskDependence::DeleteByTaskID($ID);
         CTaskDependence::DeleteByDependsOnID($ID);
         CTaskTags::DeleteByTaskID($ID);
         $strSql = "DELETE FROM b_tasks_viewed WHERE TASK_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strSql = "DELETE FROM b_tasks_reminder WHERE TASK_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         // clear cache
         if ($arTask["GROUP_ID"]) {
             $CACHE_MANAGER->ClearByTag("tasks_group_" . $arTask["GROUP_ID"]);
         }
         $arParticipants = array_unique(array_merge(array($arTask["CREATED_BY"], $arTask["RESPONSIBLE_ID"]), $arTask["ACCOMPLICES"], $arTask["AUDITORS"]));
         foreach ($arParticipants as $userId) {
             $CACHE_MANAGER->ClearByTag("tasks_user_" . $userId);
         }
         $strSql = "UPDATE b_tasks_template SET TASK_ID = NULL WHERE TASK_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strSql = "UPDATE b_tasks_template SET PARENT_ID = " . ($arTask["PARENT_ID"] ? $arTask["PARENT_ID"] : "NULL") . " WHERE PARENT_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strSql = "UPDATE b_tasks SET PARENT_ID = " . ($arTask["PARENT_ID"] ? $arTask["PARENT_ID"] : "NULL") . " WHERE PARENT_ID = " . $ID;
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         $strUpdate = $DB->PrepareUpdate("b_tasks", array('ZOMBIE' => 'Y', 'CHANGED_BY' => $actorUserId, 'CHANGED_DATE' => date($DB->DateFormatToPHP(CSite::GetDateFormat('FULL')), time() + CTasksTools::getTimeZoneOffset())), "tasks");
         $strSql = "UPDATE b_tasks SET " . $strUpdate . " WHERE ID = " . (int) $ID;
         if ($DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__)) {
             CTaskNotifications::SendDeleteMessage($arTask);
             if ($arTask["FORUM_TOPIC_ID"] && CModule::IncludeModule("forum")) {
                 CForumTopic::Delete($arTask["FORUM_TOPIC_ID"]);
             }
             if (!$paramSkipExchangeSync) {
                 CTaskSync::DeleteItem($arTask);
             }
             // MS Exchange
             // Emit pull event
             try {
                 $arPullRecipients = array();
                 foreach ($arParticipants as $userId) {
                     $arPullRecipients[] = (int) $userId;
                 }
                 $taskGroupId = 0;
                 // no group
                 if (isset($arTask['GROUP_ID']) && $arTask['GROUP_ID'] > 0) {
                     $taskGroupId = (int) $arTask['GROUP_ID'];
                 }
                 $arPullData = array('TASK_ID' => (int) $ID, 'BEFORE' => array('GROUP_ID' => $taskGroupId), 'TS' => time(), 'event_GUID' => $eventGUID);
                 self::EmitPullWithTagPrefix($arPullRecipients, 'TASKS_GENERAL_', 'task_remove', $arPullData);
                 self::EmitPullWithTag($arPullRecipients, 'TASKS_TASK_' . (int) $ID, 'task_remove', $arPullData);
             } catch (Exception $e) {
             }
             foreach (GetModuleEvents('tasks', 'OnTaskDelete', true) as $arEvent) {
                 ExecuteModuleEventEx($arEvent, array($ID));
             }
             if (CModule::IncludeModule("search")) {
                 CSearch::DeleteIndex("tasks", $ID);
             }
         }
         return true;
     }
     return false;
 }
Esempio n. 12
-1
 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;
 }