reorganisation des dossiers
[mtweb] / mw / env / modules / mw_env_config.php
1 <?php
2
3   class mw_env_config extends mw_env{
4
5     var $xml_parser;
6     var $config_file;
7     var $PATHES;
8     var $PARAMS;
9     var $CONFIG;
10     var $bdd;
11
12     function load_config($bdd, $CONFIG){
13       if(true){
14         $this->bdd = $bdd;
15         $this->bdd["table_prefix"] = array();
16         $this->CONFIG = isset($CONFIG) ? $CONFIG : array();
17         $this->PARAMS = array();
18         $this->xml_parser = new sxml();
19         $app_config_file = $this->path("mw_dir")."app/config.xml";
20         if(file_exists($app_config_file)){
21           $this->_load_config($app_config_file, $bdd);
22         }
23         if(($plugins = $this->plugins("ASC")) !== false){
24           foreach($plugins as $plugin_name => $plugin){
25             $app_config_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/config.xml";
26             if(file_exists($app_config_file) && $plugin["installed"] && $plugin["enabled"]){
27               $this->_load_config($app_config_file, $bdd);
28             }
29           }
30           $this->init_additional_get_params();
31         }
32         else $this->erreur("impossible de lire les fichiers de configuration pour les plugins", true);
33       }
34       else $this->erreur("impossible de trouver le fichier de configuration pour l'installation", true);
35     }
36
37     function _load_config($app_config_file, $bdd){
38       $this->xml_parser->parse(file_get_contents($app_config_file));
39       $app_config = $this->xml_parser->data["config"][0];
40       if(isset($app_config["subs"]["params"])){
41         foreach($app_config["subs"]["params"][0]["subs"] as $param_key => $param_elt){
42           $this->PARAMS[$param_key] = $param_elt[0]["data"];
43         }
44       }
45       if(isset($app_config["subs"]["config"])){
46         foreach($app_config["subs"]["config"][0]["subs"] as $config_key => $config_elt){
47           $this->CONFIG[$config_key] = $config_elt[0]["data"];
48         }
49       }
50       if(isset($app_config["subs"]["bdd"][0]["subs"]["table_prefix_code"])){
51         $this->add_table_prefix(
52           array(
53             $app_config["subs"]["bdd"][0]["subs"]["table_prefix_code"][0]["data"] => $bdd["table_prefix"]
54           )
55         );
56       }
57     }
58
59     function get_config_file(){
60       return $this->config_file;
61     }
62
63     function set_config_file($config_file){
64       $this->config_file = $config_file;
65     }
66
67     function get_PATHES(){
68       return $this->PATHES;
69     }
70
71     function path($name){
72       return isset($this->PATHES[$name]) ? $this->PATHES[$name] : "";
73     }
74
75     function set_PATHES($PATHES){
76       foreach($PATHES as $path_name => $path_value){
77         if($path_value && substr($path_value, -1) != "/") $PATHES[$path_name] .= "/";
78       }
79       $this->PATHES = $PATHES;
80     }
81
82     function get_PARAMS(){
83       return $this->PARAMS;
84     }
85
86     function param($name){
87       return isset($this->PARAMS[$name]) ? $this->PARAMS[$name] : "";
88     }
89
90     function get_CONFIG(){
91       return $this->CONFIG;
92     }
93
94     function config($name){
95       return isset($this->CONFIG[$name]) ? $this->CONFIG[$name] : null;
96     }
97
98     function set_config($config){
99       if(is_array($config)){
100         foreach($config as $key => $value) $this->CONFIG[$key] = $value;
101         return true;
102       }
103       return false;
104     }
105
106     function get_bdd(){
107       return $this->bdd;
108     }
109
110     function bdd($name){
111       return isset($this->bdd[$name]) ? $this->bdd[$name] : null;
112     }
113
114     function set_bdd($key, $value){
115       $this->bdd[$key] = $value;
116     }
117
118     function add_table_prefix($table_prefix){
119       if(is_array($table_prefix)){
120         foreach($table_prefix as $prefix_code => $prefix) $this->bdd["table_prefix"][$prefix_code] = $prefix;
121         return true;
122       }
123       return false;
124     }
125
126   }
127
128 ?>