function __FPF_AddEntityInForumFiles(&$arCustomFile, $arParams = null)
 {
     static $arFileParams = array();
     if ($arParams !== null) {
         $arFileParams = $arParams;
     }
     $arFiles = array(array("FILE_ID" => $arCustomFile["fileID"]));
     if (!is_array($arCustomFile) || !isset($arCustomFile['fileID'])) {
         return false;
     } elseif (!CForumFiles::CheckFields($arFiles, $arFileParams, "NOT_CHECK_DB")) {
         $ex = $GLOBALS["APPLICATION"]->GetException();
         return $ex ? $ex->GetString() : "File upload error.";
     } elseif (!empty($arFiles)) {
         $GLOBALS["APPLICATION"]->RestartBuffer();
         CForumFiles::Add($arCustomFile['fileID'], $arFileParams);
     }
 }
Example #2
0
 function OnCommentPreview()
 {
     $arResult =& $this->component->arResult;
     $arParams =& $this->component->arParams;
     $arError = array();
     $arFields = array("FORUM_ID" => intVal($arParams["FORUM_ID"]), "TOPIC_ID" => 0, "MESSAGE_ID" => 0, "USER_ID" => intVal($GLOBALS["USER"]->GetID()));
     $arFiles = array();
     $arFilesExists = array();
     $res = array();
     foreach ($_FILES as $key => $val) {
         if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) {
             $arFiles[] = $_FILES[$key];
         }
     }
     foreach ($_REQUEST["FILES"] as $key => $val) {
         if (!in_array($val, $_REQUEST["FILES_TO_UPLOAD"])) {
             $arFiles[$val] = array("FILE_ID" => $val, "del" => "Y");
             unset($_REQUEST["FILES"][$key]);
             unset($_REQUEST["FILES_TO_UPLOAD"][$key]);
         } else {
             $arFilesExists[$val] = array("FILE_ID" => $val);
         }
     }
     if (!empty($arFiles)) {
         $res = CForumFiles::Save($arFiles, $arFields);
         $res1 = $GLOBALS['APPLICATION']->GetException();
         if ($res1) {
             $arError[] = array("code" => "file upload error", "title" => $res1->GetString());
         }
     }
     $res = is_array($res) ? $res : array();
     foreach ($res as $key => $val) {
         $arFilesExists[$key] = $val;
     }
     $arFilesExists = array_keys($arFilesExists);
     sort($arFilesExists);
     $arResult["MESSAGE_VIEW"]["FILES"] = $_REQUEST["FILES"] = $arFilesExists;
     $arResult["REVIEW_FILES"] = array();
     foreach ($_REQUEST["FILES"] as $key => $val) {
         $arResult["REVIEW_FILES"][$val] = CFile::GetFileArray($val);
     }
     if (!empty($arError)) {
         $arResult['ERROR'] = $arError;
     }
 }
Example #3
0
 private function prepareFields(array &$params, ErrorCollection $errorCollectionParam)
 {
     $result = array("FORUM_ID" => $this->topic["FORUM_ID"], "TOPIC_ID" => $this->topic["ID"], "POST_MESSAGE" => trim($params["POST_MESSAGE"]), "AUTHOR_ID" => $params["AUTHOR_ID"], "AUTHOR_NAME" => trim($params["AUTHOR_NAME"]), "AUTHOR_EMAIL" => trim($params["AUTHOR_EMAIL"]), "USE_SMILES" => $params["USE_SMILES"] == "Y" ? "Y" : "N", "APPROVED" => $this->topic["APPROVED"], "XML_ID" => $this->getEntity()->getXmlId());
     $errorCollection = new ErrorCollection();
     if (strlen($result["POST_MESSAGE"]) <= 0) {
         $errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_EMPTY_TEXT"), self::ERROR_PARAMS_MESSAGE));
     }
     if (strlen($result["AUTHOR_NAME"]) <= 0 && $result["AUTHOR_ID"] > 0) {
         $result["AUTHOR_NAME"] = self::getUserName($result["AUTHOR_ID"]);
     }
     if (strlen($result["AUTHOR_NAME"]) <= 0) {
         $errorCollection->addOne(new Error(Loc::getMessage("FORUM_CM_ERR_EMPTY_AUTHORS_NAME"), self::ERROR_PARAMS_MESSAGE));
     }
     if (is_array($params["FILES"]) && in_array($this->forum["ALLOW_UPLOAD"], array("Y", "F", "A"))) {
         $result["FILES"] = array();
         foreach ($params["FILES"] as $key => $val) {
             if (intval($val["FILE_ID"]) > 0) {
                 $val["del"] = $val["del"] == "Y" ? "Y" : "";
             }
             $result["FILES"][$key] = $val;
         }
         $res = array("FORUM_ID" => $this->forum["ID"], "TOPIC_ID" => $this->topic["ID"], "MESSAGE_ID" => 0, "USER_ID" => $result["AUTHOR_ID"], "FORUM" => $this->forum);
         if (!\CForumFiles::CheckFields($result["FILES"], $res, "NOT_CHECK_DB")) {
             $text = "File upload error.";
             if (($ex = $this->getApplication()->getException()) && $ex) {
                 $text = $ex->getString();
             }
             $errorCollection->addOne(new Error($text, self::ERROR_PARAMS_MESSAGE));
         }
     }
     if ($result["APPROVED"] != "N") {
         $result["APPROVED"] = $this->forum["MODERATION"] != "Y" || $this->getEntity()->canModerate() ? "Y" : "N";
     }
     if ($errorCollection->hasErrors()) {
         $errorCollectionParam->add($errorCollection->toArray());
         return false;
     } else {
         $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("FORUM_MESSAGE", $result);
         $params = $result;
         return true;
     }
 }
Example #4
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;
}
 function OnCommentAdd($entityType, $entityID, &$arPost)
 {
     global $USER;
     $arParams =& $this->component->arParams;
     $arResult =& $this->component->arResult;
     $arForum =& $arResult['FORUM'];
     $iFileSize = intval(COption::GetOptionString("forum", "file_max_size", 50000));
     $arCommentParams = array("FORUM_ID" => $arParams["FORUM_ID"], "TOPIC_ID" => null, "USER_ID" => $USER->IsAuthorized() ? $USER->GetID() : null);
     $arFiles = $arNewFiles = array();
     if (isset($_REQUEST['FILE_NEW']) && is_array($_REQUEST['FILE_NEW'])) {
         foreach ($_REQUEST['FILE_NEW'] as $val) {
             $arNewFiles[$val] = array("FILE_ID" => $val);
         }
     }
     if (isset($_REQUEST['FILES']) && is_array($_REQUEST['FILES'])) {
         foreach ($_REQUEST['FILES'] as $val) {
             if (in_array($val, $_REQUEST["FILES_TO_UPLOAD"])) {
                 $arFiles[$val] = array("FILE_ID" => $val);
             }
         }
     }
     if (!empty($arNewFiles)) {
         CForumFiles::Add(array_keys($arNewFiles), $arCommentParams);
     }
     $arFiles = $arFiles + $arNewFiles;
     if (!isset($arPost['FILES'])) {
         $arPost['FILES'] = array();
     }
     $arPost['FILES'] = array_merge($arPost['FILES'], $arFiles);
     foreach ($arPost['FILES'] as $fileIndex => $fileArr) {
         $fileID = $fileArr['FILE_ID'];
         $attach_file = CFile::MakeFileArray(intval($fileID));
         $attach = "";
         if ($attach_file && is_set($attach_file, "name")) {
             // Y - Image files		F - Files of specified type		A - All files
             if ($arForum["ALLOW_UPLOAD"] == "Y") {
                 $attach = CFile::CheckImageFile($attach_file, $iFileSize, 0, 0);
             } elseif ($arForum["ALLOW_UPLOAD"] == "F") {
                 $attach = CFile::CheckFile($attach_file, $iFileSize, false, $arForum["ALLOW_UPLOAD_EXT"]);
             } elseif ($arForum["ALLOW_UPLOAD"] == "A") {
                 $attach = CFile::CheckFile($attach_file, $iFileSize, false, false);
             }
             if ($attach != '') {
                 unset($arPost['FILES'][$fileIndex]);
                 $arPost['ERROR'] = $attach_file['name'] . ': ' . $attach;
                 return false;
             }
         }
     }
 }
 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));
 }
