3 class mw_env_out extends mw_env{
9 function set_out($key, $value){
10 $this->out[$key] = $value; return $value;
18 return $this->out[$key];
21 function out_pathes(){
23 if($dh = opendir($this->path("out"))){
24 while(($file = readdir($dh)) !== false){
25 if(is_dir($this->path("out").$file) && substr($file, 0 ,1) != ".") $pathes[] = $file;
33 function out_file_exists($file, $PRIORITE = "DESC"){
34 $out_file = $this->_out_file($file, $PRIORITE);
35 return $out_file ? true : false;
38 function out_file($file, $PRIORITE = "DESC"){
39 $out_file = $this->_out_file($file, $PRIORITE);
40 return $out_file ? $out_file : $file;
43 function _out_file($file, $PRIORITE = "DESC"){
45 if($PRIORITE == "ASC"){
46 $tmp_out_file = $this->path("out").$this->config("out").$file;
47 if($file && file_exists($tmp_out_file)){
48 $out_file = $tmp_out_file;
51 $tmp_out_file = $this->path("out").$this->path("dist_out").$file;
52 if($file && file_exists($tmp_out_file)){
53 $out_file = $tmp_out_file;
57 if($out_file) return $out_file;
58 if(($plugins = $this->plugins($PRIORITE)) !== false){
59 foreach($plugins as $plugin_name => $plugin){
60 $tmp_out_file = $this->path("plugins").$plugin_name."/out/".$this->config("out").$file;
61 if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($tmp_out_file)){
62 $out_file = $tmp_out_file;
66 $tmp_out_file = $this->path("plugins").$plugin_name."/out/".$this->path("dist_out").$file;
67 if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($tmp_out_file)){
68 $out_file = $tmp_out_file;
73 if($PRIORITE == "DESC" && !$out_file){
74 $tmp_out_file = $this->path("out").$this->config("out").$file;
75 if($file && file_exists($tmp_out_file)){
76 $out_file = $tmp_out_file;
79 $tmp_out_file = $this->path("out").$this->path("dist_out").$file;
80 if($file && file_exists($tmp_out_file)){
81 $out_file = $tmp_out_file;
89 # ---------------------------------------------------------------------------------
93 function set_out_config($out_config){
94 $this->out_config = $out_config;
95 return $this->out_config;
98 function get_out_config(){
99 return isset($this->out_config) ? $this->out_config : array();
102 function out_config($name){
103 if(isset($this->out_config)){
104 $CONFIG = $this->get_CONFIG();
105 return isset($CONFIG["out_".$name]) ? $CONFIG["out_".$name] : $this->out_config[$name]["default"];
110 # ---------------------------------------------------------------------------------
115 return $this->layout;
118 function render_layout($layout = null){
119 if(!isset($layout)) $layout = $this->init_layout();
120 if(($plugins = $this->plugins("ASC")) !== false){
121 foreach($plugins as $plugin_name => $plugin){
122 if($plugin["installed"] && $plugin["enabled"]){
124 $functions_file = $this->path("plugins").$plugin_name."/out/".$this->config("out")."functions.php";
125 if(file_exists($functions_file)){
127 require $functions_file;
130 $functions_file = $this->path("plugins").$plugin_name."/out/".$this->path("dist_out")."functions.php";
131 if($plugin["installed"] && $plugin["enabled"] && file_exists($functions_file)){
132 require $functions_file;
138 $functions_file = $this->path("out").$this->config("out")."functions.php";
139 if(file_exists($functions_file)){
141 require $functions_file;
144 $functions_file = $this->path("out").$this->path("dist_out")."functions.php";
145 if(file_exists($functions_file)){
146 require $functions_file;
150 if($this->out_file_exists($layout["page"])) require $this->out_file($layout["page"]);
152 elseif($layout["content"]){
153 if($this->out_file_exists($layout["content"])) require $this->out_file($layout["content"]);
158 function init_layout(){
159 $this->layout = array();
160 $this->_init_layout("index");
161 if(($mod = $this->etat("mod")) != "index") $this->_init_layout($mod);
162 return $this->get_layout();
165 function _init_layout($mod){
166 if(($plugins = $this->plugins("ASC")) !== false){
167 $layout_file = false;
168 $tmp_layout_file = $this->path("out").$this->config("out")."layouts/".$mod.".xml";
169 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
171 $tmp_layout_file = $this->path("out").$this->path("dist_out")."layouts/".$mod.".xml";
172 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
174 if($layout_file) $this->load_layout($layout_file);
175 foreach($plugins as $plugin_name => $plugin){
176 if($plugin["installed"] && $plugin["enabled"]){
177 $layout_file = false;
178 $tmp_layout_file = $this->path("plugins").$plugin_name."/out/".$this->config("out")."layouts/".$mod.".xml";
179 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
181 $tmp_layout_file = $this->path("plugins").$plugin_name."/out/".$this->path("dist_out")."layouts/".$mod.".xml";
182 if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
184 if($layout_file) $this->load_layout($layout_file);
190 function load_layout($layout_file){
191 if(file_exists($layout_file)){
192 $xml_parser = new sxml();
193 $xml_parser->parse(file_get_contents($layout_file));
194 $layout = $xml_parser->data;
195 if(isset($layout["layout"][0]["subs"])){
196 foreach($layout["layout"][0]["subs"] as $mod => $mod_node){
197 if(!isset($this->layout[$mod])){
198 $this->layout[$mod] = array(
201 "controllers" => array()
204 if(isset($mod_node[0]["attrs"]["page"])) $this->layout[$mod]["page"] = $mod_node[0]["attrs"]["page"];
205 if(isset($mod_node[0]["attrs"]["content"])) $this->layout[$mod]["content"] = $mod_node[0]["attrs"]["content"];
206 if(isset($mod_node[0]["subs"])){
207 foreach($mod_node[0]["subs"] as $controller => $controller_node){
208 if(!isset($this->layout[$mod]["controllers"][$controller])){
209 $this->layout[$mod]["controllers"][$controller] = array(
215 if(isset($controller_node[0]["attrs"]["page"])) $this->layout[$mod]["controllers"][$controller]["page"] = $controller_node[0]["attrs"]["page"];
216 if(isset($controller_node[0]["attrs"]["content"])) $this->layout[$mod]["controllers"][$controller]["content"] = $controller_node[0]["attrs"]["content"];
217 if(isset($controller_node[0]["subs"])){
218 foreach($controller_node[0]["subs"] as $action => $action_node){
219 if(!isset($this->layout[$mod]["controllers"][$controller]["actions"][$action])){
220 $this->layout[$mod]["controllers"][$controller]["actions"][$action] = array(
225 if(isset($action_node[0]["attrs"]["page"])) $this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"] = $action_node[0]["attrs"]["page"];
226 if(isset($action_node[0]["attrs"]["content"])) $this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"] = $action_node[0]["attrs"]["content"];
237 function get_layout(){
238 $mod = $this->etat("mod");
239 $controller = $this->etat("controller");
240 $action = $this->etat("action");
242 if(isset($this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"])){
243 $content = $this->layout[$mod]["controllers"][$controller]["actions"][$action]["content"];
246 if(isset($this->layout[$mod]["controllers"][$controller]["content"])){
247 $content = $this->layout[$mod]["controllers"][$controller]["content"];
250 if(isset($this->layout[$mod]["content"])){
251 $content = $this->layout[$mod]["content"];
254 if(isset($this->layout["index"]["content"])){
255 $content = $this->layout["index"]["content"];
261 if(isset($this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"])){
262 $page = $this->layout[$mod]["controllers"][$controller]["actions"][$action]["page"];
265 if(isset($this->layout[$mod]["controllers"][$controller]["page"])){
266 $page = $this->layout[$mod]["controllers"][$controller]["page"];
269 if(isset($this->layout[$mod]["page"])){
270 $page = $this->layout[$mod]["page"];
273 if(isset($this->layout["index"]["page"])){
274 $page = $this->layout["index"]["page"];
281 "content" => $content