static 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(mb_strlen($Params["site"]) > 2)
{
if (!$USER->CanDoOperation('clouds_browse'))
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied');
return;
}
if($Params['operation'] !== 'O')
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_PATH_CORRUPT').' [clouds 04]', 'path_corrupt');
return;
}
if(!CModule::IncludeModule('clouds'))
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_PATH_CORRUPT').' [clouds 01]', 'path_corrupt');
return;
}
$obBucket = null;
foreach(CCloudStorageBucket::GetAllBuckets() as $arBucket)
{
if($arBucket["ACTIVE"] == "Y" && $arBucket["BUCKET"] === $Params["site"])
$obBucket = new CCloudStorageBucket($arBucket["ID"]);
}
if(!$obBucket)
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_PATH_CORRUPT').' [clouds 02]', 'path_corrupt');
return;
}
if(!$obBucket->Init())
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_PATH_CORRUPT').' [clouds 03]', 'path_corrupt');
return;
}
$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))
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_PATH_CORRUPT').' [clouds 05]', 'path_corrupt');
return;
}
?>
arFDDirs['=$path_js?>'] = [];
arFDFiles['=$path_js?>'] = [];
foreach ($arFiles["dir"] as $ind => $dir)
{
?>
arFDDirs['=$path_js?>'][=$ind?>] =
{
name : '=CUtil::JSEscape($dir)?>',
path : '=CUtil::JSEscape(preg_replace("#[\\\/]+#", "/", $path."/".$dir));?>',
empty: false,
permission : {del : false, ren : false},
date : '',
timestamp : '',
size : 0
};
}
if ($Params['getFiles'])
{
foreach ($arFiles['file'] as $ind => $file)
{
?>
arFDFiles['=$path_js?>'][=$ind?>] =
{
name : '=CUtil::JSEscape($file)?>',
path : '=CUtil::JSEscape($obBucket->GetFileSRC($path."/".$file))?>',
permission : {del : false, ren : false},
date : '',
timestamp : '',
size : '=$arFiles["file_size"][$ind];?>'
};
}
}
?>
arFDPermission['=$path_js?>'] = {
new_folder : false,
upload : false
};
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)
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_PATH_CORRUPT'), 'path_corrupt');
return;
}
elseif (!$USER->CanDoFileOperation('fm_view_listing', array($site, $path)))
{
$APPLICATION->ThrowException(GetMessage('BX_FD_ERROR').': '.GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied');
return;
}
$arDirs = array(); $arFiles = array();
GetDirList(array($site, $path), $arDirs, $arFiles, array(), array("name_nat" => "asc"), "DF", false, true);
?>
arFDDirs['=$path_js?>'] = [];
arFDFiles['=$path_js?>'] = [];
$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) // Find subfolders inside
{
$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['=$path_js?>'][=$ind?>] =
{
name : '=CUtil::JSEscape($name)?>',
path : '=CUtil::JSEscape($path_i)?>',
empty: = $empty ? 'true' : 'false';?>,
permission : {del : =$perm_del?>, ren : =$perm_ren?>},
date : '=$Dir["DATE"];?>',
timestamp : '=$Dir["TIMESTAMP"];?>',
size : 0
};
}
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 = mb_strtolower(GetFileExtension($name));
if (in_array($ext, array('gif','jpg','jpeg','png','jpe','bmp'))) // It is image
{
$upload_dir = COption::GetOptionString("main", "upload_dir", "upload");
$tmbPath = "/".$upload_dir."/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['=$path_js?>'][=$ind?>] =
{
name : '=CUtil::JSEscape($name)?>',
path : '=CUtil::JSEscape($path_i)?>',
permission : {del : =$perm_del?>, ren : =$perm_ren?>},
date : '=$File["DATE"];?>',
timestamp : '=$File["TIMESTAMP"];?>',
size : '=$File["SIZE"];?>'=$imageAddProps?>
};
}
}
$arPath = array($site, $path);
?>
arFDPermission['=$path_js?>'] = {
new_folder : = ($USER->CanDoFileOperation('fm_create_new_folder',$arPath) ? 'true' : 'false');?>,
upload : = ($USER->CanDoFileOperation('fm_upload_file',$arPath) ? 'true' : 'false');?>
};
}