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
Next Next commit
Changing instances of dirname(__FILE__) to __DIR__
it's equivalent and easier to read this constant was introduced
in php version 5.3.
  • Loading branch information
rotelok committed Jun 16, 2018
commit 76dc065d82bcb6a31440bfa20ce195404d3fc45b
10 changes: 5 additions & 5 deletions editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,26 @@
//-->
<script src="<?php echo $ICEcoder["codeMirrorDir"]; ?>/lib/codemirror-compressed.js?microtime=<?php echo microtime(true);?>"></script>
<?php
if (file_exists(dirname(__FILE__)."/plugins/jshint/jshint-2.5.6.min.js")) {
if (file_exists(__DIR__."/plugins/jshint/jshint-2.5.6.min.js")) {
echo '<script src="plugins/jshint/jshint-2.5.6.min.js?microtime='.microtime(true).'></script>';
};?>
<script src="lib/mmd.js?microtime=<?php echo microtime(true);?>"></script>
<link rel="stylesheet" href="<?php echo $ICEcoder["codeMirrorDir"]; ?>/addon/fold/foldgutter.css?microtime=<?php echo microtime(true);?>">
<link rel="stylesheet" href="<?php echo $ICEcoder["codeMirrorDir"]; ?>/addon/scroll/simplescrollbars.css?microtime=<?php echo microtime(true);?>">
<?php
if (file_exists(dirname(__FILE__)."/plugins/emmet/emmet.min.js")) {
if (file_exists(__DIR__."/plugins/emmet/emmet.min.js")) {
echo '<script src="plugins/emmet/emmet.min.js?microtime='.microtime(true).'"></script>';
};?>
<?php
if (file_exists(dirname(__FILE__)."/plugins/pesticide/pesticide.js")) {
if (file_exists(__DIR__."/plugins/pesticide/pesticide.js")) {
echo '<script src="plugins/pesticide/pesticide.js?microtime='.microtime(true).'"></script>';
};?>
<?php
if (file_exists(dirname(__FILE__)."/plugins/stats.js/stats.min.js")) {
if (file_exists(__DIR__."/plugins/stats.js/stats.min.js")) {
echo '<script src="plugins/stats.js/stats.min.js?microtime='.microtime(true).'"></script>';
};?>
<?php
if (file_exists(dirname(__FILE__)."/plugins/responsive-helper/responsive-helper.js")) {
if (file_exists(__DIR__."/plugins/responsive-helper/responsive-helper.js")) {
echo '<script src="plugins/responsive-helper/responsive-helper.js?microtime='.microtime(true).'"></script>';
};?>
<link rel="stylesheet" href="<?php
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@
</span>
<div onMouseOver="ICEcoder.showFileMenu()" style="padding: 2px 0"><hr></div>
<?php
if (file_exists(dirname(__FILE__)."/plugins/zip-it/index.php")) {
if (file_exists(__DIR__."/plugins/zip-it/index.php")) {
echo '<a href="javascript:top.ICEcoder.zipIt(top.ICEcoder.selectedFiles[top.ICEcoder.selectedFiles.length-1])" onMouseOver="ICEcoder.showFileMenu()">Zip It!</a>'.PHP_EOL;
};
?>
Expand Down Expand Up @@ -344,4 +344,4 @@

</body>

</html>
</html>
4 changes: 2 additions & 2 deletions lib/backup-versions.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@

<?php
echo "fileName = '".basename($file)."';";
include(dirname(__FILE__)."/language-modes-partial.js");
include(__DIR__."/language-modes-partial.js");
?>

var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
Expand Down Expand Up @@ -167,4 +167,4 @@

</body>

</html>
</html>
4 changes: 2 additions & 2 deletions lib/bug-files-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}

// Get dir name tmp dir's parent
$tmpLoc = dirname(__FILE__);
$tmpLoc = __DIR__;
$tmpLoc = explode(DIRECTORY_SEPARATOR,$tmpLoc);
$tmpLoc = $tmpLoc[count($tmpLoc)-2];

Expand All @@ -112,4 +112,4 @@
// Finally, display our status in JSON format as the XHR response text
echo json_encode($status);

?>
?>
10 changes: 5 additions & 5 deletions lib/file-control-xhr.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function stitchChanges($fileLines) {
$backupDirFormat = "Y-m-d";

// Establish the base, host and date dir parts...
$backupDirBase = str_replace("\\","/",dirname(__FILE__))."/../backups/";
$backupDirBase = str_replace("\\","/",__DIR__)."/../backups/";
$backupDirHost = isset($ftpSite) ? parse_url(http://github.com/$ftpSite,PHP_URL_HOST) : "localhost";
$backupDirDate = date($backupDirFormat);

Expand Down Expand Up @@ -815,7 +815,7 @@ function getDetails($fileArr) {
} else {
// Delete file to tmp dir or full delete
$ICEcoder['deleteToTmp']
? rename($fullPath,str_replace("\\","/",dirname(__FILE__))."/../tmp/.".str_replace(":","_",str_replace("/","_",$fullPath)))
? rename($fullPath,str_replace("\\","/",__DIR__)."/../tmp/.".str_replace(":","_",str_replace("/","_",$fullPath)))
: unlink($fullPath);
}
$fileName = basename($fullPath);
Expand Down Expand Up @@ -847,14 +847,14 @@ function rrmdir($dir) {
rrmdir($dir."/".$object);
} else {
$ICEcoder['deleteToTmp']
? rename($dir."/".$object,str_replace("\\","/",dirname(__FILE__))."/../tmp/.".str_replace(":","_",str_replace("/","_",$dir))."/".$object)
? rename($dir."/".$object,str_replace("\\","/",__DIR__)."/../tmp/.".str_replace(":","_",str_replace("/","_",$dir))."/".$object)
: unlink($dir."/".$object);
}
}
}
reset($objects);
$ICEcoder['deleteToTmp']
? rename($dir,str_replace("\\","/",dirname(__FILE__))."/../tmp/.".str_replace(":","_",str_replace("/","_",$dir)))
? rename($dir,str_replace("\\","/",__DIR__)."/../tmp/.".str_replace(":","_",str_replace("/","_",$dir)))
: rmdir($dir);
}
};
Expand Down Expand Up @@ -1009,4 +1009,4 @@ function rrmdir($dir) {
"errorMsg" : "'.$errorMsg.'"
}
}';
?>
?>
6 changes: 3 additions & 3 deletions lib/headers.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php
// Stop if we're running an old version in the tmp dir
if(strpos(str_replace("\\","/",dirname(__FILE__)),"tmp/oldVersion") !== false) {
if(strpos(str_replace("\\","/",__DIR__),"tmp/oldVersion") !== false) {
die("This is an old version of ICEcoder. Won't run from tmp/oldVersion/ dir.");
}

// Load common functions
include_once(dirname(__FILE__)."/settings-common.php");
include_once(__DIR__."/settings-common.php");
if (isset($_SESSION['text'])) {
$text = $_SESSION['text'];
$t = $text['headers'];
Expand Down Expand Up @@ -37,4 +37,4 @@
header('Pragma: no-cache'); // Caching over HTTP 1.0 covered
header('Expires: 0'); // Caching over Proxies covered
}
?>
?>
10 changes: 5 additions & 5 deletions lib/settings-common.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Don't display, but log all errors
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__).'/../error-log.txt');
ini_set('error_log', __DIR__.'/../error-log.txt');
error_reporting(-1);

// Set our default timezone and supress warning with @
Expand All @@ -22,13 +22,13 @@
ini_set('session.name','ICEcoder_Cookie'); // Set a seperate cookie session name
ini_set('session.cookie_lifetime','0'); // Until the browser restarts by default
ini_set('session.cookie_domain',''); // This domain only
// ini_set('session.cookie_path',str_replace($_SERVER['DOCUMENT_ROOT'],'',dirname(dirname(__FILE__)))); // ICEcoder path only, fails ON IE
// ini_set('session.cookie_path',str_replace($_SERVER['DOCUMENT_ROOT'],'',dirname(__DIR__))); // ICEcoder path only, fails ON IE
ini_set('session.use_trans_sid','0'); // Ensure this insecure feature is disabled
ini_set('session.hash_function','sha512'); // Use Sha512 for session
ini_set('session.hash_bits_per_character','6'); // Specify hash scheme of 0-9,a-v,A-Z,-,,
// ini_set('session.use_strict_mode','1'); // Reject any session ID that was user provided and not generated by the session (since PHP 5.5.2)
ini_set('session.httponly','1'); // Only allow http protocol (ie, not JS) access to the cookie (since PHP 5.2.0)
ini_set('session.save_path',dirname(__FILE__).'/../tmp'); // Localise the session files to /tmp
ini_set('session.save_path',__DIR__.'/../tmp'); // Localise the session files to /tmp

if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') {
ini_set('session.cookie_secure','1'); // Only allows access to session ID when protocol is HTTPS, switched on under 'if https' condition
Expand Down Expand Up @@ -90,7 +90,7 @@ function getData($url,$type='fopen',$dieMessage=false,$timeout=60) {

// Logout if that's the action we're taking
if (isset($_GET['logout'])) {
include(dirname(__FILE__)."/../processes/on-user-logout.php");
include(__DIR__."/../processes/on-user-logout.php");
$_SESSION['loggedIn']=false;
$_SESSION['username']=false;
session_destroy();
Expand Down Expand Up @@ -254,7 +254,7 @@ function getVersionsCount($fileLoc,$fileName) {
$dateCounts = array();
$backupDateDirs = array();
// Establish the base, host and date dirs within...
$backupDirBase = str_replace("\\","/",dirname(__FILE__))."/../backups/";
$backupDirBase = str_replace("\\","/",__DIR__)."/../backups/";
$backupDirHost = isset($ftpSite) ? parse_url(http://github.com/$ftpSite,PHP_URL_HOST) : "localhost";
// check if folder exists if local before enumerating contents
if(!isset($ftpSite)) {
Expand Down
4 changes: 2 additions & 2 deletions lib/settings-screen.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
<div style="padding: 5px 5px 5px 5px; color: #888">
<?php
// Display number of days backups available
$backupDirBase = str_replace("\\","/",dirname(__FILE__))."/../backups/";
$backupDirBase = str_replace("\\","/",__DIR__)."/../backups/";
$backupDirHost = isset($ftpSite) ? parse_url(http://github.com/$ftpSite,PHP_URL_HOST) : "localhost";
$backupDirsList = scandir($backupDirBase.$backupDirHost);
// Remove . and .. from array
Expand Down Expand Up @@ -438,4 +438,4 @@ function changeFontSize() {

</body>

</html>
</html>
50 changes: 25 additions & 25 deletions lib/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

// Create a new config file if it doesn't exist yet.
// The reason we create it, is so it has PHP write permissions, meaning we can update it later
if (!file_exists(dirname(__FILE__)."/".$configSettings)) {
if (!file_exists(__DIR__."/".$configSettings)) {
// Include our params to make use of (as $newConfigSettingsFile)
include(dirname(__FILE__)."/settings-system-params.php");
if ($fConfigSettings = fopen(dirname(__FILE__)."/".$configSettings, 'w')) {
include(__DIR__."/settings-system-params.php");
if ($fConfigSettings = fopen(__DIR__."/".$configSettings, 'w')) {
fwrite($fConfigSettings, $newConfigSettingsFile);
fclose($fConfigSettings);
} else {
Expand All @@ -17,10 +17,10 @@
}

// Load config settings
include(dirname(__FILE__)."/".$configSettings);
include(__DIR__."/".$configSettings);

// Load common functions
include_once(dirname(__FILE__)."/settings-common.php");
include_once(__DIR__."/settings-common.php");

// Establish user settings file
$username = "";
Expand All @@ -32,15 +32,15 @@
$setPWorLogin = "login";

// Create user settings file if it doesn't exist
if (!file_exists(dirname(__FILE__)."/".$settingsFile) && $ICEcoderSettings['enableRegistration']) {
if (!copy(dirname(__FILE__)."/".$configUsersTemplate, dirname(__FILE__)."/".$settingsFile)) {
if (!file_exists(__DIR__."/".$settingsFile) && $ICEcoderSettings['enableRegistration']) {
if (!copy(__DIR__."/".$configUsersTemplate, __DIR__."/".$settingsFile)) {
die("Couldn't create $settingsFile. Maybe you need write permissions on the lib folder?");
}
$setPWorLogin = "set password";
}

// Load user settings
include(dirname(__FILE__)."/".$settingsFile);
include(__DIR__."/".$settingsFile);

// Remove any previous files that are no longer there
$prevFiles = explode(",",$ICEcoderUserSettings['previousFiles']);
Expand All @@ -55,9 +55,9 @@

// Replace our config created date with the filemtime?
if (basename($_SERVER['SCRIPT_NAME']) == "index.php" && $ICEcoderUserSettings['configCreateDate'] == 0) {
$settingsContents = getData(dirname(__FILE__)."/".$settingsFile);
$settingsContents = getData(__DIR__."/".$settingsFile);
clearstatcache();
$configfilemtime = filemtime(dirname(__FILE__)."/"."config___settings.php");
$configfilemtime = filemtime(__DIR__."/"."config___settings.php");
// Make it a number (avoids null, undefined etc)
$configfilemtime = intval($configfilemtime);
// Set it to the epoch time now if we don't have a real value
Expand All @@ -66,7 +66,7 @@
}
$settingsContents = str_replace('"configCreateDate" => 0,','"configCreateDate" => '.$configfilemtime.',',$settingsContents);
// Now update the config file
$fh = fopen(dirname(__FILE__)."/".$settingsFile, 'w') or die("Can't update config file. Please set public write permissions on ".$settingsFile." and press refresh");
$fh = fopen(__DIR__."/".$settingsFile, 'w') or die("Can't update config file. Please set public write permissions on ".$settingsFile." and press refresh");
fwrite($fh, $settingsContents);
fclose($fh);
// Set the new value in array
Expand All @@ -75,7 +75,7 @@

// On mismatch of settings file to system, rename to .old and reload
If ($ICEcoderUserSettings["versionNo"] != $ICEcoderSettings["versionNo"]) {
rename(dirname(__FILE__)."/".$settingsFile,dirname(__FILE__)."/".str_replace(".php",".old",$settingsFile));
rename(__DIR__."/".$settingsFile,__DIR__."/".str_replace(".php",".old",$settingsFile));
header("Location: settings.php");
echo "<script>window.location='settings.php';</script>";
die('Found old settings file, reloading...');
Expand All @@ -86,10 +86,10 @@

// Include language file
// Load base first as foundation
include(dirname(__FILE__)."/../lang/".basename($ICEcoder['languageBase']));
include(__DIR__."/../lang/".basename($ICEcoder['languageBase']));
$baseText = $text;
// Load chosen language ontop to replace base
include(dirname(__FILE__)."/../lang/".basename($ICEcoder['languageUser']));
include(__DIR__."/../lang/".basename($ICEcoder['languageUser']));
$text = array_replace_recursive($baseText, $text);
$_SESSION['text'] = $text;

Expand Down Expand Up @@ -117,7 +117,7 @@
$tDaysRemaining = intval($tRemaining/(60*60*24));

// Update this config file?
include(dirname(__FILE__)."/settings-update.php");
include(__DIR__."/settings-update.php");

// Set loggedIn and username to false if not set as yet
if (!isset($_SESSION['loggedIn'])) {$_SESSION['loggedIn'] = false;};
Expand All @@ -132,12 +132,12 @@
$_SESSION['username'] = $_POST['username'];
}
$_SESSION['loggedIn'] = true;
include(dirname(__FILE__)."/../processes/on-user-login.php");
include(__DIR__."/../processes/on-user-login.php");
header('Location: ../');
echo "<script>window.location='../';</script>";
die('Logging you in...');
} else {
include(dirname(__FILE__)."/../processes/on-user-login-fail.php");
include(__DIR__."/../processes/on-user-login-fail.php");
}
};

Expand Down Expand Up @@ -184,10 +184,10 @@
}

// Save currently opened files in previousFiles and last10Files arrays
include(dirname(__FILE__)."/settings-save-current-files.php");
include(__DIR__."/settings-save-current-files.php");

// Display the plugins
include(dirname(__FILE__)."/plugins-display.php");
include(__DIR__."/plugins-display.php");

// If loggedIn is false or we don't have a password set yet and we're not on login screen, boot user to that
if ((!$_SESSION['loggedIn'] || $ICEcoder["password"] == "") && !strpos($_SERVER['SCRIPT_NAME'],"lib/login.php")) {
Expand Down Expand Up @@ -251,15 +251,15 @@
$serverAddr = "127.0.0.1";
}
$settingsFileAddr = 'config-'.$username.str_replace(".","_",$serverAddr).'.php';
if (!file_exists(dirname(__FILE__)."/".$settingsFileAddr)) {
if (!copy(dirname(__FILE__)."/".$settingsFile, dirname(__FILE__)."/".$settingsFileAddr)) {
if (!file_exists(__DIR__."/".$settingsFileAddr)) {
if (!copy(__DIR__."/".$settingsFile, __DIR__."/".$settingsFileAddr)) {
die("Couldn't create $settingsFileAddr. Maybe you need write permissions on the lib folder?");
}
}
// Disable the enableRegistration config setting if the user had that option chosen
if (isset($_POST['disableFurtherRegistration'])) {
$updatedConfigSettingsFile = getData(dirname(__FILE__)."/".$configSettings);
if ($fUConfigSettings = fopen(dirname(__FILE__)."/".$configSettings, 'w')) {
$updatedConfigSettingsFile = getData(__DIR__."/".$configSettings);
if ($fUConfigSettings = fopen(__DIR__."/".$configSettings, 'w')) {
$updatedConfigSettingsFile = str_replace('"enableRegistration" => true','"enableRegistration" => false',$updatedConfigSettingsFile);
fwrite($fUConfigSettings, $updatedConfigSettingsFile);
fclose($fUConfigSettings);
Expand All @@ -272,7 +272,7 @@
$_SESSION['username']=$_POST['username'];
}
$_SESSION['loggedIn'] = true;
include(dirname(__FILE__)."/../processes/on-user-new.php");
include(__DIR__."/../processes/on-user-new.php");
// Finally, load again as now this file has changed and auto login
header('Location: ../');
echo "<script>window.location='../';</script>";
Expand All @@ -290,4 +290,4 @@
// Continue with whatever we're doing
// ==================================
}
?>
?>
6 changes: 3 additions & 3 deletions lib/terminal-xhr.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
include(dirname(__FILE__)."/headers.php");
include(dirname(__FILE__)."/settings.php");
include(__DIR__."/headers.php");
include(__DIR__."/settings.php");


function proc_open_enabled() {
Expand Down Expand Up @@ -40,7 +40,7 @@ function proc_open_enabled() {

// If command contains cd but no dir
if (preg_match('/^[[:blank:]]*cd[[:blank:]]*$/', @$_REQUEST['command'])) {
$_SESSION['cwd'] = getcwd(); //dirname(__FILE__);
$_SESSION['cwd'] = getcwd(); //__DIR__;
// Else cd to a dir
} elseif (preg_match('/^[[:blank:]]*cd[[:blank:]]+([^;]+)$/', @$_REQUEST['command'], $regs)) {
// The current command is 'cd', which we have to handle as an internal shell command
Expand Down
6 changes: 3 additions & 3 deletions lib/updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,11 @@ function copyOverSettings($icvInfo) {
echo 'Transposing system settings...<br>';
// Create a new config file if it doesn't exist yet.
// The reason we create it, is so it has PHP write permissions, meaning we can update it later
if (!file_exists(dirname(__FILE__)."/".$configSettings)) {
if (!file_exists(__DIR__."/".$configSettings)) {
echo 'Creating new settings file...<br>';
// Include our params to make use of (as $newConfigSettingsFile)
include(dirname(__FILE__)."/settings-system-params.php");
if ($fConfigSettings = fopen(dirname(__FILE__)."/".$configSettings, 'w')) {
include(__DIR__."/settings-system-params.php");
if ($fConfigSettings = fopen(__DIR__."/".$configSettings, 'w')) {
fwrite($fConfigSettings, $newConfigSettingsFile);
fclose($fConfigSettings);
} else {
Expand Down
Loading