コード例 #1
0
ファイル: class.php プロジェクト: mrdeadmouse/u136006
 private function loadData()
 {
     if (empty($this->arParams['PARAMS']['arUserField'])) {
         return array();
     }
     $userId = $this->getUser()->getId();
     $values = $this->arParams['PARAMS']['arUserField']['VALUE'];
     if (!is_array($this->arParams['PARAMS']['arUserField']['VALUE'])) {
         $values = array($values);
     }
     $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
     $versions = array();
     foreach ($values as $value) {
         $attachedObjectId = (int) $value;
         if ($attachedObjectId <= 0) {
             continue;
         }
         /** @var \Bitrix\Disk\AttachedObject $attachedModel */
         $attachedModel = \Bitrix\Disk\AttachedObject::loadById($attachedObjectId, array('VERSION.OBJECT'));
         if (!$attachedModel) {
             continue;
         }
         $version = $attachedModel->getVersion();
         if (!$version) {
             continue;
         }
         $extension = $version->getExtension();
         $versions[] = array('ID' => $attachedModel->getId(), 'NAME' => $version->getName(), 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($extension), 'EDITABLE' => DocumentHandler::isEditable($extension), 'CAN_UPDATE' => $attachedModel->canUpdate($userId), 'FROM_EXTERNAL_SYSTEM' => $version->getObject()->getContentProvider() && $version->getObject()->getCreatedBy() == $userId, 'EXTENSION' => $extension, 'SIZE' => \CFile::formatSize($version->getSize()), 'HISTORY_URL' => $urlManager->getUrlUfController('history', array('attachedId' => $attachedModel->getId())), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $attachedModel->getId())), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyTome', array('attachedId' => $attachedModel->getId())), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($attachedModel->getId(), 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($attachedModel->getId(), 'gdrive'), 'GLOBAL_CONTENT_VERSION' => $version->getGlobalContentVersion(), 'ATTRIBUTES_FOR_VIEWER' => Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('version' => $version->getGlobalContentVersion(), 'canUpdate' => $attachedModel->canUpdate($userId), 'showStorage' => false, 'externalId' => false, 'relativePath' => false)));
     }
     unset($value);
     return $versions;
 }
