23 $commentText = (string)($params[
'commentText'] ??
'');
24 $excludedUserIdList = (isset($params[
'excludedUserIdList']) && is_array($params[
'excludedUserIdList']) ? $params[
'excludedUserIdList'] : []);
25 $postId = (int)($params[
'postId'] ?? 0);
26 $blogId = (int)($params[
'blogId'] ?? 0);
27 $siteId = (string)($params[
'siteId'] ?? SITE_ID);
29 $authorId = (int)($params[
'authorId'] ?? 0);
32 $excludedUserIdList[] = $authorId;
34 $excludedUserIdList = array_map(
function ($item) {
return (
int)$item; }, $excludedUserIdList);
35 $excludedUserIdList = array_unique($excludedUserIdList);
47 $postFields = \CBlogPost::getById($postId);
48 $blogId = (int)$postFields[
'BLOG_ID'];
53 || !Loader::includeModule(
'blog')
59 $newRightsList = self::parseUserList([
60 'commentText' => $commentText,
62 'excludedUserIdList' => $excludedUserIdList,
65 $newRightsList = array_merge($newRightsList, self::parseProjectList([
66 'commentText' => $commentText,
70 $newRightsList = array_merge($newRightsList, self::parseDepartmentList([
71 'commentText' => $commentText,
75 if (empty($newRightsList))
80 $fullRightsList = $newRightsList;
82 $blogPermsList = \CBlogPost::getSocnetPerms($postId);
83 foreach ($blogPermsList as $entitiesList)
85 foreach ($entitiesList as $rightsList)
87 $fullRightsList = array_merge($fullRightsList, $rightsList);
91 $fullRightsList = array_unique($fullRightsList);
93 return \Bitrix\Socialnetwork\ComponentHelper::processBlogPostShare(
98 'SONET_RIGHTS' => $fullRightsList,
99 'NEW_RIGHTS' => $newRightsList,
100 'USER_ID' => $authorId,
103 'PATH_TO_USER' => Option::get(
'main',
'TOOLTIP_PATH_TO_USER', SITE_DIR .
'company/personal/user/#user_id#/', $siteId),
104 'PATH_TO_POST' =>
Path::get(
'userblogpost_page', $siteId),
105 'NAME_TEMPLATE' => \CSite::getNameFormat(),
109 'CLEAR_COMMENTS_CACHE' => (isset($params[
'clearCache']) && $params[
'clearCache'] ===
false ?
'N' :
'Y')
114 private static function parseUserList(array $params = []): array
118 $commentText = (string)($params[
'commentText'] ??
'');
119 $excludedUserIdList = (isset($params[
'excludedUserIdList']) && is_array($params[
'excludedUserIdList']) ? $params[
'excludedUserIdList'] : []);
120 $postId = (int)($params[
'postId'] ?? 0);
124 || !Loader::includeModule(
'blog')
130 $mentionedUserIdList = \Bitrix\Socialnetwork\Helper\Mention::getUserIds($commentText);
131 if (empty($mentionedUserIdList))
136 $userIdToShareList = [];
138 foreach ($mentionedUserIdList as $userId)
140 $userId = (int)$userId;
143 || in_array($userId, $excludedUserIdList,
true)
149 $postPerm = \CBlogPost::getSocNetPostPerms([
150 'POST_ID' => $postId,
152 'USER_ID' => $userId,
153 'IGNORE_ADMIN' =>
true,
156 if ($postPerm >= Permissions::PREMODERATE)
161 $userIdToShareList[] = $userId;
164 $userIdToShareList = array_unique($userIdToShareList);
165 if (empty($userIdToShareList))
170 foreach ($userIdToShareList as $userId)
178 private static function parseProjectList(array $params = []): array
184 $commentText = (string)($params[
'commentText'] ??
'');
186 $postId = (int)($params[
'postId'] ?? 0);
190 || !Loader::includeModule(
'blog')
196 $mentionedProjectIdList = \Bitrix\Socialnetwork\Helper\Mention::getProjectIds($commentText);
197 if (empty($mentionedProjectIdList))
202 $projectIdToShareList = [];
204 $currentUserId = $USER->getId();
205 $currentAdmin = \CSocNetUser::isCurrentUserModuleAdmin(SITE_ID,
false);
206 $postPermsData = self::getSocNetPerms([
210 foreach ($mentionedProjectIdList as $projectId)
212 $projectId = (int)$projectId;
216 isset($postPermsData[
'SG'])
217 && isset($postPermsData[
'SG'][$projectId])
226 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $projectId,
'blog',
'write_post')
227 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $projectId,
'blog',
'moderate_post')
228 || \CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $projectId,
'blog',
'full_post')
236 $projectIdToShareList[] = $projectId;
239 $projectIdToShareList = array_unique($projectIdToShareList);
240 if (empty($projectIdToShareList))
245 $res = WorkgroupTable::getList([
247 '@ID' => $projectIdToShareList,
249 'select' => [
'ID' ],
251 while ($workgroupFields = $res->fetch())
253 $result[] =
'SG' . $workgroupFields[
'ID'];
259 private static function parseDepartmentList(array $params = []): array
265 $commentText = (string)($params[
'commentText'] ??
'');
267 $postId = (int)($params[
'postId'] ?? 0);
271 || !ModuleManager::isModuleInstalled(
'intranet')
272 || !Loader::includeModule(
'blog')
273 || !Loader::includeModule(
'iblock')
280 Loader::includeModule(
'extranet')
281 && !\CExtranet::isIntranetUser()
287 $mentionedDepartmentIdList = \Bitrix\Socialnetwork\Helper\Mention::getDepartmentIds($commentText);
288 if (empty($mentionedDepartmentIdList))
293 $departmentIdToShareList = [];
295 $postPermsData = self::getSocNetPerms([
299 foreach ($mentionedDepartmentIdList as $departmentId)
301 $departmentId = (int)$departmentId;
305 isset($postPermsData[
'DR'])
306 && isset($postPermsData[
'DR'][$departmentId])
313 $departmentIdToShareList[] = $departmentId;
316 $departmentIdToShareList = array_unique($departmentIdToShareList);
317 if (empty($departmentIdToShareList))
322 $res = SectionTable::getList([
324 '@ID' => $departmentIdToShareList,
327 'select' => [
'ID' ],
329 while ($sectionFields = $res->fetch())
331 $result[] =
'DR' . $sectionFields[
'ID'];
337 private static function getSocNetPerms(array $params = [])
343 $postId = (int)($params[
'postId'] ?? 0);
347 || !Loader::includeModule(
'blog')
353 if (isset($cache[$postId]))
355 $result = $cache[$postId];
359 $result = \CBlogPost::getSocnetPerms($postId);
360 $cache[$postId] = $result;