Exemplo n.º 1
0
    function GetItems($Params)
    {
        global $APPLICATION, $USER;
        static $checkChildren, $genTmb;
        if (!isset($checkChildren, $genTmb)) {
            $checkChildren = COption::GetOptionString("fileman", "file_dialog_check_children", "Y") == 'Y';
            $genTmb = COption::GetOptionString("fileman", "file_dialog_gen_thumb", "Y") == 'Y';
        }
        if (strlen($Params["site"]) > 2) {
            if (!$USER->CanDoOperation('clouds_browse')) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied');
            }
            if ($Params['operation'] !== 'O') {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 04]', 'path_corrupt');
            }
            if (!CModule::IncludeModule('clouds')) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 01]', 'path_corrupt');
            }
            $obBucket = null;
            foreach (CCloudStorageBucket::GetAllBuckets() as $arBucket) {
                if ($arBucket["ACTIVE"] == "Y" && $arBucket["BUCKET"] === $Params["site"]) {
                    $obBucket = new CCloudStorageBucket($arBucket["ID"]);
                }
            }
            if (!$obBucket) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 02]', 'path_corrupt');
            }
            if (!$obBucket->Init()) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 03]', 'path_corrupt');
            }
            $path = preg_replace("#[\\\\\\/]+#", "/", "/" . $APPLICATION->UnJSEscape($Params['path']));
            $path_js = $path == "" ? "/" : addslashes(htmlspecialcharsex($path));
            $path_js = str_replace("//", "/", $path_js);
            $arFiles = $obBucket->ListFiles($path);
            if (!is_array($arFiles)) {
                return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 05]', 'path_corrupt');
            }
            ?>
