config.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. define('PATH_ROOT',realpath(dirname(__FILE__)).'/../');
  3. define('PATH_CONFIG',PATH_ROOT.'config.json');
  4. define('PATH_DEFAULT_CONFIG',PATH_ROOT.'config.default.json');
  5. define('PATH_PHP',PATH_ROOT.'php/');
  6. define('PATH_JS',PATH_ROOT.'js/');
  7. define('PATH_CSS',PATH_ROOT.'css/');
  8. define('PATH_DATA',PATH_ROOT.'data/');
  9. global $config;
  10. if(file_exists(PATH_CONFIG)){
  11. $config = objectToArray(json_decode(file_get_contents(PATH_CONFIG),true));
  12. }else{
  13. $config = Array();
  14. }
  15. $config = array_merge($config,objectToArray(json_decode(file_get_contents(PATH_DEFAULT_CONFIG),true)));
  16. function get($setting){
  17. global $config;
  18. if(isset($config[$setting])){
  19. return $config[$setting];
  20. }else{
  21. return false;
  22. }
  23. }
  24. function set($setting,$value){
  25. global $config;
  26. $config[$setting] = $value;
  27. file_put_contents(PAT_CONFIG,json_encode($config));
  28. return $value;
  29. }
  30. function objectToArray($d){
  31. if(is_object($d)){
  32. // Gets the properties of the given object
  33. // with get_object_vars function
  34. $d = get_object_vars($d);
  35. }
  36. if(is_array($d)){
  37. /*
  38. * Return array converted to object
  39. * Using __FUNCTION__ (Magic constant)
  40. * for recursive call
  41. */
  42. return array_map(__FUNCTION__, $d);
  43. }else{
  44. // Return array
  45. return $d;
  46. }
  47. }
  48. function arrayToObject($d){
  49. if(is_array($d)){
  50. /*
  51. * Return array converted to object
  52. * Using __FUNCTION__ (Magic constant)
  53. * for recursive call
  54. */
  55. return (object)array_map(__FUNCTION__, $d);
  56. }else{
  57. // Return object
  58. return $d;
  59. }
  60. }
  61. ?>