e9b23163911d6de021e5ca9f36c8d1d98cce6684
[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     var $actions;
12
13     function load_config($bdd, $CONFIG){
14       if(true){
15         $this->bdd = $bdd;
16         $this->bdd["table_prefix"] = array();
17         $this->CONFIG = isset($CONFIG) ? $CONFIG : array();
18         $this->PARAMS = array();
19         $this->xml_parser = new sxml();
20         $app_config_file = $this->path("mw_dir")."app/config.xml";
21         if(file_exists($app_config_file)){
22           $this->_load_config($app_config_file, $bdd);
23         }
24         if(($plugins = $this->plugins("ASC")) !== false){
25           foreach($plugins as $plugin_name => $plugin){
26             $app_config_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/config.xml";
27             if(file_exists($app_config_file) && $plugin["installed"] && $plugin["enabled"]){
28               $this->_load_config($app_config_file, $bdd);
29             }
30           }
31           $this->init_additional_get_params();
32         }
33         else $this->erreur("impossible de lire les fichiers de configuration pour les plugins", true);
34       }
35       else $this->erreur("impossible de trouver le fichier de configuration pour l'installation", true);
36     }
37
38     function _load_config($app_config_file, $bdd){
39       $this->xml_parser->parse(file_get_contents($app_config_file));
40       $app_config = $this->xml_parser->data["config"][0];
41       if(isset($app_config["subs"]["params"])){
42         foreach($app_config["subs"]["params"][0]["subs"] as $param_key => $param_elt){
43           $this->PARAMS[$param_key] = $param_elt[0]["data"];
44         }
45       }
46       if(isset($app_config["subs"]["config"])){
47         foreach($app_config["subs"]["config"][0]["subs"] as $config_key => $config_elt){
48           $this->CONFIG[$config_key] = $config_elt[0]["data"];
49         }
50       }
51       if(isset($app_config["subs"]["bdd"][0]["subs"]["table_prefix_code"])){
52         $this->add_table_prefix(
53           array(
54             $app_config["subs"]["bdd"][0]["subs"]["table_prefix_code"][0]["data"] => isset($bdd["table_prefix"]) ? $bdd["table_prefix"] : ""
55           )
56         );
57       }
58       if(isset($app_config["subs"]["actions"][0]["subs"]["module"])){
59         foreach($app_config["subs"]["actions"][0]["subs"]["module"] as $module_elt){
60           $module_name = $module_elt["attrs"]["name"];
61           if(!isset($this->actions[$module_name])) $this->actions[$module_name] = array(
62             "controleurs" => array(),
63             "module_allowed" => false,
64             "is_public" => false
65           );
66           if(isset($module_elt["subs"]["controleur"])){
67             foreach($module_elt["subs"]["controleur"] as $controleur_elt){
68               $controleur_name = $controleur_elt["attrs"]["name"];
69               if(!isset($this->actions[$module_name]["controleurs"][$controleur_name])) $this->actions[$module_name]["controleurs"][$controleur_name] = array(
70                 "als" => array(),
71                 "controleur_allowed" => false,
72                 "is_public" => false
73               );
74               if(isset($controleur_elt["subs"]["al"])){
75                 $al_index = 0;
76                 foreach($controleur_elt["subs"]["al"] as $al_elt){
77                   $action_title = $al_elt["attrs"]["title"];
78                   if(isset($al_elt["subs"]["action"])){
79                     foreach($al_elt["subs"]["action"] as $action_elt){
80                       if(!isset($this->actions[$module_name]["controleurs"][$controleur_name]["als"][$al_index])){
81                         $this->actions[$module_name]["controleurs"][$controleur_name]["als"][$al_index] = array(
82                           "title" => $action_title,
83                           "action_allowed" => false,
84                           "is_public" => false,
85                           "actions" => array()
86                         );
87                       }
88                       $this->actions[$module_name]["controleurs"][$controleur_name]["als"][$al_index]["actions"][] = $action_elt["attrs"]["name"];
89                     }
90                   }
91                   $al_index++;
92                 }
93               }
94             }
95           }
96         }
97       }
98     }
99
100     function get_config_file(){
101       return $this->config_file;
102     }
103
104     function set_config_file($config_file){
105       $this->config_file = $config_file;
106     }
107
108     function get_PATHES(){
109       return $this->PATHES;
110     }
111
112     function path($name){
113       return isset($this->PATHES[$name]) ? $this->PATHES[$name] : "";
114     }
115
116     function set_PATHES($PATHES){
117       foreach($PATHES as $path_name => $path_value){
118         if($path_value && substr($path_value, -1) != "/") $PATHES[$path_name] .= "/";
119       }
120       $this->PATHES = $PATHES;
121     }
122
123     function get_PARAMS(){
124       return $this->PARAMS;
125     }
126
127     function param($name){
128       return isset($this->PARAMS[$name]) ? $this->PARAMS[$name] : "";
129     }
130
131     function get_CONFIG(){
132       return $this->CONFIG;
133     }
134
135     function config($name){
136       return isset($this->CONFIG[$name]) ? $this->CONFIG[$name] : null;
137     }
138
139     function set_config($config){
140       if(is_array($config)){
141         foreach($config as $key => $value) $this->CONFIG[$key] = $value;
142         return true;
143       }
144       return false;
145     }
146
147     function get_bdd(){
148       return $this->bdd;
149     }
150
151     function bdd($name){
152       return isset($this->bdd[$name]) ? $this->bdd[$name] : null;
153     }
154
155     function set_bdd($key, $value){
156       $this->bdd[$key] = $value;
157     }
158
159     function add_table_prefix($table_prefix){
160       if(is_array($table_prefix)){
161         foreach($table_prefix as $prefix_code => $prefix) $this->bdd["table_prefix"][$prefix_code] = $prefix;
162         return true;
163       }
164       return false;
165     }
166
167     function get_actions(){
168       return isset($this->actions) ? $this->actions : array();
169     }
170
171   }
172
173 ?>