Example #7
0
 /**
  * WARNING! This method is transitional and can be changed without 
  * any notifications! Don't use it.
  * 
  * @deprecated
  */
 public static function __deprecated_Add($commentText, $forumTopicId, $forumId, $nameTemplate, $arTask, $permissions, $commentId, $givenUserId, $imageWidth, $imageHeight, $arSmiles, $arForum, $messagesPerPage, $arUserGroupArray, $backPage, $strMsgAddComment, $strMsgEditComment, $strMsgNewTask, $componentName, &$outForumTopicId, &$arErrorCodes, &$outStrUrl, $arFieldsAdditional = array())
 {
     global $DB;
     if (is_array($arTask)) {
         if (!array_key_exists('~TITLE', $arTask)) {
             $arTmpTask = $arTask;
             foreach ($arTmpTask as $key => $value) {
                 if (substr($key, 0, 1) !== '~') {
                     $arTask['~' . $key] = $arTmpTask[$key];
                 }
             }
         }
     }
     $MID = 0;
     $TID = 0;
     if ($forumTopicId > 0 && CForumTopic::GetByID($forumTopicId) === false) {
         $forumTopicId = false;
     }
     if ($forumTopicId <= 0) {
         $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(CUser::FormatName($nameTemplate, $res)) : "";
                 $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName;
             }
         }
         $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"];
         $DB->StartTransaction();
         $arFields = array("TITLE" => $arTask["~TITLE"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions, "NAME_TEMPLATE" => $nameTemplate, 'XML_ID' => 'TASK_' . $arTask['ID']);
         $TID = CForumTopic::Add($arFields);
         if (intVal($TID) <= 0) {
             $arErrorCodes[] = array('code' => 'topic is not created');
         } else {
             $arFields = array("FORUM_TOPIC_ID" => $TID);
             $task = new CTasks();
             $task->Update($arTask["ID"], $arFields);
         }
         if (!empty($arErrorCodes)) {
             $DB->Rollback();
             return false;
         } else {
             $DB->Commit();
         }
     }
     $arFieldsG = array("POST_MESSAGE" => $commentText, "AUTHOR_NAME" => '', "AUTHOR_EMAIL" => $GLOBALS['USER']->GetEmail(), "USE_SMILES" => NULL, "PARAM2" => $arTask['ID'], "TITLE" => $arTask["~TITLE"], "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions);
     // UF_* forwarding
     if (is_array($arFieldsAdditional)) {
         foreach ($arFieldsAdditional as $field => $value) {
             if (strlen($field) && substr($field, 0, 3) == 'UF_') {
                 $arFieldsG[$field] = $value;
                 $GLOBALS[$field] = $value;
                 // strange behaviour required for ForumMessageAdd() to handle UF_* properly
             }
         }
     }
     if (!empty($_FILES["REVIEW_ATTACH_IMG"])) {
         $arFieldsG["ATTACH_IMG"] = $_FILES["REVIEW_ATTACH_IMG"];
     } else {
         $arFiles = array();
         if (!empty($_REQUEST["FILES"])) {
             foreach ($_REQUEST["FILES"] as $key) {
                 $arFiles[$key] = array("FILE_ID" => $key);
                 if (!in_array($key, $_REQUEST["FILES_TO_UPLOAD"])) {
                     $arFiles[$key]["del"] = "Y";
                 }
             }
         }
         if (!empty($_FILES)) {
             $res = array();
             foreach ($_FILES as $key => $val) {
                 if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) {
                     $arFiles[] = $_FILES[$key];
                 }
             }
         }
         if (!empty($arFiles)) {
             $arFieldsG["FILES"] = $arFiles;
         }
     }
     $TOPIC_ID = $forumTopicId > 0 ? $forumTopicId : $TID;
     $MESSAGE_ID = 0;
     $MESSAGE_TYPE = $TOPIC_ID > 0 ? "REPLY" : "NEW";
     if (COption::GetOptionString("tasks", "task_comment_allow_edit") && ($MESSAGE_ID = intval($commentId))) {
         $MESSAGE_TYPE = "EDIT";
     }
     $strErrorMessage = '';
     $strOKMessage = '';
     $MID = ForumAddMessage($MESSAGE_TYPE, $forumId, $TOPIC_ID, $MESSAGE_ID, $arFieldsG, $strErrorMessage, $strOKMessage, false, $_POST["captcha_word"], 0, $_POST["captcha_code"], $nameTemplate);
     if ($MID <= 0 || !empty($strErrorMessage)) {
         $arErrorCodes[] = array('code' => 'message is not added 2', 'title' => empty($strErrorMessage) ? NULL : $strErrorMessage);
     } else {
         $arMessage = CForumMessage::GetByID($MID);
         if ($forumTopicId <= 0) {
             $forumTopicId = $TID = intVal($arMessage["TOPIC_ID"]);
         }
         $outForumTopicId = intVal($forumTopicId);
         if ($componentName !== null) {
             ForumClearComponentCache($componentName);
         }
         // NOTIFICATION
         $arTask["ACCOMPLICES"] = $arTask["AUDITORS"] = array();
         $rsMembers = CTaskMembers::GetList(array(), array("TASK_ID" => $arTask["ID"]));
         while ($arMember = $rsMembers->Fetch()) {
             if ($arMember["TYPE"] == "A") {
                 $arTask["ACCOMPLICES"][] = $arMember["USER_ID"];
             } elseif ($arMember["TYPE"] == "U") {
                 $arTask["AUDITORS"][] = $arMember["USER_ID"];
             }
         }
         $arEmailUserIDs = array($arTask["RESPONSIBLE_ID"], $arTask["CREATED_BY"]);
         $arEmailUserIDs = array_unique(array_merge($arEmailUserIDs, $arTask["ACCOMPLICES"], $arTask["AUDITORS"]));
         $currentUserPos = array_search($givenUserId, $arEmailUserIDs);
         if ($currentUserPos !== false) {
             unset($arEmailUserIDs[$currentUserPos]);
         }
         $parser = new CTextParser();
         $parser->imageWidth = $imageWidth;
         $parser->imageHeight = $imageHeight;
         $parser->smiles = $arSmiles;
         $parser->allow = array("HTML" => $arForum["ALLOW_HTML"], "ANCHOR" => $arForum["ALLOW_ANCHOR"], "BIU" => $arForum["ALLOW_BIU"], "IMG" => "N", "VIDEO" => "N", "LIST" => $arForum["ALLOW_LIST"], "QUOTE" => $arForum["ALLOW_QUOTE"], "CODE" => $arForum["ALLOW_CODE"], "FONT" => $arForum["ALLOW_FONT"], "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => $arForum["ALLOW_NL2BR"], "TABLE" => "Y");
         $arAllow = NULL;
         $MESSAGE = HTMLToTxt($parser->convertText($commentText, $arAllow));
         // remove [ url] for socialnetwork log
         $MESSAGE = preg_replace("/(\\s\\[\\s(http:\\/\\/|https:\\/\\/|ftp:\\/\\/))(.*?)(\\s\\])/is", "", $MESSAGE);
         $parser->allow = array("HTML" => 'Y', "ANCHOR" => 'Y', "BIU" => 'Y', "IMG" => "Y", "VIDEO" => "Y", "LIST" => 'N', "QUOTE" => 'Y', "CODE" => 'Y', "FONT" => 'Y', "SMILES" => "N", "UPLOAD" => 'N', "NL2BR" => 'N', "TABLE" => "Y");
         $message_notify = $parser->convertText($commentText);
         $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask);
         // Instant Messages
         if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) {
             // this entire class is deprecated. disable edit message, add only here
             if ($MESSAGE_TYPE != 'EDIT') {
                 CTaskComments::sendAddMessage(array('ID' => $MID, 'POST_MESSAGE' => $message_notify), $arTask, $givenUserId, $arRecipientsIDs, array());
             }
         }
         $strURL = !empty($backPage) ? $backPage : $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result"));
         $strURL = ForumAddPageParams($strURL, array("MID" => $MID, "result" => $arForum["MODERATION"] != "Y" || CForumNew::CanUserModerateForum($forumId, $arUserGroupArray) ? "reply" : "not_approved"), false, false);
         $outStrUrl = $strURL;
         // sonet log
         if (CModule::IncludeModule("socialnetwork")) {
             $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID"));
             if ($arRes = $dbRes->Fetch()) {
                 $log_id = $arRes["TMP_ID"];
                 $entity_type = $arRes["ENTITY_TYPE"];
                 $entity_id = $arRes["ENTITY_ID"];
             } else {
                 $entity_type = $arTask["GROUP_ID"] ? SONET_ENTITY_GROUP : SONET_ENTITY_USER;
                 $entity_id = $arTask["GROUP_ID"] ? $arTask["GROUP_ID"] : $arTask["CREATED_BY"];
                 $rsUser = CUser::GetByID($arTask["CREATED_BY"]);
                 if ($arUser = $rsUser->Fetch()) {
                     $arSoFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks", "LOG_DATE" => $arTask["CREATED_DATE"], "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => htmlspecialcharsBack($arTask["~TITLE"]), "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $arTask["ID"], "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]), "PARAMS" => serialize(array("TYPE" => "create")));
                     $log_id = CSocNetLog::Add($arSoFields, false);
                     if (intval($log_id) > 0) {
                         CSocNetLog::Update($log_id, array("TMP_ID" => $log_id));
                         $arRights = CTaskNotifications::__UserIDs2Rights(CTaskNotifications::GetRecipientsIDs($arTask, false));
                         if ($arTask["GROUP_ID"]) {
                             $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"];
                         }
                         CSocNetLogRights::Add($log_id, $arRights);
                     }
                 }
             }
             if (intval($log_id) > 0) {
                 $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"];
                 CSocNetLog::Update($log_id, array('PARAMS' => serialize(array('TYPE' => 'comment'))));
                 $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "tasks", "SOURCE_ID" => $MID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $MID);
                 if ($MESSAGE_TYPE == "EDIT") {
                     $dbRes = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => array("tasks_comment"), "SOURCE_ID" => $MID), false, false, array("ID"));
                     while ($arRes = $dbRes->Fetch()) {
                         CSocNetLogComments::Update($arRes["ID"], $arFieldsForSocnet);
                     }
                 } else {
                     $arFieldsForSocnet['USER_ID'] = $givenUserId;
                     $arFieldsForSocnet['=LOG_DATE'] = $GLOBALS['DB']->CurrentTimeFunction();
                     $ufFileID = array();
                     $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $MID));
                     while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                         $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                     }
                     if (count($ufFileID) > 0) {
                         $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID;
                     }
                     $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $MID, LANGUAGE_ID);
                     if ($ufDocID) {
                         $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
                     }
                     $ufDocVer = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_VER", $MID, LANGUAGE_ID);
                     if ($ufDocVer) {
                         $arFieldsForSocnet["UF_SONET_COM_VER"] = $ufDocVer;
                     }
                     if (isset($arFieldsAdditional["ANCILLARY"]) && $arFieldsAdditional["ANCILLARY"]) {
                         CSocNetLogComments::Add($arFieldsForSocnet, false, false, false);
                     } else {
                         $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                         CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
                     }
                 }
             }
         }
         $occurAsUserId = CTasksTools::getOccurAsUserId();
         if (!$occurAsUserId) {
             $occurAsUserId = $arMessage["AUTHOR_ID"] ? $arMessage["AUTHOR_ID"] : 1;
         }
         // Tasks log
         $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arMessage["EDIT_DATE"] ? ConvertTimeStamp(MakeTimeStamp($arMessage["EDIT_DATE"], CSite::GetDateFormat()), "FULL") : $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $MID);
         $log = new CTaskLog();
         $log->Add($arLogFields);
     }
     return $MID;
     // Message id
 }
