protected function processActionDefault() { $this->arResult = array('FILES' => $this->loadFilesData(), 'UID' => $this->getComponentId()); $driver = \Bitrix\Disk\Driver::getInstance(); $this->arResult['CLOUD_DOCUMENT'] = array(); static $documentHandlerName = null; static $documentHandlerCode = null; static $isLocal = null; if ($documentHandlerName === null) { if (Configuration::canCreateFileByCloud()) { $documentServiceCode = \Bitrix\Disk\UserConfiguration::getDocumentServiceCode(); if (!$documentServiceCode) { $documentServiceCode = 'l'; } if (LocalDocumentController::isLocalService($documentServiceCode)) { $documentHandlerName = LocalDocumentController::getName(); $documentHandlerCode = LocalDocumentController::getCode(); $isLocal = true; } else { $defaultDocumentHandler = \Bitrix\Disk\Driver::getInstance()->getDocumentHandlersManager()->getDefaultServiceForCurrentUser(); if ($defaultDocumentHandler) { $documentHandlerName = $defaultDocumentHandler->getName(); $documentHandlerCode = $defaultDocumentHandler->getCode(); $isLocal = false; } } } } if ($documentHandlerCode) { $this->arResult['CLOUD_DOCUMENT'] = array('DEFAULT_SERVICE' => $documentHandlerCode, 'DEFAULT_SERVICE_LABEL' => $documentHandlerName, 'IS_LOCAL' => $isLocal); $this->arResult['DEFAULT_DOCUMENT_SERVICE_EDIT_NAME'] = $documentHandlerName; $this->arResult['DEFAULT_DOCUMENT_SERVICE_EDIT_CODE'] = $documentHandlerCode; } else { $documentHandlerCode = 'l'; } if ($this->editMode) { $this->arResult['controlName'] = $this->arParams['PARAMS']['arUserField']['FIELD_NAME']; $this->arResult['SHARE_EDIT_ON_OBJECT_UF'] = Configuration::isEnabledDefaultEditInUf(); $urlManager = $driver->getUrlManager(); $this->arResult['CREATE_BLANK_URL'] = $urlManager->getUrlToStartCreateUfFileByService('docx', $documentHandlerCode); $this->arResult['RENAME_FILE_URL'] = $urlManager->getUrlDocumentController('rename', array('document_action' => 'rename')); $this->arResult['UPLOAD_FILE_URL'] = $urlManager->getUrlToUploadUfFile(); //now we show checkbox only if it's create post, etc. $this->arResult['DISK_ATTACHED_OBJECT_ALLOW_EDIT'] = empty($this->arResult['FILES']); $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager(); $this->arResult['INPUT_NAME_OBJECT_ALLOW_EDIT'] = $userFieldManager->getInputNameForAllowEditByEntityType($this->arParams['PARAMS']['arUserField']['ENTITY_ID']); } foreach (GetModuleEvents("main", $this->arParams['PARAMS']['arUserField']["USER_TYPE_ID"], true) as $arEvent) { if (!ExecuteModuleEventEx($arEvent, array($this->arResult, $this->arParams))) { return; } } if (is_array($this->arParams['PARAMS'])) { $this->arParams = array_merge($this->arParams, $this->arParams['PARAMS']); } $this->includeComponentTemplate($this->editMode ? 'edit' : 'show' . ($this->arParams['INLINE'] == 'Y' ? '_inline' : '')); }
/** * For UF and work with local editors we have special scenario: * If user don't have permission for update file, * we have to attach new file to entity by posting comment with * alternative version. */ protected function processActionCommit() { $userId = $this->getUser()->getId(); if ($this->attachedModel->canUpdate($userId)) { parent::processActionCommit(); return; } $this->checkRequiredFilesParams(array('file')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $userStorage = Driver::getInstance()->getStorageByUserId($userId); if (!$userStorage) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_STORAGE'), self::ERROR_COULD_NOT_FIND_STORAGE))); $this->sendJsonErrorResponse(); } $folder = $userStorage->getFolderForCreatedFiles(); if (!$folder) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES'), self::ERROR_COULD_NOT_FIND_FOLDER_FOR_CREATED_FILES))); $this->sendJsonErrorResponse(); } if (!$folder->canAdd($folder->getStorage()->getCurrentUserSecurityContext())) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_BAD_RIGHTS'), self::ERROR_BAD_RIGHTS))); $this->sendJsonErrorResponse(); } //todo fix Cherezov. Ban encoding 1251 $fileArray = $this->request->getFile('file'); $fileArray['name'] = $this->file->getName(); $newFile = $folder->uploadFile($fileArray, array('NAME' => $this->file->getName(), 'CREATED_BY' => $userId), array(), true); if (!$newFile) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_CREATE_FILE'), self::ERROR_COULD_NOT_CREATE_FILE))); $this->errorCollection->add($folder->getErrors()); $this->sendJsonErrorResponse(); } $valueFileUf = FileUserType::NEW_FILE_PREFIX . $newFile->getId(); /** @var User $createUser */ $createUser = User::loadById($userId); if (!$createUser) { $this->sendJsonErrorResponse(); } $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_M'); if ($createUser->getPersonalGender() == 'F') { $text = Loc::getMessage('DISK_UF_LOCAL_DOC_CONTROLLER_UPLOAD_NEW_VERSION_IN_COMMENT_F'); } if ($this->attachedModel->getAllowAutoComment()) { $this->attachedModel->getConnector()->addComment($userId, array('text' => $text, 'fileId' => $valueFileUf)); } $this->sendJsonSuccessResponse(); }
?> <script type="application/javascript"> BX.message({ <?php if (!empty($arResult['CLOUD_DOCUMENT'])) { ?> wd_service_edit_doc_default: '<?php echo CUtil::JSEscape($arResult['CLOUD_DOCUMENT']['DEFAULT_SERVICE']); ?> ', <?php } ?> DISK_FOLDER_TOOLBAR_LABEL_LOCAL_BDISK_EDIT: '<?php echo CUtil::JSEscape(\Bitrix\Disk\Document\LocalDocumentController::getName()); ?> ', DISK_FOLDER_TOOLBAR_LABEL_NAME_CREATE_FOLDER: '<?php echo GetMessageJS("DISK_FOLDER_TOOLBAR_LABEL_NAME_CREATE_FOLDER"); ?> ', DISK_FOLDER_TOOLBAR_LABEL_NAME_RIGHTS_USER: '******', DISK_FOLDER_TOOLBAR_LABEL_NAME_ADD_RIGHTS_USER: '******', DISK_FOLDER_TOOLBAR_LABEL_NAME_ALLOW_SHARING_RIGHTS_USER: '<?php
protected function processActionDefault() { $driver = \Bitrix\Disk\Driver::getInstance(); $this->arResult['BUTTONS'] = array(); $securityContext = $this->storage->getCurrentUserSecurityContext(); /** @var Folder $folder */ $folder = $this->getFolder(); if (!$folder) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_FOLDER_TOOLBAR_ERROR_COULD_NOT_FIND_OBJECT'), self::ERROR_COULD_NOT_FIND_OBJECT))); $this->includeComponentTemplate(); } $this->arResult['CLOUD_DOCUMENT'] = array(); if ($this->isFolderList() && $folder->canAdd($securityContext)) { $this->arResult['BUTTONS'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_UPLOAD_FILE_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_UPLOAD_FILE_TITLE'), 'LINK' => "javascript:void(0);", 'ICON' => 'element-upload'); if (\Bitrix\Disk\Configuration::canCreateFileByCloud()) { $documentHandlerName = $documentHandlerCode = null; $documentServiceCode = \Bitrix\Disk\UserConfiguration::getDocumentServiceCode(); if (!$documentServiceCode) { $documentServiceCode = 'l'; } if (LocalDocumentController::isLocalService($documentServiceCode)) { $documentHandlerName = LocalDocumentController::getName(); $documentHandlerCode = LocalDocumentController::getCode(); } else { $defaultDocumentHandler = \Bitrix\Disk\Driver::getInstance()->getDocumentHandlersManager()->getDefaultServiceForCurrentUser(); if ($defaultDocumentHandler) { $documentHandlerName = $defaultDocumentHandler->getName(); $documentHandlerCode = $defaultDocumentHandler->getCode(); } } if ($documentHandlerCode) { $urlManager = $driver->getUrlManager(); $this->arResult['CLOUD_DOCUMENT'] = array('DEFAULT_SERVICE' => $documentHandlerCode, 'DEFAULT_SERVICE_LABEL' => $documentHandlerName, 'CREATE_BLANK_FILE_URL' => $urlManager->getUrlToStartCreateUfFileByService('docx', $documentHandlerCode), 'RENAME_BLANK_FILE_URL' => $urlManager->getUrlDocumentController('rename', array('document_action' => 'rename'))); $this->arResult['BUTTONS'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_CREATE_DOC_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_CREATE_DOC_TITLE'), 'LINK' => "javascript:BX.Disk['FolderToolbarClass_{$this->getComponentId()}'].createFile();", 'ICON' => 'docs-add'); } } $this->arResult['BUTTONS'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_CREATE_FOLDER_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_CREATE_FOLDER_TITLE'), 'LINK' => $this->extendedAddFolder ? "javascript:BX.Disk['FolderToolbarClass_{$this->getComponentId()}'].createExtendedFolder();" : "javascript:BX.Disk['FolderToolbarClass_{$this->getComponentId()}'].createFolder();", 'ICON' => 'folder-add'); } if ($this->isTrashCan() && $folder->canRestore($securityContext)) { if (!empty($this->arParams['URL_TO_EMPTY_TRASHCAN'])) { $this->arResult['BUTTONS'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EMPTY_TRASHCAN_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EMPTY_TRASHCAN_TITLE'), 'LINK' => "javascript:BX.Disk['FolderToolbarClass_{$this->getComponentId()}'].emptyTrashCan();", 'ICON' => 'empty-trashcan'); } } $this->arResult['DROPDOWN_FILTER'] = array(); if (!empty($this->arParams['URL_TO_FOLDER_LIST'])) { $this->arResult['DROPDOWN_FILTER'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_FOLDER_LIST_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_FOLDER_LIST_TITLE'), 'HREF' => $this->arParams['URL_TO_FOLDER_LIST']); if ($this->isFolderList()) { $this->arResult['DROPDOWN_FILTER_CURRENT_LABEL'] = Loc::getMessage('DISK_FOLDER_TOOLBAR_FOLDER_LIST_TEXT'); if ($this->arParams['RELATIVE_PATH'] && $folder->getId() != $this->storage->getRootObjectId()) { $relativePath = explode('/', trim($this->arParams['RELATIVE_PATH'], '/')); array_pop($relativePath); if ($relativePath) { $prevPageListing = rtrim(CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_FOLDER_LIST'], array('PATH' => implode('/', $relativePath))), '/'); } else { $prevPageListing = $this->arParams['URL_TO_FOLDER_LIST']; } array_unshift($this->arResult['BUTTONS'], array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_GO_BACK_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_GO_BACK_TITLE'), 'LINK' => $prevPageListing, 'ICON' => 'back')); } } } if (!empty($this->arParams['PATH_TO_EXTERNAL_LINK_LIST'])) { $this->arResult['DROPDOWN_FILTER'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_TEXT_2'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_TITLE'), 'HREF' => $this->arParams['PATH_TO_EXTERNAL_LINK_LIST']); if ($this->isExternalLinkList()) { $this->arResult['DROPDOWN_FILTER_CURRENT_LABEL'] = Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_TEXT_2'); $this->arResult['BUTTONS'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_GO_BACK_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_GO_BACK_TITLE'), 'LINK' => $this->arParams['URL_TO_FOLDER_LIST'], 'ICON' => 'back'); } } if (!empty($this->arParams['URL_TO_TRASHCAN_LIST'])) { $this->arResult['DROPDOWN_FILTER'][] = array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_TRASHCAN_TEXT_2'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_TRASHCAN_TITLE'), 'HREF' => $this->arParams['URL_TO_TRASHCAN_LIST']); if ($this->isTrashCan()) { $this->arResult['DROPDOWN_FILTER_CURRENT_LABEL'] = Loc::getMessage('DISK_FOLDER_TOOLBAR_TRASHCAN_TEXT'); array_unshift($this->arResult['BUTTONS'], array('TEXT' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_GO_BACK_TEXT'), 'TITLE' => Loc::getMessage('DISK_FOLDER_TOOLBAR_EXTERNAL_LINK_LIST_GO_BACK_TITLE'), 'LINK' => $this->arParams['URL_TO_FOLDER_LIST'], 'ICON' => 'back')); } } $this->includeComponentTemplate(); }
<?php use Bitrix\Disk\Document\DocumentController; use Bitrix\Disk\Document\LocalDocumentController; define("STOP_STATISTICS", true); define("PUBLIC_AJAX_MODE", true); define("NO_KEEP_STATISTIC", "Y"); define("NO_AGENT_STATISTIC", "Y"); define("DisableEventsCheck", true); require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; if (!\Bitrix\Main\Loader::includeModule('disk')) { die; } if (empty($_GET['document_action']) || empty($_GET['service'])) { die; } if (LocalDocumentController::isLocalService($_GET['service'])) { $docController = new LocalDocumentController(); $docController->setActionName(empty($_GET['primaryAction']) ? $_GET['document_action'] : $_GET['primaryAction'])->exec(); } else { $docController = new DocumentController(); $docController->setActionName($_GET['document_action'])->setDocumentHandlerName($_GET['service'])->exec(); }