From 3710fa9e7944b286432483c7cdfc97fd8170ff47 Mon Sep 17 00:00:00 2001 From: Matt Pass Date: Wed, 22 May 2013 12:58:33 +0100 Subject: [PATCH] Convert content to UTF8 no BOM Detect bad chars and BOMs in loaded content and convert plus show message to inform user Affects: Loaded files, remote loaded files, replacing text in files, saving files --- lib/file-control.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/file-control.php b/lib/file-control.php index 2fe3170..98d8542 100644 --- a/lib/file-control.php +++ b/lib/file-control.php @@ -1,4 +1,4 @@ - + fileType="text";'; echo 'top.ICEcoder.shortURL = top.ICEcoder.rightClickedFile = top.ICEcoder.thisFileFolderLink = "'.$fileLoc."/".$fileName.'";'; echo ''; - $loadedFile = file_get_contents($file); + $loadedFile = toUTF8noBOM(file_get_contents($file),true); echo '","",str_replace("&","&",$loadedFile)).''; } else if (strpos($finfo,"image")===0) { echo ''; @@ -53,7 +53,7 @@ if ($_GET['action']=="load") { // Get the contents of a remote URL if ($_GET['action']=="getRemoteFile") { - if ($remoteFile = file_get_contents($file)) { + if ($remoteFile = toUTF8noBOM(file_get_contents($file),true)) { // replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding $remoteFile = str_replace("\r\n", $ICEcoder["lineEnding"], $remoteFile); $remoteFile = str_replace("\r", $ICEcoder["lineEnding"], $remoteFile); @@ -197,7 +197,7 @@ if ($_GET['action']=="rename") { if ($_GET['action']=="replaceText") { if (!$demoMode && is_writable(str_replace("|","/",strClean($_GET['fileRef'])))) { $file = str_replace("|","/",strClean($_GET['fileRef'])); - $loadedFile = file_get_contents($file); + $loadedFile = toUTF8noBOM(file_get_contents($file),true); $newContent = str_replace(strClean($_GET['find']),strClean($_GET['replace']),$loadedFile); $fh = fopen($file, 'w') or die("Sorry, cannot save"); fwrite($fh, $newContent); @@ -290,7 +290,7 @@ if ($_GET['action']=="save") { // Reload previewWindow window if not a Markdown file echo ''; } else { - $loadedFile = file_get_contents($file); + $loadedFile = toUTF8noBOM(file_get_contents($file),true); echo '","",htmlentities($loadedFile)).''; echo ''; ?>