Пример #1
0
 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));
 }
Пример #2
0
 /**
  * @param array $values
  * @return array
  */
 public function filter(array $values)
 {
     if ($values['get']['action'] == 'showFile') {
         if ($values['get']['preview'] == 'Y') {
             $values['get']['width'] = 204;
             $values['get']['height'] = 119;
             $values['get']['signature'] = \Bitrix\Disk\Security\ParameterSigner::getImageSignature($values['get']['fileId'], $values['get']['width'], $values['get']['height']);
         } else {
             unset($values['get']['width'], $values['get']['height']);
         }
         unset($values['get']['exact']);
     } else {
         $values['get']['action'] = 'downloadFile';
     }
     return array('get' => $values['get']);
 }
Пример #3
0
 public static function getUFForPostForm($arParams)
 {
     $arFileData = array();
     $arUF = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields($arParams["ENTITY_TYPE"], $arParams["ENTITY_ID"], LANGUAGE_ID);
     $ufCode = $arParams["UF_CODE"];
     if (!empty($arUF[$ufCode]) && !empty($arUF[$ufCode]["VALUE"])) {
         if ($arParams["IS_DISK_OR_WEBDAV_INSTALLED"]) {
             if (\Bitrix\Main\Config\Option::get('disk', 'successfully_converted', false) && CModule::IncludeModule('disk')) {
                 $userFieldManager = \Bitrix\Disk\Driver::getInstance()->getUserFieldManager();
                 $urlManager = \Bitrix\Disk\Driver::getInstance()->getUrlManager();
                 $userFieldManager->loadBatchAttachedObject($arUF[$ufCode]["VALUE"]);
                 foreach ($arUF[$ufCode]["VALUE"] as $attachedId) {
                     $attachedObject = $userFieldManager->getAttachedObjectById($attachedId);
                     if ($attachedObject) {
                         $file = $attachedObject->getObject();
                         $fileName = $file->getName();
                         $fileUrl = $urlManager->getUrlUfController('download', array('attachedId' => $attachedId));
                         $fileUrl = str_replace("/bitrix/tools/disk/uf.php", SITE_DIR . "mobile/ajax.php", $fileUrl);
                         $fileUrl = $fileUrl . (strpos($fileUrl, "?") === false ? "?" : "&") . "mobile_action=disk_uf_view&filename=" . $fileName;
                         if (\Bitrix\Disk\TypeFile::isImage($file) && ($realFile = $file->getFile())) {
                             $previewImageUrl = $urlManager->getUrlUfController('show', array('attachedId' => $attachedId, 'width' => 144, 'height' => 144, 'exact' => 'Y', 'signature' => \Bitrix\Disk\Security\ParameterSigner::getImageSignature($attachedId, 144, 144)));
                         } else {
                             $previewImageUrl = false;
                         }
                         $icon = CMobileHelper::mobileDiskGetIconByFilename($fileName);
                         $iconUrl = CComponentEngine::makePathFromTemplate('/bitrix/components/bitrix/mobile.disk.file.detail/images/' . $icon);
                         $fileFata = array('type' => $file->getExtension(), 'ufCode' => $ufCode, 'id' => $attachedId, 'extension' => $file->getExtension(), 'name' => $fileName, 'url' => $fileUrl, 'iconUrl' => $iconUrl);
                         if ($previewImageUrl) {
                             $fileFata['previewImageUrl'] = CHTTP::URN2URI($previewImageUrl);
                         }
                         $arFileData[] = $fileFata;
                     }
                 }
             } else {
                 $data = CWebDavIblock::getRootSectionDataForUser($GLOBALS["USER"]->GetID());
                 if (is_array($data)) {
                     $ibe = new CIBlockElement();
                     $dbWDFile = $ibe->GetList(array(), array('ID' => $arUF[$ufCode]["VALUE"], 'IBLOCK_ID' => $data["IBLOCK_ID"]), false, false, array('ID', 'IBLOCK_ID', 'PROPERTY_FILE'));
                     while ($arWDFile = $dbWDFile->Fetch()) {
                         if ($arFile = CFile::GetFileArray($arWDFile["PROPERTY_FILE_VALUE"])) {
                             if (CFile::IsImage($arFile["FILE_NAME"], $arFile["CONTENT_TYPE"])) {
                                 $imageResized = CFile::ResizeImageGet($arFile["ID"], array("width" => 144, "height" => 144), BX_RESIZE_IMAGE_EXACT, false, true);
                                 $previewImageUrl = $imageResized["src"];
                             } else {
                                 $previewImageUrl = false;
                             }
                             $fileExtension = GetFileExtension($arFile["FILE_NAME"]);
                             $fileData = array('type' => $fileExtension, 'ufCode' => $ufCode, 'id' => $arWDFile["ID"], 'extension' => $fileExtension, 'name' => $arFile["FILE_NAME"], 'url' => $arFile["SRC"]);
                             if ($previewImageUrl) {
                                 $fileData['previewImageUrl'] = CHTTP::URN2URI($previewImageUrl);
                             }
                             $arFileData[] = $fileData;
                         }
                     }
                 }
             }
         } else {
             $dbRes = CFile::GetList(array(), array("@ID" => implode(",", $arUF[$ufCode]["VALUE"])));
             while ($arFile = $dbRes->GetNext()) {
                 if (CFile::IsImage($arFile["FILE_NAME"], $arFile["CONTENT_TYPE"])) {
                     $imageResized = CFile::ResizeImageGet($arFile["ID"], array("width" => 144, "height" => 144), BX_RESIZE_IMAGE_EXACT, false, true);
                     $previewImageUrl = $imageResized["src"];
                 } else {
                     $previewImageUrl = false;
                 }
                 $fileExtension = GetFileExtension($arFile["FILE_NAME"]);
                 $fileData = array('type' => $fileExtension, 'ufCode' => $ufCode, 'id' => $arFile["ID"], 'extension' => $fileExtension, 'name' => $arFile["FILE_NAME"], 'downloadUrl' => $arFile["SRC"]);
                 if ($previewImageUrl) {
                     $fileData['previewImageUrl'] = CHTTP::URN2URI($previewImageUrl);
                 }
                 $arFileData[] = $fileData;
             }
         }
     }
     return $arFileData;
 }
