|
1 <?php |
|
2 /*********************************************************************** |
|
3 |
|
4 Copyright (C) 2002-2008 PunBB.org |
|
5 |
|
6 This file is part of PunBB. |
|
7 |
|
8 PunBB is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published |
|
10 by the Free Software Foundation; either version 2 of the License, |
|
11 or (at your option) any later version. |
|
12 |
|
13 PunBB is distributed in the hope that it will be useful, but |
|
14 WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 GNU General Public License for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with this program; if not, write to the Free Software |
|
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
|
21 MA 02111-1307 USA |
|
22 |
|
23 ************************************************************************/ |
|
24 |
|
25 |
|
26 // if (!defined('PUN_ROOT')) |
|
27 // define('PUN_ROOT', '../'); |
|
28 // require PUN_ROOT.'include/common.php'; |
|
29 require PUN_ROOT.'include/common_admin.php'; |
|
30 |
|
31 // import globals (I really hope this isn't dangerous) |
|
32 foreach ( $GLOBALS as $key => $_ ) |
|
33 { |
|
34 $$key =& $GLOBALS[$key]; |
|
35 } |
|
36 require_once PUN_ROOT.'include/xml.php'; |
|
37 |
|
38 ($hook = get_hook('aex_start')) ? eval($hook) : null; |
|
39 |
|
40 if ($session->user_level < USER_LEVEL_ADMIN) |
|
41 message($lang_common['No permission']); |
|
42 |
|
43 // Load the admin.php language file |
|
44 require PUN_ROOT.'lang/'.$pun_user['language'].'/admin.php'; |
|
45 $GLOBALS['lang_admin'] = $lang_admin; |
|
46 |
|
47 // Make sure we have XML support |
|
48 if (!function_exists('xml_parser_create')) |
|
49 message($lang_admin['No XML support']); |
|
50 |
|
51 $section = isset($_GET['section']) ? $_GET['section'] : null; |
|
52 |
|
53 |
|
54 // Install an extension |
|
55 if (isset($_GET['install']) || isset($_GET['install_hotfix'])) |
|
56 { |
|
57 ($hook = get_hook('aex_install_selected')) ? eval($hook) : null; |
|
58 |
|
59 // User pressed the cancel button |
|
60 if (isset($_POST['install_cancel'])) |
|
61 pun_redirect(pun_link($pun_url['admin_extensions_install']), $lang_admin['Cancel redirect']); |
|
62 |
|
63 $id = preg_replace('/[^0-9a-z_]/', '', isset($_GET['install']) ? $_GET['install'] : $_GET['install_hotfix']); |
|
64 |
|
65 // Load manifest (either locally or from punbb.org updates service) |
|
66 if (isset($_GET['install'])) |
|
67 $manifest = @file_get_contents(PUN_ROOT.'extensions/'.$id.'/manifest.xml'); |
|
68 else |
|
69 $manifest = @end(get_remote_file('http://punbb.org/update/manifest/'.$id.'.xml', 16)); |
|
70 |
|
71 // Parse manifest.xml into an array and validate it |
|
72 $ext_data = xml_to_array($manifest); |
|
73 $errors = validate_manifest($ext_data, $id); |
|
74 |
|
75 if (!empty($errors)) |
|
76 message(isset($_GET['install']) ? $lang_common['Bad request'] : $lang_admin['Hotfix download failed']); |
|
77 |
|
78 // Setup breadcrumbs |
|
79 $pun_page['crumbs'] = array( |
|
80 array($pun_config['o_board_title'], pun_link($pun_url['index'])), |
|
81 array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), |
|
82 array($lang_admin['Install extensions'], pun_link($pun_url['admin_extensions_install'])), |
|
83 $lang_admin['Install extension'] |
|
84 ); |
|
85 |
|
86 if (isset($_POST['install_comply'])) |
|
87 { |
|
88 ($hook = get_hook('aex_install_comply_form_submitted')) ? eval($hook) : null; |
|
89 |
|
90 // Is there some uninstall code to store in the db? |
|
91 $uninstall_code = (isset($ext_data['extension']['uninstall']) && trim($ext_data['extension']['uninstall']) != '') ? '\''.$pun_db->escape(trim($ext_data['extension']['uninstall'])).'\'' : 'NULL'; |
|
92 |
|
93 // Is there an uninstall note to store in the db? |
|
94 $uninstall_note = 'NULL'; |
|
95 foreach ($ext_data['extension']['note'] as $cur_note) |
|
96 { |
|
97 if ($cur_note['attributes']['type'] == 'uninstall' && trim($cur_note['content']) != '') |
|
98 $uninstall_note = '\''.$pun_db->escape(trim($cur_note['content'])).'\''; |
|
99 } |
|
100 |
|
101 $notices = array(); |
|
102 |
|
103 // Is this a fresh install or an upgrade? |
|
104 $query = array( |
|
105 'SELECT' => 'e.version', |
|
106 'FROM' => 'extensions AS e', |
|
107 'WHERE' => 'e.id=\''.$pun_db->escape($id).'\'' |
|
108 ); |
|
109 |
|
110 ($hook = get_hook('aex_qr_get_current_ext_version')) ? eval($hook) : null; |
|
111 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
112 if ($pun_db->num_rows($result)) |
|
113 { |
|
114 // EXT_CUR_VERSION will be available to the extension install routine (to facilitate extension upgrades) |
|
115 define('EXT_CUR_VERSION', $pun_db->result($result)); |
|
116 |
|
117 // Run the author supplied install code |
|
118 if (isset($ext_data['extension']['install']) && trim($ext_data['extension']['install']) != '') |
|
119 eval($ext_data['extension']['install']); |
|
120 |
|
121 // Update the existing extension |
|
122 $query = array( |
|
123 'UPDATE' => 'extensions', |
|
124 'SET' => 'title=\''.$pun_db->escape($ext_data['extension']['title']).'\', version=\''.$pun_db->escape($ext_data['extension']['version']).'\', description=\''.$pun_db->escape($ext_data['extension']['description']).'\', author=\''.$pun_db->escape($ext_data['extension']['author']).'\', uninstall='.$uninstall_code.', uninstall_note='.$uninstall_note, |
|
125 'WHERE' => 'id=\''.$pun_db->escape($id).'\'' |
|
126 ); |
|
127 |
|
128 ($hook = get_hook('aex_qr_update_ext')) ? eval($hook) : null; |
|
129 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
130 |
|
131 // Delete the old hooks |
|
132 $query = array( |
|
133 'DELETE' => 'extension_hooks', |
|
134 'WHERE' => 'extension_id=\''.$pun_db->escape($id).'\'' |
|
135 ); |
|
136 |
|
137 ($hook = get_hook('aex_qr_delete_hooks')) ? eval($hook) : null; |
|
138 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
139 } |
|
140 else |
|
141 { |
|
142 // Run the author supplied install code |
|
143 if (isset($ext_data['extension']['install']) && trim($ext_data['extension']['install']) != '') |
|
144 eval($ext_data['extension']['install']); |
|
145 |
|
146 // Add the new extension |
|
147 $query = array( |
|
148 'INSERT' => 'id, title, version, description, author, uninstall, uninstall_note', |
|
149 'INTO' => 'extensions', |
|
150 'VALUES' => '\''.$pun_db->escape($ext_data['extension']['id']).'\', \''.$pun_db->escape($ext_data['extension']['title']).'\', \''.$pun_db->escape($ext_data['extension']['version']).'\', \''.$pun_db->escape($ext_data['extension']['description']).'\', \''.$pun_db->escape($ext_data['extension']['author']).'\', '.$uninstall_code.', '.$uninstall_note |
|
151 ); |
|
152 |
|
153 ($hook = get_hook('aex_qr_add_ext')) ? eval($hook) : null; |
|
154 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
155 } |
|
156 |
|
157 // Now insert the hooks |
|
158 foreach ($ext_data['extension']['hooks']['hook'] as $hook) |
|
159 { |
|
160 $query = array( |
|
161 'INSERT' => 'id, extension_id, code, installed', |
|
162 'INTO' => 'extension_hooks', |
|
163 'VALUES' => '\''.$pun_db->escape(trim($hook['attributes']['id'])).'\', \''.$pun_db->escape($id).'\', \''.$pun_db->escape(trim($hook['content'])).'\', '.time() |
|
164 ); |
|
165 |
|
166 ($hook = get_hook('aex_qr_add_hook')) ? eval($hook) : null; |
|
167 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
168 } |
|
169 |
|
170 // Empty the PHP cache |
|
171 $d = dir(PUN_CACHE_DIR); |
|
172 while (($entry = $d->read()) !== false) |
|
173 { |
|
174 if (substr($entry, strlen($entry)-4) == '.php') |
|
175 @unlink(PUN_CACHE_DIR.$entry); |
|
176 } |
|
177 $d->close(); |
|
178 |
|
179 // Regenerate the hooks cache |
|
180 require_once PUN_ROOT.'include/cache.php'; |
|
181 generate_hooks_cache(); |
|
182 |
|
183 // Display notices if there are any |
|
184 if (!empty($notices)) |
|
185 { |
|
186 ($hook = get_hook('aex_install_notices_pre_header_load')) ? eval($hook) : null; |
|
187 |
|
188 define('PUN_PAGE_SECTION', 'extensions'); |
|
189 define('PUN_PAGE', 'admin-extensions-install'); |
|
190 require PUN_ROOT.'header.php'; |
|
191 |
|
192 ?> |
|
193 <div id="pun-main" class="main sectioned admin"> |
|
194 |
|
195 <?php echo generate_admin_menu(); ?> |
|
196 |
|
197 <div class="main-head"> |
|
198 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
199 </div> |
|
200 <div class="main-content frm"> |
|
201 <div class="frm-head"> |
|
202 <h2><span><?php echo end($pun_page['crumbs']) ?> "<?php echo htmlspecialchars($ext_data['extension']['title']) ?>"</span></h2> |
|
203 </div> |
|
204 <div class="frm-info"> |
|
205 <p><?php echo $lang_admin['Extension installed info'] ?></p> |
|
206 <ul> |
|
207 <?php |
|
208 |
|
209 while (list(, $cur_notice) = each($notices)) |
|
210 echo "\t\t\t\t".'<li><span>'.$cur_notice.'</span></li>'."\n"; |
|
211 |
|
212 ?> |
|
213 </ul> |
|
214 <p><a href="<?php echo pun_link($pun_url['admin_extensions_manage']) ?>"><?php echo $lang_admin['Manage extensions'] ?></a></p> |
|
215 </div> |
|
216 </div> |
|
217 |
|
218 </div> |
|
219 <?php |
|
220 |
|
221 require PUN_ROOT.'footer.php'; |
|
222 } |
|
223 else |
|
224 pun_redirect(pun_link($pun_url['admin_extensions_manage']), $lang_admin['Extension installed'].' '.$lang_admin['Redirect']); |
|
225 } |
|
226 |
|
227 |
|
228 ($hook = get_hook('aex_install_pre_header_load')) ? eval($hook) : null; |
|
229 |
|
230 define('PUN_PAGE_SECTION', 'extensions'); |
|
231 define('PUN_PAGE', 'admin-extensions-install'); |
|
232 require PUN_ROOT.'header.php'; |
|
233 |
|
234 ?> |
|
235 <div id="pun-main" class="main sectioned admin"> |
|
236 |
|
237 <?php echo generate_admin_menu(); ?> |
|
238 |
|
239 <div class="main-head"> |
|
240 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
241 </div> |
|
242 |
|
243 <div class="main-content frm"> |
|
244 <div class="frm-head"> |
|
245 <h2><span><?php echo end($pun_page['crumbs']) ?> "<?php echo htmlspecialchars($ext_data['extension']['title']) ?>"</span></h2> |
|
246 </div> |
|
247 <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $base_url.'/admin/extensions.php'.(isset($_GET['install']) ? '?install=' : '?install_hotfix=').$id ?>"> |
|
248 <div class="hidden"> |
|
249 <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($base_url.'/admin/extensions.php'.(isset($_GET['install']) ? '?install=' : '?install_hotfix=').$id) ?>" /> |
|
250 </div> |
|
251 <div class="ext-item databox"> |
|
252 <h3 class="legend"><span><?php echo htmlspecialchars($ext_data['extension']['title']).((strpos($id, 'hotfix_') !== 0) ? ' v'.$ext_data['extension']['version'] : '') ?></span></h3> |
|
253 <p><span><?php printf($lang_admin['Extension by'], $ext_data['extension']['author']) ?></span><br /><span><?php echo htmlspecialchars($ext_data['extension']['description']) ?></span></p> |
|
254 <?php |
|
255 |
|
256 // Setup an array of warnings to display in the form |
|
257 $form_warnings = array(); |
|
258 $pun_page['num_items'] = 0; |
|
259 |
|
260 foreach ($ext_data['extension']['note'] as $cur_note) |
|
261 { |
|
262 if ($cur_note['attributes']['type'] == 'install') |
|
263 $form_warnings[] = '<p>'.++$pun_page['num_items'].'. '.htmlspecialchars($cur_note['content']).'</p>'; |
|
264 } |
|
265 |
|
266 if (version_compare(clean_version($pun_config['o_cur_version']), clean_version($ext_data['extension']['maxtestedon']), '>')) |
|
267 $form_warnings[] = '<p>'.++$pun_page['num_items'].'. '.$lang_admin['Maxtestedon warning'].'</p>'; |
|
268 |
|
269 if (!empty($form_warnings)) |
|
270 { |
|
271 |
|
272 ?> |
|
273 <h4 class="note"><?php echo $lang_admin['Install note'] ?></h4> |
|
274 <?php |
|
275 |
|
276 echo implode("\n\t\t\t\t\t", $form_warnings)."\n"; |
|
277 } |
|
278 |
|
279 ?> |
|
280 </div> |
|
281 <div class="frm-buttons"> |
|
282 <span class="submit"><input type="submit" name="install_comply" value="<?php echo ((strpos($id, 'hotfix_') !== 0) ? $lang_admin['Install extension'] : $lang_admin['Install hotfix']) ?>" /></span> |
|
283 <span class="cancel"><input type="submit" name="install_cancel" value="<?php echo $lang_admin['Cancel'] ?>" /></span> |
|
284 </div> |
|
285 </form> |
|
286 </div> |
|
287 |
|
288 </div> |
|
289 <?php |
|
290 |
|
291 require PUN_ROOT.'footer.php'; |
|
292 } |
|
293 |
|
294 |
|
295 // Uninstall an extension |
|
296 else if (isset($_GET['uninstall'])) |
|
297 { |
|
298 // User pressed the cancel button |
|
299 if (isset($_POST['uninstall_cancel'])) |
|
300 pun_redirect(pun_link($pun_url['admin_extensions_manage']), $lang_admin['Cancel redirect']); |
|
301 |
|
302 ($hook = get_hook('aex_uninstall_selected')) ? eval($hook) : null; |
|
303 |
|
304 $id = preg_replace('/[^0-9a-z_]/', '', $_GET['uninstall']); |
|
305 |
|
306 // Fetch info about the extension |
|
307 $query = array( |
|
308 'SELECT' => 'e.title, e.version, e.description, e.author, e.uninstall, e.uninstall_note', |
|
309 'FROM' => 'extensions AS e', |
|
310 'WHERE' => 'e.id=\''.$pun_db->escape($id).'\'' |
|
311 ); |
|
312 |
|
313 ($hook = get_hook('aex_qr_get_extension')) ? eval($hook) : null; |
|
314 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
315 if (!$pun_db->num_rows($result)) |
|
316 message($lang_common['Bad request']); |
|
317 |
|
318 $ext_data = $pun_db->fetch_assoc($result); |
|
319 |
|
320 // Setup breadcrumbs |
|
321 $pun_page['crumbs'] = array( |
|
322 array($pun_config['o_board_title'], pun_link($pun_url['index'])), |
|
323 array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), |
|
324 array($lang_admin['Manage extensions'], pun_link($pun_url['admin_extensions_manage'])), |
|
325 $lang_admin['Uninstall extension'] |
|
326 ); |
|
327 |
|
328 // If the user has confirmed the uninstall |
|
329 if (isset($_POST['uninstall_comply'])) |
|
330 { |
|
331 ($hook = get_hook('aex_uninstall_comply_form_submitted')) ? eval($hook) : null; |
|
332 |
|
333 $notices = array(); |
|
334 |
|
335 // Run uninstall code |
|
336 eval($ext_data['uninstall']); |
|
337 |
|
338 // Now delete the extension and its hooks from the db |
|
339 $query = array( |
|
340 'DELETE' => 'extension_hooks', |
|
341 'WHERE' => 'extension_id=\''.$pun_db->escape($id).'\'' |
|
342 ); |
|
343 |
|
344 ($hook = get_hook('aex_qr_delete_hooks')) ? eval($hook) : null; |
|
345 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
346 |
|
347 $query = array( |
|
348 'DELETE' => 'extensions', |
|
349 'WHERE' => 'id=\''.$pun_db->escape($id).'\'' |
|
350 ); |
|
351 |
|
352 ($hook = get_hook('aex_qr_delete_extension')) ? eval($hook) : null; |
|
353 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
354 |
|
355 // Empty the PHP cache |
|
356 $d = dir(PUN_CACHE_DIR); |
|
357 while (($entry = $d->read()) !== false) |
|
358 { |
|
359 if (substr($entry, strlen($entry)-4) == '.php') |
|
360 @unlink(PUN_CACHE_DIR.$entry); |
|
361 } |
|
362 $d->close(); |
|
363 |
|
364 // Regenerate the hooks cache |
|
365 require_once PUN_ROOT.'include/cache.php'; |
|
366 generate_hooks_cache(); |
|
367 |
|
368 // Display notices if there are any |
|
369 if (!empty($notices)) |
|
370 { |
|
371 ($hook = get_hook('aex_uninstall_notices_pre_header_load')) ? eval($hook) : null; |
|
372 |
|
373 define('PUN_PAGE_SECTION', 'extensions'); |
|
374 define('PUN_PAGE', 'admin-extensions-manage'); |
|
375 require PUN_ROOT.'header.php'; |
|
376 |
|
377 ?> |
|
378 <div id="pun-main" class="main sectioned admin"> |
|
379 |
|
380 <?php echo generate_admin_menu(); ?> |
|
381 |
|
382 <div class="main-head"> |
|
383 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
384 </div> |
|
385 |
|
386 <div class="main-content frm"> |
|
387 <div class="frm-head"> |
|
388 <h2><span><?php echo end($pun_page['crumbs']) ?> "<?php echo htmlspecialchars($ext_data['title']) ?>"</span></h2> |
|
389 </div> |
|
390 <div class="frm-info"> |
|
391 <p><?php echo $lang_admin['Extension uninstalled info'] ?></p> |
|
392 <ul> |
|
393 <?php |
|
394 |
|
395 while (list(, $cur_notice) = each($notices)) |
|
396 echo "\t\t\t\t".'<li><span>'.$cur_notice.'</span></li>'."\n"; |
|
397 |
|
398 ?> |
|
399 </ul> |
|
400 <p><a href="<?php echo pun_link($pun_url['admin_extensions_manage']) ?>"><?php echo $lang_admin['Manage extensions'] ?></a></p> |
|
401 </div> |
|
402 </div> |
|
403 |
|
404 </div> |
|
405 <?php |
|
406 |
|
407 require PUN_ROOT.'footer.php'; |
|
408 } |
|
409 else |
|
410 pun_redirect(pun_link($pun_url['admin_extensions_manage']), $lang_admin['Extension uninstalled'].' '.$lang_admin['Redirect']); |
|
411 } |
|
412 else // If the user hasn't confirmed the uninstall |
|
413 { |
|
414 ($hook = get_hook('aex_uninstall_pre_header_loaded')) ? eval($hook) : null; |
|
415 |
|
416 define('PUN_PAGE_SECTION', 'extensions'); |
|
417 define('PUN_PAGE', 'admin-extensions-manage'); |
|
418 require PUN_ROOT.'header.php'; |
|
419 |
|
420 ?> |
|
421 <div id="pun-main" class="main sectioned admin"> |
|
422 |
|
423 <?php echo generate_admin_menu(); ?> |
|
424 |
|
425 <div class="main-head"> |
|
426 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
427 </div> |
|
428 |
|
429 <div class="main-content frm"> |
|
430 <div class="frm-head"> |
|
431 <h2><span><?php echo end($pun_page['crumbs']) ?> "<?php echo htmlspecialchars($ext_data['title']) ?>"</span></h2> |
|
432 </div> |
|
433 <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $base_url ?>/admin/extensions.php?section=manage&uninstall=<?php echo $id ?>"> |
|
434 <div class="hidden"> |
|
435 <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($base_url.'/admin/extensions.php?section=manage&uninstall='.$id) ?>" /> |
|
436 </div> |
|
437 <div class="ext-item databox"> |
|
438 <h3 class="legend"><span><?php echo htmlspecialchars($ext_data['title']).((strpos($id, 'hotfix_') !== 0) ? ' v'.$ext_data['version'] : '') ?></span></h3> |
|
439 <p><span><?php printf($lang_admin['Extension by'], $ext_data['author']) ?></span><br /><span><?php echo htmlspecialchars($ext_data['description']) ?></span></p> |
|
440 <?php if ($ext_data['uninstall_note'] != ''): ?> <h4><?php echo $lang_admin['Uninstall note'] ?></h4> |
|
441 <p><?php echo htmlspecialchars($ext_data['uninstall_note']) ?></p> |
|
442 <?php endif; ?> </div> |
|
443 <div class="frm-info"> |
|
444 <p class="warn"><?php echo $lang_admin['Installed extensions warn'] ?></p> |
|
445 </div> |
|
446 <div class="frm-buttons"> |
|
447 <span class="submit"><input type="submit" class="button" name="uninstall_comply" value="<?php echo $lang_admin['Uninstall'] ?>" /></span> |
|
448 <span class="cancel"><input type="submit" class="button" name="uninstall_cancel" value="<?php echo $lang_admin['Cancel'] ?>" /></span> |
|
449 </div> |
|
450 </form> |
|
451 </div> |
|
452 |
|
453 </div> |
|
454 <?php |
|
455 |
|
456 require PUN_ROOT.'footer.php'; |
|
457 } |
|
458 } |
|
459 |
|
460 |
|
461 // Enable or disable an extension |
|
462 else if (isset($_GET['flip'])) |
|
463 { |
|
464 $id = preg_replace('/[^0-9a-z_]/', '', $_GET['flip']); |
|
465 |
|
466 // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid. |
|
467 // If it's in GET, we need to make sure it's valid. |
|
468 if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('flip'.$id))) |
|
469 csrf_confirm_form(); |
|
470 |
|
471 ($hook = get_hook('aex_flip_selected')) ? eval($hook) : null; |
|
472 |
|
473 // Fetch the current status of the extension |
|
474 $query = array( |
|
475 'SELECT' => 'e.disabled', |
|
476 'FROM' => 'extensions AS e', |
|
477 'WHERE' => 'e.id=\''.$pun_db->escape($id).'\'' |
|
478 ); |
|
479 |
|
480 ($hook = get_hook('aex_qr_get_disabled_status')) ? eval($hook) : null; |
|
481 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
482 if (!$pun_db->num_rows($result)) |
|
483 message($lang_common['Bad request']); |
|
484 |
|
485 // Are we disabling or enabling? |
|
486 $disable = $pun_db->result($result) == '0'; |
|
487 |
|
488 $query = array( |
|
489 'UPDATE' => 'extensions', |
|
490 'SET' => 'disabled='.($disable ? '1' : '0'), |
|
491 'WHERE' => 'id=\''.$pun_db->escape($id).'\'' |
|
492 ); |
|
493 |
|
494 ($hook = get_hook('aex_qr_update_disabled_status')) ? eval($hook) : null; |
|
495 $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
496 |
|
497 // Regenerate the hooks cache |
|
498 require_once PUN_ROOT.'include/cache.php'; |
|
499 generate_hooks_cache(); |
|
500 |
|
501 pun_redirect(pun_link($pun_url['admin_extensions_manage']), ($disable ? $lang_admin['Extension disabled'] : $lang_admin['Extension enabled']).' '.$lang_admin['Redirect']); |
|
502 } |
|
503 |
|
504 ($hook = get_hook('aex_new_action')) ? eval($hook) : null; |
|
505 |
|
506 |
|
507 // Generate an array of installed extensions |
|
508 $inst_exts = array(); |
|
509 $query = array( |
|
510 'SELECT' => 'e.*', |
|
511 'FROM' => 'extensions AS e', |
|
512 'ORDER BY' => 'e.title' |
|
513 ); |
|
514 |
|
515 ($hook = get_hook('aex_qr_get_all_extensions')) ? eval($hook) : null; |
|
516 $result = $pun_db->query_build($query) or error(__FILE__, __LINE__); |
|
517 while ($cur_ext = $pun_db->fetch_assoc($result)) |
|
518 $inst_exts[$cur_ext['id']] = $cur_ext; |
|
519 |
|
520 |
|
521 if ($section == 'install') |
|
522 { |
|
523 // Setup breadcrumbs |
|
524 $pun_page['crumbs'] = array( |
|
525 array($pun_config['o_board_title'], pun_link($pun_url['index'])), |
|
526 array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), |
|
527 $lang_admin['Install extensions'] |
|
528 ); |
|
529 |
|
530 ($hook = get_hook('aex_section_install_pre_header_load')) ? eval($hook) : null; |
|
531 |
|
532 define('PUN_PAGE_SECTION', 'extensions'); |
|
533 define('PUN_PAGE', 'admin-extensions-install'); |
|
534 |
|
535 require PUN_ROOT.'header.php'; |
|
536 |
|
537 ?> |
|
538 <div id="pun-main" class="main sectioned admin"> |
|
539 |
|
540 <?php echo generate_admin_menu(); ?> |
|
541 |
|
542 <div class="main-head"> |
|
543 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
544 </div> |
|
545 |
|
546 <div class="main-content frm"> |
|
547 <div class="frm-head"> |
|
548 <h2><span><?php echo $lang_admin['Extensions available'] ?></span></h2> |
|
549 </div> |
|
550 <?php |
|
551 |
|
552 $num_exts = 0; |
|
553 $num_failed = 0; |
|
554 $pun_page['item_num'] = 1; |
|
555 $pun_page['ext_item'] = array(); |
|
556 $pun_page['ext_error'] = array(); |
|
557 |
|
558 // Loop through any available hotfixes |
|
559 if (isset($pun_updates['hotfix'])) |
|
560 { |
|
561 // If there's only one hotfix, add one layer of arrays so we can foreach over it |
|
562 if (!is_array(current($pun_updates['hotfix']))) |
|
563 $pun_updates['hotfix'] = array($pun_updates['hotfix']); |
|
564 |
|
565 foreach ($pun_updates['hotfix'] as $hotfix) |
|
566 { |
|
567 if (!array_key_exists($hotfix['attributes']['id'], $inst_exts)) |
|
568 { |
|
569 $pun_page['ext_item'][] = '<div class="hotfix-item databox">'."\n\t\t\t".'<h3 class="legend"><span>'.htmlspecialchars($hotfix['content']).'</span></h3>'."\n\t\t\t".'<p><span>'.sprintf($lang_admin['Extension by'], 'PunBB').'</span><br /><span>'.$lang_admin['Hotfix description'].'</span></p>'."\n\t\t\t".'<p class="actions"><a href="'.$base_url.'/admin/extensions.php?install_hotfix='.urlencode($hotfix['attributes']['id']).'">'.$lang_admin['Install hotfix'].'</a></p>'."\n\t\t".'</div>'; |
|
570 ++$num_exts; |
|
571 } |
|
572 } |
|
573 } |
|
574 |
|
575 $d = dir(PUN_ROOT.'extensions'); |
|
576 while (($entry = $d->read()) !== false) |
|
577 { |
|
578 if ($entry{0} != '.' && is_dir(PUN_ROOT.'extensions/'.$entry)) |
|
579 { |
|
580 if (preg_match('/[^0-9a-z_]/', $entry)) |
|
581 { |
|
582 $pun_page['ext_error'][] = '<div class="ext-error databox db'.++$pun_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin['Extension loading error'], htmlspecialchars($entry)).'<span></h3>'."\n\t\t\t\t".'<p>'.$lang_admin['Illegal ID'].'</p>'."\n\t\t\t".'</div>'; |
|
583 ++$num_failed; |
|
584 continue; |
|
585 } |
|
586 else if (!file_exists(PUN_ROOT.'extensions/'.$entry.'/manifest.xml')) |
|
587 { |
|
588 $pun_page['ext_error'][] = '<div class="ext-error databox db'.++$pun_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin['Extension loading error'], htmlspecialchars($entry)).'<span></h3>'."\n\t\t\t\t".'<p>'.$lang_admin['Missing manifest'].'</p>'."\n\t\t\t".'</div>'; |
|
589 ++$num_failed; |
|
590 continue; |
|
591 } |
|
592 |
|
593 // Parse manifest.xml into an array |
|
594 $ext_data = xml_to_array(@file_get_contents(PUN_ROOT.'extensions/'.$entry.'/manifest.xml')); |
|
595 if (empty($ext_data)) |
|
596 { |
|
597 $pun_page['ext_error'][] = '<div class="ext-error databox db'.++$pun_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin['Extension loading error'], htmlspecialchars($entry)).'<span></h3>'."\n\t\t\t\t".'<p>'.$lang_admin['Failed parse manifest'].'</p>'."\n\t\t\t".'</div>'; |
|
598 ++$num_failed; |
|
599 continue; |
|
600 } |
|
601 |
|
602 // Validate manifest |
|
603 $errors = validate_manifest($ext_data, $entry); |
|
604 if (!empty($errors)) |
|
605 { |
|
606 $pun_page['ext_error'][] = '<div class="ext-error databox db'.++$pun_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin['Extension loading error'], htmlspecialchars($entry)).'</span></h3>'."\n\t\t\t\t".'<p>'.implode(' ', $errors).'</p>'."\n\t\t\t".'</div>'; |
|
607 ++$num_failed; |
|
608 } |
|
609 else |
|
610 { |
|
611 if (!array_key_exists($entry, $inst_exts) || version_compare($inst_exts[$entry]['version'], $ext_data['extension']['version'], '!=')) |
|
612 { |
|
613 $pun_page['ext_item'][] = '<div class="ext-item databox">'."\n\t\t\t".'<h3 class="legend"><span>'.htmlspecialchars($ext_data['extension']['title']).' v'.$ext_data['extension']['version'].'</span></h3>'."\n\t\t\t".'<p><span>'.sprintf($lang_admin['Extension by'], htmlspecialchars($ext_data['extension']['author'])).'</span>'.(($ext_data['extension']['description'] != '') ? '<br /><span>'.htmlspecialchars($ext_data['extension']['description']).'</span>' : '').'</p>'."\n\t\t\t".'<p class="actions"><a href="'.$base_url.'/admin/extensions.php?install='.urlencode($entry).'">'.$lang_admin['Install extension'].'</a></p>'."\n\t\t".'</div>'; |
|
614 ++$num_exts; |
|
615 } |
|
616 } |
|
617 } |
|
618 } |
|
619 $d->close(); |
|
620 |
|
621 ($hook = get_hook('aex_section_install_pre_display_ext_list')) ? eval($hook) : null; |
|
622 |
|
623 if ($num_exts) |
|
624 echo "\t\t".implode("\n\t\t", $pun_page['ext_item'])."\n"; |
|
625 else |
|
626 { |
|
627 |
|
628 ?> |
|
629 <div class="frm-info"> |
|
630 <p><?php echo $lang_admin['No available extensions'] ?></p> |
|
631 </div> |
|
632 <?php |
|
633 |
|
634 } |
|
635 |
|
636 // If any of the extensions had errors |
|
637 if ($num_failed) |
|
638 { |
|
639 |
|
640 ?> |
|
641 <div class="dataset"> |
|
642 <div class="ext-error databox db1"> |
|
643 <p class="important"><?php echo $lang_admin['Invalid extensions'] ?></p> |
|
644 </div> |
|
645 <?php echo implode("\n\t\t\t", $pun_page['ext_error'])."\n" ?> |
|
646 </div> |
|
647 <?php |
|
648 |
|
649 } |
|
650 |
|
651 ?> |
|
652 </div> |
|
653 |
|
654 </div> |
|
655 <?php |
|
656 |
|
657 require PUN_ROOT.'footer.php'; |
|
658 } |
|
659 else |
|
660 { |
|
661 // Setup breadcrumbs |
|
662 $pun_page['crumbs'] = array( |
|
663 array($pun_config['o_board_title'], pun_link($pun_url['index'])), |
|
664 array($lang_admin['Forum administration'], pun_link($pun_url['admin_index'])), |
|
665 $lang_admin['Manage extensions'] |
|
666 ); |
|
667 |
|
668 ($hook = get_hook('aex_section_manage_pre_header_load')) ? eval($hook) : null; |
|
669 |
|
670 define('PUN_PAGE_SECTION', 'extensions'); |
|
671 define('PUN_PAGE', 'admin-extensions-manage'); |
|
672 |
|
673 require PUN_ROOT.'header.php'; |
|
674 |
|
675 ?> |
|
676 <div id="pun-main" class="main sectioned admin"> |
|
677 |
|
678 <?php echo generate_admin_menu(); ?> |
|
679 |
|
680 <div class="main-head"> |
|
681 <h1><span>{ <?php echo end($pun_page['crumbs']) ?> }</span></h1> |
|
682 </div> |
|
683 |
|
684 <div class="main-content frm"> |
|
685 <div class="frm-head"> |
|
686 <h2><span><?php echo $lang_admin['Installed extensions'] ?></span></h2> |
|
687 </div> |
|
688 <?php |
|
689 |
|
690 if (!empty($inst_exts)) |
|
691 { |
|
692 |
|
693 ?> |
|
694 <div class="frm-info"> |
|
695 <p class="warn"><?php echo $lang_admin['Installed extensions warn'] ?></p> |
|
696 </div> |
|
697 <?php |
|
698 |
|
699 while (list($id, $ext) = @each($inst_exts)) |
|
700 { |
|
701 $pun_page['ext_actions'] = array( |
|
702 '<a href="'.$base_url.'/admin/extensions.php?section=manage&flip='.$id.'&csrf_token='.generate_form_token('flip'.$id).'">'.($ext['disabled'] != '1' ? $lang_admin['Disable'] : $lang_admin['Enable']).'</a>', |
|
703 '<a href="'.$base_url.'/admin/extensions.php?section=manage&uninstall='.$id.'">'.$lang_admin['Uninstall'].'</a>' |
|
704 ); |
|
705 |
|
706 ($hook = get_hook('aex_section_manage_pre_ext_actions')) ? eval($hook) : null; |
|
707 |
|
708 ?> |
|
709 <div class="ext-item databox<?php if ($ext['disabled'] == '1') echo ' extdisabled' ?>"> |
|
710 <h3 class="legend"><span><?php echo htmlspecialchars($ext['title']).((strpos($id, 'hotfix_') !== 0) ? ' v'.$ext['version'] : '') ?><?php if ($ext['disabled'] == '1') echo ' ( <span>'.$lang_admin['Extension disabled'].'</span> )' ?></span></h3> |
|
711 <p><span><?php printf($lang_admin['Extension by'], $ext['author']) ?></span><?php if ($ext['description'] != ''): ?><br /><span><?php echo htmlspecialchars($ext['description']) ?></span><?php endif; ?></p> |
|
712 <p class="actions"><?php echo implode('', $pun_page['ext_actions']) ?></p> |
|
713 </div> |
|
714 <?php |
|
715 |
|
716 } |
|
717 } |
|
718 else |
|
719 { |
|
720 |
|
721 ?> |
|
722 <div class="frm-info"> |
|
723 <p><?php echo $lang_admin['No installed extensions'] ?></p> |
|
724 </div> |
|
725 <?php |
|
726 |
|
727 } |
|
728 |
|
729 ?> |
|
730 </div> |
|
731 |
|
732 </div> |
|
733 <?php |
|
734 |
|
735 require PUN_ROOT.'footer.php'; |
|
736 } |
|
737 |
|
738 ($hook = get_hook('aex_end')) ? eval($hook) : null; |