1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
5 | // +-----------------------------------------------------------------------+ |
---|
6 | // | file : $Id: plugins_list.php 2255 2008-03-06 02:29:29Z rvelices $ |
---|
7 | // | last update : $Date: 2008-03-06 02:29:29 +0000 (Thu, 06 Mar 2008) $ |
---|
8 | // | last modifier : $Author: rvelices $ |
---|
9 | // | revision : $Revision: 2255 $ |
---|
10 | // +-----------------------------------------------------------------------+ |
---|
11 | // | This program is free software; you can redistribute it and/or modify | |
---|
12 | // | it under the terms of the GNU General Public License as published by | |
---|
13 | // | the Free Software Foundation | |
---|
14 | // | | |
---|
15 | // | This program is distributed in the hope that it will be useful, but | |
---|
16 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
17 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
18 | // | General Public License for more details. | |
---|
19 | // | | |
---|
20 | // | You should have received a copy of the GNU General Public License | |
---|
21 | // | along with this program; if not, write to the Free Software | |
---|
22 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
23 | // | USA. | |
---|
24 | // +-----------------------------------------------------------------------+ |
---|
25 | |
---|
26 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
27 | { |
---|
28 | die ("Hacking attempt!"); |
---|
29 | } |
---|
30 | |
---|
31 | |
---|
32 | // +-----------------------------------------------------------------------+ |
---|
33 | // | perform requested actions | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | if (isset($_GET['action']) and isset($_GET['plugin']) and !is_adviser()) |
---|
36 | { |
---|
37 | $plugin_id = $_GET['plugin']; |
---|
38 | $crt_db_plugin = get_db_plugins('', $plugin_id); |
---|
39 | if (!empty($crt_db_plugin)) |
---|
40 | { |
---|
41 | $crt_db_plugin = $crt_db_plugin[0]; |
---|
42 | } |
---|
43 | else |
---|
44 | { |
---|
45 | unset($crt_db_plugin); |
---|
46 | } |
---|
47 | |
---|
48 | $errors = array(); |
---|
49 | $file_to_include = PHPWG_PLUGINS_PATH . $plugin_id . '/maintain.inc.php'; |
---|
50 | |
---|
51 | switch ($_GET['action']) |
---|
52 | { |
---|
53 | case 'install': |
---|
54 | if (!empty($crt_db_plugin)) |
---|
55 | { |
---|
56 | array_push($errors, 'CANNOT install - ALREADY INSTALLED'); |
---|
57 | break; |
---|
58 | } |
---|
59 | $fs_plugins = get_fs_plugins(); |
---|
60 | if (!isset($fs_plugins[$plugin_id])) |
---|
61 | { |
---|
62 | array_push($errors, 'CANNOT install - NO SUCH PLUGIN'); |
---|
63 | break; |
---|
64 | } |
---|
65 | if (file_exists($file_to_include)) |
---|
66 | { |
---|
67 | include_once($file_to_include); |
---|
68 | if (function_exists('plugin_install')) |
---|
69 | { |
---|
70 | plugin_install($plugin_id, $fs_plugins[$plugin_id]['version'], $errors); |
---|
71 | } |
---|
72 | } |
---|
73 | if (empty($errors)) |
---|
74 | { |
---|
75 | $query = ' |
---|
76 | INSERT INTO ' . PLUGINS_TABLE . ' (id,version) VALUES ("' |
---|
77 | . $plugin_id . '","' . $fs_plugins[$plugin_id]['version'] . '" |
---|
78 | )'; |
---|
79 | pwg_query($query); |
---|
80 | } |
---|
81 | break; |
---|
82 | |
---|
83 | case 'activate': |
---|
84 | activate_plugin($plugin_id, $errors); |
---|
85 | break; |
---|
86 | case 'deactivate': |
---|
87 | deactivate_plugin($plugin_id, $errors); |
---|
88 | break; |
---|
89 | |
---|
90 | case 'uninstall': |
---|
91 | if (!isset($crt_db_plugin)) |
---|
92 | { |
---|
93 | die ('CANNOT ' . $_GET['action'] . ' - NOT INSTALLED'); |
---|
94 | } |
---|
95 | $query = ' |
---|
96 | DELETE FROM ' . PLUGINS_TABLE . ' WHERE id="' . $plugin_id . '"'; |
---|
97 | pwg_query($query); |
---|
98 | if (file_exists($file_to_include)) |
---|
99 | { |
---|
100 | include_once($file_to_include); |
---|
101 | if (function_exists('plugin_uninstall')) |
---|
102 | { |
---|
103 | plugin_uninstall($plugin_id); |
---|
104 | } |
---|
105 | } |
---|
106 | break; |
---|
107 | |
---|
108 | case 'delete': |
---|
109 | if (!empty($crt_db_plugin)) |
---|
110 | { |
---|
111 | array_push($errors, 'CANNOT delete - PLUGIN IS INSTALLED'); |
---|
112 | } |
---|
113 | elseif (!deltree(PHPWG_PLUGINS_PATH . $plugin_id)) |
---|
114 | { |
---|
115 | send_to_trash(PHPWG_PLUGINS_PATH . $plugin_id); |
---|
116 | } |
---|
117 | break; |
---|
118 | } |
---|
119 | if (empty($errors)) |
---|
120 | { |
---|
121 | redirect( |
---|
122 | get_root_url() |
---|
123 | .'admin.php' |
---|
124 | .get_query_string_diff( array('action', 'plugin') ) |
---|
125 | ); |
---|
126 | } |
---|
127 | else |
---|
128 | { |
---|
129 | $page['errors'] = array_merge($page['errors'], $errors); |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | |
---|
134 | $fs_plugins = get_fs_plugins(); |
---|
135 | $db_plugins = get_db_plugins(); |
---|
136 | $db_plugins_by_id = array(); |
---|
137 | foreach ($db_plugins as $db_plugin) |
---|
138 | { |
---|
139 | $db_plugins_by_id[$db_plugin['id']] = $db_plugin; |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | // +-----------------------------------------------------------------------+ |
---|
144 | // | start template output | |
---|
145 | // +-----------------------------------------------------------------------+ |
---|
146 | |
---|
147 | $template->set_filenames(array('plugins' => 'admin/plugins_list.tpl')); |
---|
148 | |
---|
149 | $base_url = get_root_url().'admin.php'; |
---|
150 | |
---|
151 | //----------------------------------------------------------------sort options |
---|
152 | $selected_order = isset($_GET['order']) ? $_GET['order'] : 'name'; |
---|
153 | |
---|
154 | $url = $base_url.get_query_string_diff( array('action', 'plugin', 'order')); |
---|
155 | |
---|
156 | $template->assign('order', |
---|
157 | array( |
---|
158 | $url.'&order=name' => l10n('Name'), |
---|
159 | $url.'&order=status' => l10n('Status'), |
---|
160 | $url.'&order=author' => l10n('Author'), |
---|
161 | $url.'&order=id' => l10n('Id'), |
---|
162 | ) |
---|
163 | ); |
---|
164 | |
---|
165 | $template->assign('selected', $url.'&order='.$selected_order); |
---|
166 | |
---|
167 | switch ($selected_order) |
---|
168 | { |
---|
169 | case 'name': |
---|
170 | uasort($fs_plugins, 'name_compare'); |
---|
171 | break; |
---|
172 | case 'id': |
---|
173 | uksort($fs_plugins, 'strcasecmp'); |
---|
174 | break; |
---|
175 | case 'author': |
---|
176 | uasort($fs_plugins, 'plugin_author_compare'); |
---|
177 | break; |
---|
178 | case 'status': |
---|
179 | $fs_plugins = sort_plugins_by_state($fs_plugins, $db_plugins_by_id); |
---|
180 | break; |
---|
181 | } |
---|
182 | |
---|
183 | |
---|
184 | //--------------------------------------------------------------display plugins |
---|
185 | |
---|
186 | $url = $base_url.get_query_string_diff( array('action', 'plugin') ); |
---|
187 | |
---|
188 | foreach($fs_plugins as $plugin_id => $fs_plugin) |
---|
189 | { |
---|
190 | $display_name = $fs_plugin['name']; |
---|
191 | if (!empty($fs_plugin['uri'])) |
---|
192 | { |
---|
193 | $display_name = '<a href="' . $fs_plugin['uri'] |
---|
194 | . '" onclick="window.open(this.href); return false;">' |
---|
195 | . $display_name . '</a>'; |
---|
196 | } |
---|
197 | $desc = $fs_plugin['description']; |
---|
198 | if (!empty($fs_plugin['author'])) |
---|
199 | { |
---|
200 | $desc .= ' (<em>'; |
---|
201 | if (!empty($fs_plugin['author uri'])) |
---|
202 | { |
---|
203 | $desc .= '<a href="' . $fs_plugin['author uri'] . '">' |
---|
204 | . $fs_plugin['author'] . '</a>'; |
---|
205 | } |
---|
206 | else |
---|
207 | { |
---|
208 | $desc .= $fs_plugin['author']; |
---|
209 | } |
---|
210 | $desc .= '</em>)'; |
---|
211 | } |
---|
212 | $tpl_plugin = |
---|
213 | array('NAME' => $display_name, |
---|
214 | 'VERSION' => $fs_plugin['version'], |
---|
215 | 'DESCRIPTION' => $desc); |
---|
216 | |
---|
217 | $action_url = $url.'&plugin='.$plugin_id; |
---|
218 | |
---|
219 | if (isset($db_plugins_by_id[$plugin_id])) |
---|
220 | { |
---|
221 | switch ($db_plugins_by_id[$plugin_id]['state']) |
---|
222 | { |
---|
223 | case 'active': |
---|
224 | $tpl_plugin['actions'][] = |
---|
225 | array('U_ACTION' => $action_url . '&action=deactivate', |
---|
226 | 'L_ACTION' => l10n('Deactivate')); |
---|
227 | break; |
---|
228 | |
---|
229 | case 'inactive': |
---|
230 | $tpl_plugin['actions'][] = |
---|
231 | array('U_ACTION' => $action_url . '&action=activate', |
---|
232 | 'L_ACTION' => l10n('Activate')); |
---|
233 | $tpl_plugin['actions'][] = |
---|
234 | array('U_ACTION' => $action_url . '&action=uninstall', |
---|
235 | 'L_ACTION' => l10n('Uninstall'), |
---|
236 | 'CONFIRM' => l10n('Are you sure?')); |
---|
237 | break; |
---|
238 | } |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | $tpl_plugin['actions'][] = |
---|
243 | array('U_ACTION' => $action_url . '&action=install', |
---|
244 | 'L_ACTION' => l10n('Install'), |
---|
245 | 'CONFIRM' => l10n('Are you sure?')); |
---|
246 | $tpl_plugin['actions'][] = |
---|
247 | array('U_ACTION' => $action_url . '&action=delete', |
---|
248 | 'L_ACTION' => l10n('plugins_delete'), |
---|
249 | 'CONFIRM' => l10n('plugins_confirm_delete')); |
---|
250 | } |
---|
251 | $template->append('plugins', $tpl_plugin); |
---|
252 | } |
---|
253 | |
---|
254 | $missing_plugin_ids = array_diff( |
---|
255 | array_keys($db_plugins_by_id), array_keys($fs_plugins) |
---|
256 | ); |
---|
257 | |
---|
258 | foreach($missing_plugin_ids as $plugin_id) |
---|
259 | { |
---|
260 | $action_url = $url.'&plugin='.$plugin_id; |
---|
261 | |
---|
262 | $template->append( 'plugins', |
---|
263 | array( |
---|
264 | 'NAME' => $plugin_id, |
---|
265 | 'VERSION' => $db_plugins_by_id[$plugin_id]['version'], |
---|
266 | 'DESCRIPTION' => "ERROR: THIS PLUGIN IS MISSING BUT IT IS INSTALLED! UNINSTALL IT NOW !", |
---|
267 | 'actions' => array ( array ( |
---|
268 | 'U_ACTION' => $action_url . '&action=uninstall', |
---|
269 | 'L_ACTION' => l10n('Uninstall'), |
---|
270 | ) ) |
---|
271 | ) |
---|
272 | ); |
---|
273 | } |
---|
274 | |
---|
275 | $template->assign_var_from_handle('ADMIN_CONTENT', 'plugins'); |
---|
276 | ?> |
---|