PageRenderTime 37ms CodeModel.GetById 1ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 1ms

/site/onyx2/load.php

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