Fixing Save As issue plus a few PHP notices

This commit is contained in:
mattpass
2020-07-21 08:13:23 +01:00
parent d1deb9313f
commit f196bb9305
3 changed files with 17 additions and 14 deletions

View File

@@ -353,9 +353,9 @@ class File
$fileLines = file($file);
$contents = $this->systemClass->stitchChanges($fileLines, $_POST['changes']);
// get old file contents, and count stats on usage \n and \r there
// in this case we can keep line endings, which file had before, without
// making code version control systems going crazy about line endings change in whole file.
// Get old file contents, and count stats on usage \n and \r\n
// We use this info shortly to standardise the file to the same line endings
// throughout, whichever is greater
$oldContents = file_exists($file) ? getData($file) : '';
$unixNewLines = preg_match_all('/[^\r][\n]/u', $oldContents);
$windowsNewLines = preg_match_all('/[\r][\n]/u', $oldContents);
@@ -368,11 +368,13 @@ class File
$systemClass->invalidateOPCache($file);
$fh = fopen($file, 'w') or die($t['Sorry, cannot save']);
// replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding
// Replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding
$contents = str_replace("\r\n", $ICEcoder["lineEnding"], $contents);
$contents = str_replace("\r", $ICEcoder["lineEnding"], $contents);
$contents = str_replace("\n", $ICEcoder["lineEnding"], $contents);
if (isset($_POST['changes']) && (0 < $unixNewLines) || (0 < $windowsNewLines)) {
// Finally, replace the line endings with whatever what greatest in the file before
// (We do this to help avoid a huge number of unnecessary changes simply on line endings)
if (isset($_POST['changes']) && (0 < $unixNewLines || 0 < $windowsNewLines)) {
if ($unixNewLines > $windowsNewLines){
$contents = str_replace($ICEcoder["lineEnding"], "\n", $contents);
} elseif ($windowsNewLines > $unixNewLines){
@@ -735,7 +737,7 @@ class File
} else {
$itemAbsPath = $file;
$itemPath = dirname($file);
$itemBytes = is_dir($file) ? null : filesize($file);
$itemBytes = is_dir($file) || !file_exists($file) ? null : filesize($file);
$itemType = (file_exists($file) ? (is_dir($file) ? "dir" : "file") : "unknown");
$itemExists = (file_exists($file) ? "true" : "false");
}

View File

@@ -136,13 +136,12 @@ if (!$error && "save" === $_GET['action']) {
if (!$demoMode && (isset($ftpSite) || (file_exists($file) && is_writable($file)) || isset($_POST['newFileName']) && "" != $_POST['newFileName'])) {
$filemtime = !isset($ftpSite) && "Windows" !== $serverType ? filemtime($file) : "1000000";
$filemtime = !isset($ftpSite) && "Windows" !== $serverType && file_exists($file) ? filemtime($file) : "1000000";
// =======================
// MDT'S MATCH, WRITE FILE
// =======================
if (!(isset($_GET['fileMDT'])) || $filemtime == $_GET['fileMDT']) {
// ==================================================
// MDT'S MATCH (OR WE'RE SAVING NEW FILE), WRITE FILE
// ==================================================
if (!(isset($_GET['fileMDT'])) || $filemtime == $_GET['fileMDT'] || isset($_POST['newFileName'])) {
// FTP Saving
if (isset($ftpSite)) {
@@ -488,7 +487,7 @@ if (!isset($ftpSite) && !$error && "checkExists" === $_GET['action']) {
// No $filemtime yet? Get it now!
if (false === isset($filemtime) && !is_dir($file)) {
$filemtime = "Windows" !== $serverType ? filemtime($file) : 1000000;
$filemtime = "Windows" !== $serverType && file_exists($file) ? filemtime($file) : 1000000;
}
if (false === isset($filemtime)) {
$filemtime = 1000000;

View File

@@ -93,7 +93,9 @@ sendCmd = function(command) {
<body onclick="document.getElementById('command').focus()">
<?php
chdir($_SESSION['cwd']);
if (true === isset($_SESSION['cwd'])) {
chdir($_SESSION['cwd']);
}
$user = str_replace("\n","",shell_exec("whoami"));
$cwd = str_replace("\n","",shell_exec("pwd"));
?>