27 $entityType = ($params[
'ENTITY_TYPE'] ??
false);
28 $entityId = (int)($params[
'ENTITY_ID'] ?? 0);
29 $sourceEntityType = (isset($params[
'SOURCE_ENTITY_TYPE']) && in_array($params[
'SOURCE_ENTITY_TYPE'], [
'BLOG_POST',
'BLOG_COMMENT' ]) ? $params[
'SOURCE_ENTITY_TYPE'] :
false);
30 $sourceEntityId = (int)($params[
'SOURCE_ENTITY_ID'] ?? 0);
34 empty($sourceEntityType)
35 || $sourceEntityId <= 0
38 || !Loader::includeModule(
'blog')
44 $entity = static::getEntityData([
45 'entityType' => $entityType,
46 'entityId' => $entityId,
54 $source = static::getSourceData([
55 'sourceEntityType' => $sourceEntityType,
56 'sourceEntityId' => $sourceEntityId,
64 $authorId = static::getEntityAuthorId([
65 'entityType' => $entityType,
66 'entityData' => $entity,
68 $userIP = \CBlogUser::getUserIP();
69 $auxText = CommentAux\CreateEntity::getPostText();
72 'POST_ID' => $source[
'post'][
'ID'],
73 'BLOG_ID' => $source[
'post'][
'BLOG_ID'],
74 'POST_TEXT' => $auxText,
75 'DATE_CREATE' => convertTimeStamp(time() + \CTimeZone::getOffset(),
'FULL'),
76 'AUTHOR_IP' => $userIP[0],
77 'AUTHOR_IP1' => $userIP[1],
79 'AUTHOR_ID' => $authorId,
80 'SHARE_DEST' => Json::encode([
81 'sourceType' => $sourceEntityType,
82 'sourceId' => $sourceEntityId,
83 'entityType' => $entityType,
84 'entityId' => $entityId,
88 $entityLivefeedPovider = Provider::getProvider($sourceEntityType);
89 $entityLivefeedPovider->setEntityId($sourceEntityId);
90 $entityLivefeedPovider->initSourceFields();
92 $url = $entityLivefeedPovider->getLiveFeedUrl();
95 $metaData = UrlPreview::getMetadataAndHtmlByUrl($url,
true,
false);
99 && !empty($metaData[
'ID'])
100 && (
int)$metaData[
'ID'] > 0
104 $logCommentFields[
'UF_BLOG_COMM_URL_PRV'] = $signer->sign($metaData[
'ID'] .
'', UrlPreview::SIGN_SALT);
108 $newCommentId = \CBlogComment::add($logCommentFields,
false);
114 BXClearCache(
true,
'/blog/comment/' . (
int)($source[
'post'][
'ID'] / 100) .
'/' . $source[
'post'][
'ID'] .
'/');
118 $res = \CSocNetLog::getList(
121 'EVENT_ID' => $blogPostLivefeedProvider->getEventId(),
122 'SOURCE_ID' => $source[
'post'][
'ID']
125 [
'nTopCount' => 1 ],
128 if ($log = $res->fetch())
130 $logId = (int)$log[
'ID'];
136 $helper = $connection->getSqlHelper();
138 $logCommentFields = [
139 'ENTITY_TYPE' => SONET_ENTITY_USER,
140 'ENTITY_ID' => $source[
'post'][
'AUTHOR_ID'],
141 'EVENT_ID' =>
'blog_comment',
142 '=LOG_DATE' => $helper->getCurrentDateTimeFunction(),
144 'USER_ID' => $authorId,
145 'MESSAGE' => $auxText,
146 'TEXT_MESSAGE' => $auxText,
147 'MODULE_ID' =>
false,
148 'SOURCE_ID' => $newCommentId,
149 'RATING_TYPE_ID' =>
'BLOG_COMMENT',
150 'RATING_ENTITY_ID' => $newCommentId,
153 \CSocNetLogComments::add($logCommentFields,
false,
false);
156 isset($params[
'LIVE'])
157 && $params[
'LIVE'] ===
'Y'
160 $userPage = Option::get(
'socialnetwork',
'user_page', SITE_DIR .
'company/personal/');
161 $userPath = $userPage .
'user/' . $source[
'post'][
'AUTHOR_ID'] .
'/';
163 $auxLiveParamList = static::getAuxLiveParams([
164 'sourceEntityType' => $sourceEntityType,
165 'sourceEntityId' => $sourceEntityId,
166 'sourceData' => $source,
167 'entityType' => $entityType,
168 'entityId' => $entityId,
169 'entityData' => $entity,
170 'userPath' => $userPath,
174 $provider = CommentAux\Base::init(CommentAux\CreateEntity::getType(), [
175 'liveParamList' => $auxLiveParamList
178 \CBlogComment::addLiveComment($newCommentId, [
179 'PATH_TO_USER' => $userPath,
181 'MODE' =>
'PULL_MESSAGE',
182 'AUX' =>
'createentity',
183 'AUX_LIVE_PARAMS' => $provider->getLiveParams(),
193 $entityType = ($params[
'ENTITY_TYPE'] ??
false);
194 $entityId = (int)($params[
'ENTITY_ID'] ?? 0);
195 $postEntityType = ($params[
'POST_ENTITY_TYPE'] ??
false);
196 $sourceEntityType = ($params[
'SOURCE_ENTITY_TYPE'] ??
false);
197 $sourceEntityId = (int)($params[
'SOURCE_ENTITY_ID'] ?? 0);
198 $sourceEntityData = (array)($params[
'SOURCE_ENTITY_DATA'] ?? []);
199 $logId = (int)($params[
'LOG_ID'] ?? 0);
200 $siteId = ($params[
'SITE_ID'] ?? SITE_ID);
205 'ENTITY_TYPE' => $entityType,
206 'ENTITY_ID' => $entityId,
207 'SOURCE_ENTITY_TYPE' => $sourceEntityType,
208 'SOURCE_ENTITY_ID' => $sourceEntityId,
214 empty($postEntityType)
215 || empty($sourceEntityType)
216 || $sourceEntityId <= 0
217 || empty($entityType)
224 $entity = static::getEntityData([
225 'entityType' => $entityType,
226 'entityId' => $entityId,
234 $res = \CSite::getById($siteId);
235 $site = $res->fetch();
237 $provider = Livefeed\Provider::init([
238 'ENTITY_TYPE' => $sourceEntityType,
239 'ENTITY_ID' => $sourceEntityId,
240 'ADDITIONAL_PARAMS' => $sourceEntityData,
249 $commentProvider =
false;
250 if ($postProvider =
Livefeed\Provider::getProvider($postEntityType))
252 $commentProvider = $postProvider->getCommentProvider();
255 if (!$commentProvider)
260 if ($postProvider::className() === $provider::className())
262 $commentProvider->setParentProvider($provider);
266 $postEntityId = $provider->getParentEntityId();
267 $postProvider->setEntityId($postEntityId);
268 $commentProvider->setParentProvider($postProvider);
271 $logId = $provider->getLogId();
275 $provider->initSourceFields();
276 $logId = $provider->getLogId();
281 $commentProvider->setLogId($provider->getLogId());
285 'sourceType' => $sourceEntityType,
286 'sourceId' => $sourceEntityId,
287 'entityType' => $entityType,
288 'entityId' => $entityId,
291 $authorId = static::getEntityAuthorId([
292 'entityType' => $entityType,
293 'entityData' => $entity,
296 $sonetCommentData = $commentProvider->add([
297 'SITE_ID' => $siteId,
298 'AUTHOR_ID' => $authorId,
299 'MESSAGE' => CommentAux\CreateEntity::getPostText(),
300 'SHARE_DEST' => Json::encode($auxData),
302 'AUX_DATA' => $auxData,
306 $sonetCommentId = (int)($sonetCommentData[
'sonetCommentId'] ?? 0);
307 $sourceCommentId = (int)($sonetCommentData[
'sourceCommentId'] ?? 0);
311 && $sourceCommentId <= 0
318 isset($params[
'LIVE'])
319 && $params[
'LIVE'] ===
'Y'
322 $userPage = Option::get(
'socialnetwork',
'user_page', $site[
'DIR'] .
'company/personal/');
323 $provider->initSourceFields();
325 $auxLiveParamList = static::getAuxLiveParams([
326 'sourceEntityType' => $sourceEntityType,
327 'sourceEntityId' => $sourceEntityId,
328 'entityType' => $entityType,
329 'entityId' => $entityId,
330 'entityData' => $entity,
331 'sourceEntityLink' => $provider->getLiveFeedUrl(),
334 $liveCommentParams = [
336 'TIME_FORMAT' => \CSite::getTimeFormat(),
337 'NAME_TEMPLATE' => \CSite::getNameFormat(
null, $siteId),
339 'AVATAR_SIZE' => 100,
340 'LANGUAGE_ID' => $site[
'LANGUAGE_ID'],
341 'SITE_ID' => $siteId,
343 'AUX' =>
'createentity',
346 if ($sonetCommentId > 0)
348 $logCommentFields = \Bitrix\Socialnetwork\Item\LogComment::getById($sonetCommentId)->getFields();
352 '=ID' => $logCommentFields[
'LOG_ID']
354 'select' => [
'ID',
'ENTITY_TYPE',
'ENTITY_ID',
'USER_ID',
'EVENT_ID',
'SOURCE_ID' ],
356 if (!($logEntry = $res->fetch()))
361 $userPath = $userPage .
'user/' . $logEntry[
'USER_ID'] .
'/';
363 $auxLiveParamList[
'userPath'] = $userPath;
365 $serviceCommentProvider = CommentAux\Base::init(
366 CommentAux\CreateEntity::getType(),
368 'liveParamList' => $auxLiveParamList,
372 $commentEvent = \CSocNetLogTools::findLogCommentEventByLogEventID($logEntry[
'EVENT_ID']);
374 $liveCommentParams[
'SOURCE_ID'] = $logCommentFields[
'SOURCE_ID'];
375 $liveCommentParams[
'PATH_TO_USER'] = $userPath;
376 $liveCommentParams[
'AUX_LIVE_PARAMS'] = $serviceCommentProvider->getLiveParams();
380 $feedParams = $commentProvider->getFeedParams();
381 if (!empty($feedParams[
'xml_id']))
383 $liveCommentParams[
'ENTITY_XML_ID'] = $feedParams[
'xml_id'];
394 elseif ($sourceCommentId > 0)
396 $commentProvider->setEntityId($sourceCommentId);
397 $commentProvider->initSourceFields();
399 $serviceCommentProvider = CommentAux\Base::init(
400 CommentAux\CreateEntity::getType(),
402 'liveParamList' => $auxLiveParamList,
407 'postProvider' => $postProvider,
408 'commentProvider' => $commentProvider,
410 'languageId' => $site[
'LANGUAGE_ID'],
411 'nameTemplate' => \CSite::getNameFormat(
null, $siteId),
414 'aux' =>
'createentity',
415 'auxLiveParams' => $serviceCommentProvider->getLiveParams()
431 $entityType = ($params[
'entityType'] ??
false);
432 $entityId = (int)($params[
'entityId'] ?? 0);
442 $cacheKey = $entityType .
'_' . $entityId;
444 if (isset($cache[$cacheKey]))
446 return $cache[$cacheKey];
451 case CommentAux\CreateEntity::ENTITY_TYPE_TASK:
453 Loader::includeModule(
'tasks')
454 && ($task = \Bitrix\Tasks\Manager\Task::get($USER->getId(), $entityId))
457 $result = $task[
'DATA'];
460 case CommentAux\CreateEntity::ENTITY_TYPE_BLOG_POST:
463 $provider->setOption(
'checkAccess',
true);
464 $provider->setEntityId($entityId);
465 $provider->initSourceFields();
467 $post = $provider->getSourceFields();
470 $post[
'URL'] = $provider->getLiveFeedUrl();
474 case CommentAux\CreateEntity::ENTITY_TYPE_CALENDAR_EVENT:
475 if (Loader::includeModule(
'calendar'))
477 $res = \CCalendarEvent::getList(
482 'parseRecursion' =>
false,
483 'fetchAttendees' =>
false,
484 'checkPermissions' =>
true,
485 'setDefaultLimit' =>
false
489 if (is_array($res) && is_array($res[0]))
498 $cache[$cacheKey] = $result;
507 $entityType = ($params[
'entityType'] ??
false);
508 $entityData = ($params[
'entityData'] ?? []);
512 || empty($entityData)
513 || !is_array($entityData)
521 case CommentAux\CreateEntity::ENTITY_TYPE_TASK:
522 $result = (isset($entityData[
'CREATED_BY']) ? (int)$entityData[
'CREATED_BY'] : 0);
524 case CommentAux\CreateEntity::ENTITY_TYPE_BLOG_POST:
525 $result = (isset($entityData[
'AUTHOR_ID']) ? (int)$entityData[
'AUTHOR_ID'] : 0);
527 case CommentAux\CreateEntity::ENTITY_TYPE_CALENDAR_EVENT:
528 $result = (isset($entityData[
'OWNER_ID']) ? (int)$entityData[
'OWNER_ID'] : 0);
540 $sourceEntityType = ($params[
'sourceEntityType'] ??
false);
541 $sourceEntityId = (int)($params[
'sourceEntityId'] ?? 0);
542 $sourceData = ($params[
'sourceData'] ?? []);
543 $entityType = ($params[
'entityType'] ??
false);
544 $entityId = (int)($params[
'entityId'] ?? 0);
545 $entityData = ($params[
'entityData'] ?? []);
546 $userPath = ($params[
'userPath'] ??
'');
547 $logId = (int)($params[
'logId'] ?? 0);
551 || $sourceEntityId <= 0
554 || empty($entityData)
555 || !is_array($entityData)
561 $entityProvider = Livefeed\Provider::init([
562 'ENTITY_TYPE' => $sourceEntityType,
563 'ENTITY_ID' => $sourceEntityId,
567 $sourceEntityLink = (
569 'sourceEntityType' => $sourceEntityType,
570 'sourceEntityId' => $sourceEntityId,
571 'sourceData' => $sourceData,
572 'entityType' => $entityType,
573 'entityData' => $entityData,
574 'userPath' => $userPath,
579 'sourceEntityType' => $sourceEntityType,
580 'sourceEntityId' => $sourceEntityId,
581 'entityType' => $entityType,
582 'entityId' => $entityId,
583 'entityUrl' => static::getEntityUrl([
584 'entityType' => $entityType,
585 'entityData' => $entityData,
587 'entityName' => static::getEntityName([
588 'entityType' => $entityType,
589 'entityData' => $entityData,
591 'sourceEntityLink' => $sourceEntityLink,
592 'suffix' => $entityProvider->getSuffix(),
597 $result[
'taskResponsibleId'] = static::getEntityAuthorId([
598 'entityType' => $entityType,
599 'entityData' => $entityData,
604 && Loader::includeModule(
'blog')
607 $result[
'socNetPermissions'] = \CBlogPost::getSocNetPermsCode($entityId);
612 if (!empty($entityData[
'USER_IDS']) && is_array($entityData[
'USER_IDS']))
614 $attendees = $entityData[
'USER_IDS'];
616 elseif (!empty($entityData[
'attendeesEntityList']))
618 $attendees = array_map(
static function($item) {
619 return (
int)(isset($item[
'entityId'], $item[
'id']) && $item[
'entityId'] ===
'user' ? $item[
'id'] : 0);
620 }, $entityData[
'attendeesEntityList']);
621 $attendees = array_filter($attendees,
static function($item) {
627 !empty($entityData[
'MEETING_HOST'])
628 && (
int)$entityData[
'MEETING_HOST'] > 0
631 $attendees[] = (int)($entityData[
'MEETING_HOST']);
634 !empty($entityData[
'CREATED_BY'])
635 && (
int)$entityData[
'CREATED_BY'] > 0
638 $attendees[] = (int)($entityData[
'CREATED_BY']);
641 $result[
'attendees'] = array_unique($attendees);
651 $entityType = ($params[
'entityType'] ??
false);
652 $entityData = ($params[
'entityData'] ?? []);
656 || empty($entityData)
657 || !is_array($entityData)
665 case CommentAux\CreateEntity::ENTITY_TYPE_TASK:
666 if (Loader::includeModule(
'tasks'))
668 $result = \CTaskNotifications::getNotificationPath([
'ID' => $entityData[
'CREATED_BY']], $entityData[
'ID'],
false);
671 case CommentAux\CreateEntity::ENTITY_TYPE_BLOG_POST:
672 $result = $entityData[
'URL'];
674 case CommentAux\CreateEntity::ENTITY_TYPE_CALENDAR_EVENT:
676 $calendarEventProvider->setEntityId((
int)$entityData[
'ID']);
677 $calendarEventProvider->initSourceFields();
678 $result = $calendarEventProvider->getLiveFeedUrl();
737 $sourceEntityType = ($params[
'sourceEntityType'] ??
false);
738 $sourceEntityId = (int)($params[
'sourceEntityId'] ?? 0);
742 && Loader::includeModule(
'blog'))
748 if ($comment = \CBlogComment::getById($sourceEntityId))
750 $postId = $comment[
'POST_ID'];
755 $postId = $sourceEntityId;
760 || !($post = \CBlogPost::getById($postId))
769 $blogId = (int)$post[
'BLOG_ID'];