83 || !Loader::includeModule(
'forum')
89 $res = MessageTable::getList([
93 'select' => [
'ID',
'POST_MESSAGE',
'SERVICE_TYPE',
'SERVICE_DATA',
'POST_DATE',
'AUTHOR_ID',
'TOPIC_ID' ]
95 $message = $res->fetch();
103 'SHARE_DEST' => $message[
'SERVICE_DATA'],
104 'SOURCE_ID' => $messageId,
111 'SOURCE_ID' => $messageId,
114 'select' => [
'ID',
'LOG_ID',
'SHARE_DEST',
'MESSAGE',
'EVENT_ID',
'RATING_TYPE_ID']
116 if ($logComentFields = $res->fetch())
118 $logId = (int)$logComentFields[
'LOG_ID'];
120 $auxData[
'ID'] = (int)$logComentFields[
'ID'];
121 $auxData[
'LOG_ID'] =
$logId;
126 $title = htmlspecialcharsback($message[
'POST_MESSAGE']);
127 $title = \Bitrix\Socialnetwork\Helper\Mention::clear($title);
129 $CBXSanitizer = new \CBXSanitizer;
130 $CBXSanitizer->delAllTags();
131 $title = preg_replace(
133 "/\n+/is".BX_UTF_PCRE_MODIFIER,
134 "/\s+/is".BX_UTF_PCRE_MODIFIER
137 \CTextParser::clearAllTags($title)
147 $res = \CSocNetLog::getList(
154 [
'ID',
'EVENT_ID' ],
156 'CHECK_RIGHTS' =>
'Y',
158 'USE_SUBSCRIBE' =>
'N',
161 if ($logFields = $res->fetch())
164 $this->
setSourceFields(array_merge($message, [
'LOG_EVENT_ID' => $logFields[
'EVENT_ID'] ]));
167 !empty($logComentFields)
172 $auxData[
'SHARE_DEST'] =
'';
173 $auxData[
'EVENT_ID'] = $logComentFields[
'EVENT_ID'];
174 $auxData[
'SOURCE_ID'] = $messageId;
175 $auxData[
'RATING_TYPE_ID'] = $logComentFields[
'RATING_TYPE_ID'];
215 static $urlCache = [];
224 if (isset($urlCache[
$logId]))
226 $entityUrl = $urlCache[
$logId];
230 $res = self::$logTable::getList([
234 'select' => [
'ENTITY_ID',
'EVENT_ID',
'SOURCE_ID',
'RATING_TYPE_ID',
'RATING_ENTITY_ID',
'PARAMS' ],
236 if ($logEntryFields = $res->fetch())
241 if (in_array((
string)$logEntryFields[
'EVENT_ID'], $providerTasksTask->getEventId(),
true))
243 $entityId = (int)$logEntryFields[
'SOURCE_ID'];
244 if ($logEntryFields[
'EVENT_ID'] ===
'crm_activity_add')
246 if ($logEntryFields[
'RATING_TYPE_ID'] ===
'TASK')
248 $entityId = (int)$logEntryFields[
'RATING_ENTITY_ID'];
251 $logEntryFields[
'RATING_TYPE_ID'] ===
'LOG_ENTRY'
252 && Loader::includeModule(
'crm')
253 && ($activity = \CCrmActivity::getById($logEntryFields[
'ENTITY_ID'],
false))
254 && (
int)$activity[
'TYPE_ID'] === \CCrmActivityType::Task
257 $entityId = (int)$activity[
'ASSOCIATED_ENTITY_ID'];
267 $provider = $providerTasksTask;
268 $provider->setOption(
'checkAccess',
false);
271 $provider->setLogId(
$logId);
272 $provider->initSourceFields();
274 $postUrl = $provider->getLiveFeedUrl();
275 $entityUrl = $postUrl.(mb_strpos($postUrl,
'?') ===
false ?
'?' :
'&').
'commentId='.$this->
getEntityId().
'#com'.$this->
getEntityId();
282 if (in_array($logEntryFields[
'EVENT_ID'], $providerCalendarEvent->getEventId(),
true))
284 $provider = $providerCalendarEvent;
285 $provider->setEntityId((
int)$logEntryFields[
'SOURCE_ID']);
286 $provider->setLogId(
$logId);
287 $provider->initSourceFields();
289 $postUrl = $provider->getLiveFeedUrl();
290 $entityUrl = $postUrl.(mb_strpos($postUrl,
'?') ===
false ?
'?' :
'&').
'commentId='.$this->
getEntityId().
'#com'.$this->
getEntityId();
297 if (in_array($logEntryFields[
'EVENT_ID'], $providerTimemanEntry->getEventId(),
true))
299 $provider = $providerTimemanEntry;
300 $provider->setEntityId((
int)$logEntryFields[
'SOURCE_ID']);
301 $provider->setLogId(
$logId);
302 $provider->initSourceFields();
303 $entityUrl = $provider->getLiveFeedUrl();
310 if (in_array($logEntryFields[
'EVENT_ID'], $providerTimemanReport->getEventId(),
true))
312 $provider = $providerTimemanReport;
313 $provider->setEntityId((
int)$logEntryFields[
'SOURCE_ID']);
314 $provider->setLogId(
$logId);
315 $provider->initSourceFields();
316 $entityUrl = $provider->getLiveFeedUrl();
323 if (in_array($logEntryFields[
'EVENT_ID'], $providerPhotogalleryPhoto->getEventId(),
true))
325 $provider = $providerPhotogalleryPhoto;
326 $provider->setEntityId((
int)$logEntryFields[
'SOURCE_ID']);
327 $provider->setLogId(
$logId);
328 $provider->initSourceFields();
329 $entityUrl = $provider->getLiveFeedUrl();
335 $providerWiki =
new Wiki();
336 if (in_array($logEntryFields[
'EVENT_ID'], $providerWiki->getEventId(),
true))
338 $provider = $providerWiki;
339 $provider->setEntityId((
int)($logEntryFields[
'SOURCE_ID']));
340 $provider->setLogId(
$logId);
341 $provider->initSourceFields();
342 $entityUrl = $provider->getLiveFeedUrl();
349 if (in_array($logEntryFields[
'EVENT_ID'], $providerListsItem->getEventId(),
true))
351 $provider = $providerListsItem;
352 $provider->setEntityId((
int)($logEntryFields[
'SOURCE_ID']));
353 $provider->setLogId(
$logId);
354 $provider->initSourceFields();
363 !empty($logEntryFields[
'PARAMS'])
364 && unserialize($logEntryFields[
'PARAMS'], [
'allowed_classes' =>
false])
365 && in_array($logEntryFields[
'EVENT_ID'], $providerForumTopic->getEventId(),
true)
368 $paramsList = unserialize($logEntryFields[
"PARAMS"], [
'allowed_classes' =>
false]);
369 if (!empty($paramsList[
"PATH_TO_MESSAGE"]))
371 $entityUrl = \CComponentEngine::makePathFromTemplate($paramsList[
"PATH_TO_MESSAGE"], [
"MID" => $this->
getEntityId() ]);
379 if (!empty($entityUrl))
381 $result = $entityUrl;
394 if (in_array(
$logEventId, $providerTasksTask->getEventId(),
true))
400 if (in_array(
$logEventId, $providerCalendarEvent->getEventId(),
true))
406 if (in_array(
$logEventId, $providerForumTopic->getEventId(),
true))
408 return 'FORUM_TOPIC';
412 if (in_array(
$logEventId, $providerTimemanEntry->getEventId(),
true))
414 return 'TIMEMAN_ENTRY';
418 if (in_array(
$logEventId, $providerTimemanReport->getEventId(),
true))
420 return 'TIMEMAN_REPORT';
424 if (in_array(
$logEventId, $providerPhotogalleryPhoto->getEventId(),
true))
426 return 'PHOTO_PHOTO';
429 $providerWiki =
new Wiki();
430 if (in_array(
$logEventId, $providerWiki->getEventId(),
true))
436 if (in_array(
$logEventId, $providerListsItem->getEventId(),
true))
438 return 'LISTS_NEW_ELEMENT';
441 elseif (!empty ($defaultValue))
443 return $defaultValue;
449 public function add($params = [])
453 static $parser =
null;
456 isset($params[
'SITE_ID'])
457 && $params[
'SITE_ID'] <>
''
463 isset($params[
'AUTHOR_ID'])
464 && (int)$params[
'AUTHOR_ID'] > 0
465 ? (
int)$params[
'AUTHOR_ID']
469 $message = (string)($params[
'MESSAGE'] ??
'');
473 || !Loader::includeModule(
'forum')
483 if (empty($feedParams))
488 $forumId = self::getForumId(array_merge($feedParams, [
497 $feed = new \Bitrix\Forum\Comments\Feed(
503 $forumMessageFields = [
504 'POST_MESSAGE' => $message,
505 'AUTHOR_ID' => $authorId,
507 'AUX' => (isset($params[
'AUX']) && $params[
'AUX'] ===
'Y' ? $params[
'AUX'] :
'N')
510 if ($message === CommentAux\CreateEntity::getPostText())
513 $forumMessageFields[
'SERVICE_DATA'] = Json::encode(isset($params[
'AUX_DATA']) && is_array($params[
'AUX_DATA']) ? $params[
'AUX_DATA'] : []);
516 ])->getText($forumMessageFields[
'SERVICE_DATA']);
517 $params[
'SHARE_DEST'] =
'';
520 is_array($params[
'AUX_DATA'])
521 && !empty($params[
'AUX_DATA'][
'entityType'])
522 && (
int)$params[
'AUX_DATA'][
'entityId'] > 0
526 $entityLivefeedPovider->setEntityId((
int)$params[
'AUX_DATA'][
'entityId']);
527 $entityLivefeedPovider->initSourceFields();
529 $url = $entityLivefeedPovider->getLiveFeedUrl();
532 $metaData = UrlPreview::getMetadataAndHtmlByUrl($url,
true,
false);
536 && !empty($metaData[
'ID'])
537 && (
int)$metaData[
'ID'] > 0
540 $signer = new \Bitrix\Main\Security\Sign\Signer();
541 $forumMessageFields[
'UF_FORUM_MES_URL_PRV'] = $signer->sign($metaData[
'ID'] .
'', UrlPreview::SIGN_SALT);
546 elseif ($message === CommentAux\CreateTask::getPostText())
549 $forumMessageFields[
'SERVICE_DATA'] = Json::encode(isset($params[
'AUX_DATA']) && is_array($params[
'AUX_DATA']) ? $params[
'AUX_DATA'] : []);
552 ])->getText($forumMessageFields[
'SERVICE_DATA']);
553 $params[
'SHARE_DEST'] =
'';
556 $forumComment = $feed->add($forumMessageFields);
563 $sonetCommentId =
false;
567 if ($params[
'AUX'] ===
'Y')
569 if ($parser ===
null)
571 $parser = new \CTextParser();
574 $sonetCommentFields = [
577 "EVENT_ID" => $this->getCommentEventId(),
578 "MESSAGE" => $message,
579 "TEXT_MESSAGE" => $parser->convert4mail($message),
580 "MODULE_ID" => $this->getModuleId(),
581 "SOURCE_ID" => $forumComment[
'ID'],
583 "RATING_TYPE_ID" =>
"FORUM_POST",
584 "RATING_ENTITY_ID" => $forumComment[
'ID'],
585 "USER_ID" => $authorId,
586 "=LOG_DATE" => \CDatabase::currentTimeFunction(),
589 if (!empty($params[
'SHARE_DEST']))
591 $sonetCommentFields[
'SHARE_DEST'] = $params[
'SHARE_DEST'];
594 if (!empty($forumMessageFields[
'UF_FORUM_MES_URL_PRV']))
596 $sonetCommentFields[
'UF_SONET_COM_URL_PRV'] = $forumMessageFields[
'UF_FORUM_MES_URL_PRV'];
599 $sonetCommentId = \CSocNetLogComments::add($sonetCommentFields,
false,
false);
605 'EVENT_ID' => $this->getCommentEventId(),
606 'SOURCE_ID' => $forumComment[
'ID'],
608 'select' => [
'ID' ],
610 if ($sonetCommentFields = $res->fetch())
612 $sonetCommentId = $sonetCommentFields[
'ID'];
618 'sonetCommentId' => $sonetCommentId,
619 'sourceCommentId' => $forumComment[
'ID']
835 $res = self::$logTable::getList(array(
839 'select' => array(
'EVENT_ID',
'SOURCE_ID')
843 ($logFields = $res->fetch())
844 && (!empty($logFields[
'EVENT_ID']))
845 && ((
int)$logFields[
'SOURCE_ID'] > 0)
851 if (in_array($logFields[
'EVENT_ID'], $providerTasksTask->getEventId(),
true))
853 $entityType = $providerTasksTask->getContentTypeId();
854 $entityId = (int)$logFields[
'SOURCE_ID'];
860 if (in_array($logFields[
'EVENT_ID'], $providerCalendarEvent->getEventId(),
true))
862 $entityType = $providerCalendarEvent->getContentTypeId();
863 $entityId = (int)$logFields[
'SOURCE_ID'];
870 if (in_array($logFields[
'EVENT_ID'], $providerForumTopic->getEventId(),
true))
872 $entityType = $providerForumTopic->getContentTypeId();
873 $entityId = (int)$logFields[
'SOURCE_ID'];
880 if (in_array($logFields[
'EVENT_ID'], $providerTimemanEntry->getEventId(),
true))
882 $entityType = $providerTimemanEntry->getContentTypeId();
883 $entityId = (int)$logFields[
'SOURCE_ID'];
890 if (in_array($logFields[
'EVENT_ID'], $providerTimemanReport->getEventId(),
true))
892 $entityType = $providerTimemanReport->getContentTypeId();
893 $entityId = (int)$logFields[
'SOURCE_ID'];
900 if (in_array($logFields[
'EVENT_ID'], $providerPhotogalleryPhoto->getEventId(),
true))
902 $entityType = $providerPhotogalleryPhoto->getContentTypeId();
903 $entityId = (int)$logFields[
'SOURCE_ID'];
909 $providerWiki =
new Wiki();
910 if (in_array($logFields[
'EVENT_ID'], $providerWiki->getEventId(),
true))
912 $entityType = $providerWiki->getContentTypeId();
913 $entityId = (int)$logFields[
'SOURCE_ID'];
920 if (in_array($logFields[
'EVENT_ID'], $providerListsItem->getEventId(),
true))
922 $entityType = $providerListsItem->getContentTypeId();
923 $entityId = (int)$logFields[
'SOURCE_ID'];
942 $xmlId =
'TASK_'.$entityId;
947 is_array($entityData)
948 && !empty($entityData[
'parentId'])
949 && !empty($entityData[
'dateFrom'])
950 && Loader::includeModule(
'calendar')
953 $calendarEntry = \CCalendarEvent::getEventForViewInterface($entityData[
'parentId'], [
954 'eventDate' => $entityData[
'dateFrom'],
955 'userId' => $USER->getId(),
960 $xmlId = \CCalendarEvent::getEventCommentXmlId($calendarEntry);
965 $xmlId =
'TOPIC_'.$entityId;
968 $xmlId =
'TIMEMAN_ENTRY_'.$entityId;
971 $xmlId =
'TIMEMAN_REPORT_'.$entityId;
974 $xmlId =
'PHOTO_'.$entityId;
977 $xmlId =
'IBLOCK_'.$entityId;
981 Loader::includeModule(
'bizproc')
982 && ($workflowId = \CBPStateService::getWorkflowByIntegerId(
$entityId))
985 $xmlId =
'WF_' . $workflowId;
1033 if (!Loader::includeModule(
'forum'))
1038 $logEventsData = (isset($params[
'logEventsData']) && is_array($params[
'logEventsData']) ? $params[
'logEventsData'] : []);
1040 $forumCommentEventIdList = $this->
getEventId();
1045 $commentEvent = \CSocNetLogTools::findLogCommentEventByLogEventID(
$logEventId);
1046 if (empty($commentEvent[
'EVENT_ID']))
1051 if (in_array($commentEvent[
'EVENT_ID'], $forumCommentEventIdList,
true))
1057 if (!empty($logIdList))
1059 $query = MessageTable::query();
1060 $query->setSelect([
'ID',
'POST_MESSAGE',
'SERVICE_DATA',
'SERVICE_TYPE' ]);
1062 $query->registerRuntimeField(
1064 'LOG_COMMENT', LogCommentTable::class, Join::on(
'this.ID',
'ref.SOURCE_ID'), [
'join_type' =>
'INNER' ]
1067 $query->whereIn(
'LOG_COMMENT.LOG_ID', $logIdList);
1068 $query->setLimit(1000);
1070 $messages = $query->exec()->fetchCollection();
1071 while ($message = $messages->current())
1073 $messageFields = $message->collectValues();
1074 self::$auxCommentsCache[$messageFields[
'ID']] = $messageFields;