예제 #1
0
     $socnetPerms[] = "SA";
     // socnet admin
     if (in_array("AU", $socnetPerms) || in_array("G2", $socnetPerms)) {
         $socnetPermsAdd = array();
         foreach ($socnetPerms as $perm_tmp) {
             if (preg_match('/^SG(\\d+)$/', $perm_tmp, $matches)) {
                 if (!in_array("SG" . $matches[1] . "_" . SONET_ROLES_USER, $socnetPerms) && !in_array("SG" . $matches[1] . "_" . SONET_ROLES_MODERATOR, $socnetPerms) && !in_array("SG" . $matches[1] . "_" . SONET_ROLES_OWNER, $socnetPerms)) {
                     $socnetPermsAdd[] = "SG" . $matches[1] . "_" . SONET_ROLES_USER;
                 }
             }
         }
         if (count($socnetPermsAdd) > 0) {
             $socnetPerms = array_merge($socnetPerms, $socnetPermsAdd);
         }
     }
     CSocNetLogRights::DeleteByLogID($arRes["ID"]);
     CSocNetLogRights::Add($arRes["ID"], $socnetPerms, true);
     if (count(array_diff($arLogSitesNew, $arLogSites)) > 0) {
         CSocNetLog::Update($arRes["ID"], array("ENTITY_TYPE" => $arRes["ENTITY_TYPE"], "SITE_ID" => $arLogSitesNew, "=LOG_UPDATE" => $DB->CurrentTimeFunction()));
     } else {
         CSocNetLog::Update($arRes["ID"], array("=LOG_UPDATE" => $DB->CurrentTimeFunction()));
     }
     /* subscribe share author */
     CSocNetLogFollow::Set($user_id, "L" . $arRes["ID"], "Y", ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL"));
 }
 /* update socnet groupd activity*/
 foreach ($arNewRights as $v) {
     if (substr($v, 0, 2) == "SG") {
         $group_id_tmp = substr($v, 2);
         if (IntVal($group_id_tmp) > 0) {
             CSocNetGroup::SetLastActivity(IntVal($group_id_tmp));
예제 #2
0
 function UpdateLog($postID, $arPost, $arBlog, $arParams)
 {
     if (!CModule::IncludeModule('socialnetwork')) {
         return;
     }
     global $DB;
     $parserBlog = new blogTextParser(false, $arParams["PATH_TO_SMILE"]);
     preg_match("#^(.*?)<cut[\\s]*(/>|>).*?\$#is", $arPost["DETAIL_TEXT"], $arMatches);
     if (count($arMatches) <= 0) {
         preg_match("#^(.*?)\\[cut[\\s]*(/\\]|\\]).*?\$#is", $arPost["DETAIL_TEXT"], $arMatches);
     }
     if (count($arMatches) > 0) {
         $cut_suffix = "#CUT#";
     } else {
         $cut_suffix = "";
     }
     $arImages = array();
     $res = CBlogImage::GetList(array("ID" => "ASC"), array("POST_ID" => $postID, "BLOG_ID" => $arBlog["ID"], "IS_COMMENT" => "N"));
     while ($arImage = $res->Fetch()) {
         $arImages[$arImage['ID']] = $arImage['FILE_ID'];
     }
     if ($arPost["DETAIL_TEXT_TYPE"] == "html" && $arParams["allowHTML"] == "Y" && $arBlog["ALLOW_HTML"] == "Y") {
         $arAllow = array("HTML" => "Y", "ANCHOR" => "Y", "IMG" => "Y", "SMILES" => "N", "NL2BR" => "N", "VIDEO" => "Y", "QUOTE" => "Y", "CODE" => "Y");
         if ($arParams["allowVideo"] != "Y") {
             $arAllow["VIDEO"] = "N";
         }
         $text4message = $parserBlog->convert($arPost["DETAIL_TEXT"], true, $arImages, $arAllow);
     } else {
         $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($arPost["DETAIL_TEXT"], true, $arImages, $arAllow, array("isSonetLog" => true));
     }
     $text4message .= $cut_suffix;
     $arSoFields = array("TITLE_TEMPLATE" => "#USER_NAME# " . GetMessage("BLG_SONET_TITLE"), "TITLE" => $arPost["TITLE"], "MESSAGE" => $text4message, "TEXT_MESSAGE" => $text4mail, "ENABLE_COMMENTS" => array_key_exists("ENABLE_COMMENTS", $arPost) && $arPost["ENABLE_COMMENTS"] == "N" ? "N" : "Y", "=LOG_UPDATE" => strlen($arPost["DATE_PUBLISH"]) > 0 ? MakeTimeStamp($arPost["DATE_PUBLISH"], CSite::GetDateFormat("FULL", $SITE_ID)) > time() + CTimeZone::GetOffset() ? $DB->CharToDateFunction($arPost["DATE_PUBLISH"], "FULL", SITE_ID) : $DB->CurrentTimeFunction() : $DB->CurrentTimeFunction());
     $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "blog_post", "SOURCE_ID" => $postID), false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
     if ($arRes = $dbRes->Fetch()) {
         CSocNetLog::Update($arRes["ID"], $arSoFields);
         $socnetPerms = CBlogPost::GetSocNetPermsCode($postID);
         if (!in_array("U" . $arPost["AUTHOR_ID"], $socnetPerms)) {
             $socnetPerms[] = "U" . $arPost["AUTHOR_ID"];
         }
         if (CModule::IncludeModule("extranet")) {
             $arSiteID = CExtranet::GetSitesByLogDestinations($socnetPerms);
             CSocNetLog::Update($arRes["ID"], array("SITE_ID" => $arSiteID));
         }
         $socnetPerms[] = "SA";
         // socnet admin
         CSocNetLogRights::DeleteByLogID($arRes["ID"]);
         CSocNetLogRights::Add($arRes["ID"], $socnetPerms);
     }
 }
예제 #3
0
 private static function RegisterLiveFeedEvent(&$arFields)
 {
     $ID = isset($arFields['ID']) ? intval($arFields['ID']) : 0;
     if ($ID <= 0) {
         $arFields['ERROR'] = 'Could not find activity ID.';
         return false;
     }
     $ownerTypeID = isset($arFields['OWNER_TYPE_ID']) ? intval($arFields['OWNER_TYPE_ID']) : CCrmOwnerType::Undefined;
     if (!CCrmOwnerType::IsDefined($ownerTypeID)) {
         $arFields['ERROR'] = 'Could not find owner type ID.';
         return false;
     }
     $ownerID = isset($arFields['OWNER_ID']) ? intval($arFields['OWNER_ID']) : 0;
     if ($ownerID <= 0) {
         $arFields['ERROR'] = 'Could not find owner ID.';
         return false;
     }
     $arOwners = array(array("OWNER_TYPE_ID" => $ownerTypeID, "OWNER_ID" => $ownerID));
     $authorID = isset($arFields['AUTHOR_ID']) ? intval($arFields['AUTHOR_ID']) : 0;
     $editorID = isset($arFields['EDITOR_ID']) ? intval($arFields['EDITOR_ID']) : 0;
     $userID = $authorID > 0 ? $authorID : $editorID;
     if ($userID <= 0) {
         $userID = CCrmSecurityHelper::GetCurrentUserID();
     }
     // Params are not assigned - we will use current activity only.
     $liveFeedFields = array('ENTITY_TYPE_ID' => CCrmOwnerType::Activity, 'ENTITY_ID' => $ID, 'USER_ID' => $userID, 'MESSAGE' => '', 'TITLE' => '');
     $bindings = isset($arFields['BINDINGS']) && is_array($arFields['BINDINGS']) ? $arFields['BINDINGS'] : array();
     if (!empty($bindings)) {
         $liveFeedFields['PARENTS'] = $bindings;
         $liveFeedFields['PARENT_OPTIONS'] = array('ENTITY_TYPE_ID_KEY' => 'OWNER_TYPE_ID', 'ENTITY_ID_KEY' => 'OWNER_ID');
         $ownerInfoOptions = array('ENTITY_TYPE_ID_KEY' => 'OWNER_TYPE_ID', 'ENTITY_ID_KEY' => 'OWNER_ID', 'ADDITIONAL_DATA' => array('LEVEL' => 2));
         $additionalParents = array();
         foreach ($bindings as &$binding) {
             $ownerTypeID = isset($binding['OWNER_TYPE_ID']) ? intval($binding['OWNER_TYPE_ID']) : CCrmOwnerType::Undefined;
             $ownerID = isset($binding['OWNER_ID']) ? intval($binding['OWNER_ID']) : 0;
             if ($ownerTypeID != CCrmOwnerType::Undefined && $ownerID > 0) {
                 $arOwners[] = array("OWNER_TYPE_ID" => $ownerTypeID, "OWNER_ID" => $ownerID);
             }
             if ($ownerTypeID === CCrmOwnerType::Contact && $ownerID > 0) {
                 $owners = array();
                 if (CCrmOwnerType::TryGetOwnerInfos(CCrmOwnerType::Contact, $ownerID, $owners, $ownerInfoOptions)) {
                     $additionalParents = array_merge($additionalParents, $owners);
                 }
             }
         }
         unset($binding);
         if (!empty($additionalParents)) {
             $liveFeedFields['PARENTS'] = array_merge($bindings, $additionalParents);
         }
         $arOwners = array_unique($arOwners);
     }
     self::PrepareStorageElementIDs($arFields);
     $arStorageElementID = $arFields["STORAGE_ELEMENT_IDS"];
     if (!empty($arStorageElementID)) {
         if ($arFields["STORAGE_TYPE_ID"] == StorageType::WebDav) {
             $liveFeedFields["UF_SONET_LOG_DOC"] = $arStorageElementID;
         } else {
             if ($arFields["STORAGE_TYPE_ID"] == StorageType::Disk) {
                 $liveFeedFields["UF_SONET_LOG_DOC"] = array();
                 //We have to add prefix Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX to file ID
                 foreach ($arStorageElementID as $elementID) {
                     $liveFeedFields["UF_SONET_LOG_DOC"][] = "n{$elementID}";
                 }
             } else {
                 $liveFeedFields["UF_SONET_LOG_FILE"] = $arStorageElementID;
             }
         }
     }
     if ($arFields['TYPE_ID'] == CCrmActivityType::Task && isset($arFields["ASSOCIATED_ENTITY_ID"]) && intval($arFields["ASSOCIATED_ENTITY_ID"]) > 0 && CModule::IncludeModule("tasks")) {
         $dbTask = CTasks::GetByID($arFields["ASSOCIATED_ENTITY_ID"], false);
         if ($arTask = $dbTask->Fetch()) {
             $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("TASKS_TASK", "UF_TASK_WEBDAV_FILES", $arTask["ID"], LANGUAGE_ID);
             if ($ufDocID) {
                 $liveFeedFields["UF_SONET_LOG_DOC"] = $ufDocID;
             }
         }
     }
     $bConvert = false;
     if ($arTask) {
         $rsLog = CSocNetLog::GetList(array(), array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]), array("ID"));
         if ($arLog = $rsLog->Fetch()) {
             $eventID = CCrmLiveFeed::ConvertTasksLogEvent(array("LOG_ID" => $arLog["ID"], "ACTIVITY_ID" => $ID));
             $bConvert = true;
         }
     }
     if (!$bConvert) {
         $eventID = CCrmLiveFeed::CreateLogEvent($liveFeedFields, CCrmLiveFeedEvent::Add);
     }
     if (!(is_int($eventID) && $eventID > 0) && isset($liveFeedFields['ERROR'])) {
         $arFields['ERROR'] = $liveFeedFields['ERROR'];
     } else {
         if ($arTask) {
             $arTaskParticipant = CTaskNotifications::GetRecipientsIDs($arTask, false);
             $arSocnetRights = CTaskNotifications::__UserIDs2Rights($arTaskParticipant);
             if (isset($arTask['GROUP_ID']) && intval($arTask['GROUP_ID']) > 0) {
                 $perm = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_GROUP, $arTask['GROUP_ID'], "tasks", "view");
                 $arSocnetRights = array_merge($arSocnetRights, array('SG' . $arTask['GROUP_ID'], 'SG' . $arTask['GROUP_ID'] . '_' . $perm));
             }
             CSocNetLogRights::DeleteByLogID($eventID);
             CSocNetLogRights::Add($eventID, $arSocnetRights);
         }
         if (intval($arFields["RESPONSIBLE_ID"]) > 0 && $arFields["RESPONSIBLE_ID"] != $userID && CModule::IncludeModule("im")) {
             $bHasPermissions = false;
             $perms = CCrmPerms::GetUserPermissions($arFields["RESPONSIBLE_ID"]);
             foreach ($arOwners as $arOwner) {
                 if (CCrmActivity::CheckReadPermission($arOwner["OWNER_TYPE_ID"], $arOwner["OWNER_ID"], $perms)) {
                     $bHasPermissions = true;
                     break;
                 }
             }
             switch ($arFields['TYPE_ID']) {
                 case CCrmActivityType::Call:
                     $type = 'CALL';
                     break;
                 case CCrmActivityType::Meeting:
                     $type = 'MEETING';
                     break;
                 default:
                     $type = false;
             }
             if ($bHasPermissions && $type) {
                 $url = "/crm/stream/?log_id=#log_id#";
                 $url = str_replace(array("#log_id#"), array($eventID), $url);
                 $serverName = (CMain::IsHTTPS() ? "https" : "http") . "://" . (defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0 ? SITE_SERVER_NAME : COption::GetOptionString("main", "server_name", ""));
                 $arMessageFields = array("MESSAGE_TYPE" => IM_MESSAGE_SYSTEM, "TO_USER_ID" => $arFields["RESPONSIBLE_ID"], "FROM_USER_ID" => $userID, "NOTIFY_TYPE" => IM_NOTIFY_FROM, "NOTIFY_MODULE" => "crm", "LOG_ID" => $eventID, "NOTIFY_EVENT" => "activity_add", "NOTIFY_TAG" => "CRM|ACTIVITY|" . $ID, "NOTIFY_MESSAGE" => GetMessage("CRM_ACTIVITY_" . $type . "_RESPONSIBLE_IM_NOTIFY", array("#title#" => '<a href="' . $url . '">' . htmlspecialcharsbx($arFields['SUBJECT']) . '</a>')), "NOTIFY_MESSAGE_OUT" => GetMessage("CRM_ACTIVITY_" . $type . "_RESPONSIBLE_IM_NOTIFY", array("#title#" => htmlspecialcharsbx($arFields['SUBJECT']))) . " (" . $serverName . $url . ")");
                 CIMNotify::Add($arMessageFields);
             }
         }
     }
     return $eventID;
 }
