public static function Add($LOG_ID, $GROUP_CODE, $bShare = false, $followSet = true) { global $DB; if (is_array($GROUP_CODE)) { foreach ($GROUP_CODE as $GROUP_CODE_TMP) { CSocNetLogRights::Add($LOG_ID, $GROUP_CODE_TMP, $bShare, $followSet); } return false; } else { $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogRightsAdd"); while ($arEvent = $db_events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array($LOG_ID, $GROUP_CODE)) === false) { return false; } } $NEW_RIGHT_ID = $DB->Add("b_sonet_log_right", array("LOG_ID" => $LOG_ID, "GROUP_CODE" => $GROUP_CODE), array(), "", true); if ($NEW_RIGHT_ID) { if (preg_match('/^U(\\d+)$/', $GROUP_CODE, $matches)) { if ($followSet) { CSocNetLogFollow::Set($matches[1], "L" . $LOG_ID, "Y", ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID)); } } elseif ($bShare && preg_match('/^SG(\\d+)$/', $GROUP_CODE, $matches)) { // get all members who unfollow and set'em unfollow from the date $arUserIDToCheck = array(); $rsGroupMembers = CSocNetUserToGroup::GetList(array(), array("GROUP_ID" => $matches[1], "USER_ACTIVE" => "Y", "<=ROLE" => SONET_ROLES_USER), false, false, array("USER_ID")); while ($arGroupMembers = $rsGroupMembers->Fetch()) { $arUserIDToCheck[] = $arGroupMembers["USER_ID"]; } if (!empty($arUserIDToCheck)) { $arUserIDFollowDefault = array("Y" => array(), "N" => array()); $arUserIDAlreadySaved = array(); $default_follow_type = COption::GetOptionString("socialnetwork", "follow_default_type", "Y"); $rsFollow = CSocNetLogFollow::GetList(array("USER_ID" => $arUserIDToCheck, "CODE" => "**"), array("USER_ID", "TYPE")); while ($arFollow = $rsFollow->Fetch()) { $arUserIDFollowDefault[$arFollow["TYPE"]][] = $arFollow["USER_ID"]; } $rsFollow = CSocNetLogFollow::GetList(array("USER_ID" => $arUserIDToCheck, "CODE" => "L" . $LOG_ID), array("USER_ID")); while ($arFollow = $rsFollow->Fetch()) { $arUserIDAlreadySaved[] = $arFollow["USER_ID"]; } foreach ($arUserIDToCheck as $iUserID) { // for them who not followed by default and not already saved follow/unfollow for the log entry if (!in_array($iUserID, $arUserIDAlreadySaved) && ($default_follow_type == "N" && !in_array($iUserID, $arUserIDFollowDefault["Y"]) || $default_follow_type == "Y" && in_array($iUserID, $arUserIDFollowDefault["N"]))) { CSocNetLogFollow::Add($iUserID, "L" . $LOG_ID, "N", ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID)); } } } } } if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_" . intval($LOG_ID)); } return $NEW_RIGHT_ID; } }
public static function GetDefaultValue($user_id) { if (intval($user_id) <= 0) return false; global $CACHE_MANAGER; if(defined("BX_COMP_MANAGED_CACHE")) $ttl = 2592000; else $ttl = 600; $cache_id = 'sonet_follow_default_'.$user_id; $obCache = new CPHPCache; $cache_dir = '/sonet/log_follow/'.$user_id.'/'; if($obCache->InitCache($ttl, $cache_id, $cache_dir)) { $tmpVal = $obCache->GetVars(); $default_follow = $tmpVal["VALUE"]; unset($tmpVal); } else { $default_follow = false; if (is_object($obCache)) $obCache->StartDataCache($ttl, $cache_id, $cache_dir); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->StartTagCache($cache_dir); $GLOBALS["CACHE_MANAGER"]->RegisterTag("SONET_LOG_FOLLOW_".$user_id); } $rsFollow = CSocNetLogFollow::GetList( array( "USER_ID" => $user_id, "CODE" => "**" ), array("TYPE") ); if ($arFollow = $rsFollow->Fetch()) $default_follow = $arFollow["TYPE"]; if (is_object($obCache)) { $arCacheData = Array( "VALUE" => $default_follow ); $obCache->EndDataCache($arCacheData); if(defined("BX_COMP_MANAGED_CACHE")) $GLOBALS["CACHE_MANAGER"]->EndTagCache(); } } unset($obCache); if (!$default_follow) $default_follow = COption::GetOptionString("socialnetwork", "follow_default_type", "Y"); return $default_follow; }
public static function NotifyGroup($arFields) { if (!CModule::IncludeModule("im")) { return; } if (!is_array($arFields["GROUP_ID"])) { $arFields["GROUP_ID"] = array($arFields["GROUP_ID"]); } if (empty($arFields["GROUP_ID"])) { return; } if (empty($arFields["EXCLUDE_USERS"])) { $arFields["EXCLUDE_USERS"] = array(); } if (intval($arFields["LOG_ID"]) > 0) { $rsUnFollower = CSocNetLogFollow::GetList(array("CODE" => "L" . intval($arFields["LOG_ID"]), "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arFields["EXCLUDE_USERS"][] = $arUnFollower["USER_ID"]; } $arFields["EXCLUDE_USERS"] = array_unique($arFields["EXCLUDE_USERS"]); } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "socialnetwork", "NOTIFY_EVENT" => "sonet_group_event", "NOTIFY_TAG" => "SONET|EVENT|" . (intval($arFields["LOG_ID"]) > 0 ? $arFields["LOG_ID"] : rand())); if (intval($arFields["FROM_USER_ID"]) > 0) { $arMessageFields["FROM_USER_ID"] = $arFields["FROM_USER_ID"]; } $arUserToSend = array(); $arUserIDToSend = array(); $arGroupID = array(); $arCodes = array(); foreach ($arFields["GROUP_ID"] as $group_id) { $arCodes[] = "SG" . $group_id; } $rsSubscriber = CSocNetSubscription::GetList(array(), array("CODE" => $arCodes), false, false, array("USER_ID", "CODE")); while ($arSubscriber = $rsSubscriber->Fetch()) { if (!in_array($arSubscriber["USER_ID"], $arFields["EXCLUDE_USERS"]) && !in_array($arSubscriber["USER_ID"], $arUserIDToSend)) { if (preg_match('/^SG(\\d+)$/', $arSubscriber["CODE"], $matches)) { $arUserToSend[] = array("USER_ID" => $arSubscriber["USER_ID"], "GROUP_ID" => $matches[1]); $arUserIDToSend[] = $arSubscriber["USER_ID"]; $arGroupID[] = $matches[1]; } } } $rsGroup = CSocNetGroup::GetList(array(), array("ID" => $arGroupID), false, false, array("ID", "NAME", "OWNER_ID")); while ($arGroup = $rsGroup->GetNext()) { $arGroups[$arGroup["ID"]] = $arGroup; } $workgroupsPage = COption::GetOptionString("socialnetwork", "workgroups_page", "/workgroups/", SITE_ID); $groupUrlTemplate = COption::GetOptionString("socialnetwork", "group_path_template", "/workgroups/group/#group_id#/", SITE_ID); $groupUrlTemplate = "#GROUPS_PATH#" . substr($groupUrlTemplate, strlen($workgroupsPage), strlen($groupUrlTemplate) - strlen($workgroupsPage)); foreach ($arUserToSend as $arUser) { $arMessageFields["TO_USER_ID"] = $arUser["USER_ID"]; $arTmp = CSocNetLogTools::ProcessPath(array("URL" => $arFields["URL"], "GROUP_URL" => str_replace(array("#group_id#", "#GROUP_ID#"), $arUser["GROUP_ID"], $groupUrlTemplate)), $arUser["USER_ID"]); $url = $arTmp["URLS"]["URL"]; if (strpos($url, "http://") === 0 || strpos($url, "https://") === 0) { $serverName = ""; } else { $serverName = $arTmp["SERVER_NAME"]; } $groupUrl = $serverName . $arTmp["URLS"]["GROUP_URL"]; $group_name = array_key_exists($arUser["GROUP_ID"], $arGroups) ? $arGroups[$arUser["GROUP_ID"]]["NAME"] : ""; $arMessageFields["NOTIFY_MESSAGE"] = str_replace(array("#URL#", "#url#", "#group_name#", "#GROUP_ID#", "#group_id#"), array($url, $url, "<a href=\"" . $groupUrl . "\" class=\"bx-notifier-item-action\">" . $group_name . "</a>", $arUser["GROUP_ID"], $arUser["GROUP_ID"]), $arFields["MESSAGE"]); $arMessageFields["NOTIFY_MESSAGE_OUT"] = str_replace(array("#URL#", "#url#", "#group_name#"), array($serverName . $url, $serverName . $url, $group_name), $arFields["MESSAGE_OUT"]); $arMessageFields2Send = $arMessageFields; if (!is_set($arMessageFields2Send["FROM_USER_ID"]) || intval($arMessageFields2Send["FROM_USER_ID"]) <= 0) { $arMessageFields2Send["NOTIFY_TYPE"] = IM_NOTIFY_SYSTEM; $arMessageFields2Send["FROM_USER_ID"] = 0; } CIMNotify::Add($arMessageFields2Send); } }
public static function AddCommentToIM($arFields) { if (CModule::IncludeModule("im") && intval($arFields["USER_ID"]) > 0) { $date_text = ""; $dbReport = CTimeManReportFull::GetByID($arFields["REPORT_ID"]); if ($arReport = $dbReport->Fetch()) { $date_from = FormatDate("j F", MakeTimeStamp($arReport["DATE_FROM"], CSite::GetDateFormat("FULL", SITE_ID))); $date_to = FormatDate("j F", MakeTimeStamp($arReport["DATE_TO"], CSite::GetDateFormat("FULL", SITE_ID))); if ($date_from == $date_to) { $date_text = $date_to; } else { $date_text = $date_from . " - " . $date_to; } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $arFields["USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "timeman", "NOTIFY_EVENT" => "report_comment", "NOTIFY_TAG" => "TIMEMAN|REPORT|" . $arFields["REPORT_ID"]); $arUserIDToSend = array($arReport["USER_ID"]); $gender_suffix = ""; $dbUser = CUser::GetByID($arFields["USER_ID"]); if ($arUser = $dbUser->Fetch()) { switch ($arUser["PERSONAL_GENDER"]) { case "M": $gender_suffix = "_M"; break; case "F": $gender_suffix = "_F"; break; default: $gender_suffix = ""; } } $arManagers = CTimeMan::GetUserManagers($arReport["USER_ID"]); if (is_array($arManagers)) { $arUserIDToSend = array_merge($arUserIDToSend, $arManagers); } $reports_page = COption::GetOptionString("timeman", "WORK_REPORT_PATH", "/company/work_report.php"); $arUnFollowers = array(); $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arUserIDToSend, "CODE" => "L" . $arFields["LOG_ID"], "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arUnFollowers[] = $arUnFollower["USER_ID"]; } $arUserIDToSend = array_diff($arUserIDToSend, $arUnFollowers); foreach ($arUserIDToSend as $user_id) { if ($arFields["USER_ID"] == $user_id) { continue; } $arMessageFields["TO_USER_ID"] = $user_id; $arTmp = CSocNetLogTools::ProcessPath(array("REPORTS_PAGE" => $reports_page), $user_id); $sender_type = $arReport["USER_ID"] == $user_id ? "1" : ($arReport["USER_ID"] == $arFields["USER_ID"] ? "2" : "3"); $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("REPORT_FULL_IM_COMMENT_" . $sender_type . $gender_suffix, array("#period#" => "<a href=\"" . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $arReport["ID"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($date_text) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("REPORT_FULL_IM_COMMENT_" . $sender_type . $gender_suffix, array("#period#" => htmlspecialcharsbx($date_text))) . " ( " . $arTmp["SERVER_NAME"] . $arTmp["URLS"]["REPORTS_PAGE"] . "#user_id=" . $arReport["USER_ID"] . "&report=" . $arReport["ID"] . " )#BR##BR#" . $arFields["MESSAGE"]; CIMNotify::Add($arMessageFields); } } } }
public static function SendMentionNotification($arCommentFields) { if (!CModule::IncludeModule("im")) { return false; } switch ($arCommentFields["EVENT_ID"]) { case "forum": $arTitleRes = self::OnSendMentionGetEntityFields_Forum($arCommentFields); break; default: $db_events = GetModuleEvents("socialnetwork", "OnSendMentionGetEntityFields"); while ($arEvent = $db_events->Fetch()) { $arTitleRes = ExecuteModuleEventEx($arEvent, array($arCommentFields)); if ($arTitleRes) { break; } } } if ($arTitleRes && is_array($arTitleRes) && !empty($arTitleRes["NOTIFY_MESSAGE"])) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "FROM_USER_ID" => $arCommentFields["USER_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => !empty($arTitleRes["NOTIFY_MODULE"]) ? $arTitleRes["NOTIFY_MODULE"] : "socialnetwork", "NOTIFY_EVENT" => "mention", "NOTIFY_TAG" => !empty($arTitleRes["NOTIFY_TAG"]) ? $arTitleRes["NOTIFY_TAG"] : "LOG_COMMENT|COMMENT_MENTION|" . $arCommentFields["ID"]); preg_match_all("/\\[user\\s*=\\s*([^\\]]*)\\](.+?)\\[\\/user\\]/ies" . BX_UTF_PCRE_MODIFIER, $arCommentFields["MESSAGE"], $arMention); if (!empty($arMention)) { $arMention = $arMention[1]; $arExcludeUsers = array(); if (!empty($arCommentFields["LOG_ID"])) { $rsUnFollower = CSocNetLogFollow::GetList(array("CODE" => "L" . $arCommentFields["LOG_ID"], "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arExcludeUsers[] = $arUnFollower["USER_ID"]; } } $arSourceURL = array("URL" => $arTitleRes["URL"]); if (!empty($arTitleRes["CRM_URL"])) { $arSourceURL["CRM_URL"] = $arTitleRes["CRM_URL"]; } foreach ($arMention as $mentionUserID) { $bHaveRights = CSocNetLogRights::CheckForUserOnly($arCommentFields["LOG_ID"], $mentionUserID); if (!$bHaveRights && $arTitleRes["IS_CRM"] == "Y") { $dbLog = CSocNetLog::GetList(array(), array("ID" => $arCommentFields["LOG_ID"], "ENTITY_TYPE" => $arCommentFields["ENTITY_TYPE"]), false, false, array("ID"), array("IS_CRM" => "Y", "CHECK_CRM_RIGHTS" => "Y", "USER_ID" => $mentionUserID, "USE_SUBSCRIBE" => "N")); if ($arLog = $dbLog->Fetch()) { $bHaveCrmRights = true; } } if (in_array($mentionUserID, $arExcludeUsers) || !$bHaveRights && !$bHaveCrmRights) { continue; } $url = false; if (!empty($arSourceURL["URL"]) || !empty($arSourceURL["CRM_URL"])) { $arTmp = CSocNetLogTools::ProcessPath($arSourceURL, $mentionUserID); if ($arTitleRes["IS_CRM"] == "Y" && !$bHaveRights && !empty($arTmp["URLS"]["CRM_URL"])) { $url = $arTmp["URLS"]["CRM_URL"]; } else { $url = $arTmp["URLS"]["URL"]; } $serverName = strpos($url, "http://") === 0 || strpos($url, "https://") === 0 ? "" : $arTmp["SERVER_NAME"]; } $arMessageFields["TO_USER_ID"] = $mentionUserID; $arMessageFields["NOTIFY_MESSAGE"] = str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE"]); $arMessageFields["NOTIFY_MESSAGE_OUT"] = !empty($arTitleRes["NOTIFY_MESSAGE_OUT"]) ? str_replace(array("#url#", "#server_name#"), array($url, $serverName), $arTitleRes["NOTIFY_MESSAGE_OUT"]) : ""; CIMNotify::Add($arMessageFields); } $arMentionedDestCode = array(); foreach ($arMention as $val) { $arMentionedDestCode[] = "U" . $val; } \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "mention", "CODE" => array_unique($arMentionedDestCode))); } } }
static function AddComment_Wiki($arFields) { if (!CModule::IncludeModule('iblock')) { return false; } if (!CModule::IncludeModule('socialnetwork')) { return false; } $ufFileID = array(); $ufDocID = array(); $dbResult = CSocNetLog::GetList(array('ID' => 'DESC'), array('TMP_ID' => $arFields['LOG_ID']), false, false, array('ID', 'SOURCE_ID', 'PARAMS', 'URL')); $bFound = false; if ($arLog = $dbResult->Fetch()) { if (strlen($arLog['PARAMS']) > 0) { $arFieldsParams = explode('&', $arLog['PARAMS']); if (is_array($arFieldsParams) && count($arFieldsParams) > 0) { foreach ($arFieldsParams as $tmp) { list($key, $value) = explode('=', $tmp); if ($key == 'forum_id') { $FORUM_ID = intval($value); break; } } } } if ($FORUM_ID > 0 && intval($arLog['SOURCE_ID']) > 0) { $bFound = true; } } if ($bFound) { $arElement = false; $arFilter = array('ID' => $arLog['SOURCE_ID']); $arSelectedFields = array('IBLOCK_ID', 'ID', 'NAME', 'TAGS', 'CODE', 'IBLOCK_SECTION_ID', 'DETAIL_PAGE_URL', 'CREATED_BY', 'PREVIEW_PICTURE', 'PREVIEW_TEXT', 'PROPERTY_FORUM_TOPIC_ID', 'PROPERTY_FORUM_MESSAGE_CNT'); $db_res = CIBlockElement::GetList(array(), $arFilter, false, false, $arSelectedFields); if ($db_res && ($res = $db_res->GetNext())) { $arElement = $res; } if ($arElement) { // check iblock properties CSocNetLogTools::AddComment_Review_CheckIBlock($arElement); $dbMessage = CForumMessage::GetList(array(), array('PARAM2' => $arElement['ID'])); if (!($arMessage = $dbMessage->Fetch())) { // Add Topic and Root Message $TOPIC_ID = CSocNetLogTools::AddComment_Review_CreateRoot($arElement, $FORUM_ID, false); $bNewTopic = true; } else { $TOPIC_ID = $arMessage['TOPIC_ID']; } if (intval($TOPIC_ID) > 0) { // Add comment $messageID = false; $arFieldsMessage = array('POST_MESSAGE' => $arFields['TEXT_MESSAGE'], 'USE_SMILES' => 'Y', 'PARAM2' => $arElement['ID'], 'APPROVED' => 'Y'); $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsMessage["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id); } } } $messageID = ForumAddMessage('REPLY', $FORUM_ID, $TOPIC_ID, 0, $arFieldsMessage, $sError, $sNote); if (!$messageID) { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } else { $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID); CSocNetLogTools::AddComment_Review_UpdateElement($arElement, $TOPIC_ID, $bNewTopic); $userID = $GLOBALS["USER"]->GetID(); if (CModule::IncludeModule("im") && intval($arElement["CREATED_BY"]) > 0 && $arElement["CREATED_BY"] != $userID) { $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arElement["CREATED_BY"], "CODE" => "L" . $arLog["ID"], "TYPE" => "N"), array("USER_ID")); $arUnFollower = $rsUnFollower->Fetch(); if (!$arUnFollower) { $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arElement["CREATED_BY"], "FROM_USER_ID" => $userID, "LOG_ID" => $arLog["ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "wiki", "NOTIFY_EVENT" => "comment"); $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arElement["NAME"]); $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100); $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255); $arTmp = CSocNetLogTools::ProcessPath(array("ELEMENT_URL" => $arLog["URL"]), $arElement["CREATED_BY"]); $serverName = $arTmp["SERVER_NAME"]; $url = $arTmp["URLS"]["ELEMENT_URL"]; $arMessageFields["NOTIFY_TAG"] = "WIKI|COMMENT|" . $arElement['ID']; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("WIKI_SONET_FROM_LOG_IM_COMMENT", array("#title#" => strlen($url) > 0 ? "<a href=\"" . $url . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>" : htmlspecialcharsbx($arParams["TITLE"]))); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("WIKI_SONET_FROM_LOG_IM_COMMENT", array("#title#" => htmlspecialcharsbx($arParams["TITLE"]))) . (strlen($url) > 0 ? " (" . $serverName . $url . ")" : "") . "#BR##BR#" . $arFields["TEXT_MESSAGE"]; CIMNotify::Add($arMessageFields); } } } } else { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } } else { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } } else { $strError = GetMessage('SONET_ADD_COMMENT_SOURCE_ERROR'); } return array('SOURCE_ID' => $messageID, 'RATING_TYPE_ID' => 'FORUM_POST', 'RATING_ENTITY_ID' => $messageID, 'ERROR' => $strError, 'NOTES' => '', "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID)); }
function Add($arFields, $bSetSource = false, $bSendEvent = true, $bSetLogUpDate = true) { global $DB; $arFields1 = array(); foreach ($arFields as $key => $value) { if (substr($key, 0, 1) == "=") { $arFields1[substr($key, 1)] = $value; unset($arFields[$key]); } } if ( $bSetSource && strlen($arFields["EVENT_ID"]) > 0) { $arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arFields["EVENT_ID"]); if ( !$arCommentEvent || !array_key_exists("ADD_CALLBACK", $arCommentEvent) || !is_callable($arCommentEvent["ADD_CALLBACK"]) ) { $bSetSource = false; } } $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogCommentAdd"); while ($arEvent = $db_events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$arFields))===false) { return false; } } if ($bSetSource) { $arSource = CSocNetLogComments::SetSource($arFields); if ( $arSource["NO_SOURCE"] == "Y" || intval($arSource["SOURCE_ID"]) > 0 ) { if ($arSource["NO_SOURCE"] == "Y") $bSetSource = false; else $arFields["SOURCE_ID"] = $arSource["SOURCE_ID"]; if ( array_key_exists("RATING_ENTITY_ID", $arSource) && array_key_exists("RATING_TYPE_ID", $arSource) && intval($arSource["RATING_ENTITY_ID"]) > 0 && strlen($arSource["RATING_TYPE_ID"]) > 0 ) { $arFields["RATING_TYPE_ID"] = $arSource["RATING_TYPE_ID"]; $arFields["RATING_ENTITY_ID"] = $arSource["RATING_ENTITY_ID"]; } if (isset($arSource["MESSAGE"]) && strlen($arSource["MESSAGE"]) > 0) $arFields["MESSAGE"] = $arSource["MESSAGE"]; if (isset($arSource["TEXT_MESSAGE"]) && strlen($arSource["TEXT_MESSAGE"]) > 0) $arFields["TEXT_MESSAGE"] = $arSource["TEXT_MESSAGE"]; if (isset($arSource["URL"]) && strlen($arSource["URL"]) > 0) $arFields["URL"] = $arSource["URL"]; if ( isset($arSource["UF"]) && isset($arSource["UF"]["FILE"]) ) { if (!is_array($arSource["UF"]["FILE"])) $arSource["UF"]["FILE"] = array($arSource["UF"]["FILE"]); $arFields["UF_SONET_COM_FILE"] = $arSource["UF"]["FILE"]; } if ( isset($arSource["UF"]) && isset($arSource["UF"]["DOC"]) ) { if (!is_array($arSource["UF"]["DOC"])) $arSource["UF"]["DOC"] = array($arSource["UF"]["DOC"]); $arFields["UF_SONET_COM_DOC"] = $arSource["UF"]["DOC"]; } } else { $strMessage = ( array_key_exists("ERROR", $arSource) && strlen($arSource["ERROR"]) > 0 ? $arSource["ERROR"] : ( array_key_exists("NOTES", $arSource) && strlen($arSource["NOTES"]) > 0 ? $arSource["NOTES"] : "" ) ); } } if (!CSocNetLogComments::CheckFields("ADD", $arFields)) { if ($e = $GLOBALS["APPLICATION"]->GetException()) { $errorMessage = $e->GetString(); } if (strlen($errorMessage) <= 0) { $errorMessage = GetMessage("SONET_GLC_ERROR_CHECKFIELDS_FAILED"); } return array( "ID" => false, "MESSAGE" => $errorMessage ); return false; } if ( !$bSetSource || ( is_array($arSource) && array_key_exists("SOURCE_ID", $arFields) && intval($arFields["SOURCE_ID"]) > 0 ) ) { $arInsert = $DB->PrepareInsert("b_sonet_log_comment", $arFields); foreach ($arFields1 as $key => $value) { if (strlen($arInsert[0]) > 0) $arInsert[0] .= ", "; $arInsert[0] .= $key; if (strlen($arInsert[1]) > 0) $arInsert[1] .= ", "; $arInsert[1] .= $value; } $ID = false; if (strlen($arInsert[0]) > 0) { $strSql = "INSERT INTO b_sonet_log_comment(".$arInsert[0].") ". "VALUES(".$arInsert[1].")"; $DB->Query($strSql, False, "File: ".__FILE__."<br>Line: ".__LINE__); $ID = IntVal($DB->LastID()); if ($ID > 0) { if ( !array_key_exists("RATING_TYPE_ID", $arFields) || empty($arFields["RATING_TYPE_ID"]) ) CSocNetLogComments::Update($ID, array( "RATING_TYPE_ID" => "LOG_COMMENT", "RATING_ENTITY_ID" => $ID )); CSocNetLogFollow::Set( $arFields["USER_ID"], "L".$arFields["LOG_ID"], "Y", ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL") ); $rsLog = CSocNetLog::GetList( array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "USER_ID") ); if ( ($arLog = $rsLog->Fetch()) && (intval($arLog["USER_ID"]) > 0) ) { $default_follow = CSocNetLogFollow::GetDefaultValue($arLog["USER_ID"]); if ($default_follow != "Y") { $rsLogFollow = CSocNetLogFollow::GetList( array( "USER_ID" => $arLog["USER_ID"], "CODE" => "L".$arFields["LOG_ID"] ), array("TYPE") ); $arLogFollow = $rsLogFollow->Fetch(); if (!$arLogFollow) CSocNetLogFollow::Set($arLog["USER_ID"], "L".$arFields["LOG_ID"], "Y"); } } if ($bSendEvent) { CSocNetLogComments::SendEvent($ID, "SONET_NEW_EVENT"); } CSocNetLogComments::UpdateLogData($arFields["LOG_ID"], $bSetLogUpDate); $db_events = GetModuleEvents("socialnetwork", "OnAfterSocNetLogCommentAdd"); while ($arEvent = $db_events->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID, $arFields)); } $GLOBALS["USER_FIELD_MANAGER"]->Update("SONET_COMMENT", $ID, $arFields); if(defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_".$arFields["LOG_ID"]); } else { $cache = new CPHPCache; $cache->CleanDir("/sonet/log/".$arFields["LOG_ID"]."/comments/"); } CSocNetLogComments::SendMentionNotification(array_merge($arFields, array("ID" => $ID))); } } CSocNetLogTools::SetCacheLastLogID("comment", $ID); return $ID; } elseif ($bSetSource && strlen($strMessage) > 0) return array( "ID" => false, "MESSAGE" => $strMessage ); else return false; }
} } 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(); foreach ($arMention[1] as $val) { $arMentionedDestCode[] = "U" . $val; } \Bitrix\Main\FinderDestTable::merge(array("CONTEXT" => "mention", "CODE" => array_unique($arMentionedDestCode))); } } $arFieldsIM["EXCLUDE_USERS"] = array(); $rsUnFollower = CSocNetLogFollow::GetList(array("CODE" => "L" . $log_id, "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arFieldsIM["EXCLUDE_USERS"][$arUnFollower["USER_ID"]] = $arUnFollower["USER_ID"]; } CBlogPost::NotifyIm($arFieldsIM); } $res = CBlogImage::GetList(array(), array("POST_ID" => $arPost["ID"], "BLOG_ID" => $arBlog["ID"], "IS_COMMENT" => "Y", "COMMENT_ID" => false, "<=TIMESTAMP_X" => ConvertTimeStamp(AddToTimeStamp(array("HH" => -3)), "FULL"))); while ($aImg = $res->Fetch()) { CBlogImage::Delete($aImg["ID"]); } if (strlen($arFields["PUBLISH_STATUS"]) > 0 && $arFields["PUBLISH_STATUS"] != BLOG_PUBLISH_STATUS_PUBLISH) { $arResult["MESSAGE"] = GetMessage("B_B_PC_MES_HIDDEN_ADDED"); } $arResult["ajax_comment"] = $commentId; $bHasImg = false; $bHasProps = false;
public static function NotifyIm($arParams) { if (!CModule::IncludeModule("im") || intval($arParams["PHOTO_AUTHOR_ID"]) <= 0 || $arParams["PHOTO_AUTHOR_ID"] == intval($arParams["COMMENT_AUTHOR_ID"])) { return; } if (!array_key_exists("SECTION_NAME", $arParams)) { $arParams["SECTION_NAME"] = ""; } if (!array_key_exists("SECTION_URL", $arParams)) { $arParams["SECTION_URL"] = 0; } $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arParams["PHOTO_AUTHOR_ID"], "FROM_USER_ID" => $arParams["COMMENT_AUTHOR_ID"], "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "photogallery", "NOTIFY_EVENT" => "comment"); $rsLog = CSocNetLog::GetList(array(), array("EVENT_ID" => array("photo_photo"), "SOURCE_ID" => $arParams["ID"]), false, false, array("ID")); if ($arLog = $rsLog->Fetch()) { $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arParams["PHOTO_AUTHOR_ID"], "CODE" => "L" . $arLog["ID"], "TYPE" => "N"), array("USER_ID")); if ($arUnFollower = $rsUnFollower->Fetch()) { return; } $arMessageFields["LOG_ID"] = $arLog["ID"]; } $arParams["TITLE"] = str_replace(array("\r\n", "\n"), " ", $arParams["TITLE"]); $arParams["TITLE"] = TruncateText($arParams["TITLE"], 100); $arParams["TITLE_OUT"] = TruncateText($arParams["TITLE"], 255); $arTmp = CSocNetLogTools::ProcessPath(array("PHOTO_URL" => $arParams["URL"], "SECTION_URL" => $arParams["SECTION_URL"]), $arParams["PHOTO_AUTHOR_ID"]); $serverName = $arTmp["SERVER_NAME"]; $arParams["URL"] = $arTmp["URLS"]["PHOTO_URL"]; $arParams["SECTION_URL"] = $arTmp["URLS"]["SECTION_URL"]; $arMessageFields["NOTIFY_TAG"] = "PHOTO|COMMENT|" . $arParams["ID"]; $arMessageFields["NOTIFY_MESSAGE"] = GetMessage("SONET_PHOTO_IM_COMMENT", array("#photo_title#" => "<a href=\"" . $arParams["URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["TITLE"]) . "</a>", "#album_title#" => "<a href=\"" . $arParams["SECTION_URL"] . "\" class=\"bx-notifier-item-action\">" . htmlspecialcharsbx($arParams["SECTION_NAME"]) . "</a>")); $arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("SONET_PHOTO_IM_COMMENT", array("#photo_title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]), "#album_title#" => htmlspecialcharsbx($arParams["SECTION_NAME"]))) . " (" . $serverName . $arParams["URL"] . ")#BR##BR#" . $arParams["MESSAGE"]; $ID = CIMNotify::Add($arMessageFields); if (!empty($arParams["COMMENT_MENTION_ID"])) { // } }
function Add($arFields, $bSetSource = false, $bSendEvent = true, $bSetLogUpDate = true) { global $DB; $arFields1 = array(); foreach ($arFields as $key => $value) { if (substr($key, 0, 1) == "=") { $arFields1[substr($key, 1)] = $value; unset($arFields[$key]); } } if (!CSocNetLogComments::CheckFields("ADD", $arFields)) { return false; } $arCommentEvent = CSocNetLogTools::FindLogCommentEventByID($arFields["EVENT_ID"]); if (!$arCommentEvent || !array_key_exists("ADD_CALLBACK", $arCommentEvent) || !is_callable($arCommentEvent["ADD_CALLBACK"])) { $bSetSource = false; } $db_events = GetModuleEvents("socialnetwork", "OnBeforeSocNetLogCommentAdd"); while ($arEvent = $db_events->Fetch()) { if (ExecuteModuleEventEx($arEvent, array(&$arFields)) === false) { return false; } } if ($bSetSource) { $arSource = CSocNetLogComments::SetSource($arFields); if (intval($arSource["SOURCE_ID"]) > 0) { $arFields["SOURCE_ID"] = $arSource["SOURCE_ID"]; if (array_key_exists("RATING_ENTITY_ID", $arSource) && array_key_exists("RATING_TYPE_ID", $arSource) && intval($arSource["RATING_ENTITY_ID"]) > 0 && strlen($arSource["RATING_TYPE_ID"]) > 0) { $arFields["RATING_TYPE_ID"] = $arSource["RATING_TYPE_ID"]; $arFields["RATING_ENTITY_ID"] = $arSource["RATING_ENTITY_ID"]; } if (isset($arSource["MESSAGE"]) && strlen($arSource["MESSAGE"]) > 0) { $arFields["MESSAGE"] = $arSource["MESSAGE"]; } if (isset($arSource["TEXT_MESSAGE"]) && strlen($arSource["TEXT_MESSAGE"]) > 0) { $arFields["TEXT_MESSAGE"] = $arSource["TEXT_MESSAGE"]; } } else { $strMessage = array_key_exists("ERROR", $arSource) && strlen($arSource["ERROR"]) > 0 ? $arSource["ERROR"] : (array_key_exists("NOTES", $arSource) && strlen($arSource["NOTES"]) > 0 ? $arSource["NOTES"] : ""); } } if (!$bSetSource || is_array($arSource) && array_key_exists("SOURCE_ID", $arFields) && intval($arFields["SOURCE_ID"]) > 0) { $arInsert = $DB->PrepareInsert("b_sonet_log_comment", $arFields); foreach ($arFields1 as $key => $value) { if (strlen($arInsert[0]) > 0) { $arInsert[0] .= ", "; } $arInsert[0] .= $key; if (strlen($arInsert[1]) > 0) { $arInsert[1] .= ", "; } $arInsert[1] .= $value; } $ID = false; if (strlen($arInsert[0]) > 0) { $strSql = "INSERT INTO b_sonet_log_comment(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")"; $DB->Query($strSql, False, "File: " . __FILE__ . "<br>Line: " . __LINE__); $ID = IntVal($DB->LastID()); if ($ID > 0) { if (!array_key_exists("RATING_TYPE_ID", $arFields) || empty($arFields["RATING_TYPE_ID"])) { CSocNetLogComments::Update($ID, array("RATING_TYPE_ID" => "LOG_COMMENT", "RATING_ENTITY_ID" => $ID)); } CSocNetLogFollow::Set($arFields["USER_ID"], "L" . $arFields["LOG_ID"], "Y"); $rsLog = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "USER_ID")); if (($arLog = $rsLog->Fetch()) && intval($arLog["USER_ID"]) > 0) { $default_follow = CSocNetLogFollow::GetDefaultValue($arLog["USER_ID"]); if ($default_follow != "Y") { $rsLogFollow = CSocNetLogFollow::GetList(array("USER_ID" => $arLog["USER_ID"], "CODE" => "L" . $arFields["LOG_ID"]), array("TYPE")); $arLogFoillow = $rsLogFollow->Fetch(); if (!$arLogFoillow) { CSocNetLogFollow::Set($arLog["USER_ID"], "L" . $arFields["LOG_ID"], "Y"); } } } if ($bSendEvent) { CSocNetLogComments::SendEvent($ID, "SONET_NEW_EVENT"); } CSocNetLogComments::UpdateLogData($arFields["LOG_ID"], $bSetLogUpDate); $db_events = GetModuleEvents("socialnetwork", "OnAfterSocNetLogCommentAdd"); while ($arEvent = $db_events->Fetch()) { ExecuteModuleEventEx($arEvent, array($ID, $arFields)); } if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->ClearByTag("SONET_LOG_" . $arFields["LOG_ID"]); } } } CSocNetLogTools::SetCacheLastLogID("comment", $ID); return $ID; } elseif ($bSetSource && strlen($strMessage) > 0) { return array("ID" => false, "MESSAGE" => $strMessage); } else { return false; } }
} } if ($GLOBALS["USER"]->IsAuthorized() && $arParams["SET_LOG_COUNTER"] == "Y" && (intval($arResult["LOG_COUNTER"]) > 0 || $bEmptyCounter)) { CUserCounter::ClearByUser($GLOBALS["USER"]->GetID(), array(SITE_ID, "**"), $arResult["COUNTER_TYPE"]); } if ($GLOBALS["USER"]->IsAuthorized() && $arParams["SET_LOG_PAGE_CACHE"] == "Y" && $dateLastPage && (!$dateLastPageStart || $dateLastPageStart != $dateLastPage || $bNeedSetLogPage)) { CSocNetLogPages::Set($GLOBALS["USER"]->GetID(), $dateLastPage, $arParams["PAGE_SIZE"], $arResult["PAGE_NUMBER"], SITE_ID, strlen($arResult["COUNTER_TYPE"]) > 0 ? $arResult["COUNTER_TYPE"] : "**"); } } else { $rsCurrentUser = CUser::GetByID($GLOBALS["USER"]->GetID()); if ($arCurrentUser = $rsCurrentUser->Fetch()) { $arResult["EmptyComment"] = array("AVATAR_SRC" => CSocNetLogTools::FormatEvent_CreateAvatar($arCurrentUser, $arParams, ""), "AUTHOR_NAME" => CUser::FormatName($arParams["NAME_TEMPLATE"], $arCurrentUser, $bUseLogin)); } } if ($GLOBALS["USER"]->IsAuthorized() && $arParams["USE_FOLLOW"] == "Y") { $rsFollow = CSocNetLogFollow::GetList(array("USER_ID" => $GLOBALS["USER"]->GetID(), "CODE" => "**"), array("TYPE")); if ($arFollow = $rsFollow->Fetch()) { $arResult["FOLLOW_DEFAULT"] = $arFollow["TYPE"]; } else { $arResult["FOLLOW_DEFAULT"] = COption::GetOptionString("socialnetwork", "follow_default_type", "Y"); } } $bAllowToAll = COption::GetOptionString("socialnetwork", "allow_livefeed_toall", "Y") == "Y"; if ($bAllowToAll) { $arToAllRights = unserialize(COption::GetOptionString("socialnetwork", "livefeed_toall_rights", 'a:1:{i:0;s:2:"AU";}')); if (!$arToAllRights) { $arToAllRights = array("AU"); } $arUserGroupCode = array_merge(array("AU"), CAccess::GetUserCodesArray($GLOBALS["USER"]->GetID())); if (count(array_intersect($arToAllRights, $arUserGroupCode)) <= 0) { $bAllowToAll = false;
function AddComment_Tasks($arFields) { global $DB; if (!CModule::IncludeModule("forum")) { return false; } if (!CModule::IncludeModule("tasks")) { return false; } $ufFileID = array(); $ufDocID = array(); $dbResult = CSocNetLog::GetList(array(), array("ID" => $arFields["LOG_ID"]), false, false, array("ID", "SOURCE_ID", "SITE_ID")); if ($arLog = $dbResult->Fetch()) { $rsTask = CTasks::GetById($arLog["SOURCE_ID"]); if ($arTask = $rsTask->Fetch()) { // read shared cross-site FORUM_ID $forumID = COption::GetOptionString("tasks", "task_forum_id", 0, $siteId = ''); if ($forumID) { if (!$arTask["FORUM_TOPIC_ID"]) { $arUserStart = array("ID" => intVal($arTask["CREATED_BY"]), "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"]); if ($arUserStart["ID"] > 0) { $res = array(); $db_res = CForumUser::GetListEx(array(), array("USER_ID" => $arTask["CREATED_BY"])); if ($db_res && ($res = $db_res->Fetch())) { $res["FORUM_USER_ID"] = intVal($res["ID"]); $res["ID"] = $res["USER_ID"]; } else { $db_res = CUser::GetByID($arTask["CREATED_BY"]); if ($db_res && ($res = $db_res->Fetch())) { $res["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y"); $res["USER_PROFILE"] = "N"; } } if (!empty($res)) { $arUserStart = $res; $sName = $res["SHOW_NAME"] == "Y" ? trim($res["NAME"] . " " . $res["LAST_NAME"]) : ""; $arUserStart["NAME"] = empty($sName) ? trim($res["LOGIN"]) : $sName; } } $arUserStart["NAME"] = empty($arUserStart["NAME"]) ? $GLOBALS["FORUM_STATUS_NAME"]["guest"] : $arUserStart["NAME"]; $DB->StartTransaction(); $arTopicFields = array("TITLE" => $arTask["TITLE"], "FORUM_ID" => $forumID, "USER_START_ID" => $arUserStart["ID"], "USER_START_NAME" => $arUserStart["NAME"], "LAST_POSTER_NAME" => $arUserStart["NAME"], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E', "APPROVED" => "Y", 'XML_ID' => 'TASK_' . $arTask['ID']); $TID = CForumTopic::Add($arTopicFields); if (intVal($TID) > 0) { $arFieldsFirstMessage = array("POST_MESSAGE" => $arTopicFields['XML_ID'], "AUTHOR_ID" => $arTopicFields["USER_START_ID"], "AUTHOR_NAME" => $arTopicFields["USER_START_NAME"], "FORUM_ID" => $arTopicFields["FORUM_ID"], "TOPIC_ID" => $TID, "APPROVED" => "Y", "NEW_TOPIC" => "Y", "PARAM1" => 'TK', "PARAM2" => $arTask['ID'], "PERMISSION_EXTERNAL" => 'E', "PERMISSION" => 'E'); CForumMessage::Add($arFieldsFirstMessage, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N")); $arTask["FORUM_TOPIC_ID"] = $TID; $arTaskFields = array("FORUM_TOPIC_ID" => $TID); $task = new CTasks(); $task->Update($arTask["ID"], $arTaskFields); } if (!$arTask["FORUM_TOPIC_ID"]) { $DB->Rollback(); } else { $DB->Commit(); } } else { // override forumId by fact forum, attached to the task if ($arTopic = CForumTopic::getByID($arTask['FORUM_TOPIC_ID'])) { $forumID = $arTopic['FORUM_ID']; } } if ($forumID && $arTask["FORUM_TOPIC_ID"]) { $userID = $GLOBALS["USER"]->GetID(); $arLogSites = array(); $rsLogSite = CSocNetLog::GetSite($arLog["ID"]); while ($arLogSite = $rsLogSite->Fetch()) { $arLogSites[] = $arLogSite["LID"]; } $bCurrentUserIsAdmin = CSocNetUser::IsCurrentUserModuleAdmin($arLogSites); if ($arFields["ENTITY_TYPE"] == SONET_ENTITY_GROUP) { if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_GROUP, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) { $strPermission = "I"; } } else { if (CSocNetFeaturesPerms::CanPerformOperation($userID, SONET_ENTITY_USER, $arFields["ENTITY_ID"], "tasks", "view", $bCurrentUserIsAdmin)) { $strPermission = "I"; } } $arFieldsMessage = array("POST_MESSAGE" => $arFields["TEXT_MESSAGE"], "USE_SMILES" => "Y", "PERMISSION_EXTERNAL" => "Q", "PERMISSION" => $strPermission, "APPROVED" => "Y"); $MESSAGE_TYPE = 'REPLY'; $GLOBALS["USER_FIELD_MANAGER"]->EditFormAddFields("SONET_COMMENT", $arTmp); if (is_array($arTmp)) { if (array_key_exists("UF_SONET_COM_DOC", $arTmp)) { $GLOBALS["UF_FORUM_MESSAGE_DOC"] = $arTmp["UF_SONET_COM_DOC"]; } elseif (array_key_exists("UF_SONET_COM_FILE", $arTmp)) { $arFieldsMessage["FILES"] = array(); foreach ($arTmp["UF_SONET_COM_FILE"] as $file_id) { $arFieldsMessage["FILES"][] = array("FILE_ID" => $file_id); } } } $messageID = ForumAddMessage($MESSAGE_TYPE, $forumID, $arTask["FORUM_TOPIC_ID"], 0, $arFieldsMessage, $sError, $sNote); // get UF DOC value and FILE_ID there if ($messageID > 0) { $dbAddedMessageFiles = CForumFiles::GetList(array("ID" => "ASC"), array("MESSAGE_ID" => $messageID)); while ($arAddedMessageFiles = $dbAddedMessageFiles->Fetch()) { $ufFileID[] = $arAddedMessageFiles["FILE_ID"]; } $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MESSAGE_DOC", $messageID, LANGUAGE_ID); } if ($messageID && ($arMessage = CForumMessage::GetByID($messageID))) { $arLogFields = array("TASK_ID" => $arTask["ID"], "USER_ID" => $userID, "CREATED_DATE" => $arMessage["POST_DATE"], "FIELD" => "COMMENT", "TO_VALUE" => $messageID); $log = new CTaskLog(); $log->Add($arLogFields); // notification to IM $arRecipientsIDs = CTaskNotifications::GetRecipientsIDs($arTask); $arUnFollowers = array(); $rsUnFollower = CSocNetLogFollow::GetList(array("USER_ID" => $arRecipientsIDs, "CODE" => "L" . $arFields["LOG_ID"], "TYPE" => "N"), array("USER_ID")); while ($arUnFollower = $rsUnFollower->Fetch()) { $arUnFollowers[] = $arUnFollower["USER_ID"]; } $arRecipientsIDs = array_diff($arRecipientsIDs, $arUnFollowers); if (IsModuleInstalled("im") && CModule::IncludeModule("im") && sizeof($arRecipientsIDs)) { $extranetSiteId = false; if (CModule::IncludeModule('extranet') && method_exists('CExtranet', 'GetExtranetSiteID')) { $extranetSiteId = CExtranet::GetExtranetSiteID(); } foreach ($arRecipientsIDs as $recipientUserID) { $arFilter = array("UF_DEPARTMENT" => false, "ID" => $recipientUserID); $rsUser = CUser::GetList($by = "last_name", $order = "asc", $arFilter, array("SELECT" => array("UF_DEPARTMENT"))); $isExtranetUser = false; if ($arUser = $rsUser->Fetch()) { $isExtranetUser = true; } if ($isExtranetUser && $extranetSiteId !== false) { if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/extranet/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $extranetSiteId)); $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate); } else { $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/extranet/contacts/personal/user/#user_id#/tasks/task/view/#task_id#/", $extranetSiteId); } } else { if ($arTask["GROUP_ID"]) { $pathTemplate = str_replace("#group_id#", $arTask["GROUP_ID"], COption::GetOptionString("tasks", "paths_task_group_entry", "/workgroups/group/#group_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"])); $pathTemplate = str_replace("#GROUP_ID#", $arTask["GROUP_ID"], $pathTemplate); } else { $pathTemplate = COption::GetOptionString("tasks", "paths_task_user_entry", "/company/personal/user/#user_id#/tasks/task/view/#task_id#/", $arLog["SITE_ID"]); } } $messageUrl = CComponentEngine::MakePathFromTemplate($pathTemplate, array("user_id" => $recipientUserID, "task_id" => $arTask["ID"], "action" => "view")); if (strpos($messageUrl, "?") === false) { $messageUrl .= "?"; } else { $messageUrl .= "&"; } $messageUrl .= "MID=" . $messageID; $MESSAGE_SITE = preg_replace(array('|\\[\\/USER\\]|', '|\\[USER=\\d+\\]|', '|\\[DISK\\sFILE\\sID=[n]*\\d+\\]|', '|\\[DOCUMENT\\sID=\\d+\\]|'), '', $arFields['TEXT_MESSAGE']); if (strlen($MESSAGE_SITE) >= 100) { $dot = '...'; $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 99); if (substr($MESSAGE_SITE, -1) === '[') { $MESSAGE_SITE = substr($MESSAGE_SITE, 0, 98); } if (($lastLinkPosition = strrpos($MESSAGE_SITE, '[u')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'http://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'https://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftp://')) !== false || ($lastLinkPosition = strrpos($MESSAGE_SITE, 'ftps://')) !== false) { if (strpos($MESSAGE_SITE, ' ', $lastLinkPosition) === false) { $MESSAGE_SITE = substr($MESSAGE_SITE, 0, $lastLinkPosition); } } $MESSAGE_SITE .= $dot; } $rsUser = CUser::GetList($by = 'id', $order = 'asc', array('ID_EQUAL_EXACT' => (int) $userID), array('FIELDS' => array('PERSONAL_GENDER'))); $strMsgAddComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD"); $strMsgEditComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT"); if ($arUser = $rsUser->fetch()) { switch ($arUser['PERSONAL_GENDER']) { case "F": case "M": $strMsgAddComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_ADD" . '_' . $arUser['PERSONAL_GENDER']); $strMsgEditComment = GetMessage("SONET_GL_EVENT_TITLE_TASK_COMMENT_MESSAGE_EDIT" . '_' . $arUser['PERSONAL_GENDER']); break; default: break; } } $arMessageFields = array("TO_USER_ID" => $recipientUserID, "FROM_USER_ID" => $userID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "tasks", "NOTIFY_EVENT" => "comment", "NOTIFY_MESSAGE" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array('[URL=' . tasksServerName() . $messageUrl . "#message" . $messageID . ']' . htmlspecialcharsbx($arTask["TITLE"]) . '[/URL]', '[COLOR=#000000]' . $MESSAGE_SITE . '[/COLOR]'), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment), "NOTIFY_MESSAGE_OUT" => str_replace(array("#TASK_TITLE#", "#TASK_COMMENT_TEXT#"), array(htmlspecialcharsbx($arTask["TITLE"]), $MESSAGE_SITE . ' #BR# ' . tasksServerName() . $messageUrl . "#message" . $messageID . ' '), $MESSAGE_TYPE != "EDIT" ? $strMsgAddComment : $strMsgEditComment) . "#BR##BR#" . $arFields["TEXT_MESSAGE"], "NOTIFY_TAG" => "TASKS|COMMENT|" . intval($arTask["ID"]) . "|" . intval($recipientUserID)); CIMNotify::Add($arMessageFields); } } CSocNetLog::Update($arFields["LOG_ID"], array('PARAMS' => serialize(array('TYPE' => 'comment')))); $arFilesIds = array_merge($ufFileID, is_array($ufDocID) ? $ufDocID : array()); CTaskComments::fireOnAfterCommentAddEvent($messageID, $arTask['ID'], $arFields["TEXT_MESSAGE"], $arFilesIds); } } } } } if (!$messageID) { $sError = GetMessage("SONET_ADD_COMMENT_SOURCE_ERROR"); } return array("SOURCE_ID" => $messageID, "MESSAGE" => $arFieldsMessage ? $arFieldsMessage["POST_MESSAGE"] : false, "RATING_TYPE_ID" => "FORUM_POST", "RATING_ENTITY_ID" => $messageID, "ERROR" => $sError, "NOTES" => $sNote, "UF" => array("FILE" => $ufFileID, "DOC" => $ufDocID), "URL" => $messageUrl); }
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"); } } }