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