예제 #4
0
 public static function OnAfterUserUpdate($arFields)
 {
     if (array_key_exists("UF_DEPARTMENT", $arFields)) {
         $arDept = $arFields["UF_DEPARTMENT"];
         if (!is_array($arDept)) {
             $arDept = array($arDept);
         }
         foreach ($arDept as $key => $val) {
             if (intval($val) <= 0) {
                 unset($arDept[$key]);
             }
         }
         if (!empty($arDept) && CModule::IncludeModule("socialnetwork")) {
             $arNewRights = CReportNotifications::GetRights($arFields["ID"]);
             $rsLog = CSocNetLog::GetList(array(), array('ENTITY_TYPE' => SONET_WORK_REPORT_ENTITY, 'ENTITY_ID' => $arFields["ID"], 'EVENT_ID' => "report"), false, false, array("ID"));
             while ($arLog = $rsLog->Fetch()) {
                 $arOldRights = array();
                 $rsLogRight = CSocNetLogRights::GetList(array(), array("LOG_ID" => $arLog["ID"]));
                 while ($arLogRight = $rsLogRight->Fetch()) {
                     $arOldRights[] = $arLogRight["GROUP_CODE"];
                 }
                 $diff1 = array_diff($arNewRights, $arOldRights);
                 $diff2 = array_diff($arOldRights, $arNewRights);
                 if (!empty($diff1) || !empty($diff2)) {
                     CSocNetLogRights::DeleteByLogID($arLog["ID"]);
                     CSocNetLogRights::Add($arLog["ID"], $arNewRights);
                 }
             }
         }
     }
 }
