array(
"exts" => array("css"),
"gtype" => "text",
"name" => GetMessage("MAIN_BFSD_FTYPE_CSS")
),
"htaccess" => array(
"exts" => array("htaccess"),
"gtype" => "text",
"name" => GetMessage("MAIN_BFSD_FTYPE_SYS")
),
"html" => array(
"exts" => array("html", "htm", "shtml", "shtm"),
"gtype" => "text",
"name" => GetMessage("MAIN_BFSD_FTYPE_HTML")
),
"png" => array(
"exts" => array("png"),
"gtype" => "image",
"name" => GetMessage("MAIN_BFSD_FTYPE_PNG")
),
"gif" => array(
"exts" => array("gif"),
"gtype" => "image",
"name" => GetMessage("MAIN_BFSD_FTYPE_GIF")
),
"jpeg" => array(
"exts" => array("jpeg", "jpg", "jpe"),
"gtype" => "image",
"name" => GetMessage("MAIN_BFSD_FTYPE_JPG")
),
"js" => array(
"exts" => array("js"),
"gtype" => "text",
"name" => "JavaScript"
),
"php" => array(
"exts" => array("php", "php3", "php4", "php5", "php6", "phtml"),
"gtype" => "text",
"name" => GetMessage("MAIN_BFSD_FTYPE_PHP")
),
"txt" => array(
"exts" => array("txt", "sql"),
"gtype" => "text",
"name" => GetMessage("MAIN_BFSD_FTYPE_TXT")
),
"xml" => array(
"exts" => array("xml", "xsl"),
"gtype" => "text",
"name" => GetMessage("MAIN_BFSD_FTYPE_XML")
),
"csv" => array(
"exts" => array("csv"),
"gtype" => "text",
"name" => GetMessage("MAIN_BFSD_FTYPE_CSV")
),
"flash" => array(
"exts" => array("fla", "swf"),
"gtype" => "file",
"name" => GetMessage("MAIN_BFSD_FTYPE_SWF")
),
"archive" => array(
"exts" => CBXArchive::GetArchiveExtensions(),
"gtype" => "file",
"name" => GetMessage("MAIN_BFSD_FTYPE_ARC")
),
"file" => array(
"exts" => array(),
"gtype" => "file",
"name" => GetMessage("MAIN_BFSD_FTYPE_NA")
)
);
// AddEventHandler("fileman", "OnBeforeHTMLEditorScriptsGet", "bitrix_tabs");
// function bitrix_tabs($editorName, $arEditorParams){return array("JS" => array('bitrix_tabs.js'));}
class CFileMan
{
public static function OnPanelCreate()
{
global $APPLICATION;
if($APPLICATION->GetGroupRight("fileman")<="D")
return;
$requestUri = $_SERVER['REQUEST_URI'];
$cur_page = $APPLICATION->GetCurPage(true);
$cur_dir = $APPLICATION->GetCurDir();
//access to curent page
$page_permission = $APPLICATION->GetFileAccessPermission($cur_page);
// access to current directory
$sect_permission = $APPLICATION->GetFileAccessPermission($cur_dir);
$main_sort = 100;
$full_src = "";
$default_edit = COption::GetOptionString("fileman", "default_edit");
if($default_edit == "php")
{
$editor_type = "file";
$full_src = "&full_src=Y";
}
elseif($default_edit == "text")
$editor_type = "file";
else
$editor_type = "html";
$aMenuItems = array(
'create' => array(),
'create_section' => array(),
'edit' => array(),
'edit_section' => array()
);
if ($sect_permission>="W")
{
// New page
$href = "/bitrix/admin/fileman_".$editor_type."_edit.php?lang=".LANGUAGE_ID."&site=".SITE_ID."&path=".UrlEncode($APPLICATION->GetCurDir())."&new=Y&templateID=".urlencode(SITE_TEMPLATE_ID)."&back_url=".UrlEncode($requestUri);
$APPLICATION->AddPanelButtonMenu('create', array("SEPARATOR"=>true, "SORT"=>99));
$APPLICATION->AddPanelButtonMenu('create', array(
"TEXT" => GetMessage("fileman_panel_admin"),
"TITLE"=> GetMessage("fileman_panel_new_page_title"),
"ACTION" => "jsUtils.Redirect([], '".CUtil::JSEscape($href)."')",
"SORT" => 100
));
//New folder
$href = "/bitrix/admin/fileman_newfolder.php?lang=".LANGUAGE_ID."&site=".SITE_ID."&path=". UrlEncode($APPLICATION->GetCurDir())."&back_url=".UrlEncode($requestUri);
$APPLICATION->AddPanelButtonMenu('create_section', array("SEPARATOR"=>true, "SORT"=>99));
$APPLICATION->AddPanelButtonMenu('create_section', array(
"TEXT" => GetMessage("fileman_panel_admin"),
"TITLE"=> GetMessage("fileman_panel_new_folder_title"),
"ACTION" => "jsUtils.Redirect([], '".CUtil::JSEscape($href)."')",
));
}
// Edit page
if ($page_permission>="W")
{
$href = "/bitrix/admin/fileman_".$editor_type."_edit.php?lang=".LANGUAGE_ID."&site=".SITE_ID."&templateID=".urlencode(SITE_TEMPLATE_ID).$full_src."&path=".UrlEncode(isset($_SERVER["REAL_FILE_PATH"]) && $_SERVER["REAL_FILE_PATH"]<>""? $_SERVER["REAL_FILE_PATH"] : $cur_page)."&back_url=".UrlEncode($requestUri);
$APPLICATION->AddPanelButtonMenu('edit', array("SEPARATOR"=>true, "SORT"=>99));
$APPLICATION->AddPanelButtonMenu('edit', array(
"TEXT" => GetMessage("fileman_panel_admin"),
"TITLE"=> GetMessage("fileman_panel_edit_title"),
"ACTION" => "jsUtils.Redirect([], '".CUtil::JSEscape($href)."')",
"SORT" => 100
));
}
// Folder properties
$alt = GetMessage("FILEMAN_FOLDER_PROPS");
if ($sect_permission>="W")
{
$href = "/bitrix/admin/fileman_folder.php?lang=".LANGUAGE_ID."&site=".SITE_ID."&path=".UrlEncode($APPLICATION->GetCurDir())."&back_url=".UrlEncode($requestUri);
$APPLICATION->AddPanelButtonMenu('edit_section', array("SEPARATOR"=>true, "SORT"=>99));
$APPLICATION->AddPanelButtonMenu('edit_section', array(
"TEXT" => GetMessage("fileman_panel_admin"),
"TITLE"=> GetMessage("fileman_panel_folder_prop_title"),
"ACTION" => "jsUtils.Redirect([], '".CUtil::JSEscape($href)."')",
"SORT"=>100,
));
}
//Sticker buttons
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/classes/general/sticker.php");
if (CSticker::CanDoOperation('sticker_view'))
{
$useHotKeys = COption::GetOptionString('fileman', "stickers_use_hotkeys", "Y") == "Y";
$arMenu = array();
if (CSticker::CanDoOperation('sticker_new'))
{
$arMenu[] = [
"TEXT" => GetMessage("FMST_PANEL_STICKER_ADD").($useHotKeys ? ' (Ctrl+Shift+S)' : ''),
"TITLE" => GetMessage("FMST_PANEL_STICKER_ADD_TITLE"),
"ICON" => "",
"ACTION" => CSticker::GetScriptStr('add'),
"DEFAULT" => true,
"HK_ID" => "FMST_PANEL_STICKER_ADD",
];
$arMenu[] = ["SEPARATOR" => true];
}
$curPageCount = CSticker::GetCurPageCount();
$arMenu[] = array(
"ID" => "bxst-show-sticker-icon",
"TEXT" => GetMessage("FMST_PANEL_STICKERS_SHOW", array("#COUNT#" => $curPageCount)).($useHotKeys ? ' (Ctrl+Shift+X)' : ''),
"TITLE" => GetMessage("FMST_PANEL_STICKERS_SHOW_TITLE"),
"ICON" => CSticker::GetBShowStickers() ? " checked" : "",
"ACTION" => CSticker::GetScriptStr('show'),
"HK_ID"=>"FMST_PANEL_STICKERS_SHOW",
);
$arMenu[] = array(
"TEXT" => GetMessage("FMST_PANEL_CUR_STICKER_LIST").($useHotKeys ? ' (Ctrl+Shift+L)' : ''),
"TITLE" => GetMessage("FMST_PANEL_CUR_STICKER_LIST_TITLE"),
"ICON" => "",
"ACTION" => CSticker::GetScriptStr('list_cur'),
"HK_ID"=>"FMST_PANEL_CUR_STICKER_LIST",
);
$arMenu[] = array(
"TEXT" => GetMessage("FMST_PANEL_ALL_STICKER_LIST"),
"TITLE" => GetMessage("FMST_PANEL_ALL_STICKER_LIST_TITLE"),
"ICON" => "",
"ACTION" => CSticker::GetScriptStr('list_all'),
"HK_ID"=>"FMST_PANEL_ALL_STICKER_LIST",
);
$APPLICATION->AddPanelButton(array(
"HREF" => 'javascript:'.(CSticker::CanDoOperation('sticker_edit') ? CSticker::GetScriptStr('add') : CSticker::GetScriptStr('show')),
"TYPE" => "SMALL",
"ICON" => "bx-panel-small-stickers-icon",
"TEXT" => GetMessage("FMST_PANEL_STICKERS_TOOLTIP_TITLE"),
"MAIN_SORT" => "1000",
"SORT" => 100,
"MENU" => $arMenu,
"HK_ID"=>"FMST_PANEL_STICKERS",
"HINT" => array(
"TITLE" => CSticker::CanDoOperation('sticker_edit') ? GetMessage("FMST_PANEL_STICKERS_TOOLTIP_TITLE") : GetMessage("FMST_PANEL_STICKERS_SHOW_1"),
"TEXT" => CSticker::CanDoOperation('sticker_edit') ? GetMessage("FMST_PANEL_STICKERS_TOOLTIP").($useHotKeys ? " (Ctrl+Shift+S)" : "") : GetMessage("FMST_PANEL_STICKERS_ALT").($useHotKeys ? " (Ctrl+Shift+X)" : "")
)
));
CSticker::Init(array('curPageCount' => $curPageCount));
}
}
public static function OnGroupDelete($group_id)
{
return "";
}
public static function GetVersion()
{
@include($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/install/version.php");
if (!isset($arModuleVersion['VERSION']))
return false;
return $arModuleVersion['VERSION'];
}
public static function SaveMenu($path, $aMenuLinksTmp, $sMenuTemplateTmp = "")
{
global $APPLICATION;
CMain::InitPathVars($site, $path);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
$strMenuLinks = "";
if($sMenuTemplateTmp <> '')
$strMenuLinks .= "\$sMenuTemplate = \"".CFileMan::EscapePHPString($sMenuTemplateTmp)."\";\n";
$strMenuLinks .= "\$aMenuLinks = Array(";
$i=0;
foreach($aMenuLinksTmp as $arMenuItem)
{
$i++;
$strMenuLinksTmp = "";
if($i>1)
$strMenuLinksTmp .= ",";
$strMenuLinkHref = $arMenuItem[1] ?? '';
$strMenuLinksTmp .= "\n".
" Array(\n".
" \"".CFileMan::EscapePHPString(($arMenuItem[0] ?? null))."\", \n".
" \"".CFileMan::EscapePHPString($strMenuLinkHref)."\", \n".
" Array(";
if(is_array(($arMenuItem[2] ?? null)))
{
for($j = 0, $l = count(($arMenuItem[2] ?? [])); $j < $l; $j++)
{
if($j>0)
$strMenuLinksTmp .= ", ";
$strMenuLinksTmp .= "\"".CFileMan::EscapePHPString($arMenuItem[2][$j] ?? null)."\"";
}
}
$strMenuLinksTmp .= "), \n";
$strMenuLinksTmp .= " Array(";
if(is_array($arMenuItem[3] ?? null))
{
$arParams = array_keys($arMenuItem[3]);
for($j = 0, $l = count($arParams); $j < $l; $j++)
{
if($j>0)
$strMenuLinksTmp .= ", ";
$strMenuLinksTmp .= "\"".CFileMan::EscapePHPString($arParams[$j])."\"=>"."\"".CFileMan::EscapePHPString($arMenuItem[3][$arParams[$j]])."\"";
}
}
$strMenuLinksTmp .= "), \n".
" \"".CFileMan::EscapePHPString($arMenuItem[4] ?? null)."\" \n".
" )";
$strMenuLinks .= $strMenuLinksTmp;
}
$strMenuLinks .= "\n);";
$APPLICATION->SaveFileContent($DOC_ROOT.$path, "<"."?\n".$strMenuLinks."\n?".">");
$GLOBALS["CACHE_MANAGER"]->CleanDir("menu");
CBitrixComponent::clearComponentCache("bitrix:menu");
}
public static function GetMenuArray($abs_path)
{
$aMenuLinks = Array();
$sMenuTemplate = '';
$io = CBXVirtualIo::GetInstance();
if ($io->FileExists($abs_path))
{
global $APPLICATION;
$arrMenuContent = $APPLICATION->GetFileContent($io->GetPhysicalName($abs_path));
$arrMenuContent = str_replace([''], '', $arrMenuContent);
if (SITE_DIR === '')
{
$arrMenuContent = str_replace('SITE_DIR."', '"/', $arrMenuContent);
}
eval($arrMenuContent);
}
return Array("aMenuLinks"=>$aMenuLinks, "sMenuTemplate" => $sMenuTemplate);
}
public static function GetFileName($path)
{
return GetFileName($path);
}
public static function CreateDir($path)
{
CMain::InitPathVars($site, $path);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
if (DEBUG_FILE_MAN) echo "CreateDir($path);
";
global $APPLICATION, $USER;
$badDirs=Array();
$io = CBXVirtualIo::GetInstance();
$path = $io->CombinePath($path);
$p = mb_strrpos($path ?? '', "/");
while($p!==false)
{
$dir = $io->GetDirectory($DOC_ROOT.$path);
if($dir->IsExists())
{
$dir->MarkWritable();
break;
}
$badDirs[] = mb_substr($path, $p + 1);
$path = mb_substr($path, 0, $p);
$p = mb_strrpos($path, "/");
}
for($i = count($badDirs) - 1; $i >= 0; $i--)
{
$path = $path."/".$badDirs[$i];
if(!$USER->CanDoFileOperation('fm_create_new_folder', Array($site,$path)))
return GetMessage("FILEMAN_FILEMAN_CREATE_FOLDER_DENY")." \"".$path."\".\n";
if (($mess = CFileMan::CheckFileName($badDirs[$i])) !== true)
return $mess;
if (!$io->CreateDirectory($DOC_ROOT.$path))
return GetMessage("FILEMAN_CREATE_FOLDER_ERROR", array('#PATH#' => htmlspecialcharsex($path)));
}
}
//Function check if there are anything exept .access.php and if folder is empty - delete it
public static function DeleteDir($path)
{
if(DEBUG_FILE_MAN)echo "DeleteDir(".$path.");
";
CMain::InitPathVars($site, $path);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
$io = CBXVirtualIo::GetInstance();
global $APPLICATION, $USER;
if(trim($path) == '')
return GetMessage("FILEMAN_FILEMAN_TRYING_ROOT_DELETE")."\n";
if(!$io->DirectoryExists($DOC_ROOT.$path))
return GetMessage("FILEMAN_FILEMAN_FOLDER")." \"$path\" ".GetMessage("FILEMAN_FILEMAN_NOT_EXISTS")."\n";
//check rights to write for this subfolder
if(!$USER->CanDoFileOperation('fm_delete_folder', Array($site,$path)))
return GetMessage("FILEMAN_FILEMAN_FOLDER_DEL_DENY")."\" ".$path."\".\n";
$d = $io->GetDirectory($DOC_ROOT.$path);
$arChildren = $d->GetChildren();
foreach ($arChildren as $child)
{
if (!$child->IsDirectory() && $child->GetName() != ".access.php")
return GetMessage("FILEMAN_FILEMAN_FOLDER_DEL_ERROR")." \"".$path."\" ".GetMessage("FILEMAN_FILEMAN_FOLDER_NOT_EMPTY").".\n";
}
//it's ok ... BUMP OFF!!!
if ($io->FileExists($DOC_ROOT.$path."/.access.php"))
{
$f = $io->GetFile($DOC_ROOT.$path."/.access.php");
$f->MarkWritable();
$io->Delete($DOC_ROOT.$path."/.access.php");
}
$d->MarkWritable();
if(DEBUG_FILE_MAN)echo "rmdir(".$path.");";
if(!$io->Delete($DOC_ROOT.$path))
return GetMessage("FILEMAN_FILEMAN_FOLDER_DEL_ERROR")." \"".$path."\".\n";
$APPLICATION->RemoveFileAccessPermission(Array($site, $path));
}
public static function DeleteFile($path)
{
global $APPLICATION, $USER;
CMain::InitPathVars($site, $path);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
$io = CBXVirtualIo::GetInstance();
if(!$io->FileExists($DOC_ROOT.$path))
return GetMessage("FILEMAN_FILEMAN_FILE")." \"$path\" ".GetMessage("FILEMAN_FILEMAN_NOT_EXISTS")."\n";
if(mb_strlen($path) >= 12 && mb_substr($path, mb_strlen($path) - 12) == "/.access.php")
return;
//check: can we delete this file
if(!$USER->CanDoFileOperation('fm_delete_file', Array($site,$path)))
return GetMessage("FILEMAN_FILEMAN_FILE_DEL_DENY")." \"".$path."\".\n";
$f = $io->GetFile($DOC_ROOT.$path);
$f->MarkWritable();
//deleting file
if(DEBUG_FILE_MAN)echo "unlink(".$DOC_ROOT.$path.");
";
$file_size = $f->GetFileSize();
if($io->Delete($DOC_ROOT.$path))
{
$APPLICATION->RemoveFileAccessPermission(Array($site, $path));
if(CModule::IncludeModule("search"))
CSearch::DeleteIndex("main", $site."|".$path);
//************************** Quota **************************//
if(COption::GetOptionInt("main", "disk_space") > 0)
{
$quota = new CDiskQuota();
$quota->updateDiskQuota("file", $file_size, "delete");
}
//************************** Quota **************************//
}
}
public static function DeleteEx($path)
{
global $APPLICATION, $USER;
CMain::InitPathVars($site, $path);
if($path == '')
return false;
$src = $_SERVER["DOCUMENT_ROOT"].$path;
$src = str_replace("//","/",$src);
if($src == $_SERVER["DOCUMENT_ROOT"])
return false;
$DOC_ROOT = CSite::GetSiteDocRoot($site);
@set_time_limit(600);
$io = CBXVirtualIo::GetInstance();
if(is_link($linkPath = CBXVirtualIoFileSystem::ConvertCharset($DOC_ROOT.$path))) //if delete symb. link todo: windows, can't delete links on dirs
{
if(@unlink($linkPath))
return;
else
return GetMessage("FILEMAN_FILEMAN_SYMLINK_DEL_ERROR")." \"".$path."\".\n";
}
elseif($io->DirectoryExists($DOC_ROOT.$path))//if delete folder
{
//check rights
if(!$USER->CanDoFileOperation('fm_delete_folder', Array($site,$path)))
return GetMessage("FILEMAN_FILEMAN_FOLDER_DEL_DENY")." \"".$path."\".\n";
}
else //if delete file
{
return CFileman::DeleteFile(Array($site, $path));
}
$strWarning = "";
//get folder content
$d = $io->GetDirectory($DOC_ROOT.$path);
$arChildren = $d->GetChildren();
foreach ($arChildren as $child)
{
$fn = $child->GetName();
if ($child->IsDirectory())
{
$strWarning .= CFileman::DeleteEx(Array($site, $path."/".$fn));
}
else
{
if($fn == ".access.php") continue;
$strWarning .= CFileman::DeleteFile(Array($site, $path."/".$fn));
}
}
//delete first folder
$strWarning .= CFileMan::DeleteDir(Array($site, $path));
return $strWarning;
}
public static function NormalizePath($path)
{
$io = CBXVirtualIo::GetInstance();
return $io->CombinePath("/", $path);
}
public static function CopyEx($path_from, $path_to, $bDeleteAfterCopy = false, $bOverride = false)
{
global $APPLICATION, $USER;
CMain::InitPathVars($site_from, $path_from);
$DOC_ROOT_FROM = CSite::GetSiteDocRoot($site_from);
CMain::InitPathVars($site_to, $path_to);
$DOC_ROOT_TO = CSite::GetSiteDocRoot($site_to);
$strWarning = '';
$path_from = Rel2Abs('/', $path_from);
$path_to = Rel2Abs('/', $path_to);
//check: if we copy to the same directory
if(mb_strpos($DOC_ROOT_TO.$path_to."/", $DOC_ROOT_FROM.$path_from."/") === 0)
return GetMessage("FILEMAN_LIB_BAD_FOLDER").": \"".$path_from."\".\n";
$io = CBXVirtualIo::GetInstance();
if($io->DirectoryExists($DOC_ROOT_FROM.$path_from))// Copy folder
{
// Minimal access - read/listing for copying files
if(!$USER->CanDoFileOperation('fm_view_listing', Array($site_from, $path_from)))
return GetMessage("FILEMAN_FILEMAN_FOLDER_READ_DENY")." \"".$path_from."\".\n";
if ($bDeleteAfterCopy && !$USER->CanDoFileOperation('fm_delete_folder', Array($site_from, $path_from)))
return GetMessage("FILEMAN_FILEMAN_FOLDER_DEL_DENY")." \"".$path_from."\".\n";
//Check: folder exist or not
$strWarTmp = CFileMan::CreateDir(Array($site_to, $path_to));
if($strWarTmp <> '')
return $strWarTmp;
$APPLICATION->CopyFileAccessPermission(Array($site_from, $path_from), Array($site_to, $path_to));
}
else // Copy file
{
// If we can write this file
if (!$USER->CanDoFileOperation('fm_create_new_file', Array($site_to, $path_to)))
return GetMessage("FILEMAN_FILEMAN_FILE_WRITE_DENY")." \"".$path_to."\".\n";
// If we can't read source-file
if(!$USER->CanDoFileOperation('fm_view_file', Array($site_from, $path_from)))
return GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY")." \"".$path_from."\".\n";
// Copying php or system file without PHP or LPA access
if (!($USER->CanDoOperation('edit_php') || $USER->CanDoFileOperation('fm_lpa', [$site_from, $path_from]) || !(HasScriptExtension($path_from) || mb_substr($path_from, 0, 1) == ".")))
{
return GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY")." \"".$path_from."\".\n";
}
// If we can't move source-file
if($bDeleteAfterCopy && !$USER->CanDoFileOperation('fm_delete_file', Array($site_from, $path_from)))
return GetMessage("FILEMAN_FILEMAN_FILE_DEL_DENY")." \"".$path_from."\".\n";
//Check if folder already exist and trying to create if not
$p = mb_strrpos($path_to, "/");
$path_to_dir = mb_substr($path_to, 0, $p);
$strWarTmp = CFileMan::CreateDir(Array($site_to, $path_to_dir));
if($strWarTmp <> '')
return $strWarTmp;
if($io->FileExists($DOC_ROOT_TO.$path_to) || $io->DirectoryExists($DOC_ROOT_TO.$path_to))
{
if ($bOverride)
{
$strWarn = CFileMan::DeleteEx(Array($site_to, $path_to));
if ($strWarn != "")
return $strWarn;
}
else
{
return GetMessage("FILEMAN_FILEMAN_FILE_WITH_NAME")." \"".$path_to."\" ".GetMessage("FILEMAN_FILEMAN_ALREADY_EXISTS")."!\n";
}
}
$APPLICATION->CopyFileAccessPermission(Array($site_from, $path_from), Array($site_to, $path_to));
//************************** Quota **************************//
if(COption::GetOptionInt("main", "disk_space") > 0)
{
$f = $io->GetFile($DOC_ROOT_FROM.$path_from);
$size = $f->GetFileSize();
$quota = new CDiskQuota();
if (!$quota->checkDiskQuota(array("FILE_SIZE"=>$size)))
return $quota->LAST_ERROR;
}
//************************** Quota **************************//
// Copy file
if(DEBUG_FILE_MAN)
echo "copy(".$DOC_ROOT_FROM.$path_from.",".$DOC_ROOT_TO.$path_to.");
";
if (!$io->Copy($DOC_ROOT_FROM.$path_from, $DOC_ROOT_TO.$path_to))
$strWarning .= GetMessage('FILEMAN_COPY_ERROR', array('#PATH_FROM#' => htmlspecialcharsex($path_from), '#PATH_TO#' => htmlspecialcharsex($path_to)));
//************************** Quota **************************//
if(COption::GetOptionInt("main", "disk_space") > 0)
$quota->updateDiskQuota("file", $size, "copy");
//************************** Quota **************************//
if(CModule::IncludeModule("search"))
{
$site = CSite::GetSiteByFullPath($DOC_ROOT_TO.$path_to);
CSearch::ReIndexFile(Array($site_to, $path_to), $site);
}
if($bDeleteAfterCopy && $strWarning == '') // If was command "delete after copy"?
$strWarning .= CFileMan::DeleteFile(Array($site_from, $path_from));
return $strWarning;
}
// Recursive
$d = $io->GetDirectory($DOC_ROOT_FROM.$path_from);
$arChildren = $d->GetChildren();
foreach ($arChildren as $child)
{
$fn = $child->GetName();
if($child->IsDirectory()) //if this is subfolder
{
//go to recursion
$strWarning .= CFileMan::CopyEx(Array($site_from, $path_from."/".$fn), Array($site_to, $path_to."/".$fn), $bDeleteAfterCopy, $bOverride);
//back from recursion, in this subfolder all right
//if($bDeleteAfterCopy) //necessary delete this subfolder
// $strWarning .= CFileMan::DeleteDir($path_from."/".$file);
}
else //this is "subfile" :-)
{
if($fn == ".access.php")
continue;
//let's check, if we can to write there
if(!$USER->CanDoFileOperation('fm_create_new_file', Array($site_to, $path_to."/".$fn)))
$strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_WRITE_DENY")." \"".$path_to."/".$fn."\".\n";
//let's check, if we can read from there
elseif(!$USER->CanDoFileOperation('fm_view_file', Array($site_from, $path_from."/".$fn)))
$strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY")." \"".$path_from."/".$fn."\".\n";
elseif (!($USER->CanDoOperation('edit_php') || $USER->CanDoFileOperation('fm_lpa', Array($site_from, $path_from."/".$fn)) || !(HasScriptExtension($fn) || mb_substr($fn, 0, 1) == ".")))
$strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_READ_DENY")." \"".$path_from."/".$fn."\".\n";
else
{
if($io->FileExists($DOC_ROOT_TO.$path_to."/".$fn))
{
if ($bOverride)
{
$strWarn = CFileMan::DeleteEx(Array($site_to, $path_to."/".$fn));
if ($strWarn != "")
$strWarning .= $strWarn."\n";
}
else
{
$strWarning .= GetMessage("FILEMAN_FILEMAN_FILE_WITH_NAME")." \"".$path_to."/".$fn."\" ".GetMessage("FILEMAN_FILEMAN_ALREADY_EXISTS")."!\n";
}
}
if ($strWarning == "")
{
//it means we can copy, if we found here
$APPLICATION->CopyFileAccessPermission(Array($site_from, $path_from."/".$fn), Array($site_to, $path_to."/".$fn));
if(DEBUG_FILE_MAN)
echo "copy(".$DOC_ROOT_FROM.$path_from."/".$fn.",".$DOC_ROOT_TO.$path_to."/".$fn.");
";
if (!$io->Copy($DOC_ROOT_FROM.$path_from."/".$fn, $DOC_ROOT_TO.$path_to."/".$fn))
$strWarning .= GetMessage('FILEMAN_COPY_ERROR', array('#PATH_FROM#' => htmlspecialcharsex($path_from."/".$fn), '#PATH_TO#' => htmlspecialcharsex($path_to."/".$fn)));
//************************** Quota **************************//
if(COption::GetOptionInt("main", "disk_space") > 0)
{
$f = $io->GetFile($DOC_ROOT_TO.$path_to."/".$fn);
$quota = new CDiskQuota();
$quota->updateDiskQuota("file", $f->GetFileSize(), "copy");
}
//************************** Quota **************************//
if(CModule::IncludeModule("search"))
{
$site = CSite::GetSiteByFullPath($DOC_ROOT_TO, $path_to."/".$fn);
CSearch::ReindexFile($path_to."/".$fn, $site);
}
if($bDeleteAfterCopy && $strWarning == '')
{
$strWarning .= CFileMan::DeleteFile(Array($site_from, $path_from."/".$fn));
}
}
}
}
}
//we may be need, to delete our initial folder
if($bDeleteAfterCopy)
$strWarning .= CFileMan::DeleteDir(Array($site_from, $path_from));
return $strWarning;
}
public static function GetAllDirList(&$arDirs, $arFilter=Array(), $site=false)
{
$arFiles = array();
CFileMan::DirsRecursive(Array($site, ""), $arDirs, $arFilter, 0);
}
public static function DirsRecursive($path, &$arDirs, $arFilter=Array(), $depth=0)
{
$depth++;
CFileMan::GetDirList($path, $arDirsTmp, $arFiles, $arFilter, Array("name"=>"asc"), "D");
for($i = 0, $l = count($arDirsTmp); $i < $l; $i++)
{
$arDir = $arDirsTmp[$i];
$arDir["DEPTH_LEVEL"] = $depth;
$arDirs[] = $arDir;
CFileMan::DirsRecursive($arDir["ABS_PATH"], $arDirs, $arFilter, $depth);
}
}
public static function CompareFiles($f1, $f2, $sort=Array())
{
return CompareFiles($f1, $f2, $sort);
}
public static function GetDirList($path, &$arDirs, &$arFiles, $arFilter=Array(), $sort=Array(), $type="DF", $bLogical=false, $task_mode=false)
{
return GetDirList($path, $arDirs, $arFiles, $arFilter, $sort, $type, $bLogical,$task_mode);
}
public static function __CheckSite($site)
{
if($site !== false)
{
if($site <> '')
{
$res = CSite::GetByID($site);
if($arSite = $res->Fetch())
$site = $arSite['ID'];
else
$site = false;
}
else
$site = false;
}
return $site;
}
public static function ParsePath($path, $bLast=false, $url=false, $param="", $bLogical = false)
{
return ParsePath($path, $bLast, $url, $param, $bLogical);
}
public static function GetFileExtension($path)
{
return GetFileExtension($path);
}
public static function GetFileType($path)
{
return GetFileType($path);
}
public static function GetStrFileSize($size)
{
return CFile::FormatSize($size);
}
public static function GetFileTypeEx($fileName)
{
global $arFilemanPredifinedFileTypesR;
$fileExt = GetFileExtension(mb_strtolower($fileName));
if (count($arFilemanPredifinedFileTypesR) <= 0)
{
foreach ($GLOBALS['arFilemanPredifinedFileTypes'] as $key => $value)
foreach ($value["exts"] as $ext)
$arFilemanPredifinedFileTypesR[$ext] = $key;
}
if (isset($arFilemanPredifinedFileTypesR[$fileExt]))
return $arFilemanPredifinedFileTypesR[$fileExt];
return "file";
}
public static function EscapePHPString($str)
{
return EscapePHPString($str);
}
public static function UnEscapePHPString($str)
{
return UnEscapePHPString($str);
}
public static function UndoFileDelete($Params, $type)
{
global $APPLICATION;
$documentRoot = CSite::GetSiteDocRoot($Params['site']);
// Restore file
if ($Params['path'] <> '')
$APPLICATION->SaveFileContent($documentRoot.$Params['path'], $Params['content']);
// Update disk quota
if (COption::GetOptionInt("main", "disk_space") > 0)
{
$io = CBXVirtualIo::GetInstance();
$f = $io->GetFile($documentRoot.$Params['path']);
$file_size = $f->GetFileSize();
$quota = new CDiskQuota();
$quota->UpdateDiskQuota("file", $file_size, "delete");
}
// Restore file access permissions
if (is_array($Params['perm']) && count($Params['perm']) > 0)
{
for ($i = 0, $l = count($Params['perm']); $i < $l; $i++)
{
$permFile = $Params['perm'][$i]['permFile'];
$permContent = $APPLICATION->GetFileContent($permFile);
$permContent = mb_substr($permContent, 0, mb_strpos($permContent, "?".">"));
$permContent .= "\$PERM[\"".EscapePHPString($Params['perm'][$i]['file'])."\"][\"".EscapePHPString($Params['perm'][$i]['group'])."\"]=\"".EscapePHPString($Params['perm'][$i]['perm'])."\";\n";
$permContent .= "?".">\n";
$APPLICATION->SaveFileContent($permFile, $permContent);
}
}
// Restore menu
if (is_array($Params['menu']) && count($Params['menu']) > 0)
{
for ($i = 0, $l = count($Params['menu']); $i < $l; $i++)
{
$menuFile = $Params['menu'][$i]['menuFile'];
$menuIndex = $Params['menu'][$i]['menuIndex'];
$menuItem = $Params['menu'][$i]['menuItem'];
$arMenu = CFileman::GetMenuArray($documentRoot.$menuFile);
$arFound = false;
if (count($arMenu["aMenuLinks"]) <= $menuIndex)
$arMenu["aMenuLinks"][] = $menuItem;
else
$arMenu["aMenuLinks"] = array_merge(array_slice($arMenu["aMenuLinks"], 0, $menuIndex), array($menuItem), array_slice($arMenu["aMenuLinks"], $menuIndex));
CFileMan::SaveMenu(Array($Params['site'], $menuFile), $arMenu["aMenuLinks"], $arMenu["sMenuTemplate"]);
}
}
// Restore UrlRewriter
if (is_array($Params['SEF']) && count($Params['SEF']) > 0)
{
for ($i = 0, $l = count($Params['SEF']); $i < $l; $i++)
{
CUrlRewriter::Add(array(
"SITE_ID" => $Params['site'],
"CONDITION" => $Params['SEF'][$i]["CONDITION"],
"ID" => $Params['SEF'][$i]["ID"],
"PATH" => $Params['SEF'][$i]["PATH"],
"RULE" => $Params['SEF'][$i]["RULE"]
));
}
}
$GLOBALS["CACHE_MANAGER"]->CleanDir("menu");
}
public static function UndoNewFile($Params, $type)
{
global $APPLICATION;
$documentRoot = CSite::GetSiteDocRoot($Params['site']);
$io = CBXVirtualIo::GetInstance();
// Delete file
$f = $io->GetFile($Params['absPath']);
$f->MarkWritable();
if (COption::GetOptionInt("main", "disk_space") > 0)
{
$file_size = $f->GetFileSize();
$quota = new CDiskQuota();
$quota->UpdateDiskQuota("file", $file_size, "delete");
}
$sucess = $io->Delete($Params['absPath']);
if (!$sucess)
return;
$APPLICATION->RemoveFileAccessPermission(Array($Params['site'], $Params['path']));
if (CModule::IncludeModule("search"))
CSearch::DeleteIndex("main", $Params['site']."|".$Params['path']);
// Find and clean file from menu
if ($Params['menu'])
{
$arMenu = CFileman::GetMenuArray($documentRoot.$Params['menu']['menuFile']);
if (!empty($arMenu["aMenuLinks"]))
{
$found = false;
foreach ($arMenu["aMenuLinks"] as $menuIndex => $arItem)
{
if ($arItem[1] == $Params['menu']['menuPath'] && $arItem[0] == $Params['menu']['menuName'])
{
unset($arMenu["aMenuLinks"][$menuIndex]);
$found = true;
break;
}
}
if ($found)
CFileMan::SaveMenu(Array($Params['site'], $Params['menu']['menuFile']), $arMenu["aMenuLinks"], $arMenu["sMenuTemplate"]);
}
}
if (isset($Params['public']) && $Params['public'] == 'Y')
{
?>
}
$GLOBALS["CACHE_MANAGER"]->CleanDir("menu");
}
public static function UndoEditFile($Params, $type)
{
global $APPLICATION;
// Restore file
if ($Params['absPath'] <> '')
$APPLICATION->SaveFileContent($Params['absPath'], $Params['content']);
$GLOBALS["CACHE_MANAGER"]->CleanDir("menu");
}
public static function UndoNewSection($Params, $type)
{
$io = CBXVirtualIo::GetInstance();
if ($Params['path'] <> '' && $Params['path'] != "/" && $io->DirectoryExists($Params['absPath']))
CFileman::DeleteEx(Array($Params['site'], $Params['path']));
$documentRoot = CSite::GetSiteDocRoot($Params['site']);
// Find and clean file from menu
if ($Params['menu'])
{
$arMenu = CFileman::GetMenuArray($documentRoot.$Params['menu']['menuFile']);
if (!empty($arMenu["aMenuLinks"]))
{
$found = false;
foreach ($arMenu["aMenuLinks"] as $menuIndex => $arItem)
{
if ($arItem[1] == $Params['menu']['menuPath'] && $arItem[0] == $Params['menu']['menuName'])
{
unset($arMenu["aMenuLinks"][$menuIndex]);
$found = true;
break;
}
}
if ($found)
CFileMan::SaveMenu(Array($Params['site'], $Params['menu']['menuFile']), $arMenu["aMenuLinks"], $arMenu["sMenuTemplate"]);
}
}
}
public static function FetchFileAccessPerm($path)
{
CMain::InitPathVars($site, $path);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
$result = false;
if(($p = bxstrrpos($path, "/")) === false)
return $result;
$path_file = mb_substr($path, $p + 1);
$path_dir = mb_substr($path, 0, $p);
$io = CBXVirtualIo::GetInstance();
if (!$io->FileExists($DOC_ROOT.$path_dir."/.access.php"))
return $result;
include($io->GetPhysicalName($DOC_ROOT.$path_dir."/.access.php"));
$result = array();
foreach($PERM as $file=>$arPerm)
{
if($file == $path_file)
{
foreach($arPerm as $group=>$perm)
$result[] = array(
'permFile' => $DOC_ROOT.$path_dir."/.access.php",
'file' => $file,
'group' => $group,
'perm' => $perm
);
}
}
return $result;
}
public static function ShowTypeSelector($params)
{
global $USER;
$useEditor3 = COption::GetOptionString('fileman', "use_editor_3", "Y") == "Y";
$name = $params['name'];
$key = isset($params['key']) ? $params['key'] : '';
$showTextType = isset($params['strTextTypeFieldName']) && $params['strTextTypeFieldName'];
$strTextTypeFieldName = $params['strTextTypeFieldName'];
$textType = $params['strTextTypeValue'] == 'html' ? 'html' : 'text';
$bxid = 'bxed_'.$name;
$replaceNewLines = COption::GetOptionString('fileman', "replace_new_lines", "Y") == "Y";
if ($textType == 'html')
{
$curType = CUserOptions::GetOption('html_editor', "type_selector_".$name.$key, false, $USER->GetId());
$curType = $curType['type'] ?? null;
if ($curType && in_array($curType, array('html', 'editor')))
{
$textType = $curType;
}
}
$ch = "checked=\"checked\"";
?>