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: 2007-01-08 00:16:10 +0000 (Mon, 08 Jan 2007) $ |
---|
10 | // | last modifier : $Author: rub $ |
---|
11 | // | revision : $Revision: 1699 $ |
---|
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 | check_status(ACCESS_ADMINISTRATOR); |
---|
35 | |
---|
36 | $my_base_url = PHPWG_ROOT_PATH.'admin.php?page=plugins'; |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | // +-----------------------------------------------------------------------+ |
---|
41 | // | perform requested actions | |
---|
42 | // +-----------------------------------------------------------------------+ |
---|
43 | if ( isset($_REQUEST['action']) and isset($_REQUEST['plugin']) ) |
---|
44 | { |
---|
45 | if (function_exists('mysql_real_escape_string')) |
---|
46 | { |
---|
47 | $plugin_id = mysql_real_escape_string($_REQUEST['plugin']); |
---|
48 | } |
---|
49 | else |
---|
50 | { |
---|
51 | $plugin_id = mysql_escape_string($_REQUEST['plugin']); |
---|
52 | } |
---|
53 | |
---|
54 | $crt_db_plugin = get_db_plugins('', $plugin_id); |
---|
55 | if (!empty($crt_db_plugin)) |
---|
56 | { |
---|
57 | $crt_db_plugin=$crt_db_plugin[0]; |
---|
58 | } |
---|
59 | else |
---|
60 | { |
---|
61 | unset($crt_db_plugin); |
---|
62 | } |
---|
63 | |
---|
64 | $file_to_include = PHPWG_PLUGINS_PATH.$plugin_id.'/maintain.inc.php'; |
---|
65 | |
---|
66 | switch ( $_REQUEST['action'] ) |
---|
67 | { |
---|
68 | case 'install': |
---|
69 | if ( !empty($crt_db_plugin)) |
---|
70 | { |
---|
71 | die ('CANNOT install - ALREADY INSTALLED'); |
---|
72 | } |
---|
73 | $fs_plugins = get_fs_plugins(); |
---|
74 | if ( !isset( $fs_plugins[$plugin_id] ) ) |
---|
75 | { |
---|
76 | die ('CANNOT install - NO SUCH PLUGIN'); |
---|
77 | } |
---|
78 | $query = ' |
---|
79 | INSERT INTO '.PLUGINS_TABLE.' (id,version) VALUES ("' |
---|
80 | .$plugin_id.'","'.$fs_plugins[$plugin_id]['version'].'" |
---|
81 | )'; |
---|
82 | pwg_query($query); |
---|
83 | |
---|
84 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
85 | @include_once($file_to_include); |
---|
86 | if ( function_exists('plugin_install') ) |
---|
87 | { |
---|
88 | plugin_install($plugin_id); |
---|
89 | } |
---|
90 | break; |
---|
91 | |
---|
92 | |
---|
93 | case 'activate': |
---|
94 | if ( !isset($crt_db_plugin) ) |
---|
95 | { |
---|
96 | die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED'); |
---|
97 | } |
---|
98 | if ($crt_db_plugin['state']!='inactive') |
---|
99 | { |
---|
100 | die('invalid current state '.$crt_db_plugin['state']); |
---|
101 | } |
---|
102 | $query = ' |
---|
103 | UPDATE '.PLUGINS_TABLE.' SET state="active" WHERE id="'.$plugin_id.'"'; |
---|
104 | pwg_query($query); |
---|
105 | |
---|
106 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
107 | @include_once($file_to_include); |
---|
108 | if ( function_exists('plugin_activate') ) |
---|
109 | { |
---|
110 | plugin_activate($plugin_id); |
---|
111 | } |
---|
112 | break; |
---|
113 | |
---|
114 | |
---|
115 | case 'deactivate': |
---|
116 | if ( !isset($crt_db_plugin) ) |
---|
117 | { |
---|
118 | die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED'); |
---|
119 | } |
---|
120 | if ($crt_db_plugin['state']!='active') |
---|
121 | { |
---|
122 | die('invalid current state '.$crt_db_plugin['state']); |
---|
123 | } |
---|
124 | $query = ' |
---|
125 | UPDATE '.PLUGINS_TABLE.' SET state="inactive" WHERE id="'.$plugin_id.'"'; |
---|
126 | pwg_query($query); |
---|
127 | |
---|
128 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
129 | @include_once($file_to_include); |
---|
130 | if ( function_exists('plugin_deactivate') ) |
---|
131 | { |
---|
132 | plugin_deactivate($plugin_id); |
---|
133 | } |
---|
134 | break; |
---|
135 | |
---|
136 | case 'uninstall': |
---|
137 | if ( !isset($crt_db_plugin) ) |
---|
138 | { |
---|
139 | die ('CANNOT '. $_REQUEST['action'] .' - NOT INSTALLED'); |
---|
140 | } |
---|
141 | $query = ' |
---|
142 | DELETE FROM '.PLUGINS_TABLE.' WHERE id="'.$plugin_id.'"'; |
---|
143 | pwg_query($query); |
---|
144 | |
---|
145 | // MAYBE TODO HERE = what if we die or we fail ??? |
---|
146 | @include_once($file_to_include); |
---|
147 | if ( function_exists('plugin_uninstall') ) |
---|
148 | { |
---|
149 | plugin_uninstall($plugin_id); |
---|
150 | } |
---|
151 | break; |
---|
152 | } |
---|
153 | // do the redirection so that we allow the plugins to load/unload |
---|
154 | redirect($my_base_url); |
---|
155 | } |
---|
156 | |
---|
157 | |
---|
158 | // +-----------------------------------------------------------------------+ |
---|
159 | // | start template output | |
---|
160 | // +-----------------------------------------------------------------------+ |
---|
161 | $fs_plugins = get_fs_plugins(); |
---|
162 | $db_plugins = get_db_plugins(); |
---|
163 | $db_plugins_by_id=array(); |
---|
164 | foreach ($db_plugins as $db_plugin) |
---|
165 | { |
---|
166 | $db_plugins_by_id[$db_plugin['id']] = $db_plugin; |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | $template->set_filenames(array('plugins' => 'admin/plugins.tpl')); |
---|
171 | |
---|
172 | $num=0; |
---|
173 | foreach( $fs_plugins as $plugin_id => $fs_plugin ) |
---|
174 | { |
---|
175 | $display_name = $fs_plugin['name']; |
---|
176 | if ( !empty($fs_plugin['uri']) ) |
---|
177 | { |
---|
178 | $display_name='<a href="'.$fs_plugin['uri'].'">'.$display_name.'</a>'; |
---|
179 | } |
---|
180 | $template->assign_block_vars( 'plugins.plugin', |
---|
181 | array( |
---|
182 | 'NAME' => $display_name, |
---|
183 | 'VERSION' => $fs_plugin['version'], |
---|
184 | 'DESCRIPTION' => $fs_plugin['description'], |
---|
185 | 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
186 | ) |
---|
187 | ); |
---|
188 | |
---|
189 | |
---|
190 | $action_url = $my_base_url.'&plugin='.$plugin_id; |
---|
191 | if ( isset($db_plugins_by_id[$plugin_id]) ) |
---|
192 | { // already in the database |
---|
193 | // MAYBE TODO HERE: check for the version and propose upgrade action |
---|
194 | switch ($db_plugins_by_id[$plugin_id]['state']) |
---|
195 | { |
---|
196 | case 'active': |
---|
197 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
198 | array( |
---|
199 | 'U_ACTION' => $action_url . '&action=deactivate', |
---|
200 | 'L_ACTION' => l10n('Deactivate'), |
---|
201 | ) |
---|
202 | ); |
---|
203 | break; |
---|
204 | case 'inactive': |
---|
205 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
206 | array( |
---|
207 | 'U_ACTION' => $action_url . '&action=activate', |
---|
208 | 'L_ACTION' => l10n('Activate'), |
---|
209 | ) |
---|
210 | ); |
---|
211 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
212 | array( |
---|
213 | 'U_ACTION' => $action_url . '&action=uninstall', |
---|
214 | 'L_ACTION' => l10n('Uninstall'), |
---|
215 | ) |
---|
216 | ); |
---|
217 | break; |
---|
218 | } |
---|
219 | } |
---|
220 | else |
---|
221 | { |
---|
222 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
223 | array( |
---|
224 | 'U_ACTION' => $action_url . '&action=install', |
---|
225 | 'L_ACTION' => l10n('Install'), |
---|
226 | ) |
---|
227 | ); |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | $missing_plugin_ids = array_diff( |
---|
232 | array_keys($db_plugins_by_id), array_keys($fs_plugins) |
---|
233 | ); |
---|
234 | foreach( $missing_plugin_ids as $plugin_id ) |
---|
235 | { |
---|
236 | $template->assign_block_vars( 'plugins.plugin', |
---|
237 | array( |
---|
238 | 'NAME' => $plugin_id, |
---|
239 | 'VERSION' => $db_plugins_by_id[$plugin_id]['version'], |
---|
240 | 'DESCRIPTION' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !", |
---|
241 | 'CLASS' => ($num++ % 2 == 1) ? 'row2' : 'row1', |
---|
242 | ) |
---|
243 | ); |
---|
244 | $action_url = $my_base_url.'&plugin='.$plugin_id; |
---|
245 | $template->assign_block_vars( 'plugins.plugin.action', |
---|
246 | array( |
---|
247 | 'U_ACTION' => $action_url . '&action=uninstall', |
---|
248 | 'L_ACTION' => l10n('Uninstall'), |
---|
249 | ) |
---|
250 | ); |
---|
251 | |
---|
252 | } |
---|
253 | |
---|
254 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugins'); |
---|
255 | ?> |
---|