예제 #5
0
 public static function CreateLogMessage(&$fields, $options = array())
 {
     if (!CModule::IncludeModule('socialnetwork')) {
         return false;
     }
     global $APPLICATION, $DB;
     if (!is_array($options)) {
         $options = array();
     }
     $entityTypeID = isset($fields['ENTITY_TYPE_ID']) ? intval($fields['ENTITY_TYPE_ID']) : CCrmOwnerType::Undefined;
     if (!CCrmOwnerType::IsDefined($entityTypeID)) {
         $fields['ERROR'] = GetMessage('CRM_LF_MSG_ENTITY_TYPE_NOT_FOUND');
         return false;
     }
     $entityType = CCrmOwnerType::ResolveName($entityTypeID);
     $entityID = isset($fields['ENTITY_ID']) ? intval($fields['ENTITY_ID']) : 0;
     if ($entityID < 0) {
         $fields['ERROR'] = GetMessage('CRM_LF_MSG_ENTITY_TYPE_NOT_FOUND');
         return false;
     }
     $message = isset($fields['MESSAGE']) && is_string($fields['MESSAGE']) ? $fields['MESSAGE'] : '';
     if ($message === '') {
         $fields['ERROR'] = GetMessage('CRM_LF_MSG_EMPTY');
         return false;
     }
     $title = isset($fields['TITLE']) && is_string($fields['TITLE']) ? $fields['TITLE'] : '';
     if ($title === '') {
         $title = self::UntitledMessageStub;
     }
     $userID = isset($fields['USER_ID']) ? intval($fields['USER_ID']) : 0;
     if ($userID <= 0) {
         $userID = CCrmSecurityHelper::GetCurrentUserID();
     }
     $bbCodeParser = new CTextParser();
     $bbCodeParser->allow["HTML"] = "Y";
     $eventText = $bbCodeParser->convert4mail($message);
     $CCrmEvent = new CCrmEvent();
     $eventID = $CCrmEvent->Add(array('ENTITY_TYPE' => $entityType, 'ENTITY_ID' => $entityID, 'EVENT_ID' => 'INFO', 'EVENT_TYPE' => 0, 'EVENT_TEXT_1' => $eventText, 'DATE_CREATE' => ConvertTimeStamp(time() + CTimeZone::GetOffset(), 'FULL', SITE_ID), 'FILES' => array()));
     if (is_string($eventID)) {
         //MS SQL RETURNS STRING INSTEAD INT
         $eventID = intval($eventID);
     }
     if (!(is_int($eventID) && $eventID > 0)) {
         $fields['ERROR'] = 'Could not create event';
         return false;
     }
     $liveFeedEntityType = CCrmLiveFeedEntity::GetByEntityTypeID($entityTypeID);
     $eventID = CCrmLiveFeedEvent::GetEventID($liveFeedEntityType, CCrmLiveFeedEvent::Message);
     $eventFields = array('EVENT_ID' => $eventID, '=LOG_DATE' => $DB->CurrentTimeFunction(), 'TITLE' => $title, 'MESSAGE' => $message, 'TEXT_MESSAGE' => '', 'MODULE_ID' => 'crm_shared', 'CALLBACK_FUNC' => false, 'ENABLE_COMMENTS' => 'Y', 'PARAMS' => '', 'USER_ID' => $userID, 'ENTITY_TYPE' => $liveFeedEntityType, 'ENTITY_ID' => $entityID, 'SOURCE_ID' => $eventID, 'URL' => CCrmUrlUtil::AddUrlParams(CCrmOwnerType::GetShowUrl($entityTypeID, $entityID), array()));
     if (isset($fields['WEB_DAV_FILES']) && is_array($fields['WEB_DAV_FILES'])) {
         $eventFields = array_merge($eventFields, $fields['WEB_DAV_FILES']);
     }
     $sendMessage = isset($options['SEND_MESSAGE']) && is_bool($options['SEND_MESSAGE']) ? $options['SEND_MESSAGE'] : false;
     $logEventID = CSocNetLog::Add($eventFields, $sendMessage);
     if (is_int($logEventID) && $logEventID > 0) {
         $arSocnetRights = $fields["RIGHTS"];
         if (!empty($arSocnetRights)) {
             $socnetPermsAdd = array();
             foreach ($arSocnetRights as $perm_tmp) {
                 if (preg_match('/^SG(\\d+)$/', $perm_tmp, $matches)) {
                     if (!in_array("SG" . $matches[1] . "_" . SONET_ROLES_USER, $arSocnetRights)) {
                         $socnetPermsAdd[] = "SG" . $matches[1] . "_" . SONET_ROLES_USER;
                     }
                     if (!in_array("SG" . $matches[1] . "_" . SONET_ROLES_MODERATOR, $arSocnetRights)) {
                         $socnetPermsAdd[] = "SG" . $matches[1] . "_" . SONET_ROLES_MODERATOR;
                     }
                     if (!in_array("SG" . $matches[1] . "_" . SONET_ROLES_OWNER, $arSocnetRights)) {
                         $socnetPermsAdd[] = "SG" . $matches[1] . "_" . SONET_ROLES_OWNER;
                     }
                 }
             }
             if (count($socnetPermsAdd) > 0) {
                 $arSocnetRights = array_merge($arSocnetRights, $socnetPermsAdd);
             }
             CSocNetLogRights::DeleteByLogID($logEventID);
             CSocNetLogRights::Add($logEventID, $arSocnetRights);
             if (array_key_exists("UF_SONET_LOG_DOC", $eventFields) && is_array($eventFields["UF_SONET_LOG_DOC"]) && count($eventFields["UF_SONET_LOG_DOC"]) > 0) {
                 if (!in_array("U" . $userID, $arSocnetRights)) {
                     $arSocnetRights[] = "U" . $userID;
                 }
                 CSocNetLogTools::SetUFRights($eventFields["UF_SONET_LOG_DOC"], $arSocnetRights);
             }
         }
         $arUpdateFields = array("RATING_TYPE_ID" => "LOG_ENTRY", "RATING_ENTITY_ID" => $logEventID);
         CSocNetLog::Update($logEventID, $arUpdateFields);
         self::RegisterOwnershipRelations($logEventID, $eventID, $fields);
         $eventFields["LOG_ID"] = $logEventID;
         CCrmLiveFeed::CounterIncrement($eventFields);
         return $logEventID;
     }
     $ex = $APPLICATION->GetException();
     $fields['ERROR'] = $ex->GetString();
     return false;
 }
