X-Git-Url: http://git.dj3c1t.com/?a=blobdiff_plain;f=web%2Fapp%2Fenv%2Fmodules%2Fmw_env_run.php;h=69360c2bf9f8d838a09594d717c672ea140409f8;hb=7cf7609a7e236347374c1b21777a9698bcd1726c;hp=ba47626d5a48d08148d44debbeabbcde638e7f27;hpb=19b8f3b9263210d9154e7556446e903f84175519;p=mtweb diff --git a/web/app/env/modules/mw_env_run.php b/web/app/env/modules/mw_env_run.php index ba47626..69360c2 100644 --- a/web/app/env/modules/mw_env_run.php +++ b/web/app/env/modules/mw_env_run.php @@ -1,18 +1,18 @@ data(); + function user(){ + $data = $this->data(); return $data->get_session_user(); } - function set_etat($etat, $valid_status = true) - { if(($this->etat = $this->valid_etat($etat)) !== false) - { if(!$valid_status || $this->status_ok($this->etat, false)) - { return $this->etat; + function set_etat($etat, $valid_status = true){ + if(($this->etat = $this->valid_etat($etat)) !== false){ + if(!$valid_status || $this->status_ok($this->etat, false)){ + return $this->etat; } else $this->erreur("Vous n'avez pas le statut requis pour effectuer cette action"); } @@ -20,86 +20,89 @@ return false; } - function valid_etat($etat) - { $_etat = array(); + function valid_etat($etat){ + $_etat = array(); $_etat["mod"] = ""; $_etat["controller"] = ""; $_etat["action"] = ""; - if(is_array($etat)) - { $_etat["mod"] = isset($etat["mod"]) ? $etat["mod"] : ""; + if(is_array($etat)){ + $_etat["mod"] = isset($etat["mod"]) ? $etat["mod"] : ""; $_etat["controller"] = isset($etat["controller"]) ? $etat["controller"] : ""; $_etat["action"] = isset($etat["action"]) ? $etat["action"] : ""; } - else - { $etat = explode("/", $etat); - foreach($etat as $etat_item) - { if($etat_item) - { if(!$_etat["mod"]) $_etat["mod"] = $etat_item; - else - { if(!$_etat["controller"]) $_etat["controller"] = $etat_item; - else - { if(!$_etat["action"]) $_etat["action"] = $etat_item; + else{ + $etat = explode("/", $etat); + foreach($etat as $etat_item){ + if($etat_item){ + if(!$_etat["mod"]) $_etat["mod"] = $etat_item; + else{ + if(!$_etat["controller"]) $_etat["controller"] = $etat_item; + else{ + if(!$_etat["action"]) $_etat["action"] = $etat_item; break; } } } } } - if(!$_etat["mod"]) - { $_etat["mod"] = "index"; + if(!$_etat["mod"]){ + $_etat["mod"] = "index"; $_etat["controller"] = "index"; $_etat["action"] = "index"; } - else - { if(!$_etat["controller"]) - { $_etat["controller"] = "index"; + else{ + if(!$_etat["controller"]){ + $_etat["controller"] = "index"; $_etat["action"] = "index"; } - else - { if(!$_etat["action"]) $_etat["action"] = "index"; + else{ + if(!$_etat["action"]) $_etat["action"] = "index"; } } - if - ( is_array($_etat) + if( + is_array($_etat) && count($_etat) == 3 && isset($_etat["mod"]) && preg_match("/^[a-zA-Z0-9_]+$/", $_etat["mod"]) && isset($_etat["controller"]) && preg_match("/^[a-zA-Z0-9_]+$/", $_etat["controller"]) && isset($_etat["action"]) && preg_match("/^[a-zA-Z0-9_]+$/", $_etat["action"]) - ) return $_etat; + ){ + return $_etat; + } return false; } - function etat_is_valid() - { return $this->valid_etat($this->etat); + function etat_is_valid(){ + return $this->valid_etat($this->etat); } - function status_ok($etat, $CHECK_FORMAT = true) - { $OK = $this->config("default_allow"); + function status_ok($etat, $CHECK_FORMAT = true){ + $OK = $this->config("default_allow"); $data = $this->data(); if($CHECK_FORMAT) $etat = $this->valid_etat($etat); - if($etat !== false) - { if(($user_status = $data->get_user_status()) !== false) - { if - ( ( $action_status = $data->get_action_status - ( $etat["mod"], + if($etat !== false){ + if(($user_status = $data->get_user_status()) !== false){ + if( + ( + $action_status = $data->get_action_status( + $etat["mod"], $etat["controller"], $etat["action"] ) ) !== false - ) - { $action = $etat["mod"]."/".$etat["controller"]."/".$etat["action"]; - if(isset($action_status[$action])) - { $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]); + ){ + $action = $etat["mod"]."/".$etat["controller"]."/".$etat["action"]; + if(isset($action_status[$action])){ + $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]); } - else - { $action = $etat["mod"]."/".$etat["controller"]; - if(isset($action_status[$action])) - { $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]); + else{ + $action = $etat["mod"]."/".$etat["controller"]; + if(isset($action_status[$action])){ + $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]); } - else - { $action = $etat["mod"]; - if(isset($action_status[$action])) - { $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]); + else{ + $action = $etat["mod"]; + if(isset($action_status[$action])){ + $OK = $action_status[$action][0] || (isset($action_status[$action][$user_status]) && $action_status[$action][$user_status]); } } } @@ -112,28 +115,28 @@ return $OK; } - function run($etat, $valid_status = true, $params = array(), $method = "GET") - { if($this->set_etat($etat, $valid_status)) - { $controller_file = "mods/".$this->etat("mod")."/".$this->etat("controller").".php"; - if($this->app_file_exists($controller_file = "mods/".$this->etat("mod")."/".$this->etat("controller").".php", "DESC")) - { if(!class_exists("mw_mod")) require $this->app_file("mods/mw_mod.php"); - if(!class_exists($controller_class = "mw_".$this->etat("mod")."_".$this->etat("controller"))) - { require $this->app_file($controller_file, "DESC"); + function run($etat, $valid_status = true, $params = array(), $method = "GET"){ + if($this->set_etat($etat, $valid_status)){ + $controller_file = "mods/".$this->etat("mod")."/".$this->etat("controller").".php"; + if($this->app_file_exists($controller_file = "mods/".$this->etat("mod")."/".$this->etat("controller").".php", "DESC")){ + if(!class_exists("mw_mod")) require $this->app_file("mods/mw_mod.php"); + if(!class_exists($controller_class = "mw_".$this->etat("mod")."_".$this->etat("controller"))){ + require $this->app_file($controller_file, "DESC"); } - if(class_exists($controller_class)) - { $controller = new $controller_class(); + if(class_exists($controller_class)){ + $controller = new $controller_class(); $action_method = $this->etat("action"); - if(method_exists($controller, $action_method)) - { foreach($params as $key => $value) - { switch(strtolower($method)) - { case "get": $_GET[$this->param($key)] = $value; break; + if(method_exists($controller, $action_method)){ + foreach($params as $key => $value){ + switch(strtolower($method)){ + case "get": $_GET[$this->param($key)] = $value; break; case "post": $_POST[$key] = $value; break; default: break; } } - if(($controller_validate = $controller->validate($this)) === true) - { if(($controller_prepare_inputs = $controller->prepare_inputs($this)) === true) - { $controller->$action_method($this); + if(($controller_validate = $controller->validate($this)) === true){ + if(($controller_prepare_inputs = $controller->prepare_inputs($this)) === true){ + $controller->$action_method($this); } else $this->erreur($controller_prepare_inputs); } @@ -148,21 +151,23 @@ else $this->erreur("Impossible d'effectuer cette action"); } - function etat($name) { return $this->etat[$name]; } + function etat($name){ + return $this->etat[$name]; + } - function check_stop() - { return $this->etat("mod") == "reponses"; + function check_stop(){ + return $this->etat("mod") == "reponses"; } - function get_mod($mod_name) - { if($etat = $this->valid_etat($mod_name)) - { if($this->app_file_exists($controller_file = "mods/".$etat["mod"]."/".$etat["controller"].".php")) - { if(!class_exists("mw_mod")) require $this->app_file("mods/mw_mod.php"); - if(!class_exists($controller_class = "mw_".$etat["mod"]."_".$etat["controller"])) - { require $this->app_file($controller_file); + function get_mod($mod_name){ + if($etat = $this->valid_etat($mod_name)){ + if($this->app_file_exists($controller_file = "mods/".$etat["mod"]."/".$etat["controller"].".php")){ + if(!class_exists("mw_mod")) require $this->app_file("mods/mw_mod.php"); + if(!class_exists($controller_class = "mw_".$etat["mod"]."_".$etat["controller"])){ + require $this->app_file($controller_file); } - if(class_exists($controller_class)) - { return new $controller_class(); + if(class_exists($controller_class)){ + return new $controller_class(); } } }