settings.php using class methods, using types, indentType used, fix lang reload

This commit is contained in:
mattpass
2020-07-11 10:27:43 +01:00
parent 0537b0fe9c
commit afd75f99ee

View File

@@ -1,4 +1,8 @@
<?php
require_once dirname(__FILE__) . "/../classes/Settings.php";
$settingsClass = new \ICEcoder\Settings();
include_once "settings-common.php";
$text = $_SESSION['text'];
$t = $text['settings-update'];
@@ -7,14 +11,9 @@ $t = $text['settings-update'];
if (!$demoMode && true === isset($_SESSION['loggedIn']) && $_SESSION['loggedIn'] &&
(true === isset($_POST["theme"]) && $_POST["theme"] || true === isset($_GET['action']) && "turnOffTutorialOnLogin" === $_GET['action'])
) {
$settingsContents = getData("../data/" . $settingsFile);
// Just updating tutorialOnLogin setting
if (true === isset($_GET['action']) && "turnOffTutorialOnLogin" === $_GET['action']) {
if (is_writeable("../data/" . $settingsFile)) {
$fh = fopen("../data/" . $settingsFile, 'w');
fwrite($fh, str_replace('"tutorialOnLogin" => true', '"tutorialOnLogin" => false', $settingsContents));
fclose($fh);
if (true === $settingsClass->turnOffTutorialOnLogin($settingsFile)) {
$ICEcoder['tutorialOnLogin'] = false;
} else {
echo "<script>parent.ICEcoder.message('" . $t['Cannot update config'] . " data/" . $settingsFile . " " . $t['and try again'] . "');</script>";
@@ -22,78 +21,68 @@ if (!$demoMode && true === isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']
exit;
}
// Replace our settings vars
$repPosStart = strpos($settingsContents, '"root"');
$repPosEnd = strpos($settingsContents, '"plugins"');
$currentSettings = $settingsClass->getConfigUsersSettings($settingsFile);
// Has there been a language change?
$languageUserChanged = $ICEcoder['languageUser'] != $_POST['languageUser'];
// Prepare all our vars
$ICEcoder = array_merge(
$ICEcoder,
[
"root" => xssClean($_POST['root'], "html"),
"checkUpdates" => isset($_POST['checkUpdates']) && $_POST['checkUpdates'] ? "true" : "false",
"openLastFiles" => isset($_POST['openLastFiles']) && $_POST['openLastFiles'] ? "true" : "false",
"updateDiffOnSave" => isset($_POST['updateDiffOnSave']) && $_POST['updateDiffOnSave'] ? "true" : "false",
"languageUser" => $_POST['languageUser'],
"backupsKept" => isset($_POST['backupsKept']) && $_POST['backupsKept'] ? "true" : "false",
"backupsDays" => intval($_POST['backupsDays']),
"deleteToTmp" => isset($_POST['deleteToTmp']) && $_POST['deleteToTmp'] ? "true" : "false",
"findFilesExclude" => 'array("'.str_replace(',', '","', str_replace(" ", "", $_POST['findFilesExclude'])) . '")',
"codeAssist" => isset($_POST['codeAssist']) && $_POST['codeAssist'] ? "true" : "false",
"visibleTabs" => isset($_POST['visibleTabs']) && $_POST['visibleTabs'] ? "true" : "false",
"lockedNav" => isset($_POST['lockedNav']) && $_POST['lockedNav'] ? "true" : "false",
"tagWrapperCommand" => $_POST['tagWrapperCommand'],
"autoComplete" => $_POST['autoComplete'],
"bannedFiles" => 'array("' . str_replace(',', '","', str_replace(" ", "", $_POST['bannedFiles'])) . '")',
"bannedPaths" => 'array("' . str_replace(',', '","', str_replace(" ", "", $_POST['bannedPaths'])) . '")',
"allowedIPs" => 'array("' . str_replace(',', '","', str_replace(" ", "", $_POST['allowedIPs'])) . '")',
"autoLogoutMins" => intval($_POST['autoLogoutMins']),
"theme" => $_POST['theme'],
"fontSize" => $_POST['fontSize'],
"lineWrapping" => $_POST['lineWrapping'],
"lineNumbers" => $_POST['lineNumbers'],
"showTrailingSpace" => $_POST['showTrailingSpace'],
"matchBrackets" => $_POST['matchBrackets'],
"autoCloseTags" => $_POST['autoCloseTags'],
"autoCloseBrackets" => $_POST['autoCloseBrackets'],
"indentWithTabs" => $_POST['indentWithTabs'],
"indentAuto" => $_POST['indentAuto'],
"indentSize" => intval($_POST['indentSize']),
"pluginPanelAligned" => $_POST['pluginPanelAligned'],
"scrollbarStyle" => $_POST['scrollbarStyle'],
"bugFilePaths" => 'array("'.str_replace(',', '","', str_replace(" ", "", $_POST['bugFilePaths'])) . '")',
"bugFileCheckTimer" => intval($_POST['bugFileCheckTimer']) >= 0 ? intval($_POST['bugFileCheckTimer']) : 0,
"bugFileMaxLines" => intval($_POST['bugFileMaxLines'])
]
);
$updatedSettings = [
"versionNo" => $currentSettings['versionNo'],
"licenseEmail" => $currentSettings['licenseEmail'],
"licenseCode" => $currentSettings['licenseCode'],
"configCreateDate" => $currentSettings['configCreateDate'],
"root" => xssClean($_POST['root'], "html"),
"checkUpdates" => isset($_POST['checkUpdates']) && $_POST['checkUpdates'],
"openLastFiles" => isset($_POST['openLastFiles']) && $_POST['openLastFiles'],
"updateDiffOnSave" => isset($_POST['updateDiffOnSave']) && $_POST['updateDiffOnSave'],
"languageUser" => $_POST['languageUser'],
"backupsKept" => isset($_POST['backupsKept']) && $_POST['backupsKept'],
"backupsDays" => intval($_POST['backupsDays']),
"deleteToTmp" => isset($_POST['deleteToTmp']) && $_POST['deleteToTmp'],
"findFilesExclude" => explode(",", str_replace(" ", "", $_POST['findFilesExclude'])),
"codeAssist" => isset($_POST['codeAssist']) && $_POST['codeAssist'],
"visibleTabs" => isset($_POST['visibleTabs']) && $_POST['visibleTabs'],
"lockedNav" => isset($_POST['lockedNav']) && $_POST['lockedNav'],
"tagWrapperCommand" => $_POST['tagWrapperCommand'],
"autoComplete" => $_POST['autoComplete'],
"password" => $currentSettings['password'],
"bannedFiles" => explode(",", str_replace(" ", "", $_POST['bannedFiles'])),
"bannedPaths" => explode(",", str_replace(" ", "", $_POST['bannedPaths'])),
"allowedIPs" => explode(",", str_replace(" ", "", $_POST['allowedIPs'])),
"autoLogoutMins" => intval($_POST['autoLogoutMins']),
"theme" => $_POST['theme'],
"fontSize" => $_POST['fontSize'],
"lineWrapping" => $_POST['lineWrapping'],
"lineNumbers" => $_POST['lineNumbers'],
"showTrailingSpace" => $_POST['showTrailingSpace'],
"matchBrackets" => $_POST['matchBrackets'],
"autoCloseTags" => $_POST['autoCloseTags'],
"autoCloseBrackets" => $_POST['autoCloseBrackets'],
"indentType" => $_POST['indentType'],
"indentAuto" => $_POST['indentAuto'],
"indentSize" => intval($_POST['indentSize']),
"pluginPanelAligned" => $_POST['pluginPanelAligned'],
"scrollbarStyle" => $_POST['scrollbarStyle'],
"bugFilePaths" => explode(",", str_replace(" ", "", $_POST['bugFilePaths'])),
"bugFileCheckTimer" => intval($_POST['bugFileCheckTimer']) >= 0 ? intval($_POST['bugFileCheckTimer']) : 0,
"bugFileMaxLines" => intval($_POST['bugFileMaxLines']),
"plugins" => $currentSettings['plugins'],
"ftpSites" => $currentSettings['ftpSites'],
"tutorialOnLogin" => isset($_POST['tutorialOnLogin']) && $_POST['tutorialOnLogin'],
"tipsOnLogin" => isset($_POST['tipsOnLogin']) && $_POST['tipsOnLogin'],
"previousFiles" => $currentSettings['previousFiles'],
"last10Files" => $currentSettings['last10Files'],
"favoritePaths" => $currentSettings['favoritePaths'],
];
if ($_POST['password']!="") {$ICEcoder["password"] = generateHash($_POST['password']);};
if ($_POST['password']!="") {$updatedSettings["password"] = generateHash($_POST['password']);};
$settingsArray = ["root", "checkUpdates", "openLastFiles", "updateDiffOnSave", "languageUser", "backupsKept", "backupsDays", "deleteToTmp", "findFilesExclude", "codeAssist", "visibleTabs", "lockedNav", "tagWrapperCommand", "autoComplete", "password", "bannedFiles", "bannedPaths", "allowedIPs", "autoLogoutMins", "theme", "fontSize", "lineWrapping", "lineNumbers", "showTrailingSpace", "matchBrackets", "autoCloseTags", "autoCloseBrackets", "indentWithTabs", "indentAuto", "indentSize", "pluginPanelAligned", "scrollbarStyle", "bugFilePaths", "bugFileCheckTimer", "bugFileMaxLines"];
$settingsNew = "";
for ($i = 0;$i < count($settingsArray); $i++) {
$settingsNew .= '"' . $settingsArray[$i] . '" => ';
// Wrap certain values in double quotes
$settingWrap = $settingsArray[$i] == "root" || $settingsArray[$i] == "password" || $settingsArray[$i] == "languageUser" || $settingsArray[$i] == "theme" || $settingsArray[$i] == "fontSize" || $settingsArray[$i] == "tagWrapperCommand" || $settingsArray[$i] == "autoComplete" || $settingsArray[$i] == "pluginPanelAligned" || $settingsArray[$i] == "scrollbarStyle" ? '"' : '';
if ("password" === $settingsArray[$i]) {
$settingsNew .= str_replace("\$", "\\$", $settingWrap . $ICEcoder[$settingsArray[$i]] . $settingWrap . ',' . PHP_EOL);
} else {
$settingsNew .= $settingWrap.$ICEcoder[$settingsArray[$i]] . $settingWrap . ',' . PHP_EOL;
}
}
// Compile our new settings
$settingsContents = substr($settingsContents, 0, $repPosStart) . $settingsNew . substr($settingsContents, ($repPosEnd), strlen($settingsContents));
$ICEcoder = array_merge($ICEcoder, $updatedSettings);
// Now update the config file
if (is_writeable("../data/".$settingsFile)) {
$fh = fopen("../data/".$settingsFile, 'w');
fwrite($fh, $settingsContents);
fclose($fh);
$settingsClass->setConfigUsersSettings($settingsFile, $updatedSettings);
} else {
echo "<script>parent.ICEcoder.message('" . $t['Cannot update config'] . " data/" . $settingsFile . " " . $t['and try again'] . "');</script>";
}
@@ -118,9 +107,9 @@ if (!$demoMode && true === isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']
$ICEcoderSettingsFromFile['enableRegistration'] = isset($_POST['enableRegistration']) && $_POST['enableRegistration'];
$settingsClass->setConfigGlobalSettings($ICEcoderSettingsFromFile);
// If we've changed langugage, reload ICEcoder now
// If we've changed language, reload ICEcoder now
if ($languageUserChanged) {
echo '<script>window.location = "../";</script>';
echo '<script>parent.window.location = "../";</script>';
die('Reloading ICEcoder after language change');
}
@@ -128,27 +117,27 @@ if (!$demoMode && true === isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']
$jsBugFilePaths = "['" . str_replace(",", "','", str_replace(" ", "", $_POST['bugFilePaths'])) . "']";
echo "<script>parent.ICEcoder.settingsScreen('hide'); parent.ICEcoder.useNewSettings('" .
$themeURL . "'," .
$ICEcoder["codeAssist"] . "," .
$ICEcoder["lockedNav"] . ",'" .
(true === $ICEcoder["codeAssist"] ? "true" : "false") . "," .
(true === $ICEcoder["lockedNav"] ? "true" : "false") . ",'" .
$ICEcoder["tagWrapperCommand"] . "','" .
$ICEcoder["autoComplete"] . "'," .
$ICEcoder["visibleTabs"] . ",'" .
(true === $ICEcoder["autoComplete"] ? "true" : "false") . "'," .
(true === $ICEcoder["visibleTabs"] ? "true" : "false") . ",'" .
$ICEcoder["fontSize"] . "'," .
$ICEcoder["lineWrapping"] . "," .
$ICEcoder["lineNumbers"] . "," .
$ICEcoder["showTrailingSpace"] . "," .
$ICEcoder["matchBrackets"] . "," .
$ICEcoder["autoCloseTags"] . "," .
$ICEcoder["autoCloseBrackets"] . "," .
$ICEcoder["indentWithTabs"] . "," .
$ICEcoder["indentAuto"] . "," .
(true === $ICEcoder["lineWrapping"] ? "true" : "false") . "," .
(true === $ICEcoder["lineNumbers"] ? "true" : "false") . "," .
(true === $ICEcoder["showTrailingSpace"] ? "true" : "false") . "," .
(true === $ICEcoder["matchBrackets"] ? "true" : "false") . "," .
(true === $ICEcoder["autoCloseTags"] ? "true" : "false") . "," .
(true === $ICEcoder["autoCloseBrackets"] ? "true" : "false") . ",'" .
$ICEcoder["indentType"] . "'," .
(true === $ICEcoder["indentAuto"] ? "true" : "false") . "," .
$ICEcoder["indentSize"] . ",'" .
$ICEcoder["pluginPanelAligned"] . "','" .
$ICEcoder["scrollbarStyle"] . "'," .
$jsBugFilePaths . "," .
$ICEcoder["bugFileCheckTimer"] . "," .
$ICEcoder["bugFileMaxLines"] . "," .
$ICEcoder["updateDiffOnSave"] . "," .
(true === $ICEcoder["updateDiffOnSave"] ? "true" : "false") . "," .
$ICEcoder["autoLogoutMins"] . "," .
$refreshFM .
");iceRoot = '" . $ICEcoder["root"] .