예제 #6
0
 function OnSearchReindex($NS = array(), $oCallback = NULL, $callback_method = "")
 {
     global $DB;
     $arResult = array();
     //CBlogSearch::Trace('OnSearchReindex', 'NS', $NS);
     if ($NS["MODULE"] == "blog" && strlen($NS["ID"]) > 0) {
         $category = substr($NS["ID"], 0, 1);
         $id = intval(substr($NS["ID"], 1));
     } else {
         $category = 'B';
         //start with blogs
         $id = 0;
         //very first id
     }
     //CBlogSearch::Trace('OnSearchReindex', 'category+id', array("CATEGORY"=>$category,"ID"=>$id));
     //Reindex blogs
     if ($category == 'B') {
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tb.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t,b.REAL_URL\n\t\t\t\t\t,b.URL\n\t\t\t\t\t," . $DB->DateToCharFunction("b.DATE_UPDATE") . " as DATE_UPDATE\n\t\t\t\t\t,b.NAME\n\t\t\t\t\t,b.DESCRIPTION\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,b.SOCNET_GROUP_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\tFROM\n\t\t\t\t\tb_blog b\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)\n\t\t\t\tWHERE\n\t\t\t\t\tb.ACTIVE = 'Y'\n\t\t\t\t\tAND b.SEARCH_INDEX = 'Y'\n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? "AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND b.ID > " . $id . "\n\t\t\t\tORDER BY\n\t\t\t\t\tb.ID\n\t\t\t";
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             if ($ar["USE_SOCNET"] == "Y") {
                 $Result = array("ID" => "B" . $ar["ID"], "BODY" => "", "TITLE" => "");
             } else {
                 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
                 $arSite = array($ar["SITE_ID"] => CBlog::PreparePath($ar["URL"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]));
                 //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
                 $Result = array("ID" => "B" . $ar["ID"], "LAST_MODIFIED" => $ar["DATE_UPDATE"], "TITLE" => $ar["NAME"], "BODY" => blogTextParser::killAllTags($ar["DESCRIPTION"]), "SITE_ID" => $arSite, "PARAM1" => "BLOG", "PARAM2" => $ar["OWNER_ID"], "PERMISSIONS" => array(2));
                 //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
             }
             if ($oCallback) {
                 $res = call_user_func(array($oCallback, $callback_method), $Result);
                 if (!$res) {
                     return $Result["ID"];
                 }
             } else {
                 $arResult[] = $Result;
             }
         }
         //all blogs indexed so let's start index posts
         $category = 'P';
         $id = 0;
     }
     if ($category == 'P') {
         $arUser2Blog = array();
         if (COption::GetOptionString("blog", "socNetNewPerms", "N") == "N") {
             $dbB = CBlog::GetList(array(), array("USE_SOCNET" => "Y", "!OWNER_ID" => false), false, false, array("ID", "OWNER_ID", "USE_SOCNET", "GROUP_ID"));
             while ($arB = $dbB->Fetch()) {
                 $arUser2Blog[$arB["OWNER_ID"]][$arB["GROUP_ID"]] = $arB["ID"];
             }
         }
         $bSonet = false;
         if (IsModuleInstalled("socialnetwork")) {
             $bSonet = true;
         }
         $parserBlog = new blogTextParser(false, "/bitrix/images/blog/smile/");
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tbp.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t,b.REAL_URL\n\t\t\t\t\t,b.URL\n\t\t\t\t\t," . $DB->DateToCharFunction("bp.DATE_PUBLISH") . " as DATE_PUBLISH\n\t\t\t\t\t,bp.TITLE\n\t\t\t\t\t,bp.DETAIL_TEXT\n\t\t\t\t\t,bp.BLOG_ID\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,bp.CATEGORY_ID\n\t\t\t\t\t,b.SOCNET_GROUP_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\t\t,b.GROUP_ID\n\t\t\t\t\t,bp.PATH\n\t\t\t\t\t,bp.MICRO\n\t\t\t\t\t,bp.PUBLISH_STATUS\n\t\t\t\t\t,bp.AUTHOR_ID " . ($bSonet ? ", BSL.ID as SLID" : "") . " FROM\n\t\t\t\t\tb_blog_post bp\n\t\t\t\t\tINNER JOIN b_blog b ON (bp.BLOG_ID = b.ID)\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID) " . ($bSonet ? "LEFT JOIN b_sonet_log BSL ON (BSL.EVENT_ID in ('blog_post', 'blog_post_micro') AND BSL.SOURCE_ID = bp.ID) " : "") . " WHERE\n\t\t\t\t\tbp.DATE_PUBLISH <= " . $DB->CurrentTimeFunction() . "\n\t\t\t\t\tAND b.ACTIVE = 'Y'\n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? "AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND bp.ID > " . $id . "\n\t\t\t\t\t\n\t\t\t\tORDER BY\n\t\t\t\t\tbp.ID\n\t\t\t";
         /*		AND bp.PUBLISH_STATUS = '".$DB->ForSQL(BLOG_PUBLISH_STATUS_PUBLISH)."'*/
         //AND b.SEARCH_INDEX = 'Y'
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             //Check permissions
             $tag = "";
             if ($ar["USE_SOCNET"] != "Y") {
                 $PostPerms = CBlogUserGroup::GetGroupPerms(1, $ar["BLOG_ID"], $ar["ID"], BLOG_PERMS_POST);
                 if ($PostPerms < BLOG_PERMS_READ) {
                     continue;
                 }
             }
             //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
             if (strlen($ar["PATH"]) > 0) {
                 $arSite = array($ar["SITE_ID"] => str_replace("#post_id#", $ar["ID"], $ar["PATH"]));
             } else {
                 $arSite = array($ar["SITE_ID"] => CBlogPost::PreparePath($ar["URL"], $ar["ID"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]));
             }
             if (strlen($ar["CATEGORY_ID"]) > 0) {
                 $arC = explode(",", $ar["CATEGORY_ID"]);
                 $tag = "";
                 $arTag = array();
                 foreach ($arC as $v) {
                     $arCategory = CBlogCategory::GetByID($v);
                     $arTag[] = $arCategory["NAME"];
                 }
                 $tag = implode(",", $arTag);
             }
             //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
             $Result = array("ID" => "P" . $ar["ID"], "LAST_MODIFIED" => $ar["DATE_PUBLISH"], "TITLE" => blogTextParser::killAllTags($ar["TITLE"]), "BODY" => blogTextParser::killAllTags($ar["DETAIL_TEXT"]), "SITE_ID" => $arSite, "PARAM1" => "POST", "PARAM2" => $ar["BLOG_ID"], "PERMISSIONS" => array(2), "TAGS" => $tag, "USER_ID" => $ar["AUTHOR_ID"], "ENTITY_TYPE_ID" => "BLOG_POST", "ENTITY_ID" => $ar["ID"]);
             if ($ar["USE_SOCNET"] == "Y" && CModule::IncludeModule("socialnetwork")) {
                 $arF = array();
                 if (COption::GetOptionString("blog", "socNetNewPerms", "N") == "N") {
                     if (IntVal($ar["SOCNET_GROUP_ID"]) > 0) {
                         $newBlogId = 0;
                         if (IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]) > 0) {
                             $newBlogId = IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]);
                         } else {
                             $arFields = array("=DATE_UPDATE" => $DB->CurrentTimeFunction(), "GROUP_ID" => $ar["GROUP_ID"], "ACTIVE" => "Y", "ENABLE_COMMENTS" => "Y", "ENABLE_IMG_VERIF" => "Y", "EMAIL_NOTIFY" => "Y", "ENABLE_RSS" => "Y", "ALLOW_HTML" => "N", "ENABLE_TRACKBACK" => "N", "SEARCH_INDEX" => "Y", "USE_SOCNET" => "Y", "=DATE_CREATE" => $DB->CurrentTimeFunction(), "PERMS_POST" => array(1 => "I", 2 => "I"), "PERMS_COMMENT" => array(1 => "P", 2 => "P"));
                             $bRights = false;
                             $rsUser = CUser::GetByID($ar["AUTHOR_ID"]);
                             $arUser = $rsUser->Fetch();
                             if (strlen($arUser["NAME"] . "" . $arUser["LAST_NAME"]) <= 0) {
                                 $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["LOGIN"];
                             } else {
                                 $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["NAME"] . " " . $arUser["LAST_NAME"];
                             }
                             $arFields["URL"] = str_replace(" ", "_", $arUser["LOGIN"]) . "-blog-" . $ar["SITE_ID"];
                             $arFields["OWNER_ID"] = $ar["AUTHOR_ID"];
                             $urlCheck = preg_replace("/[^a-zA-Z0-9_-]/is", "", $arFields["URL"]);
                             if ($urlCheck != $arFields["URL"]) {
                                 $arFields["URL"] = "u" . $arUser["ID"] . "-blog-" . $ar["SITE_ID"];
                             }
                             if (CBlog::GetByUrl($arFields["URL"])) {
                                 $uind = 0;
                                 do {
                                     $uind++;
                                     $arFields["URL"] = $arFields["URL"] . $uind;
                                 } while (CBlog::GetByUrl($arFields["URL"]));
                             }
                             $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ar["AUTHOR_ID"], "blog", "view_post");
                             if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL) {
                                 $bRights = true;
                             }
                             $blogID = CBlog::Add($arFields);
                             if ($bRights) {
                                 CBlog::AddSocnetRead($blogID);
                             }
                             $newBlogId = $blogID;
                             $arUser2Blog[$arFields["OWNER_ID"]][$arFields["GROUP_ID"]] = $newBlogId;
                         }
                         if (intVal($newBlogId) > 0) {
                             $arF = array("BLOG_ID" => $newBlogId, "SOCNET_RIGHTS" => array("SG" . $ar["SOCNET_GROUP_ID"]));
                         }
                         if (IntVal($ar["SLID"]) > 0) {
                             CSocNetLog::Delete($ar["SLID"]);
                             $ar["SLID"] = 0;
                         }
                         $arSites = array();
                         $rsGroupSite = CSocNetGroup::GetSite($ar["SOCNET_GROUP_ID"]);
                         while ($arGroupSite = $rsGroupSite->Fetch()) {
                             $arSites[] = $arGroupSite["LID"];
                         }
                     } else {
                         $newBlogId = 0;
                         if ($ar["OWNER_ID"] != $ar["AUTHOR_ID"]) {
                             if (IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]) > 0) {
                                 $newBlogId = IntVal($arUser2Blog[$ar["AUTHOR_ID"]][$ar["GROUP_ID"]]);
                             } else {
                                 $arFields = array("=DATE_UPDATE" => $DB->CurrentTimeFunction(), "GROUP_ID" => $ar["GROUP_ID"], "ACTIVE" => "Y", "ENABLE_COMMENTS" => "Y", "ENABLE_IMG_VERIF" => "Y", "EMAIL_NOTIFY" => "Y", "ENABLE_RSS" => "Y", "ALLOW_HTML" => "N", "ENABLE_TRACKBACK" => "N", "SEARCH_INDEX" => "Y", "USE_SOCNET" => "Y", "=DATE_CREATE" => $DB->CurrentTimeFunction(), "PERMS_POST" => array(1 => "I", 2 => "I"), "PERMS_COMMENT" => array(1 => "P", 2 => "P"));
                                 $bRights = false;
                                 $rsUser = CUser::GetByID($ar["AUTHOR_ID"]);
                                 $arUser = $rsUser->Fetch();
                                 if (strlen($arUser["NAME"] . "" . $arUser["LAST_NAME"]) <= 0) {
                                     $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["LOGIN"];
                                 } else {
                                     $arFields["NAME"] = GetMessage("BLG_NAME") . " " . $arUser["NAME"] . " " . $arUser["LAST_NAME"];
                                 }
                                 $arFields["URL"] = str_replace(" ", "_", $arUser["LOGIN"]) . "-blog-" . $ar["SITE_ID"];
                                 $arFields["OWNER_ID"] = $ar["AUTHOR_ID"];
                                 $urlCheck = preg_replace("/[^a-zA-Z0-9_-]/is", "", $arFields["URL"]);
                                 if ($urlCheck != $arFields["URL"]) {
                                     $arFields["URL"] = "u" . $arUser["ID"] . "-blog-" . $ar["SITE_ID"];
                                 }
                                 if (CBlog::GetByUrl($arFields["URL"])) {
                                     $uind = 0;
                                     do {
                                         $uind++;
                                         $arFields["URL"] = $arFields["URL"] . $uind;
                                     } while (CBlog::GetByUrl($arFields["URL"]));
                                 }
                                 $featureOperationPerms = CSocNetFeaturesPerms::GetOperationPerm(SONET_ENTITY_USER, $ar["AUTHOR_ID"], "blog", "view_post");
                                 if ($featureOperationPerms == SONET_RELATIONS_TYPE_ALL) {
                                     $bRights = true;
                                 }
                                 $blogID = CBlog::Add($arFields);
                                 if ($bRights) {
                                     CBlog::AddSocnetRead($blogID);
                                 }
                                 $newBlogId = $blogID;
                                 $arUser2Blog[$arFields["OWNER_ID"]][$arFields["GROUP_ID"]] = $newBlogId;
                             }
                             if (IntVal($ar["SLID"]) > 0) {
                                 CSocNetLog::Delete($ar["SLID"]);
                                 $ar["SLID"] = 0;
                             }
                         }
                         $arF = array("SOCNET_RIGHTS" => array());
                         if (intVal($newBlogId) > 0) {
                             $arF["BLOG_ID"] = $newBlogId;
                         }
                         $arSites = array($ar["SITE_ID"]);
                     }
                     if (!empty($arF)) {
                         if (IntVal($arF["BLOG_ID"]) > 0) {
                             $Result["PARAM2"] = $ar["BLOG_ID"];
                             $sqlR = "UPDATE b_blog_post SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                             $sqlR = "UPDATE b_blog_post_category SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE POST_ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                             $sqlR = "UPDATE b_blog_image SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE POST_ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                             $sqlR = "UPDATE b_blog_comment SET BLOG_ID=" . IntVal($arF["BLOG_ID"]) . " WHERE POST_ID=" . IntVal($ar["ID"]);
                             $DB->Query($sqlR, False, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                         }
                         $sqlR = "SELECT * FROM b_blog_socnet_rights where POST_ID=" . IntVal($ar["ID"]);
                         $dbBB = $DB->Query($sqlR);
                         if (!$dbBB->Fetch()) {
                             $arF["SC_PERM"] = CBlogPost::UpdateSocNetPerms($ar["ID"], $arF["SOCNET_RIGHTS"], array("AUTHOR_ID" => $ar["AUTHOR_ID"]));
                         }
                         if (IntVal($arF["BLOG_ID"]) > 0 && $ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH) {
                             $dbComment = CBlogComment::GetList(array(), array("POST_ID" => $ar["ID"]), false, false, array("ID", "POST_ID", "BLOG_ID", "PATH"));
                             if ($arComment = $dbComment->Fetch()) {
                                 $arParamsComment = array("BLOG_ID" => $arF["BLOG_ID"], "POST_ID" => $ar["ID"], "SITE_ID" => $ar["SITE_ID"], "PATH" => $arPostSite[$arGroup["SITE_ID"]] . "?commentId=#comment_id###comment_id#", "USE_SOCNET" => "Y");
                                 CBlogComment::_IndexPostComments($arParamsComment);
                             }
                         }
                     }
                 }
                 if ($ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH) {
                     if (empty($arF["SC_PERM"])) {
                         $arF["SC_PERM"] = CBlogPost::GetSocNetPermsCode($ar["ID"]);
                     }
                     $Result["PERMISSIONS"] = $arF["SC_PERM"];
                     if (IntVal($ar["SLID"]) <= 0) {
                         $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($ar["DETAIL_TEXT"], false, array(), $arAllow, array("isSonetLog" => true));
                         $arSoFields = array("EVENT_ID" => "blog_post", "=LOG_DATE" => $DB->CharToDateFunction($ar["DATE_PUBLISH"], "FULL", SITE_ID), "LOG_UPDATE" => $DB->CharToDateFunction($ar["DATE_PUBLISH"], "FULL", SITE_ID), "TITLE_TEMPLATE" => "#USER_NAME# add post", "TITLE" => $ar["TITLE"], "MESSAGE" => $text4message, "MODULE_ID" => "blog", "CALLBACK_FUNC" => false, "SOURCE_ID" => $ar["ID"], "ENABLE_COMMENTS" => "N", "ENTITY_TYPE" => SONET_ENTITY_USER, "ENTITY_ID" => $ar["AUTHOR_ID"], "USER_ID" => $ar["AUTHOR_ID"], "URL" => $arSite[$ar["SITE_ID"]], "SITE_ID" => $arSites);
                         $logID = CSocNetLog::Add($arSoFields, false);
                         if (intval($logID) > 0) {
                             $socnetPerms = $arF["SC_PERM"];
                             if (!in_array("U" . $ar["AUTHOR_ID"], $socnetPerms)) {
                                 $socnetPerms[] = "U" . $ar["AUTHOR_ID"];
                             }
                             $socnetPerms[] = "SA";
                             // socnet admin
                             CSocNetLog::Update($logID, array("TMP_ID" => $logID, "=LOG_UPDATE" => $arSoFields["LOG_UPDATE"]));
                             CSocNetLogRights::DeleteByLogID($logID);
                             CSocNetLogRights::Add($logID, $socnetPerms);
                         }
                     } else {
                         $socnetPerms = $arF["SC_PERM"];
                         if (!in_array("U" . $ar["AUTHOR_ID"], $socnetPerms)) {
                             $socnetPerms[] = "U" . $ar["AUTHOR_ID"];
                         }
                         $socnetPerms[] = "SA";
                         // socnet admin
                         CSocNetLogRights::DeleteByLogID($ar["SLID"]);
                         CSocNetLogRights::Add($ar["SLID"], $socnetPerms);
                     }
                 }
             }
             if ($ar["PUBLISH_STATUS"] == BLOG_PUBLISH_STATUS_PUBLISH && $ar["SEARCH_INDEX"] == "Y") {
                 //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
                 if ($oCallback) {
                     $res = call_user_func(array($oCallback, $callback_method), $Result);
                     if (!$res) {
                         return $Result["ID"];
                     }
                 } else {
                     $arResult[] = $Result;
                 }
             }
         }
         //all blog posts indexed so let's start index users
         $category = 'C';
         $id = 0;
         COption::SetOptionString("blog", "socNetNewPerms", "Y");
     }
     if ($category == 'C') {
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tbc.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t,bp.ID as POST_ID\n\t\t\t\t\t,b.URL\n\t\t\t\t\t,bp.TITLE as POST_TITLE\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,b.SOCNET_GROUP_ID\n\t\t\t\t\t,bc.TITLE\n\t\t\t\t\t,bc.POST_TEXT\n\t\t\t\t\t,bc.POST_ID\n\t\t\t\t\t,bc.BLOG_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\t\t,bc.PATH\n\t\t\t\t\t," . $DB->DateToCharFunction("bc.DATE_CREATE") . " as DATE_CREATE\n\t\t\t\t\t,bc.AUTHOR_ID\n\t\t\t\tFROM\n\t\t\t\t\tb_blog_comment bc\n\t\t\t\t\tINNER JOIN b_blog_post bp ON (bp.ID = bc.POST_ID)\n\t\t\t\t\tINNER JOIN b_blog b ON (bc.BLOG_ID = b.ID)\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)\n\t\t\t\tWHERE\n\t\t\t\t\tbc.ID > " . $id . " \n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? " AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND b.SEARCH_INDEX = 'Y'\n\t\t\t\tORDER BY\n\t\t\t\t\tbc.ID\n\t\t\t";
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             //Check permissions
             $tag = "";
             $PostPerms = CBlogUserGroup::GetGroupPerms(1, $ar["BLOG_ID"], $ar["POST_ID"], BLOG_PERMS_POST);
             if ($PostPerms < BLOG_PERMS_READ) {
                 continue;
             }
             //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
             if (strlen($ar["PATH"]) > 0) {
                 $arSite = array($ar["SITE_ID"] => str_replace("#comment_id#", $ar["ID"], $ar["PATH"]));
             } else {
                 $arSite = array($ar["SITE_ID"] => CBlogPost::PreparePath($ar["URL"], $ar["POST_ID"], $ar["SITE_ID"], false, $ar["OWNER_ID"], $ar["SOCNET_GROUP_ID"]));
             }
             $Result = array("ID" => "C" . $ar["ID"], "SITE_ID" => $arSite, "LAST_MODIFIED" => $ar["DATE_CREATE"], "PARAM1" => "COMMENT", "PARAM2" => $ar["BLOG_ID"] . "|" . $ar["POST_ID"], "PERMISSIONS" => array(2), "TITLE" => $ar["TITLE"], "BODY" => blogTextParser::killAllTags($ar["POST_TEXT"]), "INDEX_TITLE" => false, "USER_ID" => IntVal($ar["AUTHOR_ID"]) > 0 ? $ar["AUTHOR_ID"] : false, "ENTITY_TYPE_ID" => "BLOG_COMMENT", "ENTITY_ID" => $ar["ID"]);
             if ($ar["USE_SOCNET"] == "Y") {
                 $arSp = CBlogComment::GetSocNetCommentPerms($ar["POST_ID"]);
                 if (is_array($arSp)) {
                     $Result["PERMISSIONS"] = $arSp;
                 }
             }
             if (strlen($ar["TITLE"]) <= 0) {
                 $Result["TITLE"] = substr($Result["BODY"], 0, 100);
             }
             if ($oCallback) {
                 $res = call_user_func(array($oCallback, $callback_method), $Result);
                 if (!$res) {
                     return $Result["ID"];
                 }
             } else {
                 $arResult[] = $Result;
             }
         }
         //all blog posts indexed so let's start index users
         $category = 'U';
         $id = 0;
     }
     if ($category == 'U') {
         $strSql = "\n\t\t\t\tSELECT\n\t\t\t\t\tbu.ID\n\t\t\t\t\t,bg.SITE_ID\n\t\t\t\t\t," . $DB->DateToCharFunction("bu.LAST_VISIT") . " as LAST_VISIT\n\t\t\t\t\t," . $DB->DateToCharFunction("u.DATE_REGISTER") . " as DATE_REGISTER\n\t\t\t\t\t,bu.ALIAS\n\t\t\t\t\t,bu.DESCRIPTION\n\t\t\t\t\t,bu.INTERESTS\n\t\t\t\t\t,u.NAME\n\t\t\t\t\t,u.LAST_NAME\n\t\t\t\t\t,u.LOGIN\n\t\t\t\t\t,bu.USER_ID\n\t\t\t\t\t,b.OWNER_ID\n\t\t\t\t\t,b.USE_SOCNET\n\t\t\t\t\t,b.SEARCH_INDEX\n\t\t\t\tFROM\n\t\t\t\t\tb_blog_user bu\n\t\t\t\t\tINNER JOIN b_user u  ON (u.ID = bu.USER_ID)\n\t\t\t\t\tINNER JOIN b_blog b ON (u.ID = b.OWNER_ID)\n\t\t\t\t\tINNER JOIN b_blog_group bg ON (b.GROUP_ID = bg.ID)\n\t\t\t\tWHERE\n\t\t\t\t\tb.ACTIVE = 'Y'\n\t\t\t\t\t" . ($NS["SITE_ID"] != "" ? "AND bg.SITE_ID='" . $DB->ForSQL($NS["SITE_ID"]) . "'" : "") . "\n\t\t\t\t\tAND bu.ID > " . $id . "\n\t\t\t\t\tAND b.SEARCH_INDEX = 'Y'\n\t\t\t\tORDER BY\n\t\t\t\t\tbu.ID\n\t\t\t";
         //CBlogSearch::Trace('OnSearchReindex', 'strSql', $strSql);
         $rs = $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         while ($ar = $rs->Fetch()) {
             if ($ar["USE_SOCNET"] == "Y") {
                 $Result = array("ID" => "U" . $ar["ID"], "BODY" => "", "TITLE" => "");
             } else {
                 //CBlogSearch::Trace('OnSearchReindex', 'ar', $ar);
                 $arSite = array($ar["SITE_ID"] => CBlogUser::PreparePath($ar["USER_ID"], $ar["SITE_ID"]));
                 //CBlogSearch::Trace('OnSearchReindex', 'arSite', $arSite);
                 $Result = array("ID" => "U" . $ar["ID"], "LAST_MODIFIED" => $ar["LAST_VISIT"], "TITLE" => CBlogUser::GetUserName($ar["ALIAS"], $ar["NAME"], $ar["LAST_NAME"], $ar["LOGIN"]), "BODY" => blogTextParser::killAllTags($ar["DESCRIPTION"] . " " . $ar["INTERESTS"]), "SITE_ID" => $arSite, "PARAM1" => "USER", "PARAM2" => $ar["ID"], "PERMISSIONS" => array(2));
                 if (strlen($Result["LAST_MODIFIED"]) <= 0) {
                     $Result["LAST_MODIFIED"] = $ar["DATE_REGISTER"];
                 }
             }
             //CBlogSearch::Trace('OnSearchReindex', 'Result', $Result);
             if ($oCallback) {
                 $res = call_user_func(array($oCallback, $callback_method), $Result);
                 if (!$res) {
                     return $Result["ID"];
                 }
             } else {
                 $arResult[] = $Result;
             }
         }
     }
     if ($oCallback) {
         return false;
     }
     return $arResult;
 }
