3 class mw_env_out extends mw_env{
9 // ---------------------------------------------------------------------------------
13 function set_out($key, $value){
14 $this->out[$key] = $value;
23 return isset($this->out[$key]) ? $this->out[$key] : null;
26 // ---------------------------------------------------------------------------------
30 function out_pathes(){
32 if(($plugins = $this->plugins()) !== false){
33 foreach($plugins as $plugin_name => $plugin){
34 $out_dir = $this->path("mw_dir")."plugins/".$plugin_name."/out/";
38 && file_exists($out_dir)
41 if(($pathes = $this->_out_pathes($out_dir, $pathes)) === false) break;
44 if($pathes !== false){
45 $pathes = $this->_out_pathes($this->path("mw_dir")."out/", $pathes);
52 function _out_pathes($out_dir, $pathes = array()){
53 if($dh = opendir($out_dir)){
54 while(($file = readdir($dh)) !== false){
55 if(is_dir($out_dir.$file) && substr($file, 0 ,1) != ".") $pathes[] = $file;
63 // ---------------------------------------------------------------------------------
67 function out_file_exists($file, $PRIORITE = "DESC"){
68 $out_file = $this->_out_file($file, $PRIORITE);
69 return $out_file ? true : false;
72 function out_file($file, $PRIORITE = "DESC"){
73 $out_file = $this->_out_file($file, $PRIORITE);
74 return $out_file ? $this->path("mw_dir").$out_file : $file;
77 function out_url($file, $PRIORITE = "DESC"){
78 $out_file = $this->_out_file($file, $PRIORITE);
79 return $out_file ? $this->path("mw_path").$out_file : $file;
82 function _out_file($file, $PRIORITE = "DESC"){
84 if($PRIORITE == "ASC"){
85 $tmp_out_file = "out/".$this->config("out")."/".$file;
86 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
87 $out_file = $tmp_out_file;
90 $tmp_out_file = "out/".$this->config("default_out")."/".$file;
91 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
92 $out_file = $tmp_out_file;
96 if($out_file) return $out_file;
97 if(($plugins = $this->plugins($PRIORITE)) !== false){
98 foreach($plugins as $plugin_name => $plugin){
99 $tmp_out_file = "plugins/".$plugin_name."/out/".$this->config("out")."/".$file;
100 if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($this->path("mw_dir").$tmp_out_file)){
101 $out_file = $tmp_out_file;
105 $tmp_out_file = "plugins/".$plugin_name."/out/".$this->config("default_out")."/".$file;
106 if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($this->path("mw_dir").$tmp_out_file)){
107 $out_file = $tmp_out_file;
112 if($PRIORITE == "DESC" && !$out_file){
113 $tmp_out_file = "out/".$this->config("out")."/".$file;
114 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
115 $out_file = $tmp_out_file;
118 $tmp_out_file = "out/".$this->config("default_out")."/".$file;
119 if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
120 $out_file = $tmp_out_file;
128 // ---------------------------------------------------------------------------------
132 function set_out_config($out_config){
133 $this->out_config = $out_config;
134 return $this->out_config;
137 function get_out_config(){
138 return isset($this->out_config) ? $this->out_config : array();
141 function out_config($name){
142 if(isset($this->out_config)){
143 $CONFIG = $this->get_CONFIG();
144 return isset($CONFIG["out_".$name]) ? $CONFIG["out_".$name] : $this->out_config[$name]["default"];
149 // ---------------------------------------------------------------------------------
154 return $this->layout;
157 function render_layout($layout = null){
158 if(!isset($layout)) $layout = $this->init_layout();
159 if(($plugins = $this->plugins("ASC")) !== false){
160 foreach($plugins as $plugin_name => $plugin){
161 if($plugin["installed"] && $plugin["enabled"]){
163 $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("out")."/functions.php";
164 if(file_exists($functions_file)){
166 require $functions_file;
169 $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("default_out")."/functions.php";
170 if($plugin["installed"] && $plugin["enabled"] && file_exists($functions_file)){
171 require $functions_file;
177 $functions_file = $this->path("mw_dir")."out/".$this->config("out")."/functions.php";
178 if(file_exists($functions_file)){
180 require $functions_file;
183 $functions_file = $this->path("mw_dir")."out/".$this->config("default_out")."/functions.php";
184 if(file_exists($functions_file)){
185 require $functions_file;
189 if($this->out_file_exists($layout["page"])) require $this->out_file($layout["page"]);
191 elseif($layout["content"]){
192 if($this->out_file_exists($layout["content"])) require $this->out_file($layout["content"]);
197 function init_layout(){
198 $this->layout = array();
199 $this->_init_layout("index");
200 if(($mod = $this->etat("mod")) != "index") $this->_init_layout($mod);
201 return $this->get_layout();
204 function _init_layout($mod){
205 if(($plugins = $this->plugins("ASC")) !== false){
206 $layout_file = false;
207 $tmp_layout_file = $this->path("mw_dir")."out/".$this->config("out")."/layouts/".$mod.".xml";
208 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
210 $tmp_layout_file = $this->path("mw_dir")."out/".$this->config("default_out")."/layouts/".$mod.".xml";
211 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
213 if($layout_file) $this->load_layout($layout_file);
214 foreach($plugins as $plugin_name => $plugin){
215 if($plugin["installed"] && $plugin["enabled"]){
216 $layout_file = false;
217 $tmp_layout_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("out")."/layouts/".$mod.".xml";
218 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
220 $tmp_layout_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("default_out")."/layouts/".$mod.".xml";
221 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
223 if($layout_file) $this->load_layout($layout_file);
229 function load_layout($layout_file){
230 if(file_exists($layout_file)){
231 $xml_parser = new sxml();
232 $xml_parser->parse(file_get_contents($layout_file));
233 $layout = $xml_parser->data;
234 if(isset($layout["layout"][0]["subs"])){
235 foreach($layout["layout"][0]["subs"] as $mod => $mod_node){
236 if(!isset($this->layout[$mod])){
237 $this->layout[$mod] = array(
240 "controllers" => array()
243 if(isset($mod_node[0]["attrs"]["page"])) $this->layout[$mod]["page"] = $mod_node[0]["attrs"]["page"];
244 if(isset($mod_node[0]["attrs"]["content"])) $this->layout[$mod]["content"] = $mod_node[0]["attrs"]["content"];
245 if(isset($mod_node[0]["subs"])){
246 foreach($mod_node[0]["subs"] as $controller => $controller_node){
247 if(!isset($this->layout[$mod]["controllers"][$controller])){
248 $this->layout[$mod]["controllers"][$controller] = array(
254 if(isset($controller_node[0]["attrs"]["page"])) $this->layout[$mod]["controllers"][$controller]["page"] = $controller_node[0]["attrs"]["page"];
255 if(isset($controller_node[0]["attrs"]["content"])) $this->layout[$mod]["controllers"][$controller]["content"] = $controller_node[0]["attrs"]["content"];
256 if(isset($controller_node[0]["subs"])){
257 foreach($controller_node[0]["subs"] as $action => $action_node){
258 if(!isset($this->layout[$mod]["controllers"][$controller]["actions"][$action])){
259 $this->layout[$mod]["controllers"][$controller]["actions"][$action] = array(
264 if(isset($action_node[0]["attrs"]["page"])) $this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"] = $action_node[0]["attrs"]["page"];
265 if(isset($action_node[0]["attrs"]["content"])) $this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"] = $action_node[0]["attrs"]["content"];
276 function get_layout(){
277 $mod = $this->etat("mod");
278 $controller = $this->etat("controller");
279 $action = $this->etat("action");
281 if(isset($this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"])){
282 $content = $this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"];
285 if(isset($this->layout[$mod]["controllers"][$controller]["content"])){
286 $content = $this->layout[$mod]["controllers"][$controller]["content"];
289 if(isset($this->layout[$mod]["content"])){
290 $content = $this->layout[$mod]["content"];
293 if(isset($this->layout["index"]["content"])){
294 $content = $this->layout["index"]["content"];
300 if(isset($this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"])){
301 $page = $this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"];
304 if(isset($this->layout[$mod]["controllers"][$controller]["page"])){
305 $page = $this->layout[$mod]["controllers"][$controller]["page"];
308 if(isset($this->layout[$mod]["page"])){
309 $page = $this->layout[$mod]["page"];
312 if(isset($this->layout["index"]["page"])){
313 $page = $this->layout["index"]["page"];
320 "content" => $content