reorganisation des dossiers
[mtweb] / mw / env / modules / mw_env_out.php
similarity index 68%
rename from web/app/env/modules/mw_env_out.php
rename to mw/env/modules/mw_env_out.php
index f4ae9d9..12ab2ed 100644 (file)
@@ -6,8 +6,13 @@
     var $out_config;
     var $layout;
 
+    // ---------------------------------------------------------------------------------
+    //                                                                          out vars
+    //
+
     function set_out($key, $value){
-      $this->out[$key] = $value; return $value;
+      $this->out[$key] = $value;
+      return $value;
     }
 
     function get_out(){
     }
 
     function out($key){
-      return $this->out[$key];
+      return isset($this->out[$key]) ? $this->out[$key] : null;
     }
 
+    // ---------------------------------------------------------------------------------
+    //                                                                         templates
+    //
+
     function out_pathes(){
       $pathes = array();
-      if($dh = opendir($this->path("out"))){
+      if(($plugins = $this->plugins()) !== false){
+        foreach($plugins as $plugin_name => $plugin){
+          $out_dir = $this->path("mw_dir")."plugins/".$plugin_name."/out/";
+          if(
+               $plugin["installed"]
+            && $plugin["enabled"]
+            && file_exists($out_dir)
+            && is_dir($out_dir)
+          ){
+            if(($pathes = $this->_out_pathes($out_dir, $pathes)) === false) break;
+          }
+        }
+        if($pathes !== false){
+          $pathes = $this->_out_pathes($this->path("mw_dir")."out/", $pathes);
+        }
+      }
+      else $pathes = false;
+      return $pathes;
+    }
+
+    function _out_pathes($out_dir, $pathes = array()){
+      if($dh = opendir($out_dir)){
         while(($file = readdir($dh)) !== false){
-          if(is_dir($this->path("out").$file) && substr($file, 0 ,1) != ".") $pathes[] = $file;
+          if(is_dir($out_dir.$file) && substr($file, 0 ,1) != ".") $pathes[] = $file;
         }
         closedir($dh);
       }
       return $pathes;
     }
 
+    // ---------------------------------------------------------------------------------
+    //                                                                         out files
+    //
+
     function out_file_exists($file, $PRIORITE = "DESC"){
       $out_file = $this->_out_file($file, $PRIORITE);
       return $out_file ? true : false;
 
     function out_file($file, $PRIORITE = "DESC"){
       $out_file = $this->_out_file($file, $PRIORITE);
-      return $out_file ? $out_file : $file;
+      return $out_file ? $this->path("mw_dir").$out_file : $file;
+    }
+
+    function out_url($file, $PRIORITE = "DESC"){
+      $out_file = $this->_out_file($file, $PRIORITE);
+      return $out_file ? $this->path("mw_path").$out_file : $file;
     }
 
     function _out_file($file, $PRIORITE = "DESC"){
       $out_file = false;
       if($PRIORITE == "ASC"){
-        $tmp_out_file = $this->path("out").$this->config("out").$file;
-        if($file && file_exists($tmp_out_file)){
+        $tmp_out_file = "out/".$this->config("out")."/".$file;
+        if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
           $out_file = $tmp_out_file;
         }
         if(!$out_file){
-          $tmp_out_file = $this->path("out").$this->path("dist_out").$file;
-          if($file && file_exists($tmp_out_file)){
+          $tmp_out_file = "out/".$this->config("default_out")."/".$file;
+          if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
             $out_file = $tmp_out_file;
           }
         }
       if($out_file) return $out_file;
       if(($plugins = $this->plugins($PRIORITE)) !== false){
         foreach($plugins as $plugin_name => $plugin){
-          $tmp_out_file = $this->path("plugins").$plugin_name."/out/".$this->config("out").$file;
-          if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($tmp_out_file)){
+          $tmp_out_file = "plugins/".$plugin_name."/out/".$this->config("out")."/".$file;
+          if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($this->path("mw_dir").$tmp_out_file)){
             $out_file = $tmp_out_file;
             break;
           }
           if(!$out_file){
-            $tmp_out_file = $this->path("plugins").$plugin_name."/out/".$this->path("dist_out").$file;
-            if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($tmp_out_file)){
+            $tmp_out_file = "plugins/".$plugin_name."/out/".$this->config("default_out")."/".$file;
+            if($file && $plugin["installed"] && $plugin["enabled"] && file_exists($this->path("mw_dir").$tmp_out_file)){
               $out_file = $tmp_out_file;
               break;
             }
           }
         }
         if($PRIORITE == "DESC" && !$out_file){
-          $tmp_out_file = $this->path("out").$this->config("out").$file;
-          if($file && file_exists($tmp_out_file)){
+          $tmp_out_file = "out/".$this->config("out")."/".$file;
+          if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
             $out_file = $tmp_out_file;
           }
           if(!$out_file){
-            $tmp_out_file = $this->path("out").$this->path("dist_out").$file;
-            if($file && file_exists($tmp_out_file)){
+            $tmp_out_file = "out/".$this->config("default_out")."/".$file;
+            if($file && file_exists($this->path("mw_dir").$tmp_out_file)){
               $out_file = $tmp_out_file;
             }
           }
       return $out_file;
     }
 
-    # ---------------------------------------------------------------------------------
-    #                                                                        out config
-    #
+    // ---------------------------------------------------------------------------------
+    //                                                                        out config
+    //
 
     function set_out_config($out_config){
       $this->out_config = $out_config;
       return null;
     }
 
-    # ---------------------------------------------------------------------------------
-    #                                                                           layouts
-    #
+    // ---------------------------------------------------------------------------------
+    //                                                                           layouts
+    //
 
     function layout(){
       return $this->layout;
         foreach($plugins as $plugin_name => $plugin){
           if($plugin["installed"] && $plugin["enabled"]){
             $FOUND = false;
-            $functions_file = $this->path("plugins").$plugin_name."/out/".$this->config("out")."functions.php";
+            $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("out")."/functions.php";
             if(file_exists($functions_file)){
               $FOUND = true;
               require $functions_file;
             }
             if(!$FOUND){
-              $functions_file = $this->path("plugins").$plugin_name."/out/".$this->path("dist_out")."functions.php";
+              $functions_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("default_out")."/functions.php";
               if($plugin["installed"] && $plugin["enabled"] && file_exists($functions_file)){
                 require $functions_file;
               }
           }
         }
         $FOUND = false;
-        $functions_file = $this->path("out").$this->config("out")."functions.php";
+        $functions_file = $this->path("mw_dir")."out/".$this->config("out")."/functions.php";
         if(file_exists($functions_file)){
           $FOUND = true;
           require $functions_file;
         }
         if(!$FOUND){
-          $functions_file = $this->path("out").$this->path("dist_out")."functions.php";
+          $functions_file = $this->path("mw_dir")."out/".$this->config("default_out")."/functions.php";
           if(file_exists($functions_file)){
             require $functions_file;
           }
     function _init_layout($mod){
       if(($plugins = $this->plugins("ASC")) !== false){
         $layout_file = false;
-        $tmp_layout_file = $this->path("out").$this->config("out")."layouts/".$mod.".xml";
+        $tmp_layout_file = $this->path("mw_dir")."out/".$this->config("out")."/layouts/".$mod.".xml";
         if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
         if(!$layout_file){
-          $tmp_layout_file = $this->path("out").$this->path("dist_out")."layouts/".$mod.".xml";
+          $tmp_layout_file = $this->path("mw_dir")."out/".$this->config("default_out")."/layouts/".$mod.".xml";
           if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
         }
         if($layout_file) $this->load_layout($layout_file);
         foreach($plugins as $plugin_name => $plugin){
           if($plugin["installed"] && $plugin["enabled"]){
             $layout_file = false;
-            $tmp_layout_file = $this->path("plugins").$plugin_name."/out/".$this->config("out")."layouts/".$mod.".xml";
+            $tmp_layout_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("out")."/layouts/".$mod.".xml";
             if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
             if(!$layout_file){
-              $tmp_layout_file = $this->path("plugins").$plugin_name."/out/".$this->path("dist_out")."layouts/".$mod.".xml";
+              $tmp_layout_file = $this->path("mw_dir")."plugins/".$plugin_name."/out/".$this->config("default_out")."/layouts/".$mod.".xml";
               if(file_exists($tmp_layout_file)) $layout_file = $tmp_layout_file;
             }
             if($layout_file) $this->load_layout($layout_file);