diff options
author | Nathan Guse <nathaniel.guse@gmail.com> | 2012-07-23 19:46:21 -0500 |
---|---|---|
committer | Unknown Bliss <m@michaelcullum.com> | 2012-09-01 15:05:34 +0100 |
commit | 89f4cf6a8c10f9b0875cf7f278016aff67eb38fc (patch) | |
tree | e54d06e9d8b4b43589c2710538e14b13f529ff54 /phpBB/includes/acp/acp_extensions.php | |
parent | 106c105113886f9a9e603dbb11549c06049b255f (diff) | |
download | forums-89f4cf6a8c10f9b0875cf7f278016aff67eb38fc.tar forums-89f4cf6a8c10f9b0875cf7f278016aff67eb38fc.tar.gz forums-89f4cf6a8c10f9b0875cf7f278016aff67eb38fc.tar.bz2 forums-89f4cf6a8c10f9b0875cf7f278016aff67eb38fc.tar.xz forums-89f4cf6a8c10f9b0875cf7f278016aff67eb38fc.zip |
[ticket/10631] Use exceptions for errors. Build action list dynamically.
PHPBB3-10631
Diffstat (limited to 'phpBB/includes/acp/acp_extensions.php')
-rw-r--r-- | phpBB/includes/acp/acp_extensions.php | 111 |
1 files changed, 83 insertions, 28 deletions
diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 0e825514e6..a833c8c482 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -22,11 +22,21 @@ class acp_extensions { var $u_action; + private $db; + private $config; + private $template; + private $user; + function main() { // Start the page global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; + $this->db = $db; + $this->config = $config; + $this->template = $template; + $this->user = $user; + $user->add_lang(array('install', 'acp/extensions')); $this->page_title = 'ACP_EXTENSIONS'; @@ -39,9 +49,10 @@ class acp_extensions { $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); - if ($md_manager->get_metadata('all') === false) - { - trigger_error('EXTENSION_INVALID'); + try{ + $md_manager->get_metadata('all'); + } catch( Exception $e ) { + trigger_error($e); } } @@ -50,9 +61,9 @@ class acp_extensions { case 'list': default: - $this->list_enabled_exts($phpbb_extension_manager, $template); - $this->list_disabled_exts($phpbb_extension_manager, $template); - $this->list_available_exts($phpbb_extension_manager, $template); + $this->list_enabled_exts($phpbb_extension_manager); + $this->list_disabled_exts($phpbb_extension_manager); + $this->list_available_exts($phpbb_extension_manager); $this->tpl_name = 'acp_ext_list'; break; @@ -155,19 +166,28 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager) { foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - $template->assign_block_vars('enabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + try { + $this->template->assign_block_vars('enabled', array( + 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, - 'U_DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, - )); + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + )); + + $this->output_actions('enabled', array( + 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, + )); + } catch( Exception $e ) { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + )); + } } } @@ -178,19 +198,28 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager) { foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + try { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $md_manager->get_metadata('display-name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, - 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, - )); + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + )); + + $this->output_actions('disabled', array( + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, + )); + } catch( Exception $e ) { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + )); + } } } @@ -201,19 +230,45 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager) { $uninstalled = array_diff_key($phpbb_extension_manager->all_available(), $phpbb_extension_manager->all_configured()); foreach ($uninstalled as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); + + try { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $md_manager->get_metadata('display-name'), + + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + )); - $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + $this->output_actions('disabled', array( + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + )); + } catch( Exception $e ) { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + )); + } + } + } - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + /** + * Output actions to a block + * + * @param string $block + * @param array $actions + */ + private function output_actions($block, $actions) + { + foreach ($actions as $lang => $url) + { + $this->template->assign_block_vars($block . '.actions', array( + 'L_ACTION' => $this->user->lang($lang), + 'U_ACTION' => $url, )); } } |