1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
im_disk.php
См. документацию.
1<?php
2
3use Bitrix\Disk;
4use Bitrix\Disk\File;
5use Bitrix\Disk\FileLink;
6use Bitrix\Disk\SystemUser;
7use \Bitrix\Im as IM;
9use \Bitrix\Main\Localization\Loc;
11
12Loc::loadMessages(__FILE__);
13
15{
16 const MODULE_ID = 'im';
17
18 const PATH_TYPE_SHOW = 'show';
19 const PATH_TYPE_PREVIEW = 'preview';
20 const PATH_TYPE_DOWNLOAD = 'download';
21
22 private static $chatList = [];
23 private static $folderList = [];
24
30 public static function GetStorage(?int $chatId = null)
31 {
32 if (!self::Enabled())
33 {
34 return false;
35 }
36
37 $storageModel = false;
38 if ($storageId = self::GetStorageId($chatId))
39 {
40 $storageModel = \Bitrix\Disk\Storage::loadById($storageId);
41 if (!$storageModel)
42 {
43 $storageModel = false;
44 }
45 }
46
47 if (!$storageModel)
48 {
49 $data = [
50 'NAME' => Loc::getMessage('IM_DISK_STORAGE_TITLE'),
51 'USE_INTERNAL_RIGHTS' => 1,
52 'MODULE_ID' => self::MODULE_ID,
53 'ENTITY_TYPE' => IM\Disk\ProxyType\Im::className(),
54 'ENTITY_ID' => self::MODULE_ID,
55 ];
56
57 $driver = \Bitrix\Disk\Driver::getInstance();
58
59 // allow access for all on the top folder
60 $storageModel = $driver->addStorageIfNotExist($data);
61 if ($storageModel)
62 {
63 self::SetStorageId($storageModel->getId());
64 }
65 else
66 {
67 $storageModel = false;
68 }
69 }
70
71 return $storageModel;
72 }
73
81 public static function UploadFileRegister($chatId, $files, $text = '', $linesSilentMode = false)
82 {
83 if ((int)$chatId <= 0 || empty($files))
84 {
85 return false;
86 }
87
88 $chatRelation = \CIMChat::GetRelationById($chatId, false, true, false);
89 if (!$chatRelation[self::GetUserId()])
90 {
91 return false;
92 }
93
94 $folderModel = self::GetFolderModel($chatId);
95 if (!$folderModel)
96 {
97 return false;
98 }
99
100 $result = [];
101 $result['FILE_ID'] = [];
102 $messageFileId = [];
103 $filesModels = [];
104 foreach ($files as $fileId => $fileData)
105 {
106 if (!$fileData['mimeType'])
107 {
108 $fileData['mimeType'] = "binary";
109 }
110 if (!$fileData['name'])
111 {
112 continue;
113 }
114 $newFile = $folderModel->addBlankFile(Array(
115 'NAME' => $fileData['name'],
116 'SIZE' => $fileData['size'],
117 'CREATED_BY' => self::GetUserId(),
118 'MIME_TYPE' => $fileData['mimeType'],
119 ), Array(), true);
120 if ($newFile)
121 {
122 $result['FILE_ID'][$fileId]['TMP_ID'] = $fileId;
123 $result['FILE_ID'][$fileId]['FILE_ID'] = $newFile->getId();
124 $result['FILE_ID'][$fileId]['FILE_NAME'] = $newFile->getName();
125 $filesModels[] = $newFile;
126
127 $messageFileId[] = $newFile->getId();
128 }
129 else
130 {
131 $result['FILE_ID'][$fileId]['TMP_ID'] = $fileId;
132 $result['FILE_ID'][$fileId]['FILE_ID'] = 0;
133 }
134 }
135 if (empty($messageFileId))
136 {
137 return false;
138 }
139
140 $result['MESSAGE_ID'] = 0;
141 $arChat = \CIMChat::GetChatData(Array('ID' => $chatId));
142 $ar = Array(
143 "TO_CHAT_ID" => $chatId,
144 "FROM_USER_ID" => self::GetUserId(),
145 "MESSAGE_TYPE" => $arChat['chat'][$chatId]['message_type'],
146 "SILENT_CONNECTOR" => $linesSilentMode?'Y':'N',
147 "PARAMS" => Array(
148 'FILE_ID' => $messageFileId
149 ),
150 "FILE_MODELS" => $filesModels
151 );
152
153 $text = trim($text);
154 if ($text)
155 {
156 $ar['MESSAGE'] = $text;
157 }
159 if ($messageId)
160 {
161 }
162 else
163 {
164 if ($e = $GLOBALS["APPLICATION"]->GetException())
165 {
166 $result['MESSAGE_ERROR'] = $e->GetString();
167 }
168 }
169
170 return $result;
171 }
172
181 public static function UploadFile($hash, &$file, &$package, &$upload, &$error)
182 {
183 $post = \Bitrix\Main\Context::getCurrent()->getRequest()->getPostList()->toArray();
184 $post['PARAMS'] = IM\Text::convertSymbolsAfterJsonDecode(\CUtil::JsObjectToPhp($post['REG_PARAMS'], true));
185 $post['MESSAGE_HIDDEN'] = $post['REG_MESSAGE_HIDDEN'] == 'Y' ? 'Y' : 'N';
186 $post['PARAMS']['TEXT'] = $post['PARAMS']['TEXT'] ? trim($post['PARAMS']['TEXT']) : '';
187
188 $chatId = (int)$post['CHAT_ID'];
189 if ($chatId <= 0)
190 {
191 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E100)';
192 return false;
193 }
194
195 $chat =\Bitrix\Im\V2\Chat::getInstance($chatId);
196 if (!$chat->isExist())
197 {
198 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E101)';
199 return false;
200 }
201
202 if (!$chat->checkAccess()->isSuccess())
203 {
204 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E102)';
205 return false;
206 }
207
208 if (!$chat->canDo(IM\V2\Permission\Action::Send))
209 {
210 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E103)';
211 return false;
212 }
213
214 $folderModel = self::GetFolderModel($chatId);
215 if (!$folderModel)
216 {
217 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E104)';
218 return false;
219 }
220
221 if (!$file["files"]["default"])
222 {
223 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E106)';
224 return false;
225 }
226
227 $fileModel = $folderModel->uploadFile(
228 $file['files']['default'],
229 [
230 'NAME' => $file['name'],
231 'CREATED_BY' => self::GetUserId()
232 ],
233 [],
234 true
235 );
236
237 if (!$fileModel || !$fileModel->getId())
238 {
239 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E107)';
240 return false;
241 }
242
243 $fileTmpId = $file["id"];
244 $messageTmpId = $file["regTmpMessageId"];
245 $isMessageHidden = $file["regHiddenMessageId"] === 'Y';
246
247 if (!$fileTmpId || !$messageTmpId)
248 {
249 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E108)';
250 return false;
251 }
252 $uploadRealResult = self::UploadFileFromDisk(
253 $chatId,
254 ['upload'.$fileModel->getId()],
255 $post['PARAMS']['TEXT'],
256 [
257 'LINES_SILENT_MODE' => $isMessageHidden,
258 'TEMPLATE_ID' => $messageTmpId,
259 'FILE_TEMPLATE_ID' => $fileTmpId
260 ]
261 );
262
263 if (!$uploadRealResult)
264 {
265 $error = '';
266 if ($e = $GLOBALS["APPLICATION"]->GetException())
267 {
268 $error = $e->GetString();
269 }
270 if ($error == '')
271 {
272 $error = Loc::getMessage('IM_DISK_ERR_UPLOAD').' (E109)';
273 }
274
275 return false;
276 }
277
278 $fileModel = $folderModel->getChild(['ID' => $fileModel->getId()]);
279
280 $file['fileParams'] = self::GetFileParams($chatId, $fileModel);
281 $file['fileParams']['date'] = date('c', $file['fileParams']['date']->getTimestamp());
282
283 foreach(\GetModuleEvents("im", "OnAfterFileUpload", true) as $arEvent)
284 {
285 \ExecuteModuleEventEx($arEvent, [[
286 'CHAT_ID' => $chatId,
287 'FILE_ID' => $fileModel->getId(),
288 'MESSAGE_ID' => $uploadRealResult['MESSAGE_ID'],
289 'MESSAGE_OUT' => $post['PARAMS']['TEXT'],
290 'MESSAGE_HIDDEN' => $isMessageHidden,
291 'FILE' => $file['fileParams'],
292 ]]);
293 }
294
295 return true;
296 }
297
304 public static function UploadFileUnRegister($chatId, $files, $messages)
305 {
306 if ((int)$chatId <= 0 || empty($files))
307 {
308 return false;
309 }
310
311 $chatRelation = \CIMChat::GetRelationById($chatId, false, true, false);
312 if (!$chatRelation[self::GetUserId()])
313 {
314 return false;
315 }
316
317 $folderModel = self::GetFolderModel($chatId);
318 if (!$folderModel)
319 {
320 return false;
321 }
322
323 $result = [];
324 $result['CHAT_ID'] = $chatId;
325 $result['FILE_ID'] = [];
326 $result['MESSAGE_ID'] = [];
327 foreach ($files as $fileTmpId => $fileId)
328 {
329 $fileModel = File::getById($fileId);
330 if (
331 !$fileModel
332 || $fileModel->getParentId() != $folderModel->getId()
333 || $fileModel->getCreatedBy() != self::GetUserId()
334 )
335 {
336 continue;
337 }
338 $fileModel->delete(self::GetUserId());
339 $result['FILE_ID'][$fileTmpId] = $fileId;
340 }
341 foreach ($messages as $fileTmpId => $messageId)
342 {
343 if (!isset($result['FILE_ID'][$fileTmpId]))
344 {
345 continue;
346 }
347
348 $CIMMessage = new \CIMMessage();
349 $arMessage = $CIMMessage->GetMessage($messageId);
350 if ($arMessage['AUTHOR_ID'] != self::GetUserId())
351 {
352 continue;
353 }
355 $result['MESSAGE_ID'][$fileTmpId] = $messageId;
356 }
357 if (empty($result['FILE_ID']) && empty($result['MESSAGE_ID']))
358 {
359 return false;
360 }
361
362 if (\Bitrix\Main\Loader::includeModule('pull'))
363 {
364 $pullMessage = Array(
365 'module_id' => 'im',
366 'command' => 'fileUnRegister',
367 'params' => Array(
368 'chatId' => $result['CHAT_ID'],
369 'files' => $result['FILE_ID'],
370 'messages' => $result['MESSAGE_ID'],
371 ),
372 'extra' => \Bitrix\Im\Common::getPullExtra()
373 );
374 \Bitrix\Pull\Event::add(array_keys($chatRelation), $pullMessage);
375
376 $orm = \Bitrix\Im\Model\ChatTable::getById($result['CHAT_ID']);
377 $chat = $orm->fetch();
378 if (CIMMessenger::needToSendPublicPull($chat['TYPE']))
379 {
380 \CPullWatch::AddToStack('IM_PUBLIC_'.$chat['ID'], $pullMessage);
381 }
382 }
383
384 return $result;
385 }
386
392 public static function DeleteFile($chatId, $fileId)
393 {
394 if ((int)$chatId <= 0 || (int)$fileId <= 0)
395 {
396 return false;
397 }
398
399 $chatRelation = \CIMChat::GetRelationById($chatId, false, true, false);
400 if (!$chatRelation[self::GetUserId()])
401 {
402 return false;
403 }
404
405 $folderModel = self::getFolderModel($chatId, false);
406 if (!$folderModel)
407 {
408 return false;
409 }
410
411 $fileModel = File::getById($fileId);
412 if (!$fileModel || $fileModel->getParentId() != $folderModel->getId())
413 {
414 return false;
415 }
416
418 global $USER;
419 if (
420 $fileModel->getCreatedBy() == self::GetUserId()
421 || $USER->IsAdmin()
422 )
423 {
424 // allow deleting only owned files
425 $fileModel->delete(self::GetUserId());
426 $notifyUsers = array_keys($chatRelation);
427 }
428 else
429 {
430 $driver = \Bitrix\Disk\Driver::getInstance();
431 $rightsManager = $driver->getRightsManager();
432
433 // hide file from user by access disabling
434 $accessCodes = [
435 // keep previous scheme with Uxx access code
436 [
437 'ACCESS_CODE' => 'U'.self::GetUserId(),
438 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_FULL),
439 'NEGATIVE' => 1,
440 ]
441 ];
442 $rightsManager->append($fileModel, $accessCodes);
443
444 $notifyUsers = [self::GetUserId()];
445 }
446
447 $fileService = new IM\V2\Link\File\FileService();
448 if (\Bitrix\Main\Loader::includeModule('pull') && !$fileService->isMigrationFinished())
449 {
450 $orm = \Bitrix\Im\Model\ChatTable::getById($chatId);
451 $chat = $orm->fetch();
452 $pullMessage = Array(
453 'module_id' => 'im',
454 'command' => 'fileDelete',
455 'params' => Array(
456 'chatId' => $chatId,
457 'fileId' => $fileId
458 ),
459 'extra' => \Bitrix\Im\Common::getPullExtra()
460 );
461 if ($chat['TYPE'] === IM\V2\Chat::IM_TYPE_COMMENT)
462 {
463 \CPullWatch::AddToStack('IM_PUBLIC_'.$chat['PARENT_ID'], $pullMessage);
464 }
465 else
466 {
467 \Bitrix\Pull\Event::add($notifyUsers, $pullMessage);
468 }
469
470 if (CIMMessenger::needToSendPublicPull($chat['TYPE']))
471 {
472 \CPullWatch::AddToStack('IM_PUBLIC_'.$chat['ID'], $pullMessage);
473 }
474 }
475
476 return true;
477 }
478
487 public static function UploadFileFromDisk($chatId, $files, $text = '', $options = [], $robot = false)
488 {
489 if ((int)$chatId <= 0 || empty($files))
490 {
491 return false;
492 }
493
494 $chat = IM\V2\Chat::getInstance($chatId);
495 if ($chat instanceof IM\V2\Chat\NullChat)
496 {
497 return false;
498 }
499
500 if (isset($options['USER_ID']))
501 {
502 $userId = (int)$options['USER_ID'];
503 }
504 else
505 {
507 if (!$userId)
508 {
509 return false;
510 }
511 }
512
513 $skipUserCheck = isset($options['SKIP_USER_CHECK']) && $options['SKIP_USER_CHECK'] === true;
514 $linesSilentMode = isset($options['LINES_SILENT_MODE']) && $options['LINES_SILENT_MODE'] === true;
515 $makeSymlink = isset($options['SYMLINK']) && $options['SYMLINK'] === true;
516 $templateId = isset($options['TEMPLATE_ID']) && $options['TEMPLATE_ID'] <> '' ? $options['TEMPLATE_ID'] : '';
517 $fileTemplateId = isset($options['FILE_TEMPLATE_ID']) && $options['FILE_TEMPLATE_ID'] <> '' ? $options['FILE_TEMPLATE_ID'] : '';
518 $attach = $options['ATTACH'] ?? null;
519 $asFile = isset($options['AS_FILE']) && $options['AS_FILE'] === 'Y';
520 $params = isset($options['PARAMS']) && is_array($options['PARAMS']) ? $options['PARAMS'] : null;
521 $waitFullExecution = $options['WAIT_FULL_EXECUTION'] ?? 'Y';
522 if ($chat->getEntityType() === 'LINES' || $chat->getEntityType() === 'LIVECHAT')
523 {
524 $waitFullExecution = 'Y';
525 }
526
527 $chatRelation = $chat->getRelations();
528
529 if ($chat->getEntityType() !== 'LIVECHAT' && $userId > 0 && !$skipUserCheck)
530 {
531 if (!$chatRelation->hasUser($userId, $chatId))
532 {
533 return false;
534 }
535
536 if (
537 $chat->getEntityType() === 'ANNOUNCEMENT'
538 && !$chatRelation->getByUserId($userId, $chatId)->getManager()
539 )
540 {
541 return false;
542 }
543 }
544
545 $result = [];
546 $result['FILES'] = [];
547 $result['DISK_ID'] = [];
548 $result['FILE_MODELS'] = [];
549 foreach ($files as $fileId)
550 {
551 if (mb_substr($fileId, 0, 6) === 'upload')
552 {
553 $newFile = self::uploadFromLocalDisk($chatId, mb_substr($fileId, 6), $skipUserCheck ? 0 : $userId, $asFile);
554 }
555 else
556 {
557 $newFile = self::SaveFromLocalDisk($chatId, mb_substr($fileId, 4), $makeSymlink, $skipUserCheck? 0: $userId);
558 }
559
560 if ($newFile)
561 {
562 $result['FILES'][$fileId] = self::GetFileParams($chatId, $newFile);
563 $result['DISK_ID'][] = $newFile->getId();
564 $result['FILE_MODELS'][$fileId] = $newFile;
565
566 if ($robot)
567 {
568 if ($userId)
569 {
570 // temporary - waiting for fix in Disk
571 $recentItem = \Bitrix\Disk\Internals\RecentlyUsedTable::getList([
572 'select' => ['ID'],
573 'filter' => [
574 '=USER_ID' => $userId,
575 '=OBJECT_ID' => $newFile->getId()
576 ]
577 ])->fetch();
578
579 if ($recentItem)
580 {
581 \Bitrix\Disk\Internals\RecentlyUsedTable::delete($recentItem['ID']);
582 }
583 }
584 }
585 else if (!$skipUserCheck)
586 {
587 if ($chat->getEntityType() == 'LINES')
588 {
589 if ($userId)
590 {
591 \Bitrix\Disk\Driver::getInstance()->getRecentlyUsedManager()->push($userId, $newFile);
592 }
593 }
594 else if ($chat->getEntityType() != 'LIVECHAT')
595 {
596 foreach ($chatRelation as $relation)
597 {
598 if ($relation->getMessageType() != \IM_MESSAGE_PRIVATE)
599 {
600 break;
601 }
602
603 if ($userId == $relation->getUserId())
604 {
605 continue;
606 }
607
608 \Bitrix\Disk\Driver::getInstance()->getRecentlyUsedManager()->push($relation->getUserId(), $newFile);
609 }
610 }
611 }
612 }
613 else
614 {
615 $result['FILES'][$fileId]['id'] = 0;
616 }
617 }
618 if (empty($result['DISK_ID']))
619 {
620 return false;
621 }
622
623 $result['MESSAGE_ID'] = 0;
624
625 $ar = [
626 "TO_CHAT_ID" => $chatId,
627 "FROM_USER_ID" => $userId,
628 "MESSAGE_TYPE" => $chat->getType(),
629 "SILENT_CONNECTOR" => $linesSilentMode?'Y':'N',
630 "SKIP_USER_CHECK" => ($skipUserCheck || !$userId || $chat->getEntityType() == 'LIVECHAT'),
631 "TEMPLATE_ID" => $templateId,
632 "FILE_TEMPLATE_ID" => $fileTemplateId,
633 "FILE_MODELS" => $result['FILE_MODELS'] ?? [],
634 "WAIT_FULL_EXECUTION" => $waitFullExecution,
635 ];
636
637 if ($chat->getEntityType() == 'LIVECHAT')
638 {
639 [$lineId] = explode("|", $chat->getEntityId());
640 $ar["EXTRA_PARAMS"] = [
641 "CONTEXT" => "LIVECHAT",
642 "LINE_ID" => $lineId
643 ];
644 //TODO: fix 0135872
645 //$ar['SKIP_CONNECTOR'] = 'Y';
646 }
647
648 $ar['FILES'] = $result['DISK_ID'];
649
650 if ($params)
651 {
652 $ar['PARAMS'] = $params;
653 }
654
655 if ($attach)
656 {
657 $ar['ATTACH'] = $attach;
658 }
659
660 $text = trim($text);
661 if ($text)
662 {
663 $ar["MESSAGE"] = $text;
664 }
665
667 if (!$messageId)
668 {
669 foreach ($result['FILE_MODELS'] as $file)
670 {
671 $file->delete($userId);
672 }
673 return false;
674 }
675
676 $result['MESSAGE_ID'] = $messageId;
677
678 if (
679 !$robot
680 && !$linesSilentMode
681 && ($chat->getEntityType() == 'LINES' || $chat->getEntityType() == 'LIVECHAT')
682 )
683 {
684 $fileIds = array_map(function($item){
685 return 'disk' . $item;
686 }, $result['DISK_ID']);
687
688 $uploadResult = false;
689
690 if ($chat->getEntityType() == 'LIVECHAT' && \Bitrix\Main\Loader::includeModule('imopenlines'))
691 {
692 [$lineId, $clientUserId] = explode("|", $chat->getEntityId());
693
694 $session = new \Bitrix\Imopenlines\Session();
695 if ($session->load([
696 'USER_CODE' => 'livechat|'.$lineId.'|'.$chat->getId().'|'.$clientUserId,
697 'DEFERRED_JOIN' => 'Y',
698 ]))
699 {
700 if ($session->isNowCreated())
701 {
702 \Bitrix\ImOpenLines\Connector::saveCustomData($session->getData('CHAT_ID'), $_SESSION['LIVECHAT']['CUSTOM_DATA']);
703
704 $session->joinUser();
705
706 $messageParams = [
707 'IMOL_SID' => $session->getData('ID'),
708 "IMOL_FORM" => "welcome",
709 "TYPE" => "lines",
710 "COMPONENT_ID" => "bx-imopenlines-message",
711 ];
712 \CIMMessageParam::Set($messageId, $messageParams);
713 \CIMMessageParam::SendPull($messageId, array_keys($messageParams));
714 }
715 $session->getData('CHAT_ID');
716 //TODO: fix 0135872
717 /*$uploadResult = self::UploadFileFromDisk(
718 $session->getData('CHAT_ID'),
719 $fileIds,
720 $text,
721 ['USER_ID' => $userId],
722 true
723 );*/
724 }
725 }
726
727 if (
728 !empty($uploadResult) &&
729 $uploadResult['MESSAGE_ID'] &&
730 $result['MESSAGE_ID']
731 )
732 {
733 \Bitrix\Im\Model\MessageParamTable::add([
734 "MESSAGE_ID" => $result['MESSAGE_ID'],
735 "PARAM_NAME" => 'CONNECTOR_MID',
736 "PARAM_VALUE" => $uploadResult['MESSAGE_ID']
737 ]);
738 \Bitrix\Im\Model\MessageParamTable::add([
739 "MESSAGE_ID" => $uploadResult['MESSAGE_ID'],
740 "PARAM_NAME" => 'CONNECTOR_MID',
741 "PARAM_VALUE" => $result['MESSAGE_ID']
742 ]);
743
744 \CIMMessageParam::SendPull($result['MESSAGE_ID'], ['CONNECTOR_MID']);
745 \CIMMessageParam::SendPull($uploadResult['MESSAGE_ID'], ['CONNECTOR_MID']);
746
747 $event = new \Bitrix\Main\Event("imopenlines", "OnLivechatUploadFile", ['FILES' => $uploadResult['DISK_ID']]);
748 $event->send();
749 }
750 }
751
752 return $result;
753 }
754
755 protected static function checkDirectlyUseFileAccess(
756 File $fileModel,
757 Disk\Folder $folderModel,
758 int $userId
759 ): IM\V2\Result
760 {
761 $result = new IM\V2\Result();
762
763 if ((int)$fileModel->getParentId() !== (int)$folderModel->getId())
764 {
765 $result->addError(
766 new IM\V2\Entity\File\FileError(
767 IM\V2\Entity\File\FileError::UPLOAD_FILE_INCORRECT_FOLDER,
768 'The parent folder of the original file and the destination folder must match.'
769 )
770 );
771 }
772
773 if ((int)$fileModel->getCreatedBy() !== $userId)
774 {
775 $result->addError(
776 new IM\V2\Entity\File\FileError(
777 IM\V2\Entity\File\FileError::UPLOAD_FILE_INCORRECT_AUTHOR,
778 'You must be the author of the original file to upload it.'
779 )
780 );
781 }
782
783 return $result;
784 }
785
786 protected static function uploadFromLocalDisk(
787 int $chatId,
788 int $fileId,
789 ?int $userId = null,
790 bool $asFile = false
791 ): File|false
792 {
793 $fileModel = self::getFileModel($fileId, $userId);
794 $chat = Bitrix\Im\V2\Chat::getInstance($chatId);
795 if (!isset($fileModel) || $chat instanceof IM\V2\Chat\NullChat)
796 {
797 return false;
798 }
799
800 $folderModel = self::GetFolderModel($chatId);
801 if (!isset($folderModel))
802 {
803 return false;
804 }
805
806 $checkResult = self::checkDirectlyUseFileAccess($fileModel, $folderModel, (int)$userId);
807
808 if (!$checkResult->isSuccess())
809 {
810 (new IM\V2\Logger('chat_incorrect_file_upload'))->logErrors($checkResult->getErrorCollection());
811 }
812
813 $fileModel->increaseGlobalContentVersion();
814
815 if ($asFile)
816 {
817 (new IM\V2\Entity\File\FileItem($fileModel, $chatId))->markAsFile();
818 }
819
820 (new IM\V2\Analytics\ChatAnalytics($chat))->addUploadFile($fileModel);
821
822 return $fileModel;
823 }
824
830 public static function UploadFileFromMain($chatId, $files, ?int $authorId = null)
831 {
832 if ((int)$chatId <= 0 || empty($files))
833 {
834 return false;
835 }
836
837 $chatRelation = \CIMChat::GetRelationById($chatId, false, true, false);
838 if (!$chatRelation)
839 {
840 return false;
841 }
842
843 $folderModel = self::GetFolderModel($chatId);
844 if (!$folderModel)
845 {
846 return false;
847 }
848
849 $messageFileId = [];
850 foreach ($files as $fileId)
851 {
852 $res = \CFile::GetByID($fileId);
853 $file = $res->Fetch();
854 if (!$file)
855 {
856 continue;
857 }
858
859 if (empty($file['ORIGINAL_NAME']))
860 {
861 $fileName = $file['FILE_NAME'];
862 }
863 else
864 {
865 $fileName = $file['ORIGINAL_NAME'];
866 }
867
868 $fileName = \Bitrix\Disk\Ui\Text::correctFilename($fileName);
869 $newFile = $folderModel->addFile(array(
870 'NAME' => $fileName,
871 'FILE_ID' => $fileId,
872 'SIZE' => $file['FILE_SIZE'],
873 'CREATED_BY' => $authorId ?? SystemUser::SYSTEM_USER_ID,
874 ), Array(), true);
875 if ($newFile)
876 {
877 $newFile->increaseGlobalContentVersion();
878 $messageFileId[] = $newFile->getId();
879 }
880 }
881
882 return !empty($messageFileId) ? $messageFileId : false;
883 }
884
889 public static function SaveToLocalDisk($fileId)
890 {
891 if (!self::Enabled())
892 {
893 return false;
894 }
895
896 if ((int)$fileId <= 0)
897 {
898 return false;
899 }
900
901 $fileModel = File::getById($fileId, array('STORAGE'));
902 if (!$fileModel)
903 {
904 return false;
905 }
906 if ($fileModel instanceof FileLink)
907 {
908 $fileModel = $fileModel->getRealObject();
909 if (!$fileModel)
910 {
911 return false;
912 }
913 }
914
915 $storageModel = $fileModel->getStorage();
916 if (!$storageModel)
917 {
918 return false;
919 }
920
921 if (!$fileModel->canRead($storageModel->getCurrentUserSecurityContext()))
922 {
923 return false;
924 }
925
926 $folderModel = self::GetLocalDiskSavedModel();
927 if (!$folderModel)
928 {
929 return false;
930 }
931
932 $newFileModel = $fileModel->copyTo($folderModel, self::GetUserId(), true);
933 if (!$newFileModel)
934 {
935 return false;
936 }
937
938 return [
939 'FILE' => $newFileModel,
940 'FOLDER' => $folderModel,
941 ];
942 }
943
950 public static function IncreaseFileVersionDisk($chatId, $fileId, ?int $userId = null)
951 {
952 if (!self::Enabled())
953 {
954 return false;
955 }
956
957 if ((int)$fileId <= 0 || (int)$chatId <= 0)
958 {
959 return false;
960 }
961
962 $fileModel = File::getById($fileId, array('STORAGE'));
963 if (!$fileModel)
964 {
965 return false;
966 }
967
968 $storageModel = $fileModel->getStorage();
969 if (!$storageModel)
970 {
971 return false;
972 }
973
974 $securityContext = null;
975 if (is_null($userId))
976 {
977 $securityContext = $storageModel->getCurrentUserSecurityContext();
978 }
979 else if ($userId > 0)
980 {
981 $securityContext = $storageModel->getSecurityContext($userId);
982 }
983
984 if ($securityContext && !$fileModel->canRead($securityContext))
985 {
986 return false;
987 }
988
989 $fileModel->increaseGlobalContentVersion();
990
991 return $fileModel;
992 }
993
1001 public static function SaveFromLocalDisk($chatId, $fileId, bool $symlink = false, ?int $userId = null)
1002 {
1003 if (!self::Enabled())
1004 {
1005 return false;
1006 }
1007
1008 $fileModel = self::getFileModel((int)$fileId, $userId);
1009 $folderModel = self::GetFolderModel($chatId);
1010 $chat = IM\V2\Chat::getInstance($chatId);
1011
1012 if (
1013 !$folderModel
1014 || !$fileModel
1015 || $chat instanceof IM\V2\Chat\NullChat
1016 )
1017 {
1018 return false;
1019 }
1020
1021 if (
1022 $chat instanceof IM\V2\Chat\CollabChat
1023 && (int)$fileModel->getParentId() === (int)$folderModel->getId()
1024 )
1025 {
1026 $fileModel->increaseGlobalContentVersion();
1027
1028 return $fileModel;
1029 }
1030
1031 if ($fileModel instanceof FileLink)
1032 {
1033 $fileModel = $fileModel->getRealObject();
1034 if (!$fileModel)
1035 {
1036 return false;
1037 }
1038 }
1039
1040 if ($symlink)
1041 {
1042 $newFileModel = self::createSymlink($fileModel, $chatId, (int)$userId);
1043 }
1044 else
1045 {
1046 $newFileModel = $fileModel->copyTo($folderModel, (int)$userId, true);
1047 }
1048
1049 if (!$newFileModel)
1050 {
1051 return false;
1052 }
1053
1054 $newFileModel->increaseGlobalContentVersion();
1055
1056 return $newFileModel;
1057 }
1058
1059 protected static function createSymlink(
1060 File $fileModel,
1061 int $chatId,
1062 int $userId,
1063 bool $withSharingRights = true
1064 ): ?File
1065 {
1066 if (!self::Enabled())
1067 {
1068 return null;
1069 }
1070
1071 $folderModel = self::GetFolderModel($chatId);
1072
1073 if ($withSharingRights)
1074 {
1075 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
1076 $rightsManager = \Bitrix\Disk\Driver::getInstance()->getRightsManager();
1077
1078 $rightsManager->append(
1079 $fileModel,
1080 [[
1081 // allow reading for access code `CHATxxx`
1082 'ACCESS_CODE' => $accessProvider->generateAccessCode($chatId),
1083 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_READ)
1084 ]]
1085 );
1086 }
1087
1088 return $folderModel->addFileLink(
1089 $fileModel,
1090 [
1091 'CREATED_BY' => $userId,
1092 'GLOBAL_CONTENT_VERSION' => 1
1093 ],
1094 [],// link inherits access rights from parent folder
1095 true
1096 );
1097 }
1098
1099 protected static function getFileModel(int $fileId, ?int $contextUserId): ?File
1100 {
1101 if (!self::Enabled())
1102 {
1103 return null;
1104 }
1105
1106 if ($fileId <= 0)
1107 {
1108 return null;
1109 }
1110
1111 $fileModel = File::getById($fileId, array('STORAGE'));
1112 if (!$fileModel)
1113 {
1114 return null;
1115 }
1116
1117 $storageModel = $fileModel->getStorage();
1118 if (!$storageModel)
1119 {
1120 return null;
1121 }
1122
1123 $securityContext = null;
1124 if (!isset($contextUserId))
1125 {
1126 $securityContext = $storageModel->getCurrentUserSecurityContext();
1127 }
1128 else if ($contextUserId > 0)
1129 {
1130 $securityContext = $storageModel->getSecurityContext($contextUserId);
1131 }
1132
1133 if ($securityContext && !$fileModel->canRead($securityContext))
1134 {
1135 return null;
1136 }
1137
1138 return $fileModel;
1139 }
1140
1147 public static function RecordShare(int $chatId, int $fileId, ?int $userId = null): bool
1148 {
1149 if (!self::Enabled())
1150 {
1151 return false;
1152 }
1153
1154 if ($chatId <= 0 || $fileId <= 0)
1155 {
1156 return false;
1157 }
1158
1159 $chat = \Bitrix\Im\Model\ChatTable::getByPrimary($chatId, [
1160 'select' => ['TITLE', 'ENTITY_TYPE', 'ENTITY_ID']
1161 ])->fetch();
1162 if (!$chat)
1163 {
1164 return false;
1165 }
1166
1167 if (!\CIMChat::GetRelationById($chatId, $userId, true, false))
1168 {
1169 return false;
1170 }
1171
1172 $fileModel = File::getById($fileId, array('STORAGE'));
1173 if (!$fileModel)
1174 {
1175 return false;
1176 }
1177
1178 $storageModel = $fileModel->getStorage();
1179 if (!$storageModel)
1180 {
1181 return false;
1182 }
1183
1184 $securityContext = null;
1185 if (is_null($userId))
1186 {
1187 $securityContext = $storageModel->getCurrentUserSecurityContext();
1188 }
1189 else if ($userId > 0)
1190 {
1191 $securityContext = $storageModel->getSecurityContext($userId);
1192 }
1193
1194 if ($securityContext && !$fileModel->canRead($securityContext))
1195 {
1196 return false;
1197 }
1198
1199 self::UploadFileFromDisk($chatId, ['disk'.$fileId], '', ['SYMLINK' => true]);
1200
1201 if (!empty($chat['ENTITY_TYPE']) && !empty($chat['ENTITY_ID']))
1202 {
1203 $event = new \Bitrix\Main\Event('im', 'onDiskRecordShare', [
1204 'DISK_ID' => $fileId,
1205 'CHAT' => [
1206 'ID' => $chatId,
1207 'TITLE' => $chat['TITLE'],
1208 'ENTITY_TYPE' => $chat['ENTITY_TYPE'],
1209 'ENTITY_ID' => $chat['ENTITY_ID']
1210 ],
1211 'USER_ID' => $userId,
1212 ]);
1213 $event->send();
1214 }
1215
1216 return true;
1217 }
1218
1227 public static function UploadAvatar($hash, &$file, &$package, &$upload, &$error)
1228 {
1229 $post = \Bitrix\Main\Context::getCurrent()->getRequest()->getPostList()->toArray();
1230
1231 $chatId = (int)$post['CHAT_ID'];
1232 if ($chatId <= 0)
1233 {
1234 return false;
1235 }
1236
1237 $chat = IM\Model\ChatTable::getById($chatId)->fetch();
1238 if (!$chat)
1239 {
1240 return false;
1241 }
1242
1243 $relationError = true;
1244 $chatRelation = \CIMChat::GetRelationById($chatId, false, true, false);
1245 foreach ($chatRelation as $relation)
1246 {
1247 if ($relation["EXTERNAL_AUTH_ID"] == 'imconnector')
1248 {
1249 unset($chatRelation[$relation["USER_ID"]]);
1250 continue;
1251 }
1252 if ($relation['USER_ID'] == self::GetUserId())
1253 {
1254 $relationError = false;
1255 }
1256 }
1257 if ($relationError)
1258 {
1259 $error = Loc::getMessage('IM_DISK_ERR_AVATAR_1');
1260 return false;
1261 }
1262
1263 if ($chat['ENTITY_TYPE'] === 'ANNOUNCEMENT' && $chatRelation[self::GetUserId()]['MANAGER'] !== 'Y')
1264 {
1265 return false;
1266 }
1267
1268 $file["files"]["default"]["MODULE_ID"] = "im";
1269
1270 $checkResponse = \CFile::CheckImageFile($file["files"]["default"], (10*1024*1024), 5000, 5000);
1271 if ($checkResponse !== null)
1272 {
1273 return false;
1274 }
1275
1276 $fileId = \CFile::saveFile($file["files"]["default"], self::MODULE_ID);
1277 if ($fileId > 0)
1278 {
1279 if ($chat['AVATAR'] > 0)
1280 {
1281 \CFile::DeLete($chat['AVATAR']);
1282 }
1283 IM\Model\ChatTable::update($chatId, Array('AVATAR' => $fileId));
1284
1285 $file['chatId'] = $chatId;
1286 $file['chatAvatar'] = \CIMChat::GetAvatarImage($fileId);
1287
1288 if ($chat["ENTITY_TYPE"] != 'CALL')
1289 {
1290 \CIMChat::AddSystemMessage(Array(
1291 'CHAT_ID' => $chatId,
1292 'USER_ID' => self::GetUserId(),
1293 'MESSAGE_CODE' => 'IM_DISK_AVATAR_CHANGE_'
1294 ));
1295 }
1296
1297 if (\Bitrix\Main\Loader::includeModule('pull'))
1298 {
1299 $pullMessage = Array(
1300 'module_id' => 'im',
1301 'command' => 'chatAvatar',
1302 'params' => Array(
1303 'chatId' => $chatId,
1304 'avatar' => $file['chatAvatar'],
1305 ),
1306 'extra' => \Bitrix\Im\Common::getPullExtra()
1307 );
1308 \Bitrix\Pull\Event::add(array_keys($chatRelation), $pullMessage);
1309 if (CIMMessenger::needToSendPublicPull($chat['TYPE']))
1310 {
1311 \CPullWatch::AddToStack('IM_PUBLIC_'.$chat['ID'], $pullMessage);
1312 }
1313 if ($chat['TYPE'] === IM\V2\Chat::IM_TYPE_OPEN_CHANNEL)
1314 {
1315 IM\V2\Chat\OpenChannelChat::sendSharedPull($pullMessage);
1316 }
1317 }
1318 }
1319 else
1320 {
1321 return false;
1322 }
1323
1324 return true;
1325 }
1326
1333 public static function UpdateAvatarId($chatId, $fileId, $userId = null)
1334 {
1335 $chatId = (int)$chatId;
1336 $fileId = (int)$fileId;
1337 if ($chatId <= 0 || $fileId <= 0)
1338 {
1339 return false;
1340 }
1341
1342 $chat = IM\Model\ChatTable::getById($chatId)->fetch();
1343 if (!$chat || in_array($chat['TYPE'], Array(\IM_MESSAGE_PRIVATE, \IM_MESSAGE_SYSTEM)))
1344 {
1345 return false;
1346 }
1347
1348 $relationError = true;
1349 $chatRelation = \CIMChat::GetRelationById($chatId, false, true, false);
1350 foreach ($chatRelation as $relation)
1351 {
1352 if ($relation["EXTERNAL_AUTH_ID"] == 'imconnector')
1353 {
1354 unset($chatRelation[$relation["USER_ID"]]);
1355 continue;
1356 }
1357 if ($relation['USER_ID'] == \Bitrix\Im\Common::getUserId($userId))
1358 {
1359 $relationError = false;
1360 }
1361 }
1362 if ($relationError)
1363 {
1364 return false;
1365 }
1366
1367 if ($chat['AVATAR'] > 0)
1368 {
1369 \CFile::DeLete($chat['AVATAR']);
1370 }
1371 IM\Model\ChatTable::update($chatId, Array('AVATAR' => $fileId));
1372
1373 $file['chatId'] = $chatId;
1374 $file['chatAvatar'] = \CIMChat::GetAvatarImage($fileId);
1375
1376 if ($chat["ENTITY_TYPE"] != 'CALL')
1377 {
1378 \CIMChat::AddSystemMessage(Array(
1379 'CHAT_ID' => $chatId,
1380 'USER_ID' => \Bitrix\Im\Common::getUserId($userId),
1381 'MESSAGE_CODE' => 'IM_DISK_AVATAR_CHANGE_'
1382 ));
1383 }
1384
1385 if (\Bitrix\Main\Loader::includeModule('pull'))
1386 {
1387 $pullMessage = Array(
1388 'module_id' => 'im',
1389 'command' => 'chatAvatar',
1390 'params' => Array(
1391 'chatId' => $chatId,
1392 'avatar' => $file['chatAvatar'],
1393 ),
1394 'extra' => \Bitrix\Im\Common::getPullExtra()
1395 );
1396 \Bitrix\Pull\Event::add(array_keys($chatRelation), $pullMessage);
1397
1398 if (CIMMessenger::needToSendPublicPull($chat['TYPE']))
1399 {
1400 \CPullWatch::AddToStack('IM_PUBLIC_'.$chat['ID'], $pullMessage);
1401 }
1402 if ($chat['TYPE'] === IM\V2\Chat::IM_TYPE_OPEN_CHANNEL)
1403 {
1404 IM\V2\Chat\OpenChannelChat::sendSharedPull($pullMessage);
1405 }
1406 }
1407
1408 return true;
1409 }
1410
1416 public static function GetHistoryFiles($chatId, $historyPage = 1)
1417 {
1418 $fileArray = [];
1419 if (!self::Enabled())
1420 {
1421 return $fileArray;
1422 }
1423
1424 if ((int)$chatId <= 0)
1425 {
1426 return $fileArray;
1427 }
1428
1429 $offset = (int)$historyPage - 1;
1430 if ($offset < 0)
1431 {
1432 return $fileArray;
1433 }
1434
1435 $folderModel = self::getFolderModel($chatId, false);
1436 if (!$folderModel)
1437 {
1438 return $fileArray;
1439 }
1440
1441 $filter = Array(
1442 'PARENT_ID' => $folderModel->getId(),
1443 'STORAGE_ID' => $folderModel->getStorageId()
1444 );
1445
1446 $relation = \CIMChat::GetRelationById($chatId, self::GetUserId(), true, false);
1447 if (!$relation)
1448 {
1449 return $fileArray;
1450 }
1451
1452 if ($relation['LAST_FILE_ID'] > 0)
1453 {
1454 $filter['>ID'] = $relation['LAST_FILE_ID'];
1455 }
1456
1460 $securityContext = new \Bitrix\Disk\Security\DiskSecurityContext(self::GetUserId());
1461
1462 $parameters = Array(
1463 'filter' => $filter,
1464 'with' => Array('CREATE_USER'),
1465 'limit' => 15,
1466 'offset' => $offset*15,
1467 'order' => Array('UPDATE_TIME' => 'DESC')
1468 );
1469 $parameters = \Bitrix\Disk\Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY'));
1470
1471 $fileCollection = File::getModelList($parameters);
1472
1473 foreach ($fileCollection as $fileModel)
1474 {
1475 $fileArray[$fileModel->getId()] = self::GetFileParams($chatId, $fileModel);
1476 }
1477
1478 return $fileArray;
1479 }
1480
1486 public static function GetHistoryFilesByName($chatId, $name)
1487 {
1488 $fileArray = [];
1489 if (!self::Enabled())
1490 {
1491 return $fileArray;
1492 }
1493
1494 if ((int)$chatId <= 0)
1495 {
1496 return $fileArray;
1497 }
1498
1499 $name = trim($name);
1500 if ($name == '')
1501 {
1502 return $fileArray;
1503 }
1504
1505 $folderModel = self::getFolderModel($chatId, false);
1506 if (!$folderModel)
1507 {
1508 return $fileArray;
1509 }
1510
1511 $filter = Array(
1512 'PARENT_ID' => $folderModel->getId(),
1513 'STORAGE_ID' => $folderModel->getStorageId(),
1514 '%=NAME' => str_replace("%", '', $name)."%",
1515 );
1516
1517 $relation = \CIMChat::GetRelationById($chatId, self::GetUserId(), true, false);
1518 if (!$relation)
1519 {
1520 return $fileArray;
1521 }
1522
1523 if ($relation['LAST_FILE_ID'] > 0)
1524 {
1525 $filter['>ID'] = $relation['LAST_FILE_ID'];
1526 }
1527
1531 $securityContext = new \Bitrix\Disk\Security\DiskSecurityContext(self::GetUserId());
1532
1533 $parameters = Array(
1534 'filter' => $filter,
1535 'with' => Array('CREATE_USER'),
1536 'limit' => 100,
1537 'order' => Array('UPDATE_TIME' => 'DESC')
1538 );
1539 $parameters = \Bitrix\Disk\Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY'));
1540
1541 $fileCollection = File::getModelList($parameters);
1542
1543 foreach ($fileCollection as $fileModel)
1544 {
1545 $fileArray[$fileModel->getId()] = self::GetFileParams($chatId, $fileModel);
1546 }
1547
1548 return $fileArray;
1549 }
1550
1555 public static function GetMaxFileId($chatId)
1556 {
1557 $maxId = 0;
1558 if (!self::Enabled())
1559 {
1560 return $maxId;
1561 }
1562
1563 if ((int)$chatId <= 0)
1564 {
1565 return $maxId;
1566 }
1567
1568 $folderModel = self::getFolderModel($chatId, false);
1569 if (!$folderModel)
1570 {
1571 return $maxId;
1572 }
1573
1574 $result = \Bitrix\Disk\Internals\ObjectTable::getList(array(
1575 'select' => array('MAX_ID'),
1576 'filter' => array(
1577 '=PARENT_ID' => $folderModel->getId(),
1578 '=TYPE' => \Bitrix\Disk\Internals\ObjectTable::TYPE_FILE
1579 ),
1580 'runtime' => array(
1581 'MAX_ID' => array(
1582 'data_type' => 'integer',
1583 'expression' => array('MAX(ID)')
1584 )
1585 )
1586 ));
1587 if ($data = $result->fetch())
1588 {
1589 $maxId = $data['MAX_ID'];
1590 }
1591
1592 return (int)$maxId;
1593 }
1594
1601 public static function GetFiles($chatId, $fileId = false, $checkPermission = true)
1602 {
1603 $fileArray = Array();
1604 if (!self::Enabled())
1605 {
1606 return $fileArray;
1607 }
1608
1609 if ((int)$chatId <= 0)
1610 {
1611 return $fileArray;
1612 }
1613
1614 if ($fileId === false || $fileId === null)
1615 {
1616 if (!is_array($fileId))
1617 {
1618 $fileId = Array($fileId);
1619 }
1620 foreach ($fileId as $key => $value)
1621 {
1622 $fileId[$key] = (int)$value;
1623 }
1624 }
1625 if (empty($fileId))
1626 {
1627 return $fileArray;
1628 }
1629 $folderModel = self::getFolderModel($chatId, false);
1630 if (!$folderModel)
1631 {
1632 return $fileArray;
1633 }
1634 $filter = Array(
1635 'PARENT_ID' => $folderModel->getId(),
1636 'STORAGE_ID' => $folderModel->getStorageId()
1637 );
1638 if ($fileId)
1639 {
1640 $filter['ID'] = array_values($fileId);
1641 }
1642
1643 if ($checkPermission)
1644 {
1645 $securityContext = new \Bitrix\Disk\Security\DiskSecurityContext(self::GetUserId());
1646 }
1647 else
1648 {
1649 $securityContext = \Bitrix\Disk\Driver::getInstance()->getFakeSecurityContext();
1650 }
1651
1652 $parameters = Array(
1653 'filter' => $filter,
1654 'with' => Array('CREATE_USER')
1655 );
1656 $parameters = \Bitrix\Disk\Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, array('ID', 'CREATED_BY'));
1657
1658 $fileCollection = File::getModelList($parameters);
1659 foreach ($fileCollection as $fileModel)
1660 {
1661 $fileArray[$fileModel->getId()] = self::GetFileParams($chatId, $fileModel);
1662 }
1663
1664 return $fileArray;
1665 }
1666
1672 public static function GetFileParams($chatId, $fileModel, $options = [])
1673 {
1674 if (!self::Enabled())
1675 {
1676 return false;
1677 }
1678
1679 if ($fileModel instanceof File)
1680 {
1681 }
1682 elseif ((int)$fileModel > 0)
1683 {
1684 $fileModel = File::getById($fileModel);
1685 }
1686 else
1687 {
1688 return false;
1689 }
1690
1691 if (!$fileModel || $fileModel->getId() <= 0)
1692 {
1693 return false;
1694 }
1695
1696 $file = new IM\V2\Entity\File\FileItem($fileModel, $chatId);
1697 $params = $file->toRestFormat();
1698 $params['date'] = $fileModel->getCreateTime(); // backward compatibility
1699
1700 return $params;
1701 }
1702
1707 public static function Enabled()
1708 {
1709 static $isEnable;
1710 if ($isEnable === null)
1711 {
1712 $isEnable =
1714 && \CPullOptions::GetNginxStatus()
1716 && \Bitrix\Disk\Driver::isSuccessfullyConverted()
1717 ;
1718 }
1719
1720 return $isEnable;
1721 }
1722
1723 public static function updateFolderRights(int $chatId, bool $fullRights = false): bool
1724 {
1725 if (!self::Enabled() || $chatId <= 0)
1726 {
1727 return false;
1728 }
1729
1730 $result = IM\Model\ChatTable::getById($chatId);
1731 if (!$chat = $result->fetch())
1732 {
1733 return false;
1734 }
1735
1736 if ($chat['TYPE'] !== IM\V2\Chat::IM_TYPE_CHAT)
1737 {
1738 return false;
1739 }
1740
1741 $folderId = (int)$chat['DISK_FOLDER_ID'];
1742 if ($folderId <= 0)
1743 {
1744 return false;
1745 }
1746
1747 $folderModel = \Bitrix\Disk\Folder::getById($folderId);
1748 if (
1749 !$folderModel
1750 || !($folderModel instanceof \Bitrix\Disk\Folder)
1751 || ($folderModel->getStorageId() != self::GetStorageId($chatId))
1752 )
1753 {
1754 return false;
1755 }
1756
1757 $driver = \Bitrix\Disk\Driver::getInstance();
1758 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
1759 $rightsManager = $driver->getRightsManager();
1760
1761 if ($fullRights)
1762 {
1763 $accessCode = self::GetTopDepartmentCode();
1764 }
1765 else
1766 {
1767 $accessCode = $accessProvider->generateAccessCode($chatId);
1768 }
1769
1770 $rightsManager->delete($folderModel);
1771 return $rightsManager->append(
1772 $folderModel,
1773 [[
1774 'ACCESS_CODE' => $accessCode,
1775 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_READ)
1776 ]]
1777 );
1778 }
1779
1786 public static function GetFolderModel($chatId, $createFolder = true)
1787 {
1788 if (!self::Enabled())
1789 {
1790 return false;
1791 }
1792
1793 if ((int)$chatId <= 0)
1794 {
1795 return false;
1796 }
1797
1798 $folderModel = false;
1799
1800 if (isset(self::$chatList[$chatId]))
1801 {
1802 $chat = self::$chatList[$chatId];
1803 }
1804 else
1805 {
1806 $chat = IM\Model\ChatTable::getRow([
1807 'select' => [
1808 'TYPE',
1809 'DISK_FOLDER_ID',
1810 'PARENT_ID'
1811 ],
1812 'filter' => [
1813 'ID' => $chatId,
1814 ]
1815 ]);
1816
1817 self::$chatList[$chatId] = $chat;
1818 }
1819
1820 if (!$chat)
1821 {
1822 return false;
1823 }
1824
1825 $folderId = (int)$chat['DISK_FOLDER_ID'];
1826 if ($folderId > 0)
1827 {
1828 if (isset(self::$folderList[$folderId]) && self::$folderList[$folderId] instanceof \Bitrix\Disk\Folder)
1829 {
1830 $folderModel = self::$folderList[$folderId];
1831 }
1832 else
1833 {
1834 $folderModel = \Bitrix\Disk\Folder::getById($folderId);
1835 self::$folderList[$folderId] = $folderModel;
1836 }
1837
1838 if (
1839 !$folderModel
1840 || !($folderModel instanceof \Bitrix\Disk\Folder)
1841 || ($folderModel->getStorageId() != self::GetStorageId($chatId))
1842 )
1843 {
1844 $folderId = 0;
1845 }
1846 }
1847
1848 if ($folderId || !$createFolder)
1849 {
1850 return $folderModel;
1851 }
1852
1853 $chatType = $chat['TYPE'];
1854 $withRights = true;
1855
1856 if ($chatType === IM\V2\Chat::IM_TYPE_COMMENT)
1857 {
1858 $folderModel = self::createSubFolder($chatId, (int)$chat['PARENT_ID']);
1859 $withRights = false;
1860 }
1861 else
1862 {
1863 $folderModel = self::createFolder($chatId, $chatType);
1864 }
1865
1866 if ($folderModel)
1867 {
1868 IM\Model\ChatTable::update($chatId, ['DISK_FOLDER_ID' => $folderModel->getId()]);
1869
1870 if (isset(self::$chatList[$chatId]))
1871 {
1872 self::$chatList[$chatId]['DISK_FOLDER_ID'] = $folderModel->getId();
1873 }
1874 self::$folderList[$folderId] = $folderModel;
1875
1876 if ($withRights)
1877 {
1878 (new \Bitrix\Im\Access\ChatAuthProvider)->updateChatCodesByRelations($chatId);
1879 }
1880 }
1881
1882 return $folderModel;
1883 }
1884
1890 protected static function createSubFolder(int $chatId, int $parentId)
1891 {
1892 $parentChat = IM\V2\Chat::getInstance($parentId);
1893 $parentFolder = $parentChat->getOrCreateDiskFolder();
1894 if (!$parentFolder)
1895 {
1896 return false;
1897 }
1898 return $parentFolder->addSubFolder(
1899 [
1900 'NAME' => 'chat'.$chatId,
1901 'CREATED_BY' => self::GetUserId()
1902 ],
1903 [],
1904 true
1905 );
1906 }
1907
1913 protected static function createFolder(int $chatId, string $chatType)
1914 {
1915 $driver = \Bitrix\Disk\Driver::getInstance();
1916 $storageModel = self::GetStorage($chatId);
1917 if (!$storageModel)
1918 {
1919 return false;
1920 }
1921
1922 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
1923 $rightsManager = $driver->getRightsManager();
1924
1925 $accessCodes = [];
1926 // allow for access code `CHATxxx`
1927 $accessCodes[] = [
1928 'ACCESS_CODE' => $accessProvider->generateAccessCode($chatId),
1929 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_EDIT)
1930 ];
1931
1932 if ($chatType === IM\V2\Chat::IM_TYPE_COLLAB)
1933 {
1934 $folder = $storageModel->getFolderForUploadedFiles();
1935 if (!$folder)
1936 {
1937 return false;
1938 }
1939
1940 $driver->getRightsManager()->append($folder, $accessCodes);
1941
1942 return $folder;
1943 }
1944
1945 if ($chatType === IM\V2\Chat::IM_TYPE_OPEN || $chatType === IM\V2\Chat::IM_TYPE_OPEN_CHANNEL)
1946 {
1947 // allow reading for top department, access code `DRxxx`
1948 $departmentCode = self::GetTopDepartmentCode();
1949 if ($departmentCode)
1950 {
1951 $accessCodes[] = Array(
1952 'ACCESS_CODE' => $departmentCode,
1953 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_READ)
1954 );
1955 }
1956 }
1957
1958 return $storageModel->addFolder(
1959 [
1960 'NAME' => 'chat'.$chatId,
1961 'CREATED_BY' => self::GetUserId()
1962 ],
1963 $accessCodes,
1964 true
1965 );
1966 }
1967
1974 public static function ChangeFolderMembers($chatId, $userId, $append = true)
1975 {
1976 $chatId = (int)$chatId;
1977 if (!is_array($userId))
1978 {
1979 $userIds = Array($userId);
1980 }
1981 else
1982 {
1983 $userIds = $userId;
1984 }
1985 if ($chatId <= 0 || empty($userIds))
1986 {
1987 return false;
1988 }
1989
1990 if (isset(self::$chatList[$chatId]))
1991 {
1992 $chat = self::$chatList[$chatId];
1993 }
1994 else
1995 {
1996 $chat = IM\Model\ChatTable::getRow([
1997 'select' => [
1998 'TYPE',
1999 'DISK_FOLDER_ID',
2000 ],
2001 'filter' => [
2002 'ID' => $chatId,
2003 ]
2004 ]);
2005
2006 self::$chatList[$chatId] = $chat;
2007 }
2008
2009 if (!$chat)
2010 {
2011 return false;
2012 }
2013
2014 if ($chat['TYPE'] === IM\V2\Chat::IM_TYPE_COMMENT)
2015 {
2016 return true;
2017 }
2018
2019 $folderModel = self::getFolderModel($chatId, false);
2020 if (!$folderModel)
2021 {
2022 return false;
2023 }
2024
2025 $accessProvider = new \Bitrix\Im\Access\ChatAuthProvider;
2026
2027 if ($append)
2028 {
2029 $accessProvider->addChatCodes($chatId, $userIds);
2030 $result = true;
2031 }
2032 else
2033 {
2034 $accessProvider->deleteChatCodes($chatId, $userIds);
2035
2036 // keep removing disk access codes `Uxxx` for previous access scheme
2037 $accessCodes = Array();
2038 if ($chat['TYPE'] == \IM_MESSAGE_OPEN)
2039 {
2040 $users = \CIMContactList::GetUserData(array(
2041 'ID' => array_values($userIds),
2042 'DEPARTMENT' => 'N',
2043 'SHOW_ONLINE' => 'N',
2044 ));
2045 foreach ($users['users'] as $userData)
2046 {
2047 if ($userData['extranet'])
2048 {
2049 $accessCodes[] = 'U'.$userData['id'];
2050 }
2051 }
2052 }
2053 else
2054 {
2055 foreach ($userIds as $uid)
2056 {
2057 $uid = (int)$uid;
2058 if ($uid <= 0)
2059 {
2060 continue;
2061 }
2062
2063 $accessCodes[] = 'U'.$uid;
2064 }
2065 }
2066 $driver = \Bitrix\Disk\Driver::getInstance();
2067 $rightsManager = $driver->getRightsManager();
2068 $result = $rightsManager->revokeByAccessCodes($folderModel, $accessCodes);
2069 }
2070
2071 return $result;
2072 }
2073
2078 public static function GetBackgroundFolderModel($userId = null)
2079 {
2080 if (!self::Enabled())
2081 {
2082 return null;
2083 }
2084
2085 $userId = IM\Common::getUserId($userId);
2086 if (!$userId)
2087 {
2088 return null;
2089 }
2090
2091 $storageModel = self::GetStorage();
2092 if (!$storageModel)
2093 {
2094 return null;
2095 }
2096
2097 $folderModel = $storageModel->getSpecificFolderByCode('CALL_BACKGROUND_'.$userId);
2098 if ($folderModel)
2099 {
2100 return $folderModel;
2101 }
2102
2103 $backgroundFolderModel = $storageModel->getSpecificFolderByCode('CALL_BACKGROUND');
2104 if (!$backgroundFolderModel)
2105 {
2106 $backgroundFolderModel = $storageModel->addFolder([
2107 'NAME' => 'CALL_BACKGROUND',
2108 'CODE' => 'CALL_BACKGROUND',
2109 'CREATED_BY' => SystemUser::SYSTEM_USER_ID,
2110 ], [], true);
2111 }
2112 if (!$backgroundFolderModel)
2113 {
2114 return null;
2115 }
2116
2117 $rightsManager = \Bitrix\Disk\Driver::getInstance()->getRightsManager();
2118
2119 $folderModel = $backgroundFolderModel->addSubFolder(
2120 [
2121 'NAME' => 'CALL_BACKGROUND_'.$userId,
2122 'CODE' => 'CALL_BACKGROUND_'.$userId,
2123 'CREATED_BY' => $userId,
2124 ],
2125 [
2126 // allow only for user, access code `Uxxx`
2127 ['ACCESS_CODE' => 'U'.$userId, 'TASK_ID' => $rightsManager->getTaskIdByName($rightsManager::TASK_FULL)],
2128 ],
2129 true
2130 );
2131
2132 return $folderModel;
2133 }
2134
2140 public static function CommitBackgroundFile($userId, $fileId)
2141 {
2143 if (!$folderModel)
2144 {
2145 return false;
2146 }
2147
2148 $fileModel = File::getById($fileId);
2149 if (!$fileModel || $fileModel->getParentId() != $folderModel->getId())
2150 {
2151 return false;
2152 }
2153
2154 $fileModel->increaseGlobalContentVersion();
2155
2156 return true;
2157 }
2158
2163 public static function DeleteBackgroundFile($userId, $fileId)
2164 {
2166 if (!$folderModel)
2167 {
2168 return false;
2169 }
2170
2171 $fileModel = File::getById($fileId);
2172 if (!$fileModel || $fileModel->getParentId() != $folderModel->getId())
2173 {
2174 return false;
2175 }
2176
2177 $fileModel->delete($userId);
2178
2179 return true;
2180 }
2181
2186 public static function GetLocalDiskSavedModel($userId = null)
2187 {
2188 if (!self::Enabled())
2189 {
2190 return false;
2191 }
2192
2193 $userId = IM\Common::getUserId($userId);
2194 if (!$userId)
2195 {
2196 return false;
2197 }
2198
2199 $storageModel = \Bitrix\Disk\Driver::getInstance()->getStorageByUserId($userId);
2200 if (!$storageModel)
2201 {
2202 return false;
2203 }
2204
2205 return $storageModel->getFolderForSavedFiles();
2206 }
2207
2211 public static function GetStorageId(?int $chatId = null)
2212 {
2213 if ($chatId === null)
2214 {
2215 return (int)\Bitrix\Main\Config\Option::get('im', 'disk_storage_id', 0);
2216 }
2217
2218 return IM\V2\Chat::getInstance($chatId)->getStorageId();
2219 }
2220
2225 public static function SetStorageId($id)
2226 {
2227 $id = (int)$id;
2228 if ($id <= 0)
2229 {
2230 return false;
2231 }
2232
2233 $oldId = self::GetStorageId();
2234 if ($oldId > 0 && $oldId != $id)
2235 {
2237 $connection->queryExecute("UPDATE b_im_chat SET DISK_FOLDER_ID = 0");
2238 $connection->queryExecute("DELETE FROM b_im_message_param WHERE PARAM_NAME = 'FILE_ID'");
2239 }
2240
2241 \Bitrix\Main\Config\Option::set('im', 'disk_storage_id', $id);
2242
2243 return true;
2244 }
2245
2249 public static function GetLocalDiskFolderPath()
2250 {
2251 if (!self::Enabled())
2252 {
2253 return '';
2254 }
2255
2256 $folderModel = self::GetLocalDiskSavedModel();
2257 if (!$folderModel)
2258 {
2259 return '';
2260 }
2261
2262 return \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlFocusController('openFolderList', array('folderId' => $folderModel->getId()));
2263 }
2264
2269 public static function GetLocalDiskFilePath($fileId = 0)
2270 {
2271 if (!self::Enabled())
2272 {
2273 return '';
2274 }
2275
2276 $fileId = (int)$fileId;
2277
2278 return \Bitrix\Disk\Driver::getInstance()->getUrlManager()->getUrlFocusController('showObjectInGrid', array('objectId' => $fileId? $fileId: '_FILE_ID_'));
2279 }
2280
2287 public static function GetPublicPath($type, File $fileModel, $checkContentVersion = true)
2288 {
2289 $result = '';
2290
2291 if (!in_array($type, Array(self::PATH_TYPE_DOWNLOAD, self::PATH_TYPE_SHOW, self::PATH_TYPE_PREVIEW)))
2292 {
2293 return $result;
2294 }
2295
2296 if ($checkContentVersion && $fileModel->getGlobalContentVersion() <= 1)
2297 {
2298 return $result;
2299 }
2300
2302
2303 $isImage = \Bitrix\Disk\TypeFile::isImage($fileModel);
2304 $isVideo = \Bitrix\Disk\TypeFile::isVideo($fileModel->getName());
2305
2306 if ($type == self::PATH_TYPE_SHOW)
2307 {
2308 if ($isImage)
2309 {
2310 $result = $urlManager->create('disk.api.file.showImage', [
2311 'humanRE' => 1,
2312 'fileId' => $fileModel->getId(),
2313 'fileName' => $fileModel->getName()
2314 ])->getUri();
2315 }
2316 else
2317 {
2318 $result = $urlManager->create('disk.api.file.download', [
2319 'humanRE' => 1,
2320 'fileId' => $fileModel->getId(),
2321 'fileName' => $fileModel->getName()
2322 ])->getUri();
2323 }
2324 }
2325 else if ($type == self::PATH_TYPE_PREVIEW)
2326 {
2327 if (!($isImage || $isVideo))
2328 {
2329 return $result;
2330 }
2331
2332 if ($fileModel->getView()->getPreviewData())
2333 {
2334 $linkType = 'disk.api.file.showPreview';
2335 $fileName = 'preview.jpg';
2336 }
2337 else if ($isImage)
2338 {
2339 $linkType = 'disk.api.file.showImage';
2340 $fileName = $fileModel->getName();
2341 }
2342 else
2343 {
2344 return $result;
2345 }
2346
2347 $result = $urlManager->create($linkType, [
2348 'humanRE' => 1,
2349 'width' => 640,
2350 'height' => 640,
2351 'signature' => \Bitrix\Disk\Security\ParameterSigner::getImageSignature($fileModel->getId(), 640, 640),
2352 'fileId' => $fileModel->getId(),
2353 'fileName' => $fileName
2354 ])->getUri();
2355 }
2356 else if ($type == self::PATH_TYPE_DOWNLOAD)
2357 {
2358 $result = $urlManager->create('disk.api.file.download', [
2359 'humanRE' => 1,
2360 'fileId' => $fileModel->getId(),
2361 'fileName' => $fileModel->getName()
2362 ])->getUri();
2363 }
2364
2365 return $result;
2366 }
2367
2372 public static function GetFileLink(File $fileModel)
2373 {
2374 if (!\Bitrix\Main\Loader::includeModule('disk'))
2375 {
2376 return false;
2377 }
2378
2379 $fileId = $fileModel->getId();
2380
2381 $signer = new \Bitrix\Main\Security\Sign\Signer;
2382 $signKey = self::GetFileLinkSign();
2383 if (is_string($signKey))
2384 {
2385 $signer->setKey($signKey);
2386 }
2387 $signedValue = $signer->sign($fileId);
2388
2390 $host = $urlManager->getHostUrl();
2391 $isImage = \Bitrix\Disk\TypeFile::isImage($fileModel);
2392
2393 $link = $host.'/pub/im.file.php?FILE_ID='.$fileId.'&SIGN='.$signedValue;
2394 if ($isImage)
2395 {
2396 $link .= '&img=y';
2397 }
2398
2399 $shortLink = $host. \CBXShortUri::GetShortUri($link);
2400 if ($isImage)
2401 {
2402 $shortLink .= '#img.'.$fileModel->getExtension();
2403 }
2404
2405 return $shortLink;
2406 }
2407
2411 public static function GetFileLinkSign()
2412 {
2413 $key = \Bitrix\Main\Config\Option::get('im', 'file_link_default_key', null);
2414 if (!$key)
2415 {
2416 $key = \Bitrix\Main\Config\Option::get('main', 'signer_default_key', null);
2417 if (is_string($key))
2418 {
2419 \Bitrix\Main\Config\Option::set('im', 'file_link_default_key', $key);
2420 }
2421 }
2422 return $key;
2423 }
2424
2428 public static function RemoveTmpFileAgent(): string
2429 {
2430 $storageModel = self::GetStorage();
2431 if (!$storageModel)
2432 {
2433 return "CIMDisk::RemoveTmpFileAgent();";
2434 }
2435 $date = new \Bitrix\Main\Type\DateTime();
2436 $date->add('YESTERDAY');
2437
2438 $fileModels = File::getModelList(Array(
2439 'filter' => Array(
2440 'GLOBAL_CONTENT_VERSION' => 1,
2441 '=TYPE' => \Bitrix\Disk\Internals\FileTable::TYPE,
2442 'STORAGE_ID' => $storageModel->getId(),
2443 '<CREATE_TIME' => $date
2444 ),
2445 'limit' => 200
2446 ));
2447 foreach ($fileModels as $fileModel)
2448 {
2449 $fileModel->delete(SystemUser::SYSTEM_USER_ID);
2450 }
2451
2452 return __METHOD__. '();';
2453 }
2454
2458 public static function GetUserId()
2459 {
2461 global $USER;
2462 return $USER instanceOf \CUser ? (int)$USER->getId() : 0;
2463 }
2464
2468 public static function EnabledExternalLink()
2469 {
2470 if (!\Bitrix\Main\Loader::includeModule('disk'))
2471 {
2472 return false;
2473 }
2474
2475 return \Bitrix\Disk\Configuration::isEnabledExternalLink();
2476 }
2477
2482 public static function SetEnabledExternalLink($flag = true)
2483 {
2484 if (!\Bitrix\Main\Loader::includeModule('disk'))
2485 {
2486 return false;
2487 }
2488
2489 if (!\CIMMessenger::IsAdmin())
2490 {
2491 return false;
2492 }
2493
2494 \Bitrix\Main\Config\Option::set('disk', 'disk_allow_use_external_link', $flag ? 'Y': 'N');
2495
2496 return true;
2497 }
2498
2502 public static function GetTopDepartmentCode(): false|string
2503 {
2504 $topCode = IM\V2\Integration\HumanResources\Department\Department::getInstance()->getTopCode();
2505
2506 return $topCode ?? false;
2507 }
2508
2515 public static function OnAfterDeleteFile($fileId, $userId, $fileParams = Array())
2516 {
2517 if (
2518 !isset($fileParams['STORAGE_ID'])
2519 || !self::isStorageAssociatedWithChat((int)$fileParams['STORAGE_ID'])
2520 )
2521 {
2522 return true;
2523 }
2524
2525 $messageIds = \CIMMessageParam::GetMessageIdByParam('FILE_ID', $fileId);
2526 \CIMMessageParam::DeleteByParam('FILE_ID', $fileId);
2527 (new IM\V2\Link\File\FileService())->deleteFilesByDiskFileId($fileId);
2528 foreach ($messageIds as $messageId)
2529 {
2530 \CIMMessageParam::SendPull((int)$messageId, Array('FILE_ID'));
2531 }
2532
2533 return true;
2534 }
2535
2544 protected static function isStorageAssociatedWithChat(int $storageId): bool
2545 {
2546 if ($storageId === self::GetStorageId())
2547 {
2548 return true;
2549 }
2550
2551 if (
2552 !Loader::includeModule('disk')
2553 || !Loader::includeModule('socialnetwork')
2554 )
2555 {
2556 return false;
2557 }
2558
2559 $storage = Disk\Storage::loadById($storageId);
2560 if ($storage === null)
2561 {
2562 return false;
2563 }
2564
2565 if (!($storage->getProxyType() instanceof Disk\ProxyType\Group))
2566 {
2567 return false;
2568 }
2569
2570 $groupId = (int)$storage->getEntityId();
2571
2572 return CollabProvider::getInstance()->isCollab($groupId);
2573 }
2574}
$connection
Определения actionsdefinitions.php:38
$hash
Определения ajax_redirector.php:8
$type
Определения options.php:106
if(! $messageFields||!isset($messageFields['message_id'])||!isset($messageFields['status'])||!CModule::IncludeModule("messageservice")) $messageId
Определения callback_ismscenter.php:26
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getInstance()
Определения application.php:98
static getConnection($name="")
Определения application.php:638
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
static set($moduleId, $name, $value="", $siteId="")
Определения option.php:261
static getInstance()
Определения urlmanager.php:28
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
static add($recipient, array $parameters, $channelType=\CPullChannel::TYPE_PRIVATE)
Определения event.php:22
static GetShortUri($uri)
Определения short_uri.php:59
Определения im_disk.php:15
static UploadFileUnRegister($chatId, $files, $messages)
Определения im_disk.php:304
static getFileModel(int $fileId, ?int $contextUserId)
Определения im_disk.php:1099
static createSymlink(File $fileModel, int $chatId, int $userId, bool $withSharingRights=true)
Определения im_disk.php:1059
static RecordShare(int $chatId, int $fileId, ?int $userId=null)
Определения im_disk.php:1147
static CommitBackgroundFile($userId, $fileId)
Определения im_disk.php:2140
static GetFolderModel($chatId, $createFolder=true)
Определения im_disk.php:1786
static GetFileLinkSign()
Определения im_disk.php:2411
const PATH_TYPE_PREVIEW
Определения im_disk.php:19
static OnAfterDeleteFile($fileId, $userId, $fileParams=Array())
Определения im_disk.php:2515
static DeleteBackgroundFile($userId, $fileId)
Определения im_disk.php:2163
static updateFolderRights(int $chatId, bool $fullRights=false)
Определения im_disk.php:1723
static createSubFolder(int $chatId, int $parentId)
Определения im_disk.php:1890
static SaveToLocalDisk($fileId)
Определения im_disk.php:889
static UploadFileFromMain($chatId, $files, ?int $authorId=null)
Определения im_disk.php:830
static GetTopDepartmentCode()
Определения im_disk.php:2502
const MODULE_ID
Определения im_disk.php:16
static SetStorageId($id)
Определения im_disk.php:2225
static SetEnabledExternalLink($flag=true)
Определения im_disk.php:2482
static UploadFileRegister($chatId, $files, $text='', $linesSilentMode=false)
Определения im_disk.php:81
static GetLocalDiskSavedModel($userId=null)
Определения im_disk.php:2186
static uploadFromLocalDisk(int $chatId, int $fileId, ?int $userId=null, bool $asFile=false)
Определения im_disk.php:786
static ChangeFolderMembers($chatId, $userId, $append=true)
Определения im_disk.php:1974
static RemoveTmpFileAgent()
Определения im_disk.php:2428
static GetBackgroundFolderModel($userId=null)
Определения im_disk.php:2078
static GetStorage(?int $chatId=null)
Определения im_disk.php:30
static createFolder(int $chatId, string $chatType)
Определения im_disk.php:1913
static UploadFileFromDisk($chatId, $files, $text='', $options=[], $robot=false)
Определения im_disk.php:487
static IncreaseFileVersionDisk($chatId, $fileId, ?int $userId=null)
Определения im_disk.php:950
static DeleteFile($chatId, $fileId)
Определения im_disk.php:392
static EnabledExternalLink()
Определения im_disk.php:2468
static checkDirectlyUseFileAccess(File $fileModel, Disk\Folder $folderModel, int $userId)
Определения im_disk.php:755
static GetFiles($chatId, $fileId=false, $checkPermission=true)
Определения im_disk.php:1601
static UploadAvatar($hash, &$file, &$package, &$upload, &$error)
Определения im_disk.php:1227
static GetLocalDiskFolderPath()
Определения im_disk.php:2249
static SaveFromLocalDisk($chatId, $fileId, bool $symlink=false, ?int $userId=null)
Определения im_disk.php:1001
static GetHistoryFilesByName($chatId, $name)
Определения im_disk.php:1486
static GetUserId()
Определения im_disk.php:2458
static GetMaxFileId($chatId)
Определения im_disk.php:1555
static GetHistoryFiles($chatId, $historyPage=1)
Определения im_disk.php:1416
static GetFileParams($chatId, $fileModel, $options=[])
Определения im_disk.php:1672
static GetStorageId(?int $chatId=null)
Определения im_disk.php:2211
static Enabled()
Определения im_disk.php:1707
static GetFileLink(File $fileModel)
Определения im_disk.php:2372
static isStorageAssociatedWithChat(int $storageId)
Определения im_disk.php:2544
const PATH_TYPE_SHOW
Определения im_disk.php:18
static GetPublicPath($type, File $fileModel, $checkContentVersion=true)
Определения im_disk.php:2287
static UpdateAvatarId($chatId, $fileId, $userId=null)
Определения im_disk.php:1333
static UploadFile($hash, &$file, &$package, &$upload, &$error)
Определения im_disk.php:181
const PATH_TYPE_DOWNLOAD
Определения im_disk.php:20
static GetLocalDiskFilePath($fileId=0)
Определения im_disk.php:2269
static Add($arFields)
Определения im_message.php:28
static Delete($id, $userId=null, $completeDelete=false, $byEvent=false)
Определения im_message.php:1215
$options
Определения commerceml2.php:49
$templateId
Определения component_props2.php:51
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$host
Определения .description.php:9
$uid
Определения hot_keys_act.php:8
$filter
Определения iblock_catalog_list.php:54
const IM_MESSAGE_OPEN
Определения include.php:24
const IM_MESSAGE_SYSTEM
Определения include.php:21
const IM_MESSAGE_PRIVATE
Определения include.php:22
global $USER
Определения csv_new_run.php:40
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
$name
Определения menu_edit.php:35
$event
Определения prolog_after.php:141
return false
Определения prolog_main_admin.php:185
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
$fileName
Определения quickway.php:305
if(empty($signedUserToken)) $key
Определения quickway.php:257
if(empty($decryptedData)) $storage
Определения quickway.php:270
$text
Определения template_pdf.php:79
$messages
Определения template.php:8
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$post
Определения template.php:8
$error
Определения subscription_card_product.php:20
$GLOBALS['_____370096793']
Определения update_client.php:1