From bfbf84ca2473ec652713b56dbcc0fca8bdea2ab5 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Fri, 7 Sep 2012 17:25:56 +0100 Subject: [PATCH] New action process added for replaceText Upon replaceText being needed, we detect if we have a high enough userLevel and if it's writable, if not provide an appropriate message to the user Otherwise - read, replace and save the new content with the find/replace combo requested Clear the server message and item from the queue --- lib/file-control.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/file-control.php b/lib/file-control.php index edf017c..7d8506b 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -87,6 +87,27 @@ if ($_GET['action']=="rename") { echo ''; } +// If we're due to replace text in a file... +if ($_GET['action']=="replaceText") { + if ($_SESSION['userLevel'] > 0 && 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 { + if (!is_writable(str_replace("|","/",strClean($_GET['fileRef'])))) { + echo ""; + } else { + echo ''; + } + echo ''; + } + echo ''; +} + // If we're due to change permissions on a file/folder... if ($_GET['action']=="perms") { if ($_SESSION['userLevel'] > 0 && is_writable($file)) {