1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
livefeed.php
См. документацию.
1<?php
4
5Loc::loadMessages(__FILE__);
6
8{
9 public static function setMessageLiveFeed($users, $elementId, $workflowId, $flagCompleteProcess)
10 {
11 $elementId = intval($elementId);
12 $elementObject = CIBlockElement::getList(
13 array(),
14 array('ID' => $elementId),
15 false,
16 false,
17 array('ID', 'CREATED_BY', 'IBLOCK_NAME', 'NAME', 'IBLOCK_ID', 'LANG_DIR', 'IBLOCK_CODE')
18 );
19 $element = $elementObject->fetch();
20
21 if (!CLists::getLiveFeed($element["IBLOCK_ID"] ?? null))
22 {
23 return false;
24 }
25
26 $listSystemIblockCode = array(
27 'bitrix_holiday',
28 'bitrix_invoice',
29 'bitrix_trip',
30 'bitrix_cash',
31 'bitrix_incoming_doc',
32 'bitrix_outgoing_doc',
33 );
34
35 $params = serialize(array("ELEMENT_NAME" => $element['NAME']));
36
37 $element['NAME'] = htmlspecialcharsbx($element['NAME']);
38 if (in_array($element['IBLOCK_CODE'], $listSystemIblockCode))
39 {
40 $element['NAME'] = preg_replace_callback(
41 '#^[^\[\]]+?\[(\d+)\]#i',
42 function ($matches)
43 {
44 $userId = $matches[1];
45 $db = CUser::GetByID($userId);
46 if ($ar = $db->GetNext())
47 {
48 $ix = randString(5);
49 return '<a class="feed-post-user-name" href="/company/personal/user/'.$userId.'/"
50 bx-post-author-id="'.$userId.'" bx-post-author-gender="'.$ar['PERSONAL_GENDER'].'" bx-tooltip-user-id="'.$userId.'">'.CUser::FormatName(CSite::GetNameFormat(false), $ar, true, false).'</a>';
51 }
52 return $matches[0];
53 },
54 $element['NAME']
55 );
56 }
57
58 $path = rtrim($element['LANG_DIR'], '/');
59 $urlElement = $path.COption::GetOptionString('lists', 'livefeed_url').'?livefeed=y&list_id='.$element["IBLOCK_ID"].'&element_id='.$elementId;
60 $createdBy = $element['CREATED_BY'];
61 if(!Loader::includeModule('socialnetwork') || $createdBy <= 0)
62 return false;
63
64 $sourceId = CBPStateService::getWorkflowIntegerId($workflowId);
65 $logId = 0;
66 $userObject = CUser::getByID($createdBy);
67 $siteId = array();
68 $siteObject = CSite::getList("sort", "desc", array("ACTIVE" => "Y"));
69 while ($site = $siteObject->fetch())
70 $siteId[] = $site['LID'];
71
72 if ($userObject->fetch())
73 {
74 global $DB;
75 $soFields = Array(
76 'ENTITY_TYPE' => SONET_LISTS_NEW_POST_ENTITY,
77 'EVENT_ID' => 'lists_new_element',
78 'ENTITY_ID' => 1,
79 '=LOG_UPDATE' => $DB->currentTimeFunction(),
80 'SOURCE_ID' => $sourceId,
81 'USER_ID' => $createdBy,
82 'MODULE_ID' => 'lists',
83 'TITLE_TEMPLATE' => $urlElement,
84 'TITLE' => $element['IBLOCK_NAME'],
85 'PARAMS' => $params,
86 'MESSAGE' => $workflowId,
87 'CALLBACK_FUNC' => false,
88 'SITE_ID' => $siteId,
89 'ENABLE_COMMENTS' => 'Y',
90 'RATING_TYPE_ID' => 'LISTS_NEW_ELEMENT',
91 'RATING_ENTITY_ID' => $sourceId,
92 'URL' => '#SITE_DIR#'.COption::GetOptionString('socialnetwork', 'user_page', false, SITE_ID).'log/',
93 );
94
95 $logObject = CSocNetLog::getList(array(), array(
96 'ENTITY_TYPE' => $soFields['ENTITY_TYPE'],
97 'ENTITY_ID' => $soFields['ENTITY_ID'],
98 'EVENT_ID' => $soFields['EVENT_ID'],
99 'SOURCE_ID' => $soFields['SOURCE_ID'],
100 ));
101
102 $iblockPicture = CIBlock::getArrayByID($element['IBLOCK_ID'], 'PICTURE');
103 $imageFile = CFile::getFileArray($iblockPicture);
104 if($imageFile !== false)
105 {
106 $imageFile = CFile::ResizeImageGet(
107 $imageFile,
108 array("width" => 36, "height" => 30),
110 false
111 );
112 }
113 if(empty($imageFile['src']))
114 $imageFile['src'] = '/bitrix/images/lists/default.png';
115
116 $soFields['TEXT_MESSAGE'] = '
117 <span class="bp-title-desc">
118 <span class="bp-title-desc-icon">
119 <img src="'.$imageFile['src'].'" width="36" height="30" border="0" />
120 </span>
121 '.$element['NAME'].'
122 </span>
123 ';
124
125 if($log = $logObject->fetch())
126 {
127 if (intval($log['ID']) > 0)
128 {
129 if(empty($users))
130 {
131 CSocNetLog::update($log['ID'], $soFields);
132 }
133 else
134 {
135 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
136
137 $rights = self::getRights($activeUsers, $log['ID'], $createdBy, 'post');
138 $usersRight = self::getUserIdForRight($rights);
139
140 self::setSocnetFollow($usersRight, $log['ID'], 'Y', true);
141 /* Recipients tasks bp */
142 CSocNetLog::update($log['ID'], $soFields);
143
144 /* Increment the counter for participants */
145 CSocNetLogRights::deleteByLogID($log['ID']);
146 $rightsCounter = self::getRights($users, $log['ID'], $createdBy, 'counter');
147 CSocNetLogRights::add($log['ID'], $rightsCounter, false, false);
148 CSocNetLog::counterIncrement($log['ID'], $soFields['EVENT_ID'], false, 'L', false);
149
150 /* Return previous state rights */
151 CSocNetLogRights::deleteByLogID($log['ID']);
152 CSocNetLogRights::add($log['ID'], $rights, false, false);
153
154 self::setSocnetFollow($users, $log['ID'], 'Y');
155 self::setSocnetFollow($users, $log['ID'], 'N');
156 }
157
158 /* Completion of the process for the author */
159 if ($flagCompleteProcess)
160 {
161 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
162 $rights = self::getRights($activeUsers, $log['ID'], $createdBy, 'post');
163 $usersRight = self::getUserIdForRight($rights);
164
165 /* Increment the counter for author */
166 $users[] = $createdBy;
167 CSocNetLogRights::deleteByLogID($log['ID']);
168 $rightsCounter = self::getRights($users, $log['ID'], $createdBy, 'counter');
169 CSocNetLogRights::add($log['ID'], $rightsCounter, false, false);
170 CSocNetLog::counterIncrement($log['ID'], $soFields['EVENT_ID'], false, 'L', false);
171
172 /* Return previous state rights */
173 CSocNetLogRights::deleteByLogID($log['ID']);
174 CSocNetLogRights::add($log['ID'], $rights, false, false);
175
176 self::setSocnetFollow($users, $log['ID'], 'Y');
177 self::setSocnetFollow($usersRight, $log['ID'], 'N');
178 }
179 }
180 }
181 else
182 {
183 $activeUsers = CBPTaskService::getWorkflowParticipants($workflowId);
184
185 $soFields['=LOG_DATE'] = $DB->currentTimeFunction();
186 $logId = CSocNetLog::add($soFields, false);
187 if (intval($logId) > 0)
188 {
189 $rights = self::getRights($activeUsers, $logId, $createdBy, 'post');
190 CSocNetLogRights::add($logId, $rights, false, false);
191 $usersRight = self::getUserIdForRight($rights);
192 self::setSocnetFollow($usersRight, $logId, 'N');
193 }
194 CSocNetLog::counterIncrement($logId, $soFields['EVENT_ID'], false, 'L', false);
195 }
196 }
197 return $logId;
198 }
199
200 public static function onFillSocNetAllowedSubscribeEntityTypes(&$socnetEntityTypes)
201 {
202 $socnetEntityTypes[] = SONET_LISTS_NEW_POST_ENTITY;
203
204 global $arSocNetAllowedSubscribeEntityTypesDesc;
205 $arSocNetAllowedSubscribeEntityTypesDesc[SONET_LISTS_NEW_POST_ENTITY] = array(
206 'USE_CB_FILTER' => 'Y',
207 'TITLE_LIST' => '',
208 'TITLE_ENTITY' => '',
209 );
210 }
211
212 public static function onFillSocNetLogEvents(&$socnetLogEvents)
213 {
214 $socnetLogEvents['lists_new_element'] = array(
215 'ENTITIES' => array(
217 ),
218 'FORUM_COMMENT_ENTITY' => 'WF',
219 'CLASS_FORMAT' => 'CListsLiveFeed',
220 'METHOD_FORMAT' => 'formatListsElement',
221 'HAS_CB' => 'Y',
222 'FULL_SET' => array('lists_new_element', 'lists_new_element_comment'),
223 'COMMENT_EVENT' => array(
224 'MODULE_ID' => 'lists_new_element',
225 'EVENT_ID' => 'lists_new_element_comment',
226 'OPERATION' => 'view',
227 'OPERATION_ADD' => 'log_rights',
228 'ADD_CALLBACK' => array('CListsLiveFeed', 'addCommentLists'),
229 'UPDATE_CALLBACK' => array('CSocNetLogTools', 'UpdateComment_Forum'),
230 'DELETE_CALLBACK' => array('CListsLiveFeed', 'deleteCommentLists'),
231 'CLASS_FORMAT' => 'CSocNetLogTools',
232 'METHOD_FORMAT' => 'FormatComment_Forum',
233 "RATING_TYPE_ID" => "FORUM_POST",
234 ),
235 );
236 }
237
238 public static function formatListsElement($fields, $params, $mail = false)
239 {
240 global $CACHE_MANAGER;
241
242 $element = array(
243 'EVENT' => $fields,
244 'CREATED_BY' => array(),
245 'ENTITY' => array(),
246 'EVENT_FORMATTED' => array(),
247 );
248
249 $userObject = CUser::getByID($fields['ENTITY_ID']);
250 $user = $userObject->fetch();
251 if ($user)
252 {
253 if(!$mail)
254 {
255 global $APPLICATION;
256 $rights = array();
257 $rightsQuery = CSocNetLogRights::getList(array(), array('LOG_ID' => $fields['ID']));
258 while ($right = $rightsQuery->fetch())
259 {
260 $rights[] = $right['GROUP_CODE'];
261 }
262
263 if(defined('BX_COMP_MANAGED_CACHE'))
264 {
265 $CACHE_MANAGER->registerTag('LISTS_ELEMENT_LIVE_FEED');
266 }
267
268 $componentResult = $APPLICATION->includeComponent(
269 'bitrix:bizproc.workflow.livefeed',
270 '',
271 Array(
272 'WORKFLOW_ID' => $fields['MESSAGE'],
273 'SITE_TEMPLATE_ID' => (isset($params['SITE_TEMPLATE_ID']) ? $params['SITE_TEMPLATE_ID'] : ''),
274 ),
275 null,
276 array('HIDE_ICONS' => 'Y')
277 );
278
279 $siteDir = rtrim(SITE_DIR, '/');
280 $url = CSocNetLogTools::formatEvent_GetURL($fields, true);
281 $url = str_replace('#SITE_DIR#', $siteDir, $url);
282 $url .= ''.$fields['ID'].'/';
283
284 $componentResultMessage = $componentResult ? $componentResult['MESSAGE'] : null;
285 $element = array(
286 'EVENT' => $fields,
287 'EVENT_FORMATTED' => array(
288 'TITLE_24' => '<a href="'.$fields['TITLE_TEMPLATE'].'" class="bx-lists-live-feed-title-link">'.$fields['TITLE'].'</a>',
289 'MESSAGE' => $fields['TEXT_MESSAGE'] . $componentResultMessage,
290 'IS_IMPORTANT' => false,
291 'STYLE' => 'new-employee',
292 'AVATAR_STYLE' => 'avatar-info',
293 'DESTINATION' => CSocNetLogTools::formatDestinationFromRights($rights, array_merge($params, array('CREATED_BY' => $fields['USER_ID']))),
294 'URL' => $url,
295 ),
296 'CREATED_BY' => CSocNetLogTools::formatEvent_GetCreatedBy($fields, $params, $mail),
297 'AVATAR_SRC' => CSocNetLog::formatEvent_CreateAvatar($fields, $params),
298 'CACHED_JS_PATH' => $componentResult['CACHED_JS_PATH'] ?? null,
299 'CACHED_CSS_PATH' => $componentResult['CACHED_CSS_PATH'] ?? null,
300 );
301 if (isset($params['MOBILE']) && $params['MOBILE'] == 'Y')
302 {
303 $element['EVENT_FORMATTED']['TITLE_24'] = Loc::getMessage('LISTS_LF_MOBILE_DESTINATION');
304 $element['EVENT_FORMATTED']['TITLE_24_2'] = $fields['TITLE'];
305 unset($element['CACHED_CSS_PATH']);
306 }
307
308 if (CModule::IncludeModule('bizproc'))
309 {
310 $workflowId = \CBPStateService::getWorkflowByIntegerId($element['EVENT']['SOURCE_ID']);
311 }
312
313 if ($workflowId)
314 {
315 $element['EVENT']['SOURCE_ID'] = $workflowId;
316 }
317 }
318 return $element;
319 }
320 }
321
322 public static function addCommentLists($fields)
323 {
324 global $DB, $USER_FIELD_MANAGER;
325
326 if (!CModule::IncludeModule('forum') || !CModule::IncludeModule('bizproc'))
327 return false;
328
329 $ufFileId = array();
330 $ufDocId = array();
331 $fieldsMessage = array();
332 $messageId = array();
333 $error = array();
334 $note = array();
335 $workflowId = null;
336 $authorId = (int)($fields['USER_ID'] ?? 0);
337 $mentions = [];
338
339 $sonetLogQuery = CSocNetLog::GetList(
340 array(),
341 array('ID' => $fields['LOG_ID']),
342 false,
343 false,
344 array('ID', 'SOURCE_ID', 'SITE_ID', 'MESSAGE', 'USER_ID')
345 );
346 if($sonetLog = $sonetLogQuery->fetch())
347 {
348 $workflowId = $sonetLog['MESSAGE'];
350
351 if(preg_match_all("/(?<=\[USER=)(?P<id>[0-9]+)(?=\])/", $fields['TEXT_MESSAGE'], $matches))
352 {
353 $mentions = $matches['id'];
354 $users = array_unique(array_merge($users, $mentions));
355 }
356
357 $users[] = $sonetLog['USER_ID'];
358 self::setSocnetFollow($users, $sonetLog['ID'], 'Y', false, true);
359
360 $forumId = CBPHelper::getForumId();
361 if($forumId)
362 {
363 $topicQuery = CForumTopic::GetList(array(), array('FORUM_ID' => $forumId, 'XML_ID' => 'WF_'.$sonetLog['MESSAGE']));
364 if ($topicQuery && ($topic = $topicQuery->fetch()))
365 {
366 $topicId = $topic['ID'];
367 }
368 else
369 {
370 $dataTopic = array(
371 'AUTHOR_ID' => 0,
372 'TITLE' => 'WF_'.$sonetLog['MESSAGE'],
373 'TAGS' => '',
374 'MESSAGE' => 'WF_'.$sonetLog['MESSAGE'],
375 'XML_ID' => 'WF_'.$sonetLog['MESSAGE'],
376 );
377
378 $userStart = array(
379 "ID" => $dataTopic["AUTHOR_ID"],
380 "NAME" => $GLOBALS["FORUM_STATUS_NAME"]["guest"],
381 );
382
383 $DB->StartTransaction();
384 $topicFields = Array(
385 "TITLE" => $dataTopic["TITLE"],
386 "TAGS" => $dataTopic["TAGS"],
387 "FORUM_ID" => $forumId,
388 "USER_START_ID" => $userStart["ID"],
389 "USER_START_NAME" => $userStart["NAME"],
390 "LAST_POSTER_NAME" => $userStart["NAME"],
391 "XML_ID" => $dataTopic["XML_ID"],
392 "APPROVED" => "Y",
393 "PERMISSION_EXTERNAL" =>'Q',
394 "PERMISSION" => 'Y',
395 );
396
397 $topicId = CForumTopic::Add($topicFields);
398
399 if (intval($topicId) > 0)
400 {
401 $dataTopic['MESSAGE'] = strip_tags($dataTopic['MESSAGE']);
402
403 $dataFields = Array(
404 "POST_MESSAGE" => $dataTopic['MESSAGE'],
405 "AUTHOR_ID" => $userStart["ID"],
406 "AUTHOR_NAME" => $userStart["NAME"],
407 "FORUM_ID" => $forumId,
408 "TOPIC_ID" => $topicId,
409 "APPROVED" => "Y",
410 "NEW_TOPIC" => "Y",
411 "PARAM1" => "WF",
412 "PARAM2" => 0,
413 "PERMISSION_EXTERNAL" => 'Q',
414 "PERMISSION" => 'Y',
415 );
416 $startMessageId = CForumMessage::Add($dataFields, false, array("SKIP_INDEXING" => "Y", "SKIP_STATISTIC" => "N"));
417 if (intval($startMessageId) <= 0)
418 {
419 CForumTopic::Delete($topicId);
420 $topicId = 0;
421 }
422 }
423
424 if (intval($topicId) <= 0)
425 {
426 $DB->Rollback();
427 }
428 else
429 {
430 $DB->Commit();
431 }
432 }
433
434 if ($topicId)
435 {
436 $fieldsMessage = array(
437 'POST_MESSAGE' => $fields['TEXT_MESSAGE'],
438 'USE_SMILES' => 'Y',
439 'PERMISSION_EXTERNAL' => 'Q',
440 'PERMISSION' => 'Y',
441 'APPROVED' => 'Y',
442 );
443
444 $tmp = false;
445 $USER_FIELD_MANAGER->editFormAddFields('SONET_COMMENT', $tmp);
446 if (is_array($tmp))
447 {
448 if (array_key_exists('UF_SONET_COM_DOC', $tmp))
449 {
450 $GLOBALS['UF_FORUM_MESSAGE_DOC'] = $tmp['UF_SONET_COM_DOC'];
451 }
452 elseif (array_key_exists('UF_SONET_COM_FILE', $tmp))
453 {
454 $fieldsMessage['FILES'] = array();
455 foreach($tmp['UF_SONET_COM_FILE'] as $fileId)
456 {
457 $fieldsMessage['FILES'][] = array('FILE_ID' => $fileId);
458 }
459 }
460
461 if (array_key_exists("UF_SONET_COM_URL_PRV", $tmp))
462 {
463 $GLOBALS["UF_FORUM_MES_URL_PRV"] = $tmp["UF_SONET_COM_URL_PRV"];
464 }
465 }
466
467 $messageId = ForumAddMessage("REPLY", $forumId, $topicId, 0, $fieldsMessage, $error, $note);
468
469 if ($messageId > 0)
470 {
471 $addedMessageFilesQuery = CForumFiles::getList(array('ID' => 'ASC'), array('MESSAGE_ID' => $messageId));
472 while ($addedMessageFiles = $addedMessageFilesQuery->fetch())
473 {
474 $ufFileId[] = $addedMessageFiles['FILE_ID'];
475 }
476 $ufDocId = $USER_FIELD_MANAGER->getUserFieldValue('FORUM_MESSAGE', 'UF_FORUM_MESSAGE_DOC', $messageId, LANGUAGE_ID);
477 $ufUrlPreview = $USER_FIELD_MANAGER->GetUserFieldValue("FORUM_MESSAGE", "UF_FORUM_MES_URL_PRV", $messageId, LANGUAGE_ID);
478 }
479 }
480 }
481 }
482
483 if (!$messageId)
484 {
485 $error = Loc::getMessage('LISTS_LF_ADD_COMMENT_SOURCE_ERROR');
486 }
487
488 if (!$error)
489 {
491 }
492
493 return array(
494 'SOURCE_ID' => $messageId,
495 'MESSAGE' => ($fieldsMessage ? $fieldsMessage['POST_MESSAGE'] : false),
496 'RATING_TYPE_ID' => 'FORUM_POST',
497 'RATING_ENTITY_ID' => $messageId,
498 'ERROR' => $error,
499 'NOTES' => $note,
500 'UF' => array(
501 'FILE' => $ufFileId,
502 'DOC' => $ufDocId,
503 'URL_PREVIEW' => $ufUrlPreview,
504 ),
505 );
506 }
507
508 public static function deleteCommentLists($fields)
509 {
511
512 if (empty($parentResult['ERROR']) && CModule::IncludeModule('bizproc'))
513 {
514 $workflowId = (string)\CBPStateService::getWorkflowByIntegerId($fields['LOG_SOURCE_ID']);
515 $authorId = (int)$fields['USER_ID'];
518 }
519
520 return $parentResult;
521 }
522
523 protected static function getRights($users, $logId, $createdBy, $method)
524 {
525 $rights = array();
526 $rights[] = 'SA'; //socnet admin
527
528 if(!empty($users))
529 {
530 if($method == 'post')
531 $users[] = $createdBy;
532
533 foreach($users as $userId)
534 {
535 $rights[] = 'U'.$userId;
536 }
537 }
538
539 $rights = array_unique($rights);
540
541 return $rights;
542 }
543
544 protected static function getUserIdForRight($rights)
545 {
546 $users = array();
547 foreach($rights as $user)
548 {
549 if($user != 'SA')
550 {
551 $users[] = mb_substr($user, 1);
552 }
553 }
554 return $users;
555 }
556
557 protected static function setSocnetFollow($users, $logId, $type, $manualMode = false, $addingComment = false)
558 {
559 if($manualMode)
560 {
561 foreach($users as $userId)
562 {
563 $logFollowObject = CSocNetLogFollow::getList(
564 array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF', 'TYPE'));
565 $logFollow = $logFollowObject->fetch();
566 if(!empty($logFollow) && $logFollow['TYPE'] == 'Y' && !$logFollow['BY_WF'])
567 {
568 CSocNetLogFollow::delete($userId, 'L'.$logId, false);
569 CSocNetLogFollow::set($userId, 'L'.$logId, $type,
570 ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID), SITE_ID, true);
571
572 if (
573 $type == 'Y'
574 && method_exists('\Bitrix\Socialnetwork\ComponentHelper','userLogSubscribe')
575 )
576 {
578 'logId' => $logId,
579 'userId' => $userId,
580 'typeList' => array(
581 'COUNTER_COMMENT_PUSH',
582 ),
583 ));
584 }
585 }
586 }
587 }
588 else
589 {
590 if($type == 'Y')
591 {
592 foreach($users as $userId)
593 {
594 $logFollowObject = CSocNetLogFollow::getList(
595 array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF'));
596 $logFollow = $logFollowObject->fetch();
597
598 if(
599 empty($logFollow)
600 || ($logFollow['BY_WF'] == 'Y' || $addingComment)
601 )
602 {
603 CSocNetLogFollow::delete($userId, 'L'.$logId, false);
604
605 if (method_exists('\Bitrix\Socialnetwork\ComponentHelper','userLogSubscribe'))
606 {
608 'logId' => $logId,
609 'userId' => $userId,
610 'typeList' => array(
611 'FOLLOW',
612 'COUNTER_COMMENT_PUSH',
613 ),
614 'followDate' => 'CURRENT',
615 'followByWF' => true,
616 ));
617 }
618 else
619 {
620 CSocNetLogFollow::set($userId, 'L'.$logId, 'Y',
621 ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL", SITE_ID), SITE_ID, true);
622 }
623 }
624 }
625 }
626 else
627 {
628 foreach($users as $userId)
629 {
630 $logFollowObject = CSocNetLogFollow::getList(
631 array('USER_ID' => $userId, 'REF_ID' => $logId), array('BY_WF'));
632 $logFollow = $logFollowObject->fetch();
633
634 if(
635 empty($logFollow)
636 || $logFollow['BY_WF'] == 'Y'
637 )
638 {
639 CSocNetLogFollow::set($userId, 'L'.$logId, 'N', false, SITE_ID, true);
640 }
641 }
642 }
643 }
644 }
645
646 protected static function getSiteName()
647 {
648 return COption::getOptionString('main', 'site_name', '');
649 }
650
651 public static function BeforeIndexSocNet($bxSocNetSearch, $fields)
652 {
653 static $bizprocForumId = false;
654
655 if (!$bizprocForumId)
656 {
657 $bizprocForumId = intval(COption::GetOptionString('bizproc', 'forum_id'));
658 }
659
660 if(
661 isset($fields['ENTITY_TYPE_ID'])
662 && $fields['ENTITY_TYPE_ID'] == 'FORUM_POST'
663 && intval($fields['PARAM1']) == $bizprocForumId
664 && !empty($fields['PARAM2'])
665 && !empty($bxSocNetSearch->_params["PATH_TO_WORKFLOW"])
666 && CModule::IncludeModule("forum")
667 && CModule::IncludeModule("bizproc")
668 )
669 {
670 $topic = CForumTopic::GetByID($fields['PARAM2']);
671
672 if (
673 !empty($topic)
674 && is_array($topic)
675 && !empty($topic["XML_ID"])
676 )
677 {
678 if (preg_match('/^WF_([0-9a-f\.]+)/', $topic["XML_ID"], $match))
679 {
680 $workflowId = $match[1];
681 $state = CBPStateService::GetStateDocumentId($workflowId);
682
683 if (
684 $state[0] == 'lists'
685 && $state[1] == 'BizprocDocument'
686 && CModule::IncludeModule('iblock')
687 && (intval($state[2]) > 0)
688 )
689 {
690 $iblockElementQuery = CIBlockElement::GetList(
691 array(),
692 array(
693 "ID" => intval($state[2]),
694 ),
695 false,
696 false,
697 array("ID", "IBLOCK_ID")
698 );
699
700 if ($iblockElement = $iblockElementQuery->Fetch())
701 {
702 $listId = $iblockElement["IBLOCK_ID"];
703
704 $fields["URL"] = $bxSocNetSearch->Url(
705 str_replace(
706 array("#list_id#", "#workflow_id#"),
707 array($listId, urlencode($workflowId)),
708 $bxSocNetSearch->_params["PATH_TO_WORKFLOW"]
709 ),
710 array(
711 "MID" => $fields["ENTITY_ID"],
712 ),
713 "message".$fields["ENTITY_ID"]
714 );
715
716 if (
717 !empty($fields["LID"])
718 && is_array($fields["LID"])
719 )
720 {
721 foreach ($fields["LID"] as $siteId => $url)
722 {
723 $fields["LID"][$siteId] = $fields["URL"];
724 }
725 }
726 }
727 }
728 }
729 }
730 }
731
732 return $fields;
733 }
734
740 {
741 if ($comment["EVENT_ID"] != "lists_new_element_comment")
742 {
743 return;
744 }
745
746 $logQuery = CSocNetLog::getList(
747 array(),
748 array(
749 "ID" => $comment["LOG_ID"],
750 "EVENT_ID" => "lists_new_element",
751 ),
752 false,
753 false,
754 array("ID", "SOURCE_ID", "URL", "TITLE", "USER_ID", "PARAMS")
755 );
756
757 if (($log = $logQuery->fetch()) && (intval($log["SOURCE_ID"]) > 0))
758 {
759 $params = unserialize($log["PARAMS"], ['allowed_classes' => false]);
760 $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
761
762 $userIdsToNotify = self::getUserIdsFromRights($log['ID']);
763
764 foreach ($userIdsToNotify as $userId)
765 {
766 CListsLiveFeed::notifyComment(
767 [
768 "LOG_ID" => $comment["LOG_ID"],
769 "MESSAGE_ID" => $comment["SOURCE_ID"],
770 "TO_USER_ID" => $userId,
771 "FROM_USER_ID" => $comment["USER_ID"],
772 "URL" => $log["URL"],
773 "TITLE" => $title,
774 ]
775 );
776 }
777 }
778 }
779
786 public static function OnForumCommentIMNotify($entityType, $entityId, $comment)
787 {
788 if ($entityType != "WF")
789 return;
790
791 $logQuery = CSocNetLog::getList(
792 array(),
793 array(
794 "ID" => $comment["LOG_ID"],
795 "EVENT_ID" => "lists_new_element",
796 ),
797 false,
798 false,
799 array("ID", "SOURCE_ID", "URL", "TITLE", "USER_ID", "PARAMS")
800 );
801
802 if (($log = $logQuery->fetch()) && (intval($log["SOURCE_ID"]) > 0))
803 {
804 $params = unserialize($log["PARAMS"], ['allowed_classes' => false]);
805 $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
806
807 $userIdsToNotify = self::getUserIdsFromRights($log['ID']);
808
809 foreach ($userIdsToNotify as $userId)
810 {
811 CListsLiveFeed::notifyComment(
812 [
813 "LOG_ID" => $log["ID"],
814 "MESSAGE_ID" => $comment["MESSAGE_ID"],
815 "TO_USER_ID" => $userId,
816 "FROM_USER_ID" => $comment["USER_ID"],
817 "URL" => $log["URL"],
818 "TITLE" => $title,
819 ]
820 );
821 }
822 }
823 }
824
825 public static function NotifyComment($comment)
826 {
827 if (!Loader::includeModule("im"))
828 return;
829 if($comment["TO_USER_ID"] == $comment["FROM_USER_ID"])
830 return;
831
832 $siteDir = rtrim(SITE_DIR, '/');
833 $url = str_replace('#SITE_DIR#', $siteDir, $comment["URL"]);
834 $url .= ''.$comment['LOG_ID'].'/';
835
836 $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD",
837 array("#PROCESS#" => '<a href="'.$url.'" class="bx-notifier-item-action">'.$comment["TITLE"].'</a>'));
838 $userQuery = CUser::getList(
839 "id",
840 "asc",
841 array("ID_EQUAL_EXACT" => intval($comment["FROM_USER_ID"])),
842 array("FIELDS" => array("PERSONAL_GENDER"))
843 );
844 if ($user = $userQuery->fetch())
845 {
846 switch ($user["PERSONAL_GENDER"])
847 {
848 case "F":
849 case "M":
850 $messageAddComment = Loc::getMessage("LISTS_LF_COMMENT_MESSAGE_ADD" . '_' . $user["PERSONAL_GENDER"],
851 array("#PROCESS#" => '<a href="'.$url.'" class="bx-notifier-item-action">'.$comment["TITLE"].'</a>'));
852 break;
853 default:
854 break;
855 }
856 }
857
859 "TO_USER_ID" => $comment["TO_USER_ID"],
860 "FROM_USER_ID" => $comment["FROM_USER_ID"],
861 "NOTIFY_TYPE" => IM_NOTIFY_FROM,
862 "NOTIFY_MODULE" => "lists",
863 "NOTIFY_TAG" => "SONET|EVENT|".$comment["LOG_ID"],
864 "NOTIFY_SUB_TAG" => "FORUM|COMMENT|".$comment["MESSAGE_ID"]."|".$comment["TO_USER_ID"],
865 "NOTIFY_EVENT" => "event_lists_comment_add",
866 "NOTIFY_MESSAGE" => $messageAddComment,
867 );
868
869 CIMNotify::Add($messageFields);
870 }
871
872 public static function OnSendMentionGetEntityFields($commentFields)
873 {
874 if (!in_array($commentFields["EVENT_ID"], array("lists_new_element_comment")))
875 {
876 return false;
877 }
878
879 if (!CModule::IncludeModule("socialnetwork"))
880 {
881 return true;
882 }
883
885 array(),
886 array(
887 "ID" => $commentFields["LOG_ID"],
888 ),
889 false,
890 false,
891 array("ID", "TITLE", "SOURCE_ID", "PARAMS")
892 );
893
894 if ($log = $dbLog->GetNext())
895 {
896 $genderSuffix = "";
897 $dbUser = CUser::GetByID($commentFields["USER_ID"]);
898 if($user = $dbUser->Fetch())
899 {
900 $genderSuffix = $user["PERSONAL_GENDER"];
901 }
902
903 $params = unserialize($log["~PARAMS"], ['allowed_classes' => false]);
904 $title = $log["TITLE"]." - ".$params["ELEMENT_NAME"];
905 $entityName = GetMessage("LISTS_LF_COMMENT_MENTION_TITLE", Array("#PROCESS#" => $title));
906 $notifyMessage = GetMessage("LISTS_LF_COMMENT_MENTION" . ($genderSuffix <> '' ? "_" . $genderSuffix : ""), Array("#title#" => "<a href=\"#url#\" class=\"bx-notifier-item-action\">".$entityName."</a>"));
907 $notifyMessageOut = GetMessage("LISTS_LF_COMMENT_MENTION" . ($genderSuffix <> '' ? "_" . $genderSuffix : ""), Array("#title#" => $entityName)) . " (" . "#server_name##url#)";
908
909 $strPathToLogEntry = str_replace("#log_id#", $log["ID"], COption::GetOptionString("socialnetwork", "log_entry_page", "/company/personal/log/#log_id#/", SITE_ID));
910 $strPathToLogEntryComment = $strPathToLogEntry . (mb_strpos($strPathToLogEntry, "?") !== false ? "&" : "?") . "commentID=" . $commentFields["ID"] . "#com" . $commentFields["ID"];
911
912 $return = array(
913 "URL" => $strPathToLogEntryComment,
914 "NOTIFY_MODULE" => "lists",
915 "NOTIFY_TAG" => "LISTS|COMMENT_MENTION|".$commentFields["ID"],
916 "NOTIFY_MESSAGE" => $notifyMessage,
917 "NOTIFY_MESSAGE_OUT" => $notifyMessageOut,
918 );
919
920 return $return;
921 }
922 else
923 {
924 return false;
925 }
926 }
927
928 public static function OnSocNetGroupDelete($groupId)
929 {
930 $iblockIdList = array();
931 $res = \CIBlock::getList(array(), array("SOCNET_GROUP_ID" => $groupId));
932 while($iblock = $res->fetch())
933 {
934 $iblockIdList[] = $iblock["ID"];
935 }
936
937 if (empty($iblockIdList))
938 {
939 return true;
940 }
941
942 foreach($iblockIdList as $iblockId)
943 {
944 CIBlock::Delete($iblockId);
945 }
946
947 return true;
948 }
949
950 private static function getUserIdsFromRights(int $logId): array
951 {
952 $userIdsToNotify = [];
953 $rightsResult = \CSocNetLogRights::getList([], ['LOG_ID' => $logId]);
954 while ($right = $rightsResult->fetch())
955 {
956 if (preg_match('/^U(\d+)$/', $right["GROUP_CODE"], $matches))
957 {
958 $userIdsToNotify[] = $matches[1];
959 }
960 }
961
962 return $userIdsToNotify;
963 }
964}
$path
Определения access_edit.php:21
$type
Определения options.php:106
$messageFields
Определения callback_ednaru.php:22
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
global $APPLICATION
Определения include.php:80
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static onListsProcessesCommentAdd(string $workflowId, int $authorId, array $mentions)
Определения commentlistener.php:75
static onListsProcessesCommentDelete(string $workflowId, int $authorId, DateTime $created)
Определения commentlistener.php:81
Определения loader.php:13
static createFromUserTime($timeString)
Определения datetime.php:180
static userLogSubscribe($params=array())
Определения componenthelper.php:4799
static Delete($ID)
Определения topic.php:413
static Add($arFields)
Определения topic.php:213
static GetByID($ID, $arAddParams=array())
Определения topic.php:431
static getWorkflowIntegerId($workflowId)
Определения stateservice.php:404
static getWorkflowByIntegerId($integerId)
Определения stateservice.php:440
static getWorkflowParticipants($workflowId, $userStatus=null)
Определения taskservice.php:172
const Waiting
Определения constants.php:273
static Add($arFields, $strUploadDir=false, $arParams=array())
Определения message.php:7
static GetList($arOrder=Array("SORT"=>"ASC"), $arFilter=Array(), $bCount=false, $iNum=0, $arAddParams=array())
Определения topic.php:6
Определения livefeed.php:8
static OnSendMentionGetEntityFields($commentFields)
Определения livefeed.php:872
static OnForumCommentIMNotify($entityType, $entityId, $comment)
Определения livefeed.php:786
static getRights($users, $logId, $createdBy, $method)
Определения livefeed.php:523
static OnSocNetGroupDelete($groupId)
Определения livefeed.php:928
static onFillSocNetAllowedSubscribeEntityTypes(&$socnetEntityTypes)
Определения livefeed.php:200
static getSiteName()
Определения livefeed.php:646
static getUserIdForRight($rights)
Определения livefeed.php:544
static setSocnetFollow($users, $logId, $type, $manualMode=false, $addingComment=false)
Определения livefeed.php:557
static NotifyComment($comment)
Определения livefeed.php:825
static formatListsElement($fields, $params, $mail=false)
Определения livefeed.php:238
static deleteCommentLists($fields)
Определения livefeed.php:508
static addCommentLists($fields)
Определения livefeed.php:322
static OnAfterSonetLogEntryAddComment($comment)
Определения livefeed.php:739
static onFillSocNetLogEvents(&$socnetLogEvents)
Определения livefeed.php:212
static BeforeIndexSocNet($bxSocNetSearch, $fields)
Определения livefeed.php:651
static setMessageLiveFeed($users, $elementId, $workflowId, $flagCompleteProcess)
Определения livefeed.php:9
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array(), $arParams=array())
Определения log.php:338
static DeleteComment_Forum($arFields)
Определения log_tools.php:3484
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$right
Определения options.php:8
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
ForumAddMessage( $MESSAGE_TYPE, $FID, $TID, $MID, $arFieldsG, &$strErrorMessage, &$strOKMessage, $iFileSize=false, $captcha_word="", $captcha_sid=0, $captcha_code="")
Определения include.php:317
global $USER_FIELD_MANAGER
Определения attempt.php:6
$iblockId
Определения iblock_catalog_edit.php:30
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
const IM_NOTIFY_FROM
Определения include.php:37
const SONET_LISTS_NEW_POST_ENTITY(!defined("CACHED_b_lists_field_prefix"))
Определения include.php:18
global $DB
Определения cron_frame.php:29
$note
Определения options.php:209
const BX_RESIZE_IMAGE_PROPORTIONAL
Определения constants.php:11
const SITE_DIR(!defined('LANG'))
Определения include.php:72
$siteId
Определения ajax.php:8
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
GetMessage($name, $aReplace=null)
Определения tools.php:3397
randString($pass_len=10, $pass_chars=false)
Определения tools.php:2154
$entityId
Определения payment.php:4
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$comment
Определения template.php:15
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$title
Определения pdf.php:123
$method
Определения index.php:27
$matches
Определения index.php:22
const SITE_ID
Определения sonet_set_content_view.php:12
$error
Определения subscription_card_product.php:20
$GLOBALS['_____370096793']
Определения update_client.php:1
if(CModule::IncludeModule("forum")) if(CModule::IncludeModule("blog")) $dbLog
Определения updtr1007.php:132
$rights
Определения options.php:4
$url
Определения iframe.php:7
$site
Определения yandex_run.php:614
$fields
Определения yandex_run.php:501