Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
livefeed.php
1<?php
2
4
14
15class Livefeed extends Base
16{
17 public function configureActions(): array
18 {
19 $configureActions = parent::configureActions();
20 $configureActions['getNextPage'] = [
21 '-prefilters' => [
22 ActionFilter\Authentication::class,
23 ]
24 ];
25 $configureActions['refresh'] = [
26 '-prefilters' => [
27 ActionFilter\Authentication::class,
28 ]
29 ];
30 $configureActions['mobileLogError'] = [
31 '-prefilters' => [
32 ActionFilter\Authentication::class,
33 ]
34 ];
35
36 return $configureActions;
37 }
38
39 public function deleteEntryAction($logId = 0): ?array
40 {
41 $logId = (int)$logId;
42 if ($logId <= 0)
43 {
44 $this->addError(new Error('No Log Id', 'SONET_CONTROLLER_LIVEFEED_NO_LOG_ID'));
45 return null;
46 }
47
48 if (!Loader::includeModule('socialnetwork'))
49 {
50 $this->addError(new Error('Cannot include Socialnetwork module', 'SONET_CONTROLLER_LIVEFEED_NO_SOCIALNETWORK_MODULE'));
51 return null;
52 }
53
54 if (!\CSocNetUser::isCurrentUserModuleAdmin(SITE_ID, false))
55 {
56 $this->addError(new Error('No permissions', 'SONET_CONTROLLER_LIVEFEED_NO_PERMISSIONS'));
57 return null;
58 }
59
60 return [
61 'success' => \CSocNetLog::delete($logId)
62 ];
63 }
64
65 public function getRawEntryDataAction(array $params = []): ?array
66 {
67 $entityType = (isset($params['entityType']) && $params['entityType'] <> '' ? preg_replace("/[^a-z0-9_]/i", '', $params['entityType']) : false);
68 $entityId = (isset($params['entityId']) && (int)$params['entityId'] > 0 ? (int)$params['entityId'] : false);
69 $logId = (isset($params['logId']) && (int)$params['logId'] > 0 ? (int)$params['logId'] : false);
70 $additionalParams = (isset($params['additionalParams']) && is_array($params['additionalParams']) ? $params['additionalParams'] : []);
71
72 if (!Loader::includeModule('socialnetwork'))
73 {
74 $this->addError(new Error('Cannot include Socialnetwork module', 'SONET_CONTROLLER_LIVEFEED_NO_SOCIALNETWORK_MODULE'));
75 return null;
76 }
77
78 $provider = \Bitrix\Socialnetwork\Livefeed\Provider::init([
79 'ENTITY_TYPE' => $entityType,
80 'ENTITY_ID' => $entityId,
81 'LOG_ID' => $logId,
82 'CLONE_DISK_OBJECTS' => true
83 ]);
84
85 if (!$provider)
86 {
87 $this->addError(new Error('Cannot find Livefeed entity', 'SONET_CONTROLLER_LIVEFEED_NO_ENTITY'));
88 return null;
89 }
90
91 $returnFields = [ 'TITLE', 'DESCRIPTION', 'DISK_OBJECTS', 'GROUPS_AVAILABLE', 'LIVEFEED_URL', 'SUFFIX', 'LOG_ID' ];
92 if (
93 isset($additionalParams['returnFields'])
94 && is_array($additionalParams['returnFields'])
95 )
96 {
97 $returnFields = array_intersect($returnFields, $additionalParams['returnFields']);
98 }
99
100 $result = [
101 'TITLE' => $provider->getSourceTitle(),
102 'DESCRIPTION' => $provider->getSourceDescription(),
103 'DISK_OBJECTS' => $provider->getSourceDiskObjects()
104 ];
105
106 if (
107 isset($additionalParams['getSonetGroupAvailable'])
108 && $additionalParams['getSonetGroupAvailable'] === 'Y'
109 )
110 {
111 $feature = $operation = false;
112 if (isset($additionalParams['checkPermissions']['operation'], $additionalParams['checkPermissions']['feature']))
113 {
114 $feature = $additionalParams['checkPermissions']['feature'];
115 $operation = $additionalParams['checkPermissions']['operation'];
116 }
117
118 $result['GROUPS_AVAILABLE'] = $provider->getSonetGroupsAvailable($feature, $operation);
119 }
120
121 if (
122 isset($additionalParams['getLivefeedUrl'])
123 && $additionalParams['getLivefeedUrl'] === 'Y'
124 )
125 {
126 $result['LIVEFEED_URL'] = $provider->getLiveFeedUrl();
127 if (
128 isset($additionalParams['absoluteUrl'])
129 && $additionalParams['absoluteUrl'] === 'Y'
130 )
131 {
132 $serverName = Option::get('main', 'server_name', $_SERVER['SERVER_NAME']);
133 $res = \CSite::getById(SITE_ID);
134 if (
135 ($siteFields = $res->fetch())
136 && $siteFields['SERVER_NAME'] <> ''
137 )
138 {
139 $serverName = $siteFields['SERVER_NAME'];
140 }
141
142 $protocol = (\Bitrix\Main\Context::getCurrent()->getRequest()->isHttps() ? 'https' : 'http');
143 $result['LIVEFEED_URL'] = $protocol . '://' . $serverName . $result['LIVEFEED_URL'];
144 }
145 }
146
147 $result['SUFFIX'] = $provider->getSuffix();
148
149 if (($logId = $provider->getLogId()))
150 {
151 $result['LOG_ID'] = $logId;
152 }
153
154 return array_filter($result, static function ($key) use ($returnFields) {
155 return in_array($key, $returnFields, true);
156 }, ARRAY_FILTER_USE_KEY);
157 }
158
159 public function createEntityCommentAction(array $params = []): void
160 {
161 $postEntityType = (isset($params['postEntityType']) && $params['postEntityType'] <> '' ? preg_replace('/[^a-z0-9_]/i', '', $params['postEntityType']) : false);
162 $sourceEntityType = (isset($params['sourceEntityType']) && $params['sourceEntityType'] <> '' ? preg_replace('/[^a-z0-9_]/i', '', $params['sourceEntityType']) : false);
163 $sourceEntityId = (int)($params['sourceEntityId'] ?? 0);
164 $sourceEntityData = (array)($params['sourceEntityData'] ?? []);
165 $entityType = (isset($params['entityType']) && $params['entityType'] <> '' ? preg_replace('/[^a-z0-9_]/i', '', $params['entityType']) : false);
166 $entityId = (int)($params['entityId'] ?? 0);
167 $logId = (int)($params['logId'] ?? 0);
168
169 if (
170 !$sourceEntityType
171 || $sourceEntityId <= 0
172 || !$entityType
173 || $entityId <= 0
174 )
175 {
176 return;
177 }
178
179 if (in_array($sourceEntityType, [CommentAux\CreateEntity::SOURCE_TYPE_BLOG_POST, CommentAux\CreateEntity::SOURCE_TYPE_BLOG_COMMENT], true))
180 {
182 'ENTITY_TYPE' => $entityType,
183 'ENTITY_ID' => $entityId,
184 'SOURCE_ENTITY_TYPE' => $sourceEntityType,
185 'SOURCE_ENTITY_ID' => $sourceEntityId,
186 'SOURCE_ENTITY_DATA' => $sourceEntityData,
187 'LIVE' => 'Y',
188 ]);
189 }
190 else
191 {
193 'LOG_ID' => $logId,
194 'ENTITY_TYPE' => $entityType,
195 'ENTITY_ID' => $entityId,
196 'POST_ENTITY_TYPE' => $postEntityType,
197 'SOURCE_ENTITY_TYPE' => $sourceEntityType,
198 'SOURCE_ENTITY_ID' => $sourceEntityId,
199 'SOURCE_ENTITY_DATA' => $sourceEntityData,
200 'LIVE' => 'Y'
201 ]);
202 }
203 }
204
209 public function createTaskCommentAction(array $params = []): void
210 {
211 $postEntityType = (isset($params['postEntityType']) && $params['postEntityType'] <> '' ? preg_replace('/[^a-z0-9_]/i', '', $params['postEntityType']) : false);
212 $sourceEntityType = (isset($params['entityType']) && $params['entityType'] <> '' ? preg_replace("/[^a-z0-9_]/i", '', $params['entityType']) : false);
213 $sourceEntityId = (isset($params['entityId']) && (int)$params['entityId'] > 0 ? (int)$params['entityId'] : false);
214 $taskId = (isset($params['taskId']) && (int)$params['taskId'] > 0 ? (int)$params['taskId'] : false);
215 $logId = (isset($params['logId']) && (int)$params['logId'] > 0 ? (int)$params['logId'] : false);
216
217 if (
218 !$sourceEntityType
219 || !$sourceEntityId
220 || !$taskId
221 )
222 {
223 return;
224 }
225
227 'postEntityType' => $postEntityType,
228 'sourceEntityType' => $sourceEntityType,
229 'sourceEntityId' => $sourceEntityId,
230 'entityType' => CommentAux\CreateEntity::ENTITY_TYPE_TASK,
231 'entityId' => $taskId,
232 'logId' => $logId,
233 ]);
234 }
235
236 public function changeFavoritesAction($logId, $value): ?array
237 {
238 global $APPLICATION;
239
240 $result = [
241 'success' => false,
242 'newValue' => false
243 ];
244
245 $logId = (int)$logId;
246 if ($logId <= 0)
247 {
248 $this->addError(new Error('No Log Id', 'SONET_CONTROLLER_LIVEFEED_NO_LOG_ID'));
249 return null;
250 }
251
252 if (!(
253 Loader::includeModule('socialnetwork')
254 && ($logFields = \CSocNetLog::getById($logId))
255 ))
256 {
257 $this->addError(new Error('Cannot get log entry', 'SONET_CONTROLLER_LIVEFEED_EMPTY_LOG_ENTRY'));
258 return null;
259 }
260
261 $currentUserId = $this->getCurrentUser()->getId();
262
263 if ($res = \CSocNetLogFavorites::change($currentUserId, $logId))
264 {
265 if ($res === 'Y')
266 {
268 'logId' => $logId,
269 'userId' => $currentUserId,
270 'typeList' => [
271 'FOLLOW',
272 'COUNTER_COMMENT_PUSH',
273 ],
274 'followDate' => $logFields['LOG_UPDATE'],
275 ]);
276 }
277 $result['success'] = true;
278 $result['newValue'] = $res;
279 }
280 else
281 {
282 $this->addError(new Error((($e = $APPLICATION->getException()) ? $e->getString() : 'Cannot change log entry favorite value'), 'SONET_CONTROLLER_LIVEFEED_FAVORITES_CHANGE_ERROR'));
283 return null;
284 }
285
286 return $result;
287 }
288
289 public function changeFollowAction($logId, $value): ?array
290 {
291 $result = [
292 'success' => false
293 ];
294
295 $logId = (int)$logId;
296 if ($logId <= 0)
297 {
298 return $result;
299 }
300
301 $logId = (int)$logId;
302 if ($logId <= 0)
303 {
304 $this->addError(new Error('No Log Id', 'SONET_CONTROLLER_LIVEFEED_NO_LOG_ID'));
305 return null;
306 }
307
308 if (!Loader::includeModule('socialnetwork'))
309 {
310 $this->addError(new Error('Cannot include Socialnetwork module', 'SONET_CONTROLLER_LIVEFEED_NO_SOCIALNETWORK_MODULE'));
311 return null;
312 }
313
314 $currentUserId = $this->getCurrentUser()->getId();
315 $result['success'] = (
316 $value === 'Y'
318 'logId' => $logId,
319 'userId' => $currentUserId,
320 'typeList' => [ 'FOLLOW', 'COUNTER_COMMENT_PUSH' ]
321 ])
322 : \CSocNetLogFollow::set($currentUserId, 'L' . $logId, 'N')
323 );
324
325 return $result;
326 }
327
328 public function changeFollowDefaultAction($value): ?array
329 {
330 if (!Loader::includeModule('socialnetwork'))
331 {
332 $this->addError(new Error('Cannot include Socialnetwork module', 'SONET_CONTROLLER_LIVEFEED_NO_SOCIALNETWORK_MODULE'));
333 return null;
334 }
335
336 return [
337 'success' => \CSocNetLogFollow::set($this->getCurrentUser()->getId(), '**', ($value === 'Y' ? 'Y' : 'N'))
338 ];
339 }
340
341 public function changeExpertModeAction($expertModeValue): ?array
342 {
343 $result = [
344 'success' => false
345 ];
346
347 if (!Loader::includeModule('socialnetwork'))
348 {
349 $this->addError(new Error('Cannot include Socialnetwork module', 'SONET_CONTROLLER_LIVEFEED_NO_SOCIALNETWORK_MODULE'));
350 return null;
351 }
352
353 $viewValue = ($expertModeValue === 'Y' ? 'N' : 'Y');
354 \Bitrix\Socialnetwork\LogViewTable::set($this->getCurrentUser()->getId(), 'tasks', $viewValue);
355 \Bitrix\Socialnetwork\LogViewTable::set($this->getCurrentUser()->getId(), 'crm_activity_add', $viewValue);
356 \Bitrix\Socialnetwork\LogViewTable::set($this->getCurrentUser()->getId(), 'crm_activity_add_comment', $viewValue);
357
358 $result['success'] = true;
359
360 return $result;
361 }
362
363 public function readNoTasksNotificationAction(): array
364 {
365 $result = [
366 'success' => false
367 ];
368
369 if (\CUserOptions::setOption('socialnetwork', '~log_notasks_notification_read', 'Y'))
370 {
371 $result['success'] = true;
372 }
373
374 return $result;
375 }
376
377 public function mobileLogErrorAction($message, $url, $lineNumber): array
378 {
379 if (!\Bitrix\Main\ModuleManager::isModuleInstalled('bitrix24'))
380 {
381 AddMessage2Log("Mobile Livefeed javascript error:\nMessage: ".$message."\nURL: ".$url."\nLine number: ".$lineNumber."\nUser ID: ".$this->getCurrentUser()->getId());
382 }
383
384 return [
385 'success' => true
386 ];
387 }
388
389 public function mobileGetDetailAction($logId): ?Component
390 {
391 $logId = (int)$logId;
392 if ($logId <= 0)
393 {
394 $this->addError(new Error('No Log Id', 'SONET_CONTROLLER_LIVEFEED_NO_LOG_ID'));
395 return null;
396 }
397
398 return new Component('bitrix:mobile.socialnetwork.log.ex', '', [
399 'LOG_ID' => $logId,
400 'SITE_TEMPLATE_ID' => 'mobile_app',
401 'TARGET' => 'postContent',
402 'PATH_TO_USER' => SITE_DIR.'mobile/users/?user_id=#user_id#'
403 ]);
404 }
405
406 public static function isAdmin(): bool
407 {
408 global $USER;
409
410 return (
411 $USER->isAdmin()
412 || (
413 Loader::includeModule('bitrix24')
414 && \CBitrix24::isPortalAdmin($USER->getId())
415 )
416 );
417 }
418
419 private function getComponentReturnWhiteList(): array
420 {
421 return [ 'LAST_TS', 'LAST_ID', 'EMPTY', 'FILTER_USED', 'FORCE_PAGE_REFRESH' ];
422 }
423
424 public function getNextPageAction(array $params = []): Component
425 {
426 $componentParameters = $this->getUnsignedParameters();
427 if (!is_array($componentParameters))
428 {
429 $componentParameters = [];
430 }
431 $context = $params['context'] ?? '';
432 $requestParameters = [
433 'TARGET' => 'page',
434 'PAGE_NUMBER' => (isset($params['PAGE_NUMBER']) && (int)$params['PAGE_NUMBER'] >= 1 ? (int)$params['PAGE_NUMBER'] : 1),
435 'LAST_LOG_TIMESTAMP' => (isset($params['LAST_LOG_TIMESTAMP']) && (int)$params['LAST_LOG_TIMESTAMP'] > 0 ? (int)$params['LAST_LOG_TIMESTAMP'] : 0),
436 'PREV_PAGE_LOG_ID' => ($params['PREV_PAGE_LOG_ID'] ?? ''),
437 'CONTEXT' => $context,
438 'useBXMainFilter' => ($params['useBXMainFilter'] ?? 'N'),
439 'siteTemplateId' => ($params['siteTemplateId'] ?? 'bitrix24'),
440 'preset_filter_top_id' => ($params['preset_filter_top_id'] ?? ''),
441 'preset_filter_id' => ($params['preset_filter_id'] ?? ''),
442 ];
443
444 if ($context === Context::SPACES)
445 {
446 $requestParameters['SPACE_USER_ID'] = (int)($params['userId'] ?? $this->userId);
447 $requestParameters['GROUP_ID'] = (int)($componentParameters['GROUP_ID'] ?? $params['spaceId']);
448 }
449
450
451 return new Component('bitrix:socialnetwork.log.ex', '', array_merge($componentParameters, $requestParameters), [], $this->getComponentReturnWhiteList());
452 }
453
454 public function refreshAction(array $params = []): Component
455 {
456 $componentParameters = $this->getUnsignedParameters();
457 if (!is_array($componentParameters))
458 {
459 $componentParameters = [];
460 }
461
462 $context = $params['context'] ?? '';
463 $requestParameters = [
464 'TARGET' => 'page',
465 'PAGE_NUMBER' => 1,
466 'RELOAD' => 'Y',
467 'CONTEXT' => $context,
468 'composition' => $params['composition'] ?? [],
469 'useBXMainFilter' => ($params['useBXMainFilter'] ?? 'N'),
470 'siteTemplateId' => ($params['siteTemplateId'] ?? 'bitrix24'),
471 'assetsCheckSum' => ($params['assetsCheckSum'] ?? '')
472 ];
473
474 if ($context === Context::SPACES)
475 {
476 $requestParameters['SPACE_USER_ID'] = (int)($params['userId'] ?? $this->userId);
477 $requestParameters['GROUP_ID'] = (int)($componentParameters['GROUP_ID'] ?? $params['spaceId']);
478 }
479
480 return new Component('bitrix:socialnetwork.log.ex', '', array_merge($componentParameters, $requestParameters), [], $this->getComponentReturnWhiteList());
481 }
482
483 public function mobileCreateNotificationLinkAction($tag): string
484 {
485 $params = explode("|", $tag);
486 if (empty($params[1]) || empty($params[2]) || !Loader::includeModule('socialnetwork'))
487 {
488 return '';
489 }
490
491 $liveFeedEntity = \Bitrix\SocialNetwork\Livefeed\Provider::init([
492 'ENTITY_TYPE' => \Bitrix\Socialnetwork\Livefeed\Provider::DATA_ENTITY_TYPE_FORUM_POST,
493 'ENTITY_ID' => $params[2]
494 ]);
495
496 $suffix = $liveFeedEntity->getSuffix();
497 if ($suffix === 'TASK')
498 {
499 $res = \Bitrix\Socialnetwork\LogTable::getList(array(
500 'filter' => array(
501 'ID' => $liveFeedEntity->getLogId()
502 ),
503 'select' => [ 'ENTITY_ID', 'EVENT_ID', 'SOURCE_ID' ]
504 ));
505 if ($logEntryFields = $res->fetch())
506 {
507 if ($logEntryFields['EVENT_ID'] === 'crm_activity_add')
508 {
509 if (
510 Loader::includeModule('crm')
511 && ($activityFields = \CCrmActivity::getById($logEntryFields['ENTITY_ID'], false))
512 && $activityFields['TYPE_ID'] == \CCrmActivityType::Task
513 )
514 {
515 $taskId = (int)$activityFields['ASSOCIATED_ENTITY_ID'];
516 }
517 }
518 else
519 {
520 $taskId = (int)$logEntryFields['SOURCE_ID'];
521 }
522
523 if (isset($taskId) && $taskId > 0 && Loader::includeModule('mobile'))
524 {
525 return \CMobileHelper::getParamsToCreateTaskLink($taskId);
526 }
527 }
528 }
529
530 return SITE_DIR . "mobile/log/?ACTION=CONVERT&ENTITY_TYPE_ID=FORUM_POST&ENTITY_ID=" . $params[2];
531 }
532}
mobileLogErrorAction($message, $url, $lineNumber)
Definition livefeed.php:377
static processLogEntryCreateEntity(array $params=[])