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("app")."mw_plugin.php";
32 if(!class_exists("mw_plugin")){
37 if(file_exists($this->path("plugins"))){
38 if($dh = opendir($this->path("plugins"))){
40 while($OK && ($plugin_name = readdir($dh)) !== false){
41 if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("plugins").$plugin_name)){
42 if(!isset($plugins[$plugin_name])){
43 if(($plugin = $this->plugin_data($plugin_name)) !== false){
45 if(!isset($plugin["installed"]) || !isset($plugin["enabled"])){
46 $plugin["installed"] = false;
47 $plugin["enabled"] = false;
48 $plugin["priorite"] = 0;
51 if(!$plugin["installed"] && $plugin["enabled"]){
52 $plugin["enabled"] = false;
55 if($MAJ) $OK = $this->set_plugin_data($plugin_name, $plugin);
57 if(($plugin["impl"] = $this->plugin_impl($plugin_name)) !== false){
58 $plugin["title"] = ($plugin_title = $this->plugin_call($plugin["impl"], "title")) ? $plugin_title : "";
59 $plugin["description"] = ($plugin_description = $this->plugin_call($plugin["impl"], "description")) ? $plugin_description : "";
60 $plugin["name"] = $plugin_name;
61 $plugins[$plugin_name] = $plugin;
68 if(!$OK) $plugins = false;
71 if($plugins !== false){
72 if(file_exists($this->plugins_data_dir()) && is_dir($this->plugins_data_dir())){
73 if($dh = opendir($this->plugins_data_dir())){
74 $plugins_data_files = array();
76 while($OK && ($plugin_name = readdir($dh)) !== false){
77 if(substr($plugin_name, 0 ,1) != "." && !is_dir($this->plugin_data_file($plugin_name))){
78 if(!$plugins[$plugin_name]) $this->del_plugin_data($plugin_name);
80 if(!$OK) $plugins = false;
87 else $plugins = false;
89 if($plugins !== false){
90 if($PRIORITE == "ASC") $this->plugins_asc = $this->ordonne_plugins($plugins, $PRIORITE);
91 elseif($PRIORITE == "DESC") $this->plugins_desc = $this->ordonne_plugins($plugins, $PRIORITE);
94 $this->plugins_asc = false;
95 $this->plugins_desc = false;
99 function ordonne_plugins($plugins, $PRIORITE = "ASC"){
100 $values = array_values($plugins);
101 $maximum = count($values);
103 $maximumTemporaire = 0;
104 for($i = 0; $i < $maximum - 1; $i++){
106 ($PRIORITE == "ASC" && $values[$i]["priorite"] > $values[$i + 1]["priorite"])
107 || ($PRIORITE == "DESC" && $values[$i]["priorite"] < $values[$i + 1]["priorite"])
110 $values[$i] = $values[$i + 1];
111 $values[$i + 1] = $tmp;
112 $maximumTemporaire = $i + 1;
115 $maximum = $maximumTemporaire;
118 foreach($values as $value) if($value["name"]) $res[$value["name"]] = $value;
122 function plugin_call($impl, $method){
123 if(method_exists($impl, $method)) return $impl->$method($this);
126 # ---------------------------------------------------------------------------------
130 function plugin_impl($plugin_name){
132 if(file_exists($this->path("plugins"))){
133 if(substr($plugin_name, 0 ,1) !== "." && is_dir($this->path("plugins").$plugin_name)){
134 if(file_exists($this->path("plugins").$plugin_name."/".$plugin_name.".php")){
135 require $this->path("plugins").$plugin_name."/".$plugin_name.".php";
136 if(class_exists($plugin_name)){
137 $plugin = new $plugin_name();
145 # ---------------------------------------------------------------------------------
149 function plugins_data_dir(){
150 return $this->path("content")."data/plugins/";
153 function plugin_data_file($plugin_name){
154 return $this->plugins_data_dir().$plugin_name;
157 function plugin_data($plugin_name){
158 $data_file = $this->plugin_data_file($plugin_name);
160 if(file_exists($data_file)){
161 if($content = file_get_contents($data_file)){
162 $data = unserialize($content);
168 function set_plugin_data($plugin_name, $data){
169 $data_file = $this->plugin_data_file($plugin_name);
170 $content = serialize($data);
172 if($fh = fopen($data_file, "w")){
173 if(fwrite($fh, $content) !== false){
181 function del_plugin_data($plugin_name){
182 $data_file = $this->plugin_data_file($plugin_name);
183 if(file_exists($data_file)) return @unlink($data_file);