Example #1
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 #2
0
 public function OnAfterPhotoCommentAddBlog($ID, $arFields)
 {
     if (!CModule::IncludeModule('iblock')) {
         return;
     }
     if (!$this->IsSocnet) {
         return;
     }
     if (intval($this->PhotoElementID) > 0) {
         $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "photo_photo", "SOURCE_ID" => $this->PhotoElementID), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID", "TITLE", "URL", "USER_ID", "PARAMS"));
         $bSocNetLogRecordExists = false;
         if ($arRes = $dbRes->Fetch()) {
             $log_id = $arRes["ID"];
             $entity_type = $arRes["ENTITY_TYPE"];
             $entity_id = $arRes["ENTITY_ID"];
             $log_title = $arRes["TITLE"];
             $log_url = $arRes["URL"];
             $log_user_id = $arRes["USER_ID"];
             $bSocNetLogRecordExists = true;
             if (strlen($arRes["PARAMS"]) > 0) {
                 $arTmp = unserialize($arRes["PARAMS"]);
                 if ($arTmp) {
                     if (array_key_exists("SECTION_NAME", $arTmp) && strlen($arTmp["SECTION_NAME"]) > 0) {
                         $log_section_name = $arTmp["SECTION_NAME"];
                     }
                     if (array_key_exists("SECTION_URL", $arTmp) && strlen($arTmp["SECTION_URL"]) > 0) {
                         $log_section_url = $arTmp["SECTION_URL"];
                     }
                 }
             }
         } else {
             $rsElement = CIBlockElement::GetByID($this->PhotoElementID);
             if ($arElement = $rsElement->Fetch()) {
                 $url = $this->arPath["DETAIL_URL"];
                 $sAuthorName = GetMessage("SONET_PHOTO_LOG_GUEST");
                 if (intval($arElement["CREATED_BY"]) > 0) {
                     $rsUser = CUser::GetByID($arElement["CREATED_BY"]);
                     if ($arUser = $rsUser->Fetch()) {
                         $sAuthorName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
                     }
                 }
                 if (in_array($this->entity_type, array(SONET_ENTITY_USER, SONET_ENTITY_GROUP)) && intval($this->entity_id) > 0) {
                     $entity_type = $this->entity_type;
                     $entity_id = $this->entity_id;
                     $alias = ($this->entity_type == SONET_ENTITY_GROUP ? "group" : "user") . "_" . $this->entity_id;
                 }
                 $arLogParams = array("BLOG_ID" => intval($this->BlogID));
                 $rsIBlock = CIBlock::GetByID($arElement["IBLOCK_ID"]);
                 if ($arIBlock = $rsIBlock->Fetch()) {
                     $arLogParams["IBLOCK_ID"] = $arIBlock["ID"];
                     $arLogParams["IBLOCK_TYPE"] = $arIBlock["IBLOCK_TYPE_ID"];
                 }
                 $rsSection = CIBlockSection::GetByID($arElement["IBLOCK_SECTION_ID"]);
                 if ($arSection = $rsSection->Fetch()) {
                     $arLogParams["SECTION_ID"] = $arSection["ID"];
                     $arLogParams["SECTION_NAME"] = $arSection["NAME"];
                     $arLogParams["SECTION_URL"] = str_replace("#SECTION_ID#", $arSection["ID"], $this->arPath["SECTION_URL"]);
                     $arSectionPath = array();
                     $bPassword = false;
                     $dbSectionPath = CIBlockSection::GetList(array("LEFT_MARGIN" => "ASC"), array("IBLOCK_ID" => intval($arLogParams["IBLOCK_ID"]), "<=LEFT_BORDER" => intval($arSection["LEFT_MARGIN"]), ">=RIGHT_BORDER" => intval($arSection["RIGHT_MARGIN"]), "<=DEPTH_LEVEL" => intval($arSection["DEPTH_LEVEL"])), false, array("ID", "IBLOCK_ID", "NAME", "CREATED_BY", "DEPTH_LEVEL", "LEFT_MARGIN", "RIGHT_MARGIN", "UF_PASSWORD"));
                     while ($arPath = $dbSectionPath->Fetch()) {
                         $arSectionPath[] = $arPath;
                         if (strlen(trim($arPath["UF_PASSWORD"])) > 0) {
                             $bPassword = true;
                             break;
                         }
                     }
                     if (!$alias) {
                         $entity_type = SONET_ENTITY_USER;
                         $entity_id = $arSectionPath[0]["CREATED_BY"];
                         $alias = $arSectionPath[0]["CODE"];
                     }
                 }
                 $arLogParams["ALIAS"] = $alias;
                 $arSonetFields = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "photo_photo", "LOG_DATE" => $arElement["TIMESTAMP_X"], "TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $sAuthorName, GetMessage("SONET_PHOTOPHOTO_LOG_1")), "TITLE" => $arElement["NAME"], "MESSAGE" => "", "TEXT_MESSAGE" => "", "URL" => CComponentEngine::MakePathFromTemplate($url, array("ELEMENT_ID" => $arElement["ID"], "element_id" => $arElement["ID"], "SECTION_ID" => $arElement["IBLOCK_SECTION_ID"], "section_id" => $arElement["IBLOCK_SECTION_ID"])), "MODULE_ID" => false, "CALLBACK_FUNC" => false, "SOURCE_ID" => $arElement["ID"], "PARAMS" => serialize($arLogParams), "RATING_TYPE_ID" => "IBLOCK_ELEMENT", "RATING_ENTITY_ID" => $arElement["ID"]);
                 if (intval($arElement["CREATED_BY"]) > 0) {
                     $arSonetFields["USER_ID"] = $arElement["CREATED_BY"];
                 }
                 $log_id = CSocNetLog::Add($arSonetFields, false);
                 if (intval($log_id) > 0) {
                     $log_title = $arSonetFields["TITLE"];
                     $log_url = $arSonetFields["URL"];
                     $log_section_name = $arLogParams["SECTION_NAME"];
                     $log_section_url = $arLogParams["SECTION_URL"];
                     $log_user_id = $arSonetFields["USER_ID"];
                     CSocNetLog::Update($log_id, array("TMP_ID" => $log_id));
                     if ($bPassword) {
                         CSocNetLogRights::DeleteByLogID($log_id);
                         CSocNetLogRights::Add($log_id, array("U" . $GLOBALS["USER"]->GetID(), "SA"));
                     } else {
                         CSocNetLogRights::SetForSonet($log_id, $entity_type, $entity_id, "photo", "view", true);
                     }
                 }
             }
         }
         if (intval($log_id) > 0) {
             $parserBlog = new blogTextParser(false, $this->arPath["PATH_TO_SMILE"]);
             $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
             if ($bSocNetLogRecordExists) {
                 $text4message = $parserBlog->convert($arFields["POST_TEXT"], true, array(), $arAllow);
                 $text4mail = $parserBlog->convert4mail($arFields["POST_TEXT"]);
                 $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "photo_comment", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $text4message, "TEXT_MESSAGE" => $text4mail, "MODULE_ID" => false, "SOURCE_ID" => $ID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "BLOG_COMMENT", "RATING_ENTITY_ID" => $ID);
                 if (intval($arFields["AUTHOR_ID"]) > 0) {
                     $arFieldsForSocnet["USER_ID"] = $arFields["AUTHOR_ID"];
                 }
                 $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                 if ($comment_id) {
                     CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
                     $arFieldsIM = array("TYPE" => "COMMENT", "TITLE" => $log_title, "MESSAGE" => $arFieldsForSocnet["MESSAGE"], "URL" => $log_url, "SECTION_NAME" => $log_section_name, "SECTION_URL" => $log_section_url, "ID" => $this->PhotoElementID, "PHOTO_AUTHOR_ID" => $log_user_id, "COMMENT_AUTHOR_ID" => $arFields["AUTHOR_ID"]);
                     CSocNetPhotoCommentEvent::NotifyIm($arFieldsIM);
                 }
             } else {
                 $dbComments = CBlogComment::GetList(array(), array("BLOG_ID" => intval($this->BlogID), "POST_ID" => intval($this->PostID)), false, false, array("ID", "BLOG_ID", "POST_ID", "AUTHOR_ID", "POST_TEXT", "DATE_CREATE"));
                 while ($arComment = $dbComments->GetNext()) {
                     $text4message = $parserBlog->convert($arComment["POST_TEXT"], true, array(), $arAllow);
                     $text4mail = $parserBlog->convert4mail($arComment["POST_TEXT"]);
                     $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "photo_comment", "=LOG_DATE" => $GLOBALS["DB"]->CharToDateFunction($arComment["DATE_CREATE"], "FULL", SITE_ID), "MESSAGE" => $text4message, "TEXT_MESSAGE" => $text4mail, "MODULE_ID" => false, "SOURCE_ID" => intval($arComment["ID"]), "LOG_ID" => $log_id, "RATING_TYPE_ID" => "BLOG_COMMENT", "RATING_ENTITY_ID" => intval($arComment["ID"]));
                     if (intval($arFields["AUTHOR_ID"]) > 0) {
                         $arFieldsForSocnet["USER_ID"] = $arFields["AUTHOR_ID"];
                     }
                     $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                     if ($comment_id) {
                         CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
                         $arFieldsIM = array("TYPE" => "COMMENT", "TITLE" => $log_title, "MESSAGE" => $arFieldsForSocnet["MESSAGE"], "URL" => $log_url, "SECTION_NAME" => $log_section_name, "SECTION_URL" => $log_section_url, "ID" => $this->PhotoElementID, "PHOTO_AUTHOR_ID" => $log_user_id, "COMMENT_AUTHOR_ID" => $arFields["AUTHOR_ID"]);
                         CSocNetPhotoCommentEvent::NotifyIm($arFieldsIM);
                     }
                 }
                 if ($arElement) {
                     self::InheriteAlbumFollow($arElement["IBLOCK_SECTION_ID"], $log_id, intVal($arElement["CREATED_BY"]) > 0 ? $arElement["CREATED_BY"] : false);
                 }
             }
         }
     }
 }
