X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=mw%2Fmw_app.php;h=38d094d86f1c1f1e3c550b52734a740a03ec6f29;hb=af318ad7150a54780f3912d7fbf805c7382b2785;hp=990d7a7c91206ab0b791baedb59979ad234aa4a2;hpb=a4819cb78b71363db14f8c568a9a2552ee8f58da;p=mtweb diff --git a/mw/mw_app.php b/mw/mw_app.php index 990d7a7..38d094d 100644 --- a/mw/mw_app.php +++ b/mw/mw_app.php @@ -9,10 +9,10 @@ var $config; var $bdd; var $error; - var $DO_SETUP; + var $DO_INSTALL; - function mw_app($path_file, $DO_SETUP = false){ - $this->DO_SETUP = $DO_SETUP; + function mw_app($path_file, $DO_INSTALL = false){ + $this->DO_INSTALL = $DO_INSTALL; $this->path_file = $path_file; $this->pathes = array(); $this->config_file = ""; @@ -39,30 +39,32 @@ if(!$this->init_config()) return $this->get_error(); if(!$this->init_env()) return $this->get_error(); if(!$this->config_file){ - if($this->DO_SETUP){ - $this->setup(); + if($this->DO_INSTALL){ + $this->install(); exit; } return $this->get_error(); } $env = $this->env(); - if(!$env->version("mtweb")){ - $this->error("impossible de lire la version du code"); - return $this->get_error(); - } - $data = $env->data(); - if($data->version("mtweb") != $env->version("mtweb")){ + if(($res = $env->data_upgrade_required()) === true){ $this->upgrade(); exit; } + else{ + if($res !== false){ + $this->error($res); + return $this->get_error(); + } + } return true; } function init_pathes(){ - if(($n = strpos($_SERVER["REQUEST_URI"], "?")) !== false){ - $_SERVER["REQUEST_URI"] = substr($_SERVER["REQUEST_URI"], 0, $n); + $REQUEST_URI = $_SERVER["REQUEST_URI"]; + if(($n = strpos($REQUEST_URI, "?")) !== false){ + $REQUEST_URI = substr($REQUEST_URI, 0, $n); } - $web_path = explode("/", preg_replace('#/+#','/',$_SERVER["REQUEST_URI"])); + $web_path = explode("/", preg_replace('#/+#','/',$REQUEST_URI)); $this->pathes["web"] = ""; for($i = 0; $i < count($web_path) - 1; $i++) $this->pathes["web"] .= $web_path[$i]."/"; if( @@ -99,7 +101,11 @@ $this->error("dossier content introuvable"); return false; } - if(!is_writable($this->pathes["content"])){ + if( + !is_writable($this->pathes["content"]) + || !is_writable($this->pathes["content"]."config") + || !is_writable($this->pathes["content"]."data") + ){ $this->error("Php ne peut pas ecrire dans le dossier content"); return false; } @@ -128,7 +134,7 @@ } } else{ - if(!$this->DO_SETUP){ + if(!$this->DO_INSTALL){ $this->error("fichier config.php manquant"); return false; } @@ -165,6 +171,11 @@ $env->load_versions(); $env->load_config($this->bdd, $this->config); $env->init(); + $env->loaded_plugins(); + if(($res = $env->init_data_upgrades()) !== true){ + $this->error("impossible de lire les upgrades. ".$res); + return false; + } return true; } @@ -175,24 +186,45 @@ return true; } - function display(){ + function run_mod($mod_name, $valid_role = true){ $env = $this->env(); - if($env->etat_is_valid()){ - $template = $env->get_template(); - $layout = $env->init_layout(); - $template->render_layout($layout); + $etat = false; + if(isset($_GET[$env->param("e")])){ + $etat = $env->valid_etat($_GET[$env->param("e")]); + if(!$etat || ($etat["mod"] != $mod_name)){ + $etat = false; + } } + if(!$etat){ + $etat = $env->valid_etat($mod_name); + } + if(!$etat) return false; + $env->run($etat, array(), $valid_role); + return true; } - function setup(){ - $env = $this->env(); - $etat = isset($_GET[$env->param("e")]) ? $_GET[$env->param("e")] : "install"; - $env->run($etat, array(), false); - $this->display(); + function install(){ + if($this->run_mod("install", false)){ + $this->display(); + } } function upgrade(){ - debug("la base de données doit être mise à jour"); + $env = $this->env(); + $data = $env->data(); + $data->load_session(); + if($this->run_mod("upgrade", false)){ + $this->display(); + } + } + + function display(){ + $env = $this->env(); + if($env->etat_is_valid()){ + $template = $env->get_template(); + $layout = $env->init_layout(); + $template->render_layout($layout); + } } function error($content){