Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Increase readability #741

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merging multiple sequential str_replace() calls
  • Loading branch information
rotelok committed Jun 16, 2018
commit 399c046b6ae55be85df8554ef21ed96e07f40ac1
12 changes: 4 additions & 8 deletions lib/file-control-xhr.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ function stitchChanges($fileLines) {

// replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding
$contents = str_replace("\r\n", $ICEcoder["lineEnding"], $contents);
$contents = str_replace("\r", $ICEcoder["lineEnding"], $contents);
$contents = str_replace("\n", $ICEcoder["lineEnding"], $contents);
$contents = str_replace(array("\r", "\n"), array($ICEcoder["lineEnding"], $ICEcoder["lineEnding"]), $contents);
if (isset($_POST['changes']) && ($unixNewLines > 0) || ($windowsNewLines > 0)){
if ($unixNewLines > $windowsNewLines){
$contents = str_replace($ICEcoder["lineEnding"], "\n", $contents);
Expand Down Expand Up @@ -330,8 +329,7 @@ function stitchChanges($fileLines) {

// replace \r\n (Windows), \r (old Mac) and \n (Linux) line endings with whatever we chose to be lineEnding
$contents = str_replace("\r\n", $ICEcoder["lineEnding"], $contents);
$contents = str_replace("\r", $ICEcoder["lineEnding"], $contents);
$contents = str_replace("\n", $ICEcoder["lineEnding"], $contents);
$contents = str_replace(array("\r", "\n"), array($ICEcoder["lineEnding"], $ICEcoder["lineEnding"]), $contents);
if (isset($_POST['changes']) && ($unixNewLines > 0) || ($windowsNewLines > 0)){
if ($unixNewLines > $windowsNewLines){
$contents = str_replace($ICEcoder["lineEnding"], "\n", $contents);
Expand Down Expand Up @@ -801,8 +799,7 @@ function getDetails($fileArr) {
// Local
} else {
for ($i=0;$i<count($filesArray);$i++) {
$fullPath = str_replace($docRoot,"",$filesArray[$i]);
$fullPath = str_replace($iceRoot,"",$fullPath);
$fullPath = str_replace(array($docRoot, $iceRoot), "", $filesArray[$i]);
$fullPath = $docRoot.$iceRoot.$fullPath;

if (rtrim($fullPath,"/") == rtrim($docRoot,"/")) {
Expand Down Expand Up @@ -887,8 +884,7 @@ function rrmdir($dir) {
if ($remoteFile = toUTF8noBOM(getData($file,'curl'),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);
$remoteFile = str_replace("\n", $ICEcoder["lineEnding"], $remoteFile);
$remoteFile = str_replace(array("\r", "\n"), array($ICEcoder["lineEnding"], $ICEcoder["lineEnding"]), $remoteFile);
$doNext .= 'top.ICEcoder.newTab();';
$doNext .= 'top.ICEcoder.getcMInstance().setValue(\''.str_replace("\r","",str_replace("\t","\\\\t",str_replace("\n","\\\\n",str_replace("'","\\\\'",str_replace("\\","\\\\",preg_quote($remoteFile)))))).'\');';
$doNext .= 'top.ICEcoder.goToLine('.$lineNumber.');';
Expand Down
3 changes: 1 addition & 2 deletions lib/file-control.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@
$ghRemoteURLPaths = $ICEcoder['githubRemotePaths'];
$ghRemoteURL = $ghRemoteURLPaths[$ghRemoteURLPos];

$ghRemoteURL = str_replace("https://github.com/","",$ghRemoteURL);
$ghRemoteURL = str_replace("/","|",$ghRemoteURL);
$ghRemoteURL = str_replace(array("https://github.com/", "/"), array("", "|"), $ghRemoteURL);

// If the file is not in a sub-sub dir of the doc root
if (!strpos($fileLoc,"/",1)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/multiple-results.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
userTarget = top.document.findAndReplace.target.value;
findText = top.findAndReplace.find.value;
<?php
$findText = str_replace("ICEcoder:","",str_replace("&#39;","\'",$_GET['find']));
$findText = str_replace(array("&#39;", "ICEcoder:"), array("\'", ""), $_GET['find']);
// Find in open docs?
if (!isset($_GET['target'])) {
$targetName = $t['document'];
Expand Down
2 changes: 1 addition & 1 deletion lib/settings-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ function xssClean($data,$type) {

// Clean PHP code injection attempts
function injClean($data) {
$output = str_replace("(", "", str_replace(")", "", str_replace(";", "", $data)));
$output = str_replace(array(")", "("), "", str_replace(";", "", $data));
return $output;
}

Expand Down
6 changes: 2 additions & 4 deletions lib/settings-update.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,10 @@
// Change multiUser and enableRegistration in config___settings.php
$generalSettingsContents = getData($configSettings);
$isMultiUser = isset($_POST['multiUser']) && $_POST['multiUser'] ? "true" : "false";
$generalSettingsContents = str_replace('"multiUser" => true,','"multiUser" => '.$isMultiUser.',',$generalSettingsContents);
$generalSettingsContents = str_replace('"multiUser" => false,','"multiUser" => '.$isMultiUser.',',$generalSettingsContents);
$generalSettingsContents = str_replace(array('"multiUser" => true,', '"multiUser" => false,'), array('"multiUser" => ' . $isMultiUser . ',', '"multiUser" => ' . $isMultiUser . ','), $generalSettingsContents);

$isEnableRegistration = isset($_POST['enableRegistration']) && $_POST['enableRegistration'] ? "true" : "false";
$generalSettingsContents = str_replace('"enableRegistration" => true','"enableRegistration" => '.$isEnableRegistration,$generalSettingsContents);
$generalSettingsContents = str_replace('"enableRegistration" => false','"enableRegistration" => '.$isEnableRegistration,$generalSettingsContents);
$generalSettingsContents = str_replace(array('"enableRegistration" => true', '"enableRegistration" => false'), array('"enableRegistration" => ' . $isEnableRegistration, '"enableRegistration" => ' . $isEnableRegistration), $generalSettingsContents);

if (is_writable($configSettings)) {
$fConfigSettings = fopen($configSettings, 'w');
Expand Down
6 changes: 2 additions & 4 deletions lib/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,7 @@
if (generateHash(strClean($_POST['email']),$_POST['code'])==$_POST['code']) {
$settingsContents = getData($settingsFile);
// Replace our empty email & code with the one submitted by user
$settingsContents = str_replace('"licenseEmail" => "",','"licenseEmail" => "'.$_POST['email'].'",',$settingsContents);
$settingsContents = str_replace('"licenseCode" => "",','"licenseCode" => "'.$_POST['code'].'",',$settingsContents);
$settingsContents = str_replace(array('"licenseEmail" => "",', '"licenseCode" => "",'), array('"licenseEmail" => "' . $_POST['email'] . '",', '"licenseCode" => "' . $_POST['code'] . '",'), $settingsContents);
// Now update the config file
$fh = fopen($settingsFile, 'w') or die("Can't update config file. Please set public write permissions on ".$settingsFile." and press refresh");
fwrite($fh, $settingsContents);
Expand Down Expand Up @@ -239,8 +238,7 @@
// Also set the update checker preference
$checkUpdates = $_POST['checkUpdates']=="true" ? "true" : "false";
// once to cover the true setting, once to cover false
$settingsContents = str_replace('"checkUpdates" => true,','"checkUpdates" => '.$checkUpdates.',',$settingsContents);
$settingsContents = str_replace('"checkUpdates" => false,','"checkUpdates" => '.$checkUpdates.',',$settingsContents);
$settingsContents = str_replace(array('"checkUpdates" => true,', '"checkUpdates" => false,'), array('"checkUpdates" => ' . $checkUpdates . ',', '"checkUpdates" => ' . $checkUpdates . ','), $settingsContents);
// Now update the config file
$fh = fopen($settingsFile, 'w') or die("Can't update config file. Please set public write permissions on ".$settingsFile." and press refresh");
fwrite($fh, $settingsContents);
Expand Down