arFDDirs['<?php 
            echo $path_js;
            ?>
'] = [];
arFDFiles['<?php 
            echo $path_js;
            ?>
'] = [];
<?php 
            foreach ($arFiles["dir"] as $ind => $dir) {
                ?>
arFDDirs['<?php 
                echo $path_js;
                ?>
'][<?php 
                echo $ind;
                ?>
] =
{
	name : '<?php 
                echo CUtil::JSEscape($dir);
                ?>
',
	path : '<?php 
                echo CUtil::JSEscape(preg_replace("#[\\\\\\/]+#", "/", $path . "/" . $dir));
                ?>
',
	empty: false,
	permission : {del : false, ren : false},
	date : '',
	timestamp : '',
	size : 0
};
<?php 
            }
            if ($Params['getFiles']) {
                foreach ($arFiles['file'] as $ind => $file) {
                    ?>
arFDFiles['<?php 
                    echo $path_js;
                    ?>
'][<?php 
                    echo $ind;
                    ?>
] =
{
	name : '<?php 
                    echo CUtil::JSEscape($file);
                    ?>
',
	path : '<?php 
                    echo CUtil::JSEscape($obBucket->GetFileSRC($path . "/" . $file));
                    ?>
',
	permission : {del : false, ren : false},
	date : '',
	timestamp : '',
	size : '<?php 
                    echo $arFiles["file_size"][$ind];
                    ?>
'
};
<?php 
                }
            }
            ?>
arFDPermission['<?php 
            echo $path_js;
            ?>
'] = {
	new_folder : false,
	upload : false
};
<?php 
            return;
        }
        $io = CBXVirtualIo::GetInstance();
        $site = $Params['site'];
        $path = $io->CombinePath("/", $APPLICATION->UnJSEscape($Params['path']));
        $path_js = $path == "" ? "/" : addslashes(htmlspecialcharsex($path));
        $path_js = str_replace("//", "/", $path_js);
        $bCheckEmpty = $Params['bCheckEmpty'];
        $rootPath = CSite::GetSiteDocRoot($site);
        if (!$io->FileExists($rootPath . $path) && !$io->DirectoryExists($rootPath . $path) && $Params['bThrowException'] === true) {
            return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT'), 'path_corrupt');
        } elseif (!$USER->CanDoFileOperation('fm_view_listing', array($site, $path))) {
            return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied');
        }
        $arDirs = array();
        $arFiles = array();
        GetDirList(array($site, $path), $arDirs, $arFiles, array(), array("name" => "asc"), "DF", false, true);
        ?>
arFDDirs['<?php 
        echo $path_js;
        ?>
'] = [];
arFDFiles['<?php 
        echo $path_js;
        ?>
'] = [];
<?php 
        $ind = -1;
        foreach ($arDirs as $Dir) {
            $name = addslashes(htmlspecialcharsex($Dir["NAME"]));
            $path_i = addslashes(htmlspecialcharsex($path)) . "/" . $name;
            $path_i = str_replace("//", "/", $path_i);
            $arPath_i = array($site, $path_i);
            if (!$USER->CanDoFileOperation('fm_view_listing', $arPath_i)) {
                continue;
            }
            $ind++;
            $empty = true;
            if ($bCheckEmpty) {
                $dirTmp = $io->GetDirectory($rootPath . $path . '/' . $name);
                $arDirTmpChildren = $dirTmp->GetChildren();
                foreach ($arDirTmpChildren as $child) {
                    if (!$child->IsDirectory()) {
                        continue;
                    }
                    $empty = false;
                    break;
                }
            }
            $perm_del = $USER->CanDoFileOperation('fm_delete_folder', $arPath_i) ? 'true' : 'false';
            $perm_ren = $USER->CanDoFileOperation('fm_rename_folder', $arPath_i) ? 'true' : 'false';
            ?>
arFDDirs['<?php 
            echo $path_js;
            ?>
'][<?php 
            echo $ind;
            ?>
] =
{
	name : '<?php 
            echo $name;
            ?>
',
	path : '<?php 
            echo $path_i;
            ?>
',
	empty: <?php 
            echo $empty ? 'true' : 'false';
            ?>
,
	permission : {del : <?php 
            echo $perm_del;
            ?>
, ren : <?php 
            echo $perm_ren;
            ?>
},
	date : '<?php 
            echo $Dir["DATE"];
            ?>
',
	timestamp : '<?php 
            echo $Dir["TIMESTAMP"];
            ?>
',
	size : 0
};
<?php 
        }
        if ($Params['getFiles']) {
            $ind = -1;
            foreach ($arFiles as $File) {
                $name = addslashes(htmlspecialcharsex($File["NAME"]));
                $path_i = addslashes(htmlspecialcharsex($File["ABS_PATH"]));
                $path_i = str_replace("//", "/", $path_i);
                $arPath_i = array($site, $path_i);
                if (!$USER->CanDoFileOperation('fm_view_file', $arPath_i)) {
                    continue;
                }
                $ind++;
                $perm_del = $USER->CanDoFileOperation('fm_delete_file', $arPath_i) ? 'true' : 'false';
                $perm_ren = $USER->CanDoFileOperation('fm_rename_file', $arPath_i) ? 'true' : 'false';
                $imageAddProps = '';
                if ($genTmb) {
                    $ext = strtolower(GetFileExtension($name));
                    if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'jpe', 'bmp'))) {
                        $tmbPath = BX_PERSONAL_ROOT . "/tmp/fd_tmb" . $path_i;
                        $destinationFile = $rootPath . $tmbPath;
                        if (!file_exists($destinationFile)) {
                            $sourceFile = $File['PATH'];
                            if (CFile::ResizeImageFile($sourceFile, $destinationFile, array('width' => 140, 'height' => 110))) {
                                $imageAddProps = ",\n" . 'tmb_src : \'' . CUtil::JSEscape($tmbPath) . '\'';
                            }
                        } else {
                            $imageAddProps = ",\n" . 'tmb_src : \'' . CUtil::JSEscape($tmbPath) . '\'';
                        }
                    }
                }
                ?>
arFDFiles['<?php 
                echo $path_js;
                ?>
'][<?php 
                echo $ind;
                ?>
] =
{
	name : '<?php 
                echo $name;
                ?>
',
	path : '<?php 
                echo $path_i;
                ?>
',
	permission : {del : <?php 
                echo $perm_del;
                ?>
, ren : <?php 
                echo $perm_ren;
                ?>
},
	date : '<?php 
                echo $File["DATE"];
                ?>
',
	timestamp : '<?php 
                echo $File["TIMESTAMP"];
                ?>
',
	size : '<?php 
                echo $File["SIZE"];
                ?>
'<?php 
                echo $imageAddProps;
                ?>
};
<?php 
            }
        }
        $arPath = array($site, $path);
        ?>
arFDPermission['<?php 
        echo $path_js;
        ?>
'] = {
	new_folder : <?php 
        echo $USER->CanDoFileOperation('fm_create_new_folder', $arPath) ? 'true' : 'false';
        ?>
,
	upload : <?php 
        echo $USER->CanDoFileOperation('fm_upload_file', $arPath) ? 'true' : 'false';
        ?>
};
<?php 
    }
