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) return true;
42 if($this->DO_SETUP) $this->setup();
43 return $this->get_error();
46 function init_pathes(){
47 if(($n = strpos($_SERVER["REQUEST_URI"], "?")) !== false){
48 $_SERVER["REQUEST_URI"] = substr($_SERVER["REQUEST_URI"], 0, $n);
50 $web_path = explode("/", preg_replace('#/+#','/',$_SERVER["REQUEST_URI"]));
51 $this->pathes["web"] = "";
52 for($i = 0; $i < count($web_path) - 1; $i++) $this->pathes["web"] .= $web_path[$i]."/";
55 || !file_exists($this->path_file)
57 $this->error("le fichier des chemins est introuvable");
60 require $this->path_file;
65 $this->error("variable PATHES non defini");
68 foreach($PATHES as $path_name => $path_value){
69 $this->pathes[$path_name] = $path_value;
70 $this->pathes[$path_name] .= $path_value && substr($path_value, -1) != "/" ? "/" : "";
73 !isset($this->pathes["mw_dir"])
74 || !isset($this->pathes["mw_path"])
75 || !isset($this->pathes["content"])
77 $this->error("variable PATHES incomplete");
81 !file_exists($this->pathes["content"])
82 || !is_dir($this->pathes["content"])
84 $this->error("dossier content introuvable");
87 if(!is_writable($this->pathes["content"])){
88 $this->error("Php ne peut pas ecrire dans le dossier content");
94 function init_config(){
95 if(file_exists($config_file = $this->pathes["content"]."config/config.php")){
96 $this->config_file = $config_file;
97 require_once $this->config_file;
102 foreach($CONFIG as $config_name => $config_value){
103 $this->config[$config_name] = $config_value;
110 foreach($bdd as $bdd_key => $bdd_value){
111 $this->bdd[$bdd_key] = $bdd_value;
116 if(!$this->DO_SETUP){
117 $this->error("fichier config.php manquant");
126 !($sxml_class_file = (file_exists($this->pathes["mw_dir"]."libs/sxml.php") ? $this->pathes["mw_dir"]."libs/sxml.php" : ""))
127 || !($empty_class_file = (file_exists($this->pathes["mw_dir"]."libs/empty_class.php") ? $this->pathes["mw_dir"]."libs/empty_class.php" : ""))
128 || !($env_class_file = (file_exists($this->pathes["mw_dir"]."env/mw_env.php") ? $this->pathes["mw_dir"]."env/mw_env.php" : ""))
130 $this->error("des fichiers sont introuvables. impossible d'initialiser l'environnement");
133 if(!class_exists("sxml")) require_once $sxml_class_file;
134 if(!class_exists("empty_class")) require_once $empty_class_file;
135 if(!class_exists("mw_env")) require_once $env_class_file;
137 !class_exists("sxml")
138 || !class_exists("empty_class")
139 || !class_exists("mw_env")
141 $this->error("des classes sont introuvables. impossible d'initialiser l'environnement");
144 $env = new mw_env(true);
145 $this->set_env($env);
146 $env->load_modules($this->pathes["mw_dir"], "env/modules/");
147 $env->set_config_file($this->config_file);
148 $env->set_PATHES($this->pathes);
149 $env->init_plugins();
150 $env->load_config($this->bdd, $this->config);
155 function run($etat = "", $params = array(), $valid_role = true){
157 if(!is_callable(array($env, "run"))) return false;
164 if($env->etat_is_valid()){
165 $template = $env->get_template();
166 $layout = $env->init_layout();
167 $template->render_layout($layout);
173 $etat = isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "install";
174 $env->run($etat, array(), false);
179 function error($content){
180 $this->error = $content;
183 function get_error(){
184 return isset($this->error) && $this->error ? $this->error : false;