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