Example #8
0
 public static function AddComment_Calendar($arFields)
 {
     global $DB;
     if (!CModule::IncludeModule("forum")) {
         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()) {
         $arCalendarEvent = CCalendarEvent::GetById($arLog["SOURCE_ID"]);
         if ($arCalendarEvent) {
             $arCalendarSettings = CCalendar::GetSettings();
             $forumID = $arCalendarSettings["forum_id"];
             if ($forumID) {
                 $arFilter = array("FORUM_ID" => $forumID, "XML_ID" => "EVENT_" . $arLog["SOURCE_ID"]);
                 $dbTopic = CForumTopic::GetList(null, $arFilter);
                 if ($dbTopic && ($arTopic = $dbTopic->Fetch())) {
                     $topicID = $arTopic["ID"];
                 } else {
                     $topicID = 0;
                 }
                 $currentUserId = CCalendar::GetCurUserId();
                 $strPermission = $currentUserId == $arCalendarEvent["OWNER_ID"] ? "Y" : "M";
                 $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PERMISSION_EXTERNAL" => "Q", "PERMISSION" => $strPermission, "APPROVED" => "Y");
                 if ($topicID === 0) {
                     $arFieldsMessage["TITLE"] = "EVENT_" . $arLog["SOURCE_ID"];
                     $arFieldsMessage["TOPIC_XML_ID"] = "EVENT_" . $arLog["SOURCE_ID"];
                 }
                 $arTmp = false;
                 $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($topicID > 0 ? "REPLY" : "NEW", $forumID, $topicID, 0, $arFieldsMessage, $sError, $sNote);
                 // get UF DOC value and FILE_ID there
                 if ($messageID > 0) {
                     $messageUrl = CCalendar::GetPath("user", $arCalendarEvent["OWNER_ID"]);
                     $messageUrl = $messageUrl . (strpos($messageUrl, "?") === false ? "?" : "&") . "EVENT_ID=" . $arCalendarEvent["ID"] . "&MID=" . $messageID;
                     $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) {
         $sError = GetMessage("EC_LF_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);
 }
Example #9
0
}
$MESS = array();
$path = str_replace(array("\\", "//"), "/", dirname(__FILE__) . "/lang/" . LANGUAGE_ID . "/show_file.php");
include_once $path;
$MESS1 =& $MESS;
$GLOBALS["MESS"] = $MESS1 + $GLOBALS["MESS"];
CModule::IncludeModule("forum");
// ************************* Input params***************************************************************
// ************************* BASE **********************************************************************
$arParams = array("FILE_ID" => intval($_REQUEST["fid"]), "WIDTH" => intval($_REQUEST['width']), "HEIGHT" => intval($_REQUEST['height']), "ACTION" => $_REQUEST["action"] == "download" ? "download" : "view", "PERMISSION" => false);
// *************************/Input params***************************************************************
// ************************* Default params*************************************************************
$arResult = array("MESSAGE" => array(), "FILE" => array());
$arError = array();
if (intVal($arParams["FILE_ID"]) > 0) {
    $db_res = CForumFiles::GetList(array("ID" => "ASC"), array("FILE_ID" => $arParams["FILE_ID"]));
    if ($db_res && ($arResult["FILE"] = $db_res->GetNext())) {
        $res = CFile::GetFileArray($arParams["FILE_ID"]);
        if (!!$res) {
            $arResult["FILE"] += $res;
        }
    }
}
if (empty($arResult["FILE"])) {
    $arError = array("code" => "EMPTY FILE", "title" => GetMessage("F_EMPTY_FID"));
} elseif (intVal($arResult["FILE"]["MESSAGE_ID"]) > 0) {
    $arResult["MESSAGE"] = CForumMessage::GetByIDEx($arResult["FILE"]["MESSAGE_ID"], array("GET_FORUM_INFO" => "Y", "GET_TOPIC_INFO" => "Y"));
    $arResult["TOPIC"] = $arResult["MESSAGE"]["TOPIC_INFO"];
    $arResult["FORUM"] = $arResult["MESSAGE"]["FORUM_INFO"];
    if (IsModuleInstalled('meeting') && CModule::IncludeModule('meeting')) {
        $forumId = COption::GetOptionInt('meeting', 'comments_forum_id', 0, SITE_ID);
	public static function onAfterCommentUpdate($entityType, $entityId, $arData)
	{
		$log_event_id = CSocNetForumComments::FindLogEventIDByForumEntityID($entityType);
		if (!$log_event_id)
			return false;

		$arLogCommentEvent = CSocNetLogTools::FindLogCommentEventByLogEventID($log_event_id);
		if (!$arLogCommentEvent)
			return false;

		$arLogEvent = CSocNetLogTools::FindLogEventByID($log_event_id);

		$entityId = intval($entityId);
		if ($entityId <= 0)
			return;	

		if (empty($arData["MESSAGE_ID"]))
			return;

		$parser = new CTextParser();
		$parser->allow = array("HTML" => 'N',"ANCHOR" => 'Y',"BIU" => 'Y',"IMG" => "Y","VIDEO" => "Y","LIST" => 'N',"QUOTE" => 'Y',"CODE" => 'Y',"FONT" => 'Y',"SMILES" => "N","UPLOAD" => 'N',"NL2BR" => 'N',"TABLE" => "Y");

		switch ($arData["ACTION"])
		{
			case "DEL":
			case "HIDE":
				$dbLogComment = CSocNetLogComments::GetList(
					array("ID" => "DESC"),
					array(
						"EVENT_ID"	=> array($arLogCommentEvent["EVENT_ID"]),
						"SOURCE_ID" => intval($arData["MESSAGE_ID"])
					),
					false,
					false,
					array("ID")
				);
				while ($arLogComment = $dbLogComment->Fetch())
					CSocNetLogComments::Delete($arLogComment["ID"]);
				break;
			case "SHOW":
				$dbLogComment = CSocNetLogComments::GetList(
					array("ID" => "DESC"),
					array(
						"EVENT_ID"	=> array($arLogCommentEvent["EVENT_ID"]),
						"SOURCE_ID" => intval($arData["MESSAGE_ID"])
					),
					false,
					false,
					array("ID")
				);
				$arLogComment = $dbLogComment->Fetch();
				if (!$arLogComment)
				{
					$arMessage = CForumMessage::GetByID(intval($arData["MESSAGE_ID"]));
					if ($arMessage)
					{
						$dbLog = CSocNetLog::GetList(
							array("ID" => "DESC"),
							array(
								"EVENT_ID" => $log_event_id,
								"SOURCE_ID" => $entityId
							),
							false,
							false,
							array("ID", "ENTITY_TYPE", "ENTITY_ID")
						);

						if ($arLog = $dbLog->Fetch())
						{
							$log_id = $arLog["ID"];
							$entity_type = $arLog["ENTITY_TYPE"];
							$entity_id = $arLog["ENTITY_ID"];

							$sText = (COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]);
							$strURL = $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result"));
							$strURL = ForumAddPageParams(
								$strURL,
								array(
									"MID" => intval($arData["MESSAGE_ID"]),
									"result" => "reply"
								),
								false,
								false
							);

							$arFieldsForSocnet = array(
								"ENTITY_TYPE" => $entity_type,
								"ENTITY_ID" => $entity_id,
								"EVENT_ID" => $arLogCommentEvent["EVENT_ID"],
								"MESSAGE" => $sText,
								"TEXT_MESSAGE" => $parser->convert4mail($sText),
								"URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))),
								"MODULE_ID" => (array_key_exists("MODULE_ID", $arLogCommentEvent) && strlen($arLogCommentEvent["MODULE_ID"]) > 0 ? $arLogCommentEvent["MODULE_ID"] : ""),
								"SOURCE_ID" => intval($arData["MESSAGE_ID"]),
								"LOG_ID" => $log_id,
								"RATING_TYPE_ID" => "FORUM_POST",
								"RATING_ENTITY_ID" => intval($arData["MESSAGE_ID"])
							);

							$arFieldsForSocnet["USER_ID"] = $arMessage["AUTHOR_ID"];
							$arFieldsForSocnet["=LOG_DATE"] = $GLOBALS["DB"]->CurrentTimeFunction();

							$ufFileID = array();
							$dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => intval($arData["MESSAGE_ID"])));
							while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch())
								$ufFileID[] = $arAddedMessageFiles["FILE_ID"];

							if (count($ufFileID) > 0)
								$arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID;

							$ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", intval($arData["MESSAGE_ID"]), LANGUAGE_ID);
							if ($ufDocID)
								$arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;

							$comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
							CSocNetLog::CounterIncrement(
								$comment_id, 
								false, 
								false, 
								"LC",
								CSocNetLogRights::CheckForUserAll($log_id)
							);
						}
					}
				}
				break;
			case "EDIT":
				$arMessage = CForumMessage::GetByID(intval($arData["MESSAGE_ID"]));
				if ($arMessage)
				{
					$dbLogComment = CSocNetLogComments::GetList(
						array("ID" => "DESC"),
						array(
							"EVENT_ID"	=> array($arLogCommentEvent["EVENT_ID"]),
							"SOURCE_ID" => intval($arData["MESSAGE_ID"])
						),
						false,
						false,
						array("ID")
					);
					$arLogComment = $dbLogComment->Fetch();
					if ($arLogComment)
					{
						$sText = (COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]);
						$arFieldsForSocnet = array(
							"MESSAGE" => $sText,
							"TEXT_MESSAGE" => $parser->convert4mail($sText),
						);

						$ufFileID = array();
						$dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => intval($arData["MESSAGE_ID"])));
						while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch())
							$ufFileID[] = $arAddedMessageFiles["FILE_ID"];

						if (count($ufFileID) > 0)
							$arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID;

						$ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", intval($arData["MESSAGE_ID"]), LANGUAGE_ID);
						if ($ufDocID)
							$arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;

						CSocNetLogComments::Update($arLogComment["ID"], $arFieldsForSocnet);
					}
				}
				break;
			default:
		}

		foreach (GetModuleEvents("socialnetwork", "onAfterCommentUpdateAfter", true) as $arModuleEvent)
			ExecuteModuleEventEx($arModuleEvent, array(
				$entityType,
				$entityId,
				$arData,
				$log_id
			));
	}
Example #11
0
 function Delete($ID)
 {
     global $DB;
     $ID = intVal($ID);
     $arTopic = CForumTopic::GetByID($ID);
     if (empty($arTopic)) {
         return false;
     }
     /***************** Event onBeforeTopicDelete ***********************/
     $events = GetModuleEvents("forum", "onBeforeTopicDelete");
     while ($arEvent = $events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID, $arTopic)) === false) {
             return false;
         }
     }
     /***************** /Event ******************************************/
     $arAuthor = array();
     $arVotes = array();
     $db_res = CForumMessage::GetList(array("ID" => "ASC"), array("TOPIC_ID" => $ID));
     while ($res = $db_res->Fetch()) {
         if (intVal($res["AUTHOR_ID"]) > 0) {
             $arAuthor[intVal($res["AUTHOR_ID"])] = $res["AUTHOR_ID"];
         }
         if ($res["PARAM1"] == "VT" && intVal($res["PARAM2"]) > 0) {
             $arVotes[] = intVal($res["PARAM2"]);
         }
     }
     if (!empty($arVotes) && IsModuleInstalled("vote") && CModule::IncludeModule("vote")) {
         foreach ($arVotes as $res) {
             CVote::Delete($res);
         }
     }
     //		$DB->StartTransaction();
     CForumFiles::Delete(array("TOPIC_ID" => $ID), array("DELETE_TOPIC_FILE" => "Y"));
     $DB->Query("DELETE FROM b_forum_subscribe WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_message WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_user_topic WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_topic WHERE ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_topic WHERE TOPIC_ID = " . $ID . "");
     $DB->Query("DELETE FROM b_forum_stat WHERE TOPIC_ID = " . $ID . "");
     //		$DB->Commit();
     unset($GLOBALS["FORUM_CACHE"]["TOPIC"][$ID]);
     unset($GLOBALS["FORUM_CACHE"]["TOPIC_FILTER"][$ID]);
     foreach ($arAuthor as $key) {
         CForumUser::SetStat($key);
     }
     CForumNew::SetStat($arTopic["FORUM_ID"]);
     if (IsModuleInstalled("search") && CModule::IncludeModule("search")) {
         CSearch::DeleteIndex("forum", false, $arTopic["FORUM_ID"], $ID);
     }
     /***************** Event onAfterTopicDelete ************************/
     $events = GetModuleEvents("forum", "onAfterTopicDelete");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array(&$ID, $arTopic));
     }
     /***************** /Event ******************************************/
     return true;
 }
Example #12
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;
 }