Example #3
0
                             while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) {
                                 $ufFileID[] = $arAddedMessageFiles["FILE_ID"];
                             }
                             if (count($ufFileID) > 0) {
                                 $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID;
                             } else {
                                 unset($arFieldsForSocnet["UF_SONET_COM_FILE"]);
                             }
                             $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $arComment["ID"], LANGUAGE_ID);
                             if ($ufDocID) {
                                 $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
                             } else {
                                 unset($arFieldsForSocnet["UF_SONET_COM_DOC"]);
                             }
                             $arSocLog = array("=LOG_DATE" => $DB->CharToDateFunction($arComment['POST_DATE'], "FULL", SITE_ID), "MESSAGE" => $arComment['POST_MESSAGE'], "TEXT_MESSAGE" => $parser->convert4mail($arComment['POST_MESSAGE']), "SOURCE_ID" => intval($arComment["ID"]), "RATING_ENTITY_ID" => intval($arComment["ID"])) + (!!$arComment['AUTHOR_ID'] ? array("USER_ID" => $arComment["AUTHOR_ID"]) : array());
                             $log_comment_id = CSocNetLogComments::Add(array_merge($arFieldsForSocnet, $arSocLog), false, false);
                             CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
                         } while ($arComment = $dbComments->Fetch());
                     }
                 }
             }
         }
     }
     $res = $arParams["MID"];
 }
 if (!$res) {
     $bVarsFromForm = true;
 } else {
     $arNote = array("code" => $action, "title" => $strOKMessage, "link" => $url);
 }
 $arResult['RESULT'] = $res;
Example #4
0
     $log_id = CBlogPost::Notify($arPost, $arBlog, $arParamsNotify);
 }
 if (intval($log_id) > 0) {
     $arImages = array();
     $res = CBlogImage::GetList(array("ID" => "ASC"), array("POST_ID" => $arPost["ID"], "BLOG_ID" => $arBlog["ID"], "IS_COMMENT" => "Y", "COMMENT_ID" => $commentId));
     while ($arImage = $res->Fetch()) {
         $arImages[$arImage["ID"]] = $arImage["FILE_ID"];
     }
     $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "TABLE" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
     $text4message = $parserBlog->convert($_POST['comment'], false, $arImages, $arAllow, array("isSonetLog" => true));
     $text4mail = $parserBlog->convert4mail($_POST['comment'], $arImages);
     $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_USER, "ENTITY_ID" => $arBlog["OWNER_ID"], "EVENT_ID" => "blog_comment", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $text4message, "TEXT_MESSAGE" => $text4mail, "URL" => $commentUrl, "MODULE_ID" => false, "SOURCE_ID" => $commentId, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "BLOG_COMMENT", "RATING_ENTITY_ID" => intval($commentId));
     if (intval($user_id) > 0) {
         $arFieldsForSocnet["USER_ID"] = $user_id;
     }
     CSocNetLogComments::Add($arFieldsForSocnet);
 }
 $arPSR = CBlogPost::GetSocnetPerms($arPost["ID"]);
 $arUsrS = array();
 if (!empty($arPSR["U"])) {
     foreach ($arPSR["U"] as $k => $v) {
         $arUsrS[] = "U" . $k;
     }
 }
 preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/ies" . BX_UTF_PCRE_MODIFIER, $_POST['comment'], $arMention);
 $arFieldsIM = array("TYPE" => "COMMENT", "TITLE" => $arPost["TITLE"], "URL" => $commentUrl, "ID" => $arPost["ID"], "FROM_USER_ID" => $user_id, "TO_USER_ID" => array($arPost["AUTHOR_ID"]), "TO_SOCNET_RIGHTS" => $arUsrS, "TO_SOCNET_RIGHTS_OLD" => array(), "AUTHOR_ID" => $arPost["AUTHOR_ID"]);
 //if(!empty($arMentionOld))
 //	$arFieldsIM["MENTION_ID_OLD"] = $arMentionOld[1];
 if (!empty($arMention)) {
     $arFieldsIM["MENTION_ID"] = $arMention[1];
 }
