From 9c8bb08454fac6a7ecf1480b76af3ac7b07c712e Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Thu, 31 Jan 2013 14:05:47 +0000 Subject: [PATCH] Remove htmlentities() to avoid junk chars Not needed and just caused junk/rubbish. --- lib/file-control.php | 748 +++++++++++++++++++++---------------------- 1 file changed, 374 insertions(+), 374 deletions(-) diff --git a/lib/file-control.php b/lib/file-control.php index b9b65d2..3d25f3a 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -1,375 +1,375 @@ - -action="load";'; - - if (file_exists($file)) { - // Determine what to do based on mime type - $finfo = finfo_open(FILEINFO_MIME_TYPE); - if (strpos(finfo_file($finfo, $file),"text")===0) { - echo ''; - $loadedFile = file_get_contents($file); - echo '","",htmlentities($loadedFile)).''; - } else if (strpos(finfo_file($finfo, $file),"image")===0) { - echo ''; - } else { - echo ''; - }; - } else { - echo ''; - } - finfo_close($finfo); -}; - -// If we're due to add a new folder... -if ($_GET['action']=="newFolder") { - if (!$demoMode && is_writable($docRoot.$fileLoc)) { - mkdir($file, 0705); - // Reload file manager - echo ''; - } else { - echo ""; - } - echo ''; -} - -// If we're due to paste a new file... -if ($_GET['action']=="paste") { - $source = $file; - $dest = str_replace("//","/",$docRoot.strClean(str_replace("|","/",$_GET['location']))."/".basename($source)); - if (!$demoMode && is_writable(dirname($dest))) { - if (is_dir($source)) { - if (!is_dir($dest)) { - mkdir($dest, 0705); - } - foreach ($iterator = new RecursiveIteratorIterator( - new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), - RecursiveIteratorIterator::SELF_FIRST) as $item - ) { - if ($item->isDir()) { - mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName(), 0705); - } else { - copy($item, $dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName()); - } - } - } else { - if (!file_exists($dest)) { - copy($source, $dest); - } else { - for ($i=2; $i<1000000000; $i++) { - if (!file_exists($dest." (".$i.")")) { - $dest = $dest." (".$i.")"; - copy($source, $dest); - $i=1000000000; - } - } - } - } - // Reload file manager - echo ''; - } else { - echo ""; - } - echo ''; -} - -// If we're due to upload files... -if ($_GET['action']=="upload") { - if (!$demoMode) { - class fileUploader { - public function __construct($uploads) { - global $docRoot; - $uploadDir=$docRoot.$iceRoot.str_replace("..","",str_replace("|","/",strClean($_POST['folder'])."/")); - foreach($uploads as $current) { - $this->uploadFile=$uploadDir.$current->name; - $fileName = $current->name; - if ($this->upload($current,$this->uploadFile)) { - echo ''; - } else { - echo ""; - } - } - } - - public function upload($current,$uploadFile){ - if(move_uploaded_file($current->tmp_name,$uploadFile)){ - return true; - } - } - } - - function getDetails($fileArr) { - foreach($fileArr['name'] as $keyee => $info) { - $uploads[$keyee]->name=$fileArr['name'][$keyee]; - $uploads[$keyee]->type=$fileArr['type'][$keyee]; - $uploads[$keyee]->tmp_name=$fileArr['tmp_name'][$keyee]; - $uploads[$keyee]->error=$fileArr['error'][$keyee]; - } - return $uploads; - } - - if($_FILES['filesInput']){ - $uploads = getDetails($_FILES['filesInput']); - $fileUploader=new fileUploader($uploads); - } - } else { - echo ""; - } - - echo ""; -} - -// If we're due to rename a file/folder... -if ($_GET['action']=="rename") { - if (!$demoMode && is_writable($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])))) { - if(rename($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])),$docRoot.$fileLoc."/".$fileName)) { - // Reload file manager - echo ''; - $renamed=true; - } else { - $renamed=false; - } - } else { - $renamed=false; - } - if (!$renamed) { - echo ""; - } - echo ''; -} - -// If we're due to replace text in a file... -if ($_GET['action']=="replaceText") { - if (!$demoMode && is_writable(str_replace("|","/",strClean($_GET['fileRef'])))) { - $file = str_replace("|","/",strClean($_GET['fileRef'])); - $loadedFile = file_get_contents($file); - $newContent = str_replace(strClean($_GET['find']),strClean($_GET['replace']),$loadedFile); - $fh = fopen($file, 'w') or die("Sorry, cannot save"); - fwrite($fh, $newContent); - fclose($fh); - echo ''; - } else { - echo ""; - } - echo ''; -} - -// If we're due to change permissions on a file/folder... -if ($_GET['action']=="perms") { - if (!$demoMode && is_writable($file)) { - chmod($file,octdec(numClean($_GET['perms']))); - // Reload file manager - echo ''; - } else { - echo ""; - } - echo ''; -} - -// If we're due to delete a file... -if ($_GET['action']=="delete") { - $filesArray = explode(";",$file); // May contain more than one file here - for ($i=0;$i<=count($filesArray)-1;$i++) { - $fullPath = str_replace($docRoot,"",$filesArray[$i]); - $fullPath = str_replace($iceRoot,"",$fullPath); - $fullPath = $docRoot.$iceRoot.$fullPath; - if (!$demoMode && is_writable($fullPath)) { - is_dir($fullPath) - ? rrmdir($fullPath) - : unlink($fullPath); - $fileName = basename($fullPath); - $fileLoc = dirname(str_replace($docRoot,"",$fullPath)); - // Reload file manager - echo ''; - } else { - echo ""; - } - echo ''; - } - echo ''; -} - -// The function to recursively remove folders & files -function rrmdir($dir) { - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != "." && $object != "..") { - filetype($dir."/".$object) == "dir" - ? rrmdir($dir."/".$object) - : unlink($dir."/".$object); - } - } - reset($objects); - rmdir($dir); - } -} - -if ($_GET['action']=="save") { - echo ''; - // on the form posting via a reload, save the file - if (isset($_POST['contents'])) { - if (!$demoMode && ((file_exists($file) && is_writable($file)) || isset($_POST['newFileName']) && $_POST['newFileName']!="")) { - if (filemtime($file)==$_GET['fileMDT']||!(isset($_GET['fileMDT']))) { - $fh = fopen($file, 'w') or die("Sorry, cannot save"); - fwrite($fh, $_POST['contents']); - fclose($fh); - clearstatcache(); - echo ''; - // Reload file manager & rename tab if it was a new file - if (isset($_POST['newFileName']) && $_POST['newFileName']!="") { - echo ''; - } - // Reload stickytab window - echo ''; - } else { - $loadedFile = file_get_contents($file); - echo '","",htmlentities($loadedFile)).''; - echo ''; - ?> - - action='nothing';top.ICEcoder.message('Sorry, cannot write\\n".$file."')"; - } - echo ''; - } -}; -?> - - -
- - -
- - - -'; + + if (file_exists($file)) { + // Determine what to do based on mime type + $finfo = finfo_open(FILEINFO_MIME_TYPE); + if (strpos(finfo_file($finfo, $file),"text")===0) { + echo ''; + $loadedFile = file_get_contents($file); + echo '","",$loadedFile).''; + } else if (strpos(finfo_file($finfo, $file),"image")===0) { + echo ''; + } else { + echo ''; + }; + } else { + echo ''; + } + finfo_close($finfo); +}; + +// If we're due to add a new folder... +if ($_GET['action']=="newFolder") { + if (!$demoMode && is_writable($docRoot.$fileLoc)) { + mkdir($file, 0705); + // Reload file manager + echo ''; + } else { + echo ""; + } + echo ''; +} + +// If we're due to paste a new file... +if ($_GET['action']=="paste") { + $source = $file; + $dest = str_replace("//","/",$docRoot.strClean(str_replace("|","/",$_GET['location']))."/".basename($source)); + if (!$demoMode && is_writable(dirname($dest))) { + if (is_dir($source)) { + if (!is_dir($dest)) { + mkdir($dest, 0705); + } + foreach ($iterator = new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), + RecursiveIteratorIterator::SELF_FIRST) as $item + ) { + if ($item->isDir()) { + mkdir($dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName(), 0705); + } else { + copy($item, $dest.DIRECTORY_SEPARATOR.$iterator->getSubPathName()); + } + } + } else { + if (!file_exists($dest)) { + copy($source, $dest); + } else { + for ($i=2; $i<1000000000; $i++) { + if (!file_exists($dest." (".$i.")")) { + $dest = $dest." (".$i.")"; + copy($source, $dest); + $i=1000000000; + } + } + } + } + // Reload file manager + echo ''; + } else { + echo ""; + } + echo ''; +} + +// If we're due to upload files... +if ($_GET['action']=="upload") { + if (!$demoMode) { + class fileUploader { + public function __construct($uploads) { + global $docRoot; + $uploadDir=$docRoot.$iceRoot.str_replace("..","",str_replace("|","/",strClean($_POST['folder'])."/")); + foreach($uploads as $current) { + $this->uploadFile=$uploadDir.$current->name; + $fileName = $current->name; + if ($this->upload($current,$this->uploadFile)) { + echo ''; + } else { + echo ""; + } + } + } + + public function upload($current,$uploadFile){ + if(move_uploaded_file($current->tmp_name,$uploadFile)){ + return true; + } + } + } + + function getDetails($fileArr) { + foreach($fileArr['name'] as $keyee => $info) { + $uploads[$keyee]->name=$fileArr['name'][$keyee]; + $uploads[$keyee]->type=$fileArr['type'][$keyee]; + $uploads[$keyee]->tmp_name=$fileArr['tmp_name'][$keyee]; + $uploads[$keyee]->error=$fileArr['error'][$keyee]; + } + return $uploads; + } + + if($_FILES['filesInput']){ + $uploads = getDetails($_FILES['filesInput']); + $fileUploader=new fileUploader($uploads); + } + } else { + echo ""; + } + + echo ""; +} + +// If we're due to rename a file/folder... +if ($_GET['action']=="rename") { + if (!$demoMode && is_writable($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])))) { + if(rename($docRoot.$iceRoot.str_replace("|","/",strClean($_GET['oldFileName'])),$docRoot.$fileLoc."/".$fileName)) { + // Reload file manager + echo ''; + $renamed=true; + } else { + $renamed=false; + } + } else { + $renamed=false; + } + if (!$renamed) { + echo ""; + } + echo ''; +} + +// If we're due to replace text in a file... +if ($_GET['action']=="replaceText") { + if (!$demoMode && is_writable(str_replace("|","/",strClean($_GET['fileRef'])))) { + $file = str_replace("|","/",strClean($_GET['fileRef'])); + $loadedFile = file_get_contents($file); + $newContent = str_replace(strClean($_GET['find']),strClean($_GET['replace']),$loadedFile); + $fh = fopen($file, 'w') or die("Sorry, cannot save"); + fwrite($fh, $newContent); + fclose($fh); + echo ''; + } else { + echo ""; + } + echo ''; +} + +// If we're due to change permissions on a file/folder... +if ($_GET['action']=="perms") { + if (!$demoMode && is_writable($file)) { + chmod($file,octdec(numClean($_GET['perms']))); + // Reload file manager + echo ''; + } else { + echo ""; + } + echo ''; +} + +// If we're due to delete a file... +if ($_GET['action']=="delete") { + $filesArray = explode(";",$file); // May contain more than one file here + for ($i=0;$i<=count($filesArray)-1;$i++) { + $fullPath = str_replace($docRoot,"",$filesArray[$i]); + $fullPath = str_replace($iceRoot,"",$fullPath); + $fullPath = $docRoot.$iceRoot.$fullPath; + if (!$demoMode && is_writable($fullPath)) { + is_dir($fullPath) + ? rrmdir($fullPath) + : unlink($fullPath); + $fileName = basename($fullPath); + $fileLoc = dirname(str_replace($docRoot,"",$fullPath)); + // Reload file manager + echo ''; + } else { + echo ""; + } + echo ''; + } + echo ''; +} + +// The function to recursively remove folders & files +function rrmdir($dir) { + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != "." && $object != "..") { + filetype($dir."/".$object) == "dir" + ? rrmdir($dir."/".$object) + : unlink($dir."/".$object); + } + } + reset($objects); + rmdir($dir); + } +} + +if ($_GET['action']=="save") { + echo ''; + // on the form posting via a reload, save the file + if (isset($_POST['contents'])) { + if (!$demoMode && ((file_exists($file) && is_writable($file)) || isset($_POST['newFileName']) && $_POST['newFileName']!="")) { + if (filemtime($file)==$_GET['fileMDT']||!(isset($_GET['fileMDT']))) { + $fh = fopen($file, 'w') or die("Sorry, cannot save"); + fwrite($fh, $_POST['contents']); + fclose($fh); + clearstatcache(); + echo ''; + // Reload file manager & rename tab if it was a new file + if (isset($_POST['newFileName']) && $_POST['newFileName']!="") { + echo ''; + } + // Reload stickytab window + echo ''; + } else { + $loadedFile = file_get_contents($file); + echo '","",htmlentities($loadedFile)).''; + echo ''; + ?> + + action='nothing';top.ICEcoder.message('Sorry, cannot write\\n".$file."')"; + } + echo ''; + } +}; +?> + + +
+ + +
+ + + + \ No newline at end of file