Example #13
0
    $arTask['DESCRIPTION'] = $parser->convertText($arTask['DESCRIPTION']);
}
// collect files data
if ($arTask['FILES']) {
    $rsFiles = CFile::GetList(array(), array('@ID' => implode(',', $arTask['FILES'])));
    $arTask['FILES'] = array();
    while ($arFile = $rsFiles->GetNext()) {
        $arFile['META::SIZE_FORMATTED'] = CFile::FormatSize($arFile['FILE_SIZE']);
        $arTask['FILES'][] = $arFile;
    }
    unset($rsFiles, $arFile);
}
// collect comments files
$arTask['FORUM_FILES'] = array();
if ($arTask['FORUM_TOPIC_ID']) {
    $rsFiles = CForumFiles::GetList(array('ID' => 'ASC'), array('TOPIC_ID' => $arTask['FORUM_TOPIC_ID']));
    while ($arFile = $rsFiles->GetNext()) {
        $arFile['META::SIZE_FORMATTED'] = CFile::FormatSize($arFile['FILE_SIZE']);
        $arTask['FORUM_FILES'][] = $arFile;
    }
    unset($rsFiles, $arFile);
}
// Task last viewed by given user date
$arResult['LAST_VIEWED_DATE'] = $arTask['CREATED_DATE'];
if ($arTask['VIEWED_DATE']) {
    $arResult['LAST_VIEWED_DATE'] = $arTask['VIEWED_DATE'];
}
// Avatars and names for task members
$arTaskMembers = array((int) $arTask['CREATED_BY'], (int) $arTask['RESPONSIBLE_ID']);
if (isset($arTask['ACCOMPLICES']) && is_array($arTask['ACCOMPLICES'])) {
    $arTaskMembers = array_merge($arTaskMembers, $arTask['ACCOMPLICES']);
Example #14
0
 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);
 }
Example #15
0
 public static function UpdateCrmActivityComment($arFields)
 {
     if (!isset($arFields["SOURCE_ID"]) || intval($arFields["SOURCE_ID"]) <= 0) {
         return false;
     }
     $ufFileID = array();
     $ufDocID = array();
     $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array('ID', 'ENTITY_ID'));
     if ($arLog = $dbResult->Fetch()) {
         $dbCrmActivity = CCrmActivity::GetList(array(), array('ID' => $arLog['ENTITY_ID'], 'CHECK_PERMISSIONS' => 'N'));
         if (($arCrmActivity = $dbCrmActivity->Fetch()) && $arCrmActivity['TYPE_ID'] == CCrmActivityType::Task && CModule::IncludeModule("forum")) {
             $messageId = intval($arFields["SOURCE_ID"]);
             if ($arForumMessage = CForumMessage::GetByID($messageId)) {
                 $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "APPROVED" => "Y", "SONET_PERMS" => array("bCanFull" => true));
                 $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"][$file_id] = array("FILE_ID" => $file_id);
                         }
                         if (!empty($arFieldsMessage["FILES"])) {
                             $arFileParams = array("FORUM_ID" => $arForumMessage["FORUM_ID"], "TOPIC_ID" => $arForumMessage["TOPIC_ID"]);
                             if (CForumFiles::CheckFields($arFieldsMessage["FILES"], $arFileParams, "NOT_CHECK_DB")) {
                                 CForumFiles::Add(array_keys($arFieldsMessage["FILES"]), $arFileParams);
                             }
                         }
                     }
                 }
                 $messageID = ForumAddMessage("EDIT", $arForumMessage["FORUM_ID"], $arForumMessage["TOPIC_ID"], $messageId, $arFieldsMessage, $sError, $sNote);
                 unset($GLOBALS["UF_FORUM_MESSAGE_DOC"]);
                 // 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 {
                 $sError = GetMessage("CRM_SL_UPDATE_COMMENT_SOURCE_ERROR");
             }
             return array("ERROR" => $sError, "NOTES" => $sNote, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID));
         }
     }
     return array("NO_SOURCE" => "Y");
 }