Example #5
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 #6
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 #7
0
 function onAfterMessageAdd($ID, $arFields)
 {
     $bSocNetLogRecordExists = false;
     // add log comment
     if ((!array_key_exists('PARAM1', $arFields) || $arFields['PARAM1'] != 'IB') && array_key_exists('PARAM2', $arFields) && intval($arFields['PARAM2']) > 0) {
         $dbRes = CSocNetLog::GetList(array('ID' => 'DESC'), array("EVENT_ID" => "wiki", "SOURCE_ID" => $arFields["PARAM2"]), false, false, array('ID', 'ENTITY_TYPE', 'ENTITY_ID', 'TMP_ID', 'URL'));
         if ($arRes = $dbRes->Fetch()) {
             $log_id = $arRes['TMP_ID'];
             $url = $arRes['URL'];
             $bSocNetLogRecordExists = true;
         } else {
             $rsElement = CIBlockElement::GetByID($arFields['PARAM2']);
             if ($arElement = $rsElement->Fetch()) {
                 $arWikiElement = CWiki::GetElementById($arElement['ID'], array('IBLOCK_ID' => $arElement['IBLOCK_ID']));
                 $CWikiParser = new CWikiParser();
                 $parserLog = new logTextParser();
                 $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N", "TABLE" => "N");
                 $text4message = $CWikiParser->Parse($arElement['DETAIL_TEXT'], $arElement['DETAIL_TEXT_TYPE'], $arWikiElement['IMAGES']);
                 $text4message = preg_replace("#<br[\\s]*\\/>#is", "#BR#", $text4message);
                 $text4message = htmlspecialcharsback($parserLog->convert($text4message, array(), $arAllow));
                 $text4message = preg_replace("#\\#BR\\##is", "\n", $text4message);
                 $text4message = $CWikiParser->Clear($text4message);
                 $url = str_replace(array('#group_id#', '#wiki_name#'), array(intval($this->SonetGroupID), urlencode($arElement['NAME'])), $this->arPath['PATH_TO_POST']);
                 $arSoFields = array('ENTITY_TYPE' => SONET_SUBSCRIBE_ENTITY_GROUP, 'IS_CUSTOM_ET' => 'N', 'ENTITY_ID' => intval($this->SonetGroupID), 'EVENT_ID' => 'wiki', 'USER_ID' => $arElement['CREATED_BY'], 'LOG_DATE' => $arElement['DATE_CREATE'], 'LOG_UPDATE' => $arElement['DATE_CREATE'], 'TITLE_TEMPLATE' => GetMessage('WIKI_SONET_LOG_TITLE_TEMPLATE'), 'TITLE' => $arElement['NAME'], 'MESSAGE' => $text4message, 'TEXT_MESSAGE' => '', 'MODULE_ID' => 'wiki', 'URL' => $url, 'CALLBACK_FUNC' => false, 'SOURCE_ID' => $arFields['PARAM2'], 'PARAMS' => 'forum_id=' . $this->ForumID, 'RATING_TYPE_ID' => 'IBLOCK_ELEMENT', 'RATING_ENTITY_ID' => intval($arFields['PARAM2']));
                 $log_id = CSocNetLog::Add($arSoFields, false);
                 if (intval($log_id) > 0) {
                     CSocNetLog::Update($log_id, array("TMP_ID" => $log_id));
                     CSocNetLogRights::SetForSonet($log_id, SONET_SUBSCRIBE_ENTITY_GROUP, intval($this->SonetGroupID), "wiki", "view", true);
                 }
             }
         }
         if (intval($log_id) > 0) {
             $arForum = CForumNew::GetByID($this->ForumID);
             $parser = new textParser(LANGUAGE_ID, $this->arPath['PATH_TO_SMILE']);
             $parser->image_params['width'] = false;
             $parser->image_params['height'] = false;
             $arAllow = array('HTML' => "N", 'ANCHOR' => "N", 'BIU' => "N", 'IMG' => "N", 'LIST' => "N", 'QUOTE' => "N", 'CODE' => "N", 'FONT' => "N", 'UPLOAD' => $arForum['ALLOW_UPLOAD'], 'NL2BR' => "N", 'SMILES' => "N");
             $sAuthorForMail = str_replace('#TITLE#', $arMessage['AUTHOR_NAME'], GetMessage('SONET_FORUM_LOG_TEMPLATE_GUEST'));
             if ($bSocNetLogRecordExists) {
                 $arMessage = CForumMessage::GetByIDEx($ID);
                 $parser = new textParser(LANGUAGE_ID, $this->arPath['PATH_TO_SMILE']);
                 $parser->image_params['width'] = false;
                 $parser->image_params['height'] = false;
                 if (intVal($arMessage['AUTHOR_ID']) > 0) {
                     $sAuthorForMail = str_replace(array('#URL#', '#TITLE#'), array('http://' . SITE_SERVER_NAME . CComponentEngine::MakePathFromTemplate($this->arPath['PATH_TO_USER'], array('user_id' => $arMessage['AUTHOR_ID'])), $arMessage['AUTHOR_NAME']), GetMessage('SONET_FORUM_LOG_TEMPLATE_AUTHOR'));
                 }
                 $arFieldsForSocnet = array('ENTITY_TYPE' => SONET_SUBSCRIBE_ENTITY_GROUP, 'ENTITY_ID' => intval($this->SonetGroupID), 'EVENT_ID' => 'wiki_comment', '=LOG_DATE' => $GLOBALS['DB']->CurrentTimeFunction(), 'MESSAGE' => $parser->convert($arMessage['POST_MESSAGE'], $arAllow), 'TEXT_MESSAGE' => $parser->convert4mail($arMessage['POST_MESSAGE'] . $sAuthorForMail), 'URL' => $url, 'MODULE_ID' => false, 'SOURCE_ID' => $ID, 'LOG_ID' => $log_id, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => intval($arMessage['ID']));
                 if (intVal($arMessage['AUTHOR_ID']) > 0) {
                     $arFieldsForSocnet['USER_ID'] = $arMessage['AUTHOR_ID'];
                 }
                 CSocNetLogComments::Add($arFieldsForSocnet);
             } else {
                 $dbMessage = CForumMessage::GetListEx(array(), array('TOPIC_ID' => $arFields["TOPIC_ID"], "NEW_TOPIC" => "N"));
                 while ($arMessage = $dbMessage->GetNext()) {
                     if (intVal($arMessage['AUTHOR_ID']) > 0) {
                         $sAuthorForMail = str_replace(array('#URL#', '#TITLE#'), array('http://' . SITE_SERVER_NAME . CComponentEngine::MakePathFromTemplate($this->arPath['PATH_TO_USER'], array('user_id' => $arMessage['AUTHOR_ID'])), $arMessage['AUTHOR_NAME']), GetMessage('SONET_FORUM_LOG_TEMPLATE_AUTHOR'));
                     }
                     $arFieldsForSocnet = array('ENTITY_TYPE' => SONET_SUBSCRIBE_ENTITY_GROUP, 'ENTITY_ID' => intval($this->SonetGroupID), 'EVENT_ID' => 'wiki_comment', '=LOG_DATE' => $GLOBALS['DB']->CharToDateFunction($arMessage['POST_DATE'], "FULL", SITE_ID), 'MESSAGE' => $parser->convert($arMessage['POST_MESSAGE'], $arAllow), 'TEXT_MESSAGE' => $parser->convert4mail($arMessage['POST_MESSAGE'] . $sAuthorForMail), 'URL' => $url, 'MODULE_ID' => false, 'SOURCE_ID' => $ID, 'LOG_ID' => $log_id, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => intval($arMessage['ID']));
                     if (intVal($arMessage['AUTHOR_ID']) > 0) {
                         $arFieldsForSocnet['USER_ID'] = $arMessage['AUTHOR_ID'];
                     }
                     CSocNetLogComments::Add($arFieldsForSocnet);
                 }
             }
         }
     }
 }
Example #8
0
 public static function onAfterCommentAdd($entityType, $entityId, $arData)
 {
     global $USER;
     // 'TK' is our entity type
     if ($entityType !== 'TK' || intval($entityId) <= 0 || !CModule::IncludeModule('tasks') || !CModule::IncludeModule('socialnetwork')) {
         return;
     }
     $taskId = (int) $entityId;
     $messageId = $arData['MESSAGE_ID'];
     $parser = new CTextParser();
     $messageAuthorId = null;
     if (array_key_exists('AUTHOR_ID', $arData['PARAMS']) && array_key_exists('EDIT_DATE', $arData['PARAMS']) && array_key_exists('POST_DATE', $arData['PARAMS'])) {
         $messageAuthorId = $arData['PARAMS']['AUTHOR_ID'];
     } else {
         $arMessage = CForumMessage::GetByID($messageId);
         $messageAuthorId = $arMessage['AUTHOR_ID'];
     }
     $occurAsUserId = CTasksTools::getOccurAsUserId();
     if (!$occurAsUserId) {
         $occurAsUserId = $messageAuthorId ? $messageAuthorId : 1;
     }
     $rsTask = CTasks::GetList(false, array('ID' => $taskId), array('UF_CRM_TASK'));
     $arTask = $rsTask->GetNext();
     if (!isset($arTask) || !isset($arTask['UF_CRM_TASK']) || is_array($arTask['UF_CRM_TASK']) && (!isset($arTask['UF_CRM_TASK'][0]) || strlen($arTask['UF_CRM_TASK'][0]) <= 0) || !is_array($arTask['UF_CRM_TASK']) && strlen($arTask['UF_CRM_TASK']) <= 0) {
         return;
     }
     $dbCrmActivity = CCrmActivity::GetList(array(), array('TYPE_ID' => CCrmActivityType::Task, 'ASSOCIATED_ENTITY_ID' => $taskId, 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID'));
     $arCrmActivity = $dbCrmActivity->Fetch();
     if (!$arCrmActivity) {
         return;
     }
     $crmActivityId = $arCrmActivity['ID'];
     // sonet log
     $dbLog = CSocNetLog::GetList(array(), array("EVENT_ID" => "crm_activity_add", "ENTITY_ID" => $crmActivityId), 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"];
         $strURL = $GLOBALS['APPLICATION']->GetCurPageParam("", array("IFRAME", "MID", "SEF_APPLICATION_CUR_PAGE_URL", BX_AJAX_PARAM_ID, "result"));
         $strURL = ForumAddPageParams($strURL, array("MID" => $messageId, "result" => "reply"), false, false);
         $sText = COption::GetOptionString("forum", "FILTER", "Y") == "Y" ? $arMessage["POST_MESSAGE_FILTER"] : $arMessage["POST_MESSAGE"];
         $arFieldsForSocnet = array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => "crm_activity_add_comment", "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("?IFRAME=Y", "", str_replace("&IFRAME=Y", "", str_replace("IFRAME=Y&", "", $strURL))), "MODULE_ID" => "crm", "SOURCE_ID" => $messageId, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageId);
         $arFieldsForSocnet["USER_ID"] = $occurAsUserId;
         $arFieldsForSocnet["=LOG_DATE"] = $GLOBALS['DB']->CurrentTimeFunction();
         $ufFileID = array();
         $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageId));
         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", $messageId, LANGUAGE_ID);
         if ($ufDocID) {
             $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
         }
         $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
         CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
     }
 }
