$arSelect = array("ID", "LOG_ID", "SOURCE_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "EVENT_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "GROUP_NAME", "GROUP_OWNER_ID", "GROUP_VISIBLE", "GROUP_OPENED", "GROUP_IMAGE_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "USER_PERSONAL_PHOTO", "USER_PERSONAL_GENDER", "CREATED_BY_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LOGIN", "CREATED_BY_PERSONAL_PHOTO", "CREATED_BY_PERSONAL_GENDER", "LOG_SITE_ID", "LOG_SOURCE_ID", "RATING_TYPE_ID", "RATING_ENTITY_ID", "UF_*"); $arListParams = array("USE_SUBSCRIBE" => "N"); $arUFMeta = __SLMGetUFMeta(); $dbComments = CSocNetLogComments::GetList(array("LOG_DATE" => "ASC"), $arFilter, false, false, $arSelect, $arListParams); while ($arComments = $dbComments->GetNext()) { if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->RegisterTag("USER_NAME_" . intval($arComments["USER_ID"])); } $arComments["UF"] = $arUFMeta; foreach ($arUFMeta as $field_name => $arUF) { if (array_key_exists($field_name, $arComments)) { $arComments["UF"][$field_name]["VALUE"] = $arComments[$field_name]; $arComments["UF"][$field_name]["ENTITY_VALUE_ID"] = $arComments["ID"]; } } $arResult["arComments"][] = __SLMGetLogCommentRecord($arComments, $arParams, false); } if (is_object($cache)) { $arCacheData = array("COMMENTS_FULL_LIST" => $arResult["arComments"]); $cache->EndDataCache($arCacheData); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->EndTagCache(); } } } foreach ($arResult["arComments"] as $key => $arCommentTmp) { if ($key === 0) { $rating_entity_type = $arCommentTmp["EVENT"]["RATING_TYPE_ID"]; } if ($last_comment_ts > 0 && $arCommentTmp["LOG_DATE_TS"] >= $last_comment_ts || $last_comment_ts <= 0 && $arCommentTmp["EVENT"]["ID"] >= $last_comment_id) { unset($arResult["arComments"][$key]);
$arListParams = array("CHECK_RIGHTS" => "Y"); if ($arParams["LOG_ID"] > 0) { $arFilter = array("LOG_ID" => $arParams["LOG_ID"]); $arSelect = array("ID", "LOG_ID", "SOURCE_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "EVENT_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "GROUP_NAME", "GROUP_OWNER_ID", "GROUP_VISIBLE", "GROUP_OPENED", "GROUP_IMAGE_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "USER_PERSONAL_PHOTO", "USER_PERSONAL_GENDER", "CREATED_BY_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LOGIN", "CREATED_BY_PERSONAL_PHOTO", "CREATED_BY_PERSONAL_GENDER", "LOG_SITE_ID", "LOG_SOURCE_ID", "RATING_TYPE_ID", "RATING_ENTITY_ID", "RATING_TOTAL_VALUE", "RATING_TOTAL_VOTES", "RATING_TOTAL_POSITIVE_VOTES", "RATING_TOTAL_NEGATIVE_VOTES", "RATING_USER_VOTE_VALUE"); $arListParams["USE_SUBSCRIBE"] = "N"; } else { $arFilter = array(">LOG_DATE" => $counterLastDate, "!USER_ID" => $GLOBALS["USER"]->GetID()); $arSelect = array("ID", "LOG_ID", "LOG_DATE"); $arListParams["USE_SUBSCRIBE"] = $arParams["SUBSCRIBE_ONLY"]; } $dbComments = CSocNetLogComments::GetList(array("LOG_DATE" => "ASC"), $arFilter, false, false, $arSelect, $arListParams); $arTmpComments = array(); if ($arResult["COUNTER_TYPE"] == "**") { while ($arComments = $dbComments->GetNext()) { if ($arParams["LOG_ID"] > 0) { __SLMGetLogCommentRecord($arComments, $arParams, $arCurrentUserSubscribe, $arMyEntities, $arTmpComments); } else { if (!array_key_exists($arComments["LOG_ID"], $arTmpComments)) { $arTmpComments[$arComments["LOG_ID"]] = 0; } $arTmpComments[$arComments["LOG_ID"]]++; } } } if ($arParams["LOG_ID"] > 0 && count($arTmpComments) > $arParams["COMMENTS_IN_EVENT"]) { if (intval($arResult["LAST_LOG_TS"]) > 1 && MakeTimeStamp($arTmpComments[count($arTmpComments) - 1]["LOG_DATE"]) - intval($arResult["TZ_OFFSET"]) > $arResult["LAST_LOG_TS"]) { foreach ($arTmpComments as $j => $arComment) { if (MakeTimeStamp($arComment["LOG_DATE"]) - intval($arResult["TZ_OFFSET"]) > $arResult["LAST_LOG_TS"]) { if (count($arTmpComments) - $j <= $arParams["COMMENTS_IN_EVENT"]) { $arTmpComments = array_slice($arTmpComments, -$arParams["COMMENTS_IN_EVENT"], $arParams["COMMENTS_IN_EVENT"]); } else {
$arSelect = array("ID", "LOG_ID", "SOURCE_ID", "ENTITY_TYPE", "ENTITY_ID", "USER_ID", "EVENT_ID", "LOG_DATE", "MESSAGE", "TEXT_MESSAGE", "URL", "MODULE_ID", "GROUP_NAME", "GROUP_OWNER_ID", "GROUP_VISIBLE", "GROUP_OPENED", "GROUP_IMAGE_ID", "USER_NAME", "USER_LAST_NAME", "USER_SECOND_NAME", "USER_LOGIN", "USER_PERSONAL_PHOTO", "USER_PERSONAL_GENDER", "CREATED_BY_NAME", "CREATED_BY_LAST_NAME", "CREATED_BY_SECOND_NAME", "CREATED_BY_LOGIN", "CREATED_BY_PERSONAL_PHOTO", "CREATED_BY_PERSONAL_GENDER", "LOG_SITE_ID", "LOG_SOURCE_ID", "RATING_TYPE_ID", "RATING_ENTITY_ID", "UF_*"); $arListParams = array("USE_SUBSCRIBE" => "N", "CHECK_RIGHTS" => "N"); $arUFMeta = __SLMGetUFMeta(); $dbComments = CSocNetLogComments::GetList(array("LOG_DATE" => "DESC"), $arFilter, false, array("nTopCount" => $nTopCount), $arSelect, $arListParams); while ($arComments = $dbComments->GetNext()) { if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->RegisterTag("USER_NAME_" . intval($arComments["USER_ID"])); } $arComments["UF"] = $arUFMeta; foreach ($arUFMeta as $field_name => $arUF) { if (array_key_exists($field_name, $arComments)) { $arComments["UF"][$field_name]["VALUE"] = $arComments[$field_name]; $arComments["UF"][$field_name]["ENTITY_VALUE_ID"] = $arComments["ID"]; } } $arCommentsFullList[] = __SLMGetLogCommentRecord($arComments, $arParams, false); } if (is_object($cache)) { $arCacheData = array("COMMENTS_FULL_LIST" => $arCommentsFullList); $cache->EndDataCache($arCacheData); if (defined("BX_COMP_MANAGED_CACHE")) { $GLOBALS["CACHE_MANAGER"]->EndTagCache(); } } } $arResult["NEW_COMMENTS"] = 0; if ($arResult["COUNTER_TYPE"] == "**" || $arParams["LOG_ID"] > 0) { $arCommentsFullListCut = array(); $arCommentID = array(); if (!empty($arCommentsFullList)) { $arCommentEvent = CSocNetLogTools::FindLogCommentEventByLogEventID($arEvent["EVENT"]["EVENT_ID"]);
$arResult["arCommentFormatted"] = $arTmpCommentEvent; } } elseif ($action == "get_comments") { $arResult["arComments"] = array(); $log_tmp_id = $_REQUEST["logid"]; $last_comment_id = $_REQUEST["last_comment_id"]; if (intval($log_tmp_id) > 0) { $arParams = array("PATH_TO_USER" => $_REQUEST["p_user"], "NAME_TEMPLATE" => $_REQUEST["nt"], "SHOW_LOGIN" => $_REQUEST["sl"], "AVATAR_SIZE_COMMENT" => $as, "PATH_TO_SMILE" => $_REQUEST["p_smile"]); $arFilter = array("LOG_ID" => $log_tmp_id); if (intval($last_comment_id) > 0) { $arFilter["<ID"] = $last_comment_id; } $arListParams = array("USE_SUBSCRIBE" => "N"); $dbComments = CSocNetLogComments::GetList(array("LOG_DATE" => "ASC"), $arFilter, false, false, array(), $arListParams); while ($arComments = $dbComments->GetNext()) { __SLMGetLogCommentRecord($arComments, $arParams, false, false, $arTmpComments, false); } $arResult["arComments"] = $arTmpComments; } } elseif ($action == "change_favorites") { $log_id = $_REQUEST["log_id"]; if ($arLog = CSocNetLog::GetByID($log_id)) { if ($strRes = CSocNetLogFavorites::Change($GLOBALS["USER"]->GetID(), $log_id)) { $arResult["bResult"] = $strRes; if ($strRes == "Y") { CSocNetLogFollow::Set($GLOBALS["USER"]->GetID(), "L" . $log_id, "Y"); } } else { if ($e = $GLOBALS["APPLICATION"]->GetException()) { $arResult["strMessage"] = $e->GetString(); } else {