Example #16
0
 /**
  * WARNING! This method is transitional and can be changed without 
  * any notifications! Don't use it.
  * 
  * @deprecated
  */
 public static function __deprecated_Add($commentText, $forumTopicId, $forumId, $nameTemplate, $arTask, $permissions, $commentId, $givenUserId, $imageWidth, $imageHeight, $arSmiles, $arForum, $messagesPerPage, $arUserGroupArray, $backPage, $strMsgAddComment, $strMsgEditComment, $strMsgNewTask, $componentName, &$outForumTopicId, &$arErrorCodes, &$outStrUrl, $arFieldsAdditional)
 {
     global $DB;
     if (is_array($arTask)) {
         if (!array_key_exists('~TITLE', $arTask)) {
             $arTmpTask = $arTask;
             foreach ($arTmpTask as $key => $value) {
                 if (substr($key, 0, 1) !== '~') {
                     $arTask['~' . $key] = $arTmpTask[$key];
                 }
             }
         }
     }
     $MID = 0;
     $TID = 0;
     if ($forumTopicId > 0 && CForumTopic::GetByID($forumTopicId) === false) {
         $forumTopicId = false;
     }
     if ($forumTopicId <= 0) {
         $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(CUser::FormatName($nameTemplate, $res)) : "";
                 $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName;
             }
         }
         $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"];
         $DB->StartTransaction();
         $arFields = array("TITLE" => $arTask["~TITLE"], "FORUM_ID" => $forumId, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "APPROVED" => "Y", "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions, "NAME_TEMPLATE" => $nameTemplate, 'XML_ID' => 'TASK_' . $arTask['ID']);
         $TID = CForumTopic::Add($arFields);
         if (intVal($TID) <= 0) {
             $arErrorCodes[] = array('code' => 'topic is not created');
         } else {
             $arFields = array("FORUM_TOPIC_ID" => $TID);
             $task = new CTasks();
             $task->Update($arTask["ID"], $arFields);
         }
         if (!empty($arErrorCodes)) {
             $DB->Rollback();
             return false;
         } else {
             $DB->Commit();
         }
     }
     $arFieldsG = array("POST_MESSAGE" => $commentText, "AUTHOR_NAME" => '', "AUTHOR_EMAIL" => $GLOBALS['USER']->GetEmail(), "USE_SMILES" => NULL, "PARAM2" => $arTask['ID'], "TITLE" => $arTask["~TITLE"], "PERMISSION_EXTERNAL" => $permissions, "PERMISSION" => $permissions);
     // UF_* forwarding
     if (is_array($arFieldsAdditional)) {
         foreach ($arFieldsAdditional as $field => $value) {
             if (strlen($field) && substr($field, 0, 3) == 'UF_') {
                 $arFieldsG[$field] = $value;
                 $GLOBALS[$field] = $value;
                 // strange behaviour required for ForumMessageAdd() to handle UF_* properly
             }
         }
     }
     if (!empty($_FILES["REVIEW_ATTACH_IMG"])) {
         $arFieldsG["ATTACH_IMG"] = $_FILES["REVIEW_ATTACH_IMG"];
     } else {
         $arFiles = array();
         if (!empty($_REQUEST["FILES"])) {
             foreach ($_REQUEST["FILES"] as $key) {
                 $arFiles[$key] = array("FILE_ID" => $key);
                 if (!in_array($key, $_REQUEST["FILES_TO_UPLOAD"])) {
                     $arFiles[$key]["del"] = "Y";
                 }
             }
         }
         if (!empty($_FILES)) {
             $res = array();
             foreach ($_FILES as $key => $val) {
                 if (substr($key, 0, strLen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) {
                     $arFiles[] = $_FILES[$key];
                 }
             }
         }
         if (!empty($arFiles)) {
             $arFieldsG["FILES"] = $arFiles;
         }
     }
     $TOPIC_ID = $forumTopicId > 0 ? $forumTopicId : $TID;
     $MESSAGE_ID = 0;
     $MESSAGE_TYPE = $TOPIC_ID > 0 ? "REPLY" : "NEW";
     if (COption::GetOptionString("tasks", "task_comment_allow_edit") && ($MESSAGE_ID = intval($commentId))) {
         $MESSAGE_TYPE = "EDIT";
     }
     $strErrorMessage = '';
     $strOKMessage = '';
     $MID = ForumAddMessage($MESSAGE_TYPE, $forumId, $TOPIC_ID, $MESSAGE_ID, $arFieldsG, $strErrorMessage, $strOKMessage, false, $_POST["captcha_word"], 0, $_POST["captcha_code"], $nameTemplate);
     if ($MID <= 0 || !empty($strErrorMessage)) {
         $arErrorCodes[] = array('code' => 'message is not added 2', 'title' => empty($strErrorMessage) ? NULL : $strErrorMessage);
     } else {
         $arMessage = CForumMessage::GetByID($MID);
         if ($forumTopicId <= 0) {
             $forumTopicId = $TID = intVal($arMessage["TOPIC_ID"]);
         }
         $outForumTopicId = intVal($forumTopicId);
         if ($componentName !== null) {
             ForumClearComponentCache($componentName);
         }
         // NOTIFICATION
         $arTask["ACCOMPLICES"] = $arTask["AUDITORS"] = array();
         $rsMembers = CTaskMembers::GetList(array(), array("TASK_ID" => $arTask["ID"]));
         while ($arMember = $rsMembers->Fetch()) {
             if ($arMember["TYPE"] == "A") {
                 $arTask["ACCOMPLICES"][] = $arMember["USER_ID"];
             } elseif ($arMember["TYPE"] == "U") {
                 $arTask["AUDITORS"][] = $arMember["USER_ID"];
             }
         }
         $arEmailUserIDs = array($arTask["RESPONSIBLE_ID"], $arTask["CREATED_BY"]);
         $arEmailUserIDs = array_unique(array_merge($arEmailUserIDs, $arTask["ACCOMPLICES"], $arTask["AUDITORS"]));
         $currentUserPos = array_search($givenUserId, $arEmailUserIDs);
         if ($currentUserPos !== false) {
             unset($arEmailUserIDs[$currentUserPos]);
         }
         $parser = new CTextParser();
         $parser->imageWidth = $imageWidth;
         $parser->imageHeight = $imageHeight;
         $parser->smiles = $arSmiles;
         $parser->allow = array("HTML" => $arForum["ALLOW_HTML"], "ANCHOR" => $arForum["ALLOW_ANCHOR"], "BIU" => $arForum["ALLOW_BIU"], "IMG" => "N", "VIDEO" => "N", "LIST" => $arForum["ALLOW_LIST"], "QUOTE" => $arForum["ALLOW_QUOTE"], "CODE" => $arForum["ALLOW_CODE"], "FONT" => $arForum["ALLOW_FONT"], "SMILES" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => $arForum["ALLOW_NL2BR"], "TABLE" => "Y");
         $arAllow = NULL;
         $MESSAGE = HTMLToTxt($parser->convertText($commentText, $arAllow));
         // remove [ url] for socialnetwork log
         $MESSAGE = preg_replace("/(\\s\\[\\s(http:\\/\\/|https:\\/\\/|ftp:\\/\\/))(.*?)(\\s\\])/is", "", $MESSAGE);
         $parser->allow = array("HTML" => 'Y', "ANCHOR" => 'Y', "BIU" => 'Y', "IMG" => "Y", "VIDEO" => "Y", "LIST" => 'N', "QUOTE" => 'Y', "CODE" => 'Y', "FONT" => 'Y', "SMILES" => "N", "UPLOAD" => 'N', "NL2BR" => 'N', "TABLE" => "Y");
         $message_notify = $parser->convertText($commentText);
         $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask);
         // Instant Messages
         if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) {
             $pageNumber = CForumMessage::GetMessagePage($MID, $messagesPerPage, $arUserGroupArray);
             // There are different links for extranet users
             $isExtranetEnabled = false;
             if (CModule::IncludeModule("extranet")) {
                 $isExtranetEnabled = true;
             }
             if ($isExtranetEnabled) {
                 $arSites = array();
                 $dbSite = CSite::GetList($by = "sort", $order = "desc", array("ACTIVE" => "Y"));
                 while ($arSite = $dbSite->Fetch()) {
                     if (strlen(trim($arSite["DIR"])) > 0) {
                         $arSites[$arSite['ID']]['DIR'] = $arSite['DIR'];
                     } else {
                         $arSites[$arSite['ID']]['DIR'] = '/';
                     }
                     if (strlen(trim($arSite["SERVER_NAME"])) > 0) {
                         $arSites[$arSite['ID']]['SERVER_NAME'] = $arSite["SERVER_NAME"];
                     } else {
                         $arSites[$arSite['ID']]['SERVER_NAME'] = COption::GetOptionString("main", "server_name", $_SERVER["HTTP_HOST"]);
                     }
                     $arSites[$arSite['ID']]['urlPrefix'] = $arSites[$arSite['ID']]['SERVER_NAME'] . $arSites[$arSite['ID']]['DIR'];
                     // remove last '/'
                     if (strlen($arSites[$arSite['ID']]['urlPrefix']) > 0 && substr($arSites[$arSite['ID']]['urlPrefix'], -1) === '/') {
                         $arSites[$arSite['ID']]['urlPrefix'] = substr($arSites[$arSite['ID']]['urlPrefix'], 0, -1);
                     }
                 }
                 $extranet_site_id = CExtranet::GetExtranetSiteID();
                 $intranet_site_id = CSite::GetDefSite();
                 $arIntranetUsers = CExtranet::GetIntranetUsers();
             } else {
                 if ($arTask["GROUP_ID"]) {
                     $pathTemplateWoExtranet = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"]));
                 } else {
                     $pathTemplateWoExtranet = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arFields["SITE_ID"]);
                 }
             }
             foreach ($arRecipientsIDs as $userID) {
                 $urlPrefixForUser = tasksServerName();
                 if ($isExtranetEnabled) {
                     if (!in_array($userID, $arIntranetUsers) && $extranet_site_id) {
                         $userSiteId = $extranet_site_id;
                     } else {
                         $userSiteId = $intranet_site_id;
                     }
                     if (isset($arSites[$userSiteId]['SERVER_NAME'])) {
                         $urlPrefixForUser = tasksServerName($arSites[$userSiteId]['SERVER_NAME']);
                     }
                     if ($arTask["GROUP_ID"]) {
                         $pathTemplate = str_replace('#group_id#', $arTask['GROUP_ID'], CTasksTools::GetOptionPathTaskGroupEntry($userSiteId, ''));
                     } else {
                         $pathTemplate = CTasksTools::GetOptionPathTaskUserEntry($userSiteId, '');
                     }
                 } else {
                     $pathTemplate = $pathTemplateWoExtranet;
                 }
                 $NOTIFY_MESSAGE_TITLE_TEMPLATE = '';
                 $messageUrl = '';
                 if (strlen($pathTemplate) > 0) {
                     $groupId = 0;
                     if (isset($arTask['GROUP_ID'])) {
                         $groupId = (int) $arTask['GROUP_ID'];
                     }
                     $messageUrl = $urlPrefixForUser . CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $userID, "task_id" => $arTask["ID"], "action" => "view", "USER_ID" => $userID, "TASK_ID" => $arTask["ID"], "ACTION" => "view", 'GROUP_ID' => $groupId, 'group_id' => $groupId));
                     if ($pageNumber > 1) {
                         $messageUrl .= (strpos($messageUrl, "?") === false ? "?" : "&") . "MID=" . $MID;
                     }
                     $NOTIFY_MESSAGE_TITLE_TEMPLATE = '[URL=' . $messageUrl . "#message" . $MID . ']' . $arTask["~TITLE"] . '[/URL]';
                 } else {
                     $NOTIFY_MESSAGE_TITLE_TEMPLATE = $arTask["~TITLE"];
                 }
                 $MESSAGE_SITE = trim(htmlspecialcharsbx(strip_tags(str_replace(array("\r\n", "\n", "\r"), ' ', htmlspecialcharsback($message_notify)))));
                 $MESSAGE_EMAIL = $MESSAGE_SITE;
                 // full message to email
                 if (strlen($MESSAGE_SITE) >= 100) {
                     $dot = '...';
                     $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99);
                     if (($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;
                 }
                 $arMessageFields = array("TO_USER_ID" => $userID, "FROM_USER_ID" => $givenUserId, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($NOTIFY_MESSAGE_TITLE_TEMPLATE, '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array($arTask["~TITLE"], $MESSAGE_EMAIL . ' #BR# ' . $messageUrl . "#message" . $MID . ' '), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment));
                 CIMNotify::Add($arMessageFields);
             }
         }
         $strURL = !empty($backPage) ? $backPage : $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result"));
         $strURL = ForumAddPageParams($strURL, array("MID" => $MID, "result" => $arForum["MODERATION"] != "Y" || CForumNew::CanUserModerateForum($forumId, $arUserGroupArray) ? "reply" : "not_approved"), false, false);
         $outStrUrl = $strURL;
         // sonet log
         if (CModule::IncludeModule("socialnetwork")) {
             $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID"));
             if ($arRes = $dbRes->Fetch()) {
                 $log_id = $arRes["TMP_ID"];
                 $entity_type = $arRes["ENTITY_TYPE"];
                 $entity_id = $arRes["ENTITY_ID"];
             } else {
                 $entity_type = $arTask["GROUP_ID"] ? SONET_ENTITY_GROUP : SONET_ENTITY_USER;
                 $entity_id = $arTask["GROUP_ID"] ? $arTask["GROUP_ID"] : $arTask["CREATED_BY"];
                 $rsUser = CUser::GetByID($arTask["CREATED_BY"]);
                 if ($arUser = $rsUser->Fetch()) {
                     $arSoFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks", "LOG_DATE" => $arTask["CREATED_DATE"], "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => htmlspecialcharsBack($arTask["~TITLE"]), "MESSAGE" => "", "TEXT_MESSAGE" => $strMsgNewTask, "MODULE_ID" => "tasks", "CALLBACK_FUNC" => false, "SOURCE_ID" => $arTask["ID"], "ENABLE_COMMENTS" => "Y", "USER_ID" => $arTask["CREATED_BY"], "URL" => CTaskNotifications::GetNotificationPath($arUser, $arTask["ID"]), "PARAMS" => serialize(array("TYPE" => "create")));
                     $log_id = CSocNetLog::Add($arSoFields, false);
                     if (intval($log_id) > 0) {
                         CSocNetLog::Update($log_id, array("TMP_ID" => $log_id));
                         $arRights = CTaskNotifications::__UserIDs2Rights(CTaskNotifications::GetRecipientsIDs($arTask, false));
                         if ($arTask["GROUP_ID"]) {
                             $arRights[] = "S" . SONET_ENTITY_GROUP . $arTask["GROUP_ID"];
                         }
                         CSocNetLogRights::Add($log_id, $arRights);
                     }
                 }
             }
             if (intval($log_id) > 0) {
                 $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"];
                 CSocNetLog::Update($log_id, array('PARAMS' => serialize(array('TYPE' => 'comment'))));
                 $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "tasks_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "tasks", "SOURCE_ID" => $MID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $MID);
                 if ($MESSAGE_TYPE == "EDIT") {
                     $dbRes = CSocNetLogComments::GetList(array("ID" => "DESC"), array("EVENT_ID" => array("tasks_comment"), "SOURCE_ID" => $MID), false, false, array("ID"));
                     while ($arRes = $dbRes->Fetch()) {
                         CSocNetLogComments::Update($arRes["ID"], $arFieldsForSocnet);
                     }
                 } else {
                     $arFieldsForSocnet['USER_ID'] = $givenUserId;
                     $arFieldsForSocnet['=LOG_DATE'] = $GLOBALS['DB']->CurrentTimeFunction();
                     $ufFileID = array();
                     $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $MID));
                     while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                         $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                     }
                     if (count($ufFileID) > 0) {
                         $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID;
                     }
                     $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $MID, LANGUAGE_ID);
                     if ($ufDocID) {
                         $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
                     }
                     $ufDocVer = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_VER", $MID, LANGUAGE_ID);
                     if ($ufDocVer) {
                         $arFieldsForSocnet["UF_SONET_COM_VER"] = $ufDocVer;
                     }
                     $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                     CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
                 }
             }
         }
         $occurAsUserId = CTasksTools::getOccurAsUserId();
         if (!$occurAsUserId) {
             $occurAsUserId = $arMessage["AUTHOR_ID"] ? $arMessage["AUTHOR_ID"] : 1;
         }
         // Tasks log
         $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $occurAsUserId, "CREATED_DATE" => $arMessage["EDIT_DATE"] ? ConvertTimeStamp(MakeTimeStamp($arMessage["EDIT_DATE"], CSite::GetDateFormat()), "FULL") : $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $MID);
         $log = new CTaskLog();
         $log->Add($arLogFields);
     }
     return $MID;
     // Message id
 }
