Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
blogpost.php
1<?php
2
4
5use Bitrix\Disk\Driver;
6use Bitrix\Disk\Security\DiskSecurityContext;
19
20class BlogPost extends Base
21{
22 public function getDataAction(array $params = []): ?array
23 {
24 $postId = (int)($params['postId'] ?? 0);
25 $public = ($params['public'] ?? 'N');
26 $groupReadOnly = ($params['groupReadOnly'] ?? 'N');
27 $pathToPost = ($params['pathToPost'] ?? '');
28 $voteId = (int)($params['voteId'] ?? 0);
29 $checkModeration = ($params['checkModeration'] ?? 'N');
30
31 $currentUserId = (int)$this->getCurrentUser()->getId();
32 $currentModuleAdmin = \CSocNetUser::isCurrentUserModuleAdmin(SITE_ID, false);
33
34 $logPinnedUserId = 0;
35
36 if ($postId <= 0)
37 {
38 $this->addError(new Error(Loc::getMessage('SONET_CONTROLLER_LIVEFEED_BLOGPOST_EMPTY'), 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_EMPTY'));
39 return null;
40 }
41
42 if (
43 !Loader::includeModule('blog')
44 || !Loader::includeModule('socialnetwork')
45 || !($postItem = \Bitrix\Blog\Item\Post::getById($postId))
46 )
47 {
48 $this->addError(new Error(Loc::getMessage('SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'), 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'));
49 return null;
50 }
51
52 $postFields = $postItem->getFields();
53
54 $logId = 0;
55 $logFavoritesUserId = 0;
56 $allowModerate = false;
57
58 if (
59 $postFields['PUBLISH_STATUS'] === BLOG_PUBLISH_STATUS_READY
60 && $checkModeration === 'Y'
61 )
62 {
63 $postSocnetPermsList = \CBlogPost::getSocNetPerms($postId);
64 if (
65 !empty($postSocnetPermsList['SG'])
66 && is_array($postSocnetPermsList['SG'])
67 )
68 {
69 $groupIdList = array_keys($postSocnetPermsList['SG']);
70 foreach($groupIdList as $groupId)
71 {
72 if (
73 \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $groupId, 'blog', 'full_post', $currentModuleAdmin)
74 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $groupId, 'blog', 'write_post')
75 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $groupId, 'blog', 'moderate_post')
76 )
77 {
78 $allowModerate = true;
79 break;
80 }
81 }
82 }
83 elseif(
84 (int)$postFields['AUTHOR_ID'] === $currentUserId
85 || $currentModuleAdmin
86 )
87 {
88 $allowModerate = true;
89 }
90 }
91
92 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
93
94 $filter = array(
95 "EVENT_ID" => $blogPostLivefeedProvider->getEventId(),
96 "SOURCE_ID" => $postId,
97 );
98
99 if (
100 Loader::includeModule('extranet')
101 && \CExtranet::isExtranetSite(SITE_ID)
102 )
103 {
104 $filter["SITE_ID"] = SITE_ID;
105 }
106 elseif ($public !== 'Y')
107 {
108 $filter["SITE_ID"] = [ SITE_ID, false ];
109 }
110
111 $res = \CSocNetLog::getList(
112 [],
113 $filter,
114 false,
115 false,
116 [ 'ID', 'FAVORITES_USER_ID', 'PINNED_USER_ID' ],
117 [ 'USE_PINNED' => 'Y' ]
118 );
119
120 if ($logEntry = $res->fetch())
121 {
122 $logId = (int)$logEntry['ID'];
123 $logFavoritesUserId = (int)$logEntry['FAVORITES_USER_ID'];
124 $logPinnedUserId = (int)$logEntry['PINNED_USER_ID'];
125 }
126
127 if ((int)$postFields["AUTHOR_ID"] === $currentUserId)
128 {
129 $perms = Permissions::FULL;
130 }
131 elseif (
132 $currentModuleAdmin
133 || \CMain::getGroupRight('blog') >= 'W'
134 )
135 {
136 $perms = Permissions::FULL;
137 }
138 elseif (!$logId)
139 {
140 $perms = Permissions::DENY;
141 }
142 else
143 {
144 $permsResult = $postItem->getSonetPerms([
145 'PUBLIC' => ($public === 'Y'),
146 'CHECK_FULL_PERMS' => true,
147 'LOG_ID' => $logId
148 ]);
149 $perms = $permsResult['PERM'];
150 $groupReadOnly = (
151 $permsResult['PERM'] <= \Bitrix\Blog\Item\Permissions::READ
152 && $permsResult['READ_BY_OSG']
153 ? 'Y'
154 : 'N'
155 );
156 }
157
158 $shareForbidden = ComponentHelper::getBlogPostLimitedViewStatus(array(
159 'logId' => $logId,
160 'postId' => $postId,
161 'authorId' => $postFields['AUTHOR_ID']
162 ));
163
164 $postUrl = \CComponentEngine::makePathFromTemplate(
165 $pathToPost,
166 [
167 'post_id' => $postFields['ID'],
168 'user_id' => $postFields['AUTHOR_ID']
169 ]
170 );
171
172 $voteExportUrl = '';
173
174 if ($voteId > 0)
175 {
176 $voteExportUrl = \CHTTP::urlAddParams(
177 \CHTTP::urlDeleteParams(
178 $postUrl,
179 [ 'exportVoting ' ]
180 ),
181 [ 'exportVoting' => $voteId ]
182 );
183 }
184
185 return [
186 'perms' => $perms,
187 'isGroupReadOnly' => $groupReadOnly,
188 'isShareForbidden' => ($shareForbidden ? 'Y' : 'N'),
189 'logId' => $logId,
190 'logFavoritesUserId' => $logFavoritesUserId,
191 'logPinnedUserId' => $logPinnedUserId,
192 'authorId' => (int)$postFields['AUTHOR_ID'],
193 'urlToPost' => $postUrl,
194 'urlToVoteExport' => $voteExportUrl,
195 'allowModerate' => ($allowModerate ? 'Y' : 'N'),
196 'backgroundCode' => $postFields['BACKGROUND_CODE']
197 ];
198 }
199
200 public function shareAction(array $params = [])
201 {
202 $postId = (int)($params['postId'] ?? 0);
203 $destCodesList = ($params['DEST_CODES'] ?? []);
204 $destData = ($params['DEST_DATA'] ?? []);
205 $invitedUserName = ($params['INVITED_USER_NAME'] ?? []);
206 $invitedUserLastName = ($params['INVITED_USER_LAST_NAME'] ?? []);
207 $invitedUserCrmEntity = ($params['INVITED_USER_CRM_ENTITY'] ?? []);
208 $invitedUserCreateCrmContact = ($params['INVITED_USER_CREATE_CRM_CONTACT'] ?? []);
209 $readOnly = (isset($params['readOnly']) && $params['readOnly'] === 'Y');
210 $pathToUser = ($params['pathToUser'] ?? '');
211 $pathToPost = ($params['pathToPost'] ?? '');
212 $currentUserId = $this->getCurrentUser()->getId();
213
214 $data = [
215 'ALLOW_EMAIL_INVITATION' => (
216 ModuleManager::isModuleInstalled('mail')
217 && ModuleManager::isModuleInstalled('intranet')
218 && (
219 !Loader::includeModule('bitrix24')
220 || \CBitrix24::isEmailConfirmed()
221 )
222 )
223 ];
224
225 if ($postId <= 0)
226 {
227 $this->addError(new Error(Loc::getMessage('SONET_CONTROLLER_LIVEFEED_BLOGPOST_EMPTY'), 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_EMPTY'));
228 return null;
229 }
230
231 if (
232 !Loader::includeModule('blog')
233 || !($postItem = \Bitrix\Blog\Item\Post::getById($postId))
234 )
235 {
236 $this->addError(
237 new Error(
238 Loc::getMessage('SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'),
239 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'
240 )
241 );
242
243 return null;
244 }
245
246 // todo for check access
247 $currentUserPerm = Helper::getBlogPostPerm([
248 'USER_ID' => $currentUserId,
249 'POST_ID' => $postId,
250 ]);
251 if ($currentUserPerm <= Permissions::DENY)
252 {
253 $this->addError(
254 new Error(
255 Loc::getMessage('SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'),
256 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'
257 )
258 );
259
260 return null;
261 }
262
263 $postFields = $postItem->getFields();
264
265 if (
266 (int)$postFields['AUTHOR_ID'] !== $currentUserId
268 )
269 {
270 $visibleUserIdList = \CExtranet::getMyGroupsUsersSimple(SITE_ID);
271
272 if (!empty(array_diff([(int)$postFields['AUTHOR_ID']], $visibleUserIdList)))
273 {
274 $this->addError(
275 new Error(
276 Loc::getMessage('SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'),
277 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'
278 )
279 );
280
281 return null;
282 }
283 }
284
285 $perms2update = [];
286 $sonetPermsListOld = \CBlogPost::getSocNetPerms($postId);
287 foreach($sonetPermsListOld as $type => $val)
288 {
289 foreach($val as $id => $values)
290 {
291 if($type !== 'U')
292 {
293 $perms2update[] = $type . $id;
294 }
295 else
296 {
297 $perms2update[] = (
298 in_array('US' . $id, $values, true)
299 ? 'UA'
300 : $type.$id
301 );
302 }
303 }
304 }
305
306 $newRightsList = [];
307
308 $sonetPermsListNew = [
309 'UA' => [],
310 'U' => [],
311 'UE' => [],
312 'SG' => [],
313 'DR' => []
314 ];
315
316 if (!empty($destData))
317 {
318 try
319 {
320 $entitites = Json::decode($destData);
321 if (!empty($entitites))
322 {
323 $destCodesList = EntitySelector\Converter::convertToFinderCodes($entitites);
324 }
325 }
326 catch(ArgumentException $e)
327 {
328 }
329 }
330
331 foreach($destCodesList as $destCode)
332 {
333 if ($destCode === 'UA')
334 {
335 $sonetPermsListNew['UA'][] = 'UA';
336 }
337 elseif (preg_match('/^UE(.+)$/i', $destCode, $matches))
338 {
339 $sonetPermsListNew['UE'][] = $matches[1];
340 }
341 elseif (preg_match('/^U(\d+)$/i', $destCode, $matches))
342 {
343 $sonetPermsListNew['U'][] = 'U'.$matches[1];
344 }
345 elseif (preg_match('/^SG(\d+)$/i', $destCode, $matches))
346 {
347 $sonetPermsListNew['SG'][] = 'SG'.$matches[1];
348 }
349 elseif (preg_match('/^DR(\d+)$/i', $destCode, $matches))
350 {
351 $sonetPermsListNew['DR'][] = 'DR'.$matches[1];
352 }
353 }
354
355 $HTTPPost = [
356 'SONET_PERMS' => $sonetPermsListNew,
357 'INVITED_USER_NAME' => $invitedUserName,
358 'INVITED_USER_LAST_NAME' => $invitedUserLastName,
359 'INVITED_USER_CRM_ENTITY' => $invitedUserCrmEntity,
360 'INVITED_USER_CREATE_CRM_CONTACT' => $invitedUserCreateCrmContact
361 ];
363 $sonetPermsListNew = $HTTPPost['SONET_PERMS'];
364
365 $currentAdmin = \CSocNetUser::isCurrentUserModuleAdmin();
366 $canPublish = true;
367
368 foreach($sonetPermsListNew as $type => $val)
369 {
370 foreach($val as $code)
371 {
372 if(in_array($type, [ 'U', 'SG', 'DR', 'CRMCONTACT' ]))
373 {
374 if (!in_array($code, $perms2update))
375 {
376 if ($type === 'SG')
377 {
378 $sonetGroupId = (int)str_replace('SG', '', $code);
379
380 $canPublish = (
381 $currentAdmin
382 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $sonetGroupId, 'blog', 'write_post')
383 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $sonetGroupId, 'blog', 'moderate_post')
384 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $sonetGroupId, 'blog', 'full_post')
385 );
386
387 if (!$canPublish)
388 {
389 break;
390 }
391 }
392
393 $perms2update[] = $code;
394 $newRightsList[] = $code;
395 }
396 }
397 elseif ($type === 'UA')
398 {
399 if (!in_array('UA', $perms2update, true))
400 {
401 $perms2update[] = 'UA';
402 $newRightsList[] = 'UA';
403 }
404 }
405 }
406
407 if (!$canPublish)
408 {
409 break;
410 }
411 }
412
413 if (
414 !empty($newRightsList)
415 && $canPublish
416 )
417 {
419 [
420 'POST_ID' => $postId,
421 'BLOG_ID' => $postFields['BLOG_ID'],
422 'SITE_ID' => SITE_ID,
423 'SONET_RIGHTS' => $perms2update,
424 'NEW_RIGHTS' => $newRightsList,
425 'USER_ID' => $currentUserId
426 ],
427 [
428 'MENTION' => 'N',
429 'LIVE' => 'Y',
430 'CAN_USER_COMMENT' => (!$readOnly ? 'Y' : 'N'),
431 'PATH_TO_USER' => $pathToUser,
432 'PATH_TO_POST' => $pathToPost,
433 ]
434 );
435 }
436 elseif (!$canPublish)
437 {
438 $this->addError(new Error(Loc::getMessage('SONET_CONTROLLER_LIVEFEED_BLOGPOST_SHARE_PREMODERATION'), 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_SHARE_PREMODERATION'));
439 return null;
440 }
441 }
442
443 public function addAction(array $params = []): ?array
444 {
445 global $APPLICATION;
446
447 $warnings = [];
448
449 try
450 {
451 if (is_string($params['DEST_DATA'] ?? null))
452 {
453 $params['DEST'] = $this->convertDestData(['DEST_DATA' => $params['DEST_DATA']]);
454 }
455
456 $postId = Helper::addBlogPost($params, $this->getScope(), $resultFields);
457 if ($postId <= 0)
458 {
459 if (
460 is_array($resultFields)
461 && !empty($resultFields['ERROR_MESSAGE_PUBLIC'])
462 )
463 {
464 $this->addError(new Error($resultFields['ERROR_MESSAGE_PUBLIC'], 0, [
465 'public' => 'Y'
466 ]));
467 return null;
468 }
469
470 $e = $APPLICATION->getException();
471 throw new \Exception($e ? $e->getString() : 'Cannot add blog post');
472 }
473
474 if (
475 is_array($resultFields)
476 && !empty($resultFields['WARNING_MESSAGE_PUBLIC'])
477 )
478 {
479 $warnings[] = $resultFields['WARNING_MESSAGE_PUBLIC'];
480 }
481
482 }
483 catch (\Exception $e)
484 {
485 $this->addError(new Error($e->getMessage(), $e->getCode()));
486 return null;
487 }
488
489 return [
490 'id' => $postId,
491 'warnings' => $warnings
492 ];
493 }
494
495 public function updateAction($id = 0, array $params = []): ?array
496 {
497 global $APPLICATION;
498
499 try
500 {
501 if (is_string($params['DEST_DATA'] ?? null))
502 {
503 $params['DEST'] = $this->convertDestData(['DEST_DATA' => $params['DEST_DATA']]);
504 }
505
506 $params['POST_ID'] = $id;
507 $postId = Helper::updateBlogPost($params, $this->getScope(), $resultFields);
508 if ($postId <= 0)
509 {
510 if (
511 is_array($resultFields)
512 && !empty($resultFields['ERROR_MESSAGE_PUBLIC'])
513 )
514 {
515 $this->addError(new Error($resultFields['ERROR_MESSAGE_PUBLIC'], 0, [
516 'public' => 'Y'
517 ]));
518 return null;
519 }
520
521 $e = $APPLICATION->getException();
522 throw new \Exception($e ? $e->getString() : 'Cannot update blog post');
523 }
524 }
525 catch (\Exception $e)
526 {
527 $this->addError(new Error($e->getMessage(), $e->getCode()));
528
529 return null;
530 }
531
532 return [
533 'id' => $postId
534 ];
535 }
536
537 public function getBlogPostMobileFullDataAction(array $params = []): ?array
538 {
539 if (!Loader::includeModule('mobile'))
540 {
541 $this->addError(new Error('Mobile module not installed', 'SONET_CONTROLLER_LIVEFEED_MOBILE_MODULE_NOT_INSTALLED'));
542 return null;
543 }
544 return \Bitrix\Mobile\Livefeed\Helper::getBlogPostFullData($params);
545 }
546
547 public function deleteAction($id = 0): ?bool
548 {
549 try
550 {
551 $result = Helper::deleteBlogPost([
552 'POST_ID' => (int)$id,
553 ]);
554 }
555 catch (\Exception $e)
556 {
557 $this->addError(new Error($e->getMessage(), $e->getCode()));
558 return null;
559 }
560
561 return $result;
562 }
563
564 public function getMainPostFormAction(array $params): ?Component
565 {
566 $postId = (int) $params['postId'];
567 if (!$this->checkReadFormAccess($postId, 0))
568 {
569 $this->addError(new Error('Access denied'));
570
571 return null;
572 }
573
574 $formId = (is_string($params['formId'] ?? null) ? $params['formId'] : '');
575 $jsObjName = (is_string($params['jsObjName'] ?? null) ? $params['jsObjName'] : '');
576 $LHEId = (is_string($params['LHEId'] ?? null) ? $params['LHEId'] : '');
577 if (!$formId || !$jsObjName || !$LHEId)
578 {
579 $this->addError(new Error('Required parameters were not passed.'));
580
581 return null;
582 }
583
584 $postId = (is_numeric($params['postId'] ?? null) ? (int) $params['postId'] : 0);
585 $text = (is_string($params['text'] ?? null) ? $params['text'] : '');
586
587 $ctrlEnterHandler = (is_string($params['ctrlEnterHandler'] ?? null)
588 ? $params['ctrlEnterHandler']
589 : ''
590 );
591 $allowEmailInvitation = (is_bool($params['allowEmailInvitation'] ?? null)
592 ? $params['allowEmailInvitation']
593 : false
594 );
595 $useCut = (is_bool($params['useCut'] ?? null) ? $params['useCut'] : false);
596 $allowVideo = (is_bool($params['allowVideo'] ?? null) ? $params['allowVideo'] : false);
597
598 global $USER_FIELD_MANAGER;
599 $postFields = $USER_FIELD_MANAGER->getUserFields('BLOG_POST', $postId, LANGUAGE_ID);
600
601 $properties = [];
602 if (isset($postFields['UF_BLOG_POST_URL_PRV']))
603 {
604 $properties[] = $postFields['UF_BLOG_POST_URL_PRV'];
605 }
606 if (isset($postFields['UF_BLOG_POST_FILE']))
607 {
608 $properties[] = $postFields['UF_BLOG_POST_FILE'];
609 }
610
611 $tags = [];
612
613 if ($postId)
614 {
615 $postFields = Helper::getBlogPostFields($postId);
616
617 if ($postFields['CATEGORY_ID'] <> '')
618 {
619 $tags = $this->getPostTags($postId, $postFields['CATEGORY_ID']);
620 }
621 }
622
623 $component = new Component(
624 'bitrix:main.post.form',
625 '',
626 [
627 'FORM_ID' => $formId,
628 'SHOW_MORE' => 'Y',
629 'DEST_CONTEXT' => 'BLOG_POST',
630 'DESTINATION_SHOW' => 'Y',
631
632 'LHE' => [
633 'id' => $LHEId,
634 'documentCSS' => 'body {color:#434343;}',
635 'iframeCss' => 'html body { line-height: 20px!important;}',
636 'ctrlEnterHandler' => $ctrlEnterHandler,
637 'jsObjName' => $jsObjName,
638 'fontSize' => '14px',
639 'bInitByJS' => true,
640 'width' => '100%',
641 'minBodyWidth' => '100%',
642 'normalBodyWidth' => '100%',
643 'autoResizeMaxHeight' => 'Infinity',
644 'minBodyHeight' => 200,
645 'autoResize' => true,
646 'saveOnBlur' => false,
647 'lazyLoad' => true,
648 ],
649
650 'TEXT' => [
651 'NAME' => 'POST_MESSAGE',
652 'VALUE' => \Bitrix\Main\Text\Emoji::decode(htmlspecialcharsBack($text)),
653 'HEIGHT' => '120px'
654 ],
655
656 'USE_CLIENT_DATABASE' => 'Y',
657 'ALLOW_EMAIL_INVITATION' => $allowEmailInvitation ? 'Y' : 'N',
658 'MENTION_ENTITIES' => [
659 [
660 'id' => 'user',
661 'options' => [
662 'emailUsers' => true,
663 'inviteEmployeeLink' => false,
664 ],
665 ],
666 [
667 'id' => 'department',
668 'options' => [
669 'selectMode' => 'usersAndDepartments',
670 'allowFlatDepartments' => false,
671 ],
672 ],
673 [
674 'id' => 'project',
675 'options' => [
676 'features' => [
677 'blog' => [
678 'premoderate_post',
679 'moderate_post',
680 'write_post',
681 'full_post'
682 ],
683 ],
684 ],
685 ],
686 ],
687
688 'PARSER' => [
689 'Bold',
690 'Italic',
691 'Underline',
692 'Strike',
693 'ForeColor',
694 'FontList',
695 'FontSizeList',
696 'RemoveFormat',
697 'Quote',
698 'Code',
699 ($useCut ? 'InsertCut' : ''),
700 'CreateLink',
701 'Image',
702 'Table',
703 'Justify',
704 'InsertOrderedList',
705 'InsertUnorderedList',
706 'SmileList',
707 'Source',
708 'UploadImage',
709 ($allowVideo ? 'InputVideo' : ''),
710 'MentionUser',
711 ],
712
713 'BUTTONS' => [
714 'UploadImage',
715 'UploadFile',
716 'CreateLink',
717 ($allowVideo ? 'InputVideo' : ''),
718 'Quote',
719 'MentionUser',
720 'InputTag',
721 'VideoMessage',
722 ],
723
724 'TAGS' => [
725 'ID' => 'TAGS',
726 'NAME' => 'TAGS',
727 'VALUE' => $tags,
728 'USE_SEARCH' => 'Y',
729 'FILTER' => 'blog',
730 ],
731
732 'PROPERTIES' => $properties,
733 'UPLOAD_FILE_PARAMS' => [
734 'width' => 400,
735 'height' => 400,
736 ],
737 ]
738 );
739
740 return $component;
741 }
742
743 public function getPostFormInitDataAction(int $postId, int $groupId): ?array
744 {
745 $postId = (int) $postId;
746 $groupId = (int) $groupId;
747
748 $editMode = $postId > 0;
749 $groupMode = $groupId > 0;
750
751 if (!$this->checkReadFormAccess($postId))
752 {
753 $this->addError(new Error('Access denied'));
754
755 return null;
756 }
757
758 $userPostEditOption = \CUserOptions::getOption('socialnetwork', 'postEdit');
759
760 $initData = [
761 'isShownPostTitle' => ($userPostEditOption['showTitle'] ?? null) === 'Y' ? 'Y' : 'N',
762 'allUsersTitle' => ModuleManager::isModuleInstalled('intranet')
763 ? Loc::getMessage('SN_MPF_DESTINATION_EMPLOYEES')
764 : Loc::getMessage('SN_MPF_DESTINATION_USERS')
765 ,
766 'allowEmailInvitation' => (
767 ModuleManager::isModuleInstalled('mail')
768 && ModuleManager::isModuleInstalled('intranet')
769 && (
770 !Loader::includeModule('bitrix24')
771 || \CBitrix24::isEmailConfirmed()
772 )
773 ),
775 ];
776
777 if ($editMode)
778 {
779 try
780 {
781 $postFields = Helper::getBlogPostFields($postId);
782
783 $authorId = $postFields['AUTHOR_ID'];
784
785 $initData['title'] = $postFields['MICRO'] === 'Y' ? '' : $postFields['TITLE'];
786 $initData['message'] = $postFields['DETAIL_TEXT'];
787
788 $perms = \CBlogPost::getSocnetPerms($postFields['ID']);
789 if (
790 is_array($perms['U'][$authorId] ?? null)
791 && in_array('US' . $authorId, $perms['U'][$authorId])
792 )
793 {
794 $perms['U']['A'] = [];
795 }
796 if (
797 !is_array($perms['U'][$authorId] ?? null)
798 || !in_array('U' . $authorId, $perms["U"][$authorId])
799 )
800 {
801 unset($perms['U'][$authorId]);
802 }
803
804 $destList = $this->getPostFormDestList($perms);
805 $initData['recipients'] = Json::encode($destList);
806
807 $initData['fileIds'] = $postFields['UF_BLOG_POST_FILE'];
808 }
809 catch (\Exception $e)
810 {
811 $this->addError(new Error($e->getMessage(), $e->getCode()));
812
813 return null;
814 }
815 }
816 else
817 {
818 if ($groupMode)
819 {
820 if ($this->checkGroupAccess($groupId))
821 {
822 $initData['recipients'] = Json::encode($this->getPostFormDestList(
823 ['SG' => [$groupId => ['SG' . $groupId]]]
824 ));
825 }
826 }
827 else
828 {
830 {
831 $initData['recipients'] = Json::encode($this->getPostFormDestList(
832 ['U' => ['A' => 'UA']]
833 ));
834 }
835 }
836 }
837
838 return $initData;
839 }
840
841 // todo
842 public function uploadAIImageAction(string $imageUrl): ?array
843 {
844 $urlData = parse_url($imageUrl);
845 if ($urlData['scheme'] !== 'https')
846 {
847 $this->addError(new Error('System error. Only https.'));
848
849 return null;
850 }
851
852 if (!Loader::includeModule('disk'))
853 {
854 $this->addError(new Error('System error. Disk is not installed.'));
855
856 return null;
857 }
858
859 $client = new \Bitrix\Main\Web\HttpClient();
860 $client->setPrivateIp(false);
861
862 $tempPath = \CFile::getTempName('', bx_basename($imageUrl));
863 $isDownloaded = $client->download($imageUrl, $tempPath);
864 if (!$isDownloaded)
865 {
866 $this->addError(new Error('System error. File cannot be downloaded.'));
867
868 return null;
869 }
870
871 $currentUserId = $this->getCurrentUser()->getId();
872
873 $fileType = $client->getHeaders()->getContentType() ?: \CFile::getContentType($tempPath);
874 $recordFile = \CFile::makeFileArray($tempPath, $fileType);
875 $recordFile['MODULE_ID'] = 'socialnetwork';
876
877 $storage = Driver::getInstance()->getStorageByUserId($currentUserId);
878 $folder = $storage->getFolderForUploadedFiles();
879
880 if (!$folder->canAdd(new DiskSecurityContext($currentUserId)))
881 {
882 $this->addError(new Error('System error. Access denied.'));
883
884 return null;
885 }
886
888 $file = $folder->uploadFile(
889 $recordFile,
890 [
891 'CREATED_BY' => $currentUserId,
892 ],
893 [],
894 true
895 );
896
897 return ['fileId' => 'n' . $file->getId()];
898 }
899
900 private function getPostFormDestList(array $permList): array
901 {
902 $destList = [];
903
904 foreach ($permList as $type => $list)
905 {
906 if (!is_array($list))
907 {
908 continue;
909 }
910
911 foreach ($list as $id => $value)
912 {
913 if ($type === 'U')
914 {
915 if ($id === 'A' || $value === 'A')
916 {
918 {
919 $destList['UA'] = 'groups';
920 }
921 }
922 else
923 {
924 $destList['U' . $id] = 'users';
925 }
926 }
927 elseif ($type === 'SG')
928 {
929 $destList['SG' . $id] = 'sonetgroups';
930 }
931 elseif ($type === 'DR')
932 {
933 $destList['DR' . $id] = 'department';
934 }
935 }
936 }
937
938 return EntitySelector\Converter::sortEntities(
939 EntitySelector\Converter::convertFromFinderCodes(array_keys($destList))
940 );
941 }
942
943 private function checkReadFormAccess(int $postId): bool
944 {
945 $currentUserId = $this->getCurrentUser()->getId();
946
947 $editMode = $postId > 0;
948 if ($editMode)
949 {
950 $currentUserPerm = Helper::getBlogPostPerm([
951 'USER_ID' => $currentUserId,
952 'POST_ID' => $postId,
953 ]);
954 if ($currentUserPerm >= Permissions::READ)
955 {
956 return true;
957 }
958 }
959 else
960 {
961 return true;
962 }
963
964 return false;
965 }
966
967 private function checkGroupAccess(int $groupId): bool
968 {
969 $currentUserId = $this->getCurrentUser()->getId();
970
971 if (\CSocNetGroup::getByID($groupId))
972 {
973 if (!\CSocNetFeatures::isActiveFeature(SONET_ENTITY_GROUP, $groupId, 'blog'))
974 {
975 return false;
976 }
977 }
978 else
979 {
980 return false;
981 }
982
983 if (
984 !\CSocNetFeaturesPerms::canPerformOperation(
985 $currentUserId,
986 SONET_ENTITY_GROUP,
987 $groupId,
988 'blog',
989 'premoderate_post'
990 )
991 )
992 {
993 return false;
994 }
995
996 return true;
997 }
998
999 private function convertDestData(array $data): array
1000 {
1001 if (Loader::includeModule('blog'))
1002 {
1004
1005 $destData = [];
1006 foreach ($data['SPERM'] as $list)
1007 {
1008 $destData = array_merge($destData, $list);
1009 }
1010
1011 return $destData;
1012 }
1013
1014 return [];
1015 }
1016
1017 private function getPostTags(int $postId, string $categoryId): array
1018 {
1019 $tags = [];
1020
1021 $category = explode(",", $categoryId);
1022
1023 $blogCategoryList = [];
1024 $res = \CBlogCategory::getList([], ['@ID' => $category]);
1025 while ($blogCategoryFields = $res->fetch())
1026 {
1027 $blogCategoryList[(int) $blogCategoryFields['ID']] = htmlspecialcharsEx($blogCategoryFields['NAME']);
1028 }
1029
1030 $res = \CBlogPostCategory::getList(
1031 [ 'ID' => 'ASC' ],
1032 [
1033 '@CATEGORY_ID' => $category,
1034 'POST_ID' => $postId,
1035 ],
1036 false,
1037 false,
1038 ['CATEGORY_ID']
1039 );
1040 while ($blogPostCategoryFields = $res->fetch())
1041 {
1042 if (!isset($blogCategoryList[(int) $blogPostCategoryFields['CATEGORY_ID']]))
1043 {
1044 continue;
1045 }
1046
1047 $tags[] = $blogCategoryList[(int) $blogPostCategoryFields['CATEGORY_ID']];
1048 }
1049
1050 return $tags;
1051 }
1052}
1053
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static decode($text)
Definition emoji.php:24
static convertSelectorRequestData(array &$postFields=[], array $params=[])
static processBlogPostShare($fields, $params)
static getBlogPostLimitedViewStatus($params=array())
static processBlogPostNewMailUser(&$HTTPPost, &$componentResult)
Definition blogpost.php:21
getBlogPostMobileFullDataAction(array $params=[])
Definition blogpost.php:537
addAction(array $params=[])
Definition blogpost.php:443
getPostFormInitDataAction(int $postId, int $groupId)
Definition blogpost.php:743
updateAction($id=0, array $params=[])
Definition blogpost.php:495
getMainPostFormAction(array $params)
Definition blogpost.php:564
deleteAction($id=0)
Definition blogpost.php:547
getDataAction(array $params=[])
Definition blogpost.php:22
shareAction(array $params=[])
Definition blogpost.php:200
static updateBlogPost($params=[], $scope=Controller::SCOPE_AJAX, &$resultFields=[])
Definition helper.php:467
static addBlogPost($params, $scope=Controller::SCOPE_AJAX, &$resultFields=[])
Definition helper.php:30
static getBlogPostFields($postId)
Definition helper.php:1016
static deleteBlogPost(array $params=[])
Definition helper.php:883
static getBlogPostPerm(array $params=[])
Definition helper.php:958