3 class mw_env_plugins extends mw_env{
8 function plugins($PRIORITE = "ASC"){
9 $this->init_plugins($PRIORITE);
10 if($PRIORITE == "ASC") return $this->plugins_asc;
11 if($PRIORITE == "DESC") return $this->plugins_desc;
15 # ---------------------------------------------------------------------------------
19 function init_plugins($PRIORITE = "ASC"){
20 if(isset($this->plugins_asc) || isset($this->plugins_desc)){
21 if($PRIORITE == "ASC"){
22 if(!isset($this->plugins_asc)) $this->plugins_asc = $this->ordonne_plugins($this->plugins_desc, $PRIORITE);
24 elseif($PRIORITE == "DESC"){
25 if(!isset($this->plugins_desc)) $this->plugins_desc = $this->ordonne_plugins($this->plugins_asc, $PRIORITE);
30 if(!class_exists("mw_plugin")){
31 require $this->path("mw_dir")."plugins/mw_plugin.php";
32 if(!class_exists("mw_plugin")){
37 if($dh = opendir($this->path("mw_dir")."plugins/")){
39 while($OK && ($plugin_name = readdir($dh)) !== false){
40 if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("mw_dir")."plugins/".$plugin_name)){
41 if(!isset($plugins[$plugin_name])){
42 if(($plugin = $this->plugin_data($plugin_name)) !== false){
44 if(!isset($plugin["installed"]) || !isset($plugin["enabled"])){
45 $plugin["installed"] = false;
46 $plugin["enabled"] = false;
47 $plugin["priorite"] = 0;
50 if(!$plugin["installed"] && $plugin["enabled"]){
51 $plugin["enabled"] = false;
54 if($MAJ) $OK = $this->set_plugin_data($plugin_name, $plugin);
56 if(($plugin["impl"] = $this->plugin_impl($plugin_name)) !== false){
57 $plugin["title"] = ($plugin_title = $this->plugin_call($plugin["impl"], "title")) ? $plugin_title : "";
58 $plugin["description"] = ($plugin_description = $this->plugin_call($plugin["impl"], "description")) ? $plugin_description : "";
59 $plugin["name"] = $plugin_name;
60 $plugins[$plugin_name] = $plugin;
67 if(!$OK) $plugins = false;
70 if($plugins !== false){
71 if(file_exists($this->plugins_data_dir()) && is_dir($this->plugins_data_dir())){
72 if($dh = opendir($this->plugins_data_dir())){
73 $plugins_data_files = array();
75 while($OK && ($plugin_name = readdir($dh)) !== false){
76 if(substr($plugin_name, 0 ,1) != "." && !is_dir($this->plugin_data_file($plugin_name))){
77 if(!isset($plugins[$plugin_name])) $this->del_plugin_data($plugin_name);
79 if(!$OK) $plugins = false;
86 else $plugins = false;
87 if($plugins !== false){
88 if($PRIORITE == "ASC") $this->plugins_asc = $this->ordonne_plugins($plugins, $PRIORITE);
89 elseif($PRIORITE == "DESC") $this->plugins_desc = $this->ordonne_plugins($plugins, $PRIORITE);
92 $this->plugins_asc = false;
93 $this->plugins_desc = false;
97 function ordonne_plugins($plugins, $PRIORITE = "ASC"){
98 $values = array_values($plugins);
99 $maximum = count($values);
101 $maximumTemporaire = 0;
102 for($i = 0; $i < $maximum - 1; $i++){
104 ($PRIORITE == "ASC" && $values[$i]["priorite"] > $values[$i + 1]["priorite"])
105 || ($PRIORITE == "DESC" && $values[$i]["priorite"] < $values[$i + 1]["priorite"])
108 $values[$i] = $values[$i + 1];
109 $values[$i + 1] = $tmp;
110 $maximumTemporaire = $i + 1;
113 $maximum = $maximumTemporaire;
116 foreach($values as $value) if($value["name"]) $res[$value["name"]] = $value;
120 function plugin_call($impl, $method){
121 if(method_exists($impl, $method)) return $impl->$method($this);
124 # ---------------------------------------------------------------------------------
128 function plugin_impl($plugin_name){
130 if(file_exists($this->path("mw_dir")."plugins")){
131 if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("mw_dir")."plugins/".$plugin_name)){
132 if(file_exists($this->path("mw_dir")."plugins/".$plugin_name."/".$plugin_name.".php")){
133 require $this->path("mw_dir")."plugins/".$plugin_name."/".$plugin_name.".php";
134 if(class_exists($plugin_name)){
135 $plugin = new $plugin_name();
143 # ---------------------------------------------------------------------------------
147 function plugins_data_dir(){
148 return $this->path("content")."data/plugins/";
151 function plugin_data_file($plugin_name){
152 return $this->plugins_data_dir().$plugin_name;
155 function plugin_data($plugin_name){
156 $data_file = $this->plugin_data_file($plugin_name);
158 if(file_exists($data_file)){
159 if($content = file_get_contents($data_file)){
160 $data = unserialize($content);
166 function set_plugin_data($plugin_name, $data){
167 $data_file = $this->plugin_data_file($plugin_name);
168 $content = serialize($data);
170 if($fh = fopen($data_file, "w")){
171 if(fwrite($fh, $content) !== false){
179 function del_plugin_data($plugin_name){
180 $data_file = $this->plugin_data_file($plugin_name);
181 if(file_exists($data_file)) return @unlink($data_file);