2018-07-13 18:39:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) Codiad & Andr3as, distributed
|
|
|
|
* as-is and without warranty under the MIT License. See
|
|
|
|
* [root]/license.txt for more. This information must remain intact.
|
|
|
|
*/
|
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
class Settings {
|
|
|
|
|
2018-11-19 19:30:49 +01:00
|
|
|
const DEFAULT_OPTIONS = array(
|
2018-12-12 16:30:14 +01:00
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.autocomplete",
|
2019-01-15 16:33:59 +01:00
|
|
|
"value" => "true",
|
|
|
|
),
|
2018-11-19 19:30:49 +01:00
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.fileManagerTrigger",
|
|
|
|
"value" => "false",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.fontSize",
|
|
|
|
"value" => "14px",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.highlightLine",
|
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.indentGuides",
|
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.overScroll",
|
|
|
|
"value" => "0.5",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.persistentModal",
|
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.printMargin",
|
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.printMarginColumn",
|
|
|
|
"value" => "80",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.rightSidebarTrigger",
|
|
|
|
"value" => "false",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.softTabs",
|
|
|
|
"value" => "false",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.tabSize",
|
|
|
|
"value" => "4",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.theme",
|
|
|
|
"value" => "twilight",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.editor.wrapMode",
|
Changed $path to __DIR__ for config location, Updated auto reload variables, Removed unload listener for auto reload, Changed project default to array so that if no projects exist the program does not crash, Updated autosave to use let instead of vars, Fixed capitalization for sideExpanded variable, Added try catch to pdo initialization on install, Added more error checks on install, Removed password function on install query, Changed default settings array, Added loading div to user delete, Updated queries that threw errors when a default value was zero, Added blank username and password check,
2019-02-09 22:14:27 +01:00
|
|
|
"value" => "true",
|
2018-11-19 19:30:49 +01:00
|
|
|
),
|
|
|
|
array(
|
Changed $path to __DIR__ for config location, Updated auto reload variables, Removed unload listener for auto reload, Changed project default to array so that if no projects exist the program does not crash, Updated autosave to use let instead of vars, Fixed capitalization for sideExpanded variable, Added try catch to pdo initialization on install, Added more error checks on install, Removed password function on install query, Changed default settings array, Added loading div to user delete, Updated queries that threw errors when a default value was zero, Added blank username and password check,
2019-02-09 22:14:27 +01:00
|
|
|
"name" => "codiad.filemanager.autoReloadPreview",
|
2018-11-19 19:30:49 +01:00
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
array(
|
Changed $path to __DIR__ for config location, Updated auto reload variables, Removed unload listener for auto reload, Changed project default to array so that if no projects exist the program does not crash, Updated autosave to use let instead of vars, Fixed capitalization for sideExpanded variable, Added try catch to pdo initialization on install, Added more error checks on install, Removed password function on install query, Changed default settings array, Added loading div to user delete, Updated queries that threw errors when a default value was zero, Added blank username and password check,
2019-02-09 22:14:27 +01:00
|
|
|
"name" => "codiad.projects.sideExpanded",
|
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.settings.autosave",
|
2018-11-19 19:30:49 +01:00
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
"name" => "codiad.settings.plugin.sync",
|
|
|
|
"value" => "true",
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2018-10-09 21:30:00 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// PROPERTIES
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public $connection = '';
|
|
|
|
public $username = '';
|
|
|
|
public $settings = '';
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// METHODS
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// -----------------------------||----------------------------- //
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Construct
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
}
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
public function delete_option( $option, $username ) {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
global $sql;
|
2018-10-09 21:30:00 +02:00
|
|
|
if( $username == null ) {
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$query = "DELETE FROM options WHERE name=?";
|
2018-10-09 21:30:00 +02:00
|
|
|
$bind_variables = array(
|
|
|
|
$option,
|
|
|
|
);
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
2018-10-09 21:30:00 +02:00
|
|
|
} else {
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$query = "DELETE FROM options WHERE name=? AND username=?";
|
2018-10-09 21:30:00 +02:00
|
|
|
$bind_variables = array(
|
|
|
|
$option,
|
|
|
|
$this->username,
|
|
|
|
);
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $result > 0 ) {
|
|
|
|
|
|
|
|
echo formatJSEND( "success", null );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo formatJSEND( "error", "Could not delete option: $option" );
|
2018-10-09 21:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
public function get_option( $option, $user_setting, $action = "return" ) {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
global $sql;
|
2018-10-09 21:30:00 +02:00
|
|
|
if( $user_setting == null ) {
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$query = "SELECT value FROM options WHERE name=?;";
|
2018-10-09 21:30:00 +02:00
|
|
|
$bind_variables = array( $option );
|
2019-02-04 22:42:12 +01:00
|
|
|
$return = $sql->query( $query, $bind_variables, array() )[0];
|
2018-10-09 21:30:00 +02:00
|
|
|
} else {
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$query = "SELECT value FROM user_options WHERE name=? AND username=?;";
|
2018-10-09 21:30:00 +02:00
|
|
|
$bind_variables = array( $option, $this->username );
|
2019-02-04 22:42:12 +01:00
|
|
|
$return = $sql->query( $query, $bind_variables, array() )[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ! empty( $return ) ) {
|
2019-02-13 18:08:51 +01:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$return = $return["value"];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$return = null;
|
2018-10-09 21:30:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
switch( $action ) {
|
|
|
|
|
|
|
|
case( "exit" ):
|
|
|
|
|
|
|
|
exit( $return );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case( "return" ):
|
|
|
|
|
|
|
|
return( $return );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Save User Settings
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public function Save() {
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
global $sql;
|
2018-10-09 21:30:00 +02:00
|
|
|
foreach( $this->settings as $option => $value ) {
|
|
|
|
|
|
|
|
$this->update_option( $option, $value, $this->username );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Load User Settings
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
public function Load() {
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
global $sql;
|
|
|
|
$query = "SELECT DISTINCT * FROM user_options WHERE username=?;";
|
2018-10-09 21:30:00 +02:00
|
|
|
$bind_variables = array(
|
|
|
|
$this->username
|
|
|
|
);
|
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
$options = $sql->query( $query, $bind_variables, array() );
|
|
|
|
|
|
|
|
if( ! empty( $options ) ) {
|
|
|
|
|
|
|
|
echo formatJSEND( "success", $options );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo formatJSEND( "error", "Error, Could not load user's settings." );
|
|
|
|
}
|
2018-10-09 21:30:00 +02:00
|
|
|
}
|
|
|
|
|
2019-02-11 04:49:20 +01:00
|
|
|
public function update_option( $option, $value, $user_setting = true ) {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-04 22:42:12 +01:00
|
|
|
global $sql;
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-11 04:49:20 +01:00
|
|
|
if( $user_setting == null ) {
|
2018-10-09 21:30:00 +02:00
|
|
|
|
2019-02-11 04:49:20 +01:00
|
|
|
$query = "INSERT INTO options ( name, username, value ) VALUES ( ?, ? );";
|
2018-10-09 21:30:00 +02:00
|
|
|
$bind_variables = array(
|
2019-02-11 04:49:20 +01:00
|
|
|
$option,
|
2018-10-09 21:30:00 +02:00
|
|
|
$value,
|
2019-02-11 04:49:20 +01:00
|
|
|
);
|
|
|
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
|
|
|
|
|
|
|
if( $result == 0 ) {
|
|
|
|
|
|
|
|
$query = "UPDATE options SET value=? WHERE name=?;";
|
|
|
|
$bind_variables = array(
|
|
|
|
$value,
|
|
|
|
$option,
|
|
|
|
);
|
|
|
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$query = "INSERT INTO user_options ( name, username, value ) VALUES ( ?, ?, ? );";
|
|
|
|
$bind_variables = array(
|
2018-10-09 21:30:00 +02:00
|
|
|
$option,
|
|
|
|
$this->username,
|
2019-02-11 04:49:20 +01:00
|
|
|
$value,
|
2018-10-09 21:30:00 +02:00
|
|
|
);
|
2019-02-04 22:42:12 +01:00
|
|
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
2019-02-11 04:49:20 +01:00
|
|
|
|
|
|
|
if( $result == 0 ) {
|
|
|
|
|
|
|
|
$query = "UPDATE user_options SET value=? WHERE name=? AND username=?;";
|
|
|
|
$bind_variables = array(
|
|
|
|
$value,
|
|
|
|
$option,
|
|
|
|
$this->username,
|
|
|
|
);
|
|
|
|
$result = $sql->query( $query, $bind_variables, 0, "rowCount" );
|
|
|
|
}
|
2019-02-04 22:42:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $result > 0 ) {
|
|
|
|
|
|
|
|
echo formatJSEND( "success", null );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo formatJSEND( "error", "Error, Could not update option $option" );
|
2018-10-09 21:30:00 +02:00
|
|
|
}
|
|
|
|
}
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|