PageRenderTime 44ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 1ms

/admin/extensions.php

https://bitbucket.org/gencer/punbb
PHP | 1103 lines | 801 code | 217 blank | 85 comment | 136 complexity | af653ad33a0f646d2953a015a6adc50a MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /**
  3. * Extension and hotfix management page.
  4. *
  5. * Allows administrators to control the extensions and hotfixes installed in the site.
  6. *
  7. * @copyright (C) 2008-2012 PunBB, partially based on code (C) 2008-2009 FluxBB.org
  8. * @license http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
  9. * @package PunBB
  10. */
  11. if (!defined('FORUM_ROOT'))
  12. define('FORUM_ROOT', '../');
  13. require FORUM_ROOT.'include/common.php';
  14. require FORUM_ROOT.'include/common_admin.php';
  15. if (!defined('FORUM_XML_FUNCTIONS_LOADED'))
  16. require FORUM_ROOT.'include/xml.php';
  17. ($hook = get_hook('aex_start')) ? eval($hook) : null;
  18. if ($forum_user['g_id'] != FORUM_ADMIN)
  19. message($lang_common['No permission']);
  20. // Load the admin.php language file
  21. require FORUM_ROOT.'lang/'.$forum_user['language'].'/admin_common.php';
  22. require FORUM_ROOT.'lang/'.$forum_user['language'].'/admin_ext.php';
  23. // Make sure we have XML support
  24. if (!function_exists('xml_parser_create'))
  25. message($lang_admin_ext['No XML support']);
  26. $section = isset($_GET['section']) ? $_GET['section'] : null;
  27. // Install an extension
  28. if (isset($_GET['install']) || isset($_GET['install_hotfix']))
  29. {
  30. ($hook = get_hook('aex_install_selected')) ? eval($hook) : null;
  31. // User pressed the cancel button
  32. if (isset($_POST['install_cancel']))
  33. redirect(forum_link(isset($_GET['install']) ? $forum_url['admin_extensions_manage'] : $forum_url['admin_extensions_hotfixes']), $lang_admin_common['Cancel redirect']);
  34. $id = preg_replace('/[^0-9a-z_]/', '', isset($_GET['install']) ? $_GET['install'] : $_GET['install_hotfix']);
  35. // Load manifest (either locally or from punbb.informer.com updates service)
  36. if (isset($_GET['install']))
  37. $manifest = is_readable(FORUM_ROOT.'extensions/'.$id.'/manifest.xml') ? file_get_contents(FORUM_ROOT.'extensions/'.$id.'/manifest.xml') : false;
  38. else
  39. {
  40. $remote_file = get_remote_file('http://punbb.informer.com/update/manifest/'.$id.'.xml', 16);
  41. if (!empty($remote_file['content']))
  42. $manifest = $remote_file['content'];
  43. }
  44. // Parse manifest.xml into an array and validate it
  45. $ext_data = xml_to_array($manifest);
  46. $errors = validate_manifest($ext_data, $id);
  47. /*
  48. * TODO
  49. * Errors must be fully specified instead "bad request" message only
  50. */
  51. if (!empty($errors))
  52. message(isset($_GET['install']) ? $lang_common['Bad request'] : $lang_admin_ext['Hotfix download failed']);
  53. // Get core amd major versions
  54. if (!defined('FORUM_DISABLE_EXTENSIONS_VERSION_CHECK'))
  55. {
  56. list($forum_version_core, $forum_version_major) = explode('.', clean_version($forum_config['o_cur_version']));
  57. list($extension_maxtestedon_version_core, $extension_maxtestedon_version_major) = explode('.', clean_version($ext_data['extension']['maxtestedon']));
  58. if (version_compare($forum_version_core.'.'.$forum_version_major, $extension_maxtestedon_version_core.'.'.$extension_maxtestedon_version_major, '>'))
  59. message($lang_admin_ext['Maxtestedon error']);
  60. }
  61. // Make sure we have an array of dependencies
  62. if (!isset($ext_data['extension']['dependencies']['dependency']))
  63. $ext_data['extension']['dependencies'] = array();
  64. else if (!is_array(current($ext_data['extension']['dependencies'])))
  65. $ext_data['extension']['dependencies'] = array($ext_data['extension']['dependencies']['dependency']);
  66. else
  67. $ext_data['extension']['dependencies'] = $ext_data['extension']['dependencies']['dependency'];
  68. $query = array(
  69. 'SELECT' => 'e.id, e.version',
  70. 'FROM' => 'extensions AS e',
  71. 'WHERE' => 'e.disabled=0'
  72. );
  73. ($hook = get_hook('aex_install_check_dependencies')) ? eval($hook) : null;
  74. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  75. $installed_ext = array();
  76. while ($row = $forum_db->fetch_assoc($result))
  77. $installed_ext[$row['id']] = $row;
  78. foreach ($ext_data['extension']['dependencies'] as $dependency)
  79. {
  80. $ext_dependancy_id = is_array($dependency) ? $dependency['content'] : $dependency;
  81. if (!array_key_exists($ext_dependancy_id, $installed_ext))
  82. {
  83. $errors[] = sprintf($lang_admin_ext['Missing dependency'], $ext_dependancy_id);
  84. }
  85. else if (is_array($dependency) AND isset($dependency['attributes']['minversion']) AND version_compare($dependency['attributes']['minversion'], $installed_ext[$ext_dependancy_id]['version']) > 0)
  86. {
  87. $errors[] = sprintf($lang_admin_ext['Version dependency error'], $dependency['content'], $dependency['attributes']['minversion']);
  88. }
  89. }
  90. // Setup breadcrumbs
  91. $forum_page['crumbs'] = array(
  92. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  93. array($lang_admin_common['Forum administration'], forum_link($forum_url['admin_index'])),
  94. array($lang_admin_common['Extensions'], forum_link($forum_url['admin_extensions_manage'])),
  95. array((strpos($id, 'hotfix_') === 0) ? $lang_admin_common['Manage hotfixes'] : $lang_admin_common['Manage extensions'], (strpos($id, 'hotfix_') === 0) ? forum_link($forum_url['admin_extensions_hotfixes']) : forum_link($forum_url['admin_extensions_manage'])),
  96. (strpos($id, 'hotfix_') === 0) ? $lang_admin_ext['Install hotfix'] : $lang_admin_ext['Install extension']
  97. );
  98. if (isset($_POST['install_comply']) AND empty($errors))
  99. {
  100. ($hook = get_hook('aex_install_comply_form_submitted')) ? eval($hook) : null;
  101. // $ext_info contains some information about the extension being installed
  102. $ext_info = array(
  103. 'id' => $id,
  104. 'path' => FORUM_ROOT.'extensions/'.$id,
  105. 'url' => $base_url.'/extensions/'.$id,
  106. 'dependencies' => array()
  107. );
  108. foreach ($ext_data['extension']['dependencies'] as $dependency)
  109. {
  110. $ext_info['dependencies'][$dependency] = array(
  111. 'id' => $dependency,
  112. 'path' => FORUM_ROOT.'extensions/'.$dependency,
  113. 'url' => $base_url.'/extensions/'.$dependency,
  114. );
  115. }
  116. // Is there some uninstall code to store in the db?
  117. $uninstall_code = (isset($ext_data['extension']['uninstall']) && forum_trim($ext_data['extension']['uninstall']) != '') ? '\''.$forum_db->escape(forum_trim($ext_data['extension']['uninstall'])).'\'' : 'NULL';
  118. // Is there an uninstall note to store in the db?
  119. $uninstall_note = 'NULL';
  120. foreach ($ext_data['extension']['note'] as $cur_note)
  121. {
  122. if ($cur_note['attributes']['type'] == 'uninstall' && forum_trim($cur_note['content']) != '')
  123. $uninstall_note = '\''.$forum_db->escape(forum_trim($cur_note['content'])).'\'';
  124. }
  125. $notices = array();
  126. // Is this a fresh install or an upgrade?
  127. $query = array(
  128. 'SELECT' => 'e.version',
  129. 'FROM' => 'extensions AS e',
  130. 'WHERE' => 'e.id=\''.$forum_db->escape($id).'\''
  131. );
  132. ($hook = get_hook('aex_install_comply_qr_get_current_ext_version')) ? eval($hook) : null;
  133. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  134. $ext_version = $forum_db->result($result);
  135. if (!is_null($ext_version) && $ext_version !== false)
  136. {
  137. // EXT_CUR_VERSION will be available to the extension install routine (to facilitate extension upgrades)
  138. define('EXT_CUR_VERSION', $ext_version);
  139. // Run the author supplied install code
  140. if (isset($ext_data['extension']['install']) && forum_trim($ext_data['extension']['install']) != '')
  141. eval($ext_data['extension']['install']);
  142. // Update the existing extension
  143. $query = array(
  144. 'UPDATE' => 'extensions',
  145. 'SET' => 'title=\''.$forum_db->escape($ext_data['extension']['title']).'\', version=\''.$forum_db->escape($ext_data['extension']['version']).'\', description=\''.$forum_db->escape($ext_data['extension']['description']).'\', author=\''.$forum_db->escape($ext_data['extension']['author']).'\', uninstall='.$uninstall_code.', uninstall_note='.$uninstall_note.', dependencies=\'|'.implode('|', $ext_data['extension']['dependencies']).'|\'',
  146. 'WHERE' => 'id=\''.$forum_db->escape($id).'\''
  147. );
  148. ($hook = get_hook('aex_install_comply_qr_update_ext')) ? eval($hook) : null;
  149. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  150. // Delete the old hooks
  151. $query = array(
  152. 'DELETE' => 'extension_hooks',
  153. 'WHERE' => 'extension_id=\''.$forum_db->escape($id).'\''
  154. );
  155. ($hook = get_hook('aex_install_comply_qr_update_ext_delete_hooks')) ? eval($hook) : null;
  156. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  157. }
  158. else
  159. {
  160. // Run the author supplied install code
  161. if (isset($ext_data['extension']['install']) && forum_trim($ext_data['extension']['install']) != '')
  162. eval($ext_data['extension']['install']);
  163. // Add the new extension
  164. $query = array(
  165. 'INSERT' => 'id, title, version, description, author, uninstall, uninstall_note, dependencies',
  166. 'INTO' => 'extensions',
  167. 'VALUES' => '\''.$forum_db->escape($ext_data['extension']['id']).'\', \''.$forum_db->escape($ext_data['extension']['title']).'\', \''.$forum_db->escape($ext_data['extension']['version']).'\', \''.$forum_db->escape($ext_data['extension']['description']).'\', \''.$forum_db->escape($ext_data['extension']['author']).'\', '.$uninstall_code.', '.$uninstall_note.', \'|'.implode('|', $ext_data['extension']['dependencies']).'|\'',
  168. );
  169. ($hook = get_hook('aex_install_comply_qr_add_ext')) ? eval($hook) : null;
  170. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  171. }
  172. // Now insert the hooks
  173. if (isset($ext_data['extension']['hooks']['hook']))
  174. {
  175. foreach ($ext_data['extension']['hooks']['hook'] as $ext_hook)
  176. {
  177. $cur_hooks = explode(',', $ext_hook['attributes']['id']);
  178. foreach ($cur_hooks as $cur_hook)
  179. {
  180. $query = array(
  181. 'INSERT' => 'id, extension_id, code, installed, priority',
  182. 'INTO' => 'extension_hooks',
  183. 'VALUES' => '\''.$forum_db->escape(forum_trim($cur_hook)).'\', \''.$forum_db->escape($id).'\', \''.$forum_db->escape(forum_trim($ext_hook['content'])).'\', '.time().', '.(isset($ext_hook['attributes']['priority']) ? $ext_hook['attributes']['priority'] : 5)
  184. );
  185. ($hook = get_hook('aex_install_comply_qr_add_hook')) ? eval($hook) : null;
  186. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  187. }
  188. }
  189. }
  190. // Empty the PHP cache
  191. forum_clear_cache();
  192. // Regenerate the hooks cache
  193. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  194. require FORUM_ROOT.'include/cache.php';
  195. generate_hooks_cache();
  196. // Display notices if there are any
  197. if (!empty($notices))
  198. {
  199. ($hook = get_hook('aex_install_notices_pre_header_load')) ? eval($hook) : null;
  200. define('FORUM_PAGE_SECTION', 'extensions');
  201. if (strpos($id, 'hotfix_') === 0)
  202. define('FORUM_PAGE', 'admin-extensions-hotfixes');
  203. else
  204. define('FORUM_PAGE', 'admin-extensions-manage');
  205. require FORUM_ROOT.'header.php';
  206. // START SUBST - <!-- forum_main -->
  207. ob_start();
  208. ($hook = get_hook('aex_install_notices_output_start')) ? eval($hook) : null;
  209. ?>
  210. <div class="main-subhead">
  211. <h2 class="hn"><span><?php echo end($forum_page['crumbs']) ?> "<?php echo forum_htmlencode($ext_data['extension']['title']) ?>"</span></h2>
  212. </div>
  213. <div class="main-content main-frm">
  214. <div class="ct-box info-box">
  215. <p><?php echo $lang_admin_ext['Extension installed info'] ?></p>
  216. <ul class="data-list">
  217. <?php
  218. foreach ($notices as $cur_notice)
  219. echo "\t\t\t\t".'<li><span>'.$cur_notice.'</span></li>'."\n";
  220. ?>
  221. </ul>
  222. <p><a href="<?php echo forum_link($forum_url['admin_extensions_manage']) ?>"><?php echo $lang_admin_common['Manage extensions'] ?></a></p>
  223. </div>
  224. </div>
  225. <?php
  226. ($hook = get_hook('aex_install_notices_end')) ? eval($hook) : null;
  227. $tpl_temp = forum_trim(ob_get_contents());
  228. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  229. ob_end_clean();
  230. // END SUBST - <!-- forum_main -->
  231. require FORUM_ROOT.'footer.php';
  232. }
  233. else
  234. {
  235. // Add flash message
  236. if (strpos($id, 'hotfix_') === 0)
  237. $forum_flash->add_info($lang_admin_ext['Hotfix installed']);
  238. else
  239. $forum_flash->add_info($lang_admin_ext['Extension installed']);
  240. ($hook = get_hook('aex_install_comply_pre_redirect')) ? eval($hook) : null;
  241. if (strpos($id, 'hotfix_') === 0)
  242. redirect(forum_link($forum_url['admin_extensions_hotfixes']), $lang_admin_ext['Hotfix installed']);
  243. else
  244. redirect(forum_link($forum_url['admin_extensions_manage']), $lang_admin_ext['Extension installed']);
  245. }
  246. }
  247. ($hook = get_hook('aex_install_pre_header_load')) ? eval($hook) : null;
  248. define('FORUM_PAGE_SECTION', 'extensions');
  249. if (strpos($id, 'hotfix_') === 0)
  250. define('FORUM_PAGE', 'admin-extensions-hotfixes');
  251. else
  252. define('FORUM_PAGE', 'admin-extensions-manage');
  253. require FORUM_ROOT.'header.php';
  254. // START SUBST - <!-- forum_main -->
  255. ob_start();
  256. ($hook = get_hook('aex_install_output_start')) ? eval($hook) : null;
  257. ?>
  258. <div class="main-subhead">
  259. <h2 class="hn"><span><?php echo end($forum_page['crumbs']) ?> "<?php echo forum_htmlencode($ext_data['extension']['title']) ?>"</span></h2>
  260. </div>
  261. <div class="main-content main-frm">
  262. <?php
  263. // If there were any errors, show them
  264. if (!empty($errors))
  265. {
  266. $forum_page['errors'] = array();
  267. foreach ($errors as $cur_error)
  268. $forum_page['errors'][] = '<li class="warn"><span>'.$cur_error.'</span></li>';
  269. ($hook = get_hook('aex_install_ext_pre_errors')) ? eval($hook) : null;
  270. ?>
  271. <div class="ct-box error-box">
  272. <h2 class="warn hn"><?php echo $lang_admin_ext['Install ext errors'] ?></h2>
  273. <ul class="error-list">
  274. <?php echo implode("\n\t\t\t\t", $forum_page['errors'])."\n" ?>
  275. </ul>
  276. </div>
  277. <?php
  278. }
  279. ?>
  280. <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 ?>">
  281. <div class="hidden">
  282. <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($base_url.'/admin/extensions.php'.(isset($_GET['install']) ? '?install=' : '?install_hotfix=').$id) ?>" />
  283. </div>
  284. <div class="ct-group data-group">
  285. <div class="ct-set data-set set1">
  286. <div class="ct-box data-box">
  287. <h3 class="ct-legend hn"><span><?php echo forum_htmlencode($ext_data['extension']['title']) ?></span></h3>
  288. <p><?php echo ((strpos($id, 'hotfix_') !== 0) ? sprintf($lang_admin_ext['Version'], $ext_data['extension']['version']) : $lang_admin_ext['Hotfix']) ?></p>
  289. <p><?php printf($lang_admin_ext['Extension by'], forum_htmlencode($ext_data['extension']['author'])) ?></p>
  290. <p><?php echo forum_htmlencode($ext_data['extension']['description']) ?></p>
  291. </div>
  292. </div>
  293. </div>
  294. <?php
  295. // Setup an array of warnings to display in the form
  296. $form_warnings = array();
  297. $forum_page['num_items'] = 0;
  298. foreach ($ext_data['extension']['note'] as $cur_note)
  299. {
  300. if ($cur_note['attributes']['type'] == 'install')
  301. $form_warnings[] = '<li>'.forum_htmlencode($cur_note['content']).'</li>';
  302. }
  303. if (version_compare(clean_version($forum_config['o_cur_version']), clean_version($ext_data['extension']['maxtestedon']), '>'))
  304. $form_warnings[] = '<li>'.$lang_admin_ext['Maxtestedon warning'].'</li>';
  305. if (!empty($form_warnings))
  306. {
  307. ?> <div class="ct-box warn-box">
  308. <p class="important"><strong><?php echo $lang_admin_ext['Install note'] ?></strong></p>
  309. <ol class="info-list">
  310. <?php
  311. echo implode("\n\t\t\t\t\t", $form_warnings)."\n";
  312. ?>
  313. </ol>
  314. </div>
  315. <?php
  316. }
  317. ?> <div class="frm-buttons">
  318. <span class="submit primary"><input type="submit" name="install_comply" value="<?php echo ((strpos($id, 'hotfix_') !== 0) ? $lang_admin_ext['Install extension'] : $lang_admin_ext['Install hotfix']) ?>" /></span>
  319. <span class="cancel"><input type="submit" name="install_cancel" value="<?php echo $lang_admin_common['Cancel'] ?>" /></span>
  320. </div>
  321. </form>
  322. </div>
  323. <?php
  324. ($hook = get_hook('aex_install_end')) ? eval($hook) : null;
  325. $tpl_temp = forum_trim(ob_get_contents());
  326. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  327. ob_end_clean();
  328. // END SUBST - <!-- forum_main -->
  329. require FORUM_ROOT.'footer.php';
  330. }
  331. // Uninstall an extension
  332. else if (isset($_GET['uninstall']))
  333. {
  334. // User pressed the cancel button
  335. if (isset($_POST['uninstall_cancel']))
  336. redirect(forum_link($forum_url['admin_extensions_manage']), $lang_admin_common['Cancel redirect']);
  337. ($hook = get_hook('aex_uninstall_selected')) ? eval($hook) : null;
  338. $id = preg_replace('/[^0-9a-z_]/', '', $_GET['uninstall']);
  339. // Fetch info about the extension
  340. $query = array(
  341. 'SELECT' => 'e.title, e.version, e.description, e.author, e.uninstall, e.uninstall_note',
  342. 'FROM' => 'extensions AS e',
  343. 'WHERE' => 'e.id=\''.$forum_db->escape($id).'\''
  344. );
  345. ($hook = get_hook('aex_uninstall_qr_get_extension')) ? eval($hook) : null;
  346. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  347. $ext_data = $forum_db->fetch_assoc($result);
  348. if (!$ext_data)
  349. {
  350. message($lang_common['Bad request']);
  351. }
  352. // Check dependancies
  353. $query = array(
  354. 'SELECT' => 'e.id',
  355. 'FROM' => 'extensions AS e',
  356. 'WHERE' => 'e.dependencies LIKE \'%|'.$forum_db->escape($id).'|%\''
  357. );
  358. ($hook = get_hook('aex_uninstall_qr_check_dependencies')) ? eval($hook) : null;
  359. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  360. $dependency = $forum_db->fetch_assoc($result);
  361. if (!is_null($dependency) && $dependency !== false)
  362. {
  363. message(sprintf($lang_admin_ext['Uninstall dependency'], $dependency['id']));
  364. }
  365. // Setup breadcrumbs
  366. $forum_page['crumbs'] = array(
  367. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  368. array($lang_admin_common['Forum administration'], forum_link($forum_url['admin_index'])),
  369. array($lang_admin_common['Extensions'], forum_link($forum_url['admin_extensions_manage'])),
  370. array((strpos($id, 'hotfix_') === 0) ? $lang_admin_common['Manage hotfixes'] : $lang_admin_common['Manage extensions'], (strpos($id, 'hotfix_') === 0) ? forum_link($forum_url['admin_extensions_hotfixes']) : forum_link($forum_url['admin_extensions_manage'])),
  371. (strpos($id, 'hotfix_') === 0) ? $lang_admin_ext['Uninstall hotfix'] : $lang_admin_ext['Uninstall extension']
  372. );
  373. // If the user has confirmed the uninstall
  374. if (isset($_POST['uninstall_comply']))
  375. {
  376. ($hook = get_hook('aex_uninstall_comply_form_submitted')) ? eval($hook) : null;
  377. $ext_info = array(
  378. 'id' => $id,
  379. 'path' => FORUM_ROOT.'extensions/'.$id,
  380. 'url' => $base_url.'/extensions/'.$id
  381. );
  382. $notices = array();
  383. // Run uninstall code
  384. eval($ext_data['uninstall']);
  385. // Now delete the extension and its hooks from the db
  386. $query = array(
  387. 'DELETE' => 'extension_hooks',
  388. 'WHERE' => 'extension_id=\''.$forum_db->escape($id).'\''
  389. );
  390. ($hook = get_hook('aex_uninstall_comply_qr_uninstall_delete_hooks')) ? eval($hook) : null;
  391. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  392. $query = array(
  393. 'DELETE' => 'extensions',
  394. 'WHERE' => 'id=\''.$forum_db->escape($id).'\''
  395. );
  396. ($hook = get_hook('aex_uninstall_comply_qr_delete_extension')) ? eval($hook) : null;
  397. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  398. // Empty the PHP cache
  399. forum_clear_cache();
  400. // Regenerate the hooks cache
  401. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  402. require FORUM_ROOT.'include/cache.php';
  403. generate_hooks_cache();
  404. // Display notices if there are any
  405. if (!empty($notices))
  406. {
  407. ($hook = get_hook('aex_uninstall_notices_pre_header_load')) ? eval($hook) : null;
  408. define('FORUM_PAGE_SECTION', 'extensions');
  409. define('FORUM_PAGE', 'admin-extensions-manage');
  410. require FORUM_ROOT.'header.php';
  411. // START SUBST - <!-- forum_main -->
  412. ob_start();
  413. ($hook = get_hook('aex_uninstall_notices_output_start')) ? eval($hook) : null;
  414. ?>
  415. <div class="main-subhead">
  416. <h2 class="hn"><span><?php echo end($forum_page['crumbs']) ?> "<?php echo forum_htmlencode($ext_data['title']) ?>"</span></h2>
  417. </div>
  418. <div class="main-content main-frm">
  419. <div class="ct-box info-box">
  420. <p><?php echo $lang_admin_ext['Extension uninstalled info'] ?></p>
  421. <ul class="info-list">
  422. <?php
  423. foreach ($notices as $cur_notice)
  424. echo "\t\t\t\t".'<li><span>'.$cur_notice.'</span></li>'."\n";
  425. ?>
  426. </ul>
  427. <p><a href="<?php echo forum_link($forum_url['admin_extensions_manage']) ?>"><?php echo $lang_admin_common['Manage extensions'] ?></a></p>
  428. </div>
  429. </div>
  430. <?php
  431. ($hook = get_hook('aex_uninstall_notices_end')) ? eval($hook) : null;
  432. $tpl_temp = forum_trim(ob_get_contents());
  433. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  434. ob_end_clean();
  435. // END SUBST - <!-- forum_main -->
  436. require FORUM_ROOT.'footer.php';
  437. }
  438. else
  439. {
  440. // Add flash message
  441. if (strpos($id, 'hotfix_') === 0)
  442. $forum_flash->add_info($lang_admin_ext['Hotfix uninstalled']);
  443. else
  444. $forum_flash->add_info($lang_admin_ext['Extension uninstalled']);
  445. ($hook = get_hook('aex_uninstall_comply_pre_redirect')) ? eval($hook) : null;
  446. if (strpos($id, 'hotfix_') === 0)
  447. redirect(forum_link($forum_url['admin_extensions_hotfixes']), $lang_admin_ext['Hotfix uninstalled']);
  448. else
  449. redirect(forum_link($forum_url['admin_extensions_manage']), $lang_admin_ext['Extension uninstalled']);
  450. }
  451. }
  452. else // If the user hasn't confirmed the uninstall
  453. {
  454. ($hook = get_hook('aex_uninstall_pre_header_load')) ? eval($hook) : null;
  455. define('FORUM_PAGE_SECTION', 'extensions');
  456. if (strpos($id, 'hotfix_') === 0)
  457. define('FORUM_PAGE', 'admin-extensions-hotfixes');
  458. else
  459. define('FORUM_PAGE', 'admin-extensions-manage');
  460. require FORUM_ROOT.'header.php';
  461. // START SUBST - <!-- forum_main -->
  462. ob_start();
  463. ($hook = get_hook('aex_uninstall_output_start')) ? eval($hook) : null;
  464. ?>
  465. <div class="main-subhead">
  466. <h2 class="hn"><span><?php echo end($forum_page['crumbs']) ?> "<?php echo forum_htmlencode($ext_data['title']) ?>"</span></h2>
  467. </div>
  468. <div class="main-content main-frm">
  469. <form class="frm-form" method="post" accept-charset="utf-8" action="<?php echo $base_url ?>/admin/extensions.php?section=manage&amp;uninstall=<?php echo $id ?>">
  470. <div class="hidden">
  471. <input type="hidden" name="csrf_token" value="<?php echo generate_form_token($base_url.'/admin/extensions.php?section=manage&amp;uninstall='.$id) ?>" />
  472. </div>
  473. <div class="ct-group data-group">
  474. <div class="ct-set data-set set1">
  475. <div class="ct-box data-box">
  476. <h3 class="ct-legend hn"><span><?php echo forum_htmlencode($ext_data['title']) ?></span></h3>
  477. <p><?php echo ((strpos($id, 'hotfix_') !== 0) ? sprintf($lang_admin_ext['Version'], $ext_data['version']) : $lang_admin_ext['Hotfix']) ?></p>
  478. <p><?php printf($lang_admin_ext['Extension by'], forum_htmlencode($ext_data['author'])) ?></p>
  479. <p><?php echo forum_htmlencode($ext_data['description']) ?></p>
  480. </div>
  481. </div>
  482. </div>
  483. <?php if ($ext_data['uninstall_note'] != ''): ?> <div class="ct-box warn-box">
  484. <p class="important"><strong><?php echo $lang_admin_ext['Uninstall note'] ?></strong></p>
  485. <p><?php echo forum_htmlencode($ext_data['uninstall_note']) ?></p>
  486. </div>
  487. <?php endif; ?>
  488. <?php if (strpos($id, 'hotfix_') !== 0): ?> <div class="ct-box warn-box">
  489. <p class="warn"><?php echo $lang_admin_ext['Installed extensions warn'] ?></p>
  490. </div>
  491. <?php endif; ?> <div class="frm-buttons">
  492. <span class="submit primary caution"><input type="submit" name="uninstall_comply" value="<?php echo $lang_admin_ext['Uninstall'] ?>" /></span>
  493. <span class="cancel"><input type="submit" name="uninstall_cancel" value="<?php echo $lang_admin_common['Cancel'] ?>" /></span>
  494. </div>
  495. </form>
  496. </div>
  497. <?php
  498. ($hook = get_hook('aex_uninstall_end')) ? eval($hook) : null;
  499. $tpl_temp = forum_trim(ob_get_contents());
  500. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  501. ob_end_clean();
  502. // END SUBST - <!-- forum_main -->
  503. require FORUM_ROOT.'footer.php';
  504. }
  505. }
  506. // Enable or disable an extension
  507. else if (isset($_GET['flip']))
  508. {
  509. $id = preg_replace('/[^0-9a-z_]/', '', $_GET['flip']);
  510. // We validate the CSRF token. If it's set in POST and we're at this point, the token is valid.
  511. // If it's in GET, we need to make sure it's valid.
  512. if (!isset($_POST['csrf_token']) && (!isset($_GET['csrf_token']) || $_GET['csrf_token'] !== generate_form_token('flip'.$id)))
  513. csrf_confirm_form();
  514. ($hook = get_hook('aex_flip_selected')) ? eval($hook) : null;
  515. // Fetch the current status of the extension
  516. $query = array(
  517. 'SELECT' => 'e.disabled',
  518. 'FROM' => 'extensions AS e',
  519. 'WHERE' => 'e.id=\''.$forum_db->escape($id).'\''
  520. );
  521. ($hook = get_hook('aex_flip_qr_get_disabled_status')) ? eval($hook) : null;
  522. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  523. $ext_status = $forum_db->result($result);
  524. // No rows
  525. if (is_null($ext_status) || $ext_status === false)
  526. {
  527. message($lang_common['Bad request']);
  528. }
  529. // Are we disabling or enabling?
  530. $disable = $ext_status == '0';
  531. // Check dependancies
  532. if ($disable)
  533. {
  534. $query = array(
  535. 'SELECT' => 'e.id',
  536. 'FROM' => 'extensions AS e',
  537. 'WHERE' => 'e.disabled=0 AND e.dependencies LIKE \'%|'.$forum_db->escape($id).'|%\''
  538. );
  539. ($hook = get_hook('aex_flip_qr_get_disable_dependencies')) ? eval($hook) : null;
  540. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  541. $dependency = $forum_db->fetch_assoc($result);
  542. if (!is_null($dependency) && $dependency !== false)
  543. {
  544. message(sprintf($lang_admin_ext['Disable dependency'], $dependency['id']));
  545. }
  546. }
  547. else
  548. {
  549. $query = array(
  550. 'SELECT' => 'e.dependencies',
  551. 'FROM' => 'extensions AS e',
  552. 'WHERE' => 'e.id=\''.$forum_db->escape($id).'\''
  553. );
  554. ($hook = get_hook('aex_flip_qr_get_enable_dependencies')) ? eval($hook) : null;
  555. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  556. $dependencies = $forum_db->fetch_assoc($result);
  557. $dependencies = explode('|', substr($dependencies['dependencies'], 1, -1));
  558. $query = array(
  559. 'SELECT' => 'e.id',
  560. 'FROM' => 'extensions AS e',
  561. 'WHERE' => 'e.disabled=0'
  562. );
  563. ($hook = get_hook('aex_flip_qr_check_dependencies')) ? eval($hook) : null;
  564. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  565. $installed_ext = array();
  566. while ($row = $forum_db->fetch_assoc($result))
  567. $installed_ext[] = $row['id'];
  568. foreach ($dependencies as $dependency)
  569. {
  570. if (!empty($dependency) && !in_array($dependency, $installed_ext))
  571. message(sprintf($lang_admin_ext['Disabled dependency'], $dependency));
  572. }
  573. }
  574. $query = array(
  575. 'UPDATE' => 'extensions',
  576. 'SET' => 'disabled='.($disable ? '1' : '0'),
  577. 'WHERE' => 'id=\''.$forum_db->escape($id).'\''
  578. );
  579. ($hook = get_hook('aex_flip_qr_update_disabled_status')) ? eval($hook) : null;
  580. $forum_db->query_build($query) or error(__FILE__, __LINE__);
  581. // Regenerate the hooks cache
  582. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  583. require FORUM_ROOT.'include/cache.php';
  584. generate_hooks_cache();
  585. // Add flash message
  586. if ($section == 'hotfixes')
  587. $forum_flash->add_info(($disable ? $lang_admin_ext['Hotfix disabled'] : $lang_admin_ext['Hotfix enabled']));
  588. else
  589. $forum_flash->add_info(($disable ? $lang_admin_ext['Extension disabled'] : $lang_admin_ext['Extension enabled']));
  590. ($hook = get_hook('aex_flip_pre_redirect')) ? eval($hook) : null;
  591. if ($section == 'hotfixes')
  592. redirect(forum_link($forum_url['admin_extensions_hotfixes']), ($disable ? $lang_admin_ext['Hotfix disabled'] : $lang_admin_ext['Hotfix enabled']));
  593. else
  594. redirect(forum_link($forum_url['admin_extensions_manage']), ($disable ? $lang_admin_ext['Extension disabled'] : $lang_admin_ext['Extension enabled']));
  595. }
  596. ($hook = get_hook('aex_new_action')) ? eval($hook) : null;
  597. // Generate an array of installed extensions
  598. $inst_exts = array();
  599. $query = array(
  600. 'SELECT' => 'e.*',
  601. 'FROM' => 'extensions AS e',
  602. 'ORDER BY' => 'e.title'
  603. );
  604. ($hook = get_hook('aex_qr_get_all_extensions')) ? eval($hook) : null;
  605. $result = $forum_db->query_build($query) or error(__FILE__, __LINE__);
  606. while ($cur_ext = $forum_db->fetch_assoc($result))
  607. $inst_exts[$cur_ext['id']] = $cur_ext;
  608. // Hotfixes list
  609. if ($section == 'hotfixes')
  610. {
  611. // Setup breadcrumbs
  612. $forum_page['crumbs'] = array(
  613. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  614. array($lang_admin_common['Forum administration'], forum_link($forum_url['admin_index'])),
  615. array($lang_admin_common['Extensions'], forum_link($forum_url['admin_extensions_manage'])),
  616. array($lang_admin_common['Manage hotfixes'], forum_link($forum_url['admin_extensions_hotfixes']))
  617. );
  618. ($hook = get_hook('aex_section_hotfixes_pre_header_load')) ? eval($hook) : null;
  619. define('FORUM_PAGE_SECTION', 'extensions');
  620. define('FORUM_PAGE', 'admin-extensions-hotfixes');
  621. require FORUM_ROOT.'header.php';
  622. // START SUBST - <!-- forum_main -->
  623. ob_start();
  624. ($hook = get_hook('aex_section_hotfixes_output_start')) ? eval($hook) : null;
  625. ?>
  626. <div class="main-subhead">
  627. <h2 class="hn"><span><?php echo $lang_admin_ext['Hotfixes available'] ?></span></h2>
  628. </div>
  629. <div class="main-content main-hotfixes">
  630. <?php
  631. $num_exts = 0;
  632. $num_failed = 0;
  633. $forum_page['item_num'] = 1;
  634. $forum_page['ext_item'] = array();
  635. $forum_page['ext_error'] = array();
  636. // Loop through any available hotfixes
  637. if (isset($forum_updates['hotfix']))
  638. {
  639. // If there's only one hotfix, add one layer of arrays so we can foreach over it
  640. if (!is_array(current($forum_updates['hotfix'])))
  641. $forum_updates['hotfix'] = array($forum_updates['hotfix']);
  642. foreach ($forum_updates['hotfix'] as $hotfix)
  643. {
  644. if (!array_key_exists($hotfix['attributes']['id'], $inst_exts))
  645. {
  646. $forum_page['ext_item'][] = '<div class="ct-box info-box hotfix available">'."\n\t\t\t".'<h3 class="ct-legend hn">'.forum_htmlencode($hotfix['content']).'</h3>'."\n\t\t\t".'<ul>'."\n\t\t\t\t".'<li><span>'.sprintf($lang_admin_ext['Extension by'], 'PunBB').'</span></li>'."\n\t\t\t\t".'<li><span>'.$lang_admin_ext['Hotfix description'].'</span></li>'."\n\t\t\t".'</ul>'."\n\t\t\t\t".'<p class="options"><span class="first-item"><a href="'.$base_url.'/admin/extensions.php?install_hotfix='.urlencode($hotfix['attributes']['id']).'">'.$lang_admin_ext['Install hotfix'].'</a></span></p>'."\n\t\t".'</div>';
  647. ++$num_exts;
  648. }
  649. }
  650. }
  651. ($hook = get_hook('aex_section_hotfixes_pre_display_available_ext_list')) ? eval($hook) : null;
  652. if ($num_exts)
  653. echo "\t\t".implode("\n\t\t", $forum_page['ext_item'])."\n";
  654. else
  655. {
  656. ?>
  657. <div class="ct-box info-box">
  658. <p><?php echo $lang_admin_ext['No available hotfixes'] ?></p>
  659. </div>
  660. <?php
  661. }
  662. ?>
  663. </div>
  664. <?php
  665. ($hook = get_hook('aex_section_hotfixes_pre_display_installed_ext_list')) ? eval($hook) : null;
  666. ?>
  667. <div class="main-subhead">
  668. <h2 class="hn"><span><?php echo $lang_admin_ext['Installed hotfixes'] ?></span></h2>
  669. </div>
  670. <div class="main-content main-hotfixes">
  671. <?php
  672. $installed_count = 0;
  673. foreach ($inst_exts as $id => $ext)
  674. {
  675. if (strpos($id, 'hotfix_') !== 0)
  676. continue;
  677. $forum_page['ext_actions'] = array(
  678. 'flip' => '<span class="first-item"><a href="'.$base_url.'/admin/extensions.php?section=hotfixes&amp;flip='.$id.'&amp;csrf_token='.generate_form_token('flip'.$id).'">'.($ext['disabled'] != '1' ? $lang_admin_ext['Disable'] : $lang_admin_ext['Enable']).'</a></span>',
  679. 'uninstall' => '<span><a href="'.$base_url.'/admin/extensions.php?section=hotfixese&amp;uninstall='.$id.'">'.$lang_admin_ext['Uninstall'].'</a></span>'
  680. );
  681. ($hook = get_hook('aex_section_hotfixes_pre_ext_actions')) ? eval($hook) : null;
  682. ?>
  683. <div class="ct-box info-box hotfix <?php echo $ext['disabled'] == '1' ? 'disabled' : 'enabled' ?>">
  684. <h3 class="ct-legend hn"><span><?php echo forum_htmlencode($ext['title']) ?><?php if ($ext['disabled'] == '1') echo ' ( <span>'.$lang_admin_ext['Extension disabled'].'</span> )' ?></span></h3>
  685. <ul class="data-list">
  686. <li><span><?php echo ((strpos($id, 'hotfix_') !== 0) ? sprintf($lang_admin_ext['Version'], $ext['version']) : $lang_admin_ext['Hotfix']) ?></span></li>
  687. <li><span><?php printf($lang_admin_ext['Extension by'], forum_htmlencode($ext['author'])) ?></span></li>
  688. <?php if ($ext['description'] != ''): ?>
  689. <li><span><?php echo forum_htmlencode($ext['description']) ?></span></li>
  690. <?php endif; ?>
  691. </ul>
  692. <p class="options"><?php echo implode(' ', $forum_page['ext_actions']) ?></p>
  693. </div>
  694. <?php
  695. $installed_count++;
  696. }
  697. if ($installed_count == 0)
  698. {
  699. ?>
  700. <div class="ct-box info-box">
  701. <p><?php echo $lang_admin_ext['No installed hotfixes'] ?></p>
  702. </div>
  703. <?php
  704. }
  705. ?>
  706. </div>
  707. <?php
  708. ($hook = get_hook('aex_section_hotfixes_end')) ? eval($hook) : null;
  709. $tpl_temp = forum_trim(ob_get_contents());
  710. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  711. ob_end_clean();
  712. // END SUBST - <!-- forum_main -->
  713. require FORUM_ROOT.'footer.php';
  714. }
  715. // Extensions list
  716. else
  717. {
  718. if ($forum_config['o_check_for_versions'] == 1)
  719. {
  720. // Check for the new versions of the extensions istalled
  721. $repository_urls = array(FORUM_PUN_EXTENSION_REPOSITORY_URL);
  722. ($hook = get_hook('aex_add_extensions_repository')) ? eval($hook) : null;
  723. $repository_url_by_extension = array();
  724. foreach (array_keys($inst_exts) as $id)
  725. ($hook = get_hook('aex_add_repository_for_'.$id)) ? eval($hook) : null;
  726. if (is_readable(FORUM_CACHE_DIR.'cache_ext_version_notifications.php'))
  727. include FORUM_CACHE_DIR.'cache_ext_version_notifications.php';
  728. // Get latest timestamp in cache
  729. if (isset($forum_ext_repos))
  730. {
  731. $min_timestamp = 10000000000;
  732. foreach ($forum_ext_repos as $rep)
  733. $min_timestamp = min($min_timestamp, $rep['timestamp']);
  734. }
  735. $update_hour = (isset($forum_ext_versions_update_cache) && (time() - $forum_ext_versions_update_cache > 60 * 60));
  736. // Update last versions if there is no cahe or some extension was added/removed or one day has gone since last update
  737. $update_new_versions_cache = !defined('FORUM_EXT_VERSIONS_LOADED') || (isset($forum_ext_last_versions) && array_diff(array_keys($inst_exts), array_keys($forum_ext_last_versions)) != array()) || $update_hour || ($update_hour && isset($min_timestamp) && (time() - $min_timestamp > 60*60*24));
  738. ($hook = get_hook('aex_before_update_checking')) ? eval($hook) : null;
  739. if ($update_new_versions_cache)
  740. {
  741. if (!defined('FORUM_CACHE_FUNCTIONS_LOADED'))
  742. require_once FORUM_ROOT.'include/cache.php';
  743. generate_ext_versions_cache($inst_exts, $repository_urls, $repository_url_by_extension);
  744. include FORUM_CACHE_DIR.'cache_ext_version_notifications.php';
  745. }
  746. }
  747. // Setup breadcrumbs
  748. $forum_page['crumbs'] = array(
  749. array($forum_config['o_board_title'], forum_link($forum_url['index'])),
  750. array($lang_admin_common['Forum administration'], forum_link($forum_url['admin_index'])),
  751. array($lang_admin_common['Extensions'], forum_link($forum_url['admin_extensions_manage'])),
  752. array($lang_admin_common['Manage extensions'], forum_link($forum_url['admin_extensions_manage']))
  753. );
  754. ($hook = get_hook('aex_section_manage_pre_header_load')) ? eval($hook) : null;
  755. define('FORUM_PAGE_SECTION', 'extensions');
  756. define('FORUM_PAGE', 'admin-extensions-manage');
  757. require FORUM_ROOT.'header.php';
  758. // START SUBST - <!-- forum_main -->
  759. ob_start();
  760. ($hook = get_hook('aex_section_install_output_start')) ? eval($hook) : null;
  761. ?>
  762. <div class="main-subhead">
  763. <h2 class="hn"><span><?php echo $lang_admin_ext['Extensions available'] ?></span></h2>
  764. </div>
  765. <div class="main-content main-extensions">
  766. <?php
  767. $num_exts = 0;
  768. $num_failed = 0;
  769. $forum_page['item_num'] = 1;
  770. $forum_page['ext_item'] = array();
  771. $forum_page['ext_error'] = array();
  772. $d = dir(FORUM_ROOT.'extensions');
  773. while (($entry = $d->read()) !== false)
  774. {
  775. if ($entry{0} != '.' && is_dir(FORUM_ROOT.'extensions/'.$entry))
  776. {
  777. if (preg_match('/[^0-9a-z_]/', $entry))
  778. {
  779. $forum_page['ext_error'][] = '<div class="ext-error databox db'.++$forum_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)).'</span></h3>'."\n\t\t\t\t".'<p>'.$lang_admin_ext['Illegal ID'].'</p>'."\n\t\t\t".'</div>';
  780. ++$num_failed;
  781. continue;
  782. }
  783. else if (!file_exists(FORUM_ROOT.'extensions/'.$entry.'/manifest.xml'))
  784. {
  785. $forum_page['ext_error'][] = '<div class="ext-error databox db'.++$forum_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)).'<span></h3>'."\n\t\t\t\t".'<p>'.$lang_admin_ext['Missing manifest'].'</p>'."\n\t\t\t".'</div>';
  786. ++$num_failed;
  787. continue;
  788. }
  789. // Parse manifest.xml into an array
  790. $ext_data = is_readable(FORUM_ROOT.'extensions/'.$entry.'/manifest.xml') ? xml_to_array(file_get_contents(FORUM_ROOT.'extensions/'.$entry.'/manifest.xml')) : '';
  791. if (empty($ext_data))
  792. {
  793. $forum_page['ext_error'][] = '<div class="ext-error databox db'.++$forum_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)).'<span></h3>'."\n\t\t\t\t".'<p>'.$lang_admin_ext['Failed parse manifest'].'</p>'."\n\t\t\t".'</div>';
  794. ++$num_failed;
  795. continue;
  796. }
  797. // Validate manifest
  798. $errors = validate_manifest($ext_data, $entry);
  799. if (!empty($errors))
  800. {
  801. $forum_page['ext_error'][] = '<div class="ext-error databox db'.++$forum_page['item_num'].'">'."\n\t\t\t\t".'<h3 class="legend"><span>'.sprintf($lang_admin_ext['Extension loading error'], forum_htmlencode($entry)).'</span></h3>'."\n\t\t\t\t".'<p>'.implode(' ', $errors).'</p>'."\n\t\t\t".'</div>';
  802. ++$num_failed;
  803. }
  804. else
  805. {
  806. if (!array_key_exists($entry, $inst_exts) || version_compare($inst_exts[$entry]['version'], $ext_data['extension']['version'], '!='))
  807. {
  808. $forum_page['ext_item'][] = '<div class="ct-box info-box extension available">'."\n\t\t\t".'<h3 class="ct-legend hn">'.forum_htmlencode($ext_data['extension']['title']).' <em>'.$ext_data['extension']['version'].'</em></h3>'."\n\t\t\t".'<ul class="data-list">'."\n\t\t\t\t".'<li><span>'.sprintf($lang_admin_ext['Extension by'], forum_htmlencode($ext_data['extension']['author'])).'</span></li>'.(($ext_data['extension']['description'] != '') ? "\n\t\t\t\t".'<li><span>'.forum_htmlencode($ext_data['extension']['description']).'</span></li>' : '')."\n\t\t\t".'</ul>'."\n\t\t\t".'<p class="options"><span class="first-item"><a href="'.$base_url.'/admin/extensions.php?install='.urlencode($entry).'">'.(isset($inst_exts[$entry]['version']) ? $lang_admin_ext['Upgrade extension'] : $lang_admin_ext['Install extension']).'</a></span></p>'."\n\t\t".'</div>';
  809. ++$num_exts;
  810. }
  811. }
  812. }
  813. }
  814. $d->close();
  815. ($hook = get_hook('aex_section_install_pre_display_available_ext_list')) ? eval($hook) : null;
  816. if ($num_exts)
  817. echo "\t\t".implode("\n\t\t", $forum_page['ext_item'])."\n";
  818. else
  819. {
  820. ?>
  821. <div class="ct-box info-box">
  822. <p><?php echo $lang_admin_ext['No available extensions'] ?></p>
  823. </div>
  824. <?php
  825. }
  826. // If any of the extensions had errors
  827. if ($num_failed)
  828. {
  829. ?>
  830. <div class="ct-box data-box">
  831. <p class="important"><?php echo $lang_admin_ext['Invalid extensions'] ?></p>
  832. <?php echo implode("\n\t\t\t", $forum_page['ext_error'])."\n" ?>
  833. </div>
  834. <?php
  835. }
  836. ?>
  837. </div>
  838. <?php
  839. ($hook = get_hook('aex_section_manage_pre_display_installed_ext_list')) ? eval($hook) : null;
  840. ?>
  841. <div class="main-subhead">
  842. <h2 class="hn"><span><?php echo $lang_admin_ext['Installed extensions'] ?></span></h2>
  843. </div>
  844. <div class="main-content main-extensions">
  845. <?php
  846. $installed_count = 0;
  847. $forum_page['ext_item'] = array();
  848. foreach ($inst_exts as $id => $ext)
  849. {
  850. if (strpos($id, 'hotfix_') === 0)
  851. continue;
  852. $forum_page['ext_actions'] = array(
  853. 'flip' => '<span class="first-item"><a href="'.$base_url.'/admin/extensions.php?section=manage&amp;flip='.$id.'&amp;csrf_token='.generate_form_token('flip'.$id).'">'.($ext['disabled'] != '1' ? $lang_admin_ext['Disable'] : $lang_admin_ext['Enable']).'</a></span>',
  854. 'uninstall' => '<span><a href="'.$base_url.'/admin/extensions.php?section=manage&amp;uninstall='.$id.'">'.$lang_admin_ext['Uninstall'].'</a></span>'
  855. );
  856. if ($forum_config['o_check_for_versions'] == 1 && isset($forum_ext_last_versions[$id]) && version_compare($ext['version'], $forum_ext_last_versions[$id]['version'], '<'))
  857. $forum_page['ext_actions']['latest_ver'] = '<span><a href="'.$forum_ext_last_versions[$id]['repo_url'].'/'.$id.'/'.$id.'.zip">'.$lang_admin_ext['Download latest version'].'</a></span>';
  858. ($hook = get_hook('aex_section_manage_pre_ext_actions')) ? eval($hook) : null;
  859. if ($ext['disabled'] == '1')
  860. $forum_page['ext_item'][] = '<div class="ct-box info-box extension disabled">'."\n\t\t".'<h3 class="ct-legend hn">'.forum_htmlencode($ext['title']).' <em>'.$ext['version'].'</em> ('.$lang_admin_ext['Extension disabled'].')</h3>'."\n\t\t".'<ul class="data-list">'."\n\t\t\t".'<li><span>'.sprintf($lang_admin_ext['Extension by'], forum_htmlencode($ext['author'])).'</span></li>'."\n\t\t\t".(($ext['description'] != '') ? '<li><span>'.forum_htmlencode($ext['description']).'</span></li>' : '')."\n\t\t\t".'</ul>'."\n\t\t".'<p class="options">'.implode(' ', $forum_page['ext_actions']).'</p>'."\n\t".'</div>';
  861. else
  862. $forum_page['ext_item'][] = '<div class="ct-box info-box extension enabled">'."\n\t\t".'<h3 class="ct-legend hn">'.forum_htmlencode($ext['title']).' <em>'.$ext['version'].'</em></h3>'."\n\t\t".'<ul class="data-list">'."\n\t\t\t".'<li><span>'.sprintf($lang_admin_ext['Extension by'], forum_htmlencode($ext['author'])).'</span></li>'."\n\t\t\t".(($ext['description'] != '') ? '<li><span>'.forum_htmlencode($ext['description']).'</span></li>' : '')."\n\t\t".'</ul>'."\n\t\t".'<p class="options">'.implode(' ', $forum_page['ext_actions']).'</p>'."\n\t".'</div>';
  863. $installed_count++;
  864. }
  865. if ($installed_count > 0)
  866. {
  867. echo "\t".implode("\n\t", $forum_page['ext_item'])."\n";
  868. }
  869. else
  870. {
  871. ?>
  872. <div class="ct-box info-box">
  873. <p><?php echo $lang_admin_ext['No installed extensions'] ?></p>
  874. </div>
  875. <?php
  876. }
  877. ?>
  878. </div>
  879. <?php
  880. ($hook = get_hook('aex_section_manage_end')) ? eval($hook) : null;
  881. $tpl_temp = forum_trim(ob_get_contents());
  882. $tpl_main = str_replace('<!-- forum_main -->', $tpl_temp, $tpl_main);
  883. ob_end_clean();
  884. // END SUBST - <!-- forum_main -->
  885. require FORUM_ROOT.'footer.php';
  886. }