Example #9
0
 private function createLogComment($messageID, $bSocNetLogRecordExists, $iblockElementID, $topicID, $arLogParams)
 {
     $dbComment = CSocNetLogComments::GetList(array(), array('EVENT_ID' => 'wiki_comment', 'SOURCE_ID' => $messageID), false, false, array('ID'));
     if (($arComment = $dbComment->Fetch()) && intval($arComment['ID']) > 0) {
         return false;
     }
     $arForum = CForumNew::GetByID($this->ForumID);
     $parser = new textParser(LANGUAGE_ID, $this->arPath['PATH_TO_SMILE']);
     $parser->image_params['width'] = false;
     $parser->image_params['height'] = false;
     $arAllow = array('HTML' => "N", 'ANCHOR' => "N", 'BIU' => "N", 'IMG' => "N", 'LIST' => "N", 'QUOTE' => "N", 'CODE' => "N", 'FONT' => "N", 'UPLOAD' => $arForum['ALLOW_UPLOAD'], 'NL2BR' => "N", 'SMILES' => "N");
     if ($bSocNetLogRecordExists) {
         $arMessage = CForumMessage::GetByIDEx($messageID);
         $sAuthorForMail = str_replace('#TITLE#', $arMessage['AUTHOR_NAME'], GetMessage('SONET_FORUM_LOG_TEMPLATE_GUEST'));
         $parser = new textParser(LANGUAGE_ID, $this->arPath['PATH_TO_SMILE']);
         $parser->image_params['width'] = false;
         $parser->image_params['height'] = false;
         if (intVal($arMessage['AUTHOR_ID']) > 0) {
             $sAuthorForMail = str_replace(array('#URL#', '#TITLE#'), array('http://' . SITE_SERVER_NAME . CComponentEngine::MakePathFromTemplate($this->arPath['PATH_TO_USER'], array('user_id' => $arMessage['AUTHOR_ID'])), $arMessage['AUTHOR_NAME']), GetMessage('SONET_FORUM_LOG_TEMPLATE_AUTHOR'));
         }
         $arFieldsForSocnet = array('ENTITY_TYPE' => SONET_SUBSCRIBE_ENTITY_GROUP, 'ENTITY_ID' => intval($this->SonetGroupID), 'EVENT_ID' => 'wiki_comment', '=LOG_DATE' => $GLOBALS['DB']->CharToDateFunction($arMessage['POST_DATE'], "FULL", SITE_ID), 'MESSAGE' => $parser->convert($arMessage['POST_MESSAGE'], $arAllow), 'TEXT_MESSAGE' => $parser->convert4mail($arMessage['POST_MESSAGE'] . $sAuthorForMail), 'URL' => $arLogParams["URL"], 'MODULE_ID' => false, 'SOURCE_ID' => $messageID, 'LOG_ID' => $arLogParams["LOG_ID"], 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => intval($arMessage['ID']));
         if (intVal($arMessage['AUTHOR_ID']) > 0) {
             $arFieldsForSocnet['USER_ID'] = $arMessage['AUTHOR_ID'];
         }
         $log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
         if ($log_comment_id) {
             CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
             if (CModule::IncludeModule("im") && intval($arMessage["AUTHOR_ID"]) > 0 && $arMessage["AUTHOR_ID"] != $arLogParams["LOG_USER_ID"]) {
                 $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arLogParams["LOG_USER_ID"], "CODE" => "L" . $arLogParams["LOG_ID"], "TYPE" => "N"), array("USER_ID"));
                 $arUnFollower = $rsUnFollower->Fetch();
                 if (!$arUnFollower) {
                     $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arLogParams["LOG_USER_ID"], "FROM_USER_ID" => $arMessage["AUTHOR_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "wiki", "NOTIFY_EVENT" => "comment");
                     $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arLogParams["LOG_TITLE"]);
                     $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100);
                     $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255);
                     $arTmp = CSocNetLogTools::ProcessPath(array("ELEMENT_URL" => $arLogParams["URL"]), $arLogParams["LOG_USER_ID"]);
                     $serverName = $arTmp["SERVER_NAME"];
                     $url = $arTmp["URLS"]["ELEMENT_URL"];
                     $arMessageFields["NOTIFY_TAG"] = "WIKI|COMMENT|" . $iblockElementID;
                     $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("WIKI_SONET_IM_COMMENT", array("#title#" => "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>"));
                     $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("WIKI_SONET_IM_COMMENT", array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]))) . " (" . $serverName . $url . ")#BR##BR#" . $arFieldsForSocnet["MESSAGE"];
                     CIMNotify::Add($arMessageFields);
                 }
             }
         }
     } else {
         $dbMessage = CForumMessage::GetListEx(array(), array("TOPIC_ID" => $topicID, "NEW_TOPIC" => "N"));
         while ($arMessage = $dbMessage->GetNext()) {
             if (intVal($arMessage['AUTHOR_ID']) > 0) {
                 $sAuthorForMail = str_replace(array('#URL#', '#TITLE#'), array('http://' . SITE_SERVER_NAME . CComponentEngine::MakePathFromTemplate($this->arPath['PATH_TO_USER'], array('user_id' => $arMessage['AUTHOR_ID'])), $arMessage['AUTHOR_NAME']), GetMessage('SONET_FORUM_LOG_TEMPLATE_AUTHOR'));
             }
             $arFieldsForSocnet = array('ENTITY_TYPE' => SONET_SUBSCRIBE_ENTITY_GROUP, 'ENTITY_ID' => intval($this->SonetGroupID), 'EVENT_ID' => 'wiki_comment', '=LOG_DATE' => $GLOBALS['DB']->CharToDateFunction($arMessage['POST_DATE'], "FULL", SITE_ID), 'MESSAGE' => $parser->convert($arMessage['POST_MESSAGE'], $arAllow), 'TEXT_MESSAGE' => $parser->convert4mail($arMessage['POST_MESSAGE'] . $sAuthorForMail), 'URL' => $arLogParams["URL"], 'MODULE_ID' => false, 'SOURCE_ID' => $arMessage['ID'], 'LOG_ID' => $arLogParams["LOG_ID"], 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => intval($arMessage['ID']));
             if (intVal($arMessage['AUTHOR_ID']) > 0) {
                 $arFieldsForSocnet['USER_ID'] = $arMessage['AUTHOR_ID'];
             }
             $log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
             CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
         }
     }
 }