Example #17
0
    $arParams["SHOW_VOTE"] = empty($res) ? "N" : $arParams["SHOW_VOTE"];
}
/********************************************************************
				Data
********************************************************************/
if ($arParams["MESSAGE_TYPE"] == "EDIT") {
    $arMessage = CForumMessage::GetByIDEx($arParams["MID"], array("GET_FORUM_INFO" => "N", "GET_TOPIC_INFO" => "Y", "FILTER" => "N"));
    if (empty($arMessage)) {
        ShowError(GetMessage("F_ERROR_MESSAGE_NOT_FOUND"));
        return 0;
    }
    $arResult["TOPIC"] = $arMessage["TOPIC_INFO"];
    $arResult["TOPIC_FILTER"] = CForumTopic::GetByID($arMessage["TOPIC_ID"]);
    $arResult["MESSAGE"] = $arMessage;
    $arResult["MESSAGE"]["FILES"] = array();
    $db_res = CForumFiles::GetList(array(), array("MESSAGE_ID" => $arParams["MID"]));
    if ($db_res && ($res = $db_res->Fetch())) {
        do {
            $arResult["MESSAGE"]["FILES"][$res["FILE_ID"]] = $res;
        } while ($res = $db_res->Fetch());
    }
    if ($arParams["SHOW_VOTE"] == "Y" && $arMessage["PARAM1"] == "VT" && intVal($arMessage["PARAM2"]) > 0) {
        $db_vote = CVote::GetByID(intVal($arMessage["PARAM2"]));
        if ($db_vote && ($arVote = $db_vote->GetNext())) {
            $arResult['DATE_END'] = $arVote['DATE_END'];
        }
        $db_res = CVoteQuestion::GetListEx(array("ID" => "ASC"), array("CHANNEL_ID" => $arParams["VOTE_CHANNEL_ID"], "VOTE_ID" => $arMessage["PARAM2"]));
        if ($db_res && ($res = $db_res->Fetch())) {
            do {
                $arResult["~QUESTIONS"][$res["ID"]] = $res;
                $arResult["~QUESTIONS"][$res["ID"]]["ANSWERS"] = array();
Example #18
0
 function Delete($ID)
 {
     global $DB;
     $ID = intVal($ID);
     $bCanDelete = true;
     /***************** Event OnBeforeForumDelete ***********************/
     foreach (GetModuleEvents("forum", "OnBeforeForumDelete", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent, array(&$ID)) === false) {
             $bCanDelete = false;
             break;
         }
     }
     /***************** /Event ******************************************/
     if (!$bCanDelete) {
         return false;
     }
     /***************** Event OnForumDelete *****************************/
     foreach (GetModuleEvents("forum", "OnForumDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array(&$ID));
     }
     /***************** /Event ******************************************/
     /***************** Cleaning cache **********************************/
     unset($GLOBALS["FORUM_CACHE"]["FORUM"][$ID]);
     if (CACHED_b_forum !== false) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum");
     }
     if (CACHED_b_forum_perms !== false) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum_perms");
     }
     if (CACHED_b_forum2site !== false) {
         $GLOBALS["CACHE_MANAGER"]->CleanDir("b_forum2site");
     }
     /***************** Cleaning cache/**********************************/
     /***************** Search module ***********************************/
     set_time_limit(0);
     if (CModule::IncludeModule("search")) {
         CSearch::DeleteIndex("forum", false, $ID);
     }
     CForumFiles::Delete(array("FORUM_ID" => $ID), array("DELETE_FORUM_FILE" => "Y"));
     $DB->StartTransaction();
     // Update USER statistic
     $arProcAuth = array();
     $db_res = CForumMessage::GetList(array(), array("FORUM_ID" => $ID, "!AUTHOR_ID" => 0));
     while ($res = $db_res->Fetch()) {
         $res["AUTHOR_ID"] = intVal($res["AUTHOR_ID"]);
         if (!in_array($res["AUTHOR_ID"], $arProcAuth)) {
             $arProcAuth[] = intVal($res["AUTHOR_ID"]);
         }
     }
     if (IsModuleInstalled("vote")) {
         $db_res = CForumMessage::GetList(array(), array("FORUM_ID" => $ID, "PARAM1" => "VT", "!PARAM2" => 0));
         if ($db_res && ($res = $db_res->Fetch())) {
             CModule::IncludeModule("vote");
             do {
                 CVote::Delete($res["PARAM2"]);
             } while ($res = $db_res->Fetch());
         }
     }
     if (!$DB->Query("DELETE FROM b_forum_subscribe WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum_message WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum_topic WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum_perms WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum2site WHERE FORUM_ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     if (!$DB->Query("DELETE FROM b_forum WHERE ID=" . $ID, true)) {
         $DB->Rollback();
         return false;
     }
     // Update USER statistic
     foreach ($arProcAuth as $i => $procAuth) {
         CForumUser::SetStat($procAuth);
     }
     $DB->Commit();
     /***************** Event OnAfterForumDelete ************************/
     foreach (GetModuleEvents("forum", "OnAfterForumDelete", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent, array($ID));
     }
     /***************** /Event ******************************************/
     return true;
 }
Example #19
0
 function OnAfterCommentAdd($entityType, $entityID, $params = array())
 {
     $arPost = array();
     $arParams =& $this->component->arParams;
     $arResult =& $this->component->arResult;
     if (!!$this->OnCommentAdd($entityType, $entityID, $arPost) && !!$arPost["FILES"]) {
         CForumFiles::UpdateByID(array_keys($arPost["FILES"]), array("FORUM_ID" => $arParams["FORUM_ID"], "TOPIC_ID" => $params["TOPIC_ID"], "MESSAGE_ID" => $params["MESSAGE_ID"]));
     }
 }
Example #20
0
 public static function AddComment_Photo_Forum($arFields, $FORUM_ID, $arLog)
 {
     if (!CModule::IncludeModule("forum")) {
         return false;
     }
     if (!CModule::IncludeModule("iblock")) {
         return false;
     }
     $ufFileID = array();
     $ufDocID = array();
     $arElement = false;
     $arFilteredText = array();
     $arFilter = array("ID" => $arLog["SOURCE_ID"]);
     $arSelectedFields = array("IBLOCK_ID", "ID", "NAME", "TAGS", "CODE", "IBLOCK_SECTION_ID", "DETAIL_PAGE_URL", "CREATED_BY", "PREVIEW_PICTURE", "PREVIEW_TEXT", "PROPERTY_FORUM_TOPIC_ID", "PROPERTY_FORUM_MESSAGE_CNT");
     $db_res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelectedFields);
     if ($db_res && ($res = $db_res->GetNext())) {
         $arElement = $res;
     }
     if ($arElement) {
         // check iblock properties
         CSocNetLogTools::AddComment_Review_CheckIBlock_Forum($arElement);
         $dbMessage = CForumMessage::GetList(array(), array("PARAM2" => $arElement["ID"]));
         if (!($arMessage = $dbMessage->Fetch())) {
             // Add Topic
             $TOPIC_ID = CSocNetLogTools::AddComment_Review_CreateRoot_Forum($arElement, $FORUM_ID);
             $bNewTopic = true;
         } else {
             $TOPIC_ID = $arMessage["TOPIC_ID"];
         }
         if (intval($TOPIC_ID) > 0) {
             if (COption::GetOptionString("forum", "FILTER", "Y") == "Y") {
                 $arFields["TEXT_MESSAGE"] = $arFilteredText["TEXT_MESSAGE"] = CFilterUnquotableWords::Filter($arFields["TEXT_MESSAGE"]);
                 $arFilteredText["MESSAGE"] = CFilterUnquotableWords::Filter($arFields["MESSAGE"]);
             }
             // Add comment
             $messageID = false;
             $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PARAM2" => $arElement["ID"], "APPROVED" => "Y");
             $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp);
             if (is_array($arTmp)) {
                 if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) {
                     $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"];
                 } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) {
                     $arFieldsMessage["FILES"] = array();
                     foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) {
                         $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id);
                     }
                 }
             }
             $messageID = ForumAddMessage("REPLY", $FORUM_ID, $TOPIC_ID, 0, $arFieldsMessage, $sError, $sNote);
             if (!$messageID) {
                 $strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
             } else {
                 // get UF DOC value and FILE_ID there
                 $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID));
                 while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                     $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                 }
                 $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID);
                 CSocNetLogTools::AddComment_Review_UpdateElement_Forum($arElement, $TOPIC_ID, $bNewTopic);
             }
         } else {
             $strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
         }
     } else {
         $strError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR");
     }
     return array_merge($arFilteredText, array("SOURCE_ID" => $messageID, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $strError, "NOTES" => "", "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID), "IM_MESSAGE" => $messageID ? $arFields["TEXT_MESSAGE"] : false));
 }
Example #21
0
 static function AddComment_Wiki($arFields)
 {
     if (!CModule::IncludeModule('iblock')) {
         return false;
     }
     if (!CModule::IncludeModule('socialnetwork')) {
         return false;
     }
     $ufFileID = array();
     $ufDocID = array();
     $dbResult = CSocNetLog::GetList(array('ID' => 'DESC'), array('TMP_ID' => $arFields['LOG_ID']), false, false, array('ID', 'SOURCE_ID', 'PARAMS', 'URL'));
     $bFound = false;
     if ($arLog = $dbResult->Fetch()) {
         if (strlen($arLog['PARAMS']) > 0) {
             $arFieldsParams = explode('&', $arLog['PARAMS']);
             if (is_array($arFieldsParams) && count($arFieldsParams) > 0) {
                 foreach ($arFieldsParams as $tmp) {
                     list($key, $value) = explode('=', $tmp);
                     if ($key == 'forum_id') {
                         $FORUM_ID = intval($value);
                         break;
                     }
                 }
             }
         }
         if ($FORUM_ID > 0 && intval($arLog['SOURCE_ID']) > 0) {
             $bFound = true;
         }
     }
     if ($bFound) {
         $arElement = false;
         $arFilter = array('ID' => $arLog['SOURCE_ID']);
         $arSelectedFields = array('IBLOCK_ID', 'ID', 'NAME', 'TAGS', 'CODE', 'IBLOCK_SECTION_ID', 'DETAIL_PAGE_URL', 'CREATED_BY', 'PREVIEW_PICTURE', 'PREVIEW_TEXT', 'PROPERTY_FORUM_TOPIC_ID', 'PROPERTY_FORUM_MESSAGE_CNT');
         $db_res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelectedFields);
         if ($db_res && ($res = $db_res->GetNext())) {
             $arElement = $res;
         }
         if ($arElement) {
             // check iblock properties
             CSocNetLogTools::AddComment_Review_CheckIBlock($arElement);
             $dbMessage = CForumMessage::GetList(array(), array('PARAM2' => $arElement['ID']));
             if (!($arMessage = $dbMessage->Fetch())) {
                 // Add Topic and Root Message
                 $TOPIC_ID = CSocNetLogTools::AddComment_Review_CreateRoot($arElement, $FORUM_ID, false);
                 $bNewTopic = true;
             } else {
                 $TOPIC_ID = $arMessage['TOPIC_ID'];
             }
             if (intval($TOPIC_ID) > 0) {
                 // Add comment
                 $messageID = false;
                 $arFieldsMessage = array('POST_MESSAGE' => $arFields['TEXT_MESSAGE'], 'USE_SMILES' => 'Y', 'PARAM2' => $arElement['ID'], 'APPROVED' => 'Y');
                 $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp);
                 if (is_array($arTmp)) {
                     if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) {
                         $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"];
                     } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) {
                         $arFieldsMessage["FILES"] = array();
                         foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) {
                             $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id);
                         }
                     }
                 }
                 $messageID = ForumAddMessage('REPLY', $FORUM_ID, $TOPIC_ID, 0, $arFieldsMessage, $sError, $sNote);
                 if (!$messageID) {
                     $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR');
                 } else {
                     $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID));
                     while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                         $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                     }
                     $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID);
                     CSocNetLogTools::AddComment_Review_UpdateElement($arElement, $TOPIC_ID, $bNewTopic);
                     $userID = $GLOBALS["USER"]->GetID();
                     if (CModule::IncludeModule("im") && intval($arElement["CREATED_BY"]) > 0 && $arElement["CREATED_BY"] != $userID) {
                         $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arElement["CREATED_BY"], "CODE" => "L" . $arLog["ID"], "TYPE" => "N"), array("USER_ID"));
                         $arUnFollower = $rsUnFollower->Fetch();
                         if (!$arUnFollower) {
                             $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arElement["CREATED_BY"], "FROM_USER_ID" => $userID, "LOG_ID" => $arLog["ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "wiki", "NOTIFY_EVENT" => "comment");
                             $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arElement["NAME"]);
                             $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100);
                             $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255);
                             $arTmp = CSocNetLogTools::ProcessPath(array("ELEMENT_URL" => $arLog["URL"]), $arElement["CREATED_BY"]);
                             $serverName = $arTmp["SERVER_NAME"];
                             $url = $arTmp["URLS"]["ELEMENT_URL"];
                             $arMessageFields["NOTIFY_TAG"] = "WIKI|COMMENT|" . $arElement['ID'];
                             $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("WIKI_SONET_FROM_LOG_IM_COMMENT", array("#title#" => strlen($url) > 0 ? "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>" : htmlspecialcharsbx($arParams["TITLE"])));
                             $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("WIKI_SONET_FROM_LOG_IM_COMMENT", array("#title#" => htmlspecialcharsbx($arParams["TITLE"]))) . (strlen($url) > 0 ? " (" . $serverName . $url . ")" : "") . "#BR##BR#" . $arFields["TEXT_MESSAGE"];
                             CIMNotify::Add($arMessageFields);
                         }
                     }
                 }
             } else {
                 $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR');
             }
         } else {
             $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR');
         }
     } else {
         $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR');
     }
     return array('SOURCE_ID' => $messageID, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => $messageID, 'ERROR' => $strError, 'NOTES' => '', "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID));
 }