Пример #4
0
                    $file["BASIC"] = array("src" => $file["ORIGINAL"]["src"] . "&" . http_build_query(array_merge($arParams["SCREEN_SIZE"], array('signature' => ParameterSigner::getImageSignature($file['ID'], $arParams["SCREEN_SIZE"]["width"], $arParams["SCREEN_SIZE"]["height"])))), "width" => $arDestinationSize["width"], "height" => $arDestinationSize["height"]);
                }
            }
            $arResult["FILES"][$id] = $images[$id] = $file;
        } else {
            $files[$id] = $file;
        }
    }
    if ($this->__page == "show") {
        $arResult['IMAGES'] = $images;
        $arResult['FILES'] = $files;
    }
} elseif (strpos($this->__page, "error") === false) {
    $arParams["THUMB_SIZE"] = 100;
    $http_query = array("cache_image" => "Y", "width" => $arParams["THUMB_SIZE"], "height" => $arParams["THUMB_SIZE"]);
    foreach ($arResult['FILES'] as $id => $arElement) {
        if (array_key_exists("IMAGE", $arElement)) {
            $http_query['signature'] = ParameterSigner::getImageSignature($arElement['ID'], $arParams["THUMB_SIZE"], $arParams["THUMB_SIZE"]);
            CFile::ScaleImage($arElement["IMAGE"]["WIDTH"], $arElement["IMAGE"]["HEIGHT"], array("width" => $arParams["THUMB_SIZE"], "height" => $arParams["THUMB_SIZE"]), BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
            if ($bNeedCreatePicture) {
                $arElement["original"] = array("src" => $arElement["URL_GET"], "width" => $arElement["IMAGE"]["WIDTH"], "height" => $arElement["IMAGE"]["HEIGHT"]);
                $arElement["IMAGE"]["WIDTH"] = $arDestinationSize["width"];
                $arElement["IMAGE"]["HEIGHT"] = $arDestinationSize["height"];
                if (array_key_exists("PREVIEW_URL", $arElement)) {
                    $arElement["PREVIEW_URL"] .= (strpos($arElement["PREVIEW_URL"], "?") === false ? "?" : "&") . http_build_query($http_query);
                }
                $arResult['FILES'][$id] = $arElement;
            }
        }
    }
}
Пример #5
0
define("STOP_STATISTICS", true);

require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

if(!\Bitrix\Main\Loader::includeModule('disk'))
{
	die;
}

if($_GET['action'] == 'showFile')
{
	if ($_GET['preview'] == 'Y')
	{
		$_GET['width'] = 204;
		$_GET['height'] = 119;
		$_GET['signature'] = \Bitrix\Disk\Security\ParameterSigner::getImageSignature($_GET['fileId'], $_GET['width'], $_GET['height']);
	}
	else
	{
		unset($_GET['width']);
		unset($_GET['height']);
	}
	unset($_GET['exact']);
}
else
{
	$_GET['action'] = 'downloadFile';
}

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
Пример #6
0
 protected function processActionDownloadFile()
 {
     $this->checkRequiredGetParams(array('attachedId'));
     if ($this->errorCollection->hasErrors()) {
         $this->sendJsonErrorResponse();
     }
     $fileModel = null;
     list($type, $realValue) = FileUserType::detectType($this->request->getQuery('attachedId'));
     if ($type == FileUserType::TYPE_NEW_OBJECT) {
         /** @var File $fileModel */
         $fileModel = File::loadById((int) $realValue, array('STORAGE'));
         if (!$fileModel) {
             $this->errorCollection->add(array(new Error("Could not find file")));
             $this->sendJsonErrorResponse();
         }
         if (!$fileModel->canRead($fileModel->getStorage()->getCurrentUserSecurityContext())) {
             $this->errorCollection->add(array(new Error("Bad permission. Could not read this file")));
             $this->sendJsonErrorResponse();
         }
         $fileName = $fileModel->getName();
         $fileData = $fileModel->getFile();
         if (!$fileData) {
             $this->end();
         }
         $cacheTime = 0;
         $width = $this->request->getQuery('width');
         $height = $this->request->getQuery('height');
         if (TypeFile::isImage($fileData["ORIGINAL_NAME"]) && ($width > 0 || $height > 0)) {
             $signature = $this->request->getQuery('signature');
             if (!$signature) {
                 $this->sendJsonInvalidSignResponse('Empty signature');
             }
             if (!ParameterSigner::validateImageSignature($signature, $fileModel->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"];
             $cacheTime = 86400;
         }
         \CFile::viewByUser($fileData, array("force_download" => false, "cache_time" => $cacheTime, 'attachment_name' => $fileName));
     } else {
         $this->errorCollection->add(array(new Error('Could not find attached object')));
         $this->sendJsonErrorResponse();
     }
 }
Пример #7
0
                }
            }
            if ($bExactly && $circumscribed) {
                CFile::ScaleImage($arSize["width"], $arSize["height"], $circumscribed, BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arSize);
            }
            $file["INLINE"]["width"] = $bExactly ? $arSize["width"] : $arDestinationSize["width"];
            $file["INLINE"]["height"] = $bExactly ? $arSize["height"] : $arDestinationSize["height"];
            // gallery
            $max_real_dimension = max(array(intval($file["IMAGE"]["WIDTH"]), intval($file["IMAGE"]["HEIGHT"])));
            if ($max_real_dimension > $max_dimension) {
                $arParams["SCREEN_SIZE"] = array("width" => $max_dimension, "height" => $max_dimension);
            } else {
                $arParams["SCREEN_SIZE"] = array("width" => $max_real_dimension, "height" => $max_real_dimension);
            }
            CFile::ScaleImage($file["IMAGE"]["WIDTH"], $file["IMAGE"]["HEIGHT"], $arParams["SCREEN_SIZE"], BX_RESIZE_IMAGE_PROPORTIONAL, $bNeedCreatePicture, $arSourceSize, $arDestinationSize);
            if ($bNeedCreatePicture) {
                $arParams["SCREEN_SIZE"]["signature"] = \Bitrix\Disk\Security\ParameterSigner::getImageSignature($file["ID"], $arParams["SCREEN_SIZE"]["width"], $arParams["SCREEN_SIZE"]["height"]);
                $file["BASIC"]["src"] .= "&" . http_build_query($arParams["SCREEN_SIZE"]);
                $file["BASIC"]["width"] = $arDestinationSize["width"];
                $file["BASIC"]["height"] = $arDestinationSize["height"];
            }
            $arResult["FILES"][$id] = $images[$id] = $file;
        } else {
            $arResult["FILES"][$id] = $files[$id] = $file;
        }
    }
    if ($this->__page == "show") {
        $arResult['IMAGES'] = $images;
        $arResult['FILES'] = $files;
    }
}
Пример #8
0
 /**
  * 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);
 }