Example #10
0
                     CSocNetLogRights::SetForSonet($log_id, $arParams["MODE"] == "GROUP" ? SONET_ENTITY_GROUP : SONET_ENTITY_USER, $arParams["MODE"] == "GROUP" ? $arParams["SOCNET_GROUP_ID"] : $arParams["USER_ID"], "forum", "view");
                 }
             }
             if (intval($log_id) > 0) {
                 $arFieldsForSocnet = array("ENTITY_TYPE" => $arParams["MODE"] == "GROUP" ? SONET_ENTITY_GROUP : SONET_ENTITY_USER, "ENTITY_ID" => $arParams["MODE"] == "GROUP" ? $arParams["SOCNET_GROUP_ID"] : $arParams["USER_ID"], "EVENT_ID" => "forum", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $sText, "TEXT_MESSAGE" => $parser->convert4mail($sText), "URL" => str_replace("#result#", $arParams["MID"], $url), "MODULE_ID" => false, "SOURCE_ID" => $arParams["MID"], "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => intval($arParams["MID"]));
                 if ($bSocNetLogRecordExists) {
                     if (intVal($arResult["MESSAGE"]["AUTHOR_ID"]) > 0) {
                         $arFieldsForSocnet["USER_ID"] = $arResult["MESSAGE"]["AUTHOR_ID"];
                     }
                     CSocNetLogComments::Add($arFieldsForSocnet);
                 } else {
                     $dbComments = CForumMessage::GetListEx(array("ID" => "ASC"), array('TOPIC_ID' => $arParams["TID"], "NEW_TOPIC" => "N"));
                     if ($dbComments && ($arComment = $dbComments->Fetch())) {
                         do {
                             $arSocLog = array("=LOG_DATE" => $DB->CharToDateFunction($arComment['POST_DATE'], "FULL", SITE_ID), "MESSAGE" => $arComment['POST_MESSAGE'], "TEXT_MESSAGE" => $parser->convert4mail($arComment['POST_MESSAGE']), "SOURCE_ID" => intval($arComment["ID"]), "RATING_ENTITY_ID" => intval($arComment["ID"])) + (!!$arComment['AUTHOR_ID'] ? array("USER_ID" => $arComment["ID"]) : array());
                             CSocNetLogComments::Add(array_merge($arFieldsForSocnet, $arSocLog));
                         } while ($arComment = $dbComments->Fetch());
                     }
                 }
             }
         }
     }
     $res = $arParams["MID"];
 }
 if (!$res) {
     $bVarsFromForm = true;
 } else {
     $arNote = array("code" => $action, "title" => $strOKMessage, "link" => $url);
 }
 $arResult['RESULT'] = $res;
 if (isset($_REQUEST['AJAX_CALL']) && in_array($action, array('SHOW', 'HIDE', 'DEL'))) {
Example #11
0
 public function SocnetLogMessageAdd($ID, $arFields, $bUpdate = false)
 {
     $arForum = CForumNew::GetByID($this->forumID);
     $arMessage = CForumMessage::GetByIDEx($ID);
     if ($arMessage["TOPIC_ID"]) {
         $arTopic = CForumTopic::GetByID($arMessage["TOPIC_ID"]);
     }
     $arRes = $this->_getSocnetLogEntityByComment($arMessage);
     if ($arRes && intval($arRes["TMP_ID"]) > 0) {
         $parser = new textParser(LANGUAGE_ID, $this->arPath["PATH_TO_SMILE"]);
         $parser->image_params["width"] = false;
         $parser->image_params["height"] = false;
         $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "LIST" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => "N", "SMILES" => "N");
         if (intval($arRes["COMMENTS_COUNT"]) == intval($arTopic["POSTS"])) {
             $url = CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_MESSAGE"], array("FID" => $arMessage["FORUM_ID"], "TID" => $arMessage["TOPIC_ID"], "MID" => $ID));
             $arFieldsForSocnet = array("ENTITY_TYPE" => $arRes["ENTITY_TYPE"], "ENTITY_ID" => $arRes["ENTITY_ID"], "EVENT_ID" => $this->event_comments_id, "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $parser->convert($arMessage["POST_MESSAGE"], $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($arMessage["POST_MESSAGE"]), "URL" => $url, "MODULE_ID" => false, "SOURCE_ID" => $ID, "LOG_ID" => $arRes["TMP_ID"], "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => intval($ID));
             if (intVal($arMessage["AUTHOR_ID"]) > 0) {
                 $arFieldsForSocnet["USER_ID"] = $arMessage["AUTHOR_ID"];
             }
             if ($bUpdate) {
                 $commentID = $this->_getSocnetLogCommentByForumComment($ID, $arRes);
                 if ($arMessage['APPROVED'] == 'Y') {
                     if ($commentID) {
                         CSocNetLogComments::Update($commentID, $arFieldsForSocnet);
                     } else {
                         $log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                         //, true
                         CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
                     }
                 } else {
                     if ($commentID) {
                         CSocNetLogComments::Delete($commentID);
                     }
                 }
             } else {
                 $log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                 //, true
                 CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
             }
         } else {
             $dbComments = CForumMessage::GetListEx(array(), array('TOPIC_ID' => $arMessage["TOPIC_ID"], "NEW_TOPIC" => "N"));
             while ($arComment = $dbComments->GetNext()) {
                 $url = CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_MESSAGE"], array("FID" => $arComment["FORUM_ID"], "TID" => $arComment["TOPIC_ID"], "MID" => $arComment["ID"]));
                 $arFieldsForSocnet = array("ENTITY_TYPE" => $arRes["ENTITY_TYPE"], "ENTITY_ID" => $arRes["ENTITY_ID"], "EVENT_ID" => $this->event_comments_id, "=LOG_DATE" => $GLOBALS["DB"]->CharToDateFunction($arComment['POST_DATE'], "FULL", SITE_ID), "MESSAGE" => $parser->convert($arComment["POST_MESSAGE"], $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($arComment["POST_MESSAGE"]), "URL" => $url, "MODULE_ID" => false, "SOURCE_ID" => $arComment["ID"], "LOG_ID" => $arRes["TMP_ID"], "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => intval($arComment["ID"]));
                 if (intVal($arComment["AUTHOR_ID"]) > 0) {
                     $arFieldsForSocnet["USER_ID"] = $arComment["AUTHOR_ID"];
                 }
                 $log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
                 //, true
                 CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC");
             }
         }
     }
 }
Example #12
0
    while ($arLog = $dbLog->Fetch()) {
        $arLogComments[] = $arLog;
    }
    foreach ($arLogComments as $arLogComment) {
        if (intval($arLogComment["SOURCE_ID"]) > 0) {
            $log_tmp_id = false;
            $arBlogComment = CBlogComment::GetByID($arLogComment["SOURCE_ID"]);
            if ($arBlogComment) {
                $dbLog = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "blog_post", "SOURCE_ID" => $arBlogComment["POST_ID"]), false, array("nTopCount" => 1), array("ID", "TMP_ID"));
                if ($arLog = $dbLog->Fetch()) {
                    $log_tmp_id = $arLog["TMP_ID"];
                }
            }
            if (intval($log_tmp_id) > 0) {
                $arFields = array("ENTITY_TYPE" => $arLogComment["ENTITY_TYPE"], "ENTITY_ID" => $arLogComment["ENTITY_ID"], "EVENT_ID" => "blog_comment", "LOG_DATE" => $arLogComment["LOG_DATE"], "MESSAGE" => $arLogComment["MESSAGE"], "TEXT_MESSAGE" => $arLogComment["TEXT_MESSAGE"], "URL" => $arLogComment["URL"], "MODULE_ID" => false, "SOURCE_ID" => $arLogComment["SOURCE_ID"], "LOG_ID" => $log_tmp_id, "USER_ID" => $arLogComment["USER_ID"]);
                CSocNetLogComments::Add($arFields, false, false, false);
                CSocNetLog::Delete($arLogComment["ID"]);
            }
        }
    }
}
$dbLog = CSocNetLog::GetList(array("LOG_DATE" => "ASC"), array("COMMENTS_COUNT" => false), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "SOURCE_ID", "USER_ID"));
while ($arLog = $dbLog->Fetch()) {
    CSocNetLog::Update($arLog["ID"], array("LOG_UPDATE" => $arLog["LOG_DATE"]));
}
if (IsModuleInstalled("intranet")) {
    $dbResult = CSocNetEventUserView::GetList(array("ENTITY_ID" => "ASC"), array("ENTITY_TYPE" => "N"));
    $arResult = $dbResult->Fetch();
    if (!$arResult) {
        CSocNetEventUserView::Add(array("ENTITY_TYPE" => "N", "ENTITY_ID" => 0, "EVENT_ID" => "news", "USER_ID" => 0, "USER_ANONYMOUS" => "N"));
        CSocNetEventUserView::Add(array("ENTITY_TYPE" => "N", "ENTITY_ID" => 0, "EVENT_ID" => "news_comment", "USER_ID" => 0, "USER_ANONYMOUS" => "N"));
Example #13
0
        CSocNetLog::Update($logID, array("TMP_ID" => $logID));
        CSocNetLogRights::DeleteByLogID($logID);
        CSocNetLogRights::Add($logID, $socnetPerms);
    }
}
foreach ($categoryID as $v) {
    CBlogPostCategory::Add(array("BLOG_ID" => $blogID, "POST_ID" => $postID, "CATEGORY_ID" => $v));
}
$arBlogCommentFields = array("TITLE" => GetMessage("BLOG_DEMO_COMMENT_TITLE"), "POST_TEXT" => GetMessage("BLOG_DEMO_COMMENT_BODY"), "BLOG_ID" => $blogID, "POST_ID" => $postID, "PARENT_ID" => 0, "AUTHOR_ID" => 1, "DATE_CREATE" => ConvertTimeStamp(false, "FULL"), "AUTHOR_IP" => "192.168.0.108");
$commmentId = CBlogComment::Add($arBlogCommentFields);
if (CModule::IncludeModule("socialnetwork")) {
    $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
    $text4message = $parserBlog->convert($arBlogCommentFields["POST_TEXT"], false, array(), $arAllow);
    $text4mail = $parserBlog->convert4mail($arBlogCommentFields["POST_TEXT"]);
    $arBlogUser = CBlogUser::GetByID(1, BLOG_BY_USER_ID);
    $arBlogUser = CBlogTools::htmlspecialcharsExArray($arBlogUser);
    $AuthorName = CBlogUser::GetUserName($arBlogUser["~ALIAS"], $arUser["~NAME"], $arUser["~LAST_NAME"], $arUser["~LOGIN"]);
    $commentUrl = CComponentEngine::MakePathFromTemplate(WIZARD_SITE_DIR . "company/personal/user/#user_id#/blog/#post_id#/", array("post_id" => $postID, "user_id" => 1));
    if (strpos($commentUrl, "?") !== false) {
        $commentUrl .= "&";
    } else {
        $commentUrl .= "?";
    }
    $commentUrl .= "commentId=" . $commmentId . "#" . $commmentId;
    $arSoFields = array("ENTITY_TYPE" => "U", "ENTITY_ID" => 1, "EVENT_ID" => "blog_comment", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $text4message, "TEXT_MESSAGE" => $text4mail, "URL" => $commentUrl, "MODULE_ID" => false, "SOURCE_ID" => $commmentId, "USER_ID" => 1, "LOG_ID" => $logID, "RATING_TYPE_ID" => "BLOG_COMMENT", "RATING_ENTITY_ID" => intval($commmentId));
    CSocNetLogComments::Add($arSoFields);
}
//CWizardUtil::ReplaceMacros(WIZARD_SITE_PATH."/community/index.php", Array("SONET_GROUP_ID" => $SocNetGroupID));
CWizardUtil::ReplaceMacros(WIZARD_SITE_PATH . "/company/personal.php", array("BLOG_GROUP_ID" => $SocNetGroupID));
CWizardUtil::ReplaceMacros(WIZARD_SITE_PATH . "/index_b24.php", array("BLOG_GROUP_ID" => $SocNetGroupID));
CWizardUtil::ReplaceMacros(WIZARD_SITE_PATH . "/workgroups/index.php", array("BLOG_GROUP_ID" => $SocNetGroupID));
Example #14
0
     $log_id = CBlogPost::Notify($arPost, $arBlog, $arParamsNotify);
 }
 $arImages = array();
 $res = CBlogImage::GetList(array("ID" => "ASC"), array("POST_ID" => $arPost["ID"], "BLOG_ID" => $arBlog["ID"], "IS_COMMENT" => "Y", "COMMENT_ID" => $commentId));
 while ($arImage = $res->Fetch()) {
     $arImages[$arImage["ID"]] = $arImage["FILE_ID"];
 }
 $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "TABLE" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
 $text4mail = $parserBlog->convert4mail($_POST['comment'], $arImages);
 if (intval($log_id) > 0) {
     $text4message = $parserBlog->convert($_POST['comment'], false, $arImages, $arAllow, array("isSonetLog" => true));
     $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_USER, "ENTITY_ID" => $arBlog["OWNER_ID"], "EVENT_ID" => "blog_comment", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $text4message, "TEXT_MESSAGE" => $text4mail, "URL" => $commentUrl, "MODULE_ID" => false, "SOURCE_ID" => $commentId, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "BLOG_COMMENT", "RATING_ENTITY_ID" => intval($commentId));
     if (intval($user_id) > 0) {
         $arFieldsForSocnet["USER_ID"] = $user_id;
     }
     $log_comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
     CSocNetLog::CounterIncrement($log_comment_id, false, false, "LC", CSocNetLogRights::CheckForUserAll($log_id));
 }
 $arPSR = CBlogPost::GetSocnetPerms($arPost["ID"]);
 $arUsrS = array();
 if (!empty($arPSR["U"])) {
     foreach ($arPSR["U"] as $k => $v) {
         $arUsrS[] = "U" . $k;
     }
 }
 preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/is" . BX_UTF_PCRE_MODIFIER, $_POST['comment'], $arMention);
 $arFieldsIM = array("TYPE" => "COMMENT", "TITLE" => htmlspecialcharsBack($arPost["TITLE"]), "URL" => $commentUrl, "ID" => $arPost["ID"], "FROM_USER_ID" => $user_id, "TO_USER_ID" => array($arPost["AUTHOR_ID"]), "TO_SOCNET_RIGHTS" => $arUsrS, "TO_SOCNET_RIGHTS_OLD" => array("U" => array(), "SG" => array()), "AUTHOR_ID" => $arPost["AUTHOR_ID"], "BODY" => $text4mail);
 if (!empty($arMention)) {
     $arFieldsIM["MENTION_ID"] = $arMention[1];
     if ($_POST["act"] != "edit" && is_array($arMention[1]) && !empty($arMention[1])) {
         $arMentionedDestCode = array();
Example #15
0
             $update_id = $arRes["ID"];
             $update_log_id = $arRes["LOG_ID"];
             $update_user_id = $arRes["USER_ID"];
             $update_source_id = $arRes["SOURCE_ID"];
         }
     }
     if (intval($update_id) > 0) {
         $bAllowUpdate = CSocNetLogComponent::canUserChangeComment(array("ACTION" => "EDIT", "LOG_ID" => $update_log_id, "LOG_EVENT_ID" => $arLog["EVENT_ID"], "LOG_SOURCE_ID" => $arLog["SOURCE_ID"], "COMMENT_ID" => $update_id, "COMMENT_USER_ID" => $update_user_id));
     }
     if ($bAllowUpdate) {
         $commentIdres = CSocNetLogComments::Update($update_id, $arFields, true);
     } else {
         $commentIdres = array("MESSAGE" => GetMessage("SONET_LOG_COMMENT_NO_PERMISSIONS_UPDATE"));
     }
 } else {
     $commentIdres = CSocNetLogComments::Add($arFields, true, false);
 }
 if (!is_array($commentIdres) && intval($commentIdres) > 0) {
     if ($editCommentSourceID <= 0) {
         $db_events = GetModuleEvents("socialnetwork", "OnAfterSocNetLogEntryCommentAdd");
         while ($arEvent = $db_events->Fetch()) {
             ExecuteModuleEventEx($arEvent, array($arLog));
         }
         $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogCommentCounterIncrement");
         while ($arEvent = $db_events->Fetch()) {
             if (ExecuteModuleEventEx($arEvent, array($arLog)) === false) {
                 $bSkipCounterIncrement = true;
                 break;
             }
         }
     } else {
Example #16
0
    private function AddComment()
    {
        global $DB;
        $arNotification = $this->Notify->getNotification();
        
        $arLog = CSocNetLog::GetList(
            array("ID" => "DESC"),
            array("SOURCE_ID" => $arNotification["POST_ID"]),
            false,
            false,
            array("ID", "RATING_ENTITY_ID")
        )->Fetch();

        if($arLog)
        {
            $arNotify = Array(
                "EVENT_ID" => "idea_comment",
                "=LOG_DATE" => $DB->CurrentTimeFunction(),
                "URL" => $arNotification["PATH"],
                "MESSAGE" => $arNotification["POST_TEXT"],
                "SOURCE_ID" => $arNotification["ID"],
                "ENTITY_TYPE" => SONET_ENTITY_USER,
                "ENTITY_ID" => $arNotification["AUTHOR_ID"],
                "USER_ID" => $arNotification["AUTHOR_ID"],
                "MODULE_ID" => 'idea',
                "LOG_ID" => $arLog["ID"],
            );
            
            if($arLog["RATING_ENTITY_ID"]>0)
            {
                $arNotify["RATING_ENTITY_ID"] = $arNotification["ID"];
                $arNotify["RATING_TYPE_ID"] = "BLOG_COMMENT";
            }
            
            if($arNotification["ACTION"] == "ADD")
                $LogCommentID = CSocNetLogComments::Add($arNotify, false, false);
            elseif($arNotification["ACTION"] == "UPDATE")
            {
                $arLogComment = CSocNetLogComments::GetList(            
                    array("ID" => "DESC"),
                    array("SOURCE_ID" => $arNotification["ID"]),
                    false,
                    false,
                    array("ID")
                )->Fetch();
                
                if($arLogComment)
                    $LogCommentID = CSocNetLogComments::Update($arLogComment["ID"], $arNotify);
            }
        }

        return $LogCommentID>0;
    }
Example #17
0
 public static function SocnetLogMessageAdd($arParams, $arMessageFields, $action = "")
 {
     static $parser = null;
     if ($parser == null) {
         $parser = new forumTextParser();
     }
     $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "LIST" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "SMILES" => "N", "UPLOAD" => "Y", "NL2BR" => "N", "TABLE" => "N", "ALIGN" => "N");
     //		$arParams["LOG_ID"], $arParams["LANG"] ....
     $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_ENTITY_GROUP, "ENTITY_ID" => $arParams["ENTITY_ID"], "EVENT_ID" => "forum", "=LOG_DATE" => !!$arMessageFields["DATE_CREATE"] ? $arMessageFields["DATE_CREATE"] : $GLOBALS["DB"]->CurrentTimeFunction(), "LOG_UPDATE" => !!$arMessageFields["POST_DATE"] ? $arMessageFields["POST_DATE"] : null, "TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $arMessageFields["AUTHOR_NAME"], CForumEmail::GetLangMessage("FORUM_MAIL_SOCNET_TITLE_TOPIC", $arParams["LANG"])), "TITLE" => $arMessageFields["TITLE"], "MESSAGE" => $parser->convert($arMessageFields["POST_MESSAGE"], $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($arMessageFields["POST_MESSAGE"]), "URL" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("UID" => $arMessageFields["AUTHOR_ID"], "FID" => $arMessageFields["FORUM_ID"], "TID" => $arMessageFields["TOPIC_ID"], "TITLE_SEO" => $arMessageFields["TOPIC_ID"], "MID" => $arMessageFields["ID"])), "PARAMS" => serialize(array("PATH_TO_MESSAGE" => CComponentEngine::MakePathFromTemplate($arParams["URL_TEMPLATES_MESSAGE"], array("TID" => $arMessageFields["TOPIC_ID"])))), "MODULE_ID" => false, "CALLBACK_FUNC" => false, "SOURCE_ID" => $arMessageFields["ID"], "RATING_TYPE_ID" => "FORUM_TOPIC", "RATING_ENTITY_ID" => $arMessageFields["TOPIC_ID"]);
     if ($arMessageFields["AUTHOR_ID"] > 0) {
         $arFieldsForSocnet["USER_ID"] = $arMessageFields["AUTHOR_ID"];
     }
     $db_res = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $arMessageFields["ID"]));
     $ufFileID = array();
     while ($res = $db_res->Fetch()) {
         $ufFileID[] = $res["FILE_ID"];
     }
     $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $arMessageFields["ID"], LANGUAGE_ID);
     $logID = $arParams["LOG_ID"];
     if ($logID <= 0) {
         if (!empty($ufFileID)) {
             $arFieldsForSocnet["UF_SONET_LOG_FILE"] = $ufFileID;
         }
         if ($ufDocID) {
             $arFieldsForSocnet["UF_SONET_LOG_DOC"] = $ufDocID;
         }
         $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);
             if ($action == "SEND_EVENT") {
                 CSocNetLog::SendEvent($logID, "SONET_NEW_EVENT", $logID);
             }
         }
     }
     if ($logID > 0 && $action == "ADD_COMMENT") {
         if (!empty($ufFileID)) {
             $arFieldsForSocnet["UF_SONET_COM_FILE"] = $ufFileID;
         }
         if ($ufDocID) {
             $arFieldsForSocnet["UF_SONET_COM_DOC"] = $ufDocID;
         }
         $arFieldsForSocnet["LOG_ID"] = $logID;
         $arFieldsForSocnet["RATING_TYPE_ID"] = "FORUM_POST";
         $arFieldsForSocnet["RATING_ENTITY_ID"] = $arMessageFields["ID"];
         $commentID = CSocNetLogComments::Add($arFieldsForSocnet);
         CSocNetLog::CounterIncrement($commentID, false, false, "LC");
         return $commentID;
     }
     return $logID;
 }
