19 parent::__construct();
25 private static function getOrderFields()
30 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_LOG_DATE')
39 public static function onBuildSourceListHandler(Main\
Event $event)
42 $selector = $event->getParameter(
'SELECTOR');
46 $restrictions = $selector->getModuleRestrictions(
'socialnetwork');
49 && !empty($restrictions[
'SITE_ID'])
52 $siteId = $restrictions[
'SITE_ID'];
57 'ORDER' => self::getOrderFields(),
61 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_TITLE'),
62 'TYPE' => Landing\Node\Type::TEXT
65 'ID' =>
'PREVIEW_TEXT',
66 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_PREVIEW_TEXT'),
67 'TYPE' => Landing\Node\Type::TEXT
70 'ID' =>
'DETAIL_TEXT',
71 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_DETAIL_TEXT'),
72 'TYPE' => Landing\Node\Type::TEXT
75 'ID' =>
'AUTHOR_NAME_FORMATTED',
76 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_AUTHOR_NAME_FORMATTED'),
77 'TYPE' => Landing\Node\Type::TEXT
81 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_LOG_DATE'),
82 'TYPE' => Landing\Node\Type::TEXT
86 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_PICTURE'),
87 'TYPE' => Landing\Node\Type::IMAGE
90 'ID' =>
'AUTHOR_AVATAR',
91 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_FIELD_AUTHOR_AVATAR'),
92 'TYPE' => Landing\Node\Type::IMAGE
96 'NAME' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_ACTIONS'),
97 'TYPE' => Landing\Node\Type::LINK,
98 'ACTIONS' => $selector->getDefaultLinkActions()
106 'SOURCE_ID' =>
'livefeed',
107 'TITLE' =>
Loc::getMessage(
'SONET_LANDING_DYNAMIC_BLOCK_LIVEFEED_TITLE2'),
108 'TYPE' => Landing\Source\Selector::SOURCE_TYPE_COMPONENT,
110 'COMPONENT_NAME' =>
'bitrix:socialnetwork.landing.livefeed.selector',
111 'COMPONENT_TEMPLATE_NAME' =>
'.default',
112 'COMPONENT_PARAMS' => [
113 'SITE_ID' => $siteId,
115 "USE_UI_TOOLBAR" =>
"Y",
117 'USE_PADDING' =>
false,
118 'PLAIN_VIEW' =>
false,
119 'USE_UI_TOOLBAR' =>
'Y'
122 'SOURCE_FILTER' => [],
123 'DATA_SETTINGS' => $dataSettings,
124 'DATA_LOADER' => __CLASS__
130 return new Main\EventResult(Main\EventResult::SUCCESS, $result,
'socialnetwork');
136 private function getRightsFilter()
138 global $CACHE_MANAGER;
143 if (!is_array($settingsFilter))
145 $settingsFilter = [];
148 foreach ($settingsFilter as $filterField)
151 !empty($filterField[
'key'])
152 && !empty($filterField[
'value'])
153 && $filterField[
'key'] ==
'GROUP_ID'
154 && $filterField[
'value'] !=
'all'
157 $result[] = $filterField[
'value'];
159 if (defined(
"BX_COMP_MANAGED_CACHE"))
161 $CACHE_MANAGER->registerTag(
"landing_dynamic_filter_".$filterField[
'value']);
166 $groupIdList = array_filter(array_map(
function($val) {
168 if (preg_match(
'/^SG(\d+)$/i', $val, $matches))
170 $res = intval($matches[1]);
174 }, $result),
function ($val) {
178 if (empty($groupIdList))
184 $res = WorkgroupTable::getList([
188 '@ID' => $groupIdList
192 while ($workgroupFields = $res->fetch())
194 $result[] =
'SG'.$workgroupFields[
'ID'];
203 private function getAuthorFilter()
208 if (!is_array($settingsFilter))
210 $settingsFilter = [];
213 foreach ($settingsFilter as $filterField)
216 !empty($filterField[
'key'])
217 && !empty($filterField[
'value'])
218 && $filterField[
'key'] ==
'AUTHOR_ID'
219 && $filterField[
'value'] !=
'all'
222 $result[] = $filterField[
'value'];
226 $authorIdList = array_filter(array_map(
function($val) {
228 if (preg_match(
'/^U(\d+)$/i', $val, $matches))
230 $res = intval($matches[1]);
234 }, $result),
function ($val) {
238 if (empty($authorIdList))
244 $res = UserTable::getList([
247 '@ID' => $authorIdList
251 while ($userFields = $res->fetch())
253 $result[] = $userFields[
'ID'];
268 $rightsFilter = $this->getRightsFilter();
269 $authorFilter = $this->getAuthorFilter();
271 if (empty($rightsFilter))
276 $orderFields = self::getOrderFields();
279 if (!is_array($order))
288 && !empty($order[
'by'])
289 && !empty($order[
'order'])
292 foreach($orderFields as $field)
294 if ($order[
'by'] == $field[
'ID'])
297 $order[
'by'] => $order[
'order']
303 if (empty($livefeedOrder))
311 'LOG_RIGHTS' => $rightsFilter,
312 'EVENT_ID' => \CSocNetLogTools::findFullSetByEventID(
'blog_post'),
313 '<=LOG_DATE' =>
'NOW',
317 !empty($authorFilter)
318 && is_array($authorFilter)
319 && !empty($authorFilter[0])
322 $livefeedFilter[
'USER_ID'] = intval($authorFilter[0]);
326 'order' => $livefeedOrder,
327 'filter' => $livefeedFilter,
333 $result = $this->getElementsInternal($settings);
347 if (!is_string($element) && !is_int($element))
349 $element = (int)$element;
353 $rightsFilter = $this->getRightsFilter();
354 if (empty($rightsFilter))
362 'SOURCE_ID' => $element,
363 'LOG_RIGHTS' => $rightsFilter,
364 'EVENT_ID' => \CSocNetLogTools::findFullSetByEventID(
'blog_post'),
365 '<=LOG_DATE' =>
'NOW',
372 $result = $this->getElementsInternal($settings);
376 $current = reset($result);
377 if (!empty($current))
379 $this->seo->setTitle($current[
'TITLE']);
390 private function getElementsInternal(array $settings)
392 global $CACHE_MANAGER, $USER_FIELD_MANAGER;
396 $pathToSmile = Main\Config\Option::get(
"socialnetwork",
"smile_page",
false, SITE_ID);
397 $pathToSmile = ($pathToSmile ? $pathToSmile :
"/bitrix/images/socialnetwork/smile/");
399 $parserParams = Array(
401 "imageHeight" => 500,
418 "SHORT_ANCHOR" =>
"Y"
420 if(Main\
Config\Option::get(
"blog",
"allow_video",
"Y") !=
"Y")
422 $allow[
"VIDEO"] =
"N";
425 $iterator = \CSocNetLog::getList(
432 'CHECK_RIGHTS' =>
'N',
434 'USE_SUBSCRIBE' =>
'N',
435 'USE_FAVORITES' =>
'N',
439 $blogPostIdList = [];
440 while ($row = $iterator->fetch())
442 $blogPostIdList[] = $row[
'SOURCE_ID'];
445 $diskInstalled = Main\Loader::includeModule(
'disk');
448 !empty($blogPostIdList)
449 && Main\Loader::includeModule(
'blog')
454 $driver = \Bitrix\Disk\Driver::getInstance();
455 $urlManager = $driver->getUrlManager();
459 $query = new \Bitrix\Main\Entity\Query(PostTable::getEntity());
460 $query->addOrder(
'DATE_PUBLISH',
'DESC');
461 $query->addFilter(
'@ID', $blogPostIdList);
462 $query->addSelect(
'ID');
463 $query->addSelect(
'MICRO');
464 $query->addSelect(
'TITLE');
465 $query->addSelect(
'DETAIL_TEXT');
466 $query->addSelect(
'AUTHOR_ID');
467 $query->addSelect(
'DATE_PUBLISH');
469 $query->registerRuntimeField(
471 new \
Bitrix\Main\Entity\ReferenceField(
'U',
472 UserTable::getEntity(),
474 '=ref.ID' =>
'this.AUTHOR_ID'
476 array(
'join_type' =>
'INNER')
479 $query->addSelect(
'U.PERSONAL_PHOTO',
'AUTHOR_AVATAR');
480 $query->addSelect(
'U.NAME',
'AUTHOR_NAME');
481 $query->addSelect(
'U.LAST_NAME',
'AUTHOR_LAST_NAME');
482 $query->addSelect(
'U.SECOND_NAME',
'AUTHOR_SECOND_NAME');
483 $query->addSelect(
'U.LOGIN',
'AUTHOR_LOGIN');
485 $iterator = $query->exec();
486 while ($row = $iterator->fetch())
488 if (defined(
"BX_COMP_MANAGED_CACHE"))
490 $CACHE_MANAGER->registerTag(
"blog_post_".$row[
'ID']);
493 $attachedFilesList = [];
497 $res = \Bitrix\Disk\AttachedObject::getList(array(
499 '=ENTITY_TYPE' => \
Bitrix\Disk\Uf\BlogPostConnector::className(),
502 'select' => array(
'ID',
'OBJECT_ID',
'FILENAME' =>
'OBJECT.NAME')
504 foreach ($res as $attachedObjectFields)
506 $attachedObjectFields[
'URL'] = (\Bitrix\Disk\TypeFile::isImage($attachedObjectFields[
'FILENAME'])
507 ? $urlManager->getUrlUfController(
'show', array(
'attachedId' => $attachedObjectFields[
'ID']))
510 $attachedFilesList[] = $attachedObjectFields;
514 $detailTextInOneString = str_replace(
"\r\n",
"", $row[
"DETAIL_TEXT"]);
516 $inlineAttachmentsList = [];
517 if (preg_match_all(
'/\[DISK\sFILE\sID=([n]*)(\d+)\]/', $row[
"DETAIL_TEXT"], $matches))
519 foreach($matches[2] as $key => $value)
521 $inlineAttachmentsList[] = [
523 'KEY' => ($matches[1][$key] ===
'n' ?
'OBJECT_ID' :
'ID'),
524 'POSITION' => mb_strpos($detailTextInOneString, $matches[0][$key])
530 $diskPicturePosition =
false;
531 foreach($inlineAttachmentsList as $inlineAttachment)
533 foreach($attachedFilesList as $attachedFile)
536 $attachedFile[$inlineAttachment[
'KEY']] == $inlineAttachment[
'ID']
537 && !empty($attachedFile[
'URL'])
541 'alt' => (!empty($attachedFile[
'FILENAME']) ? $attachedFile[
'FILENAME'] :
''),
542 'src' => $attachedFile[
'URL']
544 $diskPicturePosition = $inlineAttachment[
'POSITION'];
554 $imgPattern =
'/\[IMG\s+WIDTH\s*=\s*\d+\s+HEIGHT\s*=\s*\d+\s*\](.+?)\[\/IMG\]/is'.BX_UTF_PCRE_MODIFIER;
555 $videoPattern =
'/\[VIDEO[^\]]*](.+?)\[\/VIDEO\]/is'.BX_UTF_PCRE_MODIFIER;
556 $detailText = \Bitrix\Socialnetwork\Helper\Mention::clear($row[
'DETAIL_TEXT']);
559 preg_match_all($imgPattern, $detailText, $matches)
560 && !empty($matches[0])
561 && !empty($matches[0][0])
565 $diskPicturePosition ===
false
566 || mb_strpos($detailTextInOneString, $matches[0][0]) < $diskPicturePosition
571 'src' => $matches[1][0]
576 $parser = new \blogTextParser(
false, $pathToSmile, []);
577 $parser->LAZYLOAD =
"N";
579 $postFields = $USER_FIELD_MANAGER->getUserFields(
"BLOG_POST", $row[
'ID'], LANGUAGE_ID);
580 if (!empty($postFields[
"UF_BLOG_POST_FILE"]))
582 $parser->arUserfields = array(
"UF_BLOG_POST_FILE" => array_merge($postFields[
"UF_BLOG_POST_FILE"], [
"TAG" =>
"DOCUMENT ID"]));
585 $clearedText = $detailText;
587 $clearedText = preg_replace(
588 [ $imgPattern, $videoPattern ],
592 $clearedText = preg_replace(
593 '/\[URL(.*?)]([^\]\s]{20,})\[\/URL\]/is'.BX_UTF_PCRE_MODIFIER,
597 $clearedText = preg_replace(
598 '/\[URL(.*?)]((?:[^\]\s]{1,19}\s+)+)\[\/URL\]/is'.BX_UTF_PCRE_MODIFIER,
602 $clearedText = preg_replace(
603 '/\[URL(.*?)]((?:[^\]\s]{1,19}\s+)+)\[\/URL\]/is'.BX_UTF_PCRE_MODIFIER,
607 $clearedText = \blogTextParser::killAllTags($clearedText);
611 ? truncateText($clearedText, 100)
612 : htmlspecialcharsEx($row[
"TITLE"])
617 if (intval($row[
'AUTHOR_AVATAR']) > 0)
619 $fileRes = FileTable::getById(intval($row[
'AUTHOR_AVATAR']));
620 if ($fileFields = $fileRes->fetch())
624 'src' => \CFile::getFileSrc($fileFields)
628 if (intval($row[
'AUTHOR_ID']) > 0)
630 $authorName = \CUser::formatName(\CSite::getNameFormat(), [
631 "NAME" => $row[
"AUTHOR_NAME"],
632 "LAST_NAME" => $row[
"AUTHOR_LAST_NAME"],
633 "SECOND_NAME" => $row[
"AUTHOR_SECOND_NAME"],
634 "LOGIN" => $row[
"AUTHOR_LOGIN"],
635 "NAME_LIST_FORMATTED" =>
"",
638 if ($row[
'DATE_PUBLISH'] instanceof \
Bitrix\Main\
Type\DateTime)
640 $logDate = $row[
'DATE_PUBLISH']->format(\
Bitrix\Main\
Type\Date::getFormat());
646 'PREVIEW_TEXT' => truncateText($clearedText, 255),
647 'DETAIL_TEXT' => $parser->convert($detailText,
false, [], $allow, $parserParams),
648 'PICTURE' => $picture,
649 'AUTHOR_AVATAR' => $authorAvatar,
650 'AUTHOR_NAME_FORMATTED' => $authorName,
651 'LOG_DATE' => $logDate,
656 usort($result,
function($a, $b) use ($blogPostIdList) {
657 $keyA = array_search($a[
'ID'], $blogPostIdList);
658 $keyB = array_search($b[
'ID'], $blogPostIdList);
659 return ($keyA > $keyB) ? +1 : -1;
673 global $CACHE_MANAGER;
676 defined(
"BX_COMP_MANAGED_CACHE")
678 && preg_match(
'/^SG(\d+)$/i', $code, $matches)
679 && Main\ModuleManager::isModuleInstalled(
'landing')
682 $CACHE_MANAGER->clearByTag(
"landing_dynamic_filter_".$code);
692 if (!is_array($filter))
702 foreach ($filter as $row)
704 if (empty($row) || !is_array($row))
708 if (empty($row[
'key']) || empty($row[
'value']))
718 Main\Type\Collection::sortByColumn($result, [
'key' => SORT_ASC]);