1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-10-31 06:06:42 +0000 (Tue, 31 Oct 2006) $ |
---|
10 | // | last modifier : $Author: rvelices $ |
---|
11 | // | revision : $Revision: 1588 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
29 | { |
---|
30 | die ("Hacking attempt!"); |
---|
31 | } |
---|
32 | |
---|
33 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
34 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php'); |
---|
35 | check_status(ACCESS_ADMINISTRATOR); |
---|
36 | |
---|
37 | $my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins'; |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | // +-----------------------------------------------------------------------+ |
---|
42 | // | perform requested actions | |
---|
43 | // +-----------------------------------------------------------------------+ |
---|
44 | if ( isset($_REQUEST['action']) and isset($_REQUEST['plugin']) ) |
---|
45 | { |
---|
46 | $plugin_id = $_REQUEST['plugin']; |
---|
47 | $crt_db_plugin = get_db_plugins('', $plugin_id); |
---|
48 | if (!empty($crt_db_plugin)) |
---|
49 | { |
---|
50 | $crt_db_plugin=$crt_db_plugin[0]; |
---|
51 | } |
---|
52 | else |
---|
53 | { |
---|
54 | unset($crt_db_plugin); |
---|
55 | } |
---|
56 | |
---|
57 | $file_to_include = PHPWG_PLUGINS_PATH.$plugin_id.'/maintain.inc.php'; |
---|
58 | |
---|
59 | switch ( $_REQUEST['action'] ) |
---|
60 | { |
---|
61 | case 'install': |
---|
62 | if ( !empty($crt_db_plugin)) |
---|
63 | { |
---|
64 | die ('CANNOT install - ALREADY INSTALLED'); |
---|
65 | } |
---|
66 | $fs_plugins = get_fs_plugins(); |
---|
67 | if ( !isset( $fs_plugins[$plugin_id] ) ) |
---|
68 | { |
---|
69 | die ('CANNOT install - NO SUCH PLUGIN'); |
---|
70 | } |
---|
71 | $query = ' |
---|
72 | INSERT INTO '.PLUGINS_TABLE.' (id,version) VALUES ("' |
---|
73 | .$plugin_id.'","'.$fs_plugins[$plugin_id]['version'].'" |
---|
74 | )'; |
---|
75 | pwg_query($query); |
---|
76 | |
---|
77 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
78 | @include_once($file_to_include); |
---|
79 | if ( function_exists('plugin_install') ) |
---|
80 | { |
---|
81 | plugin_install($plugin_id); |
---|
82 | } |
---|
83 | break; |
---|
84 | |
---|
85 | |
---|
86 | case 'activate': |
---|
87 | if ( !isset($crt_db_plugin) ) |
---|
88 | { |
---|
89 | die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED'); |
---|
90 | } |
---|
91 | if ($crt_db_plugin['state']!='inactive') |
---|
92 | { |
---|
93 | die('invalid current state '.$crt_db_plugin['state']); |
---|
94 | } |
---|
95 | $query = ' |
---|
96 | UPDATE '.PLUGINS_TABLE.' SET state="active" WHERE id="'.$plugin_id.'"'; |
---|
97 | pwg_query($query); |
---|
98 | |
---|
99 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
100 | @include_once($file_to_include); |
---|
101 | if ( function_exists('plugin_activate') ) |
---|
102 | { |
---|
103 | plugin_activate($plugin_id); |
---|
104 | } |
---|
105 | break; |
---|
106 | |
---|
107 | |
---|
108 | case 'deactivate': |
---|
109 | if ( !isset($crt_db_plugin) ) |
---|
110 | { |
---|
111 | die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED'); |
---|
112 | } |
---|
113 | if ($crt_db_plugin['state']!='active') |
---|
114 | { |
---|
115 | die('invalid current state '.$crt_db_plugin['state']); |
---|
116 | } |
---|
117 | $query = ' |
---|
118 | UPDATE '.PLUGINS_TABLE.' SET state="inactive" WHERE id="'.$plugin_id.'"'; |
---|
119 | pwg_query($query); |
---|
120 | |
---|
121 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
122 | @include_once($file_to_include); |
---|
123 | if ( function_exists('plugin_deactivate') ) |
---|
124 | { |
---|
125 | plugin_deactivate($plugin_id); |
---|
126 | } |
---|
127 | break; |
---|
128 | |
---|
129 | case 'uninstall': |
---|
130 | if ( !isset($crt_db_plugin) ) |
---|
131 | { |
---|
132 | die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED'); |
---|
133 | } |
---|
134 | $query = ' |
---|
135 | DELETE FROM '.PLUGINS_TABLE.' WHERE id="'.$plugin_id.'"'; |
---|
136 | pwg_query($query); |
---|
137 | |
---|
138 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
139 | @include_once($file_to_include); |
---|
140 | if ( function_exists('plugin_uninstall') ) |
---|
141 | { |
---|
142 | plugin_uninstall($plugin_id); |
---|
143 | } |
---|
144 | break; |
---|
145 | } |
---|
146 | // do the redirection so that we allow the plugins to load/unload |
---|
147 | redirect($my_base_url); |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | // +-----------------------------------------------------------------------+ |
---|
152 | // | start template output | |
---|
153 | // +-----------------------------------------------------------------------+ |
---|
154 | $fs_plugins = get_fs_plugins(); |
---|
155 | $db_plugins = get_db_plugins(); |
---|
156 | $db_plugins_by_id=array(); |
---|
157 | foreach ($db_plugins as $db_plugin) |
---|
158 | { |
---|
159 | $db_plugins_by_id[$db_plugin['id']] = $db_plugin; |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | $template->set_filenames(array('plugins' => 'admin/plugins.tpl')); |
---|
164 | |
---|
165 | trigger_event('plugin_admin_menu'); |
---|
166 | |
---|
167 | $template->assign_block_vars('plugin_menu.menu_item', |
---|
168 | array( |
---|
169 | 'NAME' => l10n('Plugins'), |
---|
170 | 'URL' => PHPWG_ROOT_PATH.'admin.php?page=plugins' |
---|
171 | ) |
---|
172 | ); |
---|
173 | |
---|
174 | if ( isset($page['plugin_admin_menu']) ) |
---|
175 | { |
---|
176 | $plug_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugin&section='; |
---|
177 | foreach ($page['plugin_admin_menu'] as $menu) |
---|
178 | { |
---|
179 | $template->assign_block_vars('plugin_menu.menu_item', |
---|
180 | array( |
---|
181 | 'NAME' => $menu['title'], |
---|
182 | 'URL' => $plug_base_url.$menu['uid'] |
---|
183 | ) |
---|
184 | ); |
---|
185 | } |
---|
186 | } |
---|
187 | |
---|
188 | $num=0; |
---|
189 | foreach( $fs_plugins as $plugin_id => $fs_plugin ) |
---|
190 | { |
---|
191 | $display_name = $fs_plugin['name']; |
---|
192 | if ( !empty($fs_plugin['uri']) ) |
---|
193 | { |
---|
194 | $display_name='<a href="'.$fs_plugin['uri'].'">'.$display_name.'</a>'; |
---|
195 | } |
---|
196 | $template->assign_block_vars( 'plugins.plugin', |
---|
197 | array( |
---|
198 | 'NAME' => $display_name, |
---|
199 | 'VERSION' => $fs_plugin['version'], |
---|
200 | 'DESCRIPTION' => $fs_plugin['description'], |
---|
201 | 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
202 | ) |
---|
203 | ); |
---|
204 | |
---|
205 | |
---|
206 | $action_url = $my_base_url.'&plugin='.$plugin_id; |
---|
207 | if ( isset($db_plugins_by_id[$plugin_id]) ) |
---|
208 | { // already in the database |
---|
209 | // MAYBE TODO HERE: check for the version and propose upgrade action |
---|
210 | switch ($db_plugins_by_id[$plugin_id]['state']) |
---|
211 | { |
---|
212 | case 'active': |
---|
213 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
214 | array( |
---|
215 | 'U_ACTION' => $action_url . '&action=deactivate', |
---|
216 | 'L_ACTION' => l10n('Deactivate'), |
---|
217 | ) |
---|
218 | ); |
---|
219 | break; |
---|
220 | case 'inactive': |
---|
221 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
222 | array( |
---|
223 | 'U_ACTION' => $action_url . '&action=activate', |
---|
224 | 'L_ACTION' => l10n('Activate'), |
---|
225 | ) |
---|
226 | ); |
---|
227 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
228 | array( |
---|
229 | 'U_ACTION' => $action_url . '&action=uninstall', |
---|
230 | 'L_ACTION' => l10n('Uninstall'), |
---|
231 | ) |
---|
232 | ); |
---|
233 | break; |
---|
234 | } |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
239 | array( |
---|
240 | 'U_ACTION' => $action_url . '&action=install', |
---|
241 | 'L_ACTION' => l10n('Install'), |
---|
242 | ) |
---|
243 | ); |
---|
244 | } |
---|
245 | } |
---|
246 | |
---|
247 | $missing_plugin_ids = array_diff( |
---|
248 | array_keys($db_plugins_by_id), array_keys($fs_plugins) |
---|
249 | ); |
---|
250 | foreach( $missing_plugin_ids as $plugin_id ) |
---|
251 | { |
---|
252 | $template->assign_block_vars( 'plugins.plugin', |
---|
253 | array( |
---|
254 | 'NAME' => $plugin_id, |
---|
255 | 'VERSION' => $db_plugins_by_id[$plugin_id]['version'], |
---|
256 | 'DESCRIPTION' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !", |
---|
257 | 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
258 | ) |
---|
259 | ); |
---|
260 | $action_url = $my_base_url.'&plugin='.$plugin_id; |
---|
261 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
262 | array( |
---|
263 | 'U_ACTION' => $action_url . '&action=uninstall', |
---|
264 | 'L_ACTION' => l10n('Uninstall'), |
---|
265 | ) |
---|
266 | ); |
---|
267 | |
---|
268 | } |
---|
269 | |
---|
270 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugins'); |
---|
271 | ?> |
---|