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