protected function processActionShowFile() { $fileName = $this->file->getName(); $fileData = $this->file->getFile(); if (!$fileData) { $this->end(); } $isImage = TypeFile::isImage($fileData["ORIGINAL_NAME"]); $cacheTime = $isImage ? 86400 : 0; $width = $this->request->getQuery('width'); $height = $this->request->getQuery('height'); if ($isImage && ($width > 0 || $height > 0)) { $signature = $this->request->getQuery('signature'); if (!$signature) { $this->sendJsonInvalidSignResponse('Empty signature'); } if (!ParameterSigner::validateImageSignature($signature, $this->file->getId(), $width, $height)) { $this->sendJsonInvalidSignResponse('Invalid signature'); } /** @noinspection PhpDynamicAsStaticMethodCallInspection */ $tmpFile = \CFile::resizeImageGet($fileData, array("width" => $width, "height" => $height), $this->request->getQuery('exact') == "Y" ? BX_RESIZE_IMAGE_EXACT : BX_RESIZE_IMAGE_PROPORTIONAL, true, false, true); $fileData["FILE_SIZE"] = $tmpFile["size"]; $fileData["SRC"] = $tmpFile["src"]; } \CFile::viewByUser($fileData, array('force_download' => false, 'cache_time' => $cacheTime, 'attachment_name' => $fileName)); }
/** * @return File|null */ public function getObject() { if (!$this->objectId) { return null; } if (isset($this->object) && $this->objectId == $this->object->getId()) { return $this->object; } $this->object = File::loadById($this->objectId); return $this->object; }
/** * @return EditSession|null */ protected function getOnlineEditSessionForFile() { if ($this->isSpecificVersion()) { return null; } return EditSession::load(array('OBJECT_ID' => $this->file->getId(), 'VERSION_ID' => null, 'IS_EXCLUSIVE' => false)); }
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(); }
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 checkDownloadToken(File $file, $token) { return $_SESSION['DISK_PUBLIC_VERIFICATION'][$file->getId()] === $token; }
/** * 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); }
/** * @return \Bitrix\Disk\ExternalLink|null */ protected function getExternalLink() { $extLinks = $this->file->getExternalLinks(array('filter' => array('OBJECT_ID' => $this->file->getId(), 'CREATED_BY' => $this->getUser()->getId(), 'TYPE' => ExternalLinkTable::TYPE_MANUAL, 'IS_EXPIRED' => false), 'limit' => 1)); return array_pop($extLinks); }