Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mention.php
1<?php
2
10
18
20{
21 public static function processCommentShare($params = [])
22 {
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);
28
29 $authorId = (int)($params['authorId'] ?? 0);
30 if ($authorId > 0)
31 {
32 $excludedUserIdList[] = $authorId;
33 }
34 $excludedUserIdList = array_map(function ($item) { return (int)$item; }, $excludedUserIdList);
35 $excludedUserIdList = array_unique($excludedUserIdList);
36
37 if (
38 $commentText === ''
39 || $postId <= 0
40 )
41 {
42 return false;
43 }
44
45 if ($blogId <= 0)
46 {
47 $postFields = \CBlogPost::getById($postId);
48 $blogId = (int)$postFields['BLOG_ID'];
49 }
50
51 if (
52 $blogId <= 0
53 || !Loader::includeModule('blog')
54 )
55 {
56 return false;
57 }
58
59 $newRightsList = self::parseUserList([
60 'commentText' => $commentText,
61 'postId' => $postId,
62 'excludedUserIdList' => $excludedUserIdList,
63 ]);
64
65 $newRightsList = array_merge($newRightsList, self::parseProjectList([
66 'commentText' => $commentText,
67 'postId' => $postId,
68 ]));
69
70 $newRightsList = array_merge($newRightsList, self::parseDepartmentList([
71 'commentText' => $commentText,
72 'postId' => $postId,
73 ]));
74
75 if (empty($newRightsList))
76 {
77 return false;
78 }
79
80 $fullRightsList = $newRightsList;
81
82 $blogPermsList = \CBlogPost::getSocnetPerms($postId);
83 foreach ($blogPermsList as $entitiesList)
84 {
85 foreach ($entitiesList as $rightsList)
86 {
87 $fullRightsList = array_merge($fullRightsList, $rightsList);
88 }
89 }
90
91 $fullRightsList = array_unique($fullRightsList);
92
93 return \Bitrix\Socialnetwork\ComponentHelper::processBlogPostShare(
94 [
95 'POST_ID' => $postId,
96 'BLOG_ID' => $blogId,
97 'SITE_ID' => $siteId,
98 'SONET_RIGHTS' => $fullRightsList,
99 'NEW_RIGHTS' => $newRightsList,
100 'USER_ID' => $authorId,
101 ],
102 [
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(),
106 'SHOW_LOGIN' => 'Y',
107 'LIVE' => 'N',
108 'MENTION' => 'Y',
109 'CLEAR_COMMENTS_CACHE' => (isset($params['clearCache']) && $params['clearCache'] === false ? 'N' : 'Y')
110 ]
111 );
112 }
113
114 private static function parseUserList(array $params = []): array
115 {
116 $result = [];
117
118 $commentText = (string)($params['commentText'] ?? '');
119 $excludedUserIdList = (isset($params['excludedUserIdList']) && is_array($params['excludedUserIdList']) ? $params['excludedUserIdList'] : []);
120 $postId = (int)($params['postId'] ?? 0);
121
122 if (
123 $postId <= 0
124 || !Loader::includeModule('blog')
125 )
126 {
127 return $result;
128 }
129
130 $mentionedUserIdList = \Bitrix\Socialnetwork\Helper\Mention::getUserIds($commentText);
131 if (empty($mentionedUserIdList))
132 {
133 return $result;
134 }
135
136 $userIdToShareList = [];
137
138 foreach ($mentionedUserIdList as $userId)
139 {
140 $userId = (int)$userId;
141 if (
142 $userId <= 0
143 || in_array($userId, $excludedUserIdList, true)
144 )
145 {
146 continue;
147 }
148
149 $postPerm = \CBlogPost::getSocNetPostPerms([
150 'POST_ID' => $postId,
151 'NEED_FULL' => true,
152 'USER_ID' => $userId,
153 'IGNORE_ADMIN' => true,
154 ]);
155
156 if ($postPerm >= Permissions::PREMODERATE)
157 {
158 continue;
159 }
160
161 $userIdToShareList[] = $userId;
162 }
163
164 $userIdToShareList = array_unique($userIdToShareList);
165 if (empty($userIdToShareList))
166 {
167 return $result;
168 }
169
170 foreach ($userIdToShareList as $userId)
171 {
172 $result[] = 'U' . $userId;
173 }
174
175 return $result;
176 }
177
178 private static function parseProjectList(array $params = []): array
179 {
180 global $USER;
181
182 $result = [];
183
184 $commentText = (string)($params['commentText'] ?? '');
185
186 $postId = (int)($params['postId'] ?? 0);
187
188 if (
189 $postId <= 0
190 || !Loader::includeModule('blog')
191 )
192 {
193 return $result;
194 }
195
196 $mentionedProjectIdList = \Bitrix\Socialnetwork\Helper\Mention::getProjectIds($commentText);
197 if (empty($mentionedProjectIdList))
198 {
199 return $result;
200 }
201
202 $projectIdToShareList = [];
203
204 $currentUserId = $USER->getId();
205 $currentAdmin = \CSocNetUser::isCurrentUserModuleAdmin(SITE_ID, false);
206 $postPermsData = self::getSocNetPerms([
207 'postId' => $postId,
208 ]);
209
210 foreach ($mentionedProjectIdList as $projectId)
211 {
212 $projectId = (int)$projectId;
213 if (
214 $projectId <= 0
215 || (
216 isset($postPermsData['SG'])
217 && isset($postPermsData['SG'][$projectId])
218 )
219 )
220 {
221 continue;
222 }
223
224 $canPublish = (
225 $currentAdmin
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')
229 );
230
231 if (!$canPublish)
232 {
233 continue;
234 }
235
236 $projectIdToShareList[] = $projectId;
237 }
238
239 $projectIdToShareList = array_unique($projectIdToShareList);
240 if (empty($projectIdToShareList))
241 {
242 return $result;
243 }
244
245 $res = WorkgroupTable::getList([
246 'filter' => [
247 '@ID' => $projectIdToShareList,
248 ],
249 'select' => [ 'ID' ],
250 ]);
251 while ($workgroupFields = $res->fetch())
252 {
253 $result[] = 'SG' . $workgroupFields['ID'];
254 }
255
256 return $result;
257 }
258
259 private static function parseDepartmentList(array $params = []): array
260 {
261 global $USER;
262
263 $result = [];
264
265 $commentText = (string)($params['commentText'] ?? '');
266
267 $postId = (int)($params['postId'] ?? 0);
268
269 if (
270 $postId <= 0
271 || !ModuleManager::isModuleInstalled('intranet')
272 || !Loader::includeModule('blog')
273 || !Loader::includeModule('iblock')
274 )
275 {
276 return $result;
277 }
278
279 if (
280 Loader::includeModule('extranet')
281 && !\CExtranet::isIntranetUser()
282 )
283 {
284 return $result;
285 }
286
287 $mentionedDepartmentIdList = \Bitrix\Socialnetwork\Helper\Mention::getDepartmentIds($commentText);
288 if (empty($mentionedDepartmentIdList))
289 {
290 return $result;
291 }
292
293 $departmentIdToShareList = [];
294
295 $postPermsData = self::getSocNetPerms([
296 'postId' => $postId,
297 ]);
298
299 foreach ($mentionedDepartmentIdList as $departmentId)
300 {
301 $departmentId = (int)$departmentId;
302 if (
303 $departmentId <= 0
304 || (
305 isset($postPermsData['DR'])
306 && isset($postPermsData['DR'][$departmentId])
307 )
308 )
309 {
310 continue;
311 }
312
313 $departmentIdToShareList[] = $departmentId;
314 }
315
316 $departmentIdToShareList = array_unique($departmentIdToShareList);
317 if (empty($departmentIdToShareList))
318 {
319 return $result;
320 }
321
322 $res = SectionTable::getList([
323 'filter' => [
324 '@ID' => $departmentIdToShareList,
325 '=ACTIVE' => 'Y',
326 ],
327 'select' => [ 'ID' ],
328 ]);
329 while ($sectionFields = $res->fetch())
330 {
331 $result[] = 'DR' . $sectionFields['ID'];
332 }
333
334 return $result;
335 }
336
337 private static function getSocNetPerms(array $params = [])
338 {
339 static $cache = [];
340
341 $result = [];
342
343 $postId = (int)($params['postId'] ?? 0);
344
345 if (
346 $postId <= 0
347 || !Loader::includeModule('blog')
348 )
349 {
350 return $result;
351 }
352
353 if (isset($cache[$postId]))
354 {
355 $result = $cache[$postId];
356 }
357 else
358 {
359 $result = \CBlogPost::getSocnetPerms($postId);
360 $cache[$postId] = $result;
361 }
362
363 return $result;
364 }
365}
static get(string $key='', $siteId=SITE_ID)
Definition path.php:17