Example #18
0
 function onAfterForumMessageAdd($ID, $arForumMessage, $arTopicInfo, $arForumInfo, $arFields)
 {
     // add log comment
     if (array_key_exists("ADD_TO_LOG", $arFields) && $arFields["ADD_TO_LOG"] == "N") {
         return;
     }
     if (array_key_exists("NEW_TOPIC", $arFields) && $arFields["NEW_TOPIC"] == "Y") {
         return;
     }
     if (!array_key_exists("TOPIC_INFO", $arForumMessage) || !is_array($arForumMessage["TOPIC_INFO"]) || !array_key_exists("XML_ID", $arForumMessage["TOPIC_INFO"]) || empty($arForumMessage["TOPIC_INFO"]["XML_ID"]) || strpos($arForumMessage["TOPIC_INFO"]["XML_ID"], "IBLOCK_") !== 0) {
         return;
     }
     $val = COption::GetOptionString("intranet", "sonet_log_news_iblock_forum");
     $arIBlockForum = strlen($val) > 0 ? unserialize($val) : array();
     if (CModule::IncludeModule("socialnetwork") && in_array($arFields["FORUM_ID"], $arIBlockForum) && array_key_exists("PARAM2", $arFields) && intval($arFields["PARAM2"]) > 0) {
         CSocNetAllowed::GetAllowedEntityTypes();
         $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "news", "SOURCE_ID" => $arFields["PARAM2"]), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID"));
         if ($arRes = $dbRes->Fetch()) {
             $log_id = $arRes["ID"];
             $entity_id = $arRes["ENTITY_ID"];
             $arForum = CForumNew::GetByID($arFields["FORUM_ID"]);
             $parser = new textParser(LANGUAGE_ID);
             // second parameter - path to smile!
             $parser->image_params["width"] = false;
             $parser->image_params["height"] = false;
             $arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "LIST" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "UPLOAD" => $arForum["ALLOW_UPLOAD"], "NL2BR" => "N", "VIDEO" => "N", "SMILES" => "N");
             $arMessage = CForumMessage::GetByIDEx($ID);
             $url = CComponentEngine::MakePathFromTemplate($arParams["~URL_TEMPLATES_MESSAGE"], array("FID" => $arMessage["FORUM_ID"], "TID" => $arMessage["TOPIC_ID"], "MID" => $ID));
             $arFieldsForSocnet = array("ENTITY_TYPE" => SONET_SUBSCRIBE_ENTITY_NEWS, "ENTITY_ID" => $entity_id, "EVENT_ID" => "news_comment", "=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(), "MESSAGE" => $parser->convert($arFields["POST_MESSAGE"], $arAllow), "TEXT_MESSAGE" => $parser->convert4mail($arFields["POST_MESSAGE"]), "URL" => $url, "MODULE_ID" => false, "SOURCE_ID" => $ID, "LOG_ID" => $log_id, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $ID);
             if (intVal($arMessage["AUTHOR_ID"]) > 0) {
                 $arFieldsForSocnet["USER_ID"] = $arMessage["AUTHOR_ID"];
             }
             $comment_id = CSocNetLogComments::Add($arFieldsForSocnet, false, false);
             CSocNetLog::CounterIncrement($comment_id, false, false, "LC");
         }
     }
 }
