variable js mw_path_url dans head.php
[mtweb] / mw / env / modules / mw_env_plugins.php
index 1df1834..b9fe042 100644 (file)
@@ -16,8 +16,8 @@
     #                                                                              init
     #
 
-    function init_plugins($PRIORITE = "ASC"){
-      if(isset($this->plugins_asc) || isset($this->plugins_desc)){
+    function init_plugins($PRIORITE = "ASC", $RELOAD = false){
+      if(!$RELOAD && (isset($this->plugins_asc) || isset($this->plugins_desc))){
         if($PRIORITE == "ASC"){
           if(!isset($this->plugins_asc)) $this->plugins_asc = $this->ordonne_plugins($this->plugins_desc, $PRIORITE);
         }
         return;
       }
       $plugins = array();
-      if(!class_exists("mw_plugin")){
-        require $this->path("mw_dir")."plugins/mw_plugin.php";
-        if(!class_exists("mw_plugin")){
-          $plugins = false;
-          return;
-        }
-      }
       if($dh = opendir($this->path("mw_dir")."plugins/")){
         $OK = true;
         while($OK && ($plugin_name = readdir($dh)) !== false){
       if(method_exists($impl, $method)) return $impl->$method($this);
     }
 
+    function loaded_plugins(){
+      if($plugins = $this->plugins()){
+        foreach($plugins as $plugin_name => $plugin){
+          $plugin["impl"]->loaded($this);
+        }
+      }
+    }
+
     # ---------------------------------------------------------------------------------
     #                                                                              impl
     #
       if(file_exists($this->path("mw_dir")."plugins")){
         if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("mw_dir")."plugins/".$plugin_name)){
           if(file_exists($this->path("mw_dir")."plugins/".$plugin_name."/".$plugin_name.".php")){
-            require $this->path("mw_dir")."plugins/".$plugin_name."/".$plugin_name.".php";
+            if(!class_exists($plugin_name)){
+              require_once $this->path("mw_dir")."plugins/".$plugin_name."/".$plugin_name.".php";
+            }
             if(class_exists($plugin_name)){
               $plugin = new $plugin_name();
             }
     }
 
     function set_plugin_data($plugin_name, $data){
+      if(!is_dir($this->plugins_data_dir())) @mkdir($this->plugins_data_dir());
+      if(!is_dir($this->plugins_data_dir())) return false;
       $data_file = $this->plugin_data_file($plugin_name);
       $content = serialize($data);
       $OK = false;
 
   }
 
+  class mw_plugin{
+
+    function title(){
+      return "(sans titre)";
+    }
+
+    function description(){
+      return "";
+    }
+
+    function loaded($env){
+    }
+
+    function install($env){
+      return true;
+    }
+
+    function uninstall($env){
+      return true;
+    }
+
+    function enable($env){
+      return true;
+    }
+
+    function disable($env){
+      return true;
+    }
+
+    function init($env){
+      return true;
+    }
+
+  }
+
 ?>
\ No newline at end of file