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
This commit is contained in:
Matt Pass
2013-05-22 12:58:33 +01:00
parent b059261065
commit 3710fa9e79

View File

@@ -1,4 +1,4 @@
<?php include("settings.php");?>
<?php include("settings.php");?>
<?php
// Get the save type if any
$saveType = isset($_GET['saveType']) ? strClean($_GET['saveType']) : "";
@@ -38,7 +38,7 @@ if ($_GET['action']=="load") {
echo '<script>fileType="text";';
echo 'top.ICEcoder.shortURL = top.ICEcoder.rightClickedFile = top.ICEcoder.thisFileFolderLink = "'.$fileLoc."/".$fileName.'";';
echo '</script>';
$loadedFile = file_get_contents($file);
$loadedFile = toUTF8noBOM(file_get_contents($file),true);
echo '<textarea name="loadedFile" id="loadedFile">'.str_replace("</textarea>","<ICEcoder:/:textarea>",str_replace("&","&amp;",$loadedFile)).'</textarea>';
} else if (strpos($finfo,"image")===0) {
echo '<script>fileType="image";fileName=\''.$fileLoc."/".$fileName.'\'</script>';
@@ -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 '<script>if (top.ICEcoder.previewWindow.location && top.ICEcoder.previewWindow.location.pathname.indexOf(".md")==-1) {top.ICEcoder.previewWindow.location.reload()};action="doneSave";</script>';
} else {
$loadedFile = file_get_contents($file);
$loadedFile = toUTF8noBOM(file_get_contents($file),true);
echo '<textarea name="loadedFile" id="loadedFile">'.str_replace("</textarea>","<ICEcoder:/:textarea>",htmlentities($loadedFile)).'</textarea>';
echo '<textarea name="userVersionFile" id="userVersionFile"></textarea>';
?>