Example #19
0
 function AddCommentToLog($arFields)
 {
     global $DB, $USER;
     CModule::IncludeModule("socialnetwork");
     $result = false;
     $LOG_ID = CTimeManNotify::SendMessage($arFields["ENTRY_ID"], 'A');
     $arMessFields = array("EVENT_ID" => "timeman_entry_comment", "ENTITY_ID" => $arFields["USER_ID"], "TEXT_MESSAGE" => $arFields["COMMENT_TEXT"], "MESSAGE" => $arFields["COMMENT_TEXT"], "USER_ID" => $arFields["USER_ID"], "ENTITY_TYPE" => SONET_TIMEMAN_ENTRY_ENTITY, "LOG_ID" => $LOG_ID, "=LOG_DATE" => $DB->CurrentTimeFunction());
     $result = CSocNetLogComments::Add($arMessFields, true, false);
     CSocNetLog::CounterIncrement($result, false, false, "LC");
     $curUser = $USER->GetID();
     $dbLogRights = CSocNetLogRights::GetList(array(), array("LOG_ID" => $LOG_ID));
     while ($arRight = $dbLogRights->Fetch()) {
         $arRights[] = $arRight["GROUP_CODE"];
     }
     if (!in_array("U" . $curUser, $arRights)) {
         CSocNetLogRights::Add($LOG_ID, "U" . $curUser);
     }
     return $result;
 }
Example #20
0
							"ENTITY_ID" => $arLog["ENTITY_ID"],
							"EVENT_ID" => $arCommentEvent["EVENT_ID"],
							"=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
							"MESSAGE" => $parser->convert($comment_text, array(), $arAllow),
							"TEXT_MESSAGE" => $comment_text,
							"MODULE_ID" => false,
							"LOG_ID" => $arLog["TMP_ID"],
							"USER_ID" => $GLOBALS["USER"]->GetID(),
							"PATH_TO_USER_BLOG_POST" => $arParams["PATH_TO_USER_BLOG_POST"],
							"PATH_TO_GROUP_BLOG_POST" => $arParams["PATH_TO_GROUP_BLOG_POST"],
							"PATH_TO_USER_MICROBLOG_POST" => $arParams["PATH_TO_USER_MICROBLOG_POST"],
							"PATH_TO_GROUP_MICROBLOG_POST" => $arParams["PATH_TO_GROUP_MICROBLOG_POST"],
							"BLOG_ALLOW_POST_CODE" => $arParams["BLOG_ALLOW_POST_CODE"]
						);

						$comment = CSocNetLogComments::Add($arFields, true);
						if (!is_array($comment) && intval($comment) > 0)
							$arResult["commentID"] = $comment;
						elseif (is_array($comment) &&  array_key_exists("MESSAGE", $comment) && strlen($comment["MESSAGE"]) > 0)
						{
							$arResult["strMessage"] = $comment["MESSAGE"];
							$arResult["commentText"] = $comment_text;
						}
					}
					else
						$arResult["strMessage"] = GetMessage("SONET_LOG_COMMENT_EMPTY");
				}
				else
					$arResult["strMessage"] = GetMessage("SONET_LOG_COMMENT_NO_PERMISSIONS");
			}
		}
	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
			));
	}
 public static function AddCommentToLog($arFields)
 {
     global $DB, $USER;
     CModule::IncludeModule("socialnetwork");
     $result = false;
     $dbLog = CSocNetLog::GetList(array(), array("SOURCE_ID" => $arFields["REPORT_ID"], "EVENT_ID" => "report"));
     if (!($arLog = $dbLog->Fetch())) {
         $LOG_ID = CReportNotifications::SendMessage($arFields["REPORT_ID"], false);
     } else {
         $LOG_ID = $arLog["ID"];
     }
     $arMessFields = array("EVENT_ID" => "report_comment", "ENTITY_ID" => $arFields["REPORT_OWNER"], "TEXT_MESSAGE" => $arFields["COMMENT_TEXT"], "MESSAGE" => $arFields["COMMENT_TEXT"], "USER_ID" => $arFields["USER_ID"], "ENTITY_TYPE" => "R", "LOG_ID" => $LOG_ID, "=LOG_DATE" => $DB->CurrentTimeFunction());
     $result = CSocNetLogComments::Add($arMessFields, true, false);
     CSocNetLog::CounterIncrement($result, false, false, "LC");
     $curUser = $USER->GetID();
     $dbLogRights = CSocNetLogRights::GetList(array(), array("LOG_ID" => $LOG_ID));
     while ($arRight = $dbLogRights->Fetch()) {
         $arRights[] = $arRight["GROUP_CODE"];
     }
     if (!in_array("U" . $curUser, $arRights)) {
         CSocNetLogRights::Add($LOG_ID, "U" . $curUser);
     }
     return $result;
 }
