Ejemplo n.º 1
0
 function findCorrectFile($path, &$strWarn, $warning = false)
 {
     $arUrl = CHTTP::ParseURL($path);
     if ($arUrl && is_array($arUrl)) {
         if (isset($arUrl['host'], $arUrl['scheme'])) {
             if (strpos($arUrl['host'], 'xn--') !== false) {
                 // Do nothing
             } else {
                 $originalPath = $path;
                 $path = $arUrl['scheme'] . '://' . $arUrl['host'];
                 $arErrors = array();
                 if (defined("BX_UTF")) {
                     $punicodedPath = CBXPunycode::ToUnicode($path, $arErrors);
                 } else {
                     $punicodedPath = CBXPunycode::ToASCII($path, $arErrors);
                 }
                 if ($pathPunicoded == $path) {
                     return $originalPath;
                 } else {
                     $path = $punicodedPath;
                 }
                 if ($arUrl['port'] && ($arUrl['scheme'] != 'http' || $arUrl['port'] != 80) && ($arUrl['scheme'] != 'https' || $arUrl['port'] != 443)) {
                     $path .= ':' . $arUrl['port'];
                 }
                 $path .= $arUrl['path_query'];
             }
         } else {
             $DOC_ROOT = $_SERVER["DOCUMENT_ROOT"];
             $path = Rel2Abs("/", $path);
             $path_ = $path;
             $io = CBXVirtualIo::GetInstance();
             if (!$io->FileExists($DOC_ROOT . $path)) {
                 if (CModule::IncludeModule('clouds')) {
                     $path = CCloudStorage::FindFileURIByURN($path, "component:player");
                     if ($path == "") {
                         if ($warning) {
                             $strWarn .= $warning . "<br />";
                         }
                         $path = $path_;
                     }
                 } else {
                     if ($warning) {
                         $strWarn .= $warning . "<br />";
                     }
                     $path = $path_;
                 }
             } elseif (strpos($_SERVER['HTTP_HOST'], 'xn--') !== false) {
                 $path = CHTTP::URN2URI($path);
             }
         }
     }
     return $path;
 }
Ejemplo n.º 2
0
 /**
  * @param array[string]string $arFields
  * @return mixed
  */
 public function Update($arFields)
 {
     global $DB, $CACHE_MANAGER;
     if ($this->_ID <= 0) {
         return false;
     }
     $this->service = CCloudStorage::GetServiceByID($this->SERVICE_ID);
     if (!is_object($this->service)) {
         return false;
     }
     unset($arFields["FILE_COUNT"]);
     unset($arFields["SERVICE_ID"]);
     unset($arFields["LOCATION"]);
     unset($arFields["BUCKET"]);
     if (!$this->CheckFields($arFields, $this->_ID)) {
         return false;
     }
     if (array_key_exists("FILE_RULES", $arFields)) {
         if (is_array($arFields["FILE_RULES"])) {
             $arFields["FILE_RULES"] = serialize($arFields["FILE_RULES"]);
         } else {
             $arFields["FILE_RULES"] = false;
         }
     }
     if (array_key_exists("SETTINGS", $arFields)) {
         if (!$this->CheckSettings($arFields["SETTINGS"])) {
             return false;
         }
         $arFields["SETTINGS"] = serialize($arFields["SETTINGS"]);
     }
     $strUpdate = $DB->PrepareUpdate("b_clouds_file_bucket", $arFields);
     if (strlen($strUpdate) > 0) {
         $strSql = "\n\t\t\t\tUPDATE b_clouds_file_bucket SET\n\t\t\t\t" . $strUpdate . "\n\t\t\t\tWHERE ID = " . $this->_ID . "\n\t\t\t";
         if (!is_object($DB->Query($strSql))) {
             return false;
         }
     }
     if (CACHED_b_clouds_file_bucket !== false) {
         $CACHE_MANAGER->CleanDir("b_clouds_file_bucket");
     }
     return $this->_ID;
 }
