PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/site/onyx2/load.php

http://xe8tmw7c.googlecode.com/
PHP | 170 lines | 125 code | 42 blank | 3 comment | 26 complexity | 292f37cd5ebb4e46b8b126086dd9f182 MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. $chrono_start = microtime(TRUE);
  3. if(version_compare(PHP_VERSION, '5.0.0', '<')) trigger_error('Version de php non supportee',E_USER_ERROR);
  4. define('ONYX_VERSION','2.0');
  5. define('FILE',$_SERVER["SCRIPT_FILENAME"]);
  6. define('ONYX',dirname(__FILE__).'/');
  7. if(!is_readable(ONYX."ban.list")) trigger_error('Fichier de ban introuvable',E_USER_ERROR);
  8. if(in_array($_SERVER['REMOTE_ADDR'], file(ONYX."ban.list",FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES))) die('banni');
  9. require_once('require/parse.php');
  10. require_once('require/cache.php');
  11. require_once('require/str.php');
  12. require_once('require/env.php');
  13. # *** Chargement de la configuration ***
  14. $cached = Cache::read('_configuration_'.FILE);
  15. if($cached['check'] == md5_file(ONYX.'config/root.xml').md5_file(ONYX.'modules/modules.xml'))
  16. {
  17. $VAR = $cached['var'];
  18. $ENV = $cached['env'];
  19. define('ROOT', $cached['root']);
  20. foreach($cached['modules'] as $name)
  21. {
  22. //if(isset($all_modules[$name]))
  23. {
  24. $OPT = $cached['opt'][$name];
  25. include_once(ONYX.'modules/'.$name.'/main.php');
  26. }
  27. }
  28. define('CACHED',TRUE);
  29. }
  30. else
  31. {
  32. $xml = new DOMDocument();
  33. $xml->load(ONYX.'config/root.xml') or trigger_error('Erreur du fichier de configuration',E_USER_ERROR);
  34. $xml->normalizeDocument();
  35. //$xml->validate();
  36. if($root = $xml->documentElement->getAttribute('root'))
  37. {
  38. if(!$xml->documentElement->getAttribute('verif') || $root == substr(FILE,0,strlen($root)))
  39. {
  40. if (!$xml->documentElement->getAttribute('verif'))
  41. {
  42. $root = dirname($_SERVER["SCRIPT_FILENAME"])."/";
  43. }
  44. define('ROOT',$root);
  45. $search = substr(FILE,strlen($root));
  46. $paths = explode('/',$search);
  47. $paths2 = $paths;
  48. foreach($paths as $key => $path)
  49. {
  50. for($i = $key - 1; $i >= 0; $i--)
  51. {
  52. $paths2[$key] = $paths[$i] . '/' . $paths2[$key];
  53. }
  54. if($key != count($paths) - 1) $paths2[$key] .= '/';
  55. }
  56. foreach($xml->getElementsByTagName('config') as $value)
  57. {
  58. $config[$value->getAttribute('match')] = $value;
  59. }
  60. $VAR = $ENV = $modules = array();
  61. array_unshift($paths2,'*');
  62. foreach($paths2 as $path)
  63. {
  64. if($config[$path])
  65. {
  66. $VAR = array_merge($VAR,parse_config($config[$path]));
  67. $ENV = array_merge($ENV,parse_config($config[$path],'env','option'));
  68. foreach($config[$path]->getElementsByTagName('module') as $module)
  69. {
  70. $modules[$module->getAttribute('name')] = $module;
  71. }
  72. }
  73. }
  74. $xml_modules = new DOMDocument();
  75. $xml_modules->load(ONYX.'modules/modules.xml') or trigger_error('Erreur du fichier de modules',E_USER_ERROR);
  76. $xml_modules->normalizeDocument();
  77. foreach($xml_modules->getElementsByTagName('module') as $module)
  78. {
  79. if(!ctype_alnum($module->getAttribute('name'))) trigger_error('Le nom du module contient des caracteres illegaux',E_USER_ERROR);
  80. $all_modules[$module->getAttribute('name')] = $module;
  81. }
  82. $all_opt = $load_modules = array();
  83. foreach($modules as $name => $module)
  84. {
  85. if(isset($all_modules[$name]) && !in_array($name,$load_modules))
  86. {
  87. if($require = $all_modules[$name]->getAttribute('require'))
  88. if(!in_array($require,$load_modules))
  89. {
  90. trigger_error("Module '$name' requiert '$require'",E_USER_WARNING);
  91. continue;
  92. }
  93. $OPT = parse_config($module,'option');
  94. $OPT = array_merge(parse_config($all_modules[$name]->getElementsByTagName('default')->item(0),'option'),$OPT);
  95. include_once(ONYX.'modules/'.$name.'/main.php');
  96. $all_opt[$name] = $OPT;
  97. $load_modules[] = $name;
  98. }
  99. }
  100. if($xml->documentElement->getAttribute('cache'))
  101. Cache::set('_configuration_'.FILE,array('var' => $VAR,'env' => $ENV, 'root' => $root,'modules' => $load_modules, 'opt' => $all_opt, 'check' => md5_file(ONYX.'config/root.xml').md5_file(ONYX.'modules/modules.xml')));
  102. else Cache::del('_configuration_'.FILE);
  103. }
  104. else trigger_error('Fichier hors de la racine',E_USER_ERROR);
  105. }
  106. else trigger_error('Configuration erronnee',E_USER_ERROR);
  107. define('CACHED',FALSE);
  108. }
  109. error_reporting($ENV['error_level']);
  110. set_include_path(get_include_path() . PATH_SEPARATOR . ONYX.'include/');
  111. ignore_user_abort($ENV['ignore_user_abort']);
  112. if (!empty($ENV['locale']))
  113. setLocale(LC_TIME,$ENV['locale']);
  114. setLocale(LC_NUMERIC, 'en_EN');
  115. if($VAR['chrono'])
  116. {
  117. function view_chrono()
  118. {
  119. global $chrono_start,$VAR;
  120. echo str_replace('$',round(microtime(TRUE) - $chrono_start,4),$VAR['chrono']);
  121. }
  122. register_shutdown_function('view_chrono');
  123. }
  124. if($ENV['log_php']) ini_set('error_log',ONYX.'log/php.log');
  125. foreach($ENV['ini'] as $name => $value) ini_set($name,$value);
  126. foreach($ENV['header'] as $name => $value) header($name.': '.$value);
  127. unset($xml,$root,$search,$paths,$paths2,$path,$key,$i,$value,$config,$modules,$module,$load_modules,$xml_modules,$all_modules,$name,$require,$OPT,$all_opt,$dir,$file,$ENV,$cached);
  128. ?>