104 global $USER, $USER_FIELD_MANAGER;
108 $logId = (int)($params[
'logId'] ?? 0);
109 $currentUserId = (int)($params[
'currentUserId'] ?? $USER->getId());
110 $crm = (isset($params[
'crm']) && $params[
'crm'] ===
'Y' ?
'Y' :
'N');
111 $languageId = (string)($params[
'languageId'] ?? LANGUAGE_ID);
112 $siteId = (string)($params[
'siteId'] ?? SITE_ID);
113 $commentParams = (isset($params[
'commentParams']) && is_array($params[
'commentParams']) ? $params[
'commentParams'] : []);
114 $message = (string)($params[
'message'] ??
'');
115 $forumId = (int)($params[
'forumId'] ?? 0);
116 $commentUid = (string)($params[
'commentUid'] ??
'');
117 $dateTimeFormat = (string)($params[
'dateTimeFormat'] ?? \CSite::getTimeFormat());
118 $nameTemplate = (string)($params[
'nameTemplate'] ?? \CSite::getNameFormat(
null, $siteId));
119 $showLogin = (string)($params[
'showLogin'] ??
'N');
120 $avatarSize = (int)($params[
'avatarSize'] ?? 100);
121 $pull = (string)($params[
'pull'] ??
'N');
122 $decode = (bool)($params[
'decode'] ??
false);
124 $pathToSmile = (string)($params[
'pathToSmile'] ??
'');
125 $pathToLogEntry = (string)($params[
'pathToLogEntry'] ??
'');
126 $pathToUser = (string)($params[
'pathToUser'] ??
'');
127 $pathToUserBlogPost = (string)($params[
'pathToUserBlogPost'] ??
'');
128 $pathToGroupBlogPost = (string)($params[
'pathToGroupBlogPost'] ??
'');
129 $pathToUserMicroBlogPost = (string)($params[
'pathToUserMicroBlogPost'] ??
'');
130 $pathToGroupMicroBlogPost = (string)($params[
'pathToGroupMicroBlogPost'] ??
'');
131 $blogAllowPostCode = (string)($params[
'blogAllowPostCode'] ??
'N');
138 if (!isset($params[
'currentUserExternalAuthId']))
140 $currentUserExternalAuthId =
'';
142 if ($USER->isAuthorized())
144 $res = \CUser::getById($currentUserId);
145 if ($userFields = $res->fetch())
147 $currentUserExternalAuthId = $userFields[
'EXTERNAL_AUTH_ID'];
153 $currentUserExternalAuthId =
'';
156 if ($logFields = \CSocNetLog::getById($logId))
159 'CHECK_RIGHTS' =>
'Y',
160 'USE_SUBSCRIBE' =>
'N'
164 $currentUserExternalAuthId !==
'email'
165 && mb_strpos($logFields[
'ENTITY_TYPE'],
'CRM') === 0
167 !in_array($logFields[
'EVENT_ID'], [
'crm_lead_message',
'crm_deal_message',
'crm_company_message',
'crm_contact_message',
'crm_activity_add' ])
170 && ModuleManager::isModuleInstalled(
'crm')
175 'CHECK_CRM_RIGHTS' =>
'Y'
186 || !($res = \CSocNetLog::GetList(array(), array(
"ID" => $logId),
false,
false, array(), $listParams))
187 || !($logFields = $res->fetch())
190 $result[
'strMessage'] =
Loc::getMessage(
'SONET_LOG_COMMENT_NO_PERMISSIONS',
false, $languageId);
194 $commentEvent = \CSocNetLogTools::FindLogCommentEventByLogEventID($logFields[
'EVENT_ID']);
202 if (!$canAddComments)
204 $result[
'strMessage'] =
Loc::getMessage(
'SONET_LOG_COMMENT_NO_PERMISSIONS',
false, $languageId);
208 $editCommentSourceId = (
209 isset($commentParams[1]) && (int)$commentParams[1] > 0
210 ? (
int)$commentParams[1]
216 'PATH_TO_SMILE' => $pathToSmile,
217 'PATH_TO_LOG_ENTRY' => $pathToLogEntry,
218 'PATH_TO_USER_BLOG_POST' => $pathToUserBlogPost,
219 'PATH_TO_GROUP_BLOG_POST' => $pathToGroupBlogPost,
220 'PATH_TO_USER_MICROBLOG_POST' => $pathToUserMicroBlogPost,
221 'PATH_TO_GROUP_MICROBLOG_POST' => $pathToGroupMicroBlogPost,
222 'BLOG_ALLOW_POST_CODE' => $blogAllowPostCode,
225 $commentText = preg_replace(
"/\xe2\x81\xa0/is",
' ', $message);
228 \CUtil::decodeURIComponent($commentText);
230 $commentText = trim($commentText);
232 if ($commentText ===
'')
234 $result[
'strMessage'] =
Loc::getMessage(
'SONET_LOG_COMMENT_EMPTY',
false, $languageId);
240 if ($commentEvent[
'EVENT_ID'] ===
'forum')
242 $searchParams[
'FORUM_ID'] = $forumId;
243 $searchParams[
'PATH_TO_GROUP_FORUM_MESSAGE'] = (
244 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_GROUP
245 ? static::replaceGroupPath($logFields[
'URL'], $siteId)
248 $searchParams[
'PATH_TO_USER_FORUM_MESSAGE'] = (
249 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER
254 elseif ($commentEvent[
'EVENT_ID'] ===
'files_comment')
258 if ((
string)$logFields[
'PARAMS'] !==
'')
260 $logParams = explode(
'&', htmlspecialcharsback($logFields[
"PARAMS"]));
261 foreach ($logParams as $prm)
263 [ $k, $v ] = explode(
'=', $prm);
264 if ($k ===
'forum_id')
266 $filesForumId = (int)$v;
272 $searchParams[
'FILES_FORUM_ID'] = $filesForumId;
273 $searchParams[
'PATH_TO_GROUP_FILES_ELEMENT'] = (
274 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_GROUP
275 ? static::replaceGroupPath($logFields[
'URL'], $siteId)
278 $searchParams[
'PATH_TO_USER_FILES_ELEMENT'] = (
279 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER
284 elseif ($commentEvent[
'EVENT_ID'] ===
'photo_comment')
288 if ((
string)$logFields[
'PARAMS'] !==
'')
290 $logParams = unserialize(htmlspecialcharsback($logFields[
'PARAMS']), [
'allowed_classes' =>
false ]);
292 isset($logParams[
'FORUM_ID'])
293 && (
int)$logParams[
'FORUM_ID'] > 0
296 $photoForumId = $logParams[
"FORUM_ID"];
299 $searchParams[
'PHOTO_FORUM_ID'] = $photoForumId;
300 $searchParams[
'PATH_TO_GROUP_PHOTO_ELEMENT'] = (
301 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_GROUP
302 ? static::replaceGroupPath($logFields[
'URL'], $siteId)
305 $searchParams[
'PATH_TO_USER_PHOTO_ELEMENT'] = (
306 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER
311 elseif ($commentEvent[
'EVENT_ID'] ===
'wiki_comment')
313 $searchParams[
'PATH_TO_GROUP_WIKI_POST_COMMENT'] = (
314 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_GROUP
315 ? Option::get(
'socialnetwork',
'workgroups_page',
'', $siteId) .
'group/#group_id#/wiki/#wiki_name#/?MID=#message_id##message#message_id#'
319 elseif ($commentEvent[
"EVENT_ID"] ===
'tasks_comment')
321 if (Loader::includeModule(
'tasks'))
327 $tasksForumId = \CTasksTools::getForumIdForIntranet();
329 catch (\Exception $e)
333 if ($tasksForumId > 0)
335 $searchParams[
'TASK_FORUM_ID'] = $tasksForumId;
336 $searchParams[
'PATH_TO_GROUP_TASK_ELEMENT'] = (
337 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_GROUP
338 ? Option::get(
'socialnetwork',
'workgroups_page',
'', $siteId) .
'group/#group_id#/tasks/task/view/#task_id#/'
341 $searchParams[
'PATH_TO_USER_TASK_ELEMENT'] = (
342 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER
343 ? Option::get(
'socialnetwork',
'user_page',
'', $siteId) .
'user/#user_id#/tasks/task/view/#task_id#/'
349 elseif ($commentEvent[
'EVENT_ID'] ===
'calendar_comment')
351 $searchParams[
'PATH_TO_GROUP_CALENDAR_ELEMENT'] = (
352 $logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_GROUP
353 ? Option::get(
'socialnetwork',
'workgroups_page',
'', $siteId) .
'group/#group_id#/calendar/?EVENT_ID=#element_id#'
357 elseif ($commentEvent[
'EVENT_ID'] ===
'lists_new_element_comment')
359 $searchParams[
'PATH_TO_WORKFLOW'] =
'/services/processes/#list_id#/bp_log/#workflow_id#/';
362 global $bxSocNetSearch;
365 !empty($searchParams)
366 && !is_object($bxSocNetSearch)
369 $bxSocNetSearch = new \CSocNetSearch(
370 ($logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER ? $logFields[
'ENTITY_ID'] :
false),
371 ($logFields[
'ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_GROUP ? $logFields[
'ENTITY_ID'] :
false),
374 AddEventHandler(
'search',
'BeforeIndex', [ $bxSocNetSearch,
'BeforeIndex' ]);
377 if ($editCommentSourceId > 0)
380 'EVENT_ID' => $commentEvent[
'EVENT_ID'],
381 'MESSAGE' => $commentText,
382 'TEXT_MESSAGE' => $commentText,
383 'BLOG_ALLOW_POST_CODE' => $options[
'BLOG_ALLOW_POST_CODE']
389 'ENTITY_TYPE' => $logFields[
'ENTITY_TYPE'],
390 'ENTITY_ID' => $logFields[
'ENTITY_ID'],
391 'EVENT_ID' => $commentEvent[
'EVENT_ID'],
392 '=LOG_DATE' => \CDatabase::currentTimeFunction(),
393 'MESSAGE' => $commentText,
394 'TEXT_MESSAGE' => $commentText,
395 'MODULE_ID' =>
false,
396 'LOG_ID' => $logFields[
'ID'],
397 'USER_ID' => $currentUserId,
398 'PATH_TO_USER_BLOG_POST' => $options[
'PATH_TO_USER_BLOG_POST'],
399 'PATH_TO_GROUP_BLOG_POST' => $options[
'PATH_TO_GROUP_BLOG_POST'],
400 'PATH_TO_USER_MICROBLOG_POST' => $options[
'PATH_TO_USER_MICROBLOG_POST'],
401 'PATH_TO_GROUP_MICROBLOG_POST' => $options[
'PATH_TO_GROUP_MICROBLOG_POST'],
402 'BLOG_ALLOW_POST_CODE' => $options[
'BLOG_ALLOW_POST_CODE']
406 $USER_FIELD_MANAGER->EditFormAddFields(
'SONET_COMMENT', $fields);
409 array_key_exists(
'UF_SONET_COM_FILE', $fields)
410 && !empty($fields[
'UF_SONET_COM_FILE'])
413 if (is_array($fields[
'UF_SONET_COM_FILE']))
415 foreach ($fields[
"UF_SONET_COM_FILE"] as $key => $fileID)
419 || !array_key_exists(
'MFI_UPLOADED_FILES_' . $commentUid, $_SESSION)
420 || !in_array($fileID, $_SESSION[
'MFI_UPLOADED_FILES_' . $commentUid],
true)
423 unset($fields[
'UF_SONET_COM_FILE'][$key]);
429 || !array_key_exists(
'MFI_UPLOADED_FILES_' . $commentUid, $_SESSION)
430 || !in_array($fields[
'UF_SONET_COM_FILE'], $_SESSION[
'MFI_UPLOADED_FILES_' . $commentUid],
true)
433 unset($fields[
'UF_SONET_COM_FILE']);
437 $inlineTagList = \Bitrix\Socialnetwork\Util::detectTags($fields, [
'MESSAGE' ]);
439 if (!empty($inlineTagList))
441 $fields[
'TAG'] = $inlineTagList;
444 $updatedCommentId = 0;
446 if ($editCommentSourceId > 0)
448 $updatedCommentLogId = 0;
449 $updatedCommentUserId = 0;
452 isset($commentEvent[
'ADD_CALLBACK'])
453 && is_callable($commentEvent[
'ADD_CALLBACK'])
456 $res = \CSocNetLogComments::getList(
459 'EVENT_ID' => $commentEvent[
'EVENT_ID'],
460 'SOURCE_ID' => $editCommentSourceId
464 [
'ID',
'USER_ID',
'LOG_ID',
'SOURCE_ID' ]
466 if ($commentFields = $res->fetch())
468 $updatedCommentId = $commentFields[
'ID'];
469 $updatedCommentLogId = $commentFields[
'LOG_ID'];
470 $updatedCommentUserId = $commentFields[
'USER_ID'];
474 if ((
int)$updatedCommentId <= 0)
476 $res = \CSocNetLogComments::getList(
479 'ID' => $editCommentSourceId,
483 [
'ID',
'USER_ID',
'LOG_ID',
'SOURCE_ID' ]
485 if ($commentFields = $res->fetch())
487 $updatedCommentId = $commentFields[
'ID'];
488 $updatedCommentLogId = $commentFields[
'LOG_ID'];
489 $updatedCommentUserId = $commentFields[
'USER_ID'];
495 if ((
int)$updatedCommentId > 0)
497 $canUpdate = \CSocNetLogComponent::canUserChangeComment(array(
499 'LOG_ID' => $updatedCommentLogId,
500 'LOG_EVENT_ID' => $logFields[
'EVENT_ID'],
501 'LOG_SOURCE_ID' => $logFields[
'SOURCE_ID'],
502 'COMMENT_ID' => $updatedCommentId,
503 'COMMENT_USER_ID' => $updatedCommentUserId
509 $commentId = \CSocNetLogComments::update($updatedCommentId, $fields,
true);
513 $result[
'strMessage'] =
Loc::getMessage(
"SONET_LOG_COMMENT_NO_PERMISSIONS_UPDATE",
false, $languageId);
514 $result[
"commentText"] = $commentText;
521 $commentId = \CSocNetLogComments::add($fields,
true,
false);
524 if ((
int)$commentId <= 0)
529 $bSkipCounterIncrement =
false;
531 if ($editCommentSourceId <= 0)
533 $res = getModuleEvents(
'socialnetwork',
'OnAfterSocNetLogEntryCommentAdd');
534 while ($event = $res->fetch())
536 ExecuteModuleEventEx($event, [
539 'SITE_ID' => $siteId,
540 'COMMENT_ID' => $commentId,
545 $res = getModuleEvents(
'socialnetwork',
'OnBeforeSocNetLogCommentCounterIncrement');
546 while ($event = $res->fetch())
548 if (ExecuteModuleEventEx($event, [ $logFields ]) ===
false)
550 $bSkipCounterIncrement =
true;
557 $bSkipCounterIncrement =
true;
560 if (!$bSkipCounterIncrement)
562 \CSocNetLog::counterIncrement(
567 \CSocNetLogRights::checkForUserAll($logFields[
'ID'])
571 $result[
'commentID'] = $commentId;
573 if ($commentFields = \CSocNetLogComments::getById($result[
'commentID']))
580 'ACTION' => ((
int)$updatedCommentId <= 0 ?
'ADD' :
"UPDATE"),
581 'SOURCE_ID' => $editCommentSourceId,
582 'TIME_FORMAT' => $dateTimeFormat,
583 "PATH_TO_USER" => $pathToUser,
584 'PATH_TO_LOG_ENTRY' => $pathToLogEntry,
585 'NAME_TEMPLATE' => $nameTemplate,
586 'SHOW_LOGIN' => $showLogin,
587 'AVATAR_SIZE' => $avatarSize,
588 'PATH_TO_SMILE' => $pathToSmile,
589 'LANGUAGE_ID' => $languageId,
590 'SITE_ID' => $siteId,
595 $result = array_merge($result, $res);
669 public static function getCommentsFullList(array $eventData, array &$params, array $options = [], array &$arResult = [])
671 global $CACHE_MANAGER;
673 $nTopCount = (isset($options[
'nTopCount']) && (int)$options[
'nTopCount'] > 0 ? (
int)$options[
'nTopCount'] : 20);
674 $timeZoneOffzet = (isset($options[
'timeZoneOffzet']) && (int)$options[
'timeZoneOffzet'] > 0 ? (
int)$options[
'timeZoneOffzet'] : 0);
675 $commentEvent = (isset($options[
'commentEvent']) && is_array($options[
'commentEvent']) ? $options[
'commentEvent'] : []);
676 $commentProvider = ($options[
'commentProvider'] ??
false);
678 $cacheTime = 31536000;
681 $useCache = ($params[
'COMMENT_ID'] <= 0);
685 $cache = new \CPHPCache;
688 $cacheIdPartsList = [];
690 'AVATAR_SIZE_COMMENT',
692 'NAME_TEMPLATE_WO_NOBR',
697 'PATH_TO_CONPANY_DEPARTMENT',
701 foreach ($keysList as $paramKey)
703 $cacheIdPartsList[$paramKey] = (
704 array_key_exists($paramKey, $params)
710 $navParams = \CDBResult::getNavParams($params[
'COMMENTS_IN_EVENT'] ??
null);
711 $navPage = (int)($navParams[
'PAGEN'] ?? 1);
713 $cacheId = implode(
'_', [
716 md5(serialize($cacheIdPartsList)),
726 $cachePath =
'/sonet/log/' . (int)((
int)$params[
'LOG_ID'] / 1000) .
'/' . $params[
'LOG_ID'] .
'/comments/';
732 && $cache->initCache($cacheTime, $cacheId, $cachePath)
735 $cacheVariables = $cache->getVars();
736 $result = $cacheVariables[
'COMMENTS_FULL_LIST'];
738 $navResultData = $cacheVariables[
'NAV_RESULT_DATA'];
739 $navResult = new \CDBResult;
740 $navResult->bShowAll = $navResultData[
'bShowAll'];
741 $navResult->bDescPageNumbering = $navResultData[
'bDescPageNumbering'];
742 $navResult->NavNum = $navResultData[
'NavNum'];
743 $navResult->NavRecordCount = $navResultData[
'NavRecordCount'];
744 $navResult->NavPageNomer = $navResultData[
'NavPageNomer'];
745 $navResult->NavPageSize = $navResultData[
'NavPageSize'];
747 if (!empty($cacheVariables[
'Assets']))
749 if (!empty($cacheVariables[
'Assets'][
'CSS']))
751 foreach ($cacheVariables[
'Assets'][
'CSS'] as $cssFile)
753 Asset::getInstance()->addCss($cssFile);
757 if (!empty($cacheVariables[
'Assets'][
'JS']))
759 foreach ($cacheVariables[
"Assets"][
'JS'] as $jsFile)
761 Asset::getInstance()->addJs($jsFile);
770 $cache->startDataCache($cacheTime, $cacheId, $cachePath);
773 if (defined(
'BX_COMP_MANAGED_CACHE'))
775 $CACHE_MANAGER->startTagCache($cachePath);
779 'LOG_ID' => $params[
'LOG_ID']
784 if ($params[
'COMMENT_ID'] > 0)
786 $logCommentId = $params[
'COMMENT_ID'];
789 !empty($params[
'FILTER'])
790 && !empty($params[
'FILTER'][
'<ID'])
791 && (
int)$params[
'FILTER'][
'<ID'] > 0
794 $logCommentId = (int)$params[
'FILTER'][
'<ID'];
798 !empty($commentEvent)
799 && !empty($commentEvent[
'RATING_TYPE_ID'])
803 $res = \CSocNetLogComments::getList(
806 'RATING_TYPE_ID' => $commentEvent[
'RATING_TYPE_ID'],
807 'RATING_ENTITY_ID' => $logCommentId,
814 if ($logCommentFields = $res->fetch())
816 $logCommentId = (int)$logCommentFields[
'ID'];
820 if ($logCommentId > 0)
822 if ($params[
'COMMENT_ID'] > 0)
824 $filter[
'>=ID'] = $logCommentId;
827 !empty($params[
'FILTER'])
828 && !empty($params[
'FILTER'][
'<ID'])
829 && (
int)$params[
'FILTER'][
'<ID'] > 0
832 $filter[
'<ID'] = $logCommentId;
837 'ID',
'LOG_ID',
'SOURCE_ID',
'ENTITY_TYPE',
'ENTITY_ID',
'USER_ID',
'EVENT_ID',
'LOG_DATE',
'MESSAGE',
'LOG_DATE_TS',
'TEXT_MESSAGE',
'URL',
'MODULE_ID',
838 'GROUP_NAME',
'GROUP_OWNER_ID',
'GROUP_VISIBLE',
'GROUP_OPENED',
'GROUP_IMAGE_ID',
839 'USER_NAME',
'USER_LAST_NAME',
'USER_SECOND_NAME',
'USER_LOGIN',
'USER_PERSONAL_PHOTO',
'USER_PERSONAL_GENDER',
840 'CREATED_BY_NAME',
'CREATED_BY_LAST_NAME',
'CREATED_BY_SECOND_NAME',
'CREATED_BY_LOGIN',
'CREATED_BY_PERSONAL_PHOTO',
'CREATED_BY_PERSONAL_GENDER',
'CREATED_BY_EXTERNAL_AUTH_ID',
842 'LOG_SITE_ID',
'LOG_SOURCE_ID',
843 'RATING_TYPE_ID',
'RATING_ENTITY_ID',
848 'USE_SUBSCRIBE' =>
'N',
849 'CHECK_RIGHTS' =>
'N'
854 if ($params[
'COMMENT_ID'] > 0)
858 elseif ($navPage > 1)
861 'iNumPage' => $navPage,
862 'nPageSize' => $params[
'COMMENTS_IN_EVENT'],
868 'nTopCount' => $nTopCount,
877 $res = \CSocNetLogComments::getList(
878 [
'LOG_DATE' =>
'DESC',
'ID' =>
'DESC' ],
886 $navResultData =
null;
887 if ($res->NavNum !==
null)
890 'bShowAll' => $res->bShowAll,
891 'bDescPageNumbering' => $res->bDescPageNumbering,
892 'NavNum' => $res->NavNum,
893 'NavRecordCount' => $res->NavRecordCount,
894 'NavPageNomer' => $res->NavPageNomer,
895 'NavPageSize' => $res->NavPageSize,
900 !empty($eventData[
'EVENT_FORMATTED'])
901 && !empty($eventData[
'EVENT_FORMATTED'][
'DESTINATION'])
902 && is_array($eventData[
'EVENT_FORMATTED'][
'DESTINATION'])
905 foreach ($eventData[
'EVENT_FORMATTED'][
'DESTINATION'] as $destination)
907 if (!empty($destination[
'CRM_USER_ID']))
909 $params[
'ENTRY_HAS_CRM_USER'] =
true;
915 $commentsList = $commentSourceIdList = [];
916 while ($commentFields = $res->getNext())
918 if (!empty($commentFields[
'SHARE_DEST']))
920 $commentFields[
'SHARE_DEST'] = htmlspecialcharsback($commentFields[
'SHARE_DEST']);
923 if (defined(
'BX_COMP_MANAGED_CACHE'))
925 $CACHE_MANAGER->registerTag(
'USER_NAME_'.(
int)$commentFields[
'USER_ID']);
928 $commentFields[
'UF'] = $usetFieldsMetaData;
929 foreach ($usetFieldsMetaData as $fieldName => $userFieldData)
931 if (array_key_exists($fieldName, $commentFields))
933 $commentFields[
'UF'][$fieldName][
'VALUE'] = $commentFields[$fieldName];
934 $commentFields[
'UF'][$fieldName][
'ENTITY_VALUE_ID'] = $commentFields[
'ID'];
935 if (method_exists(
$GLOBALS[
'USER_FIELD_MANAGER'],
'getCustomData'))
937 $commentFields[
'UF'][$fieldName][
'CUSTOM_DATA'] =
$GLOBALS[
'USER_FIELD_MANAGER']->getCustomData(
938 $commentFields[
'UF'][$fieldName],
939 (
int)$commentFields[
'ID']
945 $commentsList[] = $commentFields;
946 if ((
int)$commentFields[
'SOURCE_ID'] > 0)
948 $commentSourceIdList[] = (int)$commentFields[
'SOURCE_ID'];
953 !empty($commentSourceIdList)
954 && !empty($commentProvider)
957 $sourceAdditonalData = $commentProvider->getAdditionalData([
958 'id' => $commentSourceIdList
961 if (!empty($sourceAdditonalData))
963 foreach ($commentsList as $key => $comment)
966 !empty($comment[
'SOURCE_ID'])
967 && isset($sourceAdditonalData[$comment[
'SOURCE_ID']])
970 $commentsList[$key][
'ADDITIONAL_DATA'] = $sourceAdditonalData[$comment[
'SOURCE_ID']];
976 foreach ($commentsList as $commentFields)
982 $params[
'COMMENT_ID'] <= 0
983 && $navResultData ===
null
986 $navResult = \CSocNetLogComments::getList(
991 'nPageSize' => $params[
'COMMENTS_IN_EVENT'],
999 'bShowAll' => $navResult->bShowAll,
1000 'bDescPageNumbering' => $navResult->bDescPageNumbering,
1001 'NavNum' => $navResult->NavNum,
1002 'NavRecordCount' => $navResult->NavRecordCount,
1003 'NavPageNomer' => $navResult->NavPageNomer,
1004 'NavPageSize' => $navResult->NavPageSize,
1011 'COMMENTS_FULL_LIST' => $result,
1012 'NAV_RESULT_DATA' => $navResultData,
1015 $cache->endDataCache($cacheData);
1016 if (defined(
'BX_COMP_MANAGED_CACHE'))
1018 $CACHE_MANAGER->endTagCache();
1023 $arResult[
'NAV_RESULT'] = $navResult ??
null;
1030 global $APPLICATION, $arExtranetUserID;
1032 $extranetUserIdList = $arExtranetUserID;
1034 static $userCache = array();
1037 $timestamp = makeTimeStamp(array_key_exists(
'LOG_DATE_FORMAT', $comment)
1038 ? $comment[
'LOG_DATE_FORMAT']
1039 : $comment[
'LOG_DATE']
1042 $timeFormated = formatDateFromDB($comment[
'LOG_DATE'],
1044 mb_stripos($params[
'DATE_TIME_FORMAT'],
'a')
1046 $params[
'DATE_TIME_FORMAT'] ===
'FULL'
1049 ? (mb_strpos(FORMAT_DATETIME,
'TT') !==
false ?
'G:MI TT' :
'G:MI T')
1054 $dateTimeFormated = formatDate(
1055 (!empty($params[
'DATE_TIME_FORMAT'])
1056 ? ($params[
'DATE_TIME_FORMAT'] ===
'FULL'
1057 ? \CDatabase::dateFormatToPHP(str_replace(
':SS',
'', FORMAT_DATETIME))
1058 : $params[
'DATE_TIME_FORMAT']
1060 : \CDatabase::dateFormatToPHP(FORMAT_DATETIME)
1066 strcasecmp(LANGUAGE_ID,
'EN') !== 0
1067 && strcasecmp(LANGUAGE_ID,
'DE') !== 0
1070 $dateTimeFormated = toLower($dateTimeFormated);
1075 !empty($params[
'DATE_TIME_FORMAT'])
1077 $params[
'DATE_TIME_FORMAT'] ===
'j F Y G:i'
1078 || $params[
'DATE_TIME_FORMAT'] ===
'j F Y g:i a'
1082 $dateTimeFormated = ltrim($dateTimeFormated,
'0');
1083 $currentYear = date(
'Y');
1084 $dateTimeFormated = str_replace(array(
'-'.$currentYear,
'/'.$currentYear,
' '.$currentYear,
'.'.$currentYear),
'', $dateTimeFormated);
1088 $comment[
'ENTITY_TYPE'] === SONET_ENTITY_GROUP
1089 ? \CComponentEngine::MakePathFromTemplate($params[
'PATH_TO_GROUP'], [
'group_id' => $comment[
'ENTITY_ID'] ])
1090 : \CComponentEngine::MakePathFromTemplate($params[
'PATH_TO_USER'], [
'user_id' => $comment[
'ENTITY_ID'] ])
1093 if ((
int)$comment[
'USER_ID'] > 0)
1096 is_array($extranetUserIdList)
1097 && in_array($comment[
'USER_ID'], $extranetUserIdList)
1103 'NAME' => $comment[
'~CREATED_BY_NAME'],
1104 'LAST_NAME' => $comment[
'~CREATED_BY_LAST_NAME'],
1105 'SECOND_NAME' => $comment[
'~CREATED_BY_SECOND_NAME'],
1106 'LOGIN' => $comment[
'~CREATED_BY_LOGIN']
1108 $useLogin = ($params[
"SHOW_LOGIN"] !==
"N");
1109 $createdByFields = [
1110 'FORMATTED' => \CUser::formatName($params[
'NAME_TEMPLATE'], $userFields, $useLogin).$suffix,
1111 'URL' => \CComponentEngine::makePathFromTemplate($params[
'PATH_TO_USER'], [
1112 'user_id' => $comment[
'USER_ID'],
1113 'id' => $comment[
'USER_ID']
1117 $createdByFields[
'TOOLTIP_FIELDS'] = [
1118 'ID' => $comment[
'USER_ID'],
1119 'NAME' => $comment[
'~CREATED_BY_NAME'],
1120 'LAST_NAME' => $comment[
'~CREATED_BY_LAST_NAME'],
1121 'SECOND_NAME' => $comment[
'~CREATED_BY_SECOND_NAME'],
1122 'LOGIN' => $comment[
'~CREATED_BY_LOGIN'],
1123 'PERSONAL_GENDER' => $comment[
'~CREATED_BY_PERSONAL_GENDER'],
1124 'USE_THUMBNAIL_LIST' =>
'N',
1125 'PATH_TO_SONET_MESSAGES_CHAT' => $params[
'PATH_TO_MESSAGES_CHAT'] ??
null,
1126 'PATH_TO_SONET_USER_PROFILE' => $params[
'PATH_TO_USER'] ??
null,
1127 'PATH_TO_VIDEO_CALL' => $params[
'PATH_TO_VIDEO_CALL'] ??
null,
1128 'DATE_TIME_FORMAT' => $params[
'DATE_TIME_FORMAT'],
1129 'SHOW_YEAR' => $params[
'SHOW_YEAR'],
1130 'CACHE_TYPE' => $params[
'CACHE_TYPE'] ??
null,
1131 'CACHE_TIME' => $params[
'CACHE_TIME'] ??
null,
1132 'NAME_TEMPLATE' => $params[
'NAME_TEMPLATE'].$suffix,
1133 'SHOW_LOGIN' => $params[
'SHOW_LOGIN'],
1134 'PATH_TO_CONPANY_DEPARTMENT' => $params[
'PATH_TO_CONPANY_DEPARTMENT'] ??
null,
1136 'EXTERNAL_AUTH_ID' => $comment[
'~CREATED_BY_EXTERNAL_AUTH_ID']
1139 isset($params[
'ENTRY_HAS_CRM_USER'])
1140 && $params[
'ENTRY_HAS_CRM_USER']
1141 && ModuleManager::isModuleInstalled(
'crm')
1144 if (isset($userCache[$comment[
'USER_ID']]))
1146 $userFields = $userCache[$comment[
'USER_ID']];
1150 $res = UserTable::getList([
1152 'ID' => (
int)$comment[
'USER_ID']
1154 'select' => [
'ID',
'UF_USER_CRM_ENTITY' ]
1156 if ($userFields = $res->fetch())
1158 $userCache[$userFields[
'ID']] = $userFields;
1162 if (!empty($userFields))
1164 $createdByFields[
'TOOLTIP_FIELDS'] = array_merge($createdByFields[
'TOOLTIP_FIELDS'], $userFields);
1170 $createdByFields = [
1176 'NAME' => $comment[
'~USER_NAME'],
1177 'LAST_NAME' => $comment[
'~USER_LAST_NAME'],
1178 'SECOND_NAME' => $comment[
'~USER_SECOND_NAME'],
1179 'LOGIN' => $comment[
'~USER_LOGIN']
1182 $temporaryParams = $params;
1183 $temporaryParams[
'AVATAR_SIZE'] = ($params[
'AVATAR_SIZE_COMMON'] ?? $params[
'AVATAR_SIZE']);
1185 $commentEventFields = [
1186 'EVENT' => $comment,
1187 'LOG_DATE' => $comment[
'LOG_DATE'],
1188 'LOG_DATE_TS' => makeTimeStamp($comment[
'LOG_DATE']),
1189 'LOG_DATE_DAY' => convertTimeStamp(makeTimeStamp($comment[
'LOG_DATE']),
'SHORT'),
1190 'LOG_TIME_FORMAT' => $timeFormated,
1191 'LOG_DATETIME_FORMAT' => $dateTimeFormated,
1192 'TITLE_TEMPLATE' =>
'',
1194 'TITLE_FORMAT' =>
'',
1196 $comment[
"ENTITY_TYPE"] === SONET_ENTITY_GROUP
1197 ? $comment[
"GROUP_NAME"]
1198 : \CUser::formatName($params[
'NAME_TEMPLATE'], $userFields, $useLogin)
1200 'ENTITY_PATH' => $path2Entity,
1201 'CREATED_BY' => $createdByFields,
1202 'AVATAR_SRC' => \CSocNetLogTools::formatEvent_CreateAvatar($comment, $temporaryParams)
1205 $commentEventData = \CSocNetLogTools::findLogCommentEventByID($comment[
'EVENT_ID']);
1206 $formattedFields = [];
1209 is_array($commentEventData)
1210 && array_key_exists(
'CLASS_FORMAT', $commentEventData)
1211 && array_key_exists(
'METHOD_FORMAT', $commentEventData)
1215 ($params[
'USER_COMMENTS'] ??
'') ===
"Y"
1218 'TITLE' => $comment[
'~LOG_TITLE'] ??
'',
1219 'URL' => $comment[
'~LOG_URL'] ??
'',
1220 'PARAMS' => $comment[
'~LOG_PARAMS'] ?? null
1224 $formattedFields = call_user_func([ $commentEventData[
'CLASS_FORMAT'], $commentEventData[
'METHOD_FORMAT'] ], $comment, $params,
false, $logFields);
1227 ($params[
'USE_COMMENTS'] ??
null) !==
'Y'
1228 && array_key_exists(
'CREATED_BY', $formattedFields)
1229 && isset($formattedFields[
'CREATED_BY'][
'TOOLTIP_FIELDS']))
1231 $commentEventFields[
'CREATED_BY'][
'TOOLTIP_FIELDS'] = $formattedFields[
'CREATED_BY'][
'TOOLTIP_FIELDS'];
1235 $commentAuxProvider = \Bitrix\Socialnetwork\CommentAux\Base::findProvider(
1237 'POST_TEXT' => $comment[
'MESSAGE'],
1238 'SHARE_DEST' => $comment[
'SHARE_DEST'],
1239 'SOURCE_ID' => (
int)$comment[
'SOURCE_ID'],
1240 'EVENT_ID' => $comment[
'EVENT_ID'],
1241 'RATING_TYPE_ID' => $comment[
'RATING_TYPE_ID'],
1244 'eventId' => $comment[
'EVENT_ID']
1248 if ($commentAuxProvider)
1250 $commentAuxProvider->setOptions([
1251 'suffix' => (!empty($params[
'COMMENT_ENTITY_SUFFIX']) ? $params[
'COMMENT_ENTITY_SUFFIX'] :
''),
1252 'logId' => $comment[
'LOG_ID'],
1254 'parseBBCode' =>
true,
1255 'uf' => $comment[
'UF'],
1258 $formattedFields[
"EVENT_FORMATTED"][
"FULL_MESSAGE_CUT"] = nl2br($commentAuxProvider->getText());
1262 $message = (string)(
1263 is_array($formattedFields)
1264 && array_key_exists(
'EVENT_FORMATTED', $formattedFields)
1265 && array_key_exists(
'MESSAGE', $formattedFields[
'EVENT_FORMATTED'])
1266 ? $formattedFields[
'EVENT_FORMATTED'][
'MESSAGE']
1267 : $commentEventFields[
'EVENT'][
'MESSAGE']
1270 if ($message !==
'')
1272 $formattedFields[
'EVENT_FORMATTED'][
'FULL_MESSAGE_CUT'] = \CSocNetTextParser::closetags(htmlspecialcharsback($message));
1276 $formattedFields[
'EVENT_FORMATTED'][
'DATETIME'] = (
1277 $commentEventFields[
'LOG_DATE_DAY'] == convertTimeStamp()
1281 $commentEventFields[
'EVENT_FORMATTED'] = $formattedFields[
'EVENT_FORMATTED'];
1282 $commentEventFields[
'EVENT_FORMATTED'][
'URLPREVIEW'] =
false;
1285 isset($comment[
'UF'][
'UF_SONET_COM_URL_PRV'])
1286 && !empty($comment[
'UF'][
'UF_SONET_COM_URL_PRV'][
'VALUE'])
1289 $css = $APPLICATION->sPath2css;
1290 $js = $APPLICATION->arHeadScripts;
1294 'NAME_TEMPLATE' => $params[
'NAME_TEMPLATE'],
1295 'PATH_TO_USER' => $params[
'~PATH_TO_USER']
1298 if (!empty($urlPreviewText))
1300 $commentEventFields[
'EVENT_FORMATTED'][
'URLPREVIEW'] =
true;
1301 $commentEventFields[
'EVENT_FORMATTED'][
'FULL_MESSAGE_CUT'] .= $urlPreviewText;
1304 $assets[
'CSS'] = array_merge($assets[
'CSS'], array_diff($APPLICATION->sPath2css, $css));
1305 $assets[
'JS'] = array_merge($assets[
'JS'], array_diff($APPLICATION->arHeadScripts, $js));
1307 $commentEventFields[
'UF_HIDDEN'][
'UF_SONET_COM_URL_PRV'] = $comment[
'UF'][
'UF_SONET_COM_URL_PRV'];
1308 unset($comment[
'UF'][
'UF_SONET_COM_URL_PRV']);
1311 $commentEventFields[
'UF'] = $comment[
'UF'];
1314 isset($commentEventFields[
'EVENT_FORMATTED'])
1315 && is_array($commentEventFields[
'EVENT_FORMATTED'])
1325 foreach ($commentEventFields[
'EVENT_FORMATTED'] as $field => $value)
1327 if (!in_array($field, $fields2Cache,
true))
1329 unset($commentEventFields[
'EVENT_FORMATTED'][$field]);
1335 isset($commentEventFields[
'EVENT'])
1336 && is_array($commentEventFields[
'EVENT'])
1339 if (!empty($commentEventFields[
"EVENT"][
"URL"]))
1341 $commentEventFields[
'EVENT'][
'URL'] = str_replace(
1343 Option::get(
'socialnetwork',
'workgroups_page',
'/workgroups/', SITE_ID),
1344 $commentEventFields[
'EVENT'][
'URL']
1362 isset($params[
'MAIL'])
1363 && $params[
'MAIL'] ===
'Y'
1366 isset($params[
'COMMENT_ID'])
1367 && (
int)$params[
'COMMENT_ID'] > 0
1371 $fields2Cache[] =
'MESSAGE';
1374 foreach ($commentEventFields[
'EVENT'] as $field => $value)
1376 if (!in_array($field, $fields2Cache,
true))
1378 unset($commentEventFields[
'EVENT'][$field]);
1384 isset($commentEventFields[
'CREATED_BY'])
1385 && is_array($commentEventFields[
'CREATED_BY'])
1393 foreach ($commentEventFields[
'CREATED_BY'] as $field => $value)
1395 if (!in_array($field, $fields2Cache,
true))
1397 unset($commentEventFields[
'CREATED_BY'][$field]);
1402 isset($commentEventFields[
'CREATED_BY'][
'TOOLTIP_FIELDS'])
1403 && is_array($commentEventFields[
'CREATED_BY'][
'TOOLTIP_FIELDS'])
1408 'PATH_TO_SONET_USER_PROFILE',
1416 'UF_USER_CRM_ENTITY',
1419 foreach ($commentEventFields[
'CREATED_BY'][
'TOOLTIP_FIELDS'] as $field => $value)
1421 if (!in_array($field, $fields2Cache,
true))
1423 unset($commentEventFields[
'CREATED_BY'][
'TOOLTIP_FIELDS'][$field]);
1429 foreach ($commentEventFields[
'EVENT'] as $key => $value)
1431 if (mb_strpos($key,
'~') === 0)
1433 unset($commentEventFields[
'EVENT'][$key]);
1437 return $commentEventFields;