예제 #7
0
 function SetPerm($featureID, $operation, $perm)
 {
     $arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
     $featureID = IntVal($featureID);
     $operation = Trim($operation);
     $perm = Trim($perm);
     $dbResult = CSocNetFeaturesPerms::GetList(array(), array("FEATURE_ID" => $featureID, "OPERATION_ID" => $operation), false, false, array("ID", "FEATURE_ENTITY_TYPE", "FEATURE_ENTITY_ID", "FEATURE_FEATURE", "OPERATION_ID", "ROLE"));
     if ($arResult = $dbResult->Fetch()) {
         $r = CSocNetFeaturesPerms::Update($arResult["ID"], array("ROLE" => $perm));
     } else {
         $r = CSocNetFeaturesPerms::Add(array("FEATURE_ID" => $featureID, "OPERATION_ID" => $operation, "ROLE" => $perm));
     }
     if (!$r) {
         $errorMessage = "";
         if ($e = $GLOBALS["APPLICATION"]->GetException()) {
             $errorMessage = $e->GetString();
         }
         if (StrLen($errorMessage) <= 0) {
             $errorMessage = GetMessage("SONET_GF_ERROR_SET") . ".";
         }
         $GLOBALS["APPLICATION"]->ThrowException($errorMessage, "ERROR_SET_RECORD");
         return false;
     } else {
         if (!$arResult) {
             $arFeature = CSocNetFeatures::GetByID($featureID);
             $entity_type = $arFeature["ENTITY_TYPE"];
             $entity_id = $arFeature["ENTITY_ID"];
             $feature = $arFeature["FEATURE"];
         } else {
             $entity_type = $arResult["FEATURE_ENTITY_TYPE"];
             $entity_id = $arResult["FEATURE_ENTITY_ID"];
             $feature = $arResult["FEATURE_FEATURE"];
         }
         if (empty($arResult) || $arResult["ROLE"] != $perm) {
             if ($arResult && $arResult["ROLE"] != $perm) {
                 CSocNetSearch::SetFeaturePermissions($entity_type, $entity_id, $feature, $arResult["OPERATION_ID"], $perm);
             } else {
                 CSocNetSearch::SetFeaturePermissions($entity_type, $entity_id, $feature, $operation, $perm);
             }
         }
         if (!in_array($feature, array("tasks", "files", "blog")) && is_array($arSocNetFeaturesSettings[$feature]["subscribe_events"])) {
             $arEventsTmp = array_keys($arSocNetFeaturesSettings[$feature]["subscribe_events"]);
             $rsLog = CSocNetLog::GetList(array(), array("ENTITY_TYPE" => $entity_type, "ENTITY_ID" => $entity_id, "EVENT_ID" => $arEventsTmp), false, false, array("ID", "EVENT_ID"));
             while ($arLog = $rsLog->Fetch()) {
                 CSocNetLogRights::DeleteByLogID($arLog["ID"]);
                 CSocNetLogRights::SetForSonet($arLog["ID"], $entity_type, $entity_id, $feature, $arSocNetFeaturesSettings[$feature]["subscribe_events"][$arLog["EVENT_ID"]]["OPERATION"]);
             }
         }
     }
     return $r;
 }