コード例 #2
0
 protected function processActionCommit()
 {
     $this->checkRequiredPostParams(array('editSessionId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $this->checkUpdatePermissions();
     $currentSession = $this->getEditSessionByCurrentUser((int) $this->request->getPost('editSessionId'));
     if (!$currentSession) {
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_FIND_EDIT_SESSION'), self::ERROR_COULD_NOT_FIND_EDIT_SESSION)));
         $this->sendJsonErrorResponse();
     }
     $tmpFile = \CTempFile::getFileName(uniqid('_wd'));
     checkDirPath($tmpFile);
     $fileData = new FileData();
     $fileData->setId($currentSession->getServiceFileId());
     $fileData->setSrc($tmpFile);
     $newNameFileAfterConvert = null;
     if ($this->documentHandler->isNeedConvertExtension($this->file->getExtension())) {
         $newNameFileAfterConvert = getFileNameWithoutExtension($this->file->getName()) . '.' . $this->documentHandler->getConvertExtension($this->file->getExtension());
         $fileData->setMimeType(TypeFile::getMimeTypeByFilename($newNameFileAfterConvert));
     } else {
         $fileData->setMimeType(TypeFile::getMimeTypeByFilename($this->file->getName()));
     }
     $fileData = $this->documentHandler->downloadFile($fileData);
     if (!$fileData) {
         if ($this->documentHandler->isRequiredAuthorization()) {
             $this->sendNeedAuth();
         }
         $this->errorCollection->add($this->documentHandler->getErrors());
         $this->sendJsonErrorResponse();
     }
     $this->deleteEditSession($currentSession);
     $oldName = $this->file->getName();
     //rename in cloud service
     $renameInCloud = $fileData->getName() && $fileData->getName() != $this->file->getName();
     if ($newNameFileAfterConvert || $renameInCloud) {
         if ($newNameFileAfterConvert && $renameInCloud) {
             $newNameFileAfterConvert = getFileNameWithoutExtension($fileData->getName()) . '.' . getFileExtension($newNameFileAfterConvert);
         }
         $this->file->rename($newNameFileAfterConvert);
     }
     $fileArray = \CFile::makeFileArray($tmpFile);
     $fileArray['name'] = $this->file->getName();
     $fileArray['type'] = $fileData->getMimeType();
     $fileArray['MODULE_ID'] = Driver::INTERNAL_MODULE_ID;
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $fileId = \CFile::saveFile($fileArray, Driver::INTERNAL_MODULE_ID);
     if (!$fileId) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_SAVE_FILE'), self::ERROR_COULD_NOT_SAVE_FILE)));
         $this->sendJsonErrorResponse();
     }
     $versionModel = $this->file->addVersion(array('ID' => $fileId, 'FILE_SIZE' => $fileArray['size']), $this->getUser()->getId(), true);
     if (!$versionModel) {
         \CFile::delete($fileId);
         $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOC_CONTROLLER_ERROR_COULD_NOT_ADD_VERSION'), self::ERROR_COULD_NOT_ADD_VERSION)));
         $this->errorCollection->add($this->file->getErrors());
         $this->sendJsonErrorResponse();
     }
     if ($this->isLastEditSessionForFile()) {
         $this->deleteFile($currentSession, $fileData);
     }
     $this->sendJsonSuccessResponse(array('objectId' => $this->file->getId(), 'newName' => $this->file->getName(), 'oldName' => $oldName));
 }
コード例 #3
0
ファイル: class.php プロジェクト: mrdeadmouse/u136006
 private function loadFilesData()
 {
     if (empty($this->arParams['PARAMS']['arUserField'])) {
         return array();
     }
     $userId = $this->getUser()->getId();
     $values = $this->arParams['PARAMS']['arUserField']['VALUE'];
     if (!is_array($this->arParams['PARAMS']['arUserField']['VALUE'])) {
         $values = array($values);
     }
     $files = array();
     $driver = \Bitrix\Disk\Driver::getInstance();
     $urlManager = $driver->getUrlManager();
     $userFieldManager = $driver->getUserFieldManager();
     $userFieldManager->loadBatchAttachedObject($values);
     foreach ($values as $id) {
         $attachedModel = null;
         list($type, $realValue) = FileUserType::detectType($id);
         if ($realValue <= 0) {
             continue;
         } elseif ($type == FileUserType::TYPE_NEW_OBJECT) {
             /** @var File $fileModel */
             $fileModel = File::loadById($realValue);
             if (!$fileModel || !$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) {
                 continue;
             }
         } else {
             /** @var \Bitrix\Disk\AttachedObject $attachedModel */
             $attachedModel = $userFieldManager->getAttachedObjectById($realValue);
             if (!$attachedModel) {
                 continue;
             }
             if (!$this->editMode) {
                 $attachedModel->setOperableEntity(array('ENTITY_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_ID'], 'ENTITY_VALUE_ID' => $this->arParams['PARAMS']['arUserField']['ENTITY_VALUE_ID']));
             }
             /** @var File $fileModel */
             $fileModel = $attachedModel->getFile();
         }
         $name = $fileModel->getName();
         $data = array('ID' => $id, 'NAME' => $name, 'CONVERT_EXTENSION' => DocumentHandler::isNeedConvertExtension($fileModel->getExtension()), 'EDITABLE' => DocumentHandler::isEditable($fileModel->getExtension()), 'CAN_UPDATE' => $attachedModel ? $attachedModel->canUpdate($userId) : $fileModel->canUpdate($fileModel->getStorage()->getCurrentUserSecurityContext()), 'FROM_EXTERNAL_SYSTEM' => $fileModel->getContentProvider() && $fileModel->getCreatedBy() == $userId, 'EXTENSION' => $fileModel->getExtension(), 'SIZE' => \CFile::formatSize($fileModel->getSize()), 'XML_ID' => $fileModel->getXmlId(), 'FILE_ID' => $fileModel->getId(), 'VIEW_URL' => $urlManager->getUrlToShowAttachedFileByService($id, 'gvdrive'), 'EDIT_URL' => $urlManager->getUrlToStartEditUfFileByService($id, 'gdrive'), 'DOWNLOAD_URL' => $urlManager->getUrlUfController('download', array('attachedId' => $id)), 'COPY_TO_ME_URL' => $urlManager->getUrlUfController('copyToMe', array('attachedId' => $id)), 'DELETE_URL' => "");
         if (\Bitrix\Disk\TypeFile::isImage($fileModel)) {
             $this->arParams['PARAMS']['THUMB_SIZE'] = $this->arParams['PARAMS']['THUMB_SIZE'] > 0 ? $this->arParams['PARAMS']['THUMB_SIZE'] : 100;
             $data["PREVIEW_URL"] = $attachedModel === null ? $urlManager->getUrlForShowFile($fileModel) : $urlManager->getUrlUfController('show', array('attachedId' => $id));
             $data["IMAGE"] = $fileModel->getFile();
         }
         if ($this->editMode) {
             $data['STORAGE'] = $fileModel->getStorage()->getProxyType()->getTitleForCurrentUser() . ' / ' . $fileModel->getParent()->getName();
         } else {
             $data['ATTRIBUTES_FOR_VIEWER'] = Ui\Viewer::getAttributesByAttachedObject($attachedModel, array('canUpdate' => $data['CAN_UPDATE'], 'canFakeUpdate' => true, 'showStorage' => false, 'externalId' => false, 'relativePath' => false));
         }
         $files[] = $data;
     }
     unset($id);
     return $files;
 }
