CanDoOperation('fileman_admin_files') || $USER->CanDoOperation('fileman_edit_existent_files')))
$APPLICATION->AuthForm(GetMessage("ACCESS_DENIED"));
require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/include.php");
IncludeModuleLangFile($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/fileman/admin/fileman_html_edit.php");
$strWarning = "";
$site_template = false;
$rsSiteTemplates = CSite::GetTemplateList($site);
while($arSiteTemplate = $rsSiteTemplates->Fetch())
{
if($arSiteTemplate["CONDITION"] == '')
{
$site_template = $arSiteTemplate["TEMPLATE"];
break;
}
}
$io = CBXVirtualIo::GetInstance();
$path = $io->CombinePath("/", $path);
$path_list = GetDirPath($path);
$bVarsFromForm = false; // if 'true' - we will get content and variables from form, if 'false' - from saved file
$filename = isset($_REQUEST['filename']) ? $_REQUEST['filename'] : '';
$oldname = isset($_REQUEST['oldname']) ? $_REQUEST['oldname'] : '';
if ($filename <> '' && ($mess = CFileMan::CheckFileName($filename)) !== true)
{
$filename2 = $filename;
$filename = '';
$strWarning = $mess;
$bVarsFromForm = true;
}
$originalPath = $path;
$new = (isset($new) && mb_strtolower($new) == 'y') ? 'y' : '';
if ($new == 'y' && $filename <> '')
$path = $path."/".$filename;
$site = CFileMan::__CheckSite($site);
if(!$site)
$site = CSite::GetSiteByFullPath($_SERVER["DOCUMENT_ROOT"].$path);
$DOC_ROOT = CSite::GetSiteDocRoot($site);
$abs_path = $io->CombinePath($DOC_ROOT, $path);
$arPath = Array($site, $path);
if(GetFileType($abs_path) == "IMAGE")
$strWarning = GetMessage("FILEMAN_FILEEDIT_FILE_IMAGE_ERROR");
if($new == '' && $filename == '' && $oldname == '' && !$io->FileExists($abs_path))
{
$p = mb_strrpos($path, "/");
if($p !== false)
{
$new = "y";
$filename = mb_substr($path, $p + 1);
$path = mb_substr($path, 0, $p);
}
}
$useEditor3 = COption::GetOptionString('fileman', "use_editor_3", "Y") == "Y";
$bFullPHP = ($full_src == "Y") && $USER->CanDoOperation('edit_php');
$NEW_ROW_CNT = 1;
$arParsedPath = CFileMan::ParsePath(Array($site, $path), true, false, "", $logical == "Y");
$isScriptExt = HasScriptExtension($path);
//Check access to file
if
(
(
$new == 'y'
&&
!(
$USER->CanDoOperation('fileman_admin_files')
&&
$USER->CanDoFileOperation('fm_create_new_file', $arPath)
)
)
||
(
$new == ''
&&
!(
$USER->CanDoOperation('fileman_edit_existent_files')
&&
$USER->CanDoFileOperation('fm_edit_existent_file', $arPath)
)
)
)
{
$strWarning = GetMessage("ACCESS_DENIED");
}
elseif($strWarning == '')
{
if($new == 'y' && $filename <> '' && $io->FileExists($abs_path)) // if we want to create new file, but the file with same name is alredy exists - lets abuse
{
$strWarning = GetMessage("FILEMAN_FILEEDIT_FILE_EXISTS");
$bEdit = false;
$bVarsFromForm = true;
$path = $io->CombinePath("/", $arParsedPath["PREV"]);
$arParsedPath = CFileMan::ParsePath($path, true, false, "", $logical == "Y");
$abs_path = $io->CombinePath($DOC_ROOT, $path);
}
elseif(!$USER->IsAdmin() && mb_substr(CFileman::GetFileName($abs_path), 0, 1) == ".")
{
$strWarning = GetMessage("FILEMAN_FILEEDIT_BAD_FNAME");
$bEdit = false;
$bVarsFromForm = true;
$path = $io->CombinePath("/", $arParsedPath["PREV"]);
$arParsedPath = CFileMan::ParsePath($path, true, false, "", $logical == "Y");
$abs_path = $io->CombinePath($DOC_ROOT, $path);
}
elseif($new == 'y')
{
$bEdit = false;
}
else
{
if(!$io->FileExists($abs_path))
$strWarning = GetMessage("FILEMAN_FILEEDIT_FOLDER_EXISTS")." ";
else
$bEdit = true;
}
$limit_php_access = ($USER->CanDoFileOperation('fm_lpa', $arPath) && !$USER->CanDoOperation('edit_php'));
if ($limit_php_access)
{
//OFP - 'original full path' used for restorin' php code fragments in limit_php_access mode
if (!isset($_SESSION['arOFP']))
$_SESSION['arOFP'] = Array();
if(isset($_POST['ofp_id']))
{
$ofp_id = $_POST['ofp_id'];
}
else
{
$ofp_id = mb_substr(md5($site.'|'.$path), 0, 8);
if(!isset($_SESSION['arOFP'][$ofp_id]))
$_SESSION['arOFP'][$ofp_id] = $path;
}
}
}
$bFullScreen = ($_REQUEST['fullscreen'] ? $_REQUEST['fullscreen']=='Y' : COption::GetOptionString("fileman", "htmleditor_fullscreen", "N")=="Y");
if($back_url <> '' && mb_strpos($back_url, "/bitrix/admin/fileman_file_edit.php") !== 0)
$url = "/".ltrim($back_url, "/");
else
$url = "/bitrix/admin/fileman_admin.php?".$addUrl."&site=".Urlencode($site)."&path=".UrlEncode($arParsedPath["PREV"]);
$module_id = "fileman";
$localRedirectUrl = '';
if($strWarning == '')
{
if($bEdit)
{
$oFile = $io->GetFile($abs_path);
$filesrc_tmp = $oFile->GetContents();
}
else
{
$arTemplates = CFileman::GetFileTemplates(LANGUAGE_ID, array($site_template));
if($template <> '')
{
$len = count($arTemplates);
for ($i = 0; $i < $len; $i++)
{
if($arTemplates[$i]["file"] == $template)
{
$filesrc_tmp = CFileman::GetTemplateContent($arTemplates[$i]["file"],LANGUAGE_ID, array($site_template));
break;
}
}
}
else
{
$filesrc_tmp = CFileman::GetTemplateContent($arTemplates[0]["file"], LANGUAGE_ID, array($site_template));
}
}
if($REQUEST_METHOD == "POST" && $save <> '' && $propeditmore == '')
{
if(!check_bitrix_sessid())
{
$strWarning = GetMessage("FILEMAN_SESSION_EXPIRED");
$bVarsFromForm = true;
}
elseif((CFileman::IsPHP($filesrc) || $isScriptExt) && !($USER->CanDoOperation('edit_php') || $limit_php_access)) //check rights
{
$strWarning = GetMessage("FILEMAN_FILEEDIT_CHANGE");
$bVarsFromForm = true;
if($new == 'y' && $filename <> '')
{
$bEdit = false;
$path = $io->CombinePath("/", $arParsedPath["PREV"]);
$arParsedPath = CFileMan::ParsePath($path, true, false, "", $logical == "Y");
$abs_path = $io->CombinePath($DOC_ROOT, $path);
}
}
else
{
if($limit_php_access)
{
// ofp - original full path :)
$ofp = $_SESSION['arOFP'][$ofp_id];
$ofp = $io->CombinePath("/", $ofp);
$abs_ofp = $io->CombinePath($DOC_ROOT, $ofp);
$oFile = $io->GetFile($abs_ofp);
$fileContentTmp = $oFile->GetContents();
$old_res = CFileman::ParseFileContent($fileContentTmp, true);
$old_filesrc = $old_res["CONTENT"];
$filesrc = CMain::ProcessLPA($filesrc, $old_filesrc);
}
if(!$bFullPHP)
{
$res = CFileman::ParseFileContent($filesrc_tmp, true);
$prolog = CFileman::SetTitle($res["PROLOG"], $title);
for ($i = 0; $i<=$maxind; $i++)
{
if(Trim($_POST["CODE_".$i]) <> '')
{
if($_POST["CODE_".$i] != $_POST["H_CODE_".$i])
{
$prolog = CFileman::SetProperty($prolog, Trim($_POST["H_CODE_".$i]), "");
$prolog = CFileman::SetProperty($prolog, Trim($_POST["CODE_".$i]), Trim($_POST["VALUE_".$i]));
}
else
$prolog = CFileman::SetProperty($prolog, Trim($_POST["CODE_".$i]), Trim($_POST["VALUE_".$i]));
}
else
$prolog = CFileman::SetProperty($prolog, Trim($_POST["H_CODE_".$i]), "");
}
$epilog = $res["EPILOG"];
$filesrc_for_save = $prolog.$filesrc.$epilog;
}
else
{
$filesrc_for_save = $filesrc;
}
}
if($strWarning == '')
{
if (!CFileMan::CheckOnAllowedComponents($filesrc_for_save))
{
$str_err = $APPLICATION->GetException();
if($str_err && ($err = $str_err ->GetString()))
$strWarning .= $err;
$bVarsFromForm = true;
}
}
if($strWarning == '')
{
if(!$APPLICATION->SaveFileContent($abs_path, $filesrc_for_save))
{
if($str_err = $APPLICATION->GetException())
{
if ($err = $str_err ->GetString())
$strWarning = $err;
$path = $io->CombinePath("/", $arParsedPath["PREV"]);
$arParsedPath = CFileMan::ParsePath($path, true, false, "", $logical == "Y");
$abs_path = $io->CombinePath($DOC_ROOT, $path);
}
if (empty($strWarning))
$strWarning = GetMessage("FILEMAN_FILE_SAVE_ERROR");
$bVarsFromForm = true;
}
else
{
if(COption::GetOptionString($module_id, "log_page", "Y")=="Y")
{
$res_log['path'] = mb_substr($path, 1);
if ($new == 'y' && $filename <> '')
CEventLog::Log(
"content",
"FILE_ADD",
"fileman",
"",
serialize($res_log)
);
else
CEventLog::Log(
"content",
"FILE_EDIT",
"fileman",
"",
serialize($res_log)
);
}
// menu saving
if($add_to_menu=="Y" && $menutype <> '' && $USER->CanDoOperation('fileman_add_element_to_menu') && $USER->CanDoFileOperation('fm_add_to_menu',$arPath))
{
$menu_path = $io->CombinePath("/", $arParsedPath["PREV"], ".".$menutype.".menu.php");
if($USER->CanDoFileOperation('fm_edit_existent_file',Array($site,$menu_path)))
{
$res = CFileMan::GetMenuArray($DOC_ROOT.$menu_path);
$aMenuLinksTmp = $res["aMenuLinks"];
$sMenuTemplateTmp = $res["sMenuTemplate"];
$menuitem = intval($menuitem);
if($itemtype=="e") //means in exist item
{
$menuitem = $menuitem - 1;
if($menuitem < count($aMenuLinksTmp)) // number of item must be in bounds of amount of current menu
$aMenuLinksTmp[$menuitem][2][] = $path;
}
else //else in new
{
$menuitem = $newppos-1;
// if number of item goes out from bounds of amount of current menu
if($menuitem < 0 || $menuitem >= count($aMenuLinksTmp))
$menuitem = count($aMenuLinksTmp);
for($i=count($aMenuLinksTmp)-1; $i>=$menuitem; $i--)//shift to the right all items > our
$aMenuLinksTmp[$i+1] = $aMenuLinksTmp[$i];
$aMenuLinksTmp[$menuitem] = Array($newp, $path, Array(), Array(), "");
}
CFileMan::SaveMenu(Array($site, $menu_path), $aMenuLinksTmp, $sMenuTemplateTmp);
if(COption::GetOptionString("main", "event_log_menu", "N") === "Y")
{
$mt = COption::GetOptionString("fileman", "menutypes", $default_value, $site);
$mt = unserialize(str_replace("\\", "", $mt), ['allowed_classes' => false]);
$res_log['menu_name'] = $mt[$menutype];
$res_log['path'] = mb_substr(dirname($path), 1);
CEventLog::Log(
"content",
"MENU_EDIT",
"fileman",
"",
serialize($res_log)
);
}
}
}
if($strWarning == '' && $apply == '' && $apply2 == '')
$localRedirectUrl = $url;
else
$localRedirectUrl = "/bitrix/admin/fileman_html_edit.php?".$addUrl."&site=".Urlencode($site)."&path=".UrlEncode($path)."&back_url=".UrlEncode($back_url)."&fullscreen=".($bFullScreen?"Y":"N")."&tabControl_active_tab=".urlencode($tabControl_active_tab);
}
$filesrc_tmp = $filesrc_for_save;
$path = $io->CombinePath("/", $path);
$arParsedPath = CFileMan::ParsePath($path, true, false, "", $logical == "Y");
$abs_path = $io->CombinePath($DOC_ROOT, $path);
}
}
}
if($propeditmore <> '')
$bVarsFromForm = True;
$bEditProps = false;
if(!$bVarsFromForm)
{
if(!$bEdit && $filename == '')
$filename = ($USER->CanDoOperation('edit_php') || $limit_php_access) ? "untitled.php" : "untitled.html";
if(!$bFullPHP)
{
$res = CFileman::ParseFileContent($filesrc_tmp, true);
$filesrc = $res["CONTENT"];
// ########### L P A ############
if ($limit_php_access)
{
$arPHP = PHPParser::ParseFile($filesrc);
$l = count($arPHP);
if ($l > 0)
{
$new_filesrc = '';
$end = 0;
$php_count = 0;
for ($n = 0; $n<$l; $n++)
{
$start = $arPHP[$n][0];
$new_filesrc .= mb_substr($filesrc, $end, $start - $end);
$end = $arPHP[$n][1];
//Trim php tags
$src = $arPHP[$n][2];
if (mb_substr($src, 0, 5) == "INCLUDECOMPONENT(';
if (mb_strtoupper(mb_substr($src, 0, mb_strlen($comp2_begin))) == $comp2_begin)
$new_filesrc .= $arPHP[$n][2];
else
$new_filesrc .= '#PHP'.str_pad(++$php_count, 4, "0", STR_PAD_LEFT).'#';
}
$new_filesrc .= mb_substr($filesrc, $end);
$filesrc = $new_filesrc;
}
}
$bEditProps = $res["PROLOG"] <> '';
$title = $res["TITLE"];
$page_properties = $res["PROPERTIES"];
}
else
{
$filesrc = $filesrc_tmp;
}
if((CFileman::IsPHP($filesrc) || $isScriptExt) && !($USER->CanDoOperation('edit_php') || $limit_php_access))
$strWarning = GetMessage("FILEMAN_FILEEDIT_CHANGE_ACCESS");
}
elseif($prop_edit=="Y")
$bEditProps = true;
if($bEdit)
$APPLICATION->SetTitle(GetMessage("FILEMAN_FILEEDIT_PAGE_TITLE")." \"".htmlspecialcharsbx($arParsedPath["LAST"])."\"");
else
$APPLICATION->SetTitle(GetMessage("FILEMAN_NEWFILEEDIT_TITLE"));
$aTabs = array();
$aTabs[] = array("DIV" => "edit1", "TAB" => GetMessage("FILEMAN_H_EDIT_TAB1"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("FILEMAN_H_EDIT_TAB2"));
if($bEditProps)
$aTabs[] = array("DIV" => "edit2", "TAB" => GetMessage("FILEMAN_H_EDIT_RTAB2"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("FILEMAN_H_EDIT_TAB2_TITLE"));
if ($USER->CanDoOperation('fileman_add_element_to_menu') && $USER->CanDoFileOperation('fm_add_to_menu',$arPath))
$aTabs[] = array("DIV" => "edit3", "TAB" => GetMessage("FILEMAN_H_EDIT_TAB3"), "ICON"=>"main_user_edit", "TITLE"=>GetMessage("FILEMAN_H_EDIT_TAB3_TITLE"));
$tabControl = new CAdminTabControl("tabControl", $aTabs);
// We have to redirect after TabControl for normal work of autosave methods
if ($localRedirectUrl !== '')
{
LocalRedirect($localRedirectUrl);
}
if(count($arParsedPath["AR_PATH"]) == 1)
{
$adminChain->AddItem(
array(
"TEXT" => htmlspecialcharsex($DOC_ROOT),
"LINK" => "fileman_admin.php?lang=".LANGUAGE_ID."&site=".urlencode($site)."&path=/"
)
);
}
foreach($arParsedPath["AR_PATH"] as $chainLevel)
{
$adminChain->AddItem(
array(
"TEXT" => htmlspecialcharsex($chainLevel["TITLE"]),
"LINK" => (($chainLevel["LINK"] <> '') ? $chainLevel["LINK"] : ""),
)
);
}
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_admin_after.php");
?>
GetMessage("FILEMAN_BACK"),
"LINK" => "fileman_admin.php?".$addUrl."&site=".$site."&path=".UrlEncode($path_list),
"ICON" => "btn_list"
)
);
if ($bEdit)
{
$aMenu[] = array(
"TEXT"=>GetMessage("FILEMAN_FILE_VIEW"),
"LINK"=>"fileman_file_view.php?".$addUrl."&site=".urlencode($site)."&path=".urlencode($path)
);
}
$ismenu = preg_match('/^\.(.*)?\.menu\.(php|html|php3|php4|php5|phtml)$/i', $arParsedPath["LAST"], $regs);
$aDDMenuEdit = array();
if (!$ismenu)
{
$aDDMenuEdit[] = array(
"TEXT" => GetMessage("FILEMAN_FILEEDIT_AS_TXT"),
"ACTION" => "window.location='fileman_file_edit.php?".$addUrl.
"&site=".Urlencode($site)."&path=".UrlEncode($path).
($new == 'y' ? "&new=Y":"").
($back_url <> ''? "&back_url=".urlencode($back_url):"").
($template <> ''? "&template=".urlencode($template):"").
($template <> ''? "&template=".urlencode($template):"").
($templateID <> ''? "&templateID=".urlencode($templateID):"")."';",
);
}
if($USER->CanDoOperation('edit_php'))
{
$aDDMenuEdit[] = array(
"TEXT" => GetMessage("FILEMAN_FILEEDIT_AS_PHP"),
"ACTION" => "window.location='fileman_file_edit.php?".$addUrl."&site=".Urlencode($site).
"&path=".UrlEncode($path)."&full_src=Y".($new == 'y' ? "&new=Y":"").
($back_url <> ''? "&back_url=".urlencode($back_url):"").
($template <> ''? "&template=".urlencode($template):"").
($template <> ''? "&template=".urlencode($template):"").
($templateID <> ''? "&templateID=".urlencode($templateID):"")."';",
);
}
if ($ismenu)
{
$aDDMenuEdit[] = array(
"TEXT" => GetMessage("FILEMAN_FILEEDIT_AS_MENU"),
"ACTION" => "window.location='fileman_menu_edit.php?".$addUrl.
"&site=".Urlencode($site)."&path=".UrlEncode($arParsedPath["PREV"]).
"&name=".UrlEncode($regs[1]).($new == 'y' ? "&new=Y":"").
($back_url <> ''? "&back_url=".urlencode($back_url):"")."';"
);
}
$aDDMenuEdit[] = array(
"TEXT" => GetMessage("FILEMAN_FILEEDIT_AS_HTML"),
"ACTION" => "return;",
"ICON" => "checked"
);
$aMenu[] = array(
"TEXT" => GetMessage("FILEMAN_FILE_EDIT"),
"TITLE" => GetMessage("FILEMAN_FILE_EDIT"),
"MENU" => $aDDMenuEdit
);
if($bEdit)
{
if($USER->CanDoFileOperation('fm_rename_file',$arPath))
{
$aMenu[] = array(
"TEXT"=>GetMessage("FILEMAN_FILEEDIT_RENAME"),
"LINK"=>"fileman_rename.php?".$addUrl."&site=".Urlencode($site)."&path=".UrlEncode($arParsedPath["PREV"])."&files[]=".UrlEncode($arParsedPath["LAST"])
);
}
if(($USER->CanDoFileOperation('fm_download_file', $arPath) && !(HasScriptExtension($path) || mb_substr(CFileman::GetFileName($path), 0, 1) == ".")) || $USER->CanDoOperation('edit_php'))
{
$aMenu[] = array(
"TEXT"=>GetMessage("FILEMAN_FILEEDIT_DOWNLOAD"),
"LINK"=>"fileman_file_download.php?".$addUrl."&site=".Urlencode($site)."&path=".UrlEncode($path)
);
}
if($USER->CanDoFileOperation('fm_delete_file', $arPath))
{
$folder_path = mb_substr($path, 0, mb_strrpos($path, "/"));
$id = GetFileName($path);
$aMenu[] = array(
"TEXT" => GetMessage("FILEMAN_FILE_DELETE"),
"LINK" => "javascript:if(confirm('".GetMessage("FILEMAN_FILE_DELETE_CONFIRM")."')) window.location='/bitrix/admin/fileman_admin.php?ID=".urlencode($id)."&action=delete&".$addUrl."&site=".urlencode($site)."&path=".urlencode($folder_path)."&".bitrix_sessid_get()."';",
"TITLE" => GetMessage("FILEMAN_FILE_DELETE")
);
}
}
$context = new CAdminContextMenu($aMenu);
$context->Show();
global $__fd_path;
$__fd_path = $bEdit ? $arParsedPath["PREV"] : $path;
$arContextTemplates = Array();
$arTemplates = CFileman::GetFileTemplates(LANGUAGE_ID, array($site_template));
$cntTempl = count($arTemplates);
for($i = 0; $i < $cntTempl; $i++)
{
$arContextTemplates[] = Array(
"TEXT"=>htmlspecialcharsbx($arTemplates[$i]["name"]),
"ONCLICK" => "__NewDocTempl('".AddSlashes(htmlspecialcharsbx($arTemplates[$i]["file"]))."')",
);
}
$u = new CAdminPopup("new_doc_list", "new_doc_list", $arContextTemplates);
CAdminFileDialog::ShowScript(Array
(
"event" => "__bx_fd_save_as",
"arResultDest" => Array("FUNCTION_NAME" => "OnSaveAs"),
"arPath" => Array('SITE'=>$site, 'PATH'=>$_REQUEST['path']), //http://jabber.bx/view.php?id=27769
"select" => 'F',
"operation" => 'S',
"showUploadTab" => false,
"showAddToMenuTab" => true,
"fileFilter" => 'php,html,htm,phtml',
"allowAllFiles" => true,
"saveConfig" => false
)
);
?>
Show();
?>