protected function processActionDownloadVersion() { $this->version = $this->file->getVersion($this->versionId); if (!$this->version) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_DOWNLOAD_CONTROLLER_ERROR_COULD_NOT_FIND_VERSION'), self::ERROR_COULD_NOT_FIND_VERSION))); $this->sendJsonErrorResponse(); } $fileData = $this->version->getFile(); \CFile::viewByUser($fileData, array("force_download" => false, 'cache_time' => 0, 'attachment_name' => $this->file->getName())); }
protected function processActionCommit() { $this->checkRequiredFilesParams(array('file')); if ($this->errorCollection->hasErrors()) { $this->sendJsonErrorResponse(); } $this->checkUpdatePermissions(); //todo fix Cherezov. Ban encoding 1251 $fileArray = $this->request->getFile('file'); $fileArray['name'] = $this->file->getName(); $userId = $this->getUser()->getId(); if (!$this->file->uploadVersion($fileArray, $userId)) { $this->errorCollection->add(array(new Error(Loc::getMessage('DISK_LOCAL_DOC_CONTROLLER_ERROR_COULD_NOT_ADD_VERSION'), self::ERROR_COULD_NOT_ADD_VERSION))); $this->sendJsonErrorResponse(); } Driver::getInstance()->sendEvent($userId, 'live', array('objectId' => $this->file->getId(), 'action' => 'commit')); $this->sendJsonSuccessResponse(); }
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)); }
public static function GetPublicPath($type, \Bitrix\Disk\File $fileModel) { if (!in_array($type, array(self::PATH_TYPE_DOWNLOAD, self::PATH_TYPE_SHOW, self::PATH_TYPE_PREVIEW))) { return ''; } if ($fileModel->getGlobalContentVersion() <= 1) { return ''; } $isShow = in_array($type, array(self::PATH_TYPE_SHOW, self::PATH_TYPE_PREVIEW)) && \Bitrix\Disk\TypeFile::isImage($fileModel->getName()); $isPreview = $isShow && in_array($type, array(self::PATH_TYPE_PREVIEW)); if ($type == self::PATH_TYPE_PREVIEW && !$isPreview) { return ''; } $url = array('default' => '/bitrix/components/bitrix/im.messenger/' . ($isShow ? 'show.file.php?' : 'download.file.php?')); $url['desktop'] = '/desktop_app/' . ($isShow ? 'show.file.php?' : 'download.file.php?'); if (IsModuleInstalled('mobile')) { $url['mobile'] = '/mobile/ajax.php?mobile_action=im_files&fileType=' . ($isShow ? 'show&' : 'download&'); } foreach ($url as $key => $value) { $url[$key] = $value . 'fileId=' . $fileModel->getId() . ($isPreview ? '&preview=Y' : '') . ($isShow || $key == 'mobile' ? '&fileName=' . urlencode($fileModel->getName()) : ''); } return $url; }
private function getFileContent(File $file) { static $maxFileSize = null; if (!isset($maxFileSize)) { $maxFileSize = Option::get("search", "max_file_size", 0) * 1024; } $searchData = ''; $searchData .= strip_tags($file->getName()) . "\r\n"; if ($maxFileSize > 0 && $file->getSize() > $maxFileSize) { return ''; } $searchDataFile = array(); $fileArray = CFile::makeFileArray($file->getFileId()); if ($fileArray && $fileArray['tmp_name']) { $fileAbsPath = \CBXVirtualIo::getInstance()->getLogicalName($fileArray['tmp_name']); foreach (GetModuleEvents('search', 'OnSearchGetFileContent', true) as $event) { if ($searchDataFile = executeModuleEventEx($event, array($fileAbsPath, getFileExtension($fileArray['name'])))) { break; } } return is_array($searchDataFile) ? $searchData . "\r\n" . $searchDataFile['CONTENT'] : $searchData; } return $searchData; }
private function formatFileToResponse(File $file) { if (empty($file) || !$file->getName()) { return array(); } $path = $this->getBreadcrumbs($file); if (!$path) { return array(); } $result = array('id' => $this->generateId(array('FILE' => true, 'ID' => $file->getId())), 'isDirectory' => false, 'isDeleted' => false, 'storageId' => $this->getStringStorageId(), 'path' => '/' . trim($path, '/'), 'name' => (string) $file->getName(), 'revision' => $file->getFileId(), 'version' => (string) $this->generateTimestamp($file->getUpdateTime()->getTimestamp()), 'extra' => array('id' => (string) $file->getId(), 'iblockId' => (string) $file->getStorageId(), 'sectionId' => (string) $file->getParentId(), 'rootSectionId' => (string) $this->storage->getRootObjectId(), 'name' => (string) $file->getName()), 'size' => (string) $file->getSize(), 'permission' => 'W', 'createdBy' => (string) $file->getCreatedBy(), 'modifiedBy' => (string) $file->getUpdatedBy()); if ($this->storage->getRootObjectId() != $file->getParentId()) { $result['parentId'] = $this->generateId(array('FILE' => false, 'ID' => $file->getParentId())); } return $result; }
/** * Gets url to show file. * @param File $file Target file. * @param array $params Parameters to add in query. * @param bool $absolute Generate absolute url with host url. * @return string */ public function getUrlForShowFile(File $file, array $params = array(), $absolute = false) { if (isset($params['width']) && isset($params['height'])) { $params['signature'] = ParameterSigner::getImageSignature($file->getId(), $params['width'], $params['height']); } return $this->getUrlDownloadController('showFile', array_merge($params, array('fileId' => $file->getId(), 'filename' => $file->getName())), $absolute); }
protected function showBizProc($documentData) { $this->arResult['BIZPROC_PERMISSION'] = array(); $this->arResult['BIZPROC_PERMISSION']['START'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::StartWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']); $this->arResult['BIZPROC_PERMISSION']['VIEW'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::ViewWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']); $this->arResult['BIZPROC_PERMISSION']['STOP'] = $this->arResult['BIZPROC_PERMISSION']['START']; $this->arResult['BIZPROC_PERMISSION']['DROP'] = CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::CreateWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID']); foreach ($documentData as $nameModuleId => $data) { $temporary[$nameModuleId] = CBPDocument::getDocumentStates($data['DOCUMENT_TYPE'], $data['DOCUMENT_ID']); } if (isset($temporary['OLD_FILE'])) { $allBizProcArray = array_merge($temporary['DISK'], $temporary['WEBDAV'], $temporary['OLD_FILE']); } else { $allBizProcArray = array_merge($temporary['DISK'], $temporary['WEBDAV']); } if (!empty($allBizProcArray)) { $userGroup = $this->getUser()->getUserGroupArray(); $userGroup[] = 'author'; if ($this->request->isPost() && intval($this->request->getPost('bizproc_index')) > 0) { $bizProcWorkflowId = array(); $bizprocIndex = intval($this->request->getPost('bizproc_index')); for ($i = 1; $i <= $bizprocIndex; $i++) { $bpId = trim($this->request->getPost("bizproc_id_" . $i)); $bpTemplateId = intval($this->request->getPost("bizproc_template_id_" . $i)); $bpEvent = trim($this->request->getPost("bizproc_event_" . $i)); if (strlen($bpId) > 0) { if (!array_key_exists($bpId, $allBizProcArray)) { continue; } } else { if (!array_key_exists($bpTemplateId, $allBizProcArray)) { continue; } $bpId = $bizProcWorkflowId[$bpTemplateId]; } if (strlen($bpEvent) > 0) { $errors = array(); CBPDocument::sendExternalEvent($bpId, $bpEvent, array("Groups" => $userGroup, "User" => $this->getUser()->getId()), $errors); } else { $errors = array(); foreach ($allBizProcArray as $idBizProc => $bizProcArray) { if ($idBizProc == $bpId) { CBPDocument::TerminateWorkflow($bpId, $bizProcArray['DOCUMENT_ID'], $errors); } } } if (!empty($errors)) { foreach ($errors as $error) { $this->arResult['ERROR_MESSAGE'] = $error['message']; } } else { LocalRedirect($this->arResult['PATH_TO_FILE_VIEW'] . "#tab-bp"); } } } $this->arResult['BIZPROC_LIST'] = array(); $count = 1; foreach ($allBizProcArray as $idBizProc => $bizProcArray) { if (intVal($bizProcArray["WORKFLOW_STATUS"]) < 0 || $idBizProc <= 0) { continue; } else { if (!CBPDocument::canUserOperateDocument(CBPCanUserOperateOperation::ViewWorkflow, $this->getUser()->getId(), $documentData['DISK']['DOCUMENT_ID'], array("DocumentStates" => $bizProcArray, "WorkflowId" => $bizProcArray["ID"] > 0 ? $bizProcArray["ID"] : $bizProcArray["TEMPLATE_ID"]))) { continue; } } $groups = CBPDocument::getAllowableUserGroups($documentData['DISK']['DOCUMENT_TYPE']); foreach ($groups as $key => $val) { $groups[strtolower($key)] = $val; } $users = array(); $dmpWorkflow = CBPTrackingService::getList(array("ID" => "DESC"), array("WORKFLOW_ID" => $idBizProc, "TYPE" => array(CBPTrackingType::Report, CBPTrackingType::Custom, CBPTrackingType::FaultActivity)), false, array("nTopCount" => 5), array("ID", "TYPE", "MODIFIED", "ACTION_NOTE", "ACTION_TITLE", "ACTION_NAME", "EXECUTION_STATUS", "EXECUTION_RESULT")); while ($track = $dmpWorkflow->getNext()) { $messageTemplate = ""; switch ($track["TYPE"]) { case 1: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_1"); break; case 2: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_2"); break; case 3: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_3"); break; case 4: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_4"); break; case 5: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_5"); break; default: $messageTemplate = Loc::getMessage("DISK_FILE_VIEW_BPABL_TYPE_6"); } $name = strlen($track["ACTION_TITLE"]) > 0 ? $track["ACTION_TITLE"] : $track["ACTION_NAME"]; switch ($track["EXECUTION_STATUS"]) { case CBPActivityExecutionStatus::Initialized: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_1"); break; case CBPActivityExecutionStatus::Executing: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_2"); break; case CBPActivityExecutionStatus::Canceling: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_3"); break; case CBPActivityExecutionStatus::Closed: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_4"); break; case CBPActivityExecutionStatus::Faulting: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_5"); break; default: $status = Loc::getMessage("DISK_FILE_VIEW_BPABL_STATUS_6"); } switch ($track["EXECUTION_RESULT"]) { case CBPActivityExecutionResult::None: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_1"); break; case CBPActivityExecutionResult::Succeeded: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_2"); break; case CBPActivityExecutionResult::Canceled: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_3"); break; case CBPActivityExecutionResult::Faulted: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_4"); break; case CBPActivityExecutionResult::Uninitialized: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_5"); break; default: $result = Loc::getMessage("DISK_FILE_VIEW_BPABL_RES_6"); } $note = strlen($track["ACTION_NOTE"]) > 0 ? ": " . $track["ACTION_NOTE"] : ""; $pattern = array("#ACTIVITY#", "#STATUS#", "#RESULT#", "#NOTE#"); $replaceArray = array($name, $status, $result, $note); if (!empty($track["ACTION_NAME"]) && !empty($track["ACTION_TITLE"])) { $pattern[] = $track["ACTION_NAME"]; $replaceArray[] = $track["ACTION_TITLE"]; } $messageTemplate = str_replace($pattern, $replaceArray, $messageTemplate); if (preg_match_all("/(?<=\\{\\=user\\:)([^\\}]+)(?=\\})/is", $messageTemplate, $arMatches)) { $pattern = array(); $replacement = array(); foreach ($arMatches[0] as $user) { $user = preg_quote($user); if (in_array("/\\{\\=user\\:" . $user . "\\}/is", $pattern)) { continue; } $replace = ""; if (array_key_exists(strtolower($user), $groups)) { $replace = $groups[strtolower($user)]; } elseif (array_key_exists(strtoupper($user), $groups)) { $replace = $groups[strtoupper($user)]; } else { $id = intVal(str_replace("user_", "", $user)); if (!array_key_exists($id, $users)) { $dbRes = \CUser::getByID($id); $users[$id] = false; if ($dbRes && ($arUser = $dbRes->getNext())) { $name = \CUser::formatName($this->arParams["NAME_TEMPLATE"], $arUser); $arUser["FULL_NAME"] = empty($name) ? $arUser["LOGIN"] : $name; $users[$id] = $arUser; } } if (!empty($users[$id])) { $replace = "<a href=\"" . \CComponentEngine::makePathFromTemplate('/company/personal/user/#USER_ID#/', array("USER_ID" => $id)) . "\">" . $users[$id]["FULL_NAME"] . "</a>"; } } if (!empty($replace)) { $pattern[] = "/\\{\\=user\\:" . $user . "\\}/is"; $pattern[] = "/\\{\\=user\\:user\\_" . $user . "\\}/is"; $replacement[] = $replace; $replacement[] = $replace; } } $messageTemplate = preg_replace($pattern, $replacement, $messageTemplate); } $this->arResult['BIZPROC_LIST'][$count]['DUMP_WORKFLOW'][] = $messageTemplate; } $tasks = CBPDocument::getUserTasksForWorkflow($this->getUser()->getId(), $idBizProc); $events = CBPDocument::getAllowableEvents($this->getUser()->getId(), $userGroup, $bizProcArray); if (!empty($tasks)) { foreach ($tasks as $task) { $urlTaskBizproc = \CComponentEngine::makePathFromTemplate($this->arParams['PATH_TO_DISK_TASK'], array("ID" => $task['ID'])); $urlTaskBizproc .= "?back_url=" . urlencode($this->getApplication()->getCurPage()) . "&file=" . $this->file->getName(); $this->arResult['BIZPROC_LIST'][$count]['TASK']['URL'] = $urlTaskBizproc; $this->arResult['BIZPROC_LIST'][$count]['TASK']['TASK_ID'] = $task['ID']; $this->arResult['BIZPROC_LIST'][$count]['TASK']['TASK_NAME'] = $task['NAME']; } } $this->arResult['BIZPROC_LIST'][$count]['ID'] = $bizProcArray['ID']; $this->arResult['BIZPROC_LIST'][$count]['WORKFLOW_STATUS'] = $bizProcArray["WORKFLOW_STATUS"]; $this->arResult['BIZPROC_LIST'][$count]['TEMPLATE_ID'] = $bizProcArray['TEMPLATE_ID']; $this->arResult['BIZPROC_LIST'][$count]['TEMPLATE_NAME'] = $bizProcArray['TEMPLATE_NAME']; $this->arResult['BIZPROC_LIST'][$count]['STATE_MODIFIED'] = $bizProcArray['STATE_MODIFIED']; $this->arResult['BIZPROC_LIST'][$count]['STATE_TITLE'] = $bizProcArray['STATE_TITLE']; $this->arResult['BIZPROC_LIST'][$count]['STATE_NAME'] = $bizProcArray['STATE_NAME']; $this->arResult['BIZPROC_LIST'][$count]['EVENTS'] = $events; $count++; } } }