1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
rest.php
См. документацию.
1<?php
2
3use Bitrix\Disk\File;
4use Bitrix\Intranet\Integration\Templates\Bitrix24\ThemePicker;
21
22if (!Loader::includeModule('rest'))
23{
24 return;
25}
26
28{
29 public const PERM_DENY = 'D';
30 public const PERM_READ = 'R';
31 public const PERM_WRITE = 'W';
32
33 private static $arAllowedOperations = array('', '!', '<', '<=', '>', '>=', '><', '!><', '?', '=', '!=', '%', '!%', '');
34
35 public static function OnRestServiceBuildDescription(): array
36 {
37 return array(
38 "log" => array(
39 "log.blogpost.get" => array("CSocNetLogRestService", "getBlogPost"),
40 'log.blogpost.user.get' => array('callback' => array(__CLASS__, 'getUserBlogPost'), 'options' => array('private' => true)),
41 "log.blogpost.add" => array("CSocNetLogRestService", "addBlogPost"),
42 "log.blogpost.update" => array("CSocNetLogRestService", "updateBlogPost"),
43 "log.blogpost.share" => array("CSocNetLogRestService", "shareBlogPost"),
44 "log.blogpost.delete" => array("CSocNetLogRestService", "deleteBlogPost"),
45 "log.blogpost.getusers.important" => array("CSocNetLogRestService", "getBlogPostUsersImprtnt"),
46 "log.blogcomment.add" => array("CSocNetLogRestService", "addBlogComment"),
47 'log.blogcomment.user.get' => array('callback' => array(__CLASS__, 'getUserBlogComment'), 'options' => array('private' => true)),
48 "log.blogcomment.delete" => array("CSocNetLogRestService", "deleteBlogComment"),
49 'log.comment.user.get' => array('callback' => array(__CLASS__, 'getUserLogComment'), 'options' => array('private' => true)),
50 "log.comment.delete" => array("CSocNetLogRestService", "deleteLogComment"),
51 CRestUtil::EVENTS => array(
52 'onLivefeedPostAdd' => self::createEventInfo('socialnetwork', 'OnAfterSocNetLogAdd', array(CSocNetLogBlogPostRestProxy::class, 'processEvent')),
53 'onLivefeedPostUpdate' => self::createEventInfo('socialnetwork', 'OnAfterSocNetLogUpdate', array(CSocNetLogBlogPostRestProxy::class, 'processEvent')),
54 'onLivefeedPostDelete' => self::createEventInfo('socialnetwork', 'OnSocNetLogDelete', array(CSocNetLogBlogPostRestProxy::class, 'processEvent')),
55 ),
56 ),
57 "sonet_group" => array(
58 "sonet_group.get" => array("CSocNetLogRestService", "getGroup"),
59 "sonet_group.create" => array("CSocNetLogRestService", "createGroup"),
60 "sonet_group.update" => array("CSocNetLogRestService", "updateGroup"),
61 "sonet_group.delete" => array("CSocNetLogRestService", "deleteGroup"),
62 "sonet_group.setowner" => array("CSocNetLogRestService", "setGroupOwner"),
63 "sonet_group.user.get" => array("CSocNetLogRestService", "getGroupUsers"),
64 "sonet_group.user.invite" => array("CSocNetLogRestService", "inviteGroupUsers"),
65 "sonet_group.user.request" => array("CSocNetLogRestService", "requestGroupUser"),
66 "sonet_group.user.add" => array("CSocNetLogRestService", "addGroupUsers"),
67 "sonet_group.user.update" => array("CSocNetLogRestService", "updateGroupUsers"),
68 "sonet_group.user.delete" => array("CSocNetLogRestService", "deleteGroupUsers"),
69 "sonet_group.user.groups" => array("CSocNetLogRestService", "getUserGroups"),
70 "sonet_group.feature.access" => array("CSocNetLogRestService", "getGroupFeatureAccess"),
71 "sonet_group_subject.get" => array("CSocNetLogRestService", "getGroupSubject"),
72 "sonet_group_subject.add" => array("CSocNetLogRestService", "addGroupSubject"),
73 "sonet_group_subject.update" => array("CSocNetLogRestService", "updateGroupSubject"),
74 "sonet_group_subject.delete" => array("CSocNetLogRestService", "deleteGroupSubject"),
75 CRestUtil::EVENTS => array(
76 'onSonetGroupAdd' => self::createEventInfo('socialnetwork', 'OnSocNetGroupAdd', array(CSocNetGroupRestProxy::class, 'processEvent')),
77 'onSonetGroupUpdate' => self::createEventInfo('socialnetwork', 'OnSocNetGroupUpdate', array(CSocNetGroupRestProxy::class, 'processEvent')),
78 'onSonetGroupDelete' => self::createEventInfo('socialnetwork', 'OnSocNetGroupDelete', array(CSocNetGroupRestProxy::class, 'processEvent')),
79 'onSonetGroupSubjectAdd' => self::createEventInfo('socialnetwork', 'OnSocNetGroupSubjectAdd', array(CSocNetGroupSubjectRestProxy::class, 'processEvent')),
80 'onSonetGroupSubjectUpdate' => self::createEventInfo('socialnetwork', 'OnSocNetGroupSubjectUpdate', array(CSocNetGroupSubjectRestProxy::class, 'processEvent')),
81 'onSonetGroupSubjectDelete' => self::createEventInfo('socialnetwork', 'OnSocNetGroupSubjectDelete', array(CSocNetGroupSubjectRestProxy::class, 'processEvent'))
82 ),
83 CRestUtil::PLACEMENTS => array(
84 'SONET_GROUP_DETAIL_TAB' => array()
85 ),
86 )
87 );
88 }
89
90 public static function createEventInfo($moduleName, $eventName, array $callback): array
91 {
92 return array($moduleName, $eventName, $callback, array('category' => \Bitrix\Rest\Sqs::CATEGORY_DEFAULT));
93 }
94
95 private static function getBlogPostEventId(): array
96 {
97 static $blogPostEventIdList = null;
98 if ($blogPostEventIdList === null)
99 {
100 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
101 $blogPostEventIdList = $blogPostLivefeedProvider->getEventId();
102 }
103
104 $arEventId = $blogPostEventIdList;
105 $arEventIdFullset = array();
106 foreach ($arEventId as $eventId)
107 {
108 $arEventIdFullset = array_merge($arEventIdFullset, CSocNetLogTools::FindFullSetByEventID($eventId));
109 }
110
111 return array_unique($arEventIdFullset);
112 }
113
114 private static function getBlogCommentEventId(): ?array
115 {
116 static $blogCommentEventIdList = null;
117 if ($blogCommentEventIdList === null)
118 {
119 $blogCommentLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogComment;
120 $blogCommentEventIdList = $blogCommentLivefeedProvider->getEventId();
121 }
122
123 return $blogCommentEventIdList;
124 }
125
126 private static function getLogCommentEventId(): ?array
127 {
128 static $logCommentEventIdList = null;
129 if ($logCommentEventIdList === null)
130 {
131 $logCommentLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\LogComment;
132 $logCommentEventIdList = $logCommentLivefeedProvider->getEventId();
133 }
134
135 return $logCommentEventIdList;
136 }
137
138 public static function getBlogPost($fields, $n, $server): array
139 {
140 global $USER_FIELD_MANAGER;
141
142 $result = array();
143 if (!CModule::IncludeModule("blog"))
144 {
145 return $result;
146 }
147
148 $tzOffset = CTimeZone::getOffset();
149 $arOrder = [ 'LOG_UPDATE' => 'DESC' ];
150
151 $res = CUser::getById(self::getCurrentUserId());
152 if ($userFields = $res->Fetch())
153 {
154 $currentUserIntranet = (
155 !empty($userFields["UF_DEPARTMENT"])
156 && is_array($userFields["UF_DEPARTMENT"])
157 && (int)$userFields["UF_DEPARTMENT"][0] > 0
158 );
159
160 $extranetSiteId = self::getExtranetSiteId();
161
162 if (
163 empty($extranetSiteId)
164 || $currentUserIntranet
165 )
166 {
167 $userSiteFields = CSocNetLogComponent::getSiteByDepartmentId($userFields["UF_DEPARTMENT"]);
168 if (!empty($userSiteFields))
169 {
170 $siteId = $userSiteFields['LID'];
171 }
172 }
173 elseif (
174 !empty($extranetSiteId)
175 && !$currentUserIntranet
176 )
177 {
178 $siteId = $extranetSiteId;
179 }
180 else
181 {
182 $siteId = CSite::getDefSite();
183 }
184 }
185
186 $filter = [
187 "EVENT_ID" => self::getBlogPostEventId(),
188 "SITE_ID" => [ $siteId, false ],
189 "<=LOG_DATE" => "NOW"
190 ];
191
192 if (
193 isset($fields['POST_ID'])
194 && (int)$fields['POST_ID'] > 0
195 )
196 {
197 $filter['SOURCE_ID'] = $fields['POST_ID'];
198 }
199 elseif (
200 isset($fields['LOG_RIGHTS'])
201 && is_array($fields['LOG_RIGHTS'])
202 )
203 {
204 $filter["LOG_RIGHTS"] = $fields['LOG_RIGHTS'];
205 }
206
207 $arListParams = array(
208 "CHECK_RIGHTS" => "Y",
209 "USE_FOLLOW" => "N",
210 "USE_SUBSCRIBE" => "N"
211 );
212
214 $arOrder,
215 $filter,
216 false,
217 self::getNavData($n),
218 array("ID", "SOURCE_ID"),
219 $arListParams
220 );
221
222 $arPostId = $arPostIdToGet = array();
223
224 while ($arLog = $dbLog->Fetch())
225 {
226 $arPostId[] = $arLog["SOURCE_ID"];
227 }
228
229 $cacheTtl = 2592000;
230
231 foreach ($arPostId as $key => $postId)
232 {
233 $cacheId = 'blog_post_socnet_rest_'.$postId.'_ru'.($tzOffset <> 0 ? '_'.$tzOffset : '');
235 'TYPE' => 'post',
236 'POST_ID' => $postId
237 ));
238 $obCache = new CPHPCache;
239 if ($obCache->InitCache($cacheTtl, $cacheId, $cacheDir))
240 {
241 $result[$key] = $obCache->GetVars();
242 }
243 else
244 {
245 $arPostIdToGet[$key] = $postId;
246 }
247 $obCache->EndDataCache();
248 }
249
250 if (!empty($arPostIdToGet))
251 {
252 foreach ($arPostIdToGet as $key => $postId)
253 {
254 $cacheId = 'blog_post_socnet_rest_'.$postId.'_ru'.($tzOffset <> 0 ? '_'.$tzOffset : '');
256 'TYPE' => 'post_general',
257 'POST_ID' => $postId
258 ));
259 $obCache = new CPHPCache;
260 $obCache->InitCache($cacheTtl, $cacheId, $cacheDir);
261
262 $obCache->StartDataCache();
263
264 $dbPost = CBlogPost::GetList(
265 array(),
266 array("ID" => $postId),
267 false,
268 false,
269 array(
270 "ID",
271 "BLOG_ID",
272 "PUBLISH_STATUS",
273 "TITLE",
274 "AUTHOR_ID",
275 "ENABLE_COMMENTS",
276 "NUM_COMMENTS",
277 "CODE",
278 "MICRO",
279 "DETAIL_TEXT",
280 "DATE_PUBLISH",
281 "CATEGORY_ID",
282 "HAS_SOCNET_ALL",
283 "HAS_TAGS",
284 "HAS_IMAGES",
285 "HAS_PROPS",
286 "HAS_COMMENT_IMAGES"
287 )
288 );
289
290 if ($arPost = $dbPost->Fetch())
291 {
292 if (!empty($arPost['DETAIL_TEXT']))
293 {
294 $arPost['DETAIL_TEXT'] = Emoji::decode($arPost['DETAIL_TEXT']);
295 }
296
297 if ($arPost["PUBLISH_STATUS"] !== BLOG_PUBLISH_STATUS_PUBLISH)
298 {
299 unset($arPost);
300 }
301 else
302 {
303 if (!empty($arPost['DATE_PUBLISH']))
304 {
305 $arPost['DATE_PUBLISH'] = CRestUtil::convertDateTime($arPost['DATE_PUBLISH']);
306 }
307
308 if ($arPost["HAS_PROPS"] !== 'N')
309 {
310 $arPostFields = $USER_FIELD_MANAGER->GetUserFields("BLOG_POST", $arPost["ID"], LANGUAGE_ID);
311 $arPost = array_merge($arPost, $arPostFields);
312 }
313
314 if (
315 !empty($arPost['UF_BLOG_POST_FILE'])
316 && !empty($arPost['UF_BLOG_POST_FILE']['VALUE'])
317 )
318 {
319 $arPost['FILES'] = $arPost['UF_BLOG_POST_FILE']['VALUE'];
320 }
321
322 $result[$key] = $arPost;
323 }
324 }
325
326 $obCache->EndDataCache($arPost);
327 }
328 }
329
330 ksort($result);
331
333 }
334
335 public static function getUserBlogPost($arParams, $offset, CRestServer $server): array
336 {
337 $arParams = array_change_key_case($arParams, CASE_UPPER);
338
339 $result = Array(
340 'POSTS' => array(),
341 'FILES' => array(),
342 );
343
344 if (!Loader::includeModule("blog"))
345 {
346 return $result;
347 }
348
349 $userId = (int)(
350 isset($arParams["USER_ID"])
351 && (int)$arParams["USER_ID"] > 0
352 && self::isAdmin()
353 ? $arParams["USER_ID"]
354 : self::getCurrentUserId()
355 );
356
357 $otherUserMode = ($userId !== self::getCurrentUserId());
358
359 if ($userId <= 0)
360 {
361 throw new RestException("User ID can't be empty", "ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
362 }
363
364 if (isset($arParams['FIRST_ID']))
365 {
366 $options['FIRST_ID'] = (int)$arParams['FIRST_ID'];
367 }
368 else
369 {
370 $options['LAST_ID'] = isset($arParams['LAST_ID']) && (int)$arParams['LAST_ID'] > 0 ? (int)$arParams['LAST_ID'] : 0;
371 }
372
373 $options['LIMIT'] = isset($arParams['LIMIT'])? ((int)$arParams['LIMIT'] > 1000 ? 1000 : (int)$arParams['LIMIT']) : 100;
374
375 $filter = [
376 '=USER_ID' => $userId,
377 '@EVENT_ID' => self::getBlogPostEventId()
378 ];
379
380 if (isset($options['FIRST_ID']))
381 {
382 $order = [];
383
384 if ((int)$options['FIRST_ID'] > 0)
385 {
386 $filter['>ID'] = $options['FIRST_ID'];
387 }
388 }
389 else
390 {
391 $order = [ 'ID' => 'DESC' ];
392
393 if (isset($options['LAST_ID']) && (int)$options['LAST_ID'] > 0)
394 {
395 $filter['<ID'] = (int)$options['LAST_ID'];
396 }
397 }
398
399 $logIdList = array();
400
402 'filter' => $filter,
403 'select' => array(
404 'ID', 'SOURCE_ID'
405 ),
406 'order' => $order,
407 'limit' => $options['LIMIT']
408 ));
409
410 $postIdList = array();
411 while ($logFields = $res->fetch())
412 {
413 if ((int)$logFields['SOURCE_ID'] > 0)
414 {
415 $postIdList[] = $logFields['SOURCE_ID'];
416 $logIdList[$logFields['SOURCE_ID']] = $logFields['ID'];
417 }
418 }
419
420 $postIdList = array_unique($postIdList);
421 if (empty($postIdList))
422 {
423 return $result;
424 }
425
426 $res = Bitrix\Blog\PostTable::getList([
427 'filter' => [
428 '@ID' => $postIdList,
429 ],
430 'select' => [
431 'ID', 'DATE_CREATE', 'TITLE', 'DETAIL_TEXT', 'UF_BLOG_POST_FILE'
432 ],
433 'order' => [ 'ID' => 'DESC' ],
434 ]);
435
436 $attachedIdList = [];
437 $postAttachedList = [];
438
439 while ($postFields = $res->fetch())
440 {
441 $result['POSTS'][$postFields['ID']] = [
442 'ID' => (int)$logIdList[$postFields['ID']],
443 'POST_ID' => (int)$postFields['ID'],
444 'DATE_CREATE' => $postFields['DATE_CREATE'],
445 'TITLE' => ($otherUserMode ? '' : (string)$postFields['TITLE']),
446 'TEXT' => ($otherUserMode ? '' : (string)$postFields['DETAIL_TEXT']),
447 'ATTACH' => [],
448 ];
449 if (!empty($postFields['UF_BLOG_POST_FILE']))
450 {
451 if (is_array($postFields['UF_BLOG_POST_FILE']))
452 {
453 $attached = $postFields['UF_BLOG_POST_FILE'];
454 }
455 elseif ((int)$postFields['UF_BLOG_POST_FILE'] > 0)
456 {
457 $attached = array((int)$postFields['UF_BLOG_POST_FILE']);
458 }
459 else
460 {
461 $attached = array();
462 }
463
464 if (!empty($attached))
465 {
466 $attachedIdList = array_merge($attachedIdList, $attached);
467 }
468
469 $postAttachedList[$postFields['ID']] = $attached;
470 }
471 }
472
473 $attachedObjectList = [];
474
475 if (
476 !empty($attachedIdList)
477 && Loader::includeModule('disk')
478 )
479 {
480 $res = Bitrix\Disk\AttachedObject::getList([
481 'filter' => [
482 '@ID' => array_unique($attachedIdList)
483 ],
484 'select' => [ 'ID', 'OBJECT_ID' ],
485 ]);
486 while ($attachedObjectFields = $res->fetch())
487 {
488 $diskObjectId = $attachedObjectFields['OBJECT_ID'];
489
490 if ($fileData = self::getFileData($diskObjectId))
491 {
492 $attachedObjectList[$attachedObjectFields['ID']] = $diskObjectId;
493 $result['FILES'][$diskObjectId] = $fileData;
494 }
495 }
496 }
497
498 foreach ($result['POSTS'] as $key => $value)
499 {
500 if ($value['DATE_CREATE'] instanceof \Bitrix\Main\Type\DateTime)
501 {
502 $result['POSTS'][$key]['DATE_CREATE'] = date('c', $value['DATE_CREATE']->getTimestamp());
503 }
504
505 if (!empty($postAttachedList[$key]))
506 {
507 foreach ($postAttachedList[$key] as $attachedId)
508 {
509 if (!empty($attachedObjectList[$attachedId]))
510 {
511 $result['POSTS'][$key]['ATTACH'][] = $attachedObjectList[$attachedId];
512 }
513 }
514 }
515
516 $result['POSTS'][$key] = array_change_key_case($result['POSTS'][$key], CASE_LOWER);
517 }
518
519 $result['POSTS'] = array_values($result['POSTS']);
520 $result['FILES'] = self::convertFileData($result['FILES']);
521
522 return $result;
523 }
524
525 public static function addBlogPost($arFields)
526 {
527 global $APPLICATION;
528
529 try
530 {
531 $postId = Helper::addBlogPost($arFields, \Bitrix\Main\Engine\Controller::SCOPE_REST);
532 if ($postId <= 0)
533 {
534 $e = $APPLICATION->getException();
535 throw new RestException($e ? $e->getString() : 'Cannot add blog post');
536 }
537 }
538 catch (Exception $e)
539 {
540 throw new RestException($e->getMessage(), $e->getCode());
541 }
542
543 return $postId;
544 }
545
546 public static function updateBlogPost($arFields)
547 {
548 global $APPLICATION;
549
550 try
551 {
552 $postId = Helper::updateBlogPost($arFields, \Bitrix\Main\Engine\Controller::SCOPE_REST);
553 if ($postId <= 0)
554 {
555 $e = $APPLICATION->getException();
556 throw new RestException($e ? $e->getString() : 'Cannot update blog post');
557 }
558 }
559 catch (Exception $e)
560 {
561 throw new RestException($e->getMessage(), $e->getCode());
562 }
563
564 return $postId;
565 }
566
567 public static function deleteBlogPost($arFields): bool
568 {
569 try
570 {
571 $result = Helper::deleteBlogPost([
572 'POST_ID' => (int) ($arFields['POST_ID'] ?? null),
573 ]);
574 }
575 catch (Exception $e)
576 {
577 throw new RestException($e->getMessage(), $e->getCode());
578 }
579
580 return $result;
581 }
582
583 public static function shareBlogPost($fields): bool
584 {
585 $postId = (int)$fields['POST_ID'];
586
587 if ($postId <= 0)
588 {
589 throw new RestException('Wrong post ID');
590 }
591
592 if (!Loader::includeModule('blog'))
593 {
594 throw new RestException('Blog module not installed');
595 }
596
597 $siteId = (
598 is_set($fields, "SITE_ID")
599 && !empty($fields["SITE_ID"])
600 ? $fields["SITE_ID"]
601 : SITE_ID
602 );
603
604 $blogId = false;
605
606 if (
607 !is_set($fields, "BLOG_ID")
608 || (int)$fields["BLOG_ID"] <= 0
609 )
610 {
611 $res = \Bitrix\Blog\PostTable::getList(array(
612 'filter' => array(
613 '=ID' => $postId
614 ),
615 'select' => array('BLOG_ID')
616 ));
617 if (
618 ($postFields = $res->fetch())
619 && !empty($postFields['BLOG_ID'])
620 )
621 {
622 $blogId = (int)$postFields['BLOG_ID'];
623 }
624 }
625 else
626 {
627 $blogId = (int)$fields["BLOG_ID"];
628 }
629
630 $blogPostPermsNewList = $fields['DEST'];
631
632 if (!is_array($blogPostPermsNewList))
633 {
634 $blogPostPermsNewList = array($blogPostPermsNewList);
635 }
636
637 foreach ($blogPostPermsNewList as $key => $code)
638 {
639 if (
640 $code !== 'UA'
641 && !preg_match('/^SG(\d+)$/', $code, $matches)
642 && !preg_match('/^U(\d+)$/', $code, $matches)
643 && !preg_match('/^UE(.+)$/', $code, $matches)
644 && !preg_match('/^DR(\d+)$/', $code, $matches)
645 )
646 {
647 unset($blogPostPermsNewList[$key]);
648 }
649 }
650
651 if (empty($blogPostPermsNewList))
652 {
653 throw new RestException('Wrong destinations');
654 }
655
656 $currentUserId = (
657 isset($fields["USER_ID"])
658 && (int)$fields["USER_ID"] > 0
659 && self::isAdmin()
660 ? $fields["USER_ID"]
661 : self::getCurrentUserId()
662 );
663
664 $currentUserPerm = self::getBlogPostPerm(array(
665 'USER_ID' => $currentUserId,
666 'POST_ID' => $postId
667 ));
668
669 if ($currentUserPerm <= \Bitrix\Blog\Item\Permissions::READ)
670 {
671 throw new RestException('No read perms');
672 }
673
674 $resultFields = array(
675 'ERROR_MESSAGE' => false,
676 'PUBLISH_STATUS' => BLOG_PUBLISH_STATUS_PUBLISH
677 );
678
681 && (
682 !Loader::includeModule('bitrix24')
683 || CBitrix24::isEmailConfirmed()
684 )
685 )
686 {
687 $destinationList = $blogPostPermsNewList;
689 $blogPostPermsNewList = array_unique($destinationList);
690 }
691
693 'DEST' => $blogPostPermsNewList,
694 'SITE_ID' => $siteId,
695 'AUTHOR_ID' => $currentUserId,
696 ), $resultFields);
697
698 if ($resultFields['ERROR_MESSAGE'])
699 {
700 throw new RestException($resultFields['ERROR_MESSAGE']);
701 }
702
703 if ($resultFields['PUBLISH_STATUS'] !== BLOG_PUBLISH_STATUS_PUBLISH)
704 {
705 throw new RestException('No permissions to share by this user (ID =' . $currentUserId . ')');
706 }
707
708 $permsFull = array();
709 $blogPostPermsOldList = CBlogPost::getSocNetPerms($postId);
710
711 foreach ($blogPostPermsOldList as $type => $val)
712 {
713 foreach ($val as $id => $values)
714 {
715 if ($type !== 'U')
716 {
717 $permsFull[] = $type.$id;
718 }
719 else
720 {
721 $permsFull[] = (
722 in_array('US' . $id, $values, true)
723 ? 'UA'
724 : $type . $id
725 );
726 }
727 }
728 }
729
730 foreach ($permsNew as $key => $code)
731 {
732 if (!in_array($code, $permsFull))
733 {
734 $permsFull[] = $code;
735 }
736 else
737 {
738 unset($permsNew[$key]);
739 }
740 }
741
742 if (!empty($permsNew))
743 {
745 array(
746 "POST_ID" => $postId,
747 "BLOG_ID" => $blogId,
748 "SITE_ID" => $siteId,
749 "SONET_RIGHTS" => $permsFull,
750 "NEW_RIGHTS" => $permsNew,
751 "USER_ID" => $currentUserId
752 ),
753 array(
754 'PATH_TO_POST' => \Bitrix\Socialnetwork\Helper\Path::get('userblogpost_page', $siteId)
755 )
756 );
757 }
758
759 return true;
760 }
761
762 public static function getBlogPostUsersImprtnt($fields): array
763 {
764 global $CACHE_MANAGER;
765
766 if (!is_array($fields))
767 {
768 throw new RestException('Incorrect input data');
769 }
770
771 $arParams["postId"] = (int) ($fields['POST_ID'] ?? null);
772
773 if ($arParams['postId'] <= 0)
774 {
775 throw new RestException('Wrong post ID');
776 }
777
778 $arParams["nTopCount"] = 500;
779 $arParams["paramName"] = 'BLOG_POST_IMPRTNT';
780 $arParams["paramValue"] = 'Y';
781
782 $result = array();
783
784 $cache = new CPHPCache();
785 $cache_id = "blog_post_param_".serialize(array(
786 $arParams["postId"],
787 $arParams["nTopCount"],
788 $arParams["paramName"],
789 $arParams["paramValue"]
790 ));
791 $cache_path = $CACHE_MANAGER->GetCompCachePath(CComponentEngine::MakeComponentPath("socialnetwork.blog.blog"))."/".$arParams["postId"];
792 $cache_time = (defined("BX_COMP_MANAGED_CACHE") ? 3600*24*365 : 600);
793
794 if ($cache->InitCache($cache_time, $cache_id, $cache_path))
795 {
796 $result = $cache->GetVars();
797 }
798 else
799 {
800 $cache->StartDataCache($cache_time, $cache_id, $cache_path);
801
802 if (CModule::IncludeModule("blog"))
803 {
804 if (defined("BX_COMP_MANAGED_CACHE"))
805 {
806 $CACHE_MANAGER->StartTagCache($cache_path);
807 $CACHE_MANAGER->RegisterTag($arParams["paramName"].$arParams["postId"]);
808 }
809
810 if ($arBlogPost = CBlogPost::GetByID($arParams["postId"]))
811 {
812 $postPerms = CBlogPost::GetSocNetPostPerms($arParams["postId"], true, self::getCurrentUserId(), $arBlogPost["AUTHOR_ID"]);
813 if ($postPerms >= BLOG_PERMS_READ)
814 {
816 [],
817 [
818 'POST_ID' => $arParams["postId"],
819 'NAME' => $arParams["paramName"],
820 'VALUE' => $arParams["paramValue"],
821 'USER_ACTIVE' => 'Y',
822 ],
823 [
824 "nTopCount" => $arParams["nTopCount"],
825 'SELECT' => [ 'USER_ID' ],
826 ]
827 );
828 if ($res)
829 {
830 while ($userOptionFields = $res->fetch())
831 {
832 $result[] = $userOptionFields['USER_ID'];
833 }
834 }
835 }
836 }
837
838 if (defined("BX_COMP_MANAGED_CACHE"))
839 {
840 $CACHE_MANAGER->EndTagCache();
841 }
842
843 $cache->EndDataCache($result);
844 }
845 }
846
847 return $result;
848 }
849
850 public static function getUserBlogComment($arParams, $offset, CRestServer $server): array
851 {
852 $arParams = array_change_key_case($arParams, CASE_UPPER);
853
854 $result = Array(
855 'COMMENTS' => array(),
856 'FILES' => array(),
857 );
858
859 if (!Loader::includeModule("blog"))
860 {
861 return $result;
862 }
863
864 $userId = (int)(
865 isset($arParams["USER_ID"])
866 && (int)$arParams['USER_ID'] > 0
867 && self::isAdmin()
868 ? $arParams["USER_ID"]
869 : self::getCurrentUserId()
870 );
871
872 $otherUserMode = ($userId !== self::getCurrentUserId());
873
874 if ($userId <= 0)
875 {
876 throw new RestException("User ID can't be empty", "ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
877 }
878
879 if (isset($arParams['FIRST_ID']))
880 {
881 $options['FIRST_ID'] = (int)$arParams['FIRST_ID'];
882 }
883 else
884 {
885 $options['LAST_ID'] = (
886 isset($arParams['LAST_ID']) && (int)$arParams['LAST_ID'] > 0
887 ? (int)$arParams['LAST_ID']
888 : 0
889 );
890 }
891
892 $options['LIMIT'] = (
893 isset($arParams['LIMIT'])
894 ? (
895 (int)$arParams['LIMIT'] > 1000
896 ? 1000
897 : (int)$arParams['LIMIT'])
898 : 100
899 );
900
901 $filter = [
902 '=USER_ID' => $userId,
903 '@EVENT_ID' => self::getBlogCommentEventId(),
904 ];
905
906 if (isset($options['FIRST_ID']))
907 {
908 $order = array();
909
910 if ((int)$options['FIRST_ID'] > 0)
911 {
912 $filter['>ID'] = $options['FIRST_ID'];
913 }
914 }
915 else
916 {
917 $order = Array('ID' => 'DESC');
918
919 if (isset($options['LAST_ID']) && (int)$options['LAST_ID'] > 0)
920 {
921 $filter['<ID'] = (int)$options['LAST_ID'];
922 }
923 }
924
925 $logCommentIdList = array();
926
928 'filter' => $filter,
929 'select' => array(
930 'ID', 'SOURCE_ID'
931 ),
932 'order' => $order,
933 'limit' => $options['LIMIT']
934 ));
935
936 $commentIdList = [];
937 while ($logCommentFields = $res->fetch())
938 {
939 if ((int)$logCommentFields['SOURCE_ID'] > 0)
940 {
941 $commentIdList[] = $logCommentFields['SOURCE_ID'];
942 $logCommentIdList[$logCommentFields['SOURCE_ID']] = $logCommentFields['ID'];
943 }
944 }
945
946 $commentIdList = array_unique($commentIdList);
947 if (empty($commentIdList))
948 {
949 return $result;
950 }
951
952 $res = Bitrix\Blog\CommentTable::getList(array(
953 'filter' => array(
954 '@ID' => $commentIdList
955 ),
956 'select' => array(
957 'ID', 'AUTHOR_ID', 'POST_ID', 'DATE_CREATE', 'POST_TEXT', 'SHARE_DEST', 'UF_BLOG_COMMENT_FILE'
958 ),
959 'order' => array('ID' => 'DESC')
960 ));
961
962 $attachedIdList = array();
963 $commentAttachedList = array();
964
965 $loadedSocialnetwork = Loader::includeModule('socialnetwork');
966
967 while ($commentFields = $res->fetch())
968 {
969 $result['COMMENTS'][$commentFields['ID']] = array(
970 'ID' => (int)$logCommentIdList[$commentFields['ID']],
971 'COMMENT_ID' => (int)$commentFields['ID'],
972 'POST_ID' => (int)$commentFields['POST_ID'],
973 'DATE' => $commentFields['DATE_CREATE'],
974 'TEXT' => ($otherUserMode ? '' : (string)$commentFields['POST_TEXT']),
975 'ATTACH' => array()
976 );
977
978 if (
979 $loadedSocialnetwork
980 && ($commentAuxProvider = \Bitrix\Socialnetwork\CommentAux\Base::findProvider(
981 $commentFields,
982 array(
983 "mobile" => false,
984 "bPublicPage" => true,
985 "cache" => true
986 )
987 )
988 ))
989 {
990 $result['COMMENTS'][$commentFields['ID']]['TEXT'] = $commentAuxProvider->getText();
991 }
992
993 if (!empty($commentFields['UF_BLOG_COMMENT_FILE']))
994 {
995 if (is_array($commentFields['UF_BLOG_COMMENT_FILE']))
996 {
997 $attached = $commentFields['UF_BLOG_COMMENT_FILE'];
998 }
999 elseif ((int)$commentFields['UF_BLOG_COMMENT_FILE'] > 0)
1000 {
1001 $attached = [ (int)$commentFields['UF_BLOG_COMMENT_FILE'] ];
1002 }
1003 else
1004 {
1005 $attached = [];
1006 }
1007
1008 if (!empty($attached))
1009 {
1010 $attachedIdList = array_merge($attachedIdList, $attached);
1011 }
1012
1013 $commentAttachedList[$commentFields['ID']] = $attached;
1014 }
1015 }
1016
1017 $attachedObjectList = array();
1018
1019 if (
1020 !empty($attachedIdList)
1021 && Loader::includeModule('disk')
1022 )
1023 {
1024 $res = Bitrix\Disk\AttachedObject::getList(array(
1025 'filter' => array(
1026 '@ID' => array_unique($attachedIdList)
1027 ),
1028 'select' => array('ID', 'OBJECT_ID')
1029 ));
1030 while ($attachedObjectFields = $res->fetch())
1031 {
1032 $diskObjectId = $attachedObjectFields['OBJECT_ID'];
1033 if ($fileData = self::getFileData($diskObjectId))
1034 {
1035 $attachedObjectList[$attachedObjectFields['ID']] = $diskObjectId;
1036 $result['FILES'][$diskObjectId] = $fileData;
1037 }
1038 }
1039 }
1040
1041 foreach ($result['COMMENTS'] as $key => $value)
1042 {
1043 if ($value['DATE'] instanceof \Bitrix\Main\Type\DateTime)
1044 {
1045 $result['COMMENTS'][$key]['DATE'] = date('c', $value['DATE']->getTimestamp());
1046 }
1047
1048 if (!empty($commentAttachedList[$key]))
1049 {
1050 foreach ($commentAttachedList[$key] as $attachedId)
1051 {
1052 if (!empty($attachedObjectList[$attachedId]))
1053 {
1054 $result['COMMENTS'][$key]['ATTACH'][] = $attachedObjectList[$attachedId];
1055 }
1056 }
1057 }
1058
1059 $result['COMMENTS'][$key] = array_change_key_case($result['COMMENTS'][$key], CASE_LOWER);
1060 }
1061
1062 $result['COMMENTS'] = array_values($result['COMMENTS']);
1063 $result['FILES'] = self::convertFileData($result['FILES']);
1064
1065 return $result;
1066 }
1067
1068 public static function addBlogComment($fields): int
1069 {
1070 $authorId = (int)(
1071 isset($fields["USER_ID"])
1072 && (int)$fields["USER_ID"] > 0
1073 && self::isAdmin()
1074 ? $fields["USER_ID"]
1075 : self::getCurrentUserId()
1076 );
1077
1078 if (!Loader::includeModule('blog'))
1079 {
1080 throw new RestException('No blog module installed');
1081 }
1082
1083 $postId = (int) ($fields['POST_ID'] ?? null);
1084 if ($postId <= 0)
1085 {
1086 throw new RestException('No post found');
1087 }
1088
1089 $res = CBlogPost::getList(
1090 array(),
1091 array(
1092 "ID" => $postId
1093 ),
1094 false,
1095 false,
1096 array("ID", "BLOG_ID", "AUTHOR_ID", "BLOG_OWNER_ID", "TITLE")
1097 );
1098
1099 $post = $res->fetch();
1100 if (!$post)
1101 {
1102 throw new RestException('No post found');
1103 }
1104
1105 $blog = CBlog::getById($post["BLOG_ID"]);
1106 if (!$blog)
1107 {
1108 throw new RestException('No blog found');
1109 }
1110
1111 if (
1112 empty($fields["FILES"])
1113 && !\Bitrix\Blog\Item\Comment::checkDuplicate(array(
1114 'MESSAGE' => $fields["TEXT"] ?? null,
1115 'BLOG_ID' => $post['BLOG_ID'],
1116 'POST_ID' => $post['ID'],
1117 'AUTHOR_ID' => $authorId,
1118 ))
1119 )
1120 {
1121 throw new RestException('Duplicate comment');
1122 }
1123
1124 $userIP = CBlogUser::getUserIP();
1125
1126 $commentFields = array(
1127 "POST_ID" => $post['ID'],
1128 "BLOG_ID" => $post['BLOG_ID'],
1129 "TITLE" => '',
1130 "POST_TEXT" => $fields["TEXT"],
1131 "DATE_CREATE" => convertTimeStamp(time() + CTimeZone::getOffset(), "FULL"),
1132 "AUTHOR_IP" => $userIP[0],
1133 "AUTHOR_IP1" => $userIP[1],
1134 "URL" => $blog["URL"],
1135 "PARENT_ID" => false,
1136 "SEARCH_GROUP_ID" => $blog['GROUP_ID'],
1137 "AUTHOR_ID" => $authorId
1138 );
1139
1141 if ((int)$post['AUTHOR_ID'] === $authorId)
1142 {
1144 }
1145 else
1146 {
1147 $postPerm = CBlogPost::getSocNetPostPerms($post["ID"]);
1148 if ($postPerm > \Bitrix\Blog\Item\Permissions::DENY)
1149 {
1150 $perm = CBlogComment::getSocNetUserPerms($post["ID"], $post["AUTHOR_ID"]);
1151 }
1152 }
1153
1154 if ($perm === \Bitrix\Blog\Item\Permissions::DENY)
1155 {
1156 throw new RestException('No permissions');
1157 }
1158
1159 if ($perm === \Bitrix\Blog\Item\Permissions::PREMODERATE)
1160 {
1161 $commentFields["PUBLISH_STATUS"] = BLOG_PUBLISH_STATUS_READY;
1162 }
1163
1164 $result = CBlogComment::add($commentFields);
1165 if (!$result)
1166 {
1167 throw new RestException('Blog comment hasn\'t been added');
1168 }
1169
1170 if (
1171 isset($fields["FILES"])
1172 && Option::get('disk', 'successfully_converted', false)
1173 && Loader::includeModule('disk')
1174 && ($storage = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($authorId))
1175 && ($folder = $storage->getFolderForUploadedFiles())
1176 )
1177 {
1178 // upload to storage
1179 $filesList = array();
1180
1181 foreach ($fields["FILES"] as $tmp)
1182 {
1183 $fileFields = CRestUtil::saveFile($tmp);
1184
1185 if (is_array($fileFields))
1186 {
1187 $file = $folder->uploadFile(
1188 $fileFields, // file array
1189 array(
1190 'NAME' => $fileFields["name"],
1191 'CREATED_BY' => $authorId
1192 ),
1193 array(),
1194 true
1195 );
1196
1197 if ($file)
1198 {
1199 $filesList[] = \Bitrix\Disk\Uf\FileUserType::NEW_FILE_PREFIX.$file->getId();
1200 }
1201 }
1202 }
1203
1204 if (!empty($filesList)) // update post
1205 {
1206 CBlogComment::update(
1207 $result,
1208 array(
1209 "HAS_PROPS" => "Y",
1210 "UF_BLOG_COMMENT_FILE" => $filesList
1211 )
1212 );
1213 }
1214 }
1215
1217 'MESSAGE' => $commentFields["POST_TEXT"],
1218 'BLOG_ID' => $post["BLOG_ID"],
1219 'BLOG_OWNER_ID' => $post["BLOG_OWNER_ID"],
1220 'POST_ID' => $post["ID"],
1221 'POST_TITLE' => $post["TITLE"],
1222 'POST_AUTHOR_ID' => $post["AUTHOR_ID"],
1223 'COMMENT_ID' => $result,
1224 'AUTHOR_ID' => $authorId,
1225 ));
1226
1227 return $result;
1228 }
1229
1230 public static function deleteBlogComment($fields): bool
1231 {
1232 $commentId = (int) ($fields['COMMENT_ID'] ?? null);
1233
1234 if ($commentId <= 0)
1235 {
1236 throw new RestException('Wrong comment ID');
1237 }
1238
1239 if (!Loader::includeModule('blog'))
1240 {
1241 throw new RestException('Blog module not installed');
1242 }
1243
1244 $currentUserId = (
1245 isset($fields["USER_ID"])
1246 && (int)$fields["USER_ID"] > 0
1247 && self::isAdmin()
1248 ? $fields["USER_ID"]
1249 : self::getCurrentUserId()
1250 );
1251
1252 $currentUserPerm = self::getBlogCommentPerm(array(
1253 'USER_ID' => $currentUserId,
1254 'COMMENT_ID' => $commentId
1255 ));
1256
1257 if ($currentUserPerm < \Bitrix\Blog\Item\Permissions::FULL)
1258 {
1259 throw new RestException('No delete perms');
1260 }
1261
1262 $commentFields = \Bitrix\Blog\Item\Comment::getById($commentId)->getFields();
1263 if (empty($commentId))
1264 {
1265 throw new RestException('No comment found');
1266 }
1267
1268 if ($result = CBlogComment::Delete($commentId))
1269 {
1271 'TYPE' => 'post_comments',
1272 'POST_ID' => $commentFields["POST_ID"]
1273 )));
1274 CBlogComment::DeleteLog($commentId);
1275 }
1276
1277 return (bool)$result;
1278 }
1279
1280 public static function getUserLogComment($arParams, $offset, CRestServer $server): array
1281 {
1282 $arParams = array_change_key_case($arParams, CASE_UPPER);
1283
1284 $result = [
1285 'COMMENTS' => [],
1286 'FILES' => [],
1287 ];
1288
1289 $userId = (int)(
1290 isset($arParams["USER_ID"])
1291 && (int)$arParams["USER_ID"] > 0
1292 && self::isAdmin()
1293 ? $arParams["USER_ID"]
1294 : self::getCurrentUserId()
1295 );
1296
1297 $otherUserMode = ($userId !== self::getCurrentUserId());
1298
1299 if ($userId <= 0)
1300 {
1301 throw new RestException("User ID can't be empty", "ID_EMPTY", CRestServer::STATUS_WRONG_REQUEST);
1302 }
1303
1304 if (isset($arParams['FIRST_ID']))
1305 {
1306 $options['FIRST_ID'] = (int)$arParams['FIRST_ID'];
1307 }
1308 else
1309 {
1310 $options['LAST_ID'] = (
1311 isset($arParams['LAST_ID'])
1312 && (int)$arParams['LAST_ID'] > 0
1313 ? (int)$arParams['LAST_ID']
1314 : 0
1315 );
1316 }
1317
1318 $options['LIMIT'] = (
1319 isset($arParams['LIMIT'])
1320 ? (
1321 (int)$arParams['LIMIT'] > 1000
1322 ? 1000
1323 : (int)$arParams['LIMIT'])
1324 : 100
1325 );
1326
1327 $filter = array(
1328 '=USER_ID' => $userId,
1329 '@EVENT_ID' => self::getLogCommentEventId()
1330 );
1331
1332 if (isset($options['FIRST_ID']))
1333 {
1334 $order = array();
1335
1336 if ((int)$options['FIRST_ID'] > 0)
1337 {
1338 $filter['>ID'] = $options['FIRST_ID'];
1339 }
1340 }
1341 else
1342 {
1343 $order = [ 'ID' => 'DESC' ];
1344
1345 if (isset($options['LAST_ID']) && (int)$options['LAST_ID'] > 0)
1346 {
1347 $filter['<ID'] = (int)$options['LAST_ID'];
1348 }
1349 }
1350
1352 'filter' => $filter,
1353 'select' => array(
1354 'ID', 'LOG_ID', 'LOG_DATE', 'MESSAGE', 'UF_SONET_COM_DOC'
1355 ),
1356 'order' => $order,
1357 'limit' => $options['LIMIT']
1358 ));
1359
1360 $attachedIdList = array();
1361
1362 while ($commentFields = $res->fetch())
1363 {
1364 $result['COMMENTS'][$commentFields['ID']] = array(
1365 'ID' => (int)$commentFields['ID'],
1366 'COMMENT_ID' => (int)$commentFields['ID'],
1367 'LOG_ID' => (int)$commentFields['LOG_ID'],
1368 'DATE' => $commentFields['LOG_DATE'],
1369 'TEXT' => ($otherUserMode ? '' : (string)$commentFields['MESSAGE']),
1370 'ATTACH' => array()
1371 );
1372
1373 if (!empty($commentFields['UF_SONET_COM_DOC']))
1374 {
1375 if (is_array($commentFields['UF_SONET_COM_DOC']))
1376 {
1377 $attached = $commentFields['UF_SONET_COM_DOC'];
1378 }
1379 elseif ((int)$commentFields['UF_SONET_COM_DOC'] > 0)
1380 {
1381 $attached = array((int)$commentFields['UF_SONET_COM_DOC']);
1382 }
1383 else
1384 {
1385 $attached = array();
1386 }
1387
1388 if (!empty($attached))
1389 {
1390 $attachedIdList = array_merge($attachedIdList, $attached);
1391 }
1392
1393 $commentAttachedList[$commentFields['ID']] = $attached;
1394 }
1395 }
1396
1397 $attachedObjectList = array();
1398
1399 if (
1400 !empty($attachedIdList)
1401 && Loader::includeModule('disk')
1402 )
1403 {
1404 $res = Bitrix\Disk\AttachedObject::getList(array(
1405 'filter' => array(
1406 '@ID' => array_unique($attachedIdList)
1407 ),
1408 'select' => array('ID', 'OBJECT_ID')
1409 ));
1410 while ($attachedObjectFields = $res->fetch())
1411 {
1412 $diskObjectId = $attachedObjectFields['OBJECT_ID'];
1413
1414 if ($fileData = self::getFileData($diskObjectId))
1415 {
1416 $attachedObjectList[$attachedObjectFields['ID']] = $diskObjectId;
1417 $result['FILES'][$diskObjectId] = $fileData;
1418 }
1419 }
1420 }
1421
1422 foreach ($result['COMMENTS'] as $key => $value)
1423 {
1424 if ($value['DATE'] instanceof \Bitrix\Main\Type\DateTime)
1425 {
1426 $result['COMMENTS'][$key]['DATE'] = date('c', $value['DATE']->getTimestamp());
1427 }
1428
1429 if (!empty($commentAttachedList[$key]))
1430 {
1431 foreach ($commentAttachedList[$key] as $attachedId)
1432 {
1433 if (!empty($attachedObjectList[$attachedId]))
1434 {
1435 $result['COMMENTS'][$key]['ATTACH'][] = $attachedObjectList[$attachedId];
1436 }
1437 }
1438 }
1439
1440 $result['COMMENTS'][$key] = array_change_key_case($result['COMMENTS'][$key], CASE_LOWER);
1441 }
1442
1443 $result['COMMENTS'] = array_values($result['COMMENTS']);
1444 $result['FILES'] = self::convertFileData($result['FILES']);
1445
1446 return $result;
1447 }
1448
1449 public static function deleteLogComment($arFields): bool
1450 {
1451 $commentId = (int)$arFields['COMMENT_ID'];
1452
1453 if ($commentId <= 0)
1454 {
1455 throw new RestException('Wrong comment ID');
1456 }
1457
1458 $currentUserId = (
1459 isset($arFields["USER_ID"])
1460 && (int)$arFields["USER_ID"] > 0
1461 && self::isAdmin()
1462 ? $arFields["USER_ID"]
1463 : self::getCurrentUserId()
1464 );
1465
1466 $commentFields = \Bitrix\Socialnetwork\Item\LogComment::getById($commentId)->getFields();
1467 if (empty($commentFields))
1468 {
1469 throw new RestException('No comment found');
1470 }
1471
1472 $currentUserPerm = self::getLogCommentPerm(array(
1473 'USER_ID' => $currentUserId,
1474 'COMMENT_ID' => $commentId
1475 ));
1476
1477 if ($currentUserPerm < self::PERM_WRITE)
1478 {
1479 throw new RestException('No write perms');
1480 }
1481
1482 $result = CSocNetLogComments::Delete($commentId);
1483
1484 return (bool)$result;
1485 }
1486
1487 private static function getBlogPostPerm($fields)
1488 {
1489 return Helper::getBlogPostPerm($fields);
1490 }
1491
1492 private static function getBlogCommentPerm($fields)
1493 {
1494 if (!Loader::includeModule('blog'))
1495 {
1496 throw new RestException('Blog module not installed');
1497 }
1498
1500
1501 $commentId = $fields['COMMENT_ID'];
1502
1503 $currentUserId = (int)(
1504 isset($fields["USER_ID"])
1505 && (int)$fields['USER_ID'] > 0
1506 && self::isAdmin()
1507 ? $fields["USER_ID"]
1508 : self::getCurrentUserId()
1509 );
1510
1511 $arComment = self::getBlogCommentFields($commentId);
1512 if (empty($arComment))
1513 {
1514 return $result;
1515 }
1516
1517 if ((int)$arComment["AUTHOR_ID"] === $currentUserId)
1518 {
1520 }
1521 elseif (CSocNetUser::isUserModuleAdmin($currentUserId, SITE_ID))
1522 {
1524 }
1525 elseif ($arComment['PUBLISH_STATUS'] === BLOG_PUBLISH_STATUS_PUBLISH)
1526 {
1527 $postItem = \Bitrix\Blog\Item\Post::getById($arComment['POST_ID']);
1528 $permsResult = $postItem->getSonetPerms(array(
1529 "CHECK_FULL_PERMS" => true
1530 ));
1531 $result = $permsResult['PERM'];
1532 if (
1533 $result <= \Bitrix\Blog\Item\Permissions::READ
1534 && $permsResult['READ_BY_OSG']
1535 )
1536 {
1538 }
1539 elseif ($result > \Bitrix\Blog\Item\Permissions::READ)
1540 {
1542 }
1543 }
1544
1545 return $result;
1546 }
1547
1548 private static function getLogCommentPerm($arFields): string
1549 {
1550 $result = self::PERM_DENY;
1551
1552 $commentId = $arFields['COMMENT_ID'];
1553
1554 $currentUserId = (int)(
1555 isset($arFields["USER_ID"])
1556 && (int)$arFields["USER_ID"] > 0
1557 && self::isAdmin()
1558 ? $arFields["USER_ID"]
1559 : self::getCurrentUserId()
1560 );
1561
1562 if (
1563 CSocNetUser::isUserModuleAdmin($currentUserId, SITE_ID)
1564 || (
1565 ($arComment = self::getLogCommentFields($commentId))
1566 && (int)$arComment['USER_ID'] === $currentUserId
1567 )
1568 )
1569 {
1570 $result = self::PERM_WRITE;
1571 }
1572
1573 return $result;
1574 }
1575
1576 private static function getBlogCommentFields($commentId): array
1577 {
1578 $result = array();
1579 if ($commentItem = \Bitrix\Blog\Item\Comment::getById($commentId))
1580 {
1581 $result = $commentItem->getFields();
1582 }
1583 return $result;
1584 }
1585
1586 private static function getLogCommentFields($commentId): array
1587 {
1588 $result = array();
1589 if ($commentItem = \Bitrix\Socialnetwork\Item\LogComment::getById($commentId))
1590 {
1591 $result = $commentItem->getFields();
1592 }
1593 return $result;
1594 }
1595
1596 private static function getFileData($diskObjectId)
1597 {
1598 $result = false;
1599
1600 $diskObjectId = (int)$diskObjectId;
1601 if ($diskObjectId <= 0)
1602 {
1603 return $result;
1604 }
1605
1606 if ($fileModel = \Bitrix\Disk\File::getById($diskObjectId))
1607 {
1609 $contentType = 'file';
1610 $imageParams = false;
1611 if (\Bitrix\Disk\TypeFile::isImage($fileModel))
1612 {
1613 $contentType = 'image';
1614 $params = $fileModel->getFile();
1615 $imageParams = Array(
1616 'width' => (int)$params['WIDTH'],
1617 'height' => (int)$params['HEIGHT'],
1618 );
1619 }
1620 else if (\Bitrix\Disk\TypeFile::isVideo($fileModel->getName()))
1621 {
1622 $contentType = 'video';
1623 $params = $fileModel->getView()->getPreviewData();
1624 $imageParams = Array(
1625 'width' => (int)$params['WIDTH'],
1626 'height' => (int)$params['HEIGHT'],
1627 );
1628 }
1629
1630 $isImage = \Bitrix\Disk\TypeFile::isImage($fileModel);
1631 $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
1632
1633 $result = array(
1634 'id' => (int)$fileModel->getId(),
1635 'date' => $fileModel->getCreateTime(),
1636 'type' => $contentType,
1637 'name' => $fileModel->getName(),
1638 'size' => (int)$fileModel->getSize(),
1639 'image' => $imageParams,
1640 'authorId' => (int)$fileModel->getCreatedBy(),
1641 'authorName' => CUser::FormatName(CSite::getNameFormat(false), $fileModel->getCreateUser(), true, true),
1642 'urlPreview' => (
1643 $fileModel->getPreviewId()
1644 ? $urlManager->getUrlForShowPreview($fileModel, [ 'width' => 640, 'height' => 640])
1645 : (
1646 $isImage
1647 ? $urlManager->getUrlForShowFile($fileModel, [ 'width' => 640, 'height' => 640])
1648 : null
1649 )
1650 ),
1651 'urlShow' => ($isImage ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlForDownloadFile($fileModel)),
1652 'urlDownload' => $urlManager->getUrlForDownloadFile($fileModel)
1653 );
1654 }
1655
1656 return $result;
1657 }
1658
1659 private static function convertFileData($fileData): array
1660 {
1661 if (!is_array($fileData))
1662 {
1663 return array();
1664 }
1665
1666 foreach ($fileData as $key => $value)
1667 {
1668 if ($value['date'] instanceof \Bitrix\Main\Type\DateTime)
1669 {
1670 $fileData[$key]['date'] = date('c', $value['date']->getTimestamp());
1671 }
1672
1673 foreach (['urlPreview', 'urlShow', 'urlDownload'] as $field)
1674 {
1675 $url = $fileData[$key][$field];
1676 if (is_string($url) && $url && mb_strpos($url, 'http') !== 0)
1677 {
1678 $fileData[$key][$field] = self::getPublicDomain().$url;
1679 }
1680 }
1681 }
1682
1683 return $fileData;
1684 }
1685
1686 private static function getPublicDomain(): ?string
1687 {
1688 static $result = null;
1689 if ($result === null)
1690 {
1691 $result = (\Bitrix\Main\Context::getCurrent()->getRequest()->isHttps() ? "https" : "http")."://".((defined("SITE_SERVER_NAME") && SITE_SERVER_NAME <> '') ? SITE_SERVER_NAME : Option::get("main", "server_name", $_SERVER['SERVER_NAME']));
1692 }
1693
1694 return $result;
1695 }
1696
1697 public static function createGroup($fields)
1698 {
1699 if (!is_array($fields))
1700 {
1701 throw new RestException('Incorrect input data');
1702 }
1703
1704 foreach ($fields as $key => $value)
1705 {
1706 if (in_array(mb_substr($key, 0, 1), [ '~', '=' ]))
1707 {
1708 unset($fields[$key]);
1709 }
1710 }
1711
1712 if (isset($fields['IMAGE_FILE_ID']) && Loader::includeModule('disk'))
1713 {
1714 if (
1715 (($imageFileId = (int)$fields['IMAGE_FILE_ID']) > 0)
1716 && ($file = File::loadById($imageFileId))
1717 && $file->canRead($file->getStorage()->getSecurityContext(self::getCurrentUserId()))
1718 )
1719 {
1720 $image = \CFile::MakeFileArray($file->getFileId());
1721 $image['del'] = 'N';
1722 \CFile::ResizeImage($image, ['width' => 300, 'height' => 300]);
1723 $fields['IMAGE_ID'] = $image;
1724
1725 unset($fields['IMAGE']);
1726 }
1727 else
1728 {
1729 unset($fields['IMAGE_FILE_ID']);
1730 }
1731 }
1732
1733 if (isset($fields['IMAGE']))
1734 {
1735 $fields['IMAGE_ID'] = CRestUtil::saveFile($fields['IMAGE']);
1736 if (!$fields['IMAGE_ID'])
1737 {
1738 unset($fields['IMAGE_ID']);
1739 }
1740 unset($fields['IMAGE']);
1741 }
1742
1743 $validateExtranetField = static fn ($siteId) =>
1744 Option::get('socialnetwork', 'enable_extranet_for_groups', 0)
1745 || (
1746 Loader::includeModule('extranet')
1747 && !CExtranet::IsExtranetSite($siteId)
1748 )
1749 ;
1750
1751 if (!isset($fields['SITE_ID']))
1752 {
1753 $fields['SITE_ID'] = [SITE_ID];
1754 }
1755 else
1756 {
1757 $siteIds = is_array($fields['SITE_ID']) ? $fields['SITE_ID'] : [$fields['SITE_ID']];
1758 $filteredSiteIds = array_filter($siteIds, $validateExtranetField);
1759
1760 if (empty($filteredSiteIds))
1761 {
1762 $fields['SITE_ID'] = [SITE_ID];
1763 }
1764 else
1765 {
1766 $fields['SITE_ID'] = $filteredSiteIds;
1767 }
1768 }
1769
1770 $siteIdForCheck = $fields['SITE_ID'][0];
1771
1772 if (
1773 Loader::includeModule('extranet')
1774 && !CExtranet::isIntranetUser()
1775 )
1776 {
1777 $siteIdForCheck = self::getExtranetSiteId();
1778 $fields['SITE_ID'][] = $siteIdForCheck;
1779 $fields['VISIBLE'] = 'N';
1780 $fields['OPENED'] = 'N';
1781 }
1782
1783 if (!\Bitrix\Socialnetwork\Helper\Workgroup::canCreate([
1784 'siteId' => $siteIdForCheck,
1785 'checkAdminSession' => false,
1786 ]))
1787 {
1788 throw new RestException('You have no permissions to create a group');
1789 }
1790
1791 if (
1792 !is_set($fields, "SUBJECT_ID")
1793 || (int)$fields["SUBJECT_ID"] <= 0
1794 )
1795 {
1796 $rsSubject = CSocNetGroupSubject::GetList(
1797 array("SORT" => "ASC"),
1798 array("SITE_ID" => $fields["SITE_ID"]),
1799 false,
1800 false,
1801 array("ID")
1802 );
1803 if ($arSubject = $rsSubject->Fetch())
1804 {
1805 $fields["SUBJECT_ID"] = $arSubject["ID"];
1806 }
1807 }
1808
1809 $initiatePerms = [
1813 ];
1814 if (
1815 !isset($fields['INITIATE_PERMS'])
1816 || !in_array($fields['INITIATE_PERMS'], $initiatePerms, true)
1817 )
1818 {
1819 $isExtranetInstalled = (
1822 && !empty(Option::get('extranet', 'extranet_site'))
1823 );
1824 $isExtranet = (
1825 $isExtranetInstalled
1826 && Loader::includeModule('extranet')
1827 && \CExtranet::IsExtranetSite()
1828 );
1829
1830 $fields['INITIATE_PERMS'] = ($isExtranet ? UserToGroupTable::ROLE_MODERATOR : UserToGroupTable::ROLE_USER);
1831 }
1832
1833 if (!empty($fields['PROJECT_DATE_START']))
1834 {
1835 $fields['PROJECT_DATE_START'] = CRestUtil::unConvertDate($fields['PROJECT_DATE_START']);
1836 }
1837 if (!empty($fields['PROJECT_DATE_FINISH']))
1838 {
1839 $fields['PROJECT_DATE_FINISH'] = CRestUtil::unConvertDate($fields['PROJECT_DATE_FINISH']);
1840 }
1841
1842 $ownerId = (
1843 !empty($fields['OWNER_ID'])
1844 && (int)$fields['OWNER_ID'] > 0
1845 && self::isCurrentUserAdmin()
1846 ? (int)$fields['OWNER_ID']
1847 : self::getCurrentUserId()
1848 );
1849
1850 Workgroup::mutateScrumFormFields($fields);
1851
1852 $groupId = CSocNetGroup::createGroup($ownerId, $fields, false);
1853
1854 if ($groupId <= 0)
1855 {
1856 throw new RestException('Cannot create group');
1857 }
1858
1859 CSocNetFeatures::SetFeature(
1861 $groupId,
1862 'files',
1863 true
1864 );
1865
1866 if (
1867 isset($fields['GROUP_THEME_ID'])
1868 && Loader::includeModule('intranet')
1869 )
1870 {
1871 $siteTemplateId = 'bitrix24';
1872
1873 if ($themePicker = new ThemePicker($siteTemplateId, SITE_ID, self::getCurrentUserId(), ThemePicker::ENTITY_TYPE_SONET_GROUP, $groupId))
1874 {
1875 if (empty($fields['GROUP_THEME_ID']))
1876 {
1877 $themesList = $themePicker->getPatternThemes();
1878 $themePickerData = $themesList[array_rand($themesList)];
1879 $fields['GROUP_THEME_ID'] = $themePickerData['id'];
1880 }
1881
1882 try
1883 {
1884 $themePicker->setCurrentThemeId($fields['GROUP_THEME_ID']);
1885 unset($themePicker);
1886 }
1887 catch (ArgumentException $exception)
1888 {
1889
1890 }
1891 }
1892 }
1893
1894 return $groupId;
1895 }
1896
1897 public static function updateGroup($arFields)
1898 {
1899 foreach ($arFields as $key => $value)
1900 {
1901 if (in_array(mb_substr($key, 0, 1), [ '~', '=' ]))
1902 {
1903 unset($arFields[$key]);
1904 }
1905 }
1906
1907 if (isset($arFields['IMAGE_FILE_ID']) && Loader::includeModule('disk'))
1908 {
1909 $imageFileId = (int)$arFields['IMAGE_FILE_ID'];
1910
1911 if ($imageFileId === 0)
1912 {
1913 $arFields['IMAGE_ID'] = ['del' => 'Y'];
1914 unset($arFields['IMAGE']);
1915 }
1916 else if (
1917 $imageFileId > 0
1918 && ($file = File::loadById($imageFileId))
1919 && $file->canRead($file->getStorage()->getSecurityContext(self::getCurrentUserId()))
1920 )
1921 {
1922 $image = \CFile::MakeFileArray($file->getFileId());
1923 $image['del'] = 'N';
1924 \CFile::ResizeImage($image, ['width' => 300, 'height' => 300]);
1925 $arFields['IMAGE_ID'] = $image;
1926
1927 unset($arFields['IMAGE']);
1928 }
1929 else
1930 {
1931 unset($arFields['IMAGE_FILE_ID']);
1932 }
1933 }
1934
1935 if (isset($arFields['IMAGE']))
1936 {
1937 $arFields['IMAGE_ID'] = CRestUtil::saveFile($arFields['IMAGE']);
1938 if (!$arFields['IMAGE_ID'])
1939 {
1940 $arFields['IMAGE_ID'] = array('del' => 'Y');
1941 }
1942 unset($arFields['IMAGE']);
1943 }
1944
1945 if (!empty($arFields['PROJECT_DATE_START']))
1946 {
1947 $arFields['PROJECT_DATE_START'] = CRestUtil::unConvertDate($arFields['PROJECT_DATE_START']);
1948 }
1949 if (!empty($arFields['PROJECT_DATE_FINISH']))
1950 {
1951 $arFields['PROJECT_DATE_FINISH'] = CRestUtil::unConvertDate($arFields['PROJECT_DATE_FINISH']);
1952 }
1953
1954 $groupID = $arFields['GROUP_ID'] ?? null;
1955 unset($arFields['GROUP_ID']);
1956
1957 if ((int)$groupID <= 0)
1958 {
1959 throw new RestException('Wrong group ID');
1960 }
1961
1962 $isModifySiteIdsNeeded =
1963 isset($arFields['SITE_ID'])
1964 && !Option::get('socialnetwork', 'enable_extranet_for_groups', 0)
1965 ;
1966
1967 if ($isModifySiteIdsNeeded)
1968 {
1969 $arFields['SITE_ID'] = self::getModifiedGroupSiteIdsForDisabledExtranet(
1970 $groupID,
1971 is_array($arFields['SITE_ID']) ? $arFields['SITE_ID'] : [$arFields['SITE_ID']]
1972 );
1973 }
1974
1976 'groupId' => $groupID,
1977 'checkAdminSession' => false,
1978 ]))
1979 {
1980 throw new RestException('User has no permissions to update group');
1981 }
1982
1983 $groupFields = \Bitrix\Socialnetwork\WorkgroupTable::getList([
1984 'select' => [
1985 'TYPE',
1986 'SITE_ID',
1987 'OWNER_ID',
1988 'NAME',
1989 ],
1990 'filter' => ['ID' => $groupID],
1991 ])->fetch();
1992
1993 $res = CSocNetGroup::Update($groupID, $arFields, false);
1994 if ((int)$res <= 0)
1995 {
1996 throw new RestException('Cannot update group');
1997 }
1998
1999 $newOwnerId = (int)($arFields['OWNER_ID'] ?? 0);
2000 if ($newOwnerId && $newOwnerId !== (int)$groupFields['OWNER_ID'])
2001 {
2002 CSocNetUserToGroup::setOwner($newOwnerId, $groupID, $groupFields);
2003 }
2004
2005 return $res;
2006 }
2007
2008 private static function getModifiedGroupSiteIdsForDisabledExtranet(int $groupId, array $siteIds): array
2009 {
2010 if (!Loader::includeModule('extranet'))
2011 {
2012 return $siteIds;
2013 }
2014
2015 $leaveGroupTypeExtranet = CExtranet::IsExtranetSocNetGroup($groupId);
2016
2017 $extranetSiteId = CExtranet::GetExtranetSiteID();
2018
2019 $addSiteIdIfMissing = static function (array &$siteIds, mixed $siteId) {
2020 if (!in_array($siteId, $siteIds, true))
2021 {
2022 $siteIds[] = $siteId;
2023 }
2024 };
2025
2026 $removeSiteIdIfExists = static function (array &$siteIds, mixed $siteId) {
2027 $key = array_search($siteId, $siteIds, true);
2028
2029 if ($key !== false)
2030 {
2031 unset($siteIds[$key]);
2032 }
2033 };
2034
2035 $addSiteIdIfMissing(
2036 $siteIds,
2037 $leaveGroupTypeExtranet ? $extranetSiteId : SITE_ID
2038 );
2039 $removeSiteIdIfExists(
2040 $siteIds,
2041 $leaveGroupTypeExtranet ? SITE_ID : $extranetSiteId
2042 );
2043
2044 return $siteIds;
2045 }
2046
2047 public static function deleteGroup($arFields): bool
2048 {
2049 $groupId = (int) ($arFields['GROUP_ID'] ?? null);
2050
2051 if ($groupId <= 0)
2052 {
2053 throw new RestException('Wrong group ID');
2054 }
2055
2056 $filter = [
2057 'ID' => $groupId,
2058 ];
2059
2060 if (!self::isCurrentUserAdmin())
2061 {
2062 $filter['CHECK_PERMISSIONS'] = self::getCurrentUserId();
2063 }
2064
2065 $res = CSocNetGroup::GetList([], $filter);
2066 $groupFields = $res->Fetch();
2067 if (!is_array($groupFields))
2068 {
2069 throw new RestException('Socialnetwork group not found');
2070 }
2071
2072 if (
2073 (int)$groupFields["OWNER_ID"] !== self::getCurrentUserId()
2074 && !self::isCurrentUserAdmin()
2075 )
2076 {
2077 throw new RestException('User has no permissions to delete group');
2078 }
2079
2080 if (!CSocNetGroup::Delete($groupFields["ID"]))
2081 {
2082 throw new RestException('Cannot delete group');
2083 }
2084
2085 return true;
2086 }
2087
2088 public static function setGroupOwner($arFields): bool
2089 {
2090 try
2091 {
2092 return Workgroup::setOwner([
2093 'groupId' => $arFields['GROUP_ID'] ?? null,
2094 'userId' => $arFields['USER_ID'] ?? null,
2095 ]);
2096 }
2097 catch(Exception $e)
2098 {
2099 throw new RestException($e->getMessage(), $e->getCode());
2100 }
2101 }
2102
2103 public static function getGroup($arFields, $n, $server)
2104 {
2105 $arOrder = $arFields['ORDER'] ?? null;
2106 if (!is_array($arOrder))
2107 {
2108 $arOrder = array("ID" => "DESC");
2109 }
2110
2111 if (
2112 ($arFields['IS_ADMIN'] ?? null) === 'Y'
2113 && !self::isCurrentUserAdmin()
2114 )
2115 {
2116 unset($arFields['IS_ADMIN']);
2117 }
2118
2119 $filter = self::checkGroupFilter($arFields['FILTER'] ?? null);
2120
2121 if (
2122 isset($arFields['GROUP_ID'])
2123 && (int)$arFields['GROUP_ID'] > 0
2124 )
2125 {
2126 $filter['ID'] = $arFields['GROUP_ID'];
2127 }
2128
2129 if (($arFields['IS_ADMIN'] ?? null) !== 'Y')
2130 {
2131 $filter['CHECK_PERMISSIONS'] = self::getCurrentUserId();
2132 }
2133
2134 $extranetSiteId = self::getExtranetSiteId();
2135
2136 if (
2137 $extranetSiteId
2138 && ($arFields['IS_ADMIN'] ?? null) !== 'Y'
2139 && self::getCurrentUserType() === 'extranet'
2140 )
2141 {
2142 $filter['SITE_ID'] = $extranetSiteId;
2143 }
2144
2145 $result = [];
2146 $res = CSocNetGroup::GetList($arOrder, $filter, false, self::getNavData($n));
2147 while ($groupFields = $res->Fetch())
2148 {
2149 if (!empty($groupFields['NAME']))
2150 {
2151 $groupFields['NAME'] = Emoji::decode($groupFields['NAME']);
2152 }
2153 if (!empty($groupFields['DESCRIPTION']))
2154 {
2155 $groupFields['DESCRIPTION'] = Emoji::decode($groupFields['DESCRIPTION']);
2156 }
2157
2158 $groupFields['DATE_CREATE'] = CRestUtil::ConvertDateTime($groupFields['DATE_CREATE']);
2159 $groupFields['DATE_UPDATE'] = CRestUtil::ConvertDateTime($groupFields['DATE_UPDATE']);
2160 $groupFields['DATE_ACTIVITY'] = CRestUtil::ConvertDateTime($groupFields['DATE_ACTIVITY']);
2161
2162 if ($groupFields['IMAGE_ID'] > 0)
2163 {
2164 $groupFields['IMAGE'] = self::getFile($groupFields['IMAGE_ID']);
2165 }
2166
2167 if ($extranetSiteId)
2168 {
2169 $groupFields["IS_EXTRANET"] = "N";
2170 $rsGroupSite = CSocNetGroup::GetSite($groupFields["ID"]);
2171 while ($arGroupSite = $rsGroupSite->Fetch())
2172 {
2173 if ($arGroupSite["LID"] === $extranetSiteId)
2174 {
2175 $groupFields["IS_EXTRANET"] = "Y";
2176 break;
2177 }
2178 }
2179 }
2180
2181 unset($groupFields['INITIATE_PERMS'], $groupFields['SPAM_PERMS'], $groupFields['IMAGE_ID']);
2182
2183 $result[] = $groupFields;
2184 }
2185
2186 return self::setNavData($result, $res);
2187 }
2188
2189 public static function getGroupUsers($arFields, $n, $server): array
2190 {
2191 $GROUP_ID = (int) ($arFields['ID'] ?? null);
2192
2193 if ($GROUP_ID <= 0)
2194 {
2195 throw new RestException('Wrong socialnetwork group ID');
2196 }
2197
2198 $filter = [
2199 'ID' => $GROUP_ID,
2200 ];
2201
2202 if (!self::isCurrentUserAdmin())
2203 {
2204 $filter['CHECK_PERMISSIONS'] = self::getCurrentUserId();
2205
2206 if (self::getCurrentUserType() === 'extranet')
2207 {
2208 $filter['SITE_ID'] = self::getExtranetSiteId();
2209 }
2210 }
2211
2212 $res = CSocNetGroup::GetList([], $filter);
2213 $groupFields = $res->fetch();
2214 if (!is_array($groupFields))
2215 {
2216 throw new RestException('Socialnetwork group not found');
2217 }
2218
2219 $res = CSocNetUserToGroup::getList(
2220 [ 'ID' => 'ASC' ],
2221 array(
2222 'GROUP_ID' => $groupFields['ID'],
2223 '<=ROLE' => SONET_ROLES_USER,
2224 '=USER_ACTIVE' => 'Y'
2225 ),
2226 false,
2227 false,
2228 [ 'USER_ID', 'ROLE' ]
2229 );
2230
2231 $result = [];
2232 while ($relationFields = $res->fetch())
2233 {
2234 $result[] = $relationFields;
2235 }
2236
2237 return $result;
2238 }
2239
2240 public static function inviteGroupUsers($arFields): array
2241 {
2242 $groupID = $arFields['GROUP_ID'] ?? null;
2243 $arUserID = $arFields['USER_ID'] ?? null;
2244 $message = $arFields['MESSAGE'] ?? null;
2245
2246 if ((int)$groupID <= 0)
2247 {
2248 throw new RestException('Wrong group ID');
2249 }
2250
2251 if (
2252 (!is_array($arUserID) && (int)$arUserID <= 0)
2253 || (is_array($arUserID) && count($arUserID) <= 0)
2254 )
2255 {
2256 throw new RestException('Wrong user IDs');
2257 }
2258
2259 if (!is_array($arUserID))
2260 {
2261 $arUserID = array($arUserID);
2262 }
2263
2264 $arSuccessID = array();
2265
2266 $dbRes = CSocNetGroup::GetList(array(), array(
2267 "ID" => $groupID,
2268 "CHECK_PERMISSIONS" => self::getCurrentUserId(),
2269 ));
2270 $arGroup = $dbRes->Fetch();
2271 if (!is_array($arGroup))
2272 {
2273 throw new RestException('Socialnetwork group not found');
2274 }
2275
2276 foreach ($arUserID as $user_id)
2277 {
2278 $isCurrentUserTmp = (self::getCurrentUserId() === (int)$user_id);
2279 $canInviteGroup = CSocNetUserPerms::CanPerformOperation(self::getCurrentUserId(), $user_id, "invitegroup", self::isCurrentUserAdmin());
2280 $user2groupRelation = CSocNetUserToGroup::GetUserRole($user_id, $arGroup["ID"]);
2281
2282 if (
2283 !$isCurrentUserTmp && $canInviteGroup && !$user2groupRelation
2284 && CSocNetUserToGroup::SendRequestToJoinGroup(self::getCurrentUserId(), $user_id, $arGroup["ID"], $message, true)
2285 )
2286 {
2287 $arSuccessID[] = $user_id;
2288 }
2289 }
2290
2291 return $arSuccessID;
2292 }
2293
2294 public static function requestGroupUser($arFields): bool
2295 {
2296 $groupID = $arFields['GROUP_ID'] ?? null;
2297 $message = $arFields['MESSAGE'] ?? null;
2298
2299 if ((int)$groupID <= 0)
2300 {
2301 throw new RestException('Wrong group ID');
2302 }
2303
2304 $filter = [
2305 'ID' => $groupID,
2306 'CHECK_PERMISSIONS' => self::getCurrentUserId(),
2307 ];
2308 if (self::getCurrentUserType() === 'extranet')
2309 {
2310 $filter['SITE_ID'] = self::getExtranetSiteId();
2311 }
2312 $dbRes = CSocNetGroup::getList([], $filter);
2313 $arGroup = $dbRes->Fetch();
2314 if (is_array($arGroup))
2315 {
2316 $url = (CMain::IsHTTPS() ? "https://" : "http://").$_SERVER["HTTP_HOST"].CComponentEngine::MakePathFromTemplate("/workgroups/group/#group_id#/requests/", array("group_id" => $arGroup["ID"]));
2317
2318 if (!CSocNetUserToGroup::SendRequestToBeMember(self::getCurrentUserId(), $arGroup["ID"], $message, $url, false))
2319 {
2320 throw new RestException('Cannot request to join group');
2321 }
2322
2323 return true;
2324 }
2325
2326 throw new RestException('Socialnetwork group not found');
2327 }
2328
2329 public static function addGroupUsers($arFields): array
2330 {
2331 $groupId = $arFields['GROUP_ID'] ?? null;
2332 $userIdList = $arFields['USER_ID'] ?? null;
2333
2334 if ((int)$groupId <= 0)
2335 {
2336 throw new RestException('Wrong group ID');
2337 }
2338
2339 if (!self::isCurrentUserAdmin())
2340 {
2341 throw new RestException('No permissions to add users');
2342 }
2343
2344 if (
2345 (!is_array($userIdList) && (int)$userIdList <= 0)
2346 || (is_array($userIdList) && count($userIdList) <= 0)
2347 )
2348 {
2349 throw new RestException('Wrong user IDs');
2350 }
2351
2352 if (!is_array($userIdList))
2353 {
2354 $userIdList = [ $userIdList ];
2355 }
2356
2357 $res = CSocNetGroup::getList(array(), array(
2358 "ID" => $groupId
2359 ));
2360 $groupFields = $res->fetch();
2361 if (!is_array($groupFields))
2362 {
2363 throw new RestException('Socialnetwork group not found');
2364 }
2365
2366 if (
2367 !empty($userIdList)
2368 && Loader::includeModule('intranet')
2369 )
2370 {
2371 $extranetSiteId = self::getExtranetSiteId();
2372
2373 $res = \Bitrix\Intranet\UserTable::getList([
2374 'filter' => [
2375 '@ID' => $userIdList
2376 ],
2377 'select' => [ 'ID', 'USER_TYPE' ]
2378 ]);
2379 $userIdList = [];
2380 while ($userFields = $res->fetch())
2381 {
2382 if (!in_array($userFields['USER_TYPE'], [ 'employee', 'extranet' ]))
2383 {
2384 continue;
2385 }
2386 $userIdList[] = $userFields['ID'];
2387
2388 if (
2389 $userFields['USER_TYPE'] === 'extranet'
2390 && $extranetSiteId
2391 )
2392 {
2393 $groupSiteList = [];
2394 $resSite = \Bitrix\Socialnetwork\WorkgroupSiteTable::getList([
2395 'filter' => [
2396 '=GROUP_ID' => $groupId
2397 ],
2398 'select' => [ 'SITE_ID' ]
2399 ]);
2400 while ($groupSite = $resSite->fetch())
2401 {
2402 $groupSiteList[] = $groupSite['SITE_ID'];
2403 }
2404 if (!in_array($extranetSiteId, $groupSiteList, true))
2405 {
2406 $groupSiteList[] = $extranetSiteId;
2407 CSocNetGroup::update($groupId, [
2408 'SITE_ID' => $groupSiteList
2409 ]);
2410 }
2411 }
2412 }
2413 }
2414
2415 $successUserId = [];
2416
2417 foreach ($userIdList as $userId)
2418 {
2419 $user2groupRelation = CSocNetUserToGroup::getUserRole($userId, $groupId);
2420 if ($user2groupRelation)
2421 {
2422 continue;
2423 }
2424
2425 if (CSocNetUserToGroup::add([
2426 "USER_ID" => $userId,
2427 "GROUP_ID" => $groupId,
2429 "=DATE_CREATE" => CDatabase::currentTimeFunction(),
2430 "=DATE_UPDATE" => CDatabase::currentTimeFunction(),
2431 "MESSAGE" => '',
2432 "INITIATED_BY_TYPE" => UserToGroupTable::INITIATED_BY_GROUP,
2433 "INITIATED_BY_USER_ID" => $groupFields['OWNER_ID']
2434 ]))
2435 {
2436 $successUserId[] = $userId;
2437
2439 'group_id' => $groupId,
2440 'user_id' => $userId,
2441 'action' => UserToGroup::CHAT_ACTION_IN,
2443 ]);
2444 }
2445 }
2446
2447 return $successUserId;
2448 }
2449
2450 public static function updateGroupUsers($arFields): array
2451 {
2452 $groupId = $arFields['GROUP_ID'] ?? null;
2453 $userIdList = $arFields['USER_ID'] ?? null;
2454 $role = $arFields['ROLE'] ?? null;
2455
2456 if ((int)$groupId <= 0)
2457 {
2458 throw new RestException('Wrong group ID');
2459 }
2460
2461 if (!self::isCurrentUserAdmin())
2462 {
2463 throw new RestException('No permissions to update users role');
2464 }
2465
2466 if (!in_array($role, [ UserToGroupTable::ROLE_MODERATOR, UserToGroupTable::ROLE_USER ], true))
2467 {
2468 throw new RestException('Incorrect role code');
2469 }
2470
2471 if (
2472 (!is_array($userIdList) && (int)$userIdList <= 0)
2473 || (is_array($userIdList) && count($userIdList) <= 0)
2474 )
2475 {
2476 throw new RestException('Wrong user IDs');
2477 }
2478
2479 if (!is_array($userIdList))
2480 {
2481 $userIdList = [ $userIdList ];
2482 }
2483
2484 $res = CSocNetGroup::getList(array(), array(
2485 "ID" => $groupId
2486 ));
2487 $groupFields = $res->fetch();
2488 if (!is_array($groupFields))
2489 {
2490 throw new RestException('Socialnetwork group not found');
2491 }
2492
2493 $successUserId = [];
2494
2495 $resRelation = UserToGroupTable::getList(array(
2496 'filter' => array(
2497 'GROUP_ID' => $groupId,
2498 '@USER_ID' => $userIdList
2499 ),
2500 'select' => array('ID', 'USER_ID', 'ROLE')
2501 ));
2502 while ($relation = $resRelation->fetch())
2503 {
2504 if (
2505 $relation['ROLE'] === $role
2506 || $relation['ROLE'] === UserToGroupTable::ROLE_OWNER
2507 )
2508 {
2509 continue;
2510 }
2511
2512 if (CSocNetUserToGroup::update($relation['ID'], [
2513 "ROLE" => $role,
2514 "=DATE_UPDATE" => CDatabase::currentTimeFunction(),
2515 ]))
2516 {
2517 $successUserId[] = $relation['USER_ID'];
2518 }
2519 }
2520
2521 return $successUserId;
2522 }
2523
2524 public static function deleteGroupUsers($arFields): array
2525 {
2526 $groupId = $arFields['GROUP_ID'] ?? null;
2527 $userIdList = $arFields['USER_ID'] ?? null;
2528
2529 if ((int)$groupId <= 0)
2530 {
2531 throw new RestException('Wrong group ID');
2532 }
2533
2534 if (!self::isCurrentUserAdmin())
2535 {
2536 throw new RestException('No permissions to update users role');
2537 }
2538
2539 if (
2540 (!is_array($userIdList) && (int)$userIdList <= 0)
2541 || (is_array($userIdList) && count($userIdList) <= 0)
2542 )
2543 {
2544 throw new RestException('Wrong user IDs');
2545 }
2546
2547 if (!is_array($userIdList))
2548 {
2549 $userIdList = [ $userIdList ];
2550 }
2551
2552 $res = CSocNetGroup::getList(
2553 [],
2554 [
2555 'ID' => $groupId,
2556 ],
2557 false,
2558 false,
2559 [ 'SCRUM_MASTER_ID' ]
2560 );
2561 $groupFields = $res->fetch();
2562 if (!is_array($groupFields))
2563 {
2564 throw new RestException('Socialnetwork group not found');
2565 }
2566
2567 $successUserId = [];
2568
2569 $resRelation = UserToGroupTable::getList(array(
2570 'filter' => array(
2571 'GROUP_ID' => $groupId,
2572 '@USER_ID' => $userIdList
2573 ),
2574 'select' => array('ID', 'USER_ID', 'ROLE')
2575 ));
2576 while ($relation = $resRelation->fetch())
2577 {
2578 if ($relation['ROLE'] === UserToGroupTable::ROLE_OWNER)
2579 {
2580 continue;
2581 }
2582
2583 if ((int)$groupFields['SCRUM_MASTER_ID'] === (int)$relation['USER_ID'])
2584 {
2585 continue;
2586 }
2587
2588 if (CSocNetUserToGroup::delete($relation['ID']))
2589 {
2590 $successUserId[] = $relation['USER_ID'];
2591 }
2592 }
2593
2594 return $successUserId;
2595 }
2596
2597 public static function getUserGroups($arFields, $n, $server): array
2598 {
2599 $res = CSocNetUserToGroup::getList(
2600 [ 'ID' => 'ASC' ],
2601 [
2602 'USER_ID' => self::getCurrentUserId(),
2603 '<=ROLE' => SONET_ROLES_USER
2604 ],
2605 false,
2606 false,
2607 [ 'GROUP_ID', 'GROUP_NAME', 'ROLE', 'GROUP_IMAGE_ID' ]
2608 );
2609
2610 $result = [];
2611 $files = [];
2612 while ($groupFields = $res->fetch())
2613 {
2614 if (!empty($groupFields['GROUP_NAME']))
2615 {
2616 $groupFields['GROUP_NAME'] = Emoji::decode($groupFields['GROUP_NAME']);
2617 }
2618
2619 $groupFields['GROUP_IMAGE'] = '';
2620 $result[] = $groupFields;
2621
2622 if ($groupFields['GROUP_IMAGE_ID'] > 0)
2623 {
2624 $files[] = (int)$groupFields['GROUP_IMAGE_ID'];
2625 }
2626 }
2627
2628 if (
2629 !empty($result)
2630 && ($extranetSiteId = self::getExtranetSiteId())
2631 )
2632 {
2633 $extranetWorkgroupIdList = [];
2634 $workgroupIdList = array_map(static function($item) { return $item['GROUP_ID']; }, $result);
2635 $res = \Bitrix\Socialnetwork\WorkgroupSiteTable::getList([
2636 'filter' => [
2637 'GROUP_ID' => $workgroupIdList,
2638 'SITE_ID' => $extranetSiteId
2639 ],
2640 'select' => [ 'GROUP_ID' ]
2641 ]);
2642 while ($workgroupSiteFields = $res->fetch())
2643 {
2644 $extranetWorkgroupIdList[] = (int)$workgroupSiteFields['GROUP_ID'];
2645 }
2646
2647 if (!empty($extranetWorkgroupIdList))
2648 {
2649 foreach ($result as $key => $groupFields)
2650 {
2651 if (in_array((int)$groupFields['GROUP_ID'], $extranetWorkgroupIdList, true))
2652 {
2653 $result[$key]['IS_EXTRANET'] = 'Y';
2654 }
2655 }
2656 }
2657 }
2658
2659 if (!empty($files))
2660 {
2661 $files = CRestUtil::getFile($files, [
2662 'width' => 150,
2663 'height' => 150,
2664 ]);
2665
2666 foreach ($result as $key => $groupFields)
2667 {
2668 if ($groupFields['GROUP_IMAGE_ID'] > 0)
2669 {
2670 $result[$key]['GROUP_IMAGE'] = $files[$groupFields['GROUP_IMAGE_ID']];
2671 }
2672 }
2673 }
2674
2675 return $result;
2676 }
2677
2678 public static function getGroupFeatureAccess($arFields)
2679 {
2680 $arSocNetFeaturesSettings = CSocNetAllowed::GetAllowedFeatures();
2681
2682 $groupID = (int) ($arFields["GROUP_ID"] ?? null);
2683 $feature = trim((string) ($arFields["FEATURE"] ?? ''));
2684 $operation = trim((string) ($arFields["OPERATION"] ?? ''));
2685
2686 if ($groupID <= 0)
2687 {
2688 throw new RestException("Wrong socialnetwork group ID");
2689 }
2690
2691 if (
2692 $feature === ''
2693 || !array_key_exists($feature, $arSocNetFeaturesSettings)
2694 || !array_key_exists("allowed", $arSocNetFeaturesSettings[$feature])
2695 || !in_array(SONET_ENTITY_GROUP, $arSocNetFeaturesSettings[$feature]["allowed"], true)
2696 )
2697 {
2698 throw new RestException("Wrong feature");
2699 }
2700
2701 if (
2702 $operation === ''
2703 || !array_key_exists("operations", $arSocNetFeaturesSettings[$feature])
2704 || !array_key_exists($operation, $arSocNetFeaturesSettings[$feature]["operations"])
2705 )
2706 {
2707 throw new RestException("Wrong operation");
2708 }
2709
2710 return CSocNetFeaturesPerms::CurrentUserCanPerformOperation(SONET_ENTITY_GROUP, $groupID, $feature, $operation);
2711 }
2712
2713 private static function checkGroupFilter($arFilter)
2714 {
2715 if (!is_array($arFilter))
2716 {
2717 $arFilter = array();
2718 }
2719 else
2720 {
2721 foreach ($arFilter as $key => $value)
2722 {
2723 if (preg_match('/^([^a-zA-Z]*)(.*)/', $key, $matches))
2724 {
2725 $operation = $matches[1];
2726 $field = $matches[2];
2727
2728 if (!in_array($operation, self::$arAllowedOperations, true))
2729 {
2730 unset($arFilter[$key]);
2731 }
2732 else
2733 {
2734 switch($field)
2735 {
2736 case 'DATE_CREATE':
2737 case 'DATE_ACTIVITY':
2738 case 'DATE_UPDATE':
2740 break;
2741 case 'IS_EXTRANET':
2742 if ($extranetSiteId = self::getExtranetSiteId())
2743 {
2744 if ($value === 'Y')
2745 {
2746 $arFilter['=SITE_ID'] = $extranetSiteId;
2747 }
2748 elseif ($value === 'N')
2749 {
2750 $arFilter['!=SITE_ID'] = $extranetSiteId;
2751 }
2752 }
2753 unset($arFilter[$key]);
2754 break;
2755 case 'CHECK_PERMISSIONS':
2756 unset($arFilter[$key]);
2757 break;
2758 default:
2759 break;
2760 }
2761 }
2762 }
2763 }
2764 }
2765
2766 return $arFilter;
2767 }
2768
2769 private static function getFile($fileId)
2770 {
2771 $arFile = CFile::GetFileArray($fileId);
2772 if (is_array($arFile))
2773 {
2774 return $arFile['SRC'];
2775 }
2776
2777 return '';
2778 }
2779
2780 private static function isAdmin(): bool
2781 {
2782 global $USER;
2783 return (
2784 $USER->isAdmin()
2785 || (
2786 Loader::includeModule('bitrix24')
2787 && CBitrix24::isPortalAdmin(self::getCurrentUserId())
2788 )
2789 );
2790 }
2791
2792 public static function getGroupSubject($arFields, $n, $server)
2793 {
2794 $arOrder = $arFields['ORDER'] ?? null;
2795 if (!is_array($arOrder))
2796 {
2797 $arOrder = array("SORT" => "ASC");
2798 }
2799
2800 $arFilter = [
2801 'SITE_ID' => (
2802 isset($arFields['SITE_ID'])
2803 && !empty($arFields['SITE_ID'])
2804 ? $arFields['SITE_ID']
2805 : CSite::getDefSite()
2806 )
2807 ];
2808
2809 if (
2810 isset($arFields['SUBJECT_ID'])
2811 && (int)$arFields['SUBJECT_ID'] > 0
2812 )
2813 {
2814 $arFilter['ID'] = $arFields['SUBJECT_ID'];
2815 }
2816
2817 $subjectIdList = [];
2818 $result = [];
2819
2820 $resSubject = CSocNetGroupSubject::getList(
2821 $arOrder,
2822 $arFilter,
2823 false,
2824 self::getNavData($n),
2825 array("ID", "NAME")
2826 );
2827 while ($subjectFields = $resSubject->fetch())
2828 {
2829 $subjectIdList[] = $subjectFields['ID'];
2830 $result[$subjectFields['ID']] = $subjectFields;
2831 }
2832
2833 if (!empty($subjectIdList))
2834 {
2835 $res = \Bitrix\Socialnetwork\WorkgroupSubjectSiteTable::getList([
2836 'filter' => [
2837 '@SUBJECT_ID' => $subjectIdList
2838 ],
2839 'select' => ['SUBJECT_ID', 'SITE_ID']
2840 ]);
2841
2842 while ($subjectSiteFields = $res->Fetch())
2843 {
2844 if (
2845 isset($result[$subjectSiteFields['SUBJECT_ID']])
2846 && is_array($result[$subjectSiteFields['SUBJECT_ID']])
2847 )
2848 {
2849 if (!isset($result[$subjectSiteFields['SUBJECT_ID']]['SITE_ID']))
2850 {
2851 $result[$subjectSiteFields['SUBJECT_ID']]['SITE_ID'] = [];
2852 }
2853 $result[$subjectSiteFields['SUBJECT_ID']]['SITE_ID'][] = $subjectSiteFields['SITE_ID'];
2854 }
2855 }
2856 }
2857
2858 $result = array_values($result);
2859
2860 return self::setNavData($result, $resSubject);
2861 }
2862
2863 public static function updateGroupSubject($fields)
2864 {
2865 foreach ($fields as $key => $value)
2866 {
2867 if (in_array(mb_substr($key, 0, 1), [ '~', '=' ]))
2868 {
2869 unset($fields[$key]);
2870 }
2871 }
2872
2873 $subjectId = $fields['SUBJECT_ID'] ?? null;
2874 unset($fields['SUBJECT_ID']);
2875
2876 if ((int)$subjectId <= 0)
2877 {
2878 throw new RestException('Wrong group subject ID');
2879 }
2880
2881 $arFilter = [
2882 'ID' => $subjectId
2883 ];
2884
2885 $dbRes = CSocNetGroupSubject::getList(array(), $arFilter);
2886
2887 if (!($arGroupSubject = $dbRes->fetch()))
2888 {
2889 throw new RestException('Socialnetwork group subject not found');
2890 }
2891
2892 if (!self::isCurrentUserAdmin())
2893 {
2894 throw new RestException('User has no permissions to update group subject');
2895 }
2896
2897 $res = CSocNetGroupSubject::update($arGroupSubject["ID"], $fields);
2898 if ((int)$res <= 0)
2899 {
2900 throw new RestException('Cannot update group subject');
2901 }
2902
2903 return $res;
2904 }
2905
2906 public static function deleteGroupSubject($arFields): bool
2907 {
2908 $subjectId = $arFields['SUBJECT_ID'] ?? null;
2909
2910 if ((int)$subjectId <= 0)
2911 {
2912 throw new RestException('Wrong group subject ID');
2913 }
2914
2915 $arFilter = [
2916 'ID' => $subjectId,
2917 ];
2918
2919 $dbRes = CSocNetGroupSubject::getList(array(), $arFilter);
2920 $arGroupSubject = $dbRes->fetch();
2921 if (!is_array($arGroupSubject))
2922 {
2923 throw new RestException('Socialnetwork group subject not found');
2924 }
2925
2926 $resSites = CSocNetGroupSubject::getSite($arGroupSubject['ID']);
2927 while ($siteFields = $resSites->fetch())
2928 {
2929 $count = CSocNetGroupSubject::getList(
2930 [],
2931 [
2932 'SITE_ID' => $siteFields['LID']
2933 ],
2934 [] // count
2935 );
2936 if ($count <= 1)
2937 {
2938 throw new RestException('Cannot delete the sole group subject for site ('.$siteFields['LID'].')');
2939 }
2940 }
2941
2942 if (!self::isCurrentUserAdmin())
2943 {
2944 throw new RestException('User has no permissions to delete group subject');
2945 }
2946
2947 if (!CSocNetGroupSubject::delete($arGroupSubject["ID"]))
2948 {
2949 throw new RestException('Cannot delete group subject');
2950 }
2951
2952 return true;
2953 }
2954
2955 public static function addGroupSubject($fields): array
2956 {
2957 if (!self::isCurrentUserAdmin())
2958 {
2959 throw new RestException('User has no permissions to add group subject');
2960 }
2961
2962 foreach ($fields as $key => $value)
2963 {
2964 if (in_array(mb_substr($key, 0, 1), [ '~', '=' ]))
2965 {
2966 unset($fields[$key]);
2967 }
2968 }
2969
2970 if (empty($fields['SITE_ID']))
2971 {
2972 $fields['SITE_ID'] = [ CSite::getDefSite() ];
2973 }
2974
2975 $result = (int)CSocNetGroupSubject::add($fields);
2976
2977 if (!$result)
2978 {
2979 throw new RestException('Socialnetwork group subject hasn\'t been added');
2980 }
2981
2982 return [
2983 'SUBJECT_ID' => $result,
2984 ];
2985 }
2986
2987 private static function getCurrentUserId(): int
2988 {
2989 global $USER;
2990
2991 return (int)$USER->getId();
2992 }
2993
2994 private static function isCurrentUserAdmin(): bool
2995 {
2996 static $value = null;
2997 if ($value === null)
2998 {
2999 $value = CSocNetUser::isCurrentUserModuleAdmin(SITE_ID, false);
3000 }
3001
3002 return $value;
3003 }
3004
3005 public static function getCurrentUserType(): string
3006 {
3007 $result = '';
3008
3009 if (!Loader::includeModule('intranet'))
3010 {
3011 return $result;
3012 }
3013
3014 $res = \Bitrix\Intranet\UserTable::getList([
3015 'filter' => [
3016 '=ID' => self::getCurrentUserId(),
3017 ],
3018 'select' => [ 'USER_TYPE' ],
3019 ]);
3020 if ($userFields = $res->fetch()
3021 )
3022 {
3023 $result = $userFields['USER_TYPE'];
3024 }
3025
3026 return $result;
3027 }
3028
3029 public static function getExtranetSiteId()
3030 {
3031 static $result = null;
3032
3033 if ($result === null)
3034 {
3035 $result = (ModuleManager::isModuleInstalled('extranet') ? Option::get('extranet', 'extranet_site') : false);
3036 }
3037
3038 return $result;
3039 }
3040}
3041
3043{
3044 public static function processEvent(array $arParams, array $arHandler)
3045 {
3046 static $processedIdList = array();
3047
3048 if (!Loader::includeModule('blog'))
3049 {
3050 return false;
3051 }
3052
3053 $eventName = $arHandler['EVENT_NAME'];
3054
3055 $appKey = $arHandler['APP_ID'].$arHandler['APPLICATION_TOKEN'];
3056 if (!isset($processedIdList[$appKey]))
3057 {
3058 $processedIdList[$appKey] = array();
3059 }
3060
3061 switch(mb_strtolower($eventName))
3062 {
3063 case 'onlivefeedpostadd':
3064 case 'onlivefeedpostupdate':
3065 case 'onlivefeedpostdelete':
3066
3067 $id = 0;
3068
3069 if (mb_strtolower($eventName) === 'onlivefeedpostadd')
3070 {
3071 $fields = isset($arParams[0]) && is_array($arParams[0])? $arParams[0] : array();
3072 $id = (int)($fields['ID'] ?? 0);
3073 }
3074 elseif (in_array(mb_strtolower($eventName), array('onlivefeedpostupdate', 'onlivefeedpostdelete')))
3075 {
3076 $id = (int)($arParams[0] ?? 0);
3077 $fields = isset($arParams[1]) && is_array($arParams[1])? $arParams[1] : array();
3078 }
3079
3080 if ($id <= 0)
3081 {
3082 throw new RestException('Could not find livefeed entity ID in fields of event "' . $eventName . '"');
3083 }
3084
3085 if (
3086 mb_strtolower($eventName) === 'onlivefeedpostupdate'
3087 && in_array($id, $processedIdList[$appKey], true)
3088 )
3089 {
3090 throw new RestException('ID ' . $id . 'has already been processed');
3091 }
3092
3093 if (in_array(mb_strtolower($eventName), array('onlivefeedpostadd', 'onlivefeedpostupdate')))
3094 {
3095 $processedIdList[$appKey][] = $id;
3096 }
3097
3098 if (
3099 !isset($fields['SOURCE_ID'], $fields['EVENT_ID'])
3100 && mb_strtolower($eventName) === 'onlivefeedpostupdate'
3101 )
3102 {
3104 'filter' => array(
3105 'ID' => $id
3106 ),
3107 'select' => array('EVENT_ID', 'SOURCE_ID')
3108 ));
3109
3110 if ($logFields = $res->fetch())
3111 {
3112 $sourceId = (int)($logFields['SOURCE_ID'] ?? 0);
3113 $logEventId = $logFields['EVENT_ID'] ?? false;
3114 }
3115 }
3116 else
3117 {
3118 $sourceId = isset($fields['SOURCE_ID']) ? (int)$fields['SOURCE_ID'] : 0;
3119 $logEventId = $fields['EVENT_ID'] ?? false;
3120 }
3121
3122 if (in_array($logEventId, \Bitrix\Blog\Integration\Socialnetwork\Log::getEventIdList(), true))
3123 {
3124 if ($sourceId <= 0)
3125 {
3126 throw new RestException('Could not find livefeed source ID in fields of event "' . $eventName . '"');
3127 }
3128
3129 return array('FIELDS' => array('POST_ID' => $sourceId));
3130 }
3131
3132 throw new RestException('The event "' . $logEventId .'" is not processed by the log.blogpost REST events');
3133 default:
3134 throw new RestException("Incorrect handler ID");
3135 }
3136 }
3137}
3138
3140{
3141 public static function processEvent(array $arParams, array $arHandler): array
3142 {
3143 static $processedIdList = array();
3144
3145 $eventName = $arHandler['EVENT_NAME'];
3146
3147 $appKey = $arHandler['APP_ID'].$arHandler['APPLICATION_TOKEN'];
3148 if (!isset($processedIdList[$appKey]))
3149 {
3150 $processedIdList[$appKey] = array();
3151 }
3152
3153 switch (mb_strtolower($eventName))
3154 {
3155 case 'onsonetgroupadd':
3156 case 'onsonetgroupupdate':
3157 case 'onsonetgroupdelete':
3158
3159 $id = (int)($arParams[0] ?? 0);
3160
3161 if ($id <= 0)
3162 {
3163 throw new RestException('Could not find sonet group ID in fields of event "' . $eventName . '"');
3164 }
3165
3166 if (
3167 mb_strtolower($eventName) === 'onsonetgroupupdate'
3168 && in_array($id, $processedIdList[$appKey], true)
3169 )
3170 {
3171 throw new RestException('ID ' . $id .' has already been processed');
3172 }
3173
3174 if (in_array(mb_strtolower($eventName), array('onsonetgroupadd', 'onsonetgroupupdate')))
3175 {
3176 $processedIdList[$appKey][] = $id;
3177 }
3178
3179 return array('FIELDS' => array('ID' => $id));
3180 default:
3181 throw new RestException("Incorrect handler ID");
3182 }
3183 }
3184}
3185
3187{
3188 public static function processEvent(array $arParams, array $arHandler): array
3189 {
3190 static $processedIdList = array();
3191
3192 $eventName = $arHandler['EVENT_NAME'];
3193
3194 $appKey = $arHandler['APP_ID'].$arHandler['APPLICATION_TOKEN'];
3195 if (!isset($processedIdList[$appKey]))
3196 {
3197 $processedIdList[$appKey] = array();
3198 }
3199
3200 switch(mb_strtolower($eventName))
3201 {
3202 case 'onsonetgroupsubjectadd':
3203 case 'onsonetgroupsubjectupdate':
3204 case 'onsonetgroupsubjectdelete':
3205
3206 $id = (int)($arParams[0] ?? 0);
3207
3208 if ($id <= 0)
3209 {
3210 throw new RestException('Could not find sonet group subject ID in fields of event "' . $eventName . '"');
3211 }
3212
3213 if (
3214 mb_strtolower($eventName) === 'onsonetgroupsubjectupdate'
3215 && in_array($id, $processedIdList[$appKey], true)
3216 )
3217 {
3218 throw new RestException('ID '. $id . 'has already been processed');
3219 }
3220
3221 if (in_array(mb_strtolower($eventName), array('onsonetgroupsubjectadd', 'onsonetgroupsubjectupdate')))
3222 {
3223 $processedIdList[$appKey][] = $id;
3224 }
3225
3226 return array('FIELDS' => array('ID' => $id));
3227 default:
3228 throw new RestException("Incorrect handler ID");
3229 }
3230 }
3231}
$arParams
Определения access_dialog.php:21
$count
Определения admin_tab.php:4
$type
Определения options.php:106
const BLOG_PUBLISH_STATUS_READY
Определения include.php:46
const BLOG_PERMS_READ
Определения include.php:6
const BLOG_PUBLISH_STATUS_PUBLISH
Определения include.php:47
global $APPLICATION
Определения include.php:80
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getById($commentId=0)
Определения comment.php:25
static actionsAfter(array $params)
Определения comment.php:153
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static getList(array $parameters=array())
Определения datamanager.php:431
Определения emoji.php:10
static decode($text)
Определения emoji.php:24
static getBlogPostCacheDir($params=array())
Определения componenthelper.php:4475
static checkBlogPostDestinationList($params, &$resultFields)
Определения componenthelper.php:4245
static processBlogPostShare($fields, $params)
Определения componenthelper.php:1540
static processBlogPostNewMailUserDestinations(&$destinationList)
Определения componenthelper.php:3268
static get(string $key='', $siteId=SITE_ID)
Определения path.php:17
static canUpdate(array $params=[])
Определения access.php:159
static getById($logCommentId=0)
Определения logcomment.php:16
static addInfoToChat($params=[])
Определения usertogroup.php:522
static DeleteLog($commentID)
Определения blog_comment.php:595
static Delete($ID)
Определения blog_comment.php:110
static getSocNetPerms($ID, $useCache=true)
Определения blog_post.php:1460
static GetSocNetPostPerms( $postId=0, $bNeedFull=false, $userId=false, $postAuthor=0)
Определения blog_post.php:1623
static Delete($ID, $bSetSource=false)
Определения log_comments.php:161
static CanPerformOperation($fromUserID, $toUserID, $operation, $bCurrentUserIsAdmin=false)
Определения user_perms.php:231
static GetByID($ID)
Определения blog_post.php:511
static GetList( $arOrder=["ID"=> "DESC"], $arFilter=[], $arGroupBy=false, $arNavStartParams=false, $arSelectFields=[])
Определения blog_post.php:554
static GetList($arOrder=array("ID"=> "ASC"), $arFilter=array(), $arAddParams=array())
Определения blog_post_param.php:13
static GetFileArray($fileId, $uploadDir=false)
Определения file.php:1207
Определения cache.php:11
InitCache($TTL, $uniq_str, $initdir=false, $basedir="cache")
Определения cache.php:30
EndDataCache($vars=false)
Определения cache.php:79
Определения rest.php:24
static unConvertDateTime($iso8601, $enableOffset=false)
Определения rest_util.php:319
Определения rest.php:3140
static processEvent(array $arParams, array $arHandler)
Определения rest.php:3141
static processEvent(array $arParams, array $arHandler)
Определения rest.php:3188
Определения rest.php:3043
static processEvent(array $arParams, array $arHandler)
Определения rest.php:3044
static GetList($arOrder=Array("ID"=> "DESC"), $arFilter=Array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array(), $arParams=array())
Определения log.php:338
Определения rest.php:28
static getGroupSubject($arFields, $n, $server)
Определения rest.php:2792
static setGroupOwner($arFields)
Определения rest.php:2088
static getUserGroups($arFields, $n, $server)
Определения rest.php:2597
static updateGroup($arFields)
Определения rest.php:1897
static getGroupUsers($arFields, $n, $server)
Определения rest.php:2189
static getCurrentUserType()
Определения rest.php:3005
const PERM_READ
Определения rest.php:30
static getGroupFeatureAccess($arFields)
Определения rest.php:2678
static deleteGroupSubject($arFields)
Определения rest.php:2906
static updateGroupUsers($arFields)
Определения rest.php:2450
static shareBlogPost($fields)
Определения rest.php:583
static getBlogPost($fields, $n, $server)
Определения rest.php:138
static deleteBlogComment($fields)
Определения rest.php:1230
static getExtranetSiteId()
Определения rest.php:3029
static createGroup($fields)
Определения rest.php:1697
static deleteGroupUsers($arFields)
Определения rest.php:2524
const PERM_DENY
Определения rest.php:29
static getGroup($arFields, $n, $server)
Определения rest.php:2103
static OnRestServiceBuildDescription()
Определения rest.php:35
static addGroupSubject($fields)
Определения rest.php:2955
static getUserBlogComment($arParams, $offset, CRestServer $server)
Определения rest.php:850
static updateBlogPost($arFields)
Определения rest.php:546
static addBlogPost($arFields)
Определения rest.php:525
static addGroupUsers($arFields)
Определения rest.php:2329
static deleteBlogPost($arFields)
Определения rest.php:567
static requestGroupUser($arFields)
Определения rest.php:2294
const PERM_WRITE
Определения rest.php:31
static updateGroupSubject($fields)
Определения rest.php:2863
static deleteLogComment($arFields)
Определения rest.php:1449
static getUserLogComment($arParams, $offset, CRestServer $server)
Определения rest.php:1280
static createEventInfo($moduleName, $eventName, array $callback)
Определения rest.php:90
static inviteGroupUsers($arFields)
Определения rest.php:2240
static addBlogComment($fields)
Определения rest.php:1068
static getBlogPostUsersImprtnt($fields)
Определения rest.php:762
static deleteGroup($arFields)
Определения rest.php:2047
static getUserBlogPost($arParams, $offset, CRestServer $server)
Определения rest.php:335
static FindFullSetByEventID($event_id)
Определения log_tools.php:223
Определения rest.php:896
static setNavData($result, $dbRes)
Определения rest.php:927
global $CACHE_MANAGER
Определения clear_component_cache.php:7
$options
Определения commerceml2.php:49
if(!is_array($prop["VALUES"])) $tmp
Определения component_props.php:203
$arFields
Определения dblapprove.php:5
</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
$perm
Определения options.php:169
global $USER_FIELD_MANAGER
Определения attempt.php:6
$result
Определения get_property_values.php:14
$filter
Определения iblock_catalog_list.php:54
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$siteId
Определения ajax.php:8
is_set($a, $k=false)
Определения tools.php:2133
BXClearCache($full=false, $initdir='')
Определения tools.php:5150
$value
Определения Param.php:39
Определения action.php:3
Определения handlers.php:8
Определения collection.php:2
$files
Определения mysql_to_pgsql.php:30
$order
Определения payment.php:8
$message
Определения payment.php:8
return false
Определения prolog_main_admin.php:185
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$contentType
Определения quickway.php:301
if(empty($decryptedData)) $storage
Определения quickway.php:270
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$post
Определения template.php:8
$val
Определения options.php:1793
$matches
Определения index.php:22
const SONET_ROLES_USER
Определения include.php:31
const SONET_ENTITY_GROUP
Определения include.php:117
if( $_SERVER $arSocNetFeaturesSettings['REQUEST_METHOD']=="GET" &&($RestoreDefaults ?? null)<> '' && $SONET_RIGHT=="W" &&check_bitrix_sessid())
Определения options.php:35
const SITE_ID
Определения sonet_set_content_view.php:12
$n
Определения update_log.php:107
if(CModule::IncludeModule("forum")) if(CModule::IncludeModule("blog")) $dbLog
Определения updtr1007.php:132
$arFilter
Определения user_search.php:106
$url
Определения iframe.php:7
$dbRes
Определения yandex_detail.php:168
$fields
Определения yandex_run.php:501