14 function mw_app($path_file, $DO_SETUP = false){
15 $this->DO_SETUP = $DO_SETUP;
16 $this->path_file = $path_file;
17 $this->pathes = array();
18 $this->config_file = "";
19 $this->config = array();
24 function set_env(&$env){
32 function param($name){
33 if(!isset($this->env)) return false;
34 return $this->env->param($name);
38 if(!$this->init_pathes()) return $this->get_error();
39 if(!$this->init_config()) return $this->get_error();
40 if(!$this->init_env()) return $this->get_error();
41 if(!$this->config_file){
46 return $this->get_error();
49 if(!$env->version("mtweb")){
50 $this->error("impossible de lire la version du code");
51 return $this->get_error();
54 if($data->version("mtweb") != $env->version("mtweb")){
61 function init_pathes(){
62 if(($n = strpos($_SERVER["REQUEST_URI"], "?")) !== false){
63 $_SERVER["REQUEST_URI"] = substr($_SERVER["REQUEST_URI"], 0, $n);
65 $web_path = explode("/", preg_replace('#/+#','/',$_SERVER["REQUEST_URI"]));
66 $this->pathes["web"] = "";
67 for($i = 0; $i < count($web_path) - 1; $i++) $this->pathes["web"] .= $web_path[$i]."/";
70 || !file_exists($this->path_file)
72 $this->error("le fichier des chemins est introuvable");
75 require $this->path_file;
80 $this->error("variable PATHES non defini");
83 foreach($PATHES as $path_name => $path_value){
84 $this->pathes[$path_name] = $path_value;
85 $this->pathes[$path_name] .= $path_value && substr($path_value, -1) != "/" ? "/" : "";
88 !isset($this->pathes["mw_dir"])
89 || !isset($this->pathes["mw_path"])
90 || !isset($this->pathes["content"])
92 $this->error("variable PATHES incomplete");
96 !file_exists($this->pathes["content"])
97 || !is_dir($this->pathes["content"])
99 $this->error("dossier content introuvable");
102 if(!is_writable($this->pathes["content"])){
103 $this->error("Php ne peut pas ecrire dans le dossier content");
109 function init_config(){
110 if(file_exists($config_file = $this->pathes["content"]."config/config.php")){
111 $this->config_file = $config_file;
112 require_once $this->config_file;
117 foreach($CONFIG as $config_name => $config_value){
118 $this->config[$config_name] = $config_value;
125 foreach($bdd as $bdd_key => $bdd_value){
126 $this->bdd[$bdd_key] = $bdd_value;
131 if(!$this->DO_SETUP){
132 $this->error("fichier config.php manquant");
141 !($sxml_class_file = (file_exists($this->pathes["mw_dir"]."libs/sxml.php") ? $this->pathes["mw_dir"]."libs/sxml.php" : ""))
142 || !($empty_class_file = (file_exists($this->pathes["mw_dir"]."libs/empty_class.php") ? $this->pathes["mw_dir"]."libs/empty_class.php" : ""))
143 || !($env_class_file = (file_exists($this->pathes["mw_dir"]."env/mw_env.php") ? $this->pathes["mw_dir"]."env/mw_env.php" : ""))
145 $this->error("des fichiers sont introuvables. impossible d'initialiser l'environnement");
148 if(!class_exists("sxml")) require_once $sxml_class_file;
149 if(!class_exists("empty_class")) require_once $empty_class_file;
150 if(!class_exists("mw_env")) require_once $env_class_file;
152 !class_exists("sxml")
153 || !class_exists("empty_class")
154 || !class_exists("mw_env")
156 $this->error("des classes sont introuvables. impossible d'initialiser l'environnement");
159 $env = new mw_env(true);
160 $this->set_env($env);
161 $env->load_modules($this->pathes["mw_dir"], "env/modules/");
162 $env->set_config_file($this->config_file);
163 $env->set_PATHES($this->pathes);
164 $env->init_plugins();
165 $env->load_versions();
166 $env->load_config($this->bdd, $this->config);
171 function run($etat = "", $params = array(), $valid_role = true){
173 if(!is_callable(array($env, "run"))) return false;
180 if($env->etat_is_valid()){
181 $template = $env->get_template();
182 $layout = $env->init_layout();
183 $template->render_layout($layout);
189 $etat = isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "install";
190 $env->run($etat, array(), false);
195 debug("la base de données doit être mise à jour");
198 function error($content){
199 $this->error = $content;
202 function get_error(){
203 return isset($this->error) && $this->error ? $this->error : false;