|
@@ -1,17 +1,61 @@
|
|
|
<?php
|
|
|
define('PATH_ROOT',realpath(dirname(__FILE__)).'/../');
|
|
|
define('PATH_CONFIG',PATH_ROOT.'config.json');
|
|
|
+ define('PATH_DEFAULT_CONFIG',PATH_ROOT.'config.default.json');
|
|
|
define('PATH_PHP',PATH_ROOT.'php/');
|
|
|
define('PATH_JS',PATH_ROOT.'js/');
|
|
|
define('PATH_CSS',PATH_ROOT.'css/');
|
|
|
define('PATH_DATA',PATH_ROOT.'data/');
|
|
|
- $GLOBALS['config'] = json_decode(file_get_contents(PATH_CONFIG),true);
|
|
|
+ global $config;
|
|
|
+ if(file_exists(PATH_CONFIG)){
|
|
|
+ $config = objectToArray(json_decode(file_get_contents(PATH_CONFIG),true));
|
|
|
+ }else{
|
|
|
+ $config = Array();
|
|
|
+ }
|
|
|
+ $config = array_merge($config,objectToArray(json_decode(file_get_contents(PATH_DEFAULT_CONFIG),true)));
|
|
|
function get($setting){
|
|
|
- return $GLOBALS['config'][$setting];
|
|
|
+ global $config;
|
|
|
+ if(isset($config[$setting])){
|
|
|
+ return $config[$setting];
|
|
|
+ }else{
|
|
|
+ return false;
|
|
|
+ }
|
|
|
}
|
|
|
function set($setting,$value){
|
|
|
- $GLOBALS['config'][$setting] = $value;
|
|
|
- file_put_contents(PAT_CONFIG,json_encode($GLOBALS['config']));
|
|
|
+ global $config;
|
|
|
+ $config[$setting] = $value;
|
|
|
+ file_put_contents(PAT_CONFIG,json_encode($config));
|
|
|
return $value;
|
|
|
}
|
|
|
+ function objectToArray($d){
|
|
|
+ if(is_object($d)){
|
|
|
+ // Gets the properties of the given object
|
|
|
+ // with get_object_vars function
|
|
|
+ $d = get_object_vars($d);
|
|
|
+ }
|
|
|
+ if(is_array($d)){
|
|
|
+ /*
|
|
|
+ * Return array converted to object
|
|
|
+ * Using __FUNCTION__ (Magic constant)
|
|
|
+ * for recursive call
|
|
|
+ */
|
|
|
+ return array_map(__FUNCTION__, $d);
|
|
|
+ }else{
|
|
|
+ // Return array
|
|
|
+ return $d;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ function arrayToObject($d){
|
|
|
+ if(is_array($d)){
|
|
|
+ /*
|
|
|
+ * Return array converted to object
|
|
|
+ * Using __FUNCTION__ (Magic constant)
|
|
|
+ * for recursive call
|
|
|
+ */
|
|
|
+ return (object)array_map(__FUNCTION__, $d);
|
|
|
+ }else{
|
|
|
+ // Return object
|
|
|
+ return $d;
|
|
|
+ }
|
|
|
+ }
|
|
|
?>
|