예제 #8
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);
                 }
             }
         }
     }
 }
예제 #9
0
 public static function OnEditCalendarEventEntry($eventId, $arFields = array(), $attendeesCodes = array())
 {
     global $DB;
     if ($eventId > 0) {
         $arSoFields = array("ENTITY_ID" => $arFields["OWNER_ID"], "USER_ID" => $arFields["OWNER_ID"], "=LOG_DATE" => $DB->CurrentTimeFunction(), "TITLE_TEMPLATE" => "#TITLE#", "TITLE" => $arFields["NAME"], "MESSAGE" => "", "TEXT_MESSAGE" => "");
         $arAccessCodes = array();
         foreach ($attendeesCodes as $value) {
             if ($value == "UA") {
                 $arAccessCodes[] = "G2";
             } else {
                 $arAccessCodes[] = $value;
             }
         }
         $dbRes = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => "calendar", "SOURCE_ID" => $eventId), false, false, array("ID"));
         $arCodes = array();
         foreach ($arAccessCodes as $value) {
             if (substr($value, 0, 2) === 'SG') {
                 $arCodes[] = $value . '_K';
             }
             $arCodes[] = $value;
         }
         $arCodes = array_unique($arCodes);
         if ($arRes = $dbRes->Fetch()) {
             CSocNetLog::Update($arRes["ID"], $arSoFields);
             CSocNetLogRights::DeleteByLogID($arRes["ID"]);
             CSocNetLogRights::Add($arRes["ID"], $arCodes);
         } else {
             $arSoFields = array_merge($arSoFields, array("ENTITY_TYPE" => SONET_SUBSCRIBE_ENTITY_USER, "EVENT_ID" => "calendar", "SITE_ID" => SITE_ID, "SOURCE_ID" => $eventId, "ENABLE_COMMENTS" => "Y", "CALLBACK_FUNC" => false));
             $logID = CSocNetLog::Add($arSoFields, false);
             CSocNetLogRights::Add($logID, $arCodes);
         }
     }
 }
