1 | <?php |
---|
2 | /***************************************************************************/ |
---|
3 | class set_plugins { |
---|
4 | //============================================================================= |
---|
5 | function set_plugins_admin_menu($menu) { |
---|
6 | array_push( |
---|
7 | $menu, |
---|
8 | array( |
---|
9 | 'NAME' => 'Set_plugins', |
---|
10 | 'URL' => get_admin_plugin_menu_link(dirname(__FILE__)).'/admin.php' |
---|
11 | ) |
---|
12 | ); |
---|
13 | return $menu; |
---|
14 | } |
---|
15 | //============================================================================ |
---|
16 | function begin_admin() { |
---|
17 | global $erreur_message,$liste_des_plugins,$liste_active_plugins,$page; |
---|
18 | //========= Liste des plugins actifs ================= |
---|
19 | |
---|
20 | |
---|
21 | if (!isset($page['body_id'])) return; |
---|
22 | if($page['body_id']!='theAdminPage' ) return ; |
---|
23 | if($page['page']=='plugins_list' || $page['page']=='plugins'){ |
---|
24 | |
---|
25 | |
---|
26 | |
---|
27 | $plugins = new plugins(); |
---|
28 | $plugins->sort_fs_plugins('name'); |
---|
29 | $liste_des_plugins = array(); |
---|
30 | foreach ($plugins->fs_plugins as $plugin_id => $fs_plugin){ |
---|
31 | if(isset( $plugins->db_plugins_by_id[$plugin_id])){ |
---|
32 | $State_id=$plugins->db_plugins_by_id[$plugin_id]['state'] ; |
---|
33 | if($State_id=="active" && $plugin_id!="set_plugins") |
---|
34 | array_push($liste_des_plugins,$plugin_id); |
---|
35 | } |
---|
36 | } |
---|
37 | |
---|
38 | if (isset($_GET['liste_des_plugins'])){ |
---|
39 | array_push($liste_des_plugins,$_GET); |
---|
40 | echo json_encode($liste_des_plugins); |
---|
41 | exit; |
---|
42 | } |
---|
43 | $liste_active_plugins=$liste_des_plugins; |
---|
44 | } |
---|
45 | } |
---|
46 | //============================================================================ |
---|
47 | function set_plugins_add() { |
---|
48 | global $user, $template, $val,$page,$conf,$erreur_message,$infos_message; |
---|
49 | global $liste_des_plugins,$liste_active_plugins; |
---|
50 | if (!isset($page['body_id'])) return; |
---|
51 | |
---|
52 | switch($page['body_id']){ |
---|
53 | case 'theAdminPage': |
---|
54 | switch($page['page']){ |
---|
55 | case 'plugins_list': |
---|
56 | if(!isset($template)) return ; |
---|
57 | set_plugins::Affiche_set_plugins(); |
---|
58 | break; |
---|
59 | case 'plugins': |
---|
60 | if (!isset($page['tab'])) return; |
---|
61 | if ($page['tab']!="installed") return ; |
---|
62 | set_plugins::Affiche_set_plugins(); |
---|
63 | break; |
---|
64 | } |
---|
65 | } |
---|
66 | } |
---|
67 | //============================================================================ |
---|
68 | function messages_admin(){ |
---|
69 | global $template,$page, $template, $pwg_loaded_plugins,$infos_message,$erreur_message,$infos_warning; |
---|
70 | |
---|
71 | if ( (isset($_GET['page']) AND $_GET['page'] == 'plugins_list') ) { |
---|
72 | if (!isset($page['infos'])) $page['infos']=array(); |
---|
73 | if ($infos_message != "") { |
---|
74 | array_push($page['infos'], $infos_message); |
---|
75 | $infos_message=""; |
---|
76 | |
---|
77 | } |
---|
78 | if (count($page['infos']) != 0){ |
---|
79 | $template->assign('infos', $page['infos']); |
---|
80 | } |
---|
81 | if (!isset($page['errors'])) $page['errors']=array(); |
---|
82 | if ($erreur_message != "") { |
---|
83 | array_push($page['errors'], $erreur_message); |
---|
84 | $erreur_message=""; |
---|
85 | } |
---|
86 | if (count($page['errors']) != 0){ |
---|
87 | $template->assign('errors', $page['errors']); |
---|
88 | } |
---|
89 | |
---|
90 | if (!isset($page['warnings'])) $page['warnings']=array(); |
---|
91 | if ($infos_warning!= "") { |
---|
92 | array_push($page['warnings'], $infos_warning); |
---|
93 | $infos_warning= ""; |
---|
94 | } |
---|
95 | if (count($page['warnings']) != 0){ |
---|
96 | $template->assign('warnings', $page['warnings']); |
---|
97 | } |
---|
98 | } |
---|
99 | } |
---|
100 | //========================================================================================== |
---|
101 | function set_var($key,$defaut){ |
---|
102 | global $set_plugins_parametres; |
---|
103 | global $infos_message; |
---|
104 | |
---|
105 | if(isset($set_plugins_parametres) && isset($set_plugins_parametres[$key])) |
---|
106 | $ret=$set_plugins_parametres[$key]; |
---|
107 | |
---|
108 | $ret= (isset($ret))?$ret:$defaut; |
---|
109 | $ret=isset($_POST[$key])?$_POST[$key]:$ret; |
---|
110 | return $ret ; |
---|
111 | } |
---|
112 | //================================================================ |
---|
113 | function save_config(){ |
---|
114 | global $list_visible, $state,$liste,$nb,$page,$conf ; |
---|
115 | global $infos_message,$infos_warning,$erreur_message ; |
---|
116 | $config=array(); |
---|
117 | $config = array( |
---|
118 | 'list_visible' => $list_visible, |
---|
119 | 'state' => $state, |
---|
120 | 'liste'=>$liste, |
---|
121 | 'nb' =>$nb |
---|
122 | ); |
---|
123 | // $infos_warning .="save_config" . set_plugins::memo_var($conf['set_plugins'] ); |
---|
124 | $conf['set_plugins']= (serialize($config)); |
---|
125 | conf_update_param('set_plugins', $conf['set_plugins']); |
---|
126 | |
---|
127 | |
---|
128 | } |
---|
129 | //================================================================= |
---|
130 | function memo_var($variables){ |
---|
131 | ob_start(); |
---|
132 | echo '<pre>'; |
---|
133 | print_r($variables); |
---|
134 | echo '</pre>'; |
---|
135 | $m= ob_get_contents(); |
---|
136 | ob_end_clean(); |
---|
137 | return $m; |
---|
138 | } |
---|
139 | //=================================================================== |
---|
140 | function Affiche_set_plugins(){ |
---|
141 | global $infos_message,$liste_des_plugins,$erreur_message ; |
---|
142 | |
---|
143 | include_once(SET_PLUGINS_PATH."include/constants.php"); |
---|
144 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
145 | $all_tpl_vars = $template->get_template_vars('plugins'); |
---|
146 | if(!$all_tpl_vars) return; |
---|
147 | |
---|
148 | if( $set=="true" ){ |
---|
149 | $state=""; |
---|
150 | if(isset($_POST['unset_plugins']) ) |
---|
151 | $state='inactive'; |
---|
152 | elseif(isset($_POST['set_plugins']) ) |
---|
153 | $state='active'; |
---|
154 | if($state!=""){ |
---|
155 | if($state=="inactive") |
---|
156 | $sens ="DESC"; |
---|
157 | else |
---|
158 | $sens="ASC"; |
---|
159 | $infos_message .="-----> $state $sens<br />"; |
---|
160 | //============================ |
---|
161 | $query = 'SELECT * |
---|
162 | FROM ' . PLUGINS_TABLE . ' |
---|
163 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
164 | ORDER BY `id` '.$sens.' |
---|
165 | LIMIT '.$nb.' |
---|
166 | '; |
---|
167 | $result = pwg_query($query); |
---|
168 | //======= mise à jour ========= |
---|
169 | if($result){ |
---|
170 | $query = ' |
---|
171 | UPDATE '.PLUGINS_TABLE.' |
---|
172 | SET state="'.$state.'" |
---|
173 | WHERE `state` NOT LIKE "'.$state. '" AND id!="' . "set_plugins" . '" |
---|
174 | ORDER BY `id` '.$sens.' |
---|
175 | LIMIT '.$nb.';'; |
---|
176 | pwg_query($query); |
---|
177 | } |
---|
178 | //===================================== |
---|
179 | if(isset($result) && $result==true){ |
---|
180 | $liste= array_unique($liste); |
---|
181 | if(!array_search($add_plugins, $liste)){ |
---|
182 | array_push($liste, $add_plugins ); |
---|
183 | } |
---|
184 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
185 | $url = $row['id'] ; |
---|
186 | array_push($liste, $url); |
---|
187 | } |
---|
188 | } |
---|
189 | |
---|
190 | |
---|
191 | }else if (isset($_POST['init_plugins'])){ |
---|
192 | $liste = array(); |
---|
193 | $state="active"; |
---|
194 | $query = 'SELECT * |
---|
195 | FROM ' . PLUGINS_TABLE . ' |
---|
196 | WHERE `state` LIKE "active" AND id!="' . "set_plugins" . '" |
---|
197 | '; |
---|
198 | $result = pwg_query($query); |
---|
199 | if(isset($result) && $result==true){ |
---|
200 | $liste_plugins = array(); |
---|
201 | while ($row = pwg_db_fetch_assoc($result)) { |
---|
202 | $url = $row['id'] ; |
---|
203 | //array_push($liste_plugins, array('plugin' => $url ) ); |
---|
204 | array_push($liste, $url ); |
---|
205 | } |
---|
206 | } |
---|
207 | $nb=count($liste_plugins); |
---|
208 | |
---|
209 | } |
---|
210 | if(isset($result) && $result==true){ |
---|
211 | $redirect_url = get_root_url().'admin.php?page='.$_GET['page']; |
---|
212 | set_plugins::save_config(); |
---|
213 | $_POST['set']=""; |
---|
214 | $set=""; |
---|
215 | include(SET_PLUGINS_PATH.'include/affiche.php'); |
---|
216 | // redirect($redirect_url); |
---|
217 | } |
---|
218 | |
---|
219 | } |
---|
220 | $template->set_filenames( |
---|
221 | array( 'cl_plugin' => SET_PLUGINS_PATH_ABS.'template/admin.tpl' ) |
---|
222 | ); |
---|
223 | |
---|
224 | //=========================================================== |
---|
225 | $header_1='<div id="titrePage"> |
---|
226 | <h2>'.l10n("set_plugins").l10n("Version").": ".$cl_set_plugins_plugin['version'] .'</h2> |
---|
227 | </div>'; |
---|
228 | $bpplus=$header_1.$template->parse('cl_plugin', true); |
---|
229 | |
---|
230 | $template-> assign('ADMIN_CONTENT',$bpplus); |
---|
231 | $bpplus=$template->parse('plugins', true); |
---|
232 | $template-> concat('ADMIN_CONTENT',$bpplus); |
---|
233 | |
---|
234 | } |
---|
235 | |
---|
236 | //======================================== |
---|
237 | function save_to_file($liste){ |
---|
238 | global $infos_message; |
---|
239 | $edited_file=set_plugins::get_file_name(); |
---|
240 | if (file_exists($edited_file)){ |
---|
241 | copy($edited_file, substr_replace($edited_file, '.bak', strrpos($edited_file , '.'), 0) ); |
---|
242 | } |
---|
243 | if ($file = @fopen($edited_file , "w")) { |
---|
244 | $liste= array_unique($liste); |
---|
245 | @fwrite($file , serialize($liste)); |
---|
246 | @fclose($file); |
---|
247 | $infos_message.=l10n("save config").set_plugins::memo_var($edited_file); |
---|
248 | unset($_POST['submit']); |
---|
249 | } |
---|
250 | } |
---|
251 | //============================================== |
---|
252 | function restore_from_file(){ |
---|
253 | global $infos_message; |
---|
254 | $edited_file=set_plugins::get_file_name(); |
---|
255 | $content_file = file_get_contents($edited_file); |
---|
256 | $file =array(); |
---|
257 | $liste= array_unique(unserialize($content_file)); |
---|
258 | unset($_POST['restore']); |
---|
259 | } |
---|
260 | //=============================================== |
---|
261 | function get_file_name(){ |
---|
262 | global $edited_file; |
---|
263 | $dir=realpath('./local/plugins/set_plugins'); |
---|
264 | if (!is_dir($dir)){ |
---|
265 | $dir= realpath('./local/plugins'). "\\set_plugins"; |
---|
266 | $umask = umask(0); |
---|
267 | $mkd = @mkdir($dir, 0755, true ); |
---|
268 | umask($umask); |
---|
269 | if ($mkd==false){ |
---|
270 | fatal_error( "$dir ".l10n('no write access')); |
---|
271 | } |
---|
272 | $file = $dir.'\\.htaccess'; |
---|
273 | @file_put_contents( $file, 'allow from all' ); |
---|
274 | } |
---|
275 | $dir=realpath('./local/plugins/set_plugins'); |
---|
276 | if(!isset($edited_file) || $edited_file=="") |
---|
277 | $edited_file=$dir."/config.txt"; |
---|
278 | $edited_file=str_replace("\\","/", $edited_file); |
---|
279 | return $edited_file ; |
---|
280 | } |
---|
281 | |
---|
282 | |
---|
283 | }// fin classe |
---|
284 | ?> |
---|