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');
31 $currentUserId = (int)$this->getCurrentUser()->getId();
32 $currentModuleAdmin = \CSocNetUser::isCurrentUserModuleAdmin(SITE_ID,
false);
43 !Loader::includeModule(
'blog')
44 || !Loader::includeModule(
'socialnetwork')
45 || !($postItem = \
Bitrix\
Blog\Item\Post::getById($postId))
48 $this->
addError(
new Error(
Loc::getMessage(
'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'),
'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'));
52 $postFields = $postItem->getFields();
55 $logFavoritesUserId = 0;
56 $allowModerate =
false;
59 $postFields[
'PUBLISH_STATUS'] === BLOG_PUBLISH_STATUS_READY
60 && $checkModeration ===
'Y'
63 $postSocnetPermsList = \CBlogPost::getSocNetPerms($postId);
65 !empty($postSocnetPermsList[
'SG'])
66 && is_array($postSocnetPermsList[
'SG'])
69 $groupIdList = array_keys($postSocnetPermsList[
'SG']);
70 foreach($groupIdList as $groupId)
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')
78 $allowModerate =
true;
84 (
int)$postFields[
'AUTHOR_ID'] === $currentUserId
85 || $currentModuleAdmin
88 $allowModerate =
true;
92 $blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
95 "EVENT_ID" => $blogPostLivefeedProvider->getEventId(),
96 "SOURCE_ID" => $postId,
100 Loader::includeModule(
'extranet')
101 && \CExtranet::isExtranetSite(SITE_ID)
104 $filter[
"SITE_ID"] = SITE_ID;
106 elseif ($public !==
'Y')
108 $filter[
"SITE_ID"] = [ SITE_ID, false ];
111 $res = \CSocNetLog::getList(
116 [
'ID',
'FAVORITES_USER_ID',
'PINNED_USER_ID' ],
117 [
'USE_PINNED' =>
'Y' ]
120 if ($logEntry = $res->fetch())
122 $logId = (int)$logEntry[
'ID'];
123 $logFavoritesUserId = (int)$logEntry[
'FAVORITES_USER_ID'];
124 $logPinnedUserId = (int)$logEntry[
'PINNED_USER_ID'];
127 if ((
int)$postFields[
"AUTHOR_ID"] === $currentUserId)
129 $perms = Permissions::FULL;
133 || \CMain::getGroupRight(
'blog') >=
'W'
136 $perms = Permissions::FULL;
140 $perms = Permissions::DENY;
144 $permsResult = $postItem->getSonetPerms([
145 'PUBLIC' => ($public ===
'Y'),
146 'CHECK_FULL_PERMS' =>
true,
149 $perms = $permsResult[
'PERM'];
152 && $permsResult[
'READ_BY_OSG']
161 'authorId' => $postFields[
'AUTHOR_ID']
164 $postUrl = \CComponentEngine::makePathFromTemplate(
167 'post_id' => $postFields[
'ID'],
168 'user_id' => $postFields[
'AUTHOR_ID']
176 $voteExportUrl = \CHTTP::urlAddParams(
177 \CHTTP::urlDeleteParams(
181 [
'exportVoting' => $voteId ]
187 'isGroupReadOnly' => $groupReadOnly,
188 'isShareForbidden' => ($shareForbidden ?
'Y' :
'N'),
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']
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();
215 'ALLOW_EMAIL_INVITATION' => (
216 ModuleManager::isModuleInstalled(
'mail')
217 && ModuleManager::isModuleInstalled(
'intranet')
219 !Loader::includeModule(
'bitrix24')
220 || \CBitrix24::isEmailConfirmed()
232 !Loader::includeModule(
'blog')
233 || !($postItem = \
Bitrix\
Blog\Item\Post::getById($postId))
239 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'
248 'USER_ID' => $currentUserId,
249 'POST_ID' => $postId,
251 if ($currentUserPerm <= Permissions::DENY)
256 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'
263 $postFields = $postItem->getFields();
266 (
int)$postFields[
'AUTHOR_ID'] !== $currentUserId
270 $visibleUserIdList = \CExtranet::getMyGroupsUsersSimple(SITE_ID);
272 if (!empty(array_diff([(
int)$postFields[
'AUTHOR_ID']], $visibleUserIdList)))
277 'SONET_CONTROLLER_LIVEFEED_BLOGPOST_NOT_FOUND'
286 $sonetPermsListOld = \CBlogPost::getSocNetPerms($postId);
287 foreach($sonetPermsListOld as $type => $val)
289 foreach($val as $id => $values)
293 $perms2update[] = $type . $id;
298 in_array(
'US' . $id, $values,
true)
308 $sonetPermsListNew = [
316 if (!empty($destData))
320 $entitites = Json::decode($destData);
321 if (!empty($entitites))
323 $destCodesList = EntitySelector\Converter::convertToFinderCodes($entitites);
331 foreach($destCodesList as $destCode)
333 if ($destCode ===
'UA')
335 $sonetPermsListNew[
'UA'][] =
'UA';
337 elseif (preg_match(
'/^UE(.+)$/i', $destCode, $matches))
339 $sonetPermsListNew[
'UE'][] = $matches[1];
341 elseif (preg_match(
'/^U(\d+)$/i', $destCode, $matches))
343 $sonetPermsListNew[
'U'][] =
'U'.$matches[1];
345 elseif (preg_match(
'/^SG(\d+)$/i', $destCode, $matches))
347 $sonetPermsListNew[
'SG'][] =
'SG'.$matches[1];
349 elseif (preg_match(
'/^DR(\d+)$/i', $destCode, $matches))
351 $sonetPermsListNew[
'DR'][] =
'DR'.$matches[1];
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
363 $sonetPermsListNew = $HTTPPost[
'SONET_PERMS'];
365 $currentAdmin = \CSocNetUser::isCurrentUserModuleAdmin();
368 foreach($sonetPermsListNew as $type => $val)
370 foreach($val as $code)
372 if(in_array($type, [
'U',
'SG',
'DR',
'CRMCONTACT' ]))
374 if (!in_array($code, $perms2update))
378 $sonetGroupId = (int)str_replace(
'SG',
'', $code);
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')
393 $perms2update[] = $code;
394 $newRightsList[] = $code;
397 elseif ($type ===
'UA')
399 if (!in_array(
'UA', $perms2update,
true))
401 $perms2update[] =
'UA';
402 $newRightsList[] =
'UA';
414 !empty($newRightsList)
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
430 'CAN_USER_COMMENT' => (!$readOnly ?
'Y' :
'N'),
431 'PATH_TO_USER' => $pathToUser,
432 'PATH_TO_POST' => $pathToPost,
436 elseif (!$canPublish)
438 $this->
addError(
new Error(
Loc::getMessage(
'SONET_CONTROLLER_LIVEFEED_BLOGPOST_SHARE_PREMODERATION'),
'SONET_CONTROLLER_LIVEFEED_BLOGPOST_SHARE_PREMODERATION'));
451 if (is_string($params[
'DEST_DATA'] ??
null))
453 $params[
'DEST'] = $this->convertDestData([
'DEST_DATA' => $params[
'DEST_DATA']]);
460 is_array($resultFields)
461 && !empty($resultFields[
'ERROR_MESSAGE_PUBLIC'])
464 $this->
addError(
new Error($resultFields[
'ERROR_MESSAGE_PUBLIC'], 0, [
470 $e = $APPLICATION->getException();
471 throw new \Exception($e ? $e->getString() :
'Cannot add blog post');
475 is_array($resultFields)
476 && !empty($resultFields[
'WARNING_MESSAGE_PUBLIC'])
479 $warnings[] = $resultFields[
'WARNING_MESSAGE_PUBLIC'];
491 'warnings' => $warnings
501 if (is_string($params[
'DEST_DATA'] ??
null))
503 $params[
'DEST'] = $this->convertDestData([
'DEST_DATA' => $params[
'DEST_DATA']]);
506 $params[
'POST_ID'] = $id;
511 is_array($resultFields)
512 && !empty($resultFields[
'ERROR_MESSAGE_PUBLIC'])
515 $this->
addError(
new Error($resultFields[
'ERROR_MESSAGE_PUBLIC'], 0, [
521 $e = $APPLICATION->getException();
522 throw new \Exception($e ? $e->getString() :
'Cannot update blog post');
566 $postId = (int) $params[
'postId'];
567 if (!$this->checkReadFormAccess($postId, 0))
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)
579 $this->
addError(
new Error(
'Required parameters were not passed.'));
584 $postId = (is_numeric($params[
'postId'] ??
null) ? (int) $params[
'postId'] : 0);
585 $text = (is_string($params[
'text'] ??
null) ? $params[
'text'] :
'');
587 $ctrlEnterHandler = (is_string($params[
'ctrlEnterHandler'] ??
null)
588 ? $params[
'ctrlEnterHandler']
591 $allowEmailInvitation = (is_bool($params[
'allowEmailInvitation'] ??
null)
592 ? $params[
'allowEmailInvitation']
595 $useCut = (is_bool($params[
'useCut'] ??
null) ? $params[
'useCut'] :
false);
596 $allowVideo = (is_bool($params[
'allowVideo'] ??
null) ? $params[
'allowVideo'] :
false);
598 global $USER_FIELD_MANAGER;
599 $postFields = $USER_FIELD_MANAGER->getUserFields(
'BLOG_POST', $postId, LANGUAGE_ID);
602 if (isset($postFields[
'UF_BLOG_POST_URL_PRV']))
604 $properties[] = $postFields[
'UF_BLOG_POST_URL_PRV'];
606 if (isset($postFields[
'UF_BLOG_POST_FILE']))
608 $properties[] = $postFields[
'UF_BLOG_POST_FILE'];
617 if ($postFields[
'CATEGORY_ID'] <>
'')
619 $tags = $this->getPostTags($postId, $postFields[
'CATEGORY_ID']);
624 'bitrix:main.post.form',
627 'FORM_ID' => $formId,
629 'DEST_CONTEXT' =>
'BLOG_POST',
630 'DESTINATION_SHOW' =>
'Y',
634 'documentCSS' =>
'body {color:#434343;}',
635 'iframeCss' =>
'html body { line-height: 20px!important;}',
636 'ctrlEnterHandler' => $ctrlEnterHandler,
637 'jsObjName' => $jsObjName,
638 'fontSize' =>
'14px',
641 'minBodyWidth' =>
'100%',
642 'normalBodyWidth' =>
'100%',
643 'autoResizeMaxHeight' =>
'Infinity',
644 'minBodyHeight' => 200,
645 'autoResize' =>
true,
646 'saveOnBlur' =>
false,
651 'NAME' =>
'POST_MESSAGE',
656 'USE_CLIENT_DATABASE' =>
'Y',
657 'ALLOW_EMAIL_INVITATION' => $allowEmailInvitation ?
'Y' :
'N',
658 'MENTION_ENTITIES' => [
662 'emailUsers' =>
true,
663 'inviteEmployeeLink' =>
false,
667 'id' =>
'department',
669 'selectMode' =>
'usersAndDepartments',
670 'allowFlatDepartments' =>
false,
699 ($useCut ?
'InsertCut' :
''),
705 'InsertUnorderedList',
709 ($allowVideo ?
'InputVideo' :
''),
717 ($allowVideo ?
'InputVideo' :
''),
732 'PROPERTIES' => $properties,
733 'UPLOAD_FILE_PARAMS' => [
745 $postId = (int) $postId;
746 $groupId = (int) $groupId;
748 $editMode = $postId > 0;
749 $groupMode = $groupId > 0;
751 if (!$this->checkReadFormAccess($postId))
758 $userPostEditOption = \CUserOptions::getOption(
'socialnetwork',
'postEdit');
761 'isShownPostTitle' => ($userPostEditOption[
'showTitle'] ??
null) ===
'Y' ?
'Y' :
'N',
762 'allUsersTitle' => ModuleManager::isModuleInstalled(
'intranet')
766 'allowEmailInvitation' => (
767 ModuleManager::isModuleInstalled(
'mail')
768 && ModuleManager::isModuleInstalled(
'intranet')
770 !Loader::includeModule(
'bitrix24')
771 || \CBitrix24::isEmailConfirmed()
783 $authorId = $postFields[
'AUTHOR_ID'];
785 $initData[
'title'] = $postFields[
'MICRO'] ===
'Y' ?
'' : $postFields[
'TITLE'];
786 $initData[
'message'] = $postFields[
'DETAIL_TEXT'];
788 $perms = \CBlogPost::getSocnetPerms($postFields[
'ID']);
790 is_array($perms[
'U'][$authorId] ??
null)
791 && in_array(
'US' . $authorId, $perms[
'U'][$authorId])
794 $perms[
'U'][
'A'] = [];
797 !is_array($perms[
'U'][$authorId] ??
null)
798 || !in_array(
'U' . $authorId, $perms[
"U"][$authorId])
801 unset($perms[
'U'][$authorId]);
804 $destList = $this->getPostFormDestList($perms);
805 $initData[
'recipients'] = Json::encode($destList);
807 $initData[
'fileIds'] = $postFields[
'UF_BLOG_POST_FILE'];
820 if ($this->checkGroupAccess($groupId))
822 $initData[
'recipients'] = Json::encode($this->getPostFormDestList(
823 [
'SG' => [$groupId => [
'SG' . $groupId]]]
831 $initData[
'recipients'] = Json::encode($this->getPostFormDestList(
832 [
'U' => [
'A' =>
'UA']]
862 $tempPath = \CFile::getTempName(
'', bx_basename($imageUrl));