config.php 1.5 KB

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