From fc79be30105ba80881accd5148aa12afa8f401da Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Sun, 12 May 2013 17:12:14 +0100 Subject: [PATCH] getRemote file function added Firstly, avoid establishing a full path if we have a getRemoteFile action as it will be a URL If we want to get a remote URL, attempt to get remote contents, standardise all line endings to be Linux based, create a new tab, new textarea and finally set the value of the new tab. If we don't manage to get the file, show an error message --- lib/file-control.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/file-control.php b/lib/file-control.php index 9bc677e..3a54eab 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -14,7 +14,7 @@ $file = str_replace("|","/",strClean( $file = rtrim(rtrim($file,'+'),' '); // Make $file a full path and establish the $fileLoc and $fileName -if (strpos($file,$docRoot)===false) {$file=str_replace("|","/",$docRoot.$iceRoot.$file);}; +if (strpos($file,$docRoot)===false && $_GET['action']!="getRemoteFile") {$file=str_replace("|","/",$docRoot.$iceRoot.$file);}; $fileLoc = substr(str_replace($docRoot,"",$file),0,strrpos(str_replace($docRoot,"",$file),"/")); $fileName = basename($file); @@ -51,6 +51,21 @@ if ($_GET['action']=="load") { }; +// Get the contents of a remote URL +if ($_GET['action']=="getRemoteFile") { + if ($remoteFile = file_get_contents($file)) { + // replace \r\n (Windows) and \r (old Mac) line endings with \n (Linux) + $remoteFile = str_replace("\r\n", "\n", $remoteFile); + $remoteFile = str_replace("\r", "\n", $remoteFile); + echo ''; + echo '","",str_replace("&","&",$remoteFile)).''; + echo ''; + } else { + echo ''; + } + echo ''; +} + // If we're due to add a new folder... if ($_GET['action']=="newFolder") { if (!$demoMode && is_writable($docRoot.$fileLoc)) {