Ejemplo n.º 3
0
 public static function OnBeforeProlog()
 {
     if (defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI) {
         $upload_dir = "/" . trim(COption::GetOptionString("main", "upload_dir", "upload"), "/") . "/";
         $request_uri = urldecode($_SERVER["REQUEST_URI"]);
         $request_uri = CCloudUtil::URLEncode($request_uri, LANG_CHARSET);
         foreach (CCloudStorageBucket::GetAllBuckets() as $arBucket) {
             if ($arBucket["ACTIVE"] == "Y") {
                 $obBucket = new CCloudStorageBucket($arBucket["ID"]);
                 if ($obBucket->Init()) {
                     $match = array();
                     if ($obBucket->FileExists($request_uri)) {
                         if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                             CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                         }
                         LocalRedirect($obBucket->GetFileSRC($request_uri), true);
                     } elseif (strpos($request_uri, $upload_dir) === 0) {
                         $check_url = substr($request_uri, strlen($upload_dir) - 1);
                         if ($obBucket->FileExists($check_url)) {
                             if (COption::GetOptionString("clouds", "log_404_errors") === "Y") {
                                 CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
                             }
                             LocalRedirect($obBucket->GetFileSRC($check_url), true);
                         }
                     } elseif (COption::GetOptionString("clouds", "delayed_resize") === "Y" && preg_match("#^(/" . $obBucket->PREFIX . "|)(/resize_cache/.*\$)#", $request_uri, $match)) {
                         session_write_close();
                         $to_file = $obBucket->GetFileSRC(urldecode($match[2]));
                         if (CCloudStorage::ResizeImageFileCheck($obBucket, $to_file)) {
                             LocalRedirect($to_file, true);
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
	function MakeFileArray($file)
	{
		if(
			(!is_array($file))
			&& (strlen($file) > 0)
			&& is_file($this->files_dir.$file)
		)
		{
			return CFile::MakeFileArray($this->files_dir.$file);
		}
		elseif(is_array($file) && array_key_exists(GetMessage("IBLOCK_XML2_BX_URL"), $file))
		{
			if(CModule::IncludeModule('clouds'))
			{
				$bucket = CCloudStorage::FindBucketByFile($file[GetMessage("IBLOCK_XML2_BX_URL")]);
				if(is_object($bucket) && $bucket->READ_ONLY === "Y")
				{
					return array(
						"name" => $file[GetMessage("IBLOCK_XML2_BX_ORIGINAL_NAME")],
						"description" => $file[GetMessage("IBLOCK_XML2_DESCRIPTION")],
						"tmp_name" => $file[GetMessage("IBLOCK_XML2_BX_URL")],
						"file_size" => $file[GetMessage("IBLOCK_XML2_BX_FILE_SIZE")],
						"width" => $file[GetMessage("IBLOCK_XML2_BX_FILE_WIDTH")],
						"height" => $file[GetMessage("IBLOCK_XML2_BX_FILE_HEIGHT")],
						"type" => $file[GetMessage("IBLOCK_XML2_BX_FILE_CONTENT_TYPE")],
						"content" => "", //Fake field in order to avoid warning
						"bucket" => $bucket,
					);
				}
			}

			return CFile::MakeFileArray($this->URLEncode($file[GetMessage("IBLOCK_XML2_BX_URL")])); //Download from the cloud
		}
		else
			return array("tmp_name"=>"", "del"=>"Y");
	}
Ejemplo n.º 5
0
 /**
  * @param array $values
  * @param string $inputNameTemplate
  * @param bool|array $showInfo
  * @param bool $maxCount
  * @param array $inputs
  * @return string
  */
 public static function ShowMultiple($values = array(), $inputNameTemplate = "", $showInfo = false, $maxCount = false, $inputs = array())
 {
     CJSCore::Init('file_input');
     ob_start();
     global $USER;
     self::Init($showInfo, $inputNameTemplate, $maxCount);
     self::$bMultiple = true;
     $arDescInput = is_array($inputs['description']) && isset($inputs['description']['VALUES']) && isset($inputs['description']['NAME_TEMPLATE']) ? $inputs['description'] : false;
     $inputs = array('upload' => $inputs['upload'] === true, 'medialib' => $inputs['medialib'] === true && COption::GetOptionString('fileman', "use_medialib", "Y") != "N", 'file_dialog' => $inputs['file_dialog'] === true, 'cloud' => $inputs['cloud'] === true && $USER->CanDoOperation("clouds_browse") && CModule::IncludeModule("clouds") && CCloudStorage::HasActiveBuckets(), 'del' => $inputs['del'] !== false, 'description' => $inputs['description'] === true || $arDescInput);
     self::$bUseUpload = $inputs['upload'];
     self::$bUseMedialib = $inputs['medialib'];
     self::$bUseFileDialog = $inputs['file_dialog'];
     self::$bUseCloud = $inputs['cloud'];
     self::$bShowDelInput = $inputs['del'];
     self::$bShowDescInput = $inputs['description'];
     self::$inputNameTemplate = $inputNameTemplate;
     self::$bViewMode = self::IsViewMode();
     if (self::$bViewMode) {
         self::$bShowDelInput = false;
     }
     if (self::$bShowDelInput) {
         self::$delInputName = self::GetInputName($inputNameTemplate, "_del");
     }
     if (self::$bShowDescInput) {
         self::$descInputName = '';
         if ($arDescInput) {
             self::$descInputName = $arDescInput['NAME_TEMPLATE'];
         }
         if (empty(self::$descInputName)) {
             self::$descInputName = self::GetInputName($inputNameTemplate, "_descr");
         }
     }
     // $arFile - Array with current file or false if it's empty
     self::$curFiles = array();
     self::$bFileExists = false;
     foreach ($values as $inputName => $fileId) {
         if (strlen($fileId) <= 1 && intVal($fileId) === 0) {
             continue;
         }
         self::$bFileExists = true;
         if ($arFile = self::GetFile($fileId)) {
             $arFile['FILE_NOT_FOUND'] = false;
             $arFile['INPUT_NAME'] = $inputName;
             $arFile['DEL_NAME'] = self::GetInputName($inputName, '_del');
             $arFile['DESC_NAME'] = self::GetInputName($inputName, '_descr');
             if ($arDescInput) {
                 list($descName, $descVal) = each($arDescInput['VALUES']);
                 $arFile['DESC_NAME'] = $descName;
                 $arFile['DESCRIPTION'] = $descVal;
             }
         } else {
             $arFile = array('FILE_NOT_FOUND' => true, 'INPUT_NAME' => $inputName, 'DEL_NAME' => self::GetInputName($inputName, '_del'), 'DESC_NAME' => self::GetInputName($inputName, '_descr'));
         }
         self::$curFiles[] = $arFile;
     }
     self::DisplayControl($inputs);
     $result = ob_get_contents();
     ob_end_clean();
     return $result;
 }
Ejemplo n.º 6
0
 public static function DeleteHistoryByDocument($documentId)
 {
     global $DB;
     $arDocumentId = CBPHelper::ParseDocumentId($documentId);
     $dest = self::GenerateFilePath($documentId);
     DeleteDirFilesEx("/" . COption::GetOptionString("main", "upload_dir", "upload") . $dest);
     if (CModule::IncludeModule('clouds')) {
         CCloudStorage::DeleteDirFilesEx($dest);
     }
     $DB->Query("DELETE FROM b_bp_history " . "WHERE DOCUMENT_ID = '" . $DB->ForSql($arDocumentId[2]) . "' " . "\tAND ENTITY = '" . $DB->ForSql($arDocumentId[1]) . "' " . "\tAND MODULE_ID " . (strlen($arDocumentId[0]) > 0 ? "= '" . $DB->ForSql($arDocumentId[0]) . "'" : "IS NULL") . " ", true);
 }
Ejemplo n.º 7
0
 }
 if ($PathToFile && file_exists($_SERVER["DOCUMENT_ROOT"] . "/" . $PathToFile) && is_file($_SERVER["DOCUMENT_ROOT"] . "/" . $PathToFile)) {
     $FileSize = filesize($_SERVER["DOCUMENT_ROOT"] . "/" . $PathToFile);
     if ($FileSize) {
         $FileSize = round(sprintf("%u", $FileSize) / 1024 / 1024, 2);
     }
     if ($FileSize <= 0) {
         $FileSize = "";
     }
     $ext = strtolower(substr($PathToFile, -4));
     if ($ext == ".wmv" || $ext == "wma") {
         $FileType = "wmv";
     } else {
         $FileType = "flv";
     }
 } elseif (CModule::IncludeModule("clouds") && ($uri = CCloudStorage::FindFileURIByURN($PathToFile, "component:iblock.tv, iblock:" . $arParams["IBLOCK_ID"] . ", element: " . $arItem["ID"])) !== "") {
     $PathToFile = $uri;
     $FileSize = "";
     $ext = strtolower(substr($PathToFile, -4));
     if ($ext == ".wmv" || $ext == "wma") {
         $FileType = "wmv";
     } else {
         $FileType = "flv";
     }
 } else {
     $FileSize = "";
     $FileType = "flv";
 }
 if (!$arResult['FIRST_FLV_ITEM'] && $FileType == 'flv') {
     $arResult['FIRST_FLV_ITEM'] = $PathToFile;
 }
Ejemplo n.º 8
0
 /**
  * If enable module clouds, then find bucket for file
  * @param array $params
  * @return null|\CCloudStorageBucket
  */
 private function findBucketForFile(array $params)
 {
     if (!Loader::includeModule("clouds")) {
         return null;
     }
     /** @noinspection PhpDynamicAsStaticMethodCallInspection */
     $bucket = \CCloudStorage::findBucketForFile(array('FILE_SIZE' => $params['fileSize'], 'MODULE_ID' => Driver::INTERNAL_MODULE_ID), $params['name']);
     if (!$bucket || !$bucket->init()) {
         return null;
     }
     return $bucket;
 }
Ejemplo n.º 9
0
	function OnBeforeProlog()
	{
		if(defined("BX_CHECK_SHORT_URI") && BX_CHECK_SHORT_URI)
		{
			$upload_dir = "/".trim(COption::GetOptionString("main", "upload_dir", "upload"), "/")."/";
			$request_uri = urldecode($_SERVER["REQUEST_URI"]);
			$request_uri = CCloudUtil::URLEncode($request_uri, LANG_CHARSET);
			foreach(CCloudStorageBucket::GetAllBuckets() as $arBucket)
			{
				if($arBucket["ACTIVE"] == "Y")
				{
					$obBucket = new CCloudStorageBucket($arBucket["ID"]);
					if($obBucket->Init())
					{
						$match = array();
						if(
							COption::GetOptionString("clouds", "delayed_resize") === "Y"
							&& preg_match("#^(/".$obBucket->PREFIX."|)(/resize_cache/.*\$)#", $request_uri, $match)
						)
						{
							session_write_close();
							$to_file = $obBucket->GetFileSRC(urldecode($match[2]));
							if (CCloudStorage::ResizeImageFileCheck($obBucket, $to_file))
							{
								$cache_time = 3600*24*30; // 30 days
								header("Cache-Control: max-age=".$cache_time);
								header("Expires: ".gmdate("D, d M Y H:i:s", time()+$cache_time)." GMT");
								header_remove("Pragma");
								LocalRedirect($to_file, true, "301 Moved Permanently");
							}
						}
						elseif($obBucket->FileExists($request_uri))
						{
							if(COption::GetOptionString("clouds", "log_404_errors") === "Y")
								CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
							LocalRedirect($obBucket->GetFileSRC($request_uri), true);
						}
						elseif(strpos($request_uri, $upload_dir) === 0)
						{
							$check_url = substr($request_uri, strlen($upload_dir)-1);
							if($obBucket->FileExists($check_url))
							{
								if(COption::GetOptionString("clouds", "log_404_errors") === "Y")
									CEventLog::Log("WARNING", "CLOUDS_404", "clouds", $_SERVER["REQUEST_URI"], $_SERVER["HTTP_REFERER"]);
								LocalRedirect($obBucket->GetFileSRC($check_url), true);
							}
						}
					}
				}
			}
		}
	}
Ejemplo n.º 10
0
 /**
  * @param array $params
  */
 public function __construct($params = array())
 {
     global $USER;
     $inputs = array_merge($this->elementSetts, $params);
     $this->elementSetts = array("name" => $inputs["name"], "description" => !empty($inputs["description"]), "delete" => $inputs['delete'] !== false, "edit" => $inputs['edit'] !== false, "thumbSize" => 640);
     $replace = array("/\\#MESS_LOADING\\#/" => Loc::getMessage("BXU_LoadingProcess"), "/\\#description\\#/" => $this->elementSetts["edit"] == true && $this->elementSetts["description"] == true ? self::$templatePatterns["description"] : "", "/\\#properties\\#/" => "", "/[\n\t]+/" => "");
     $this->templates["uploaded"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["uploaded"]);
     $this->templates["unexisted"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["unexisted"]);
     $this->templates["new"] = preg_replace(array_keys($replace), array_values($replace), self::$templatePatterns["new"]);
     $replace = array("#input_name#" => $inputs["name"], "#input_value#" => "", "#description_name#" => self::getInputName($inputs["name"], "_descr"), "#description#" => "");
     $this->templates["new"] = str_replace(array_keys($replace), array_values($replace), $this->templates["new"]);
     $inputs = array_merge($this->uploadSetts, $params);
     $this->uploadSetts = array("upload" => '', "uploadType" => "path", "medialib" => $inputs['medialib'] === true && \COption::GetOptionString('fileman', "use_medialib", "Y") != "N", "fileDialog" => $inputs['file_dialog'] === true || $inputs['fileDialog'] === true, "cloud" => $inputs['cloud'] === true && $USER->CanDoOperation("clouds_browse") && \CModule::IncludeModule("clouds") && \CCloudStorage::HasActiveBuckets(), "maxCount" => $params["maxCount"] > 0 ? $params["maxCount"] : 0, "maxSize" => $params["maxSize"] > 0 ? $params["maxSize"] : 0, "allowUpload" => in_array($params["allowUpload"], array("A", "I", "F")) ? $params["allowUpload"] : "A", "allowUploadExt" => trim($params["allowUploadExt"]), "allowSort" => $params["allowSort"] == "N" ? "N" : "Y");
     if (empty($this->uploadSetts["allowUploadExt"]) && $this->uploadSetts["allowUpload"] == "F") {
         $this->uploadSetts["allowUpload"] = "A";
     }
     $this->id = 'bx_file_' . strtolower(preg_replace("/[^a-z0-9]/i", "_", $this->elementSetts["name"]));
     if ($inputs['upload'] === true) {
         $this->uploadSetts['upload'] = FileInputReceiver::sign(array("id" => $inputs['uploadType'] === "hash" ? "hash" : "path", "allowUpload" => $this->uploadSetts["allowUpload"], "allowUploadExt" => $this->uploadSetts["allowUploadExt"]));
         $this->uploadSetts['uploadType'] = in_array($inputs["uploadType"], array("hash", "path")) ? $inputs["uploadType"] : "path";
     }
     self::$instance = $this;
 }
Ejemplo n.º 11
0
 function OnFileSave(&$arFile, $strFileName, $strSavePath, $bForceMD5 = false, $bSkipExt = false)
 {
     if (!$arFile["tmp_name"] && !$arFile["content"]) {
         return false;
     }
     if (array_key_exists("bucket", $arFile)) {
         $bucket = $arFile["bucket"];
     } else {
         $bucket = CCloudStorage::FindBucketForFile($arFile, $strFileName);
     }
     if (!is_object($bucket)) {
         return false;
     }
     if (!$bucket->Init()) {
         return false;
     }
     if (array_key_exists("bucket", $arFile)) {
         $newName = bx_basename($arFile["tmp_name"]);
         $prefix = $bucket->GetFileSRC("/");
         $subDir = substr($arFile["tmp_name"], strlen($prefix));
         $subDir = substr($subDir, 0, -strlen($newName) - 1);
     } else {
         if ($bForceMD5 != true && COption::GetOptionString("main", "save_original_file_name", "N") == "Y") {
             if (COption::GetOptionString("main", "convert_original_file_name", "Y") == "Y") {
                 $newName = CCloudStorage::translit($strFileName);
             } else {
                 $newName = $strFileName;
             }
         } else {
             $strFileExt = $bSkipExt == true ? '' : strrchr($strFileName, ".");
             $newName = md5(uniqid(mt_rand(), true)) . $strFileExt;
         }
         //check for double extension vulnerability
         $newName = RemoveScriptExtension($newName);
         while (true) {
             $strRand = md5(mt_rand());
             $strRand = substr($strRand, 0, 3) . "/" . $strRand;
             if (substr($strSavePath, -1) == "/") {
                 $subDir = $strSavePath . $strRand;
             } else {
                 $subDir = $strSavePath . "/" . $strRand;
             }
             $subDir = ltrim($subDir, "/");
             $filePath = "/" . $subDir . "/" . $newName;
             if (!$bucket->FileExists($filePath)) {
                 break;
             }
         }
         if (!$bucket->SaveFile($filePath, $arFile)) {
             return false;
         }
     }
     $arFile["HANDLER_ID"] = $bucket->ID;
     $arFile["SUBDIR"] = $subDir;
     $arFile["FILE_NAME"] = $newName;
     $arFile["WIDTH"] = 0;
     $arFile["HEIGHT"] = 0;
     if (array_key_exists("bucket", $arFile)) {
         $arFile["WIDTH"] = $arFile["width"];
         $arFile["HEIGHT"] = $arFile["height"];
         $arFile["size"] = $arFile["file_size"];
     } elseif (array_key_exists("content", $arFile)) {
         $tmp_name = tempnam();
         $fp = fopen($tmp_name, "ab");
         if ($fp) {
             if (fwrite($fp, $arFile["content"])) {
                 $bucket->IncFileCounter(filesize($tmp_name));
                 $imgArray = CFile::GetImageSize($tmp_name);
                 if (is_array($imgArray)) {
                     $arFile["WIDTH"] = $imgArray[0];
                     $arFile["HEIGHT"] = $imgArray[1];
                 }
             }
             fclose($fp);
             unlink($tmp_name);
         }
     } else {
         $bucket->IncFileCounter(filesize($arFile["tmp_name"]));
         $imgArray = CFile::GetImageSize($arFile["tmp_name"]);
         if (is_array($imgArray)) {
             $arFile["WIDTH"] = $imgArray[0];
             $arFile["HEIGHT"] = $imgArray[1];
         }
     }
     if (isset($arFile["old_file"])) {
         CFile::DoDelete($arFile["old_file"]);
     }
     return true;
 }
Ejemplo n.º 12
0
 protected function migrateVersion()
 {
     if (!$this->runWorkWithBizproc) {
         return;
     }
     if ($this->isStepFinished(__METHOD__)) {
         return;
     }
     $uploadDir = COption::getOptionString("main", "upload_dir", "upload");
     $isCloud = CModule::IncludeModule("clouds");
     $useGZipCompressionOption = \Bitrix\Main\Config\Option::get("bizproc", "use_gzip_compression", "");
     $isBitrix24 = IsModuleInstalled('bitrix24');
     $bucket = null;
     if ($isBitrix24 && $isCloud) {
         $bucket = new CCloudStorageBucket(1);
         $bucket->init();
     }
     if ($useGZipCompressionOption === "Y") {
         $this->useGZipCompression = true;
     } elseif ($useGZipCompressionOption === "N") {
         $this->useGZipCompression = false;
     } else {
         $this->useGZipCompression = function_exists("gzcompress") && ($GLOBALS["DB"]->type != "ORACLE" || !defined('BX_UTF'));
     }
     $sqlHelper = $this->connection->getSqlHelper();
     $lastId = $this->getStorageId();
     $versionQuery = $this->connection->query("\n\t\t\tSELECT\n\t\t\t\tobj.*,\n\t\t\t\th.ID VERSION_ID,\n\t\t\t\th.NAME VERSION_NAME,\n\t\t\t\th.DOCUMENT VERSION_DOC,\n\t\t\t\th.USER_ID VERSION_USER_ID,\n\t\t\t\th.MODIFIED VERSION_MODIFIED\n\t\t\tFROM b_disk_object obj\n\t\t\t\tINNER JOIN b_bp_history h ON h.DOCUMENT_ID = obj.WEBDAV_ELEMENT_ID AND h.MODULE_ID = 'webdav'\n\n\t\t\tWHERE obj.TYPE = 3 AND h.ID > {$lastId} ORDER BY h.ID\n\t\t");
     while ($version = $versionQuery->fetch()) {
         $this->abortIfNeeded();
         if (strlen($version['VERSION_DOC']) > 0) {
             if ($this->useGZipCompression) {
                 $version['VERSION_DOC'] = gzuncompress($version['VERSION_DOC']);
             }
             $version['VERSION_DOC'] = unserialize($version['VERSION_DOC']);
             if (!is_array($version['VERSION_DOC'])) {
                 $version['VERSION_DOC'] = array();
             }
         } else {
             $version['VERSION_DOC'] = array();
         }
         if (empty($version['VERSION_DOC']) || empty($version['VERSION_DOC']['PROPERTIES']['WEBDAV_VERSION']['VALUE']) || empty($version['VERSION_DOC']['PROPERTIES']['FILE']['VALUE'])) {
             $this->storeStorageId($version['VERSION_ID']);
             continue;
         }
         $version['VERSION_NAME'] = $sqlHelper->forSql($version['VERSION_NAME']);
         $version['VERSION_MODIFIED'] = $sqlHelper->getCharToDateFunction($version['VERSION_MODIFIED']->format("Y-m-d H:i:s"));
         $version['UPDATE_TIME'] = $sqlHelper->getCharToDateFunction($version['UPDATE_TIME']->format("Y-m-d H:i:s"));
         $fullPath = $version['VERSION_DOC']['PROPERTIES']['FILE']['VALUE'];
         $handlerId = '';
         $filename = bx_basename($fullPath);
         if (substr($fullPath, 0, 4) == "http") {
             if (!$isCloud) {
                 $this->storeStorageId($version['VERSION_ID']);
                 continue;
             }
             if (!$isBitrix24) {
                 $bucket = CCloudStorage::findBucketByFile($fullPath);
                 if (!$bucket) {
                     $this->storeStorageId($version['VERSION_ID']);
                     continue;
                 }
             }
             $handlerId = $bucket->ID;
             $subDir = trim(substr(getDirPath($fullPath), strlen($bucket->getFileSRC('/'))), '/');
             $contentType = \Bitrix\Disk\TypeFile::getMimeTypeByFilename($filename);
         } else {
             $subDir = trim(substr(getDirPath($fullPath), strlen('/' . $uploadDir)), '/');
             $contentType = CFile::getContentType($_SERVER["DOCUMENT_ROOT"] . $fullPath);
             $contentType = \Bitrix\Disk\TypeFile::normalizeMimeType($contentType, $filename);
         }
         $webdavSize = $version['VERSION_DOC']['PROPERTIES']['WEBDAV_SIZE']['VALUE'];
         if (empty($webdavSize)) {
             $webdavSize = 0;
         }
         $fileId = CFile::doInsert(array('HEIGHT' => 0, 'WIDTH' => 0, 'FILE_SIZE' => $webdavSize, 'CONTENT_TYPE' => $contentType, 'SUBDIR' => $subDir, 'FILE_NAME' => $filename, 'MODULE_ID' => Driver::INTERNAL_MODULE_ID, 'ORIGINAL_NAME' => $filename, 'DESCRIPTION' => '', 'HANDLER_ID' => $handlerId, 'EXTERNAL_ID' => md5(mt_rand())));
         if (!$fileId) {
             $this->storeStorageId($version['VERSION_ID']);
             continue;
         }
         $this->connection->queryExecute("\n\t\t\t\tINSERT INTO b_disk_version (OBJECT_ID, FILE_ID, " . $this->sqlHelper->quote('SIZE') . ", NAME, CREATE_TIME, CREATED_BY, MISC_DATA, OBJECT_CREATE_TIME, OBJECT_CREATED_BY, OBJECT_UPDATE_TIME, OBJECT_UPDATED_BY, GLOBAL_CONTENT_VERSION, BP_VERSION_ID)\n\t\t\t\tVALUES ({$version['ID']}, {$fileId}, {$webdavSize}, '{$version['VERSION_NAME']}', {$version['VERSION_MODIFIED']},  {$version['VERSION_USER_ID']}, null, {$version['VERSION_MODIFIED']}, {$version['CREATED_BY']}, {$version['UPDATE_TIME']}, {$version['UPDATED_BY']}, {$version['VERSION_DOC']['PROPERTIES']['WEBDAV_VERSION']['VALUE']}, {$version['VERSION_ID']})\n\t\t\t");
         $this->storeStorageId($version['VERSION_ID']);
     }
     $this->abortIfNeeded();
     $this->storeStorageId(0);
     $this->setStepFinished(__METHOD__);
 }
Ejemplo n.º 13
0
        ?>
" style="display:<?php 
        echo $arRes["SERVICE_ID"] === $SERVICE_ID || !$bServiceSet ? "" : "none";
        ?>
" class="location-tr">
			<td><?php 
        echo GetMessage("CLO_STORAGE_EDIT_LOCATION");
        ?>
:</td>
			<td>
			<select name="LOCATION[<?php 
        echo htmlspecialcharsbx($SERVICE_ID);
        ?>
]">
			<?php 
        foreach (CCloudStorage::GetServiceLocationList($SERVICE_ID) as $LOCATION_ID => $LOCATION_NAME) {
            ?>
<option value="<?php 
            echo htmlspecialcharsbx($LOCATION_ID);
            ?>
"<?php 
            if ($arRes["SERVICE_ID"] === $LOCATION_ID) {
                echo " selected";
            }
            ?>
><?php 
            echo htmlspecialcharsex($LOCATION_NAME);
            ?>
</option><?php 
        }
        ?>
Ejemplo n.º 14
0
 /**
  * If enable module clouds, then find bucket for file
  * @param array $params
  * @return bool|CCloudStorageBucket
  */
 protected function findBucketForFile(array $params)
 {
     if (!CModule::IncludeModule("clouds")) {
         return false;
     }
     $bucket = CCloudStorage::FindBucketForFile(array('FILE_SIZE' => $params['fileSize'], 'MODULE_ID' => 'iblock'), $params['name']);
     if ($bucket === null || !$bucket->init()) {
         return false;
     }
     return $bucket;
 }
Ejemplo n.º 15
0
 function MakeFileArray($file, $fields = array())
 {
     if (is_array($file)) {
         if (array_key_exists($this->mess["IBLOCK_XML2_BX_URL"], $file) && strlen($file[$this->mess["IBLOCK_XML2_BX_URL"]]) > 0) {
             if (CModule::IncludeModule('clouds')) {
                 $bucket = CCloudStorage::FindBucketByFile($file[$this->mess["IBLOCK_XML2_BX_URL"]]);
                 if (is_object($bucket) && $bucket->READ_ONLY === "Y") {
                     return array("name" => $file[$this->mess["IBLOCK_XML2_BX_ORIGINAL_NAME"]], "description" => $file[$this->mess["IBLOCK_XML2_DESCRIPTION"]], "tmp_name" => $file[$this->mess["IBLOCK_XML2_BX_URL"]], "file_size" => $file[$this->mess["IBLOCK_XML2_BX_FILE_SIZE"]], "width" => $file[$this->mess["IBLOCK_XML2_BX_FILE_WIDTH"]], "height" => $file[$this->mess["IBLOCK_XML2_BX_FILE_HEIGHT"]], "type" => $file[$this->mess["IBLOCK_XML2_BX_FILE_CONTENT_TYPE"]], "content" => "", "bucket" => $bucket);
                 }
             }
             return CFile::MakeFileArray($this->URLEncode($file[$this->mess["IBLOCK_XML2_BX_URL"]]));
             //Download from the cloud
         }
     } else {
         if (strlen($file) > 0) {
             $external_id = md5($file);
             if (is_file($this->files_dir . $file)) {
                 return CFile::MakeFileArray($this->files_dir . $file, false, false, $external_id);
             }
             $fileId = $this->CheckFileByName($external_id, $fields);
             if ($fileId > 0) {
                 return CFile::MakeFileArray($fileId);
             }
         }
     }
     return array("tmp_name" => "", "del" => "Y");
 }
Ejemplo n.º 16
0
	public static function InitiateMultipartUpload($arBucket, &$NS, $filePath, $fileSize, $ContentType)
	{
		$filePath = '/'.trim($filePath, '/');
		if($arBucket["PREFIX"])
		{
			if(substr($filePath, 0, strlen($arBucket["PREFIX"])+2) != "/".$arBucket["PREFIX"]."/")
				$filePath = "/".$arBucket["PREFIX"].$filePath;
		}

		$NS = array(
			"filePath" => $filePath,
			"fileTemp" => CCloudStorage::translit("/tmp".$filePath, "/"),
			"partsCount" => 0,
			"Content-Type" => $ContentType,
		);

		return true;
	}
Ejemplo n.º 17
0
		{
			$FileSize = filesize($_SERVER["DOCUMENT_ROOT"]."/".$PathToFile);
			if($FileSize)
				$FileSize = round(sprintf("%u", $FileSize)/1024/1024, 2);
			if($FileSize <= 0)
				$FileSize = "";

			$ext = strtolower(substr($PathToFile, -4));
			if($ext == ".wmv" || $ext == "wma")
				$FileType = "wmv";
			else
				$FileType = "flv";
		}
		elseif(
			CModule::IncludeModule("clouds")
			&& ($uri = CCloudStorage::FindFileURIByURN($PathToFile, "component:iblock.tv, iblock:".$arParams["IBLOCK_ID"].", element: ".$arItem["ID"])) !== ""
		)
		{
			$PathToFile = $uri;

			$FileSize = "";

			$ext = strtolower(substr($PathToFile, -4));
			if($ext == ".wmv" || $ext == "wma")
				$FileType = "wmv";
			else
				$FileType = "flv";
		}
		else
		{
			$FileSize = "";
Ejemplo n.º 18
0
}
$arHeaders = array(array("id" => "SORT", "content" => GetMessage("CLO_STORAGE_LIST_SORT"), "align" => "right", "default" => true), array("id" => "ID", "content" => GetMessage("CLO_STORAGE_LIST_ID"), "align" => "right", "default" => true), array("id" => "ACTIVE", "content" => GetMessage("CLO_STORAGE_LIST_ACTIVE"), "align" => "center", "default" => true), array("id" => "FILE_COUNT", "content" => GetMessage("CLO_STORAGE_LIST_FILE_COUNT"), "align" => "right", "default" => true), array("id" => "FILE_SIZE", "content" => GetMessage("CLO_STORAGE_LIST_FILE_SIZE"), "align" => "right", "default" => true), array("id" => "READ_ONLY", "content" => GetMessage("CLO_STORAGE_LIST_MODE"), "align" => "center", "default" => true), array("id" => "SERVICE", "content" => GetMessage("CLO_STORAGE_LIST_SERVICE"), "default" => true), array("id" => "BUCKET", "content" => GetMessage("CLO_STORAGE_LIST_BUCKET"), "align" => "center", "default" => true));
$lAdmin->AddHeaders($arHeaders);
$rsData = CCloudStorageBucket::GetList(array("SORT" => "DESC", "ID" => "ASC"));
$rsData = new CAdminResult($rsData, $sTableID);
while (is_array($arRes = $rsData->Fetch())) {
    $row =& $lAdmin->AddRow($arRes["ID"], $arRes);
    $row->AddViewField("ID", '<a href="clouds_storage_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $arRes["ID"] . '">' . $arRes["ID"] . '</a>');
    if ($arRes["ACTIVE"] === "Y") {
        $html = '<div class="lamp-green"></div>';
    } else {
        $html = '<div class="lamp-red"></div>';
    }
    $row->AddViewField("ACTIVE", $html);
    $row->AddViewField("READ_ONLY", $arRes["READ_ONLY"] === "Y" ? GetMessage("CLO_STORAGE_LIST_READ_ONLY") : GetMessage("CLO_STORAGE_LIST_READ_WRITE"));
    $row->AddViewField("SERVICE", CCloudStorage::GetServiceDescription($arRes["SERVICE_ID"]));
    $row->AddViewField("FILE_SIZE", CFile::FormatSize($arRes["FILE_SIZE"]));
    $arActions = array(array("ICON" => "edit", "DEFAULT" => true, "TEXT" => GetMessage("CLO_STORAGE_LIST_EDIT"), "ACTION" => $lAdmin->ActionRedirect('clouds_storage_edit.php?lang=' . LANGUAGE_ID . '&ID=' . $arRes["ID"])));
    $arActions[] = array("SEPARATOR" => "Y");
    if ($arRes["ACTIVE"] === "Y") {
        if ($arRes["READ_ONLY"] !== "Y") {
            if (intval($arRes["LAST_FILE_ID"]) > 0) {
                $arActions[] = array("TEXT" => GetMessage("CLO_STORAGE_LIST_CONT_MOVE_FILES"), "ACTION" => $lAdmin->ActionDoGroup($arRes["ID"], "move"));
            } else {
                $arActions[] = array("TEXT" => GetMessage("CLO_STORAGE_LIST_START_MOVE_FILES"), "ACTION" => $lAdmin->ActionDoGroup($arRes["ID"], "move"));
            }
        }
        if ($bHasLocalStorage) {
            $arActions[] = array("TEXT" => GetMessage("CLO_STORAGE_LIST_MOVE_LOCAL"), "ACTION" => "if(confirm('" . GetMessage("CLO_STORAGE_LIST_MOVE_LOCAL_CONF") . "')) " . $lAdmin->ActionDoGroup($arRes["ID"], "download"));
        }
        $arActions[] = array("TEXT" => GetMessage("CLO_STORAGE_LIST_DEACTIVATE"), "ACTION" => "if(confirm('" . GetMessage("CLO_STORAGE_LIST_DEACTIVATE_CONF") . "')) " . $lAdmin->ActionDoGroup($arRes["ID"], "deactivate"));