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($dh = opendir($this->path("mw_dir")."plugins/")){
32 while($OK && ($plugin_name = readdir($dh)) !== false){
33 if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("mw_dir")."plugins/".$plugin_name)){
34 if(!isset($plugins[$plugin_name])){
35 if(($plugin = $this->plugin_data($plugin_name)) !== false){
37 if(!isset($plugin["installed"]) || !isset($plugin["enabled"])){
38 $plugin["installed"] = false;
39 $plugin["enabled"] = false;
40 $plugin["priorite"] = 0;
43 if(!$plugin["installed"] && $plugin["enabled"]){
44 $plugin["enabled"] = false;
47 if($MAJ) $OK = $this->set_plugin_data($plugin_name, $plugin);
49 if(($plugin["impl"] = $this->plugin_impl($plugin_name)) !== false){
50 $plugin["title"] = ($plugin_title = $this->plugin_call($plugin["impl"], "title")) ? $plugin_title : "";
51 $plugin["description"] = ($plugin_description = $this->plugin_call($plugin["impl"], "description")) ? $plugin_description : "";
52 $plugin["name"] = $plugin_name;
53 $plugins[$plugin_name] = $plugin;
60 if(!$OK) $plugins = false;
63 if($plugins !== false){
64 if(file_exists($this->plugins_data_dir()) && is_dir($this->plugins_data_dir())){
65 if($dh = opendir($this->plugins_data_dir())){
66 $plugins_data_files = array();
68 while($OK && ($plugin_name = readdir($dh)) !== false){
69 if(substr($plugin_name, 0 ,1) != "." && !is_dir($this->plugin_data_file($plugin_name))){
70 if(!isset($plugins[$plugin_name])) $this->del_plugin_data($plugin_name);
72 if(!$OK) $plugins = false;
79 else $plugins = false;
80 if($plugins !== false){
81 if($PRIORITE == "ASC") $this->plugins_asc = $this->ordonne_plugins($plugins, $PRIORITE);
82 elseif($PRIORITE == "DESC") $this->plugins_desc = $this->ordonne_plugins($plugins, $PRIORITE);
85 $this->plugins_asc = false;
86 $this->plugins_desc = false;
90 function ordonne_plugins($plugins, $PRIORITE = "ASC"){
91 $values = array_values($plugins);
92 $maximum = count($values);
94 $maximumTemporaire = 0;
95 for($i = 0; $i < $maximum - 1; $i++){
97 ($PRIORITE == "ASC" && $values[$i]["priorite"] > $values[$i + 1]["priorite"])
98 || ($PRIORITE == "DESC" && $values[$i]["priorite"] < $values[$i + 1]["priorite"])
101 $values[$i] = $values[$i + 1];
102 $values[$i + 1] = $tmp;
103 $maximumTemporaire = $i + 1;
106 $maximum = $maximumTemporaire;
109 foreach($values as $value) if($value["name"]) $res[$value["name"]] = $value;
113 function plugin_call($impl, $method){
114 if(method_exists($impl, $method)) return $impl->$method($this);
117 # ---------------------------------------------------------------------------------
121 function plugin_impl($plugin_name){
123 if(file_exists($this->path("mw_dir")."plugins")){
124 if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("mw_dir")."plugins/".$plugin_name)){
125 if(file_exists($this->path("mw_dir")."plugins/".$plugin_name."/".$plugin_name.".php")){
126 if(!class_exists($plugin_name)){
127 require_once $this->path("mw_dir")."plugins/".$plugin_name."/".$plugin_name.".php";
129 if(class_exists($plugin_name)){
130 $plugin = new $plugin_name();
138 # ---------------------------------------------------------------------------------
142 function plugins_data_dir(){
143 return $this->path("content")."data/plugins/";
146 function plugin_data_file($plugin_name){
147 return $this->plugins_data_dir().$plugin_name;
150 function plugin_data($plugin_name){
151 $data_file = $this->plugin_data_file($plugin_name);
153 if(file_exists($data_file)){
154 if($content = file_get_contents($data_file)){
155 $data = unserialize($content);
161 function set_plugin_data($plugin_name, $data){
162 $data_file = $this->plugin_data_file($plugin_name);
163 $content = serialize($data);
165 if($fh = fopen($data_file, "w")){
166 if(fwrite($fh, $content) !== false){
174 function del_plugin_data($plugin_name){
175 $data_file = $this->plugin_data_file($plugin_name);
176 if(file_exists($data_file)) return @unlink($data_file);
185 return "(sans titre)";
188 function description(){
192 function install($env){
196 function uninstall($env){
200 function enable($env){
204 function disable($env){