Example #23
0
	function OnAfterPhotoCommentAddBlog($ID, $arFields)
	{
		if (!CModule::IncludeModule('iblock'))
			return;

		if (!$this->IsSocnet)
			return;

		if (intval($this->PhotoElementID) > 0)
		{
			$dbRes = CSocNetLog::GetList(
				array("ID" => "DESC"),
				array(
					"EVENT_ID"	=> "photo_photo",
					"SOURCE_ID"	=> $this->PhotoElementID
				),
				false,
				false,
				array("ID", "ENTITY_TYPE", "ENTITY_ID", "TMP_ID")
			);

			$bSocNetLogRecordExists = false;
			if ($arRes = $dbRes->Fetch())
			{
				$log_id = $arRes["ID"];
				$entity_type = $arRes["ENTITY_TYPE"];
				$entity_id = $arRes["ENTITY_ID"];
				$bSocNetLogRecordExists = true;
			}
			else
			{
				$rsElement = CIBlockElement::GetByID($this->PhotoElementID);
				if ($arElement = $rsElement->Fetch())
				{
					$url = $this->arPath["DETAIL_URL"];

					$sAuthorName = GetMessage("SONET_LOG_GUEST");
					if (intval($arElement["CREATED_BY"]) > 0)
					{
						$rsUser = CUser::GetByID($arElement["CREATED_BY"]);
						if ($arUser = $rsUser->Fetch())
							$sAuthorName = CUser::FormatName(CSite::GetNameFormat(false), $arUser, true, false);
					}

					if (
						in_array($this->entity_type, array(SONET_ENTITY_USER, SONET_ENTITY_GROUP))
						&& intval($this->entity_id) > 0
					)
					{
						$entity_type = $this->entity_type;
						$entity_id = $this->entity_id;
						$alias = ($this->entity_type == SONET_ENTITY_GROUP ? "group" : "user")."_".$this->entity_id;
					}

					$arLogParams = array(
						"BLOG_ID" => intval($this->BlogID)
					);

					$rsIBlock = CIBlock::GetByID($arElement["IBLOCK_ID"]);
					if($arIBlock = $rsIBlock->Fetch())
					{
						$arLogParams["IBLOCK_ID"] = $arIBlock["ID"];
						$arLogParams["IBLOCK_TYPE"] = $arIBlock["IBLOCK_TYPE_ID"];
					}

					$rsSection = CIBlockSection::GetByID($arElement["IBLOCK_SECTION_ID"]);
					if ($arSection = $rsSection->Fetch())
					{
						$arLogParams["SECTION_ID"] = $arSection["ID"];
						$arLogParams["SECTION_NAME"] = $arSection["NAME"];
						$arLogParams["SECTION_URL"] = str_replace("#SECTION_ID#", $arSection["ID"], $this->arPath["SECTION_URL"]);

						if (!$alias)
						{
							$arSectionPath = array();
							$rsPath = CIBlockSection::GetNavChain($arLogParams["IBLOCK_ID"], intval($arLogParams["SECTION_ID"]));
							if($arPath = $rsPath->Fetch())
							{
								$entity_type = SONET_ENTITY_USER;
								$entity_id = $arPath["CREATED_BY"];
								$alias = $arPath["CODE"];
							}
						}
					}

					$arLogParams["ALIAS"] = $alias;

					$arSonetFields = array(
						"ENTITY_TYPE" => $entity_type,
						"ENTITY_ID" => $entity_id,
						"EVENT_ID" => "photo_photo",
						"LOG_DATE" => $arElement["TIMESTAMP_X"],
						"TITLE_TEMPLATE" => str_replace("#AUTHOR_NAME#", $sAuthorName, GetMessage("SONET_PHOTOPHOTO_LOG_1")),
						"TITLE" => $arElement["NAME"],
						"MESSAGE" => "",
						"TEXT_MESSAGE" => "",
						"URL" => CComponentEngine::MakePathFromTemplate($url, array(
							"ELEMENT_ID" => $arElement["ID"],
							"element_id" => $arElement["ID"],
							"SECTION_ID" => $arElement["IBLOCK_SECTION_ID"],
							"section_id" => $arElement["IBLOCK_SECTION_ID"]
						)),
						"MODULE_ID" => false,
						"CALLBACK_FUNC" => false,
						"SOURCE_ID" => $arElement["ID"],
						"PARAMS" => serialize($arLogParams),
						"RATING_TYPE_ID" 	=> "IBLOCK_ELEMENT",
						"RATING_ENTITY_ID"=> $arElement["ID"],
					);

					if (intval($arElement["CREATED_BY"]) > 0)
						$arSonetFields["USER_ID"] = $arElement["CREATED_BY"];

					$log_id = CSocNetLog::Add($arSonetFields, false);
					if (intval($log_id) > 0)
					{
						CSocNetLog::Update($log_id, array("TMP_ID" => $log_id));
						CSocNetLogRights::SetForSonet($log_id, $entity_type, $entity_id, "photo", "view", true);
					}
				}
			}

			if (intval($log_id) > 0)
			{
				$parserBlog = new blogTextParser(false, $this->arPath["PATH_TO_SMILE"]);
				$arAllow = array("HTML" => "N", "ANCHOR" => "N", "BIU" => "N", "IMG" => "N", "QUOTE" => "N", "CODE" => "N", "FONT" => "N", "LIST" => "N", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "N");
				
				if ($bSocNetLogRecordExists)
				{
					$text4message = $parserBlog->convert($arFields["POST_TEXT"], true, array(), $arAllow);
					$text4mail = $parserBlog->convert4mail($arFields["POST_TEXT"]);

					$arFieldsForSocnet = array(
						"ENTITY_TYPE" => $entity_type,
						"ENTITY_ID" => $entity_id,
						"EVENT_ID" => "photo_comment",
						"=LOG_DATE" => $GLOBALS["DB"]->CurrentTimeFunction(),
						"MESSAGE" => $text4message,
						"TEXT_MESSAGE" => $text4mail,
						"MODULE_ID" => false,
						"SOURCE_ID" => $ID,
						"LOG_ID" => $log_id,
						"RATING_TYPE_ID" => "BLOG_COMMENT",
						"RATING_ENTITY_ID" => $ID,
					);

					if (intval($arFields["AUTHOR_ID"]) > 0)
						$arFieldsForSocnet["USER_ID"] = $arFields["AUTHOR_ID"];

					CSocNetLogComments::Add($arFieldsForSocnet);
				}
				else //socnetlog record didn't exist - adding all comments
				{
					$dbComments = CBlogComment::GetList(array(), 
						array(
							"BLOG_ID" => intval($this->BlogID), 
							"POST_ID" => intval($this->PostID)
						), 
						false, 
						false, 
						array("ID", "BLOG_ID", "POST_ID", "AUTHOR_ID", "POST_TEXT", "DATE_CREATE")
						);

					while ($arComment = $dbComments->GetNext())
					{
						$text4message = $parserBlog->convert($arComment["POST_TEXT"], true, array(), $arAllow);
						$text4mail = $parserBlog->convert4mail($arComment["POST_TEXT"]);

						$arFieldsForSocnet = array(
							"ENTITY_TYPE" => $entity_type,
							"ENTITY_ID" => $entity_id,
							"EVENT_ID" => "photo_comment",
							"=LOG_DATE" => $GLOBALS["DB"]->CharToDateFunction($arComment["DATE_CREATE"], "FULL", SITE_ID),
							"MESSAGE" => $text4message,
							"TEXT_MESSAGE" => $text4mail,
							"MODULE_ID" => false,
							"SOURCE_ID" => intval($arComment["ID"]),
							"LOG_ID" => $log_id,
							"RATING_TYPE_ID" => "BLOG_COMMENT",
							"RATING_ENTITY_ID" => intval($arComment["ID"]),
						);

						if (intval($arFields["AUTHOR_ID"]) > 0)
							$arFieldsForSocnet["USER_ID"] = $arFields["AUTHOR_ID"];

						CSocNetLogComments::Add($arFieldsForSocnet);
					}
				}
			}
		}
	}