Example #22
0
	function Add($arFields, $strUploadDir = false, $arParams = array())
	{
		global $DB;

		$strUploadDir = ($strUploadDir === false ? "forum/upload" : $strUploadDir);

		if (!CForumMessage::CheckFields("ADD", $arFields))
			return false;

		$arForum = CForumNew::GetByID($arFields["FORUM_ID"]);
		$arParams["SKIP_STATISTIC"] = ($arParams["SKIP_STATISTIC"] == "Y" ? "Y" : "N");
		$arParams["SKIP_INDEXING"] = ($arParams["SKIP_INDEXING"] == "Y" || $arForum["INDEXATION"] != "Y" ? "Y" : "N");

		$POST_MESSAGE = $arFields["POST_MESSAGE"];
		$parser = new forumTextParser(LANGUAGE_ID);
		$allow = forumTextParser::GetFeatures($arForum);
		$allow['SMILES'] = (($arFields["USE_SMILES"] != "Y") ? 'N' : $allow['SMILES']);
		if (COption::GetOptionString("forum", "FILTER", "Y") == "Y")
		{
			$POST_MESSAGE = CFilterUnquotableWords::Filter($POST_MESSAGE);
			$arFields["POST_MESSAGE_FILTER"] = (empty($POST_MESSAGE) ? "*" : $POST_MESSAGE);
		}
/***************** Attach ******************************************/
		$arFiles = array();
		if (is_array($arFields["ATTACH_IMG"]))
			$arFields["FILES"] = array($arFields["ATTACH_IMG"]);
		unset($arFields["ATTACH_IMG"]);
		if (is_array($arFields["FILES"]) && !empty($arFields["FILES"]))
		{
			$res = array("FORUM_ID" => $arFields["FORUM_ID"], "USER_ID" => $arFields["AUTHOR_ID"], "upload_dir" => $strUploadDir);
			$arFiles = CForumFiles::Save($arFields["FILES"], $res, false);
			if (!empty($arFiles))
			{
				$arFiles = array_keys($arFiles);
				sort($arFiles);
				$arFields["ATTACH_IMG"] = $arFiles[0];
				$arFields["ATTACHED_FILES"] = $arFiles;
			}
			unset($arFields["FILES"]);
		}
/***************** Attach/******************************************/
		if (COption::GetOptionString("forum", "MESSAGE_HTML", "N") == "Y")
			$POST_MESSAGE = $parser->convert($POST_MESSAGE, $allow, "html", $arFiles);
		$arFields["POST_MESSAGE_HTML"] = $POST_MESSAGE;
/***************** Event onBeforeMessageAdd ************************/
		foreach(GetModuleEvents("forum", "onBeforeMessageAdd", true) as $arEvent)
		{
			if (ExecuteModuleEventEx($arEvent, array(&$arFields, &$strUploadDir)) === false)
				return false;
		}
/***************** /Event ******************************************/
		if (empty($arFields))
			return false;
		$arInsert = $DB->PrepareInsert("b_forum_message", $arFields, $strUploadDir);

		$strDatePostField = "";
		$strDatePostValue = "";
		if (!is_set($arFields, "POST_DATE"))
		{
			$strDatePostField = ", POST_DATE";
			$strDatePostValue = ", ".$DB->GetNowFunction()."";
		}

		$strSql = "INSERT INTO b_forum_message(".$arInsert[0].$strDatePostField.") VALUES(".$arInsert[1].$strDatePostValue.")";
		$DB->Query($strSql, false, "File: ".__FILE__."<br>Line: ".__LINE__);
		$ID = intVal($DB->LastID());
/***************** Attach ******************************************/
		if (!empty($arFiles))
			CForumFiles::UpdateByID($arFiles, array("FORUM_ID" => $arFields["FORUM_ID"],
				"TOPIC_ID" => $arFields["TOPIC_ID"], "MESSAGE_ID" => $ID));
/***************** Attach/******************************************/
/***************** Quota *******************************************/
		$_SESSION["SESS_RECOUNT_DB"] = "Y";

		$GLOBALS["USER_FIELD_MANAGER"]->Update("FORUM_MESSAGE", $ID, $arFields);
		if ($arParams["SKIP_STATISTIC"] == "Y" && $arParams["SKIP_INDEXING"] == "Y")
			return $ID;
		$arMessage = CForumMessage::GetByIDEx($ID, array("GET_FORUM_INFO" => "N", "GET_TOPIC_INFO" => "Y", "FILTER" => "Y"));

		if ($arParams["SKIP_STATISTIC"] != "Y")
		{
			if (intVal($arMessage["AUTHOR_ID"]) > 0)
			{
				CForumUser::SetStat($arMessage["AUTHOR_ID"], array("MESSAGE" => $arMessage));
			}
			CForumTopic::SetStat($arMessage["TOPIC_ID"],  array("MESSAGE" => $arMessage));
			CForumNew::SetStat($arMessage["FORUM_ID"],  array("MESSAGE" => $arMessage));
		}
/***************** Events onAfterMessageAdd ************************/
		foreach(GetModuleEvents("forum", "onAfterMessageAdd", true) as $arEvent)
			ExecuteModuleEventEx($arEvent, array(&$ID, $arMessage, $arMessage["TOPIC_INFO"], $arMessage["FORUM_INFO"], $arFields));
/***************** /Events *****************************************/
		if ($arMessage["APPROVED"] == "Y")
		{
			if ($arParams["SKIP_INDEXING"] != "Y" && CModule::IncludeModule("search"))
			{
				$arMessage["POST_MESSAGE"] = (COption::GetOptionString("forum", "FILTER", "Y") == "Y" ?
					$arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"]);
				$arParams = array(
					"PERMISSION" => array(),
					"SITE" => CForumNew::GetSites($arMessage["FORUM_ID"]),
					"DEFAULT_URL" => "/");

				$arGroups = CForumNew::GetAccessPermissions($arMessage["FORUM_ID"]);
				foreach($arGroups as $arGroup)
				{
					if ($arGroup[1] >= "E")
					{
						$arParams["PERMISSION"][] = $arGroup[0];
						if ($arGroup[0] == 2)
							break;
					}
				}

				$arSearchInd = array(
					"LID" => array(),
					"LAST_MODIFIED" => $arMessage["POST_DATE"],
					"PARAM1" => $arMessage["FORUM_ID"],
					"PARAM2" => $arMessage["TOPIC_ID"],
					"ENTITY_TYPE_ID"  => ($arMessage["NEW_TOPIC"] == "Y"? "FORUM_TOPIC": "FORUM_POST"),
					"ENTITY_ID" => ($arMessage["NEW_TOPIC"] == "Y"? $arMessage["TOPIC_ID"]: $ID),
					"USER_ID" => $arMessage["AUTHOR_ID"],
					"PERMISSIONS" => $arParams["PERMISSION"],
					"TITLE" => $arMessage["TOPIC_INFO"]["TITLE"].($arMessage["NEW_TOPIC"] == "Y" && !empty($arMessage["TOPIC_INFO"]["DESCRIPTION"]) ?
						", ".$arMessage["TOPIC_INFO"]["DESCRIPTION"] : ""),
					"TAGS" => ($arMessage["NEW_TOPIC"] == "Y" ? $arMessage["TOPIC_INFO"]["TAGS"] : ""),
					"BODY" => GetMessage("AVTOR_PREF")." ".$arMessage["AUTHOR_NAME"].". ".(textParser::killAllTags($arMessage["POST_MESSAGE"])),
					"URL" => "",
					"INDEX_TITLE" => $arMessage["NEW_TOPIC"] == "Y",
				);

				// get mentions
				$arMentionedUserID = CForumMessage::GetMentionedUserID($arMessage["POST_MESSAGE"]);
				if (!empty($arMentionedUserID))
				{
					$arSearchInd["PARAMS"] = array(
						"mentioned_user_id" => $arMentionedUserID
					);
				}

				$urlPatterns = array(
					"FORUM_ID" => $arMessage["FORUM_ID"],
					"TOPIC_ID" => $arMessage["TOPIC_ID"],
					"TITLE_SEO" => $arMessage["TOPIC_INFO"]["TITLE_SEO"],
					"MESSAGE_ID" => $arMessage["ID"],
					"SOCNET_GROUP_ID" => $arMessage["TOPIC_INFO"]["SOCNET_GROUP_ID"],
					"OWNER_ID" => $arMessage["TOPIC_INFO"]["OWNER_ID"],
					"PARAM1" => $arMessage["PARAM1"],
					"PARAM2" => $arMessage["PARAM2"]);
				foreach ($arParams["SITE"] as $key => $val)
				{
					$arSearchInd["LID"][$key] = CForumNew::PreparePath2Message($val, $urlPatterns);
					if (empty($arSearchInd["URL"]) && !empty($arSearchInd["LID"][$key]))
						$arSearchInd["URL"] = $arSearchInd["LID"][$key];
				}

				if (empty($arSearchInd["URL"]))
				{
					foreach ($arParams["SITE"] as $key => $val):
						$db_lang = CLang::GetByID($key);
						if ($db_lang && $ar_lang = $db_lang->Fetch()):
							$arParams["DEFAULT_URL"] = $ar_lang["DIR"];
							break;
						endif;
					endforeach;
					$arParams["DEFAULT_URL"] .= COption::GetOptionString("forum", "REL_FPATH", "").
						"forum/read.php?FID=#FID#&TID=#TID#&MID=#MID##message#MID#";

					$arSearchInd["URL"] = CForumNew::PreparePath2Message($arParams["DEFAULT_URL"], $urlPatterns);
				}
				CSearch::Index("forum", $ID, $arSearchInd);
			}
		}
		return $ID;
	}
Example #23
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);
                 }
             }
         }
     }
 }
