X-Git-Url: http://git.dj3c1t.com/index.cgi?a=blobdiff_plain;f=mw%2Fenv%2Fmodules%2Fmw_env_config.php;fp=mw%2Fenv%2Fmodules%2Fmw_env_config.php;h=64da6d33eac1e51e3607f7868a333867efbae7e2;hb=36ed114046cbe3d72a3589230e9f306a54fcc79d;hp=0000000000000000000000000000000000000000;hpb=281c96e95451269f2614684b8de5be25862c8374;p=mtweb diff --git a/mw/env/modules/mw_env_config.php b/mw/env/modules/mw_env_config.php new file mode 100644 index 0000000..64da6d3 --- /dev/null +++ b/mw/env/modules/mw_env_config.php @@ -0,0 +1,128 @@ +bdd = $bdd; + $this->bdd["table_prefix"] = array(); + $this->CONFIG = isset($CONFIG) ? $CONFIG : array(); + $this->PARAMS = array(); + $this->xml_parser = new sxml(); + $app_config_file = $this->path("mw_dir")."app/config.xml"; + if(file_exists($app_config_file)){ + $this->_load_config($app_config_file, $bdd); + } + if(($plugins = $this->plugins("ASC")) !== false){ + foreach($plugins as $plugin_name => $plugin){ + $app_config_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/config.xml"; + if(file_exists($app_config_file) && $plugin["installed"] && $plugin["enabled"]){ + $this->_load_config($app_config_file, $bdd); + } + } + $this->init_additional_get_params(); + } + else $this->erreur("impossible de lire les fichiers de configuration pour les plugins", true); + } + else $this->erreur("impossible de trouver le fichier de configuration pour l'installation", true); + } + + function _load_config($app_config_file, $bdd){ + $this->xml_parser->parse(file_get_contents($app_config_file)); + $app_config = $this->xml_parser->data["config"][0]; + if(isset($app_config["subs"]["params"])){ + foreach($app_config["subs"]["params"][0]["subs"] as $param_key => $param_elt){ + $this->PARAMS[$param_key] = $param_elt[0]["data"]; + } + } + if(isset($app_config["subs"]["config"])){ + foreach($app_config["subs"]["config"][0]["subs"] as $config_key => $config_elt){ + $this->CONFIG[$config_key] = $config_elt[0]["data"]; + } + } + if(isset($app_config["subs"]["bdd"][0]["subs"]["table_prefix_code"])){ + $this->add_table_prefix( + array( + $app_config["subs"]["bdd"][0]["subs"]["table_prefix_code"][0]["data"] => $bdd["table_prefix"] + ) + ); + } + } + + function get_config_file(){ + return $this->config_file; + } + + function set_config_file($config_file){ + $this->config_file = $config_file; + } + + function get_PATHES(){ + return $this->PATHES; + } + + function path($name){ + return isset($this->PATHES[$name]) ? $this->PATHES[$name] : ""; + } + + function set_PATHES($PATHES){ + foreach($PATHES as $path_name => $path_value){ + if($path_value && substr($path_value, -1) != "/") $PATHES[$path_name] .= "/"; + } + $this->PATHES = $PATHES; + } + + function get_PARAMS(){ + return $this->PARAMS; + } + + function param($name){ + return isset($this->PARAMS[$name]) ? $this->PARAMS[$name] : ""; + } + + function get_CONFIG(){ + return $this->CONFIG; + } + + function config($name){ + return isset($this->CONFIG[$name]) ? $this->CONFIG[$name] : null; + } + + function set_config($config){ + if(is_array($config)){ + foreach($config as $key => $value) $this->CONFIG[$key] = $value; + return true; + } + return false; + } + + function get_bdd(){ + return $this->bdd; + } + + function bdd($name){ + return isset($this->bdd[$name]) ? $this->bdd[$name] : null; + } + + function set_bdd($key, $value){ + $this->bdd[$key] = $value; + } + + function add_table_prefix($table_prefix){ + if(is_array($table_prefix)){ + foreach($table_prefix as $prefix_code => $prefix) $this->bdd["table_prefix"][$prefix_code] = $prefix; + return true; + } + return false; + } + + } + +?> \ No newline at end of file