File manager - Edit - /home/c14075/dragmet-ural.ru/www/V2.tar
Back
Result.php 0000644 00000001146 15133253725 0006543 0 ustar 00 <?php namespace Bitrix\Im\V2; /** * @template T */ class Result extends \Bitrix\Main\Result { protected bool $hasResult = false; /** * Sets only the result. * @param T $result * @return self */ public function setResult($result): self { $this->hasResult = true; return parent::setData(['RESULT' => $result]); } /** * Returns a single result. * @return T|null */ public function getResult() { return parent::getData()['RESULT'] ?? null; } /** * We have a result. * @return bool */ public function hasResult(): bool { return $this->isSuccess() && $this->hasResult; } } Controller/Call/Mask.php 0000644 00000000401 15133253725 0011147 0 ustar 00 <?php namespace Bitrix\Im\V2\Controller\Call; use Bitrix\Main\Engine\Controller; class Mask extends Controller { /** * @restMethod im.v2.Call.Mask.get */ public function getAction() { return [ 'masks' => \Bitrix\Im\Call\Mask::get(), ]; } } Controller/Call/Background.php 0000644 00000003075 15133253725 0012345 0 ustar 00 <?php namespace Bitrix\Im\V2\Controller\Call; use Bitrix\Main\Engine\Controller; use Bitrix\UI\InfoHelper; class Background extends Controller { /** * @restMethod im.v2.Call.Background.get */ public function getAction() { $diskFolder = \Bitrix\Im\Call\Background::getUploadFolder(); $diskFolderId = $diskFolder? (int)$diskFolder->getId(): 0; $infoHelperParams = \Bitrix\Main\Loader::includeModule('ui')? InfoHelper::getInitParams(): []; return [ 'backgrounds' => [ 'default' => \Bitrix\Im\Call\Background::get(), 'custom' => \Bitrix\Im\Call\Background::getCustom(), ], 'upload' => [ 'folderId' => $diskFolderId, ], 'limits' => \Bitrix\Im\Call\Background::getLimitForJs(), 'infoHelperParams' => $infoHelperParams, ]; } /** * @restMethod im.v2.Call.Background.commit */ public function commitAction(int $fileId) { $result = \CIMDisk::CommitBackgroundFile( $this->getCurrentUser()->getId(), $fileId ); if (!$result) { $this->addError(new \Bitrix\Main\Error( "Specified fileId is not located in background folder.", "FILE_ID_ERROR" )); return false; } return [ 'result' => true ]; } /** * @restMethod im.v2.Call.Background.delete */ public function deleteAction(int $fileId) { $result = \CIMDisk::DeleteBackgroundFile( $this->getCurrentUser()->getId(), $fileId ); if (!$result) { $this->addError(new \Bitrix\Main\Error( "Specified fileId is not located in background folder.", "FILE_ID_ERROR" )); return false; } return [ 'result' => true ]; } } Controller/Import.php 0000644 00000012764 15133253725 0010672 0 ustar 00 <?php namespace Bitrix\Im\V2\Controller; use Bitrix\Im\Chat; use Bitrix\Im\V2\Chat\ChatError; use Bitrix\Im\V2\Import\ImportError; use Bitrix\Im\V2\Import\ImportService; use Bitrix\Main\Engine\Controller; use Bitrix\Main\Engine\CurrentUser; use CFile; use CRestUtil; class Import extends Controller { protected function getDefaultPreFilters() { return array_merge( parent::getDefaultPreFilters(), [ new \Bitrix\Rest\Engine\ActionFilter\Scope('im.import'), new \Bitrix\Main\Engine\ActionFilter\Scope(\Bitrix\Main\Engine\ActionFilter\Scope::REST), new \Bitrix\Rest\Engine\ActionFilter\AuthType(\Bitrix\Rest\Engine\ActionFilter\AuthType::APPLICATION) ] ); } public function createGroupAction(int $ownerId, CurrentUser $user, array $fields = [], string $externalId = ''): ?array { if (!ImportService::isAdmin((int)$user->getId())) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } $isOpen = ($fields['isOpen'] ?? 'N') === 'Y'; $type = $isOpen ? \IM_MESSAGE_OPEN : \IM_MESSAGE_CHAT; $chatParams = [ 'TITLE' => $fields['title'] ?? null, 'DESCRIPTION' => $fields['description'] ?? null, 'TYPE' => $type, 'AVATAR_ID' => $this->saveAvatar($fields['avatar'] ?? null), 'ENTITY_ID' => $externalId, 'AUTHOR_ID' => $ownerId, 'USERS' => false, ]; $initResult = ImportService::create($chatParams); if (!$initResult->isSuccess()) { $this->addErrors($initResult->getErrors()); return null; } return $this->convertKeysToCamelCase($initResult->getResult()); } public function createPrivateAction(array $users, CurrentUser $user, string $externalId = ''): ?array { if (!ImportService::isAdmin((int)$user->getId())) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } if (count($users) !== 2) { $this->addError(new ImportError(ImportError::PRIVATE_CHAT_COUNT_USERS_ERROR)); return null; } $users = array_map('intval', $users); $chatParams = [ 'TYPE' => \IM_MESSAGE_PRIVATE, 'ENTITY_ID' => $externalId, 'ENTITY_DATA_1' => "{$users[0]}|{$users[1]}", 'AUTHOR_ID' => $users[0], 'USERS' => false, ]; $initResult = ImportService::create($chatParams); if (!$initResult->isSuccess()) { $this->addErrors($initResult->getErrors()); return null; } return $this->convertKeysToCamelCase($initResult->getResult()); } public function getFolderIdAction(int $chatId, CurrentUser $user): ?array { $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']); if (!$chat) { $this->addError(new ChatError(ChatError::NOT_FOUND)); return null; } if (!(new ImportService($chat, (int)$user->getId()))->hasAccess()) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } $folderId = \CIMDisk::GetFolderModel($chatId)->getId(); \CIMDisk::ChangeFolderMembers($chatId, (int)$user->getId()); return ['chatFolderId' => $folderId]; } public function abortAction(int $chatId, CurrentUser $user): ?array { $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']); if (!$chat) { $this->addError(new ChatError(ChatError::NOT_FOUND)); return null; } $importService = new ImportService($chat, (int)$user->getId()); if (!$importService->hasAccess()) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } $abortResult = $importService->abort(); if (!$abortResult->isSuccess()) { $this->addErrors($abortResult->getErrors()); return null; } return [ 'success' => true ]; } public function commitGroupAction(int $chatId, array $users, CurrentUser $user, \CRestServer $server): ?array { $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']); if (!$chat) { $this->addError(new ChatError(ChatError::NOT_FOUND)); return null; } $importService = new ImportService($chat, (int)$user->getId()); if (!$importService->hasAccess()) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } $finalizeResult = $importService->commitGroup($users, $server->getClientId()); if (!$finalizeResult->isSuccess()) { $this->addErrors($finalizeResult->getErrors()); return null; } return [ 'success' => true ]; } public function commitPrivateAction(int $chatId, string $newIsMain, CurrentUser $user, \CRestServer $server, string $hideOriginal = 'Y'): ?array { $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']); if (!$chat) { $this->addError(new ChatError(ChatError::NOT_FOUND)); return null; } $importService = new ImportService($chat, (int)$user->getId()); if (!$importService->hasAccess()) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } $finalizeResult = $importService->commitPrivate($newIsMain === 'Y', $hideOriginal === 'Y', $server->getClientId()); if (!$finalizeResult->isSuccess()) { $this->addErrors($finalizeResult->getErrors()); return null; } return [ 'success' => true ]; } private function saveAvatar(?string $fileContent): ?int { if (!isset($fileContent) || !$fileContent) { return null; } $file = CRestUtil::saveFile($fileContent); $imageCheck = (new \Bitrix\Main\File\Image($file["tmp_name"]))->getInfo(); if( !$imageCheck || !$imageCheck->getWidth() || $imageCheck->getWidth() > 5000 || !$imageCheck->getHeight() || $imageCheck->getHeight() > 5000 ) { return null; } if (!$file || !str_starts_with($file['type'], "image/")) { return null; } return CFile::saveFile($file, 'im'); } } Controller/Import/Message.php 0000644 00000003741 15133253725 0012251 0 ustar 00 <?php namespace Bitrix\Im\V2\Controller\Import; use Bitrix\Im\Chat; use Bitrix\Im\V2\Chat\ChatError; use Bitrix\Im\V2\Import\ImportError; use Bitrix\Im\V2\Import\ImportService; use Bitrix\Main\Engine\Controller; use Bitrix\Main\Engine\CurrentUser; class Message extends Controller { protected function getDefaultPreFilters() { return array_merge( parent::getDefaultPreFilters(), [ new \Bitrix\Rest\Engine\ActionFilter\Scope('im.import'), new \Bitrix\Main\Engine\ActionFilter\Scope(\Bitrix\Main\Engine\ActionFilter\Scope::REST), new \Bitrix\Rest\Engine\ActionFilter\AuthType(\Bitrix\Rest\Engine\ActionFilter\AuthType::APPLICATION) ] ); } public function addAction(int $chatId, array $messages, CurrentUser $user): ?array { $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']); if (!$chat) { $this->addError(new ChatError(ChatError::NOT_FOUND)); return null; } $importService = new ImportService($chat, (int)$user->getId()); if (!$importService->hasAccess()) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } $addResult = $importService->addMessages($messages); if (!$addResult->isSuccess()) { $this->addErrors($addResult->getErrors()); return null; } return $this->convertKeysToCamelCase($addResult->getResult()); } public function updateAction(array $messages, int $chatId, CurrentUser $user): ?array { $chat = Chat::getById($chatId, ['CHECK_ACCESS' => 'N']); if (!$chat) { $this->addError(new ChatError(ChatError::NOT_FOUND)); return null; } $importService = new ImportService($chat, (int)$user->getId()); if (!$importService->hasAccess()) { $this->addError(new ImportError(ImportError::ACCESS_ERROR)); return null; } $updateResult = $importService->updateMessages($messages); if (!$updateResult->isSuccess()) { $this->addErrors($updateResult->getErrors()); return null; } return $this->convertKeysToCamelCase($updateResult->getResult()); } } Message/MessageError.php 0000644 00000002300 15133253725 0011240 0 ustar 00 <?php namespace Bitrix\Im\V2\Message; use Bitrix\Im\V2\Error; use Bitrix\Main\Localization\Loc; class MessageError extends Error { public const WRONG_PARAMETER = 'WRONG_PARAMETER', WRONG_SENDER = 'WRONG_SENDER', EMPTY_MESSAGE = 'EMPTY_MESSAGE', NOTIFY_MODULE = 'NOTIFY_MODULE', NOTIFY_EVENT = 'NOTIFY_EVENT', NOTIFY_TYPE = 'NOTIFY_TYPE', NOTIFY_BUTTONS = 'NOTIFY_BUTTONS', MESSAGE_NOT_FOUND = 'MESSAGE_NOT_FOUND', MESSAGE_DUPLICATED_BY_UUID = 'MESSAGE_DUPLICATED_BY_UUID', MESSAGE_IS_ALREADY_FAVORITE = 'MESSAGE_IS_ALREADY_FAVORITE', MESSAGE_IS_ALREADY_PIN = 'MESSAGE_IS_ALREADY_PIN', MESSAGE_IS_ALREADY_IN_REMINDERS = 'MESSAGE_IS_ALREADY_IN_REMINDERS', MESSAGE_ACCESS_ERROR = 'MESSAGE_ACCESS_ERROR', DIFFERENT_CHAT_ERROR = 'MESSAGES_IN_DIFFERENT_CHAT_ERROR', TOO_MANY_MESSAGES = 'TOO_MANY_MESSAGES', SENDING_FAILED = 'SENDING_FAILED', MARK_FAILED = 'MESSAGE_MARK_FAILED' ; protected function loadErrorMessage($code, $replacements): string { return Loc::getMessage("ERROR_MESSAGE_{$code}", $replacements) ?: ''; } protected function loadErrorDescription($code, $replacements): string { return Loc::getMessage("ERROR_MESSAGE_{$code}_DESC", $replacements) ?: ''; } } Error.php 0000644 00000003165 15133253725 0006361 0 ustar 00 <?php namespace Bitrix\Im\V2; use Bitrix\Main\Localization\Loc; class Error extends \Bitrix\Main\Error { public const NOT_FOUND = 'NOT_FOUND'; protected string $description = ''; public function __construct(string $code, ...$args) { $message = null; $description = null; $customData = []; if (!empty($args)) { $message = isset($args[0]) && is_string($args[0]) ? $args[0] : null; $description = isset($args[1]) && is_string($args[1]) ? $args[1] : null; $inx = count($args) - 1; $customData = isset($args[$inx]) && is_array($args[$inx]) ? $args[$inx] : []; } $replacements = []; foreach ($customData as $key => $value) { $replacements["#{$key}#"] = $value; } if (!is_string($message)) { $message = $this->loadErrorMessage($code, $replacements); } if (is_string($message) && mb_strlen($message) > 0 && !is_string($description)) { $description = $this->loadErrorDescription($code, $replacements); } if (!is_string($message) || mb_strlen($message) === 0) { $message = $code; } parent::__construct($message, $code, $customData); if (is_string($description)) { $this->setDescription($description); } } public function getDescription(): string { return $this->description; } public function setDescription(string $description): void { $this->description = $description; } protected function loadErrorMessage($code, $replacements): string { return Loc::getMessage("ERROR_{$code}", $replacements) ?? ''; } protected function loadErrorDescription($code, $replacements): string { return Loc::getMessage("ERROR_{$code}_DESC", $replacements) ?? ''; } } Chat/ChatError.php 0000644 00000001460 15133253725 0010034 0 ustar 00 <?php namespace Bitrix\Im\V2\Chat; use Bitrix\Im\V2\Error; use Bitrix\Main\Localization\Loc; class ChatError extends Error { public const WRONG_TYPE = 'WRONG_MESSAGE_TYPE', WRONG_PARAMETER = 'WRONG_PARAMETER', WRONG_SENDER = 'WRONG_SENDER', WRONG_RECIPIENT = 'WRONG_RECIPIENT', WRONG_TARGET_CHAT = 'WRONG_TARGET_CHAT', WRONG_COLOR = 'WRONG_COLOR', ACCESS_DENIED = 'ACCESS_DENIED', NOT_FOUND = 'CHAT_NOT_FOUND', BEFORE_SEND_EVENT = 'EVENT_MESSAGE_SEND', CREATION_ERROR = 'CHAT_CREATION_ERROR' ; protected function loadErrorMessage($code, $replacements): string { return Loc::getMessage("ERROR_CHAT_{$code}", $replacements) ?: ''; } protected function loadErrorDescription($code, $replacements): string { return Loc::getMessage("ERROR_CHAT_{$code}_DESC", $replacements) ?: ''; } } Import/ImportError.php 0000644 00000001642 15133253725 0011024 0 ustar 00 <?php $MESS["ERROR_IMPORT_IMPORT_ACCESS_ERROR"] = "You do not have access to message import to this chat"; $MESS["ERROR_IMPORT_IMPORT_ADD_MESSAGE_ERROR"] = "Error adding imported message"; $MESS["ERROR_IMPORT_IMPORT_CHRONOLOGY_ERROR"] = "Chronological error: each subsequent message date must be later or equal to the date of previous message"; $MESS["ERROR_IMPORT_IMPORT_DATETIME_ERROR"] = "Invalid date format."; $MESS["ERROR_IMPORT_IMPORT_DATETIME_FORMAT_ERROR_FIRST"] = "Incorrect date format for the first imported message. The import procedure has been cancelled."; $MESS["ERROR_IMPORT_IMPORT_FILE_ACCESS_ERROR"] = "File does not belong to imported chat"; $MESS["ERROR_IMPORT_IMPORT_FILE_NOT_FOUND"] = "File not found."; $MESS["ERROR_IMPORT_IMPORT_PRIVATE_CHAT_COUNT_USERS_ERROR"] = "Person-to-person chat can have only 2 participants"; $MESS["ERROR_IMPORT_IMPORT_UPDATE_MESSAGE_ERROR"] = "Error updating imported message"; Import/ImportSendingService.php 0000644 00000000114 15133253725 0012634 0 ustar 00 <?php $MESS["IM_IMPORT_BROKEN_MESSAGE"] = "Error while importing message."; Import/ImportService.php 0000644 00000000553 15133253725 0011333 0 ustar 00 <?php $MESS["IM_IMPORT_FINISH_MESSAGE"] = "This chat was created based on imported history using \"#APP_NAME#\""; $MESS["IM_IMPORT_GROUP_FROM_ORIGINAL_PRIVATE_CHAT_TITLE"] = "\"#USER_NAME_1# - #USER_NAME_2#\", archived person-to-person chat"; $MESS["IM_IMPORT_GROUP_FROM_PRIVATE_CHAT_TITLE"] = "\"#USER_NAME_1# - #USER_NAME_2#\", imported person-to-person chat";
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.27 |
proxy
|
phpinfo
|
Settings