3 class mw_env_out extends mw_env{
12 // ---------------------------------------------------------------------------------
16 function set_out($key, $value){
17 $this->out[$key] = $value;
26 return isset($this->out[$key]) ? $this->out[$key] : null;
29 // ---------------------------------------------------------------------------------
33 function out_pathes(){
35 if(($plugins = $this->plugins()) !== false){
36 foreach($plugins as $plugin_name => $plugin){
37 $out_dir = $this->path("mw_dir")."plugins/".$plugin_name."/app/out/";
41 && file_exists($out_dir)
44 if(($pathes = $this->_out_pathes($out_dir, $pathes)) === false) break;
47 if($pathes !== false){
48 $pathes = $this->_out_pathes($this->path("mw_dir")."app/out/", $pathes);
55 function _out_pathes($out_dir, $pathes = array()){
56 if($dh = opendir($out_dir)){
57 while(($file = readdir($dh)) !== false){
58 if(is_dir($out_dir.$file) && substr($file, 0 ,1) != "." && !in_array($file, $pathes)) $pathes[] = $file;
66 // ---------------------------------------------------------------------------------
70 function out_file_exists($file, $PRIORITE = "DESC"){
71 $out_file = $this->_out_file($file, $PRIORITE);
72 return $out_file ? true : false;
75 function out_file($file, $PRIORITE = "DESC"){
76 $out_file = $this->_out_file($file, $PRIORITE);
77 return $out_file ? $this->path("mw_dir").$out_file : $file;
80 function out_url($file, $PRIORITE = "DESC"){
81 $out_file = $this->_out_file($file, $PRIORITE);
82 return $out_file ? $this->path("mw_path").$out_file : $file;
85 function _out_file($file, $PRIORITE = "DESC"){
87 if($PRIORITE == "ASC"){
88 $tmp_out_file = "app/out/".$this->config("out")."/".$file;
89 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
90 $out_file = $tmp_out_file;
93 $tmp_out_file = "app/out/".$this->config("default_out")."/".$file;
94 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
95 $out_file = $tmp_out_file;
99 if($out_file) return $out_file;
100 if(($plugins = $this->plugins($PRIORITE)) !== false){
101 foreach($plugins as $plugin_name => $plugin){
102 $tmp_out_file = "plugins/".$plugin_name."/app/out/".$this->config("out")."/".$file;
103 if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($this->path("mw_dir").$tmp_out_file)){
104 $out_file = $tmp_out_file;
108 $tmp_out_file = "plugins/".$plugin_name."/app/out/".$this->config("default_out")."/".$file;
109 if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($this->path("mw_dir").$tmp_out_file)){
110 $out_file = $tmp_out_file;
115 if($PRIORITE == "DESC" && !$out_file){
116 $tmp_out_file = "app/out/".$this->config("out")."/".$file;
117 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
118 $out_file = $tmp_out_file;
121 $tmp_out_file = "app/out/".$this->config("default_out")."/".$file;
122 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
123 $out_file = $tmp_out_file;
131 // ---------------------------------------------------------------------------------
136 if(!isset($this->js_files)) $this->js_files = array();
138 foreach($this->js_files as $url => $enabled){
139 if($enabled) $files[] = $url;
144 function add_js_file($url){
145 if(!isset($this->js_files)) $this->js_files = array();
146 $this->js_files[$url] = true;
149 function remove_js_file($url){
150 if(isset($this->js_files) && isset($this->js_files[$url])){
151 unset($this->js_files[$url]);
155 function css_files(){
156 if(!isset($this->css_files)) $this->css_files = array();
158 foreach($this->css_files as $url => $enabled){
159 if($enabled) $files[] = $url;
164 function add_css_file($url){
165 if(!isset($this->css_files)) $this->css_files = array();
166 $this->css_files[$url] = true;
169 function remove_css_file($url){
170 if(isset($this->css_files) && isset($this->css_files[$url])){
171 unset($this->css_files[$url]);
175 // ---------------------------------------------------------------------------------
179 function set_out_config($out_config){
180 $this->out_config = $out_config;
181 return $this->out_config;
184 function get_out_config(){
185 return isset($this->out_config) ? $this->out_config : array();
188 function out_config($name){
189 if(isset($this->out_config)){
190 $CONFIG = $this->get_CONFIG();
191 return isset($CONFIG["out_".$name]) ? $CONFIG["out_".$name] : $this->out_config[$name]["default"];
196 // ---------------------------------------------------------------------------------
201 return $this->layout;
204 function render_layout($layout = null){
205 if(!isset($layout)) $layout = $this->init_layout();
206 if(($plugins = $this->plugins("ASC")) !== false){
207 foreach($plugins as $plugin_name => $plugin){
208 if($plugin["installed"] && $plugin["enabled"]){
210 $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/out/".$this->config("out")."/functions.php";
211 if(file_exists($functions_file)){
213 require $functions_file;
216 $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/out/".$this->config("default_out")."/functions.php";
217 if($plugin["installed"] && $plugin["enabled"] && file_exists($functions_file)){
218 require $functions_file;
224 $functions_file = $this->path("mw_dir")."app/out/".$this->config("out")."/functions.php";
225 if(file_exists($functions_file)){
227 require $functions_file;
230 $functions_file = $this->path("mw_dir")."app/out/".$this->config("default_out")."/functions.php";
231 if(file_exists($functions_file)){
232 require $functions_file;
236 if($this->out_file_exists($layout["page"])) require $this->out_file($layout["page"]);
238 elseif($layout["content"]){
239 if($this->out_file_exists($layout["content"])) require $this->out_file($layout["content"]);
244 function init_layout(){
245 $this->layout = array();
246 $this->_init_layout("index");
247 if(($mod = $this->etat("mod")) != "index") $this->_init_layout($mod);
248 return $this->get_layout();
251 function _init_layout($mod){
252 if(($plugins = $this->plugins("ASC")) !== false){
253 $layout_file = false;
254 $tmp_layout_file = $this->path("mw_dir")."app/out/".$this->config("out")."/layouts/".$mod.".xml";
255 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
257 $tmp_layout_file = $this->path("mw_dir")."app/out/".$this->config("default_out")."/layouts/".$mod.".xml";
258 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
260 if($layout_file) $this->load_layout($layout_file);
261 foreach($plugins as $plugin_name => $plugin){
262 if($plugin["installed"] && $plugin["enabled"]){
263 $layout_file = false;
264 $tmp_layout_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/out/".$this->config("out")."/layouts/".$mod.".xml";
265 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
267 $tmp_layout_file = $this->path("mw_dir")."plugins/".$plugin_name."/app/out/".$this->config("default_out")."/layouts/".$mod.".xml";
268 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
270 if($layout_file) $this->load_layout($layout_file);
276 function load_layout($layout_file){
277 if(file_exists($layout_file)){
278 $xml_parser = new sxml();
279 $xml_parser->parse(file_get_contents($layout_file));
280 $layout = $xml_parser->data;
281 if(isset($layout["layout"][0]["subs"])){
282 foreach($layout["layout"][0]["subs"] as $mod => $mod_node){
283 if(!isset($this->layout[$mod])){
284 $this->layout[$mod] = array(
287 "controllers" => array()
290 if(isset($mod_node[0]["attrs"]["page"])) $this->layout[$mod]["page"] = $mod_node[0]["attrs"]["page"];
291 if(isset($mod_node[0]["attrs"]["content"])) $this->layout[$mod]["content"] = $mod_node[0]["attrs"]["content"];
292 if(isset($mod_node[0]["subs"])){
293 foreach($mod_node[0]["subs"] as $controller => $controller_node){
294 if(!isset($this->layout[$mod]["controllers"][$controller])){
295 $this->layout[$mod]["controllers"][$controller] = array(
301 if(isset($controller_node[0]["attrs"]["page"])) $this->layout[$mod]["controllers"][$controller]["page"] = $controller_node[0]["attrs"]["page"];
302 if(isset($controller_node[0]["attrs"]["content"])) $this->layout[$mod]["controllers"][$controller]["content"] = $controller_node[0]["attrs"]["content"];
303 if(isset($controller_node[0]["subs"])){
304 foreach($controller_node[0]["subs"] as $action => $action_node){
305 if(!isset($this->layout[$mod]["controllers"][$controller]["actions"][$action])){
306 $this->layout[$mod]["controllers"][$controller]["actions"][$action] = array(
311 if(isset($action_node[0]["attrs"]["page"])) $this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"] = $action_node[0]["attrs"]["page"];
312 if(isset($action_node[0]["attrs"]["content"])) $this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"] = $action_node[0]["attrs"]["content"];
323 function get_layout(){
324 $mod = $this->etat("mod");
325 $controller = $this->etat("controller");
326 $action = $this->etat("action");
328 if(isset($this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"])){
329 $content = $this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"];
332 if(isset($this->layout[$mod]["controllers"][$controller]["content"])){
333 $content = $this->layout[$mod]["controllers"][$controller]["content"];
336 if(isset($this->layout[$mod]["content"])){
337 $content = $this->layout[$mod]["content"];
340 if(isset($this->layout["index"]["content"])){
341 $content = $this->layout["index"]["content"];
347 if(isset($this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"])){
348 $page = $this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"];
351 if(isset($this->layout[$mod]["controllers"][$controller]["page"])){
352 $page = $this->layout[$mod]["controllers"][$controller]["page"];
355 if(isset($this->layout[$mod]["page"])){
356 $page = $this->layout[$mod]["page"];
359 if(isset($this->layout["index"]["page"])){
360 $page = $this->layout["index"]["page"];
367 "content" => $content