diff --git a/lib/file-control-xhr.php b/lib/file-control-xhr.php index 33eab41..0569ac1 100644 --- a/lib/file-control-xhr.php +++ b/lib/file-control-xhr.php @@ -87,6 +87,17 @@ if (!$error) { } } +$doNext = ""; +// If we're in FTP mode, start a connection and leave open for FTP actions +if (isset($ftpSite)) { + ftpStart(); + // Show user warning if no good connection + if (!$ftpConn || !$ftpLogin) { + $doNext .= 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; + } +} + + // ============ // SAVING FILES // ============ @@ -101,7 +112,7 @@ if (!$error && $_GET['action']=="save") { $finalAction = strpos($fileOrig,"[NEW]")>0 ? "save as" : "save"; $fileURL = isset($file) ? $file : ""; $fileMDTURLPart = isset($_GET["fileMDT"]) && $_GET["fileMDT"]!="undefined" ? "&fileMDT=".numClean($_GET['fileMDT']) : ""; - $doNext = ' + $doNext .= ' top.ICEcoder.serverMessage(); fileLoc = "'.$fileLoc.'"; overwriteOK = false; @@ -178,7 +189,8 @@ if (!$error && $_GET['action']=="save") { // ================= if (!$demoMode && (isset($ftpSite) || (file_exists($file) && is_writable($file)) || isset($_POST['newFileName']) && $_POST['newFileName']!="")) { - $filemtime = $serverType=="Linux" ? filemtime($file) : "1000000"; + + $filemtime = !isset($ftpSite) && $serverType=="Linux" ? filemtime($file) : "1000000"; // ======================= // MDT'S MATCH, WRITE FILE @@ -186,16 +198,9 @@ if (!$error && $_GET['action']=="save") { if (!(isset($_GET['fileMDT']))||$filemtime==$_GET['fileMDT']) { - $doNext = ""; - // FTP Saving if (isset($ftpSite)) { - ftpStart(); - // Show user warning if no good connection - if (!$ftpConn || !$ftpLogin) { - $doNext .= 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; - } - // Write our file contents and close the FTP connection + // Write our file contents $ftpFilepath = ltrim($fileLoc."/".$fileName,"/"); // replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding $contents = $_POST['contents']; @@ -205,7 +210,7 @@ if (!$error && $_GET['action']=="save") { if (!ftpWriteFile($ftpConn, $ftpFilepath, $contents, $ftpMode)) { $doNext .= 'top.ICEcoder.message("Sorry, could not write '.$ftpFilepath.' at '.$ftpHost.'");'; } - ftpEnd(); + $doNext .= 'top.ICEcoder.openFileMDTs[top.ICEcoder.selectedTab-1]="'.$filemtime.'";'; // Local saving } else { // Newly created files have the perms set too @@ -295,8 +300,9 @@ if (!$error && $_GET['action']=="save") { // ====================================================== } else { + // Only applicable for local files $loadedFile = toUTF8noBOM(file_get_contents($file,false,$context),true); - $doNext = ' + $doNext .= ' var loadedFile = document.createElement("textarea"); loadedFile.value = "'.str_replace('"','\\\"',str_replace("\r","\\\\r",str_replace("\n","\\\\n",str_replace("","",$loadedFile)))).'"; var refreshFile = top.ICEcoder.ask("'.$t['Sorry, this file...'].'\\\n'.$file.'\\\n\\\n'.$t['Reload this file...'].'"); @@ -323,7 +329,7 @@ if (!$error && $_GET['action']=="save") { } else { $finalAction = "nothing"; - $doNext = "top.ICEcoder.message('".$t['Sorry, cannot save']."\\\\n".$file."');"; + $doNext .= "top.ICEcoder.message('".$t['Sorry, cannot save']."\\\\n".$file."');"; } $doNext .= 'top.ICEcoder.serverMessage();top.ICEcoder.serverQueue("del",0);'; } @@ -338,19 +344,12 @@ if (!$error && $_GET['action']=="newFolder") { $updateFM = false; // FTP if (isset($ftpSite)) { - ftpStart(); - // Show user warning if no good connection - if (!$ftpConn || !$ftpLogin) { - $doNext = 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; + $ftpFilepath = ltrim($fileLoc."/".$fileName,"/"); + if (!ftpMkDir($ftpConn, octdec($ICEcoder['newDirPerms']), $ftpFilepath)) { + $doNext .= 'top.ICEcoder.message("Sorry, could not create dir '.$ftpFilepath.' at '.$ftpHost.'");'; } else { - $ftpFilepath = ltrim($fileLoc."/".$fileName,"/"); - if (!ftpMkDir($ftpConn, octdec($ICEcoder['newDirPerms']), $ftpFilepath)) { - $doNext = 'top.ICEcoder.message("Sorry, could not create dir '.$ftpFilepath.' at '.$ftpHost.'");'; - } else { - $updateFM = true; - } + $updateFM = true; } - ftpEnd(); // Local } else { mkdir($file, octdec($ICEcoder['newDirPerms'])); @@ -359,13 +358,13 @@ if (!$error && $_GET['action']=="newFolder") { } // Update file manager on success if ($updateFM) { - $doNext = 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'add\',\''.$fileLoc.'\',\''.$fileName.'\',false,false,false,\'folder\');'; + $doNext .= 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'add\',\''.$fileLoc.'\',\''.$fileName.'\',false,false,false,\'folder\');'; } $finalAction = "newFolder"; // Run our custom processes include_once("../processes/on-new-dir.php"); } else { - $doNext = "top.ICEcoder.message('".$t['Sorry, cannot create...']."\\\\n".$fileLoc."');"; + $doNext .= "top.ICEcoder.message('".$t['Sorry, cannot create...']."\\\\n".$fileLoc."');"; $finalAction = "nothing"; } $doNext .= 'top.ICEcoder.serverMessage();top.ICEcoder.serverQueue("del",0);'; @@ -388,19 +387,12 @@ if (!$error && $_GET['action']=="move") { $updateFM = false; // FTP if (isset($ftpSite)) { - ftpStart(); - // Show user warning if no good connection - if (!$ftpConn || !$ftpLogin) { - $doNext = 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; + if (!ftpRename($ftpConn, $srcDir, $tgtDir)) { + $doNext .= 'top.ICEcoder.message("Sorry, could not rename '.$srcDir.' to '.$tgtDir.'");'; } else { - if (!ftpRename($ftpConn, $srcDir, $tgtDir)) { - $doNext = 'top.ICEcoder.message("Sorry, could not rename '.$srcDir.' to '.$tgtDir.'");'; - } else { - $fileOrFolder = "folder"; - $updateFM = true; - } + $fileOrFolder = "folder"; + $updateFM = true; } - ftpEnd(); // Local } else { if(rename($srcDir,$tgtDir)) { @@ -411,17 +403,17 @@ if (!$error && $_GET['action']=="move") { } // Update file manager on success if ($updateFM) { - $doNext = 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'move\',\''.$fileLoc.'\',\''.$fileName.'\',\'\',\''.str_replace($iceRoot,"",strClean(str_replace("|","/",$_GET['oldFileName']))).'\',false,top.ICEcoder.isFileFolder(\''.strClean($_GET['oldFileName']).'\'));'; + $doNext .= 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'move\',\''.$fileLoc.'\',\''.$fileName.'\',\'\',\''.str_replace($iceRoot,"",strClean(str_replace("|","/",$_GET['oldFileName']))).'\',false,top.ICEcoder.isFileFolder(\''.strClean($_GET['oldFileName']).'\'));'; } $finalAction = "move"; // Run our custom processes include_once("../processes/on-file-dir-move.php"); } else { - $doNext = "top.ICEcoder.message('".$t['Sorry, cannot move']."\\\\n".str_replace("|","/",strClean($_GET['oldFileName']))."\\\\n\\\\n".$t['Maybe public write...']."');"; + $doNext .= "top.ICEcoder.message('".$t['Sorry, cannot move']."\\\\n".str_replace("|","/",strClean($_GET['oldFileName']))."\\\\n\\\\n".$t['Maybe public write...']."');"; $finalAction = "nothing"; } } else { - $doNext = ""; + $doNext .= ""; $finalAction = "nothing"; } $doNext .= 'top.ICEcoder.serverMessage();top.ICEcoder.serverQueue("del",0);'; @@ -436,19 +428,12 @@ if (!$error && $_GET['action']=="rename") { $updateFM = false; // FTP if (isset($ftpSite)) { - ftpStart(); - // Show user warning if no good connection - if (!$ftpConn || !$ftpLogin) { - $doNext = 'top.ICEcoder.message("Sorry, no FTP connection to '.$ftpHost.' for user '.$ftpUser.'");'; + $ftpFilepath = ltrim($fileLoc."/".$fileName,"/"); + if (!ftpRename($ftpConn, ltrim(strClean($_GET['oldFileName']),"/"), $ftpFilepath)) { + $doNext .= 'top.ICEcoder.message("Sorry, could not rename '.ltrim(strClean($_GET['oldFileName']),"/").' to '.$ftpFilepath.'");'; } else { - $ftpFilepath = ltrim($fileLoc."/".$fileName,"/"); - if (!ftpRename($ftpConn, ltrim(strClean($_GET['oldFileName']),"/"), $ftpFilepath)) { - $doNext = 'top.ICEcoder.message("Sorry, could not rename '.ltrim(strClean($_GET['oldFileName']),"/").' to '.$ftpFilepath.'");'; - } else { - $updateFM = true; - } + $updateFM = true; } - ftpEnd(); // Local } else { rename($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])),$docRoot.$fileLoc."/".$fileName); @@ -456,13 +441,13 @@ if (!$error && $_GET['action']=="rename") { } // Update file manager on success if ($updateFM) { - $doNext = 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'rename\',\''.$fileLoc.'\',\''.$fileName.'\',\'\',\''.str_replace($iceRoot,"",strClean($_GET['oldFileName'])).'\');'; + $doNext .= 'top.ICEcoder.selectedFiles=[];top.ICEcoder.updateFileManagerList(\'rename\',\''.$fileLoc.'\',\''.$fileName.'\',\'\',\''.str_replace($iceRoot,"",strClean($_GET['oldFileName'])).'\');'; } $finalAction = "rename"; // Run our custom processes include_once("../processes/on-file-dir-rename.php"); } else { - $doNext = "top.ICEcoder.message('".$t['Sorry, cannot rename']."\\\\n".strClean($_GET['oldFileName'])."\\\\n\\\\n".$t['Maybe public write...']."');"; + $doNext .= "top.ICEcoder.message('".$t['Sorry, cannot rename']."\\\\n".strClean($_GET['oldFileName'])."\\\\n\\\\n".$t['Maybe public write...']."');"; $finalAction = "nothing"; } $doNext .= 'top.ICEcoder.serverMessage();top.ICEcoder.serverQueue("del",0);'; @@ -514,12 +499,12 @@ if (!isset($ftpSite) && !$error && $_GET['action']=="paste") { } } // Reload file manager - $doNext = 'top.ICEcoder.updateFileManagerList(\'add\',\''.strClean(str_replace("|","/",$_GET['location'])).'\',\''.basename($dest).'\',false,false,false,\''.$fileOrFolder.'\');'; + $doNext .= 'top.ICEcoder.updateFileManagerList(\'add\',\''.strClean(str_replace("|","/",$_GET['location'])).'\',\''.basename($dest).'\',false,false,false,\''.$fileOrFolder.'\');'; $finalAction = "pasteFile"; // Run our custom processes include_once("../processes/on-file-dir-paste.php"); } else { - $doNext = "top.ICEcoder.message('".$t['Sorry, cannot copy']." \\\\n".str_replace($docRoot,"",$source)."\\\\n ".$t['into']." \\\\n".str_replace($docRoot,"",$dest)."');"; + $doNext .= "top.ICEcoder.message('".$t['Sorry, cannot copy']." \\\\n".str_replace($docRoot,"",$source)."\\\\n ".$t['into']." \\\\n".str_replace($docRoot,"",$dest)."');"; $finalAction = "nothing"; } $doNext .= 'top.ICEcoder.serverMessage();top.ICEcoder.serverQueue("del",0);'; @@ -531,7 +516,6 @@ if (!isset($ftpSite) && !$error && $_GET['action']=="paste") { if (!isset($ftpSite) && !$error && $_GET['action']=="upload") { if (!$demoMode) { - $doNext = ""; class fileUploader { public function __construct($uploads) { global $docRoot,$iceRoot,$ICEcoder,$doNext; @@ -596,7 +580,6 @@ if (!isset($ftpSite) && !$error && $_GET['action']=="upload") { // ======================== if (!isset($ftpSite) && !$error && $_GET['action']=="delete") { - $doNext = ""; $filesArray = explode(";",$file); // May contain more than one file here for ($i=0;$i