예제 #10
0
 public function ShowMessage()
 {
     if (!$this->IsAvailable()) {
         return false;
     }
     $arNotification = $this->Notify->getNotification();
     $oLog = CSocNetLog::GetList(array("ID" => "DESC"), array("EVENT_ID" => 'idea', "SOURCE_ID" => $arNotification["ID"]), false, false, array("ID"));
     while ($arLog = $oLog->Fetch()) {
         CSocNetLogRights::DeleteByLogID($arLog["ID"]);
         CSocNetLogRights::Add($arLog["ID"], array("G2"));
     }
     return false;
 }
예제 #11
0
 protected static function SendMessageToSocNet($arFields, $bSpawnedByAgent, $arChanges = null, $arTask = null, array $parameters = array())
 {
     global $USER, $DB;
     $effectiveUserId = self::getEffectiveUserId($arFields, array(), $bSpawnedByAgent, $parameters);
     if (!CModule::IncludeModule('socialnetwork')) {
         return null;
     }
     $bCrmTask = 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);
     $arLogFilter = false;
     if (!$bCrmTask) {
         $arLogFilter = array("EVENT_ID" => "tasks", "SOURCE_ID" => $arTask["ID"]);
     } elseif (CModule::IncludeModule("crm")) {
         $dbCrmActivity = CCrmActivity::GetList(array(), array('TYPE_ID' => CCrmActivityType::Task, 'ASSOCIATED_ENTITY_ID' => $arTask["ID"], 'CHECK_PERMISSIONS' => 'N'), false, false, array('ID'));
         if ($arCrmActivity = $dbCrmActivity->Fetch()) {
             $arLogFilter = array("EVENT_ID" => "crm_activity_add", "ENTITY_ID" => $arCrmActivity["ID"]);
         }
     }
     if (!$arLogFilter) {
         return null;
     }
     static $arCheckedUsers = array();
     // users that checked for their existing
     static $cachedSiteTimeFormat = -1;
     // select "real" author
     $occurAsUserId = CTasksTools::getOccurAsUserId();
     if (!$occurAsUserId) {
         $occurAsUserId = $effectiveUserId;
     }
     if ($cachedSiteTimeFormat === -1) {
         $cachedSiteTimeFormat = CSite::GetDateFormat('FULL', SITE_ID);
     }
     static $cachedAllSitesIds = -1;
     if ($cachedAllSitesIds === -1) {
         $cachedAllSitesIds = array();
         $dbSite = CSite::GetList($by = 'sort', $order = 'desc', array('ACTIVE' => 'Y'));
         while ($arSite = $dbSite->Fetch()) {
             $cachedAllSitesIds[] = $arSite['ID'];
         }
     }
     // Check that user exists
     if (!in_array((int) $arFields["CREATED_BY"], $arCheckedUsers, true)) {
         $rsUser = CUser::GetList($by = 'ID', $order = 'ASC', array('ID' => $arFields["CREATED_BY"]), array('FIELDS' => array('ID')));
         if (!($arUser = $rsUser->Fetch())) {
             return false;
         }
         $arCheckedUsers[] = (int) $arFields["CREATED_BY"];
     }
     if (is_array($arChanges)) {
         if (count($arChanges) == 0) {
             $rsSocNetLogItems = CSocNetLog::GetList(array("ID" => "DESC"), $arLogFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
             while ($arRes = $rsSocNetLogItems->Fetch()) {
                 $authorUserId = false;
                 if (isset($arFields['CREATED_BY'])) {
                     $authorUserId = (int) $arFields['CREATED_BY'];
                 } elseif (isset($arTask['CREATED_BY'])) {
                     $authorUserId = (int) $arTask['CREATED_BY'];
                 }
                 // Add author to list of users that view log about task in livefeed
                 // But only when some other person change task
                 // or if added FORUM_TOPIC_ID
                 if ($authorUserId !== $effectiveUserId || $arTask['FORUM_TOPIC_ID'] == 0 && isset($arFields['FORUM_TOPIC_ID']) && $arFields['FORUM_TOPIC_ID'] > 0) {
                     $authorGroupCode = 'U' . $authorUserId;
                     $rsRights = CSocNetLogRights::GetList(array(), array('LOG_ID' => $arRes['ID'], 'GROUP_CODE' => $authorGroupCode));
                     // If task's author hasn't rights yet, give them
                     if (!($arRights = $rsRights->fetch())) {
                         CSocNetLogRights::Add($arRes["ID"], array($authorGroupCode));
                     }
                 }
             }
             return null;
         } elseif (count($arChanges) == 1 && isset($arChanges['STATUS'])) {
             return null;
             // if only status changes - don't send message, because it will be sent by SendStatusMessage()
         }
     }
     if ($bSpawnedByAgent === 'Y') {
         $bSpawnedByAgent = true;
     } elseif ($bSpawnedByAgent === 'N') {
         $bSpawnedByAgent = false;
     }
     if (!is_bool($bSpawnedByAgent)) {
         return false;
     }
     $taskId = false;
     if (is_array($arFields) && isset($arFields['ID']) && $arFields['ID'] > 0) {
         $taskId = $arFields['ID'];
     } elseif (is_array($arTask) && isset($arTask['ID']) && $arTask['ID'] > 0) {
         $taskId = $arTask['ID'];
     }
     // We will mark this to false, if we send update message and log item already exists
     $bSocNetAddNewItem = true;
     $logDate = $DB->CurrentTimeFunction();
     $curTimeTimestamp = time() + CTimeZone::GetOffset();
     if (!$bCrmTask) {
         $arSoFields = array('EVENT_ID' => 'tasks', 'TITLE' => $arFields['TITLE'], 'MESSAGE' => '', 'MODULE_ID' => 'tasks');
     } else {
         $arSoFields = array();
     }
     // If changes and task data given => we are prepare "update" message,
     // or "add" message otherwise
     if (is_array($arChanges) && is_array($arTask)) {
         // Prepare "update" message here
         if (strlen($arFields["CHANGED_DATE"]) > 0) {
             $createdDateTimestamp = MakeTimeStamp($arFields["CHANGED_DATE"], $cachedSiteTimeFormat);
             if ($createdDateTimestamp > $curTimeTimestamp) {
                 $logDate = $DB->CharToDateFunction($arFields["CHANGED_DATE"], "FULL", SITE_ID);
             }
         }
         $arChangesFields = array_keys($arChanges);
         $arSoFields['TEXT_MESSAGE'] = str_replace('#CHANGES#', implode(', ', CTaskNotifications::__Fields2Names($arChangesFields)), GetMessage('TASKS_SONET_TASK_CHANGED_MESSAGE'));
         if (!$bCrmTask) {
             if ($arFields["GROUP_ID"] === NULL && $arTask['GROUP_ID'] || $arFields['GROUP_ID']) {
                 $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_GROUP;
                 $arSoFields["ENTITY_ID"] = $arFields["GROUP_ID"] ? $arFields["GROUP_ID"] : $arTask['GROUP_ID'];
             } else {
                 $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_USER;
                 $arSoFields["ENTITY_ID"] = $arFields["CREATED_BY"] ? $arFields["CREATED_BY"] : $arTask["CREATED_BY"];
             }
         }
         $arSoFields['PARAMS'] = serialize(array('TYPE' => 'modify', 'CHANGED_FIELDS' => $arChangesFields, 'CREATED_BY' => $arFields["CREATED_BY"] ? $arFields["CREATED_BY"] : $arTask["CREATED_BY"], 'CHANGED_BY' => $occurAsUserId ? $occurAsUserId : $arFields['CHANGED_BY'], 'PREV_REAL_STATUS' => isset($arTask['REAL_STATUS']) ? $arTask['REAL_STATUS'] : false));
         // Determine, does item exists in sonet log
         $rsSocNetLogItems = CSocNetLog::GetList(array("ID" => "DESC"), $arLogFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
         if ($rsSocNetLogItems->Fetch()) {
             $bSocNetAddNewItem = false;
             // item already exists, update it, not create.
         }
     } else {
         if (strlen($arFields["CREATED_DATE"]) > 0) {
             $createdDateTimestamp = MakeTimeStamp($arFields["CREATED_DATE"], $cachedSiteTimeFormat);
             if ($createdDateTimestamp > $curTimeTimestamp) {
                 $logDate = $DB->CharToDateFunction($arFields["CREATED_DATE"], "FULL", SITE_ID);
             }
         }
         $arSoFields['TEXT_MESSAGE'] = GetMessage('TASKS_SONET_NEW_TASK_MESSAGE');
         if ($arFields["GROUP_ID"]) {
             $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_GROUP;
             $arSoFields["ENTITY_ID"] = $arFields["GROUP_ID"];
         } else {
             $arSoFields["ENTITY_TYPE"] = SONET_ENTITY_USER;
             $arSoFields["ENTITY_ID"] = $arFields["CREATED_BY"];
         }
         $arParamsLog = array('TYPE' => 'create', 'CREATED_BY' => $arFields["CREATED_BY"] ? $arFields["CREATED_BY"] : $arTask["CREATED_BY"], 'PREV_REAL_STATUS' => isset($arTask['REAL_STATUS']) ? $arTask['REAL_STATUS'] : false);
         if ($occurAsUserId) {
             $arParamsLog["CREATED_BY"] = $occurAsUserId;
         }
         $arSoFields['PARAMS'] = serialize($arParamsLog);
     }
     // rating entity id (ilike)
     $arSoFields["RATING_ENTITY_ID"] = $taskId;
     $arSoFields["RATING_TYPE_ID"] = "TASK";
     // Do we need add new item to socnet?
     // We adds new item, if it is not exists.
     $logID = false;
     if (IsModuleInstalled("webdav") || IsModuleInstalled("disk")) {
         $ufDocID = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFieldValue("TASKS_TASK", "UF_TASK_WEBDAV_FILES", $taskId, LANGUAGE_ID);
         if ($ufDocID) {
             $arSoFields["UF_SONET_LOG_DOC"] = $ufDocID;
         }
     }
     if ($bSocNetAddNewItem) {
         $arSoFields['=LOG_DATE'] = $logDate;
         $arSoFields['CALLBACK_FUNC'] = false;
         $arSoFields['SOURCE_ID'] = $taskId;
         $arSoFields['ENABLE_COMMENTS'] = 'Y';
         $arSoFields['URL'] = CTaskNotifications::GetNotificationPath(array('ID' => (int) $arFields["CREATED_BY"]), $taskId, false);
         $arSoFields['USER_ID'] = $arFields['CREATED_BY'];
         $arSoFields['TITLE_TEMPLATE'] = '#TITLE#';
         // Set all sites because any user from any site may be
         // added to task in future. For example, new auditor, etc.
         $arSoFields['SITE_ID'] = $cachedAllSitesIds;
         $logID = CSocNetLog::Add($arSoFields, false);
         if (intval($logID) > 0) {
             CSocNetLog::Update($logID, array("TMP_ID" => $logID));
             $arTaskParticipant = CTaskNotifications::GetRecipientsIDs($arFields, false);
             // Exclude author
             $arLogCanViewedBy = array_diff($arTaskParticipant, array($arFields['CREATED_BY']));
             $arRights = CTaskNotifications::__UserIDs2Rights($arLogCanViewedBy);
             if (isset($arFields['GROUP_ID'])) {
                 $arRights = array_merge($arRights, self::prepareRightsCodesForViewInGroupLiveFeed($logID, $arFields['GROUP_ID']));
             }
             CSocNetLogRights::Add($logID, $arRights);
             CSocNetLog::SendEvent($logID, "SONET_NEW_EVENT", $logID);
         }
     } else {
         $arSoFields['=LOG_DATE'] = $logDate;
         $arSoFields['=LOG_UPDATE'] = $logDate;
         // All tasks posts in live feed should be from director
         if (isset($arFields['CREATED_BY'])) {
             $arSoFields['USER_ID'] = $arFields['CREATED_BY'];
         } elseif (isset($arTask['CREATED_BY'])) {
             $arSoFields['USER_ID'] = $arTask['CREATED_BY'];
         } elseif ($occurAsUserId) {
             $arSoFields['USER_ID'] = $occurAsUserId;
         } else {
             unset($arSoFields['USER_ID']);
         }
         $rsSocNetLogItems = CSocNetLog::GetList(array("ID" => "DESC"), $arLogFilter, false, false, array("ID", "ENTITY_TYPE", "ENTITY_ID"));
         while ($arRes = $rsSocNetLogItems->Fetch()) {
             CSocNetLog::Update($arRes["ID"], $arSoFields);
             $arTaskParticipant = CTaskNotifications::GetRecipientsIDs($arFields, false, true);
             $bAuthorMustBeExcluded = false;
             $authorUserId = false;
             if (isset($arFields['CREATED_BY'])) {
                 $authorUserId = (int) $arFields['CREATED_BY'];
             } elseif (isset($arTask['CREATED_BY'])) {
                 $authorUserId = (int) $arTask['CREATED_BY'];
             }
             // Get current rights
             $rsRights = CSocNetLogRights::GetList(array(), array('LOG_ID' => $arRes['ID']));
             $arCurrentRights = array();
             while ($arRights = $rsRights->fetch()) {
                 $arCurrentRights[] = $arRights['GROUP_CODE'];
             }
             // If author changes the task and author doesn't have
             // access to task yet, don't give access to him.
             if ($authorUserId === $effectiveUserId) {
                 $authorGroupCode = 'U' . $authorUserId;
                 // If task's author hasn't rights yet, still exclude him
                 if (!in_array($authorGroupCode, $arCurrentRights, true)) {
                     $bAuthorMustBeExcluded = true;
                 }
             }
             if ($bAuthorMustBeExcluded) {
                 $arLogCanViewedBy = array_diff($arTaskParticipant, array($authorUserId));
             } else {
                 $arLogCanViewedBy = $arTaskParticipant;
             }
             $arNewRights = CTaskNotifications::__UserIDs2Rights($arLogCanViewedBy);
             $bGroupChanged = false;
             if (isset($arFields['GROUP_ID'], $arTask['GROUP_ID']) && $arFields['GROUP_ID'] && $arFields['GROUP_ID'] != $arTask['GROUP_ID']) {
                 $bGroupChanged = true;
             }
             // If rights really changed, update them
             if (count(array_diff($arCurrentRights, $arNewRights)) || count(array_diff($arNewRights, $arCurrentRights)) || $bGroupChanged) {
                 if (isset($arFields['GROUP_ID'])) {
                     $arNewRights = array_merge($arNewRights, self::prepareRightsCodesForViewInGroupLiveFeed($logID, $arFields['GROUP_ID']));
                 } elseif (isset($arTask['GROUP_ID'])) {
                     $arNewRights = array_merge($arNewRights, self::prepareRightsCodesForViewInGroupLiveFeed($logID, $arTask['GROUP_ID']));
                 }
                 CSocNetLogRights::DeleteByLogID($arRes["ID"], true);
                 CSocNetLogRights::Add($arRes["ID"], $arNewRights);
             }
         }
     }
     return $logID;
 }
예제 #12
0
         }
         if (intval($arParams["user_id"]) > 0) {
             $arSoFields["USER_ID"] = $arParams["user_id"];
         }
         $logID = CSocNetLog::Add($arSoFields, false);
         if (intval($logID) > 0) {
             $socnetPerms = CBlogPost::GetSocNetPermsCode($arPost["ID"]);
             if (!in_array("U" . $arPost["AUTHOR_ID"], $socnetPerms)) {
                 $socnetPerms[] = "U" . $arPost["AUTHOR_ID"];
             }
             CSocNetLog::Update($logID, array("TMP_ID" => $logID));
             if (CModule::IncludeModule("extranet")) {
                 $arSiteID = CExtranet::GetSitesByLogDestinations($socnetPerms);
                 CSocNetLog::Update($logID, array("SITE_ID" => $arSiteID));
             }
             CSocNetLogRights::DeleteByLogID($logID);
             CSocNetLogRights::Add($logID, $socnetPerms);
             CSocNetLog::SendEvent($logID, "SONET_NEW_EVENT", $logID);
         }
     }
 }
 // IMAGES UPDATE
 if (!empty($arImagesToUpdate)) {
     foreach ($arImagesToUpdate as $imgID) {
         CBlogImage::Update($imgID, array("POST_ID" => $postID));
     }
 }
 // category update
 foreach ($iCategory as $iCategoryValue) {
     CBlogPostCategory::Add(array("BLOG_ID" => $blogID, "POST_ID" => $postID, "CATEGORY_ID" => $iCategoryValue));
 }
예제 #13
0
 public function SocnetLogUpdateRights($ID, $iblockID, $eventID)
 {
     if (!CModule::IncludeModule("socialnetwork")) {
         return null;
     }
     $arReaders = CWebDavIblock::GetReaders($ID, $iblockID);
     if ($arLog = self::GetSocnetLogByFileID($ID, $eventID)) {
         CSocNetLogRights::DeleteByLogID($arLog['ID']);
         if (CModule::IncludeModule("extranet")) {
             $arSiteID = CExtranet::GetSitesByLogDestinations($arReaders);
             CSocNetLog::Update($arLog['ID'], array("SITE_ID" => $arSiteID));
         }
         CSocNetLogRights::Add($arLog['ID'], $arReaders);
     }
 }