Example #24
0
 function Save(&$arFields, $arParams, $bCheckFields = true)
 {
     global $DB;
     if ($bCheckFields && !CForumFiles::CheckFields($arFields, $arParams, "ADD")) {
         return false;
     }
     $arFiles = array();
     $arParams = is_array($arParams) ? $arParams : array($arParams);
     $strUploadDir = !is_set($arParams, "upload_dir") ? "forum/upload" : $arParams["upload_dir"];
     $arParams = array("FORUM_ID" => intVal($arParams["FORUM_ID"]), "USER_ID" => intVal($arParams["USER_ID"]), "TOPIC_ID" => 0, "MESSAGE_ID" => 0);
     foreach ($arFields as $key => $val) {
         $val["MODULE_ID"] = "forum";
         $val["FILE_ID"] = intVal($val["FILE_ID"]);
         $val["old_file"] = intVal($val["old_file"]);
         if ($val["FILE_ID"] <= 0 && $val["old_file"] > 0) {
             $val["FILE_ID"] = $val["old_file"];
         }
         $old_file = $val["FILE_ID"];
         unset($val["old_file"]);
         if (!empty($val["name"])) {
             $res = CFile::SaveFile($val, $strUploadDir, true, true);
             $DB->Commit();
             if ($res > 0) {
                 CForumFiles::Add($res, $arParams);
                 $arFiles[$res] = $arParams;
             }
             if (($res > 0 || !empty($val["del"])) && $old_file > 0) {
                 CFile::Delete($old_file);
                 unset($arFields[$key]);
             }
         } elseif (!empty($val["del"])) {
             CFile::Delete($val["FILE_ID"]);
             unset($arFields[$key]);
         } else {
             $arFiles[$val["FILE_ID"]] = $val;
         }
     }
     return $arFiles;
 }
Example #25
0
    $res["URL"]["EDIT"] = ForumAddPageParams(CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_TOPIC_NEW"], array("FID" => $arParams["FID"])), array("TID" => $arParams["TID"], "MID" => $res["ID"], "MESSAGE_TYPE" => "EDIT")) . "&amp;" . bitrix_sessid_get();
    /************** Panels/*********************************************/
    /************** For custom templates *******************************/
    $res["profile_view"] = $res["URL"]["AUTHOR"];
    $res["MESSAGE_ANCHOR"] = $res["URL"]["MESSAGE"];
    $res["message_link"] = $res["URL"]["MESSAGE"];
    $res["email"] = $res["URL"]["AUTHOR_EMAIL"];
    $res["icq"] = $res["URL"]["AUTHOR_ICQ"];
    $res["pm_edit"] = $res["URL"]["AUTHOR_PM"];
    /************** For custom templates/*******************************/
    $arResult["MESSAGE_LIST"][$res["ID"]] = $res;
}
/************** Attach files ***************************************/
if (!empty($arResult["MESSAGE_LIST"])) {
    $arFilter = array("@FILE_MESSAGE_ID" => array_keys($arResult["MESSAGE_LIST"]));
    $db_files = CForumFiles::GetList(array("MESSAGE_ID" => "ASC"), $arFilter);
    if ($db_files && ($res = $db_files->Fetch())) {
        do {
            $res["SRC"] = CFile::GetFileSRC($res);
            if ($arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["~ATTACH_IMG"] == $res["FILE_ID"]) {
                // attach for custom
                $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["~ATTACH_FILE"] = $res;
                $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["ATTACH_IMG"] = CFile::ShowFile($res["FILE_ID"], 0, $arParams["IMAGE_SIZE"], $arParams["IMAGE_SIZE"], true, "border=0", false);
                $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["ATTACH_FILE"] = $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["ATTACH_IMG"];
            }
            $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["FILES"][$res["FILE_ID"]] = $res;
            $arResult["FILES"][$res["FILE_ID"]] = $res;
        } while ($res = $db_files->Fetch());
    }
    /************** Message info ***************************************/
    $parser->arFiles = $arResult["FILES"];
Example #26
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));
 }
Example #27
0
 foreach ($_FILES as $key => $val) {
     if (substr($key, 0, strlen("FILE_NEW")) == "FILE_NEW" && !empty($val["name"])) {
         $arFiles[] = $_FILES[$key];
     }
 }
 foreach ($_REQUEST["FILES"] as $key => $val) {
     if (!in_array($val, $_REQUEST["FILES_TO_UPLOAD"])) {
         $arFiles[$val] = array("FILE_ID" => $val, "del" => "Y");
         unset($_REQUEST["FILES"][$key]);
         unset($_REQUEST["FILES_TO_UPLOAD"][$key]);
     } else {
         $arFilesExists[$val] = array("FILE_ID" => $val);
     }
 }
 if (!empty($arFiles)) {
     $res = CForumFiles::Save($arFiles, $arFields);
     $res1 = $GLOBALS['APPLICATION']->GetException();
     if ($res1) {
         $strErrorMessage .= $res1->GetString();
     }
 }
 $res = is_array($res) ? $res : array();
 foreach ($res as $key => $val) {
     $arFilesExists[$key] = $val;
 }
 $arFilesExists = array_keys($arFilesExists);
 sort($arFilesExists);
 $arResult["MESSAGE_VIEW"]["FILES"] = $_REQUEST["FILES"] = $arFilesExists;
 $arResult["POST_MESSAGE_VIEW"] = $parser->convert($_POST["POST_MESSAGE"], $arAllow, "html", $arResult["MESSAGE_VIEW"]["FILES"]);
 $arResult["MESSAGE_VIEW"]["FILES_PARSED"] = $parser->arFilesIDParsed;
 $arResult["MESSAGE_VIEW"]["AUTHOR_NAME"] = $USER->IsAuthorized() || empty($_POST["AUTHOR_NAME"]) ? $arResult["USER"]["SHOW_NAME"] : trim($_POST["AUTHOR_NAME"]);
Example #28
0
        $arResult["ERROR_MESSAGE"] = $strErrorMessage;
        $bVarsFromForm = true;
    }
}
/************** Show message for ajax ******************************/
if ($arResult["SHOW_MESSAGE_FOR_AJAX"] == "Y") {
    $APPLICATION->RestartBuffer();
    if (empty($arResult["MESSAGE"])) {
        $db_res = CForumMessage::GetList(array(), array("ID" => $MID1));
        if ($db_res && ($res = $db_res->GetNext())) {
            $arResult["MESSAGE"] = $res;
        }
    }
    if (!empty($arResult["MESSAGE"])) {
        $arResult["MESSAGE"]["FILES"] = array();
        $db_res = CForumFiles::GetList(array(), array("MESSAGE_ID" => $arResult["MESSAGE"]["ID"]));
        if ($db_res && ($res = $db_res->GetNext())) {
            do {
                $res["SRC"] = CFile::GetFileSRC($res);
                $arResult["MESSAGE"]["FILES"][$res["FILE_ID"]] = $res;
            } while ($res = $db_res->GetNext());
        }
        $res = $arResult["MESSAGE"];
        $res["POST_MESSAGE_TEXT"] = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $res["~POST_MESSAGE_FILTER"] : $res["~POST_MESSAGE"];
        $res["POST_MESSAGE_TEXT"] = $parser->convert($res["POST_MESSAGE_TEXT"], $arAllow, "html", $res["FILES"]);
        $res["FILES_PARSED"] = $parser->arFilesIDParsed;
        //				************************message attach img****************************************
        $res["ATTACH_IMG"] = "";
        if (intVal($res["~ATTACH_IMG"]) > 0 && in_array($arResult["FORUM"]["ALLOW_UPLOAD"], array("Y", "A", "F"))) {
            $res["ATTACH_IMG"] = CFile::ShowFile($res["~ATTACH_IMG"], 0, 300, 300, true, "border=0", false);
        }
Example #29
0
                $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["~ATTACH_FILE"] = $res;
                $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["ATTACH_FILE"] = $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["ATTACH_IMG"] = CFile::ShowFile($res["FILE_ID"], 0, $arParams["IMAGE_SIZE"], $arParams["IMAGE_SIZE"], true, "border=0", false);
            }
            if ($arResult["MESSAGE_FIRST"]["ID"] == $res["MESSAGE_ID"]) {
                $arResult["MESSAGE_FIRST"]["FILES"][$res["FILE_ID"]] = $res;
                if (!$bNeedFirstMessage) {
                    $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["FILES"][$res["FILE_ID"]] = $res;
                }
            } else {
                $arResult["MESSAGE_LIST"][$res["MESSAGE_ID"]]["FILES"][$res["FILE_ID"]] = $res;
            }
            $arResult["FILES"][$res["FILE_ID"]] = $res;
        } while ($res = $db_files->Fetch());
        $bNeedLoop = false;
        if ($bNeedFirstMessage && !$bBreakLoop) {
            $db_files = CForumFiles::GetList(array("MESSAGE_ID" => "ASC"), array("MESSAGE_ID" => $arResult["MESSAGE_FIRST"]["ID"]));
            if ($db_files && ($res = $db_files->Fetch())) {
                $bNeedLoop = $bBreakLoop = true;
            }
        }
    }
}
$parser->arFiles = $arResult["FILES"];
if (!empty($arResult["MESSAGE_FIRST"])) {
    $arResult["MESSAGE_FIRST"]["POST_MESSAGE_TEXT"] = $parser->convert($arResult["MESSAGE_FIRST"]["~POST_MESSAGE_TEXT"], $arResult["MESSAGE_FIRST"]["ALLOW"]);
    $arResult["MESSAGE_FIRST"]["FILES_PARSED"] = $parser->arFilesIDParsed;
}
foreach ($arResult["MESSAGE_LIST"] as $iID => $res) {
    $arResult["MESSAGE_LIST"][$iID]["POST_MESSAGE_TEXT"] = $parser->convert($res["~POST_MESSAGE_TEXT"], $res["ALLOW"]);
    $arResult["MESSAGE_LIST"][$iID]["FILES_PARSED"] = $parser->arFilesIDParsed;
}
Example #30
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()) {
         self::setSocnetFollow(array($sonetLog['USER_ID']), $sonetLog['ID'], 'Y');
         $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 {
                 $topicId = 0;
             }
             $fieldsMessage = array('POST_MESSAGE' => $fields['TEXT_MESSAGE'], 'USE_SMILES' => 'Y', 'PERMISSION_EXTERNAL' => 'Q', 'PERMISSION' => 'Y', 'APPROVED' => 'Y');
             if ($topicId === 0) {
                 $fieldsMessage['TITLE'] = 'WF_' . $sonetLog['MESSAGE'];
                 $fieldsMessage['TOPIC_XML_ID'] = 'WF_' . $sonetLog['MESSAGE'];
             }
             $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);
                     }
                 }
             }
             $messageId = ForumAddMessage($topicId > 0 ? "REPLY" : "NEW", $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);
             }
         }
     }
     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));
 }