コード例 #4
0
ファイル: viewer.php プロジェクト: DarneoStudio/bitrix
 /**
  * Gets data attributes by attached object to viewer.
  * @param AttachedObject $attachedObject Target attached object.
  * @param array          $additionalParams Additional parameters 'relativePath', 'externalId', 'canUpdate', 'canFakeUpdate', 'showStorage', 'version'.
  * @return string
  */
 public static function getAttributesByAttachedObject(AttachedObject $attachedObject, array $additionalParams = array())
 {
     $urlManager = Driver::getInstance()->getUrlManager();
     $version = $object = null;
     if ($attachedObject->isSpecificVersion()) {
         $version = $attachedObject->getVersion();
         if (!$version) {
             return '';
         }
         $name = $version->getName();
         $extension = $version->getExtension();
         $size = $version->getSize();
         $updateTime = $version->getCreateTime();
     } else {
         $object = $attachedObject->getObject();
         if (!$object) {
             return '';
         }
         $name = $object->getName();
         $extension = $object->getExtension();
         $size = $object->getSize();
         $updateTime = $object->getUpdateTime();
     }
     if (DocumentHandler::isEditable($extension)) {
         $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowAttachedFileByService($attachedObject->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="' . (DocumentHandler::isNeedConvertExtension($extension) ? '1' : '') . '" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($size)) . '" ';
     } elseif (Viewer::isViewable($extension)) {
         $dataAttributesForViewer = 'data-bx-viewer="iframe" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlToShowAttachedFileByService($attachedObject->getId(), 'gvdrive') . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-askConvert="0" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($size)) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($updateTime) . '" ';
     } elseif (TypeFile::isImage($name)) {
         $dataAttributesForViewer = 'data-bx-viewer="image" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-src="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ';
     } else {
         $user = $version ? $version->getCreateUser() : $object->getCreateUser();
         $formattedName = $user ? $user->getFormattedName() : '';
         $dataAttributesForViewer = 'data-bx-viewer="unknown" ' . 'data-bx-src="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-isFromUserLib="" ' . 'data-bx-download="' . $urlManager->getUrlUfController('download', array('attachedId' => $attachedObject->getId())) . '" ' . 'data-bx-title="' . htmlspecialcharsbx($name) . '" ' . 'data-bx-owner="' . htmlspecialcharsbx($formattedName) . '" ' . 'data-bx-dateModify="' . htmlspecialcharsbx($updateTime) . '" ' . 'data-bx-size="' . htmlspecialcharsbx(CFile::formatSize($size)) . '" ';
     }
     $dataAttributesForViewer .= " data-bx-history=\"\"" . " data-bx-historyPage=\"\"";
     if ($object) {
         $dataAttributesForViewer .= " bx-attach-file-id=\"{$object->getId()}\"";
     }
     if (!empty($additionalParams['relativePath'])) {
         $dataAttributesForViewer .= ' data-bx-relativePath="' . htmlspecialcharsbx($additionalParams['relativePath'] . '/' . $name) . '" ';
     }
     if (!empty($additionalParams['externalId'])) {
         $dataAttributesForViewer .= ' data-bx-externalId="' . htmlspecialcharsbx($additionalParams['externalId']) . '" ';
     }
     if (!empty($additionalParams['canUpdate'])) {
         $dataAttributesForViewer .= ' data-bx-edit="' . $urlManager->getUrlToStartEditUfFileByService($attachedObject->getId(), 'gdrive') . '" ';
     }
     if (!empty($additionalParams['canFakeUpdate'])) {
         $dataAttributesForViewer .= ' data-bx-fakeEdit="' . $urlManager->getUrlToStartEditUfFileByService($attachedObject->getId(), 'gdrive') . '" ';
     }
     if (!empty($additionalParams['showStorage']) && $object) {
         $dataAttributesForViewer .= ' data-bx-storage="' . htmlspecialcharsbx($object->getParent()->getName()) . '" ';
     }
     if (!empty($additionalParams['version'])) {
         $dataAttributesForViewer .= ' data-bx-version="' . htmlspecialcharsbx($additionalParams['version']) . '" ';
     }
     return $dataAttributesForViewer;
 }