Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logentry.php
1<?php
2
4
14use Bitrix\Main\Page\Asset;
19
20Loc::loadMessages(__FILE__);
21
23{
24 protected const STATUS_SUCCESS = 'success';
25 protected const STATUS_DENIED = 'denied';
26 protected const STATUS_ERROR = 'error';
27
30
31 public function getErrorByCode($code)
32 {
33 return $this->errorCollection->getErrorByCode($code);
34 }
35
40 public function getErrors()
41 {
42 return $this->errorCollection->toArray();
43 }
44
45 public function configureActions(): array
46 {
47 return [];
48 }
49
50 public function onPrepareComponentParams($params = [])
51 {
52 if (
53 !isset($params['IND'])
54 || (string)$params['IND'] === ''
55 )
56 {
57 $params['IND'] = \Bitrix\Main\Security\Random::getString(8);
58 }
59
60 if (empty($params['LOG_PROPERTY']))
61 {
62 $params['LOG_PROPERTY'] = [ 'UF_SONET_LOG_FILE' ];
63 if (
64 ModuleManager::isModuleInstalled('webdav')
65 || ModuleManager::isModuleInstalled('disk'))
66 {
67 $params['LOG_PROPERTY'][] = 'UF_SONET_LOG_DOC';
68 }
69 }
70
71 if (empty($params['COMMENT_PROPERTY']))
72 {
73 $params['COMMENT_PROPERTY'] = [ 'UF_SONET_COM_FILE' ];
74 if (
75 ModuleManager::isModuleInstalled('webdav')
76 || ModuleManager::isModuleInstalled('disk')
77 )
78 {
79 $params['COMMENT_PROPERTY'][] = 'UF_SONET_COM_DOC';
80 }
81
82 $params['COMMENT_PROPERTY'][] = 'UF_SONET_COM_URL_PRV';
83 }
84
85 if (empty($params['PATH_TO_LOG_TAG']))
86 {
87 $folderUsers = Option::get('socialnetwork', 'user_page', false, SITE_ID);
88 $params['PATH_TO_LOG_TAG'] = $folderUsers . 'log/?TAG=#tag#';
89 if (SITE_TEMPLATE_ID === 'bitrix24')
90 {
91 $params['PATH_TO_LOG_TAG'] .= '&apply_filter=Y';
92 }
93 }
94
95 \CSocNetLogComponent::processDateTimeFormatParams($params);
96
97 $params['COMMENT_ID'] = (int) ($params['COMMENT_ID'] ?? 0);
98
99 return $params;
100 }
101
102 public static function addComment(array $params = []): array
103 {
104 global $USER, $USER_FIELD_MANAGER;
105
106 $result = [];
107
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);
123
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');
132
133 if ($logId <= 0)
134 {
135 return $result;
136 }
137
138 if (!isset($params['currentUserExternalAuthId']))
139 {
140 $currentUserExternalAuthId = '';
141
142 if ($USER->isAuthorized())
143 {
144 $res = \CUser::getById($currentUserId);
145 if ($userFields = $res->fetch())
146 {
147 $currentUserExternalAuthId = $userFields['EXTERNAL_AUTH_ID'];
148 }
149 }
150 }
151 else
152 {
153 $currentUserExternalAuthId = '';
154 }
155
156 if ($logFields = \CSocNetLog::getById($logId))
157 {
158 $listParams = [
159 'CHECK_RIGHTS' => 'Y',
160 'USE_SUBSCRIBE' => 'N'
161 ];
162
163 if (
164 $currentUserExternalAuthId !== 'email'
165 && mb_strpos($logFields['ENTITY_TYPE'], 'CRM') === 0
166 && (
167 !in_array($logFields['EVENT_ID'], [ 'crm_lead_message', 'crm_deal_message', 'crm_company_message', 'crm_contact_message', 'crm_activity_add' ])
168 || $crm === 'Y'
169 )
170 && ModuleManager::isModuleInstalled('crm')
171 )
172 {
173 $listParams = [
174 'IS_CRM' => 'Y',
175 'CHECK_CRM_RIGHTS' => 'Y'
176 ];
177 }
178 }
179 else
180 {
181 $logId = 0;
182 }
183
184 if (
185 $logId <= 0
186 || !($res = \CSocNetLog::GetList(array(), array("ID" => $logId), false, false, array(), $listParams))
187 || !($logFields = $res->fetch())
188 )
189 {
190 $result['strMessage'] = Loc::getMessage('SONET_LOG_COMMENT_NO_PERMISSIONS', false, $languageId);
191 return $result;
192 }
193
194 $commentEvent = \CSocNetLogTools::FindLogCommentEventByLogEventID($logFields['EVENT_ID']);
195 if (!$commentEvent)
196 {
197 return $result;
198 }
199
200 $canAddComments = ComponentHelper::canAddComment($logFields, $commentEvent);
201
202 if (!$canAddComments)
203 {
204 $result['strMessage'] = Loc::getMessage('SONET_LOG_COMMENT_NO_PERMISSIONS', false, $languageId);
205 return $result;
206 }
207
208 $editCommentSourceId = (
209 isset($commentParams[1]) && (int)$commentParams[1] > 0
210 ? (int)$commentParams[1]
211 : 0
212 );
213
214 // add source object and get source_id, $source_url
215 $options = [
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,
223 ];
224
225 $commentText = preg_replace("/\xe2\x81\xa0/is", ' ', $message); // INVISIBLE_CURSOR from editor
226 if ($decode)
227 {
228 \CUtil::decodeURIComponent($commentText);
229 }
230 $commentText = trim($commentText);
231
232 if ($commentText === '')
233 {
234 $result['strMessage'] = Loc::getMessage('SONET_LOG_COMMENT_EMPTY', false, $languageId);
235 return $result;
236 }
237
238 $searchParams = [];
239
240 if ($commentEvent['EVENT_ID'] === 'forum')
241 {
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)
246 : ''
247 );
248 $searchParams['PATH_TO_USER_FORUM_MESSAGE'] = (
249 $logFields['ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER
250 ? $logFields['URL']
251 : ''
252 );
253 }
254 elseif ($commentEvent['EVENT_ID'] === 'files_comment')
255 {
256 $filesForumId = 0;
257
258 if ((string)$logFields['PARAMS'] !== '')
259 {
260 $logParams = explode('&', htmlspecialcharsback($logFields["PARAMS"]));
261 foreach ($logParams as $prm)
262 {
263 [ $k, $v ] = explode('=', $prm);
264 if ($k === 'forum_id')
265 {
266 $filesForumId = (int)$v;
267 break;
268 }
269 }
270 }
271
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)
276 : ''
277 );
278 $searchParams['PATH_TO_USER_FILES_ELEMENT'] = (
279 $logFields['ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER
280 ? $logFields['URL']
281 : ''
282 );
283 }
284 elseif ($commentEvent['EVENT_ID'] === 'photo_comment')
285 {
286 $photoForumId = 0;
287
288 if ((string)$logFields['PARAMS'] !== '')
289 {
290 $logParams = unserialize(htmlspecialcharsback($logFields['PARAMS']), [ 'allowed_classes' => false ]);
291 if (
292 isset($logParams['FORUM_ID'])
293 && (int)$logParams['FORUM_ID'] > 0
294 )
295 {
296 $photoForumId = $logParams["FORUM_ID"];
297 }
298 }
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)
303 : ''
304 );
305 $searchParams['PATH_TO_USER_PHOTO_ELEMENT'] = (
306 $logFields['ENTITY_TYPE'] === SONET_SUBSCRIBE_ENTITY_USER
307 ? $logFields['URL']
308 : ''
309 );
310 }
311 elseif ($commentEvent['EVENT_ID'] === 'wiki_comment')
312 {
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#'
316 : ''
317 );
318 }
319 elseif ($commentEvent["EVENT_ID"] === 'tasks_comment')
320 {
321 if (Loader::includeModule('tasks'))
322 {
323 $tasksForumId = 0;
324
325 try
326 {
327 $tasksForumId = \CTasksTools::getForumIdForIntranet();
328 }
329 catch (\Exception $e)
330 {
331 }
332
333 if ($tasksForumId > 0)
334 {
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#/'
339 : ''
340 );
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#/'
344 : ""
345 );
346 }
347 }
348 }
349 elseif ($commentEvent['EVENT_ID'] === 'calendar_comment')
350 {
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#'
354 : ''
355 );
356 }
357 elseif ($commentEvent['EVENT_ID'] === 'lists_new_element_comment')
358 {
359 $searchParams['PATH_TO_WORKFLOW'] = '/services/processes/#list_id#/bp_log/#workflow_id#/';
360 }
361
362 global $bxSocNetSearch;
363
364 if (
365 !empty($searchParams)
366 && !is_object($bxSocNetSearch)
367 )
368 {
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),
372 $searchParams
373 );
374 AddEventHandler('search', 'BeforeIndex', [ $bxSocNetSearch, 'BeforeIndex' ]);
375 }
376
377 if ($editCommentSourceId > 0)
378 {
379 $fields = [
380 'EVENT_ID' => $commentEvent['EVENT_ID'],
381 'MESSAGE' => $commentText,
382 'TEXT_MESSAGE' => $commentText,
383 'BLOG_ALLOW_POST_CODE' => $options['BLOG_ALLOW_POST_CODE']
384 ];
385 }
386 else
387 {
388 $fields = [
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']
403 ];
404 }
405
406 $USER_FIELD_MANAGER->EditFormAddFields('SONET_COMMENT', $fields);
407
408 if (
409 array_key_exists('UF_SONET_COM_FILE', $fields)
410 && !empty($fields['UF_SONET_COM_FILE'])
411 )
412 {
413 if (is_array($fields['UF_SONET_COM_FILE']))
414 {
415 foreach ($fields["UF_SONET_COM_FILE"] as $key => $fileID)
416 {
417 if (
418 !$commentUid
419 || !array_key_exists('MFI_UPLOADED_FILES_' . $commentUid, $_SESSION)
420 || !in_array($fileID, $_SESSION['MFI_UPLOADED_FILES_' . $commentUid], true)
421 )
422 {
423 unset($fields['UF_SONET_COM_FILE'][$key]);
424 }
425 }
426 }
427 elseif (
428 !$commentUid
429 || !array_key_exists('MFI_UPLOADED_FILES_' . $commentUid, $_SESSION)
430 || !in_array($fields['UF_SONET_COM_FILE'], $_SESSION['MFI_UPLOADED_FILES_' . $commentUid], true)
431 )
432 {
433 unset($fields['UF_SONET_COM_FILE']);
434 }
435 }
436
437 $inlineTagList = \Bitrix\Socialnetwork\Util::detectTags($fields, [ 'MESSAGE' ]);
438
439 if (!empty($inlineTagList))
440 {
441 $fields['TAG'] = $inlineTagList;
442 }
443
444 $updatedCommentId = 0;
445
446 if ($editCommentSourceId > 0)
447 {
448 $updatedCommentLogId = 0;
449 $updatedCommentUserId = 0;
450
451 if (
452 isset($commentEvent['ADD_CALLBACK'])
453 && is_callable($commentEvent['ADD_CALLBACK'])
454 )
455 {
456 $res = \CSocNetLogComments::getList(
457 [],
458 [
459 'EVENT_ID' => $commentEvent['EVENT_ID'],
460 'SOURCE_ID' => $editCommentSourceId
461 ],
462 false,
463 false,
464 [ 'ID', 'USER_ID', 'LOG_ID', 'SOURCE_ID' ]
465 );
466 if ($commentFields = $res->fetch())
467 {
468 $updatedCommentId = $commentFields['ID'];
469 $updatedCommentLogId = $commentFields['LOG_ID'];
470 $updatedCommentUserId = $commentFields['USER_ID'];
471 }
472 }
473
474 if ((int)$updatedCommentId <= 0)
475 {
476 $res = \CSocNetLogComments::getList(
477 [],
478 [
479 'ID' => $editCommentSourceId,
480 ],
481 false,
482 false,
483 [ 'ID', 'USER_ID', 'LOG_ID', 'SOURCE_ID' ]
484 );
485 if ($commentFields = $res->fetch())
486 {
487 $updatedCommentId = $commentFields['ID'];
488 $updatedCommentLogId = $commentFields['LOG_ID'];
489 $updatedCommentUserId = $commentFields['USER_ID'];
490 }
491 }
492
493 $canUpdate = false;
494
495 if ((int)$updatedCommentId > 0)
496 {
497 $canUpdate = \CSocNetLogComponent::canUserChangeComment(array(
498 'ACTION' => 'EDIT',
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
504 ));
505 }
506
507 if ($canUpdate)
508 {
509 $commentId = \CSocNetLogComments::update($updatedCommentId, $fields, true);
510 }
511 else
512 {
513 $result['strMessage'] = Loc::getMessage("SONET_LOG_COMMENT_NO_PERMISSIONS_UPDATE", false, $languageId);
514 $result["commentText"] = $commentText;
515
516 return $result;
517 }
518 }
519 else
520 {
521 $commentId = \CSocNetLogComments::add($fields, true, false);
522 }
523
524 if ((int)$commentId <= 0)
525 {
526 return $result;
527 }
528
529 $bSkipCounterIncrement = false;
530
531 if ($editCommentSourceId <= 0)
532 {
533 $res = getModuleEvents('socialnetwork', 'OnAfterSocNetLogEntryCommentAdd');
534 while ($event = $res->fetch())
535 {
536 ExecuteModuleEventEx($event, [
537 $logFields,
538 [
539 'SITE_ID' => $siteId,
540 'COMMENT_ID' => $commentId,
541 ]
542 ]);
543 }
544
545 $res = getModuleEvents('socialnetwork', 'OnBeforeSocNetLogCommentCounterIncrement');
546 while ($event = $res->fetch())
547 {
548 if (ExecuteModuleEventEx($event, [ $logFields ]) === false)
549 {
550 $bSkipCounterIncrement = true;
551 break;
552 }
553 }
554 }
555 else
556 {
557 $bSkipCounterIncrement = true;
558 }
559
560 if (!$bSkipCounterIncrement)
561 {
562 \CSocNetLog::counterIncrement(
563 $commentId,
564 false,
565 false,
566 "LC",
567 \CSocNetLogRights::checkForUserAll($logFields['ID'])
568 );
569 }
570
571 $result['commentID'] = $commentId;
572
573 if ($commentFields = \CSocNetLogComments::getById($result['commentID']))
574 {
576 $commentFields,
577 $logFields,
578 $commentEvent,
579 [
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,
591 'PULL' => $pull,
592 ]
593 );
594
595 $result = array_merge($result, $res);
596 }
597
598 return $result;
599 }
600
601 public static function deleteComment(array $params = [])
602 {
603 global $APPLICATION;
604
605 $result = false;
606
607 $logId = (int)($params['logId'] ?? 0);
608 $commentId = (int)($params['commentId'] ?? 0);
609
610 if (
611 $logId <= 0
612 || $commentId <= 0
613 )
614 {
615 throw new ArgumentException('Wrong method parameters');
616 }
617
618 $commentFields = \CSocNetLogComponent::getCommentByRequest($commentId, $logId, 'delete');
619 if (!$commentFields)
620 {
621 throw new AccessDeniedException('Cannot get comment');
622 }
623
624 if (!\CSocNetLogComments::delete($commentFields['ID'], true))
625 {
626 if ($e = $APPLICATION->getException())
627 {
628 throw new SystemException($e->getString());
629 }
630 }
631 else
632 {
633 $result = (int)(
634 $commentFields['SOURCE_ID'] > 0
635 ? $commentFields['SOURCE_ID']
636 : $commentFields['ID']
637 );
638 }
639
640 return $result;
641 }
642
643 public static function replaceGroupPath($url = '', $siteId = SITE_ID): string
644 {
645 static $workgroupsPage = null;
646 if ($workgroupsPage === null)
647 {
648 $workgroupsPage = Option::get('socialnetwork', 'workgroups_page', false, $siteId);
649 }
650
651 return str_replace(
652 '#GROUPS_PATH#',
653 $workgroupsPage,
654 $url
655 );
656 }
657
658 public static function getUserFieldsFMetaData()
659 {
660 global $USER_FIELD_MANAGER;
661 static $arUFMeta;
662 if (!$arUFMeta)
663 {
664 $arUFMeta = $USER_FIELD_MANAGER->GetUserFields("SONET_COMMENT", 0, LANGUAGE_ID);
665 }
666 return $arUFMeta;
667 }
668
669 public static function getCommentsFullList(array $eventData, array &$params, array $options = [], array &$arResult = [])
670 {
671 global $CACHE_MANAGER;
672
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);
677
678 $cacheTime = 31536000;
679 $cache = false;
680
681 $useCache = ($params['COMMENT_ID'] <= 0);
682
683 if ($useCache)
684 {
685 $cache = new \CPHPCache;
686 }
687
688 $cacheIdPartsList = [];
689 $keysList = [
690 'AVATAR_SIZE_COMMENT',
691 'NAME_TEMPLATE',
692 'NAME_TEMPLATE_WO_NOBR',
693 'SHOW_LOGIN',
694 'DATE_TIME_FORMAT',
695 'PATH_TO_USER',
696 'PATH_TO_GROUP',
697 'PATH_TO_CONPANY_DEPARTMENT',
698 'FILTER',
699 ];
700
701 foreach ($keysList as $paramKey)
702 {
703 $cacheIdPartsList[$paramKey] = (
704 array_key_exists($paramKey, $params)
705 ? $params[$paramKey]
706 : false
707 );
708 }
709
710 $navParams = \CDBResult::getNavParams($params['COMMENTS_IN_EVENT'] ?? null);
711 $navPage = (int)($navParams['PAGEN'] ?? 1);
712
713 $cacheId = implode('_', [
714 'log_comments',
715 $params['LOG_ID'],
716 md5(serialize($cacheIdPartsList)),
717 SITE_TEMPLATE_ID,
718 SITE_ID,
719 LANGUAGE_ID,
720 FORMAT_DATETIME,
721 $timeZoneOffzet,
722 $nTopCount,
723 $navPage,
724 ]);
725
726 $cachePath = '/sonet/log/' . (int)((int)$params['LOG_ID'] / 1000) . '/' . $params['LOG_ID'] . '/comments/';
727
728 $result = [];
729
730 if (
731 $useCache
732 && $cache->initCache($cacheTime, $cacheId, $cachePath)
733 )
734 {
735 $cacheVariables = $cache->getVars();
736 $result = $cacheVariables['COMMENTS_FULL_LIST'];
737
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'];
746
747 if (!empty($cacheVariables['Assets']))
748 {
749 if (!empty($cacheVariables['Assets']['CSS']))
750 {
751 foreach ($cacheVariables['Assets']['CSS'] as $cssFile)
752 {
753 Asset::getInstance()->addCss($cssFile);
754 }
755 }
756
757 if (!empty($cacheVariables['Assets']['JS']))
758 {
759 foreach ($cacheVariables["Assets"]['JS'] as $jsFile)
760 {
761 Asset::getInstance()->addJs($jsFile);
762 }
763 }
764 }
765 }
766 else
767 {
768 if ($useCache)
769 {
770 $cache->startDataCache($cacheTime, $cacheId, $cachePath);
771 }
772
773 if (defined('BX_COMP_MANAGED_CACHE'))
774 {
775 $CACHE_MANAGER->startTagCache($cachePath);
776 }
777
778 $filter = [
779 'LOG_ID' => $params['LOG_ID']
780 ];
781
782 $logCommentId = 0;
783
784 if ($params['COMMENT_ID'] > 0)
785 {
786 $logCommentId = $params['COMMENT_ID'];
787 }
788 elseif (
789 !empty($params['FILTER'])
790 && !empty($params['FILTER']['<ID'])
791 && (int)$params['FILTER']['<ID'] > 0
792 )
793 {
794 $logCommentId = (int)$params['FILTER']['<ID'];
795 }
796
797 if (
798 !empty($commentEvent)
799 && !empty($commentEvent['RATING_TYPE_ID'])
800 && $logCommentId > 0
801 )
802 {
803 $res = \CSocNetLogComments::getList(
804 [],
805 [
806 'RATING_TYPE_ID' => $commentEvent['RATING_TYPE_ID'],
807 'RATING_ENTITY_ID' => $logCommentId,
808 ],
809 false,
810 false,
811 [ 'ID' ]
812 );
813
814 if ($logCommentFields = $res->fetch())
815 {
816 $logCommentId = (int)$logCommentFields['ID'];
817 }
818 }
819
820 if ($logCommentId > 0)
821 {
822 if ($params['COMMENT_ID'] > 0)
823 {
824 $filter['>=ID'] = $logCommentId;
825 }
826 elseif (
827 !empty($params['FILTER'])
828 && !empty($params['FILTER']['<ID'])
829 && (int)$params['FILTER']['<ID'] > 0
830 )
831 {
832 $filter['<ID'] = $logCommentId;
833 }
834 }
835
836 $select = [
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',
841 'SHARE_DEST',
842 'LOG_SITE_ID', 'LOG_SOURCE_ID',
843 'RATING_TYPE_ID', 'RATING_ENTITY_ID',
844 'UF_*'
845 ];
846
847 $listParams = [
848 'USE_SUBSCRIBE' => 'N',
849 'CHECK_RIGHTS' => 'N'
850 ];
851
852 $usetFieldsMetaData = self::getUserFieldsFMetaData();
853
854 if ($params['COMMENT_ID'] > 0)
855 {
856 $navParams = false;
857 }
858 elseif ($navPage > 1)
859 {
860 $navParams = [
861 'iNumPage' => $navPage,
862 'nPageSize' => $params['COMMENTS_IN_EVENT'],
863 ];
864 }
865 else
866 {
867 $navParams = [
868 'nTopCount' => $nTopCount,
869 ];
870 }
871
872 $assets = [
873 'CSS' => [],
874 'JS' => []
875 ];
876
877 $res = \CSocNetLogComments::getList(
878 [ 'LOG_DATE' => 'DESC', 'ID' => 'DESC' ], // revert then
879 $filter,
880 false,
881 $navParams,
882 $select,
883 $listParams
884 );
885
886 $navResultData = null;
887 if ($res->NavNum !== null)
888 {
889 $navResultData = [
890 'bShowAll' => $res->bShowAll,
891 'bDescPageNumbering' => $res->bDescPageNumbering,
892 'NavNum' => $res->NavNum,
893 'NavRecordCount' => $res->NavRecordCount,
894 'NavPageNomer' => $res->NavPageNomer,
895 'NavPageSize' => $res->NavPageSize,
896 ];
897 }
898
899 if (
900 !empty($eventData['EVENT_FORMATTED'])
901 && !empty($eventData['EVENT_FORMATTED']['DESTINATION'])
902 && is_array($eventData['EVENT_FORMATTED']['DESTINATION'])
903 )
904 {
905 foreach ($eventData['EVENT_FORMATTED']['DESTINATION'] as $destination)
906 {
907 if (!empty($destination['CRM_USER_ID']))
908 {
909 $params['ENTRY_HAS_CRM_USER'] = true;
910 break;
911 }
912 }
913 }
914
915 $commentsList = $commentSourceIdList = [];
916 while ($commentFields = $res->getNext())
917 {
918 if (!empty($commentFields['SHARE_DEST']))
919 {
920 $commentFields['SHARE_DEST'] = htmlspecialcharsback($commentFields['SHARE_DEST']);
921 }
922
923 if (defined('BX_COMP_MANAGED_CACHE'))
924 {
925 $CACHE_MANAGER->registerTag('USER_NAME_'.(int)$commentFields['USER_ID']);
926 }
927
928 $commentFields['UF'] = $usetFieldsMetaData;
929 foreach ($usetFieldsMetaData as $fieldName => $userFieldData)
930 {
931 if (array_key_exists($fieldName, $commentFields))
932 {
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'))
936 {
937 $commentFields['UF'][$fieldName]['CUSTOM_DATA'] = $GLOBALS['USER_FIELD_MANAGER']->getCustomData(
938 $commentFields['UF'][$fieldName],
939 (int)$commentFields['ID']
940 );
941 }
942
943 }
944 }
945 $commentsList[] = $commentFields;
946 if ((int)$commentFields['SOURCE_ID'] > 0)
947 {
948 $commentSourceIdList[] = (int)$commentFields['SOURCE_ID'];
949 }
950 }
951
952 if (
953 !empty($commentSourceIdList)
954 && !empty($commentProvider)
955 )
956 {
957 $sourceAdditonalData = $commentProvider->getAdditionalData([
958 'id' => $commentSourceIdList
959 ]);
960
961 if (!empty($sourceAdditonalData))
962 {
963 foreach ($commentsList as $key => $comment)
964 {
965 if (
966 !empty($comment['SOURCE_ID'])
967 && isset($sourceAdditonalData[$comment['SOURCE_ID']])
968 )
969 {
970 $commentsList[$key]['ADDITIONAL_DATA'] = $sourceAdditonalData[$comment['SOURCE_ID']];
971 }
972 }
973 }
974 }
975
976 foreach ($commentsList as $commentFields)
977 {
978 $result[] = self::getLogCommentRecord($commentFields, $params, $assets);
979 }
980
981 if (
982 $params['COMMENT_ID'] <= 0
983 && $navResultData === null
984 )
985 {
986 $navResult = \CSocNetLogComments::getList(
987 [ ],
988 $filter,
989 false,
990 [
991 'nPageSize' => $params['COMMENTS_IN_EVENT'],
992 'bShowAll' => false,
993 ],
994 [ 'ID' ],
995 $listParams
996 );
997
998 $navResultData = [
999 'bShowAll' => $navResult->bShowAll,
1000 'bDescPageNumbering' => $navResult->bDescPageNumbering,
1001 'NavNum' => $navResult->NavNum,
1002 'NavRecordCount' => $navResult->NavRecordCount,
1003 'NavPageNomer' => $navResult->NavPageNomer,
1004 'NavPageSize' => $navResult->NavPageSize,
1005 ];
1006 }
1007
1008 if ($useCache)
1009 {
1010 $cacheData = [
1011 'COMMENTS_FULL_LIST' => $result,
1012 'NAV_RESULT_DATA' => $navResultData,
1013 'Assets' => $assets
1014 ];
1015 $cache->endDataCache($cacheData);
1016 if (defined('BX_COMP_MANAGED_CACHE'))
1017 {
1018 $CACHE_MANAGER->endTagCache();
1019 }
1020 }
1021 }
1022
1023 $arResult['NAV_RESULT'] = $navResult ?? null;
1024
1025 return $result;
1026 }
1027
1028 public static function getLogCommentRecord(array $comment, array $params, array &$assets): array
1029 {
1030 global $APPLICATION, $arExtranetUserID;
1031
1032 $extranetUserIdList = $arExtranetUserID;
1033
1034 static $userCache = array();
1035
1036 // for the same post log_update - time only, if not - date and time
1037 $timestamp = makeTimeStamp(array_key_exists('LOG_DATE_FORMAT', $comment)
1038 ? $comment['LOG_DATE_FORMAT']
1039 : $comment['LOG_DATE']
1040 );
1041
1042 $timeFormated = formatDateFromDB($comment['LOG_DATE'],
1043 (
1044 mb_stripos($params['DATE_TIME_FORMAT'], 'a')
1045 || (
1046 $params['DATE_TIME_FORMAT'] === 'FULL'
1047 && isAmPmMode()
1048 ) !== false
1049 ? (mb_strpos(FORMAT_DATETIME, 'TT') !== false ? 'G:MI TT' : 'G:MI T')
1050 : 'HH:MI'
1051 )
1052 );
1053
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']
1059 )
1060 : \CDatabase::dateFormatToPHP(FORMAT_DATETIME)
1061 ),
1062 $timestamp
1063 );
1064
1065 if (
1066 strcasecmp(LANGUAGE_ID, 'EN') !== 0
1067 && strcasecmp(LANGUAGE_ID, 'DE') !== 0
1068 )
1069 {
1070 $dateTimeFormated = toLower($dateTimeFormated);
1071 }
1072
1073 // strip current year
1074 if (
1075 !empty($params['DATE_TIME_FORMAT'])
1076 && (
1077 $params['DATE_TIME_FORMAT'] === 'j F Y G:i'
1078 || $params['DATE_TIME_FORMAT'] === 'j F Y g:i a'
1079 )
1080 )
1081 {
1082 $dateTimeFormated = ltrim($dateTimeFormated, '0');
1083 $currentYear = date('Y');
1084 $dateTimeFormated = str_replace(array('-'.$currentYear, '/'.$currentYear, ' '.$currentYear, '.'.$currentYear), '', $dateTimeFormated);
1085 }
1086
1087 $path2Entity = (
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'] ])
1091 );
1092
1093 if ((int)$comment['USER_ID'] > 0)
1094 {
1095 $suffix = (
1096 is_array($extranetUserIdList)
1097 && in_array($comment['USER_ID'], $extranetUserIdList)
1098 ? Loc::getMessage('SONET_LOG_EXTRANET_SUFFIX')
1099 : ""
1100 );
1101
1102 $userFields = [
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']
1107 ];
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']
1114 ])
1115 ];
1116
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,
1135 'INLINE' => 'Y',
1136 'EXTERNAL_AUTH_ID' => $comment['~CREATED_BY_EXTERNAL_AUTH_ID']
1137 ];
1138 if (
1139 isset($params['ENTRY_HAS_CRM_USER'])
1140 && $params['ENTRY_HAS_CRM_USER']
1141 && ModuleManager::isModuleInstalled('crm')
1142 )
1143 {
1144 if (isset($userCache[$comment['USER_ID']]))
1145 {
1146 $userFields = $userCache[$comment['USER_ID']];
1147 }
1148 else
1149 {
1150 $res = UserTable::getList([
1151 'filter' => [
1152 'ID' => (int)$comment['USER_ID']
1153 ],
1154 'select' => [ 'ID', 'UF_USER_CRM_ENTITY' ]
1155 ]);
1156 if ($userFields = $res->fetch())
1157 {
1158 $userCache[$userFields['ID']] = $userFields;
1159 }
1160 }
1161
1162 if (!empty($userFields))
1163 {
1164 $createdByFields['TOOLTIP_FIELDS'] = array_merge($createdByFields['TOOLTIP_FIELDS'], $userFields);
1165 }
1166 }
1167 }
1168 else
1169 {
1170 $createdByFields = [
1171 'FORMATTED' => Loc::getMessage("SONET_C73_CREATED_BY_ANONYMOUS")
1172 ];
1173 }
1174
1175 $userFields = [
1176 'NAME' => $comment['~USER_NAME'],
1177 'LAST_NAME' => $comment['~USER_LAST_NAME'],
1178 'SECOND_NAME' => $comment['~USER_SECOND_NAME'],
1179 'LOGIN' => $comment['~USER_LOGIN']
1180 ];
1181
1182 $temporaryParams = $params;
1183 $temporaryParams['AVATAR_SIZE'] = ($params['AVATAR_SIZE_COMMON'] ?? $params['AVATAR_SIZE']);
1184
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' => '',
1193 'TITLE' => '',
1194 'TITLE_FORMAT' => '', // need to use url here
1195 'ENTITY_NAME' => (
1196 $comment["ENTITY_TYPE"] === SONET_ENTITY_GROUP
1197 ? $comment["GROUP_NAME"]
1198 : \CUser::formatName($params['NAME_TEMPLATE'], $userFields, $useLogin)
1199 ),
1200 'ENTITY_PATH' => $path2Entity,
1201 'CREATED_BY' => $createdByFields,
1202 'AVATAR_SRC' => \CSocNetLogTools::formatEvent_CreateAvatar($comment, $temporaryParams)
1203 ];
1204
1205 $commentEventData = \CSocNetLogTools::findLogCommentEventByID($comment['EVENT_ID']);
1206 $formattedFields = [];
1207
1208 if (
1209 is_array($commentEventData)
1210 && array_key_exists('CLASS_FORMAT', $commentEventData)
1211 && array_key_exists('METHOD_FORMAT', $commentEventData)
1212 )
1213 {
1214 $logFields = (
1215 ($params['USER_COMMENTS'] ?? '') === "Y"
1216 ? []
1217 : [
1218 'TITLE' => $comment['~LOG_TITLE'] ?? '',
1219 'URL' => $comment['~LOG_URL'] ?? '',
1220 'PARAMS' => $comment['~LOG_PARAMS'] ?? null
1221 ]
1222 );
1223
1224 $formattedFields = call_user_func([ $commentEventData['CLASS_FORMAT'], $commentEventData['METHOD_FORMAT'] ], $comment, $params, false, $logFields);
1225
1226 if (
1227 ($params['USE_COMMENTS'] ?? null) !== 'Y'
1228 && array_key_exists('CREATED_BY', $formattedFields)
1229 && isset($formattedFields['CREATED_BY']['TOOLTIP_FIELDS']))
1230 {
1231 $commentEventFields['CREATED_BY']['TOOLTIP_FIELDS'] = $formattedFields['CREATED_BY']['TOOLTIP_FIELDS'];
1232 }
1233 }
1234
1235 $commentAuxProvider = \Bitrix\Socialnetwork\CommentAux\Base::findProvider(
1236 [
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'],
1242 ],
1243 [
1244 'eventId' => $comment['EVENT_ID']
1245 ]
1246 );
1247
1248 if ($commentAuxProvider)
1249 {
1250 $commentAuxProvider->setOptions([
1251 'suffix' => (!empty($params['COMMENT_ENTITY_SUFFIX']) ? $params['COMMENT_ENTITY_SUFFIX'] : ''),
1252 'logId' => $comment['LOG_ID'],
1253 'cache' => true,
1254 'parseBBCode' => true,
1255 'uf' => $comment['UF'],
1256 ]);
1257
1258 $formattedFields["EVENT_FORMATTED"]["FULL_MESSAGE_CUT"] = nl2br($commentAuxProvider->getText());
1259 }
1260 else
1261 {
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']
1268 );
1269
1270 if ($message !== '')
1271 {
1272 $formattedFields['EVENT_FORMATTED']['FULL_MESSAGE_CUT'] = \CSocNetTextParser::closetags(htmlspecialcharsback($message));
1273 }
1274 }
1275
1276 $formattedFields['EVENT_FORMATTED']['DATETIME'] = (
1277 $commentEventFields['LOG_DATE_DAY'] == convertTimeStamp()
1278 ? $timeFormated
1279 : $dateTimeFormated
1280 );
1281 $commentEventFields['EVENT_FORMATTED'] = $formattedFields['EVENT_FORMATTED'];
1282 $commentEventFields['EVENT_FORMATTED']['URLPREVIEW'] = false;
1283
1284 if (
1285 isset($comment['UF']['UF_SONET_COM_URL_PRV'])
1286 && !empty($comment['UF']['UF_SONET_COM_URL_PRV']['VALUE'])
1287 )
1288 {
1289 $css = $APPLICATION->sPath2css;
1290 $js = $APPLICATION->arHeadScripts;
1291
1292 $urlPreviewText = ComponentHelper::getUrlPreviewContent($comment['UF']['UF_SONET_COM_URL_PRV'], array(
1293 'MOBILE' => 'N',
1294 'NAME_TEMPLATE' => $params['NAME_TEMPLATE'],
1295 'PATH_TO_USER' => $params['~PATH_TO_USER']
1296 ));
1297
1298 if (!empty($urlPreviewText))
1299 {
1300 $commentEventFields['EVENT_FORMATTED']['URLPREVIEW'] = true;
1301 $commentEventFields['EVENT_FORMATTED']['FULL_MESSAGE_CUT'] .= $urlPreviewText;
1302 }
1303
1304 $assets['CSS'] = array_merge($assets['CSS'], array_diff($APPLICATION->sPath2css, $css));
1305 $assets['JS'] = array_merge($assets['JS'], array_diff($APPLICATION->arHeadScripts, $js));
1306
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']);
1309 }
1310
1311 $commentEventFields['UF'] = $comment['UF'];
1312
1313 if (
1314 isset($commentEventFields['EVENT_FORMATTED'])
1315 && is_array($commentEventFields['EVENT_FORMATTED'])
1316 )
1317 {
1318 $fields2Cache = [
1319 'DATETIME',
1320 'MESSAGE',
1321 'FULL_MESSAGE_CUT',
1322 'ERROR_MSG',
1323 'URLPREVIEW',
1324 ];
1325 foreach ($commentEventFields['EVENT_FORMATTED'] as $field => $value)
1326 {
1327 if (!in_array($field, $fields2Cache, true))
1328 {
1329 unset($commentEventFields['EVENT_FORMATTED'][$field]);
1330 }
1331 }
1332 }
1333
1334 if (
1335 isset($commentEventFields['EVENT'])
1336 && is_array($commentEventFields['EVENT'])
1337 )
1338 {
1339 if (!empty($commentEventFields["EVENT"]["URL"]))
1340 {
1341 $commentEventFields['EVENT']['URL'] = str_replace(
1342 '#GROUPS_PATH#',
1343 Option::get('socialnetwork', 'workgroups_page', '/workgroups/', SITE_ID),
1344 $commentEventFields['EVENT']['URL']
1345 );
1346 }
1347
1348 $fields2Cache = [
1349 'ID',
1350 'SOURCE_ID',
1351 'EVENT_ID',
1352 'USER_ID',
1353 'LOG_DATE',
1354 'RATING_TYPE_ID',
1355 'RATING_ENTITY_ID',
1356 'URL',
1357 'SHARE_DEST'
1358 ];
1359
1360 if (
1361 (
1362 isset($params['MAIL'])
1363 && $params['MAIL'] === 'Y'
1364 )
1365 || (
1366 isset($params['COMMENT_ID'])
1367 && (int)$params['COMMENT_ID'] > 0
1368 )
1369 )
1370 {
1371 $fields2Cache[] = 'MESSAGE';
1372 }
1373
1374 foreach ($commentEventFields['EVENT'] as $field => $value)
1375 {
1376 if (!in_array($field, $fields2Cache, true))
1377 {
1378 unset($commentEventFields['EVENT'][$field]);
1379 }
1380 }
1381 }
1382
1383 if (
1384 isset($commentEventFields['CREATED_BY'])
1385 && is_array($commentEventFields['CREATED_BY'])
1386 )
1387 {
1388 $fields2Cache = [
1389 'TOOLTIP_FIELDS',
1390 'FORMATTED',
1391 'URL'
1392 ];
1393 foreach ($commentEventFields['CREATED_BY'] as $field => $value)
1394 {
1395 if (!in_array($field, $fields2Cache, true))
1396 {
1397 unset($commentEventFields['CREATED_BY'][$field]);
1398 }
1399 }
1400
1401 if (
1402 isset($commentEventFields['CREATED_BY']['TOOLTIP_FIELDS'])
1403 && is_array($commentEventFields['CREATED_BY']['TOOLTIP_FIELDS'])
1404 )
1405 {
1406 $fields2Cache = [
1407 'ID',
1408 'PATH_TO_SONET_USER_PROFILE',
1409 'NAME',
1410 'LAST_NAME',
1411 'SECOND_NAME',
1412 'PERSONAL_GENDER',
1413 'LOGIN',
1414 'EMAIL',
1415 'EXTERNAL_AUTH_ID',
1416 'UF_USER_CRM_ENTITY',
1417 'UF_DEPARTMENT'
1418 ];
1419 foreach ($commentEventFields['CREATED_BY']['TOOLTIP_FIELDS'] as $field => $value)
1420 {
1421 if (!in_array($field, $fields2Cache, true))
1422 {
1423 unset($commentEventFields['CREATED_BY']['TOOLTIP_FIELDS'][$field]);
1424 }
1425 }
1426 }
1427 }
1428
1429 foreach ($commentEventFields['EVENT'] as $key => $value)
1430 {
1431 if (mb_strpos($key, '~') === 0)
1432 {
1433 unset($commentEventFields['EVENT'][$key]);
1434 }
1435 }
1436
1437 return $commentEventFields;
1438 }
1439
1440 public static function formatStubEvent($arFields, $arParams): array
1441 {
1442 $arResult = [
1443 'HAS_COMMENTS' => 'N',
1444 'EVENT' => $arFields,
1445 'EVENT_FORMATTED' => [
1446 'TITLE' => '',
1447 'TITLE_24' => '',
1448 'URL' => '',
1449 'MESSAGE' => '',
1450 'SHORT_MESSAGE' => '',
1451 'IS_IMPORTANT' => false,
1452 'STUB' => true,
1453 ],
1454 ];
1455 $arResult['ENTITY']['FORMATTED']['NAME'] = '';
1456 $arResult['ENTITY']['FORMATTED']['URL'] = '';
1457 $arResult['AVATAR_SRC'] = \CSocNetLog::FormatEvent_CreateAvatar($arFields, $arParams, 'CREATED_BY');
1458
1459 $arFieldsTooltip = [
1460 'ID' => $arFields['USER_ID'],
1461 'NAME' => $arFields['~CREATED_BY_NAME'],
1462 'LAST_NAME' => $arFields['~CREATED_BY_LAST_NAME'],
1463 'SECOND_NAME' => $arFields['~CREATED_BY_SECOND_NAME'],
1464 'LOGIN' => $arFields['~CREATED_BY_LOGIN'],
1465 ];
1466 $arResult['CREATED_BY']['TOOLTIP_FIELDS'] = \CSocNetLog::FormatEvent_FillTooltip($arFieldsTooltip, $arParams);
1467
1468 return $arResult;
1469 }
1470
1471
1472}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
Definition logentry.php:23
const STATUS_ERROR
Definition logentry.php:26
static getLogCommentRecord(array $comment, array $params, array &$assets)
const STATUS_DENIED
Definition logentry.php:25
getErrors()
Definition logentry.php:40
$errorCollection
Definition logentry.php:29
static replaceGroupPath($url='', $siteId=SITE_ID)
Definition logentry.php:643
static getUserFieldsFMetaData()
Definition logentry.php:658
onPrepareComponentParams($params=[])
Definition logentry.php:50
static addComment(array $params=[])
Definition logentry.php:102
configureActions()
Definition logentry.php:45
static deleteComment(array $params=[])
Definition logentry.php:601
getErrorByCode($code)
Definition logentry.php:31
const STATUS_SUCCESS
Definition logentry.php:24
static getCommentsFullList(array $eventData, array &$params, array $options=[], array &$arResult=[])
Definition logentry.php:669
static formatStubEvent($arFields, $arParams)
static getUrlPreviewContent($uf, $params=array())
static addLiveComment($comment=[], $logEntry=[], $commentEvent=[], $params=[])
static canAddComment($logEntry=array(), $commentEvent=array())
$GLOBALS['____1444769544']
Definition license.php:1