Exemplo n.º 2
0
 public static function DeleteDirFilesEx($path)
 {
     $path = rtrim($path, "/") . "/";
     foreach (CCloudStorageBucket::GetAllBuckets() as $bucket) {
         $obBucket = new CCloudStorageBucket($bucket["ID"]);
         if ($obBucket->Init()) {
             $arCloudFiles = $obBucket->ListFiles($path, true);
             if (is_array($arCloudFiles["file"])) {
                 foreach ($arCloudFiles["file"] as $i => $file_name) {
                     $tmp = $obBucket->DeleteFile($path . $file_name);
                     if ($tmp) {
                         $obBucket->DecFileCounter($arCloudFiles["file_size"][$i]);
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
$sTableID = "tbl_clouds_file_search";
$lAdmin = new CAdminList($sTableID);
$lAdmin->InitFilter(array("bucket", "path"));
$path = isset($_GET["path"]) ? $_GET["path"] : $path;
$path = preg_replace("#[\\\\\\/]+#", "/", "/" . $path . "/");
$n = preg_replace("/[^a-zA-Z0-9_:\\[\\]]/", "", $_GET["n"]);
if (intval($bucket) <= 0 && count($arBuckets) == 1) {
    $bucket = $bucket_id;
}
//TODO when there is only one cloud storage there is no need for filter or at least we can preset it
$arHeaders = array(array("id" => "FILE_NAME", "content" => GetMessage("CLO_STORAGE_SEARCH_NAME"), "default" => true), array("id" => "FILE_SIZE", "content" => GetMessage("CLO_STORAGE_SEARCH_SIZE"), "align" => "right", "default" => true));
$lAdmin->AddHeaders($arHeaders);
$arData = array();
$obBucket = new CCloudStorageBucket($bucket);
if ($obBucket->Init() && $_GET["file"] !== "y") {
    $arFiles = $obBucket->ListFiles($path);
    if ($path != "/") {
        $arData[] = array("ID" => "D..", "TYPE" => "dir", "NAME" => "..", "SIZE" => "");
    }
    if (is_array($arFiles)) {
        foreach ($arFiles["dir"] as $i => $dir) {
            $arData[] = array("ID" => "D" . $dir, "TYPE" => "dir", "NAME" => $dir, "SIZE" => '');
        }
        foreach ($arFiles["file"] as $i => $file) {
            $arData[] = array("ID" => "F" . $file, "TYPE" => "file", "NAME" => $file, "SIZE" => $arFiles["file_size"][$i]);
        }
    } else {
        $e = $APPLICATION->GetException();
        if (is_object($e)) {
            $message = new CAdminMessage(GetMessage("CLO_STORAGE_SEARCH_LIST_ERROR"), $e);
        }
Exemplo n.º 4
0
 function GetBucketFileList($BUCKET_ID, $path)
 {
     static $CACHE;
     if ($CACHE[$BUCKET_ID]) {
         $obBucket = $CACHE[$BUCKET_ID];
     } else {
         $CACHE[$BUCKET_ID] = $obBucket = new CCloudStorageBucket($BUCKET_ID);
     }
     if ($obBucket->Init()) {
         return $obBucket->ListFiles($path);
     }
     return false;
 }
Exemplo n.º 5
0
	public static function GetBucketFileList($BUCKET_ID, $path)
	{
		static $CACHE;

		if ($CACHE[$BUCKET_ID])
			$obBucket = $CACHE[$BUCKET_ID];
		else
			$CACHE[$BUCKET_ID] = $obBucket = new CCloudStorageBucket($BUCKET_ID);

		if ($obBucket->Init())
			return $obBucket->ListFiles($path);
		return false;
	}
Exemplo n.º 6
0
 switch ($action) {
     case "delete":
         if (substr($ID, 0, 1) === "F") {
             $file_size = $obBucket->GetFileSize($path . substr($ID, 1));
             if (!$obBucket->DeleteFile($path . substr($ID, 1))) {
                 $e = $APPLICATION->GetException();
                 if (is_object($e)) {
                     $lAdmin->AddUpdateError($e->GetString(), $ID);
                 } else {
                     $lAdmin->AddUpdateError(GetMessage("CLO_STORAGE_FILE_UNKNOWN_ERROR", array("#CODE#" => "D01")), $ID);
                 }
             } else {
                 $obBucket->DecFileCounter($file_size);
             }
         } elseif (substr($ID, 0, 1) === "D") {
             $arFiles = $obBucket->ListFiles($path . substr($ID, 1), true);
             foreach ($arFiles["file"] as $i => $file) {
                 if (!$obBucket->DeleteFile($path . substr($ID, 1) . "/" . $file)) {
                     $e = $APPLICATION->GetException();
                     if (is_object($e)) {
                         $lAdmin->AddUpdateError($e->GetString(), $ID);
                     } else {
                         $lAdmin->AddUpdateError(GetMessage("CLO_STORAGE_FILE_UNKNOWN_ERROR", array("#CODE#" => "D02")), $ID);
                     }
                     break;
                 } else {
                     $obBucket->DecFileCounter($arFiles["file_size"][$i]);
                 }
             }
         }
         break;