From 5e6b4c7192a80dc29382ad06976e9ce6d5c16efd Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Wed, 29 Feb 2012 21:23:50 +0000 Subject: [ticket/10631] Adding an extensions admin PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 265 +++++++++++++++++++++++++++++ phpBB/includes/acp/info/acp_extensions.php | 34 ++++ 2 files changed, 299 insertions(+) create mode 100644 phpBB/includes/acp/acp_extensions.php create mode 100644 phpBB/includes/acp/info/acp_extensions.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php new file mode 100644 index 0000000000..a0a7db4474 --- /dev/null +++ b/phpBB/includes/acp/acp_extensions.php @@ -0,0 +1,265 @@ +add_lang(array('install', 'acp/customisations')); + + $this->page_title = 'ACP_EXTENSIONS'; + + $action = $request->variable('action', ''); + $ext_name = $request->variable('ext_name', ''); + + // Set action to list if not set + if (empty($action)) + { + $action = "list"; + } + + // What are we doing? + switch ($action) + { + case 'list': + default: + $this->list_enabled_exts(); + $this->list_disabled_exts(); + $this->tpl_name = 'acp_ext_list'; + break; + + case 'enable_pre': + $this->tpl_name = 'acp_ext_enable'; + $template->assign_vars(array( + 'PRE' => true, + 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . $ext_name, + ) + ); + break; + + case 'enable': + $name = $request->variable('ext_name', ''); + $this->enable_extension($name); + $this->tpl_name = 'acp_ext_enable'; + break; + + case 'disable_pre': + $this->tpl_name = 'acp_ext_disable'; + $template->assign_vars(array( + 'PRE' => true, + 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name, + ) + ); + break; + + case 'disable': + $name = $request->variable('ext_name', ''); + $this->disable_extension($name); + $this->tpl_name = 'acp_ext_disable'; + break; + + case 'purge_pre': + $this->tpl_name = 'acp_ext_purge'; + $template->assign_vars(array( + 'PRE' => true, + 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name, + ) + ); + break; + + case 'purge': + $name = $request->variable('ext_name', ''); + $this->purge_extension($name); + $this->tpl_name = 'acp_ext_purge'; + break; + + case 'delete_pre': + $this->tpl_name = 'acp_ext_delete'; + $template->assign_vars(array( + 'PRE' => true, + 'U_DELETE' => $this->u_action . '&action=delete&ext_name=' . $ext_name, + ) + ); + break; + + case 'delete': + $name = $request->variable('ext_name', ''); + $this->tpl_name = 'acp_ext_delete'; + break; + + case 'details': + $name = $request->variable('ext_name', ''); + $filepath = $phpbb_root_path . 'ext/' . $name . '/extension.json'; + $this->tpl_name = 'acp_ext_details'; + $this->get_meta_info($filepath); + break; + } + } + + function enable_extension($name) + { + global $phpbb_extension_manager, $template, $cache; + + $phpbb_extension_manager->enable($name); + $template->assign_vars(array( + 'U_RETURN' => $this->u_action . '&action=list', + )); + $cache->purge(); + } + + function disable_extension($name) + { + global $phpbb_extension_manager, $template, $cache; + $phpbb_extension_manager->disable($name); + $template->assign_vars(array( + 'U_RETURN' => $this->u_action . '&action=list', + )); + $cache->purge(); + } + + function purge_extension($name) + { + global $phpbb_extension_manager, $template, $cache; + $phpbb_extension_manager->purge($name); + $template->assign_vars(array( + 'U_RETURN' => $this->u_action . '&action=list', + )); + $cache->purge(); + } + + function list_enabled_exts() + { + global $db, $template; + + $sql = 'SELECT ext_name + FROM ' . EXT_TABLE . ' + WHERE ext_active= 1 + ORDER BY ext_name ASC'; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $template->assign_block_vars('enabled', array( + 'EXT_NAME' => $row['ext_name'], + + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $row['ext_name'], + 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $row['ext_name'], + 'U_DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $row['ext_name'], + )); + } + $db->sql_freeresult($result); + + return; + } + + function list_disabled_exts() + { + global $db, $template; + + $sql = 'SELECT ext_name + FROM ' . EXT_TABLE . ' + WHERE ext_active= 0 + ORDER BY ext_name ASC'; + $result = $db->sql_query($sql); + while ($row = $db->sql_fetchrow($result)) + { + $template->assign_block_vars('disabled', array( + 'EXT_NAME' => $row['ext_name'], + + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $row['ext_name'], + 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $row['ext_name'], + 'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $row['ext_name'], + 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $row['ext_name'], + )); + } + $db->sql_freeresult($result); + + return; + } + + function list_avaliable_exts() + { + $phpbb_extension_manager->load_extensions(); + $allavailable = array_keys($phpbb_extension_manager->all_available()); + $allconfigured = array_keys($phpbb_extension_manager->all_configured()); + $uninstalled = array_diff($allavailable, $allconfigured); + + foreach ($uninstalled as $ext) + { + $template->assign_block_vars('disabled', array( + 'EXT_NAME' => $ext['ext_name'], + + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $ext['ext_name'], + 'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $ext['ext_name'], + 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $ext['ext_name'], + )); + } + + return; + } + + function get_meta_info($filepath) + { + global $template; + + $metadatafile = file_get_contents($filepath); + $metadata = json_decode($metadatafile,true); + + $name = $metadata["name"]; + $type = $metadata["type"]; + $description = $metadata["description"]; + $homepage = $metadata["homepage"]; + $version = $metadata["version"]; + $time = $metadata["time"]; + $licence = $metadata["licence"]; + $require_php = $metadata["require"]["php"]; + $require_phpbb = $metadata["require"]["phpbb"]; + $display_name = $metadata["extra"]["display-name"]; + + $template->assign_vars(array( + 'NAME' => $name, + 'TYPE' => $type, + 'DESCRIPTION' => $description, + 'HOMEPAGE' => $homepage, + 'VERSION' => $version, + 'TIME' => $time, + 'LICENSE' => $licence, + 'REQUIRE_PHP' => $require_php, + 'REQUIRE_PHPBB' => $require_phpbb, + 'DISPLAY_NAME' => $display_name, + ) + ); + + foreach ($metadata["authors"] as $author) + { + $template->assign_block_vars('authors', array( + 'AUTHOR_NAME' => $author["name"], + 'AUTHOR_USERNAME' => $author["username"], + 'AUTHOR_EMAIL' => $author["email"], + 'AUTHOR_HOMEPAGE' => $author["homepage"], + 'AUTHOR_TYPE' => $author["type"], + )); + } + } +} diff --git a/phpBB/includes/acp/info/acp_extensions.php b/phpBB/includes/acp/info/acp_extensions.php new file mode 100644 index 0000000000..87e30bf25d --- /dev/null +++ b/phpBB/includes/acp/info/acp_extensions.php @@ -0,0 +1,34 @@ + 'acp_extensions', + 'title' => 'ACP_EXTENSIONS', + 'version' => '1.0.0', + 'modes' => array( + 'main' => array('title' => 'ACP_EXTENSIONS', 'auth' => 'acl_a_extensions', 'cat' => array('ACP_CAT_SYSTEM')), + ), + ); + } + + function install() + { + } + + function uninstall() + { + } +} -- cgit v1.2.1 From 305b5fe93906838b8b963570da077539715ad13f Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 4 Mar 2012 16:00:43 +0000 Subject: [ticket/10631] Fixing some issues spotted in extensions admin Removing whitespace, cast the items from the json file straight into template vars (not via variables) and fixing some double quotes to single quotes. PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 83 +++++++++++++++-------------------- 1 file changed, 36 insertions(+), 47 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index a0a7db4474..b6224f6c26 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -21,25 +21,25 @@ if (!defined('IN_PHPBB')) class acp_extensions { var $u_action; - + function main() { // Start the page global $user, $template, $request; - + $user->add_lang(array('install', 'acp/customisations')); - + $this->page_title = 'ACP_EXTENSIONS'; - + $action = $request->variable('action', ''); $ext_name = $request->variable('ext_name', ''); - + // Set action to list if not set if (empty($action)) { - $action = "list"; + $action = 'list'; } - + // What are we doing? switch ($action) { @@ -58,13 +58,13 @@ class acp_extensions ) ); break; - + case 'enable': $name = $request->variable('ext_name', ''); $this->enable_extension($name); $this->tpl_name = 'acp_ext_enable'; break; - + case 'disable_pre': $this->tpl_name = 'acp_ext_disable'; $template->assign_vars(array( @@ -73,13 +73,13 @@ class acp_extensions ) ); break; - + case 'disable': $name = $request->variable('ext_name', ''); $this->disable_extension($name); $this->tpl_name = 'acp_ext_disable'; break; - + case 'purge_pre': $this->tpl_name = 'acp_ext_purge'; $template->assign_vars(array( @@ -88,13 +88,13 @@ class acp_extensions ) ); break; - + case 'purge': $name = $request->variable('ext_name', ''); $this->purge_extension($name); $this->tpl_name = 'acp_ext_purge'; break; - + case 'delete_pre': $this->tpl_name = 'acp_ext_delete'; $template->assign_vars(array( @@ -103,12 +103,12 @@ class acp_extensions ) ); break; - + case 'delete': $name = $request->variable('ext_name', ''); $this->tpl_name = 'acp_ext_delete'; break; - + case 'details': $name = $request->variable('ext_name', ''); $filepath = $phpbb_root_path . 'ext/' . $name . '/extension.json'; @@ -121,7 +121,7 @@ class acp_extensions function enable_extension($name) { global $phpbb_extension_manager, $template, $cache; - + $phpbb_extension_manager->enable($name); $template->assign_vars(array( 'U_RETURN' => $this->u_action . '&action=list', @@ -148,7 +148,7 @@ class acp_extensions )); $cache->purge(); } - + function list_enabled_exts() { global $db, $template; @@ -172,7 +172,7 @@ class acp_extensions return; } - + function list_disabled_exts() { global $db, $template; @@ -197,14 +197,14 @@ class acp_extensions return; } - + function list_avaliable_exts() { $phpbb_extension_manager->load_extensions(); $allavailable = array_keys($phpbb_extension_manager->all_available()); $allconfigured = array_keys($phpbb_extension_manager->all_configured()); $uninstalled = array_diff($allavailable, $allconfigured); - + foreach ($uninstalled as $ext) { $template->assign_block_vars('disabled', array( @@ -215,42 +215,31 @@ class acp_extensions 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $ext['ext_name'], )); } - + return; } - + function get_meta_info($filepath) { global $template; - + $metadatafile = file_get_contents($filepath); $metadata = json_decode($metadatafile,true); - - $name = $metadata["name"]; - $type = $metadata["type"]; - $description = $metadata["description"]; - $homepage = $metadata["homepage"]; - $version = $metadata["version"]; - $time = $metadata["time"]; - $licence = $metadata["licence"]; - $require_php = $metadata["require"]["php"]; - $require_phpbb = $metadata["require"]["phpbb"]; - $display_name = $metadata["extra"]["display-name"]; - + $template->assign_vars(array( - 'NAME' => $name, - 'TYPE' => $type, - 'DESCRIPTION' => $description, - 'HOMEPAGE' => $homepage, - 'VERSION' => $version, - 'TIME' => $time, - 'LICENSE' => $licence, - 'REQUIRE_PHP' => $require_php, - 'REQUIRE_PHPBB' => $require_phpbb, - 'DISPLAY_NAME' => $display_name, + 'NAME' => $metadata['name'], + 'TYPE' => $metadata['type'], + 'DESCRIPTION' => $metadata['description'], + 'HOMEPAGE' => $metadata['homepage'], + 'VERSION' => $metadata['version'], + 'TIME' => $metadata['time'], + 'LICENSE' => $metadata['licence'], + 'REQUIRE_PHP' => $metadata['require']['php'], + 'REQUIRE_PHPBB' => $metadata['require']['phpbb'], + 'DISPLAY_NAME' => $metadata['extra']['display-name'], ) ); - + foreach ($metadata["authors"] as $author) { $template->assign_block_vars('authors', array( @@ -258,7 +247,7 @@ class acp_extensions 'AUTHOR_USERNAME' => $author["username"], 'AUTHOR_EMAIL' => $author["email"], 'AUTHOR_HOMEPAGE' => $author["homepage"], - 'AUTHOR_TYPE' => $author["type"], + 'AUTHOR_ROLE' => $author["role"], )); } } -- cgit v1.2.1 From 3a5843959c754b99e595ca6d1ffa30ad67d31209 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 9 Mar 2012 18:19:21 +0000 Subject: [ticket/10631] Fixing some extension admin issues found PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index b6224f6c26..918ef3f813 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -60,8 +60,7 @@ class acp_extensions break; case 'enable': - $name = $request->variable('ext_name', ''); - $this->enable_extension($name); + $this->enable_extension($ext_name); $this->tpl_name = 'acp_ext_enable'; break; @@ -75,8 +74,7 @@ class acp_extensions break; case 'disable': - $name = $request->variable('ext_name', ''); - $this->disable_extension($name); + $this->disable_extension($ext_name); $this->tpl_name = 'acp_ext_disable'; break; @@ -90,8 +88,7 @@ class acp_extensions break; case 'purge': - $name = $request->variable('ext_name', ''); - $this->purge_extension($name); + $this->purge_extension($ext_name); $this->tpl_name = 'acp_ext_purge'; break; @@ -105,20 +102,18 @@ class acp_extensions break; case 'delete': - $name = $request->variable('ext_name', ''); $this->tpl_name = 'acp_ext_delete'; break; case 'details': - $name = $request->variable('ext_name', ''); - $filepath = $phpbb_root_path . 'ext/' . $name . '/extension.json'; + $filepath = $phpbb_root_path . 'ext/' . $ext_name . '/extension.json'; $this->tpl_name = 'acp_ext_details'; $this->get_meta_info($filepath); break; } } - function enable_extension($name) + function enable_extension($ext_name) { global $phpbb_extension_manager, $template, $cache; @@ -129,7 +124,7 @@ class acp_extensions $cache->purge(); } - function disable_extension($name) + function disable_extension($ext_name) { global $phpbb_extension_manager, $template, $cache; $phpbb_extension_manager->disable($name); @@ -139,7 +134,7 @@ class acp_extensions $cache->purge(); } - function purge_extension($name) + function purge_extension($ext_name) { global $phpbb_extension_manager, $template, $cache; $phpbb_extension_manager->purge($name); @@ -198,12 +193,12 @@ class acp_extensions return; } - function list_avaliable_exts() + function list_available_exts() { $phpbb_extension_manager->load_extensions(); - $allavailable = array_keys($phpbb_extension_manager->all_available()); - $allconfigured = array_keys($phpbb_extension_manager->all_configured()); - $uninstalled = array_diff($allavailable, $allconfigured); + $all_available = array_keys($phpbb_extension_manager->all_available()); + $all_configured = array_keys($phpbb_extension_manager->all_configured()); + $uninstalled = array_diff($all_available, $all_configured); foreach ($uninstalled as $ext) { -- cgit v1.2.1 From 7a954d352ef1fe84256ad691135b6c6bf0d4bcc5 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 28 Apr 2012 18:13:28 +0100 Subject: [ticket/10631] Fixing some items mentioned in PR PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 111 ++++++++++++---------------------- phpBB/includes/extension/manager.php | 64 ++++++++++++++++++++ 2 files changed, 101 insertions(+), 74 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 918ef3f813..130d00208d 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -25,28 +25,23 @@ class acp_extensions function main() { // Start the page - global $user, $template, $request; + global $user, $template, $request, $phpbb_extension_manager, $db; - $user->add_lang(array('install', 'acp/customisations')); + $user->add_lang(array('install', 'acp/extensions')); $this->page_title = 'ACP_EXTENSIONS'; - $action = $request->variable('action', ''); + $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); - // Set action to list if not set - if (empty($action)) - { - $action = 'list'; - } - // What are we doing? switch ($action) { case 'list': default: - $this->list_enabled_exts(); - $this->list_disabled_exts(); + $this->list_enabled_exts($db, $template); + $this->list_disabled_exts($db, $template); + $this->list_available_exts($phpbb_extension_manager, $template); $this->tpl_name = 'acp_ext_list'; break; @@ -55,13 +50,15 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . $ext_name, - ) - ); + )); break; case 'enable': - $this->enable_extension($ext_name); + $phpbb_extension_manager->enable($ext_name); $this->tpl_name = 'acp_ext_enable'; + $template->assign_vars(array( + 'U_RETURN' => $this->u_action . '&action=list', + )); break; case 'disable_pre': @@ -69,13 +66,15 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name, - ) - ); + )); break; case 'disable': - $this->disable_extension($ext_name); + $phpbb_extension_manager->disable($ext_name); $this->tpl_name = 'acp_ext_disable'; + $template->assign_vars(array( + 'U_RETURN' => $this->u_action . '&action=list', + )); break; case 'purge_pre': @@ -83,13 +82,15 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name, - ) - ); + )); break; case 'purge': - $this->purge_extension($ext_name); + $phpbb_extension_manager->purge($ext_name); $this->tpl_name = 'acp_ext_purge'; + $template->assign_vars(array( + 'U_RETURN' => $this->u_action . '&action=list', + )); break; case 'delete_pre': @@ -97,8 +98,7 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, 'U_DELETE' => $this->u_action . '&action=delete&ext_name=' . $ext_name, - ) - ); + )); break; case 'delete': @@ -108,49 +108,16 @@ class acp_extensions case 'details': $filepath = $phpbb_root_path . 'ext/' . $ext_name . '/extension.json'; $this->tpl_name = 'acp_ext_details'; - $this->get_meta_info($filepath); + $this->parse_meta_info($ext_name, $phpbb_extension_manager); break; } } - - function enable_extension($ext_name) - { - global $phpbb_extension_manager, $template, $cache; - - $phpbb_extension_manager->enable($name); - $template->assign_vars(array( - 'U_RETURN' => $this->u_action . '&action=list', - )); - $cache->purge(); - } - - function disable_extension($ext_name) - { - global $phpbb_extension_manager, $template, $cache; - $phpbb_extension_manager->disable($name); - $template->assign_vars(array( - 'U_RETURN' => $this->u_action . '&action=list', - )); - $cache->purge(); - } - function purge_extension($ext_name) + private function list_enabled_exts($db, $template) { - global $phpbb_extension_manager, $template, $cache; - $phpbb_extension_manager->purge($name); - $template->assign_vars(array( - 'U_RETURN' => $this->u_action . '&action=list', - )); - $cache->purge(); - } - - function list_enabled_exts() - { - global $db, $template; - $sql = 'SELECT ext_name FROM ' . EXT_TABLE . ' - WHERE ext_active= 1 + WHERE ext_active = 1 ORDER BY ext_name ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -168,13 +135,11 @@ class acp_extensions return; } - function list_disabled_exts() + private function list_disabled_exts($db, $template) { - global $db, $template; - $sql = 'SELECT ext_name FROM ' . EXT_TABLE . ' - WHERE ext_active= 0 + WHERE ext_active = 0 ORDER BY ext_name ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) @@ -193,7 +158,7 @@ class acp_extensions return; } - function list_available_exts() + function list_available_exts($phpbb_extension_manager, $template) { $phpbb_extension_manager->load_extensions(); $all_available = array_keys($phpbb_extension_manager->all_available()); @@ -214,12 +179,9 @@ class acp_extensions return; } - function get_meta_info($filepath) + function parse_meta_info($ext_name, $phpbb_extension_manager) { - global $template; - - $metadatafile = file_get_contents($filepath); - $metadata = json_decode($metadatafile,true); + $phpbb_extension_manager->get_meta_data($ext_name) $template->assign_vars(array( 'NAME' => $metadata['name'], @@ -235,15 +197,16 @@ class acp_extensions ) ); - foreach ($metadata["authors"] as $author) + foreach ($metadata['authors'] as $author) { $template->assign_block_vars('authors', array( - 'AUTHOR_NAME' => $author["name"], - 'AUTHOR_USERNAME' => $author["username"], - 'AUTHOR_EMAIL' => $author["email"], - 'AUTHOR_HOMEPAGE' => $author["homepage"], - 'AUTHOR_ROLE' => $author["role"], + 'AUTHOR_NAME' => $author['name'], + 'AUTHOR_EMAIL' => $author['email'], + 'AUTHOR_HOMEPAGE' => $author['homepage'], + 'AUTHOR_ROLE' => $author['role'], )); } + + return $metadata; } } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 86d8fab64b..2eebebf9b2 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -464,4 +464,68 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } + + /** + * Gets and processes the contents of the composer.json file. + * + * TODO: Add authors, fix it + * + * @param string $name Extension name to check + * @return array All the existing metadata keys + */ + public function get_meta_data($name) + { + // Find out where the composer.json is + $ext_filepath = get_extension_path($name); + $md_filepath = $phpbb_root_path . $ext_filepath . '/composer.json'; + + // Read the composer.json and decode it + $metadatafile = file_get_contents($filepath); + $metadata = json_decode($metadatafile, true); + + // What keys are required + $required_md_keys = array( + $metadata['name'], + $metadata['type'], + $metadata['description'], + $metadata['version'], + $metadata['license'], + $medadata['require']['phpbb'], + $metadata['extra']['dispay-name'], + ); + + // Check for required keys and trigger and error if it doesn't exist + foreach ($required_md_keys as $md_key) + { + if (empty($md_key)) + { + trigger_error('Not all required items exist in the composer.json'); + } + else + { + $existing_required_keys += $md_key; + } + } + + // Which keys are optional + $optional_md_keys = array( + $metadata['require']['php'], + $metadata['time'], + $metadata['homepage'], + ); + + $existing_optional_keys = array(); + + foreach ($optional_md_keys as $md_key) + { + if (!empty($md_key)) + { + $existing_optional_keys += $md_key; + } + } + + $keys = array_merge($existing_optional_keys, $existing_required_keys); + + return $keys; + } } -- cgit v1.2.1 From 4cbfa6175303d23d35aaa06f8f68d9a3d7d0beb2 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 29 Apr 2012 00:34:50 +0100 Subject: [ticket/10631] A few more extension admin changes PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 130d00208d..bcc77dfb25 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -181,7 +181,7 @@ class acp_extensions function parse_meta_info($ext_name, $phpbb_extension_manager) { - $phpbb_extension_manager->get_meta_data($ext_name) + $phpbb_extension_manager->get_meta_data($ext_name); $template->assign_vars(array( 'NAME' => $metadata['name'], @@ -194,8 +194,7 @@ class acp_extensions 'REQUIRE_PHP' => $metadata['require']['php'], 'REQUIRE_PHPBB' => $metadata['require']['phpbb'], 'DISPLAY_NAME' => $metadata['extra']['display-name'], - ) - ); + )); foreach ($metadata['authors'] as $author) { -- cgit v1.2.1 From a0e283d7b025325476c3c44f033410b47a87c621 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 19:56:02 +0100 Subject: [ticket/10631] Adding extension metadata manager class PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 368 ++++++++++++++++++++++++++ 1 file changed, 368 insertions(+) create mode 100644 phpBB/includes/extension/metadata_manager.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php new file mode 100644 index 0000000000..b58f1c6498 --- /dev/null +++ b/phpBB/includes/extension/metadata_manager.php @@ -0,0 +1,368 @@ +phpbb_root_path = $phpbb_root_path; + $this->db = $db; + $this->phpEx = $phpEx; + $this->extension_manager = $extension_manager; + $this->ext_name = $ext_name; + $this->template = $template; + $this->metadata = array(); + $this->metadata_file = ''; + } + + /** + * Processes and gets the metadata requested + * + * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. + * @param bool $template_output True if you want the requested metadata assigned to template vars + * @return array Contains all of the requested metadata + */ + public function get_meta_data($element = 'all', $template_output = false) + { + // TODO: Check ext_name exists and is an extension that exists + if (!$this->set_meta_data_file()) + { + return false; + } + + switch ($element) + { + case 'all': + default: + if (!$this->clean_metadata_array()) + { + return false; + } + + if ($template_output) + { + $this->output_template_data(); + } + + return $this->metadata; + break; + + case 'name': + if($this->validate_name) + { + if ($template_output) + { + $this->template->assign_vars(array( + 'MD_NAME' => htmlspecialchars($this->metadata['name']), + )); + } + return $this->metadata['name']; + } + else + { + return false; + } + break; + // TODO: Add remaining cases + } + } + + /** + * Sets the filepath of the metadata file + * + * @return null + */ + private function set_meta_data_file() + { + $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); + $metadata_filepath = $this->phpbb_root_path . $ext_filepath . '/composer.json'; + + $this->metadata_file = $metadata_filepath; + + if(!file_exists($this->metadata_file)) + { + return false; + } + else + { + return true; + } + } + + /** + * This array handles the validation and cleaning of the array + * + * @return array Contains the cleaned and validated metadata array + */ + private function clean_metadata_array() + { + if (!$this->validate_name() || !$this->validate_type() || !$this->validate_license() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) + { + return false; + } + + $this->check_for_optional(true); + +// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors +// $this->metadata = $metadata_finished; + $metadata_finished = $this->metadata; + + return $metadata_finished; + } + + /** + * Validates the contents of the name field + * + * @return bool True when passes validation + */ + private function validate_name() + { + if(preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the type field + * + * @return bool True when passes validation + */ + private function validate_type() + { + if ($this->metadata['type'] != 'phpbb3-extension') + { + return false; + } + else + { + return true; + } + } + + /** + * Validates the contents of the description field + * + * @return bool True when passes validation + */ + private function validate_description() + { + if(preg_match('^{10,}$', $this->metadata['description'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the version field + * + * @return bool True when passes validation + */ + private function validate_version() + { + if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the license field + * + * @return bool True when passes validation + */ + private function validate_license() + { + if ($this->metadata['license'] != 'GPLv2') + { + return false; + } + else + { + return true; + } + } + + /** + * Validates the contents of the phpbb requirement field + * + * @return bool True when passes validation + */ + private function validate_require_phpbb() + { + if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>') + { + return true; + } + else + { + return false; + } + } + + /** + * Validates the contents of the display name field + * + * @return bool True when passes validation + */ + private function validate_extra_display_name() + { + if(preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name'])) + { + return true; + } + else + { + return false; + } + } + + /** + * Checks which optional fields exist + * + * @return boolean False if any that exist fail validation, otherwise true. + */ + public function check_for_optional() + { + if ((isset($this->metadata['require']['php']) && !$this->validate_require_php()) || (isset($this->metadata['time']) && !$this->validate_time()) || (isset($this->metadata['validate_homepage']) && !$this->validate_homepage())) + { + return false; + } + } + + /** + * Validates the contents of the php requirement field + * + * @return bool True when passes validation + */ + private function validate_require_php() + { + + } + + /** + * Validates the contents of the time field + * + * @return bool True when passes validation + */ + private function validate_time() + { + + } + + /** + * Validates the contents of the homepage field + * + * @return bool True when passes validation + */ + private function validate_homepage() + { + + } + + /** + * Validates the contents of the authors field + * + * @return bool True when passes validation + */ + private function validate_authors() + { + + } + + /** + * Gets the contents of the composer.json file and can also assign template vars + * + * @return array Contains everything from the meta data file. Do not use without validating and cleaning first + */ + private function fetch_metadata() + { + // Read it + $metadata_file = file_get_contents($metadata_filepath); + $metadata = json_decode($metadata_file, true) + + $this->metadata = $metadata; + + return $metadata; + } + + /** + * Outputs the metadata into the template + * + * @return null + */ + public function output_template_data() + { + $template->assign_vars(array( + 'MD_NAME' => htmlspecialchars($this->metadata['name']), + 'MD_TYPE' => htmlspecialchars($this->metadata['type']), + 'MD_DESCRIPTION' => htmlspecialchars($this->metadata['description']), + 'MD_HOMEPAGE' => $this->metadata['homepage'], + 'MD_VERSION' => htmlspecialchars($this->metadata['version']), + 'MD_TIME' => htmlspecialchars($this->metadata['time']), + 'MD_LICENSE' => htmlspecialchars($this->metadata['license']), + 'MD_REQUIRE_PHP' => htmlspecialchars($this->metadata['require']['php']), + 'MD_REQUIRE_PHPBB' => htmlspecialchars($this->metadata['require']['phpbb']), + 'MD_DISPLAY_NAME' => htmlspecialchars($this->metadata['extra']['display-name']), + )); + + foreach ($this->metadata['authors'] as $author) + { + $template->assign_block_vars('md_authors', array( + 'AUTHOR_NAME' => htmlspecialchars($author['name']), + 'AUTHOR_EMAIL' => $author['email'], + 'AUTHOR_HOMEPAGE' => $author['homepage'], + 'AUTHOR_ROLE' => htmlspecialchars($author['role']), + )); + } + + return; + } -- cgit v1.2.1 From ac883e26528736c74f96b5bc692f685bdb25fd57 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 19:57:02 +0100 Subject: [ticket/10631] Remove the now un-used method PHPBB3-10631 --- phpBB/includes/extension/manager.php | 65 ------------------------------------ 1 file changed, 65 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 2eebebf9b2..287e3828f9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -464,68 +464,3 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } - - /** - * Gets and processes the contents of the composer.json file. - * - * TODO: Add authors, fix it - * - * @param string $name Extension name to check - * @return array All the existing metadata keys - */ - public function get_meta_data($name) - { - // Find out where the composer.json is - $ext_filepath = get_extension_path($name); - $md_filepath = $phpbb_root_path . $ext_filepath . '/composer.json'; - - // Read the composer.json and decode it - $metadatafile = file_get_contents($filepath); - $metadata = json_decode($metadatafile, true); - - // What keys are required - $required_md_keys = array( - $metadata['name'], - $metadata['type'], - $metadata['description'], - $metadata['version'], - $metadata['license'], - $medadata['require']['phpbb'], - $metadata['extra']['dispay-name'], - ); - - // Check for required keys and trigger and error if it doesn't exist - foreach ($required_md_keys as $md_key) - { - if (empty($md_key)) - { - trigger_error('Not all required items exist in the composer.json'); - } - else - { - $existing_required_keys += $md_key; - } - } - - // Which keys are optional - $optional_md_keys = array( - $metadata['require']['php'], - $metadata['time'], - $metadata['homepage'], - ); - - $existing_optional_keys = array(); - - foreach ($optional_md_keys as $md_key) - { - if (!empty($md_key)) - { - $existing_optional_keys += $md_key; - } - } - - $keys = array_merge($existing_optional_keys, $existing_required_keys); - - return $keys; - } -} -- cgit v1.2.1 From 10cba1426d7119a98c55cbefe2cfb1fd7de9b057 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 23:32:34 +0100 Subject: [ticket/10631] Some tidying up PHPBB3-10631 --- phpBB/includes/extension/manager.php | 1 + phpBB/includes/extension/metadata_manager.php | 71 +++++---------------------- 2 files changed, 12 insertions(+), 60 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 287e3828f9..86d8fab64b 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -464,3 +464,4 @@ class phpbb_extension_manager { return new phpbb_extension_finder($this, $this->phpbb_root_path, $this->cache, $this->php_ext, $this->cache_name . '_finder'); } +} diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index b58f1c6498..db8d09b696 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -39,7 +39,7 @@ class phpbb_extension_metadata_manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', template $template) + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; @@ -84,7 +84,7 @@ class phpbb_extension_metadata_manager break; case 'name': - if($this->validate_name) + if ($this->validate_name) { if ($template_output) { @@ -106,7 +106,7 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file * - * @return null + * @return boolean Set to true if it exists */ private function set_meta_data_file() { @@ -115,7 +115,7 @@ class phpbb_extension_metadata_manager $this->metadata_file = $metadata_filepath; - if(!file_exists($this->metadata_file)) + if (!file_exists($this->metadata_file)) { return false; } @@ -153,14 +153,7 @@ class phpbb_extension_metadata_manager */ private function validate_name() { - if(preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name'])) - { - return true; - } - else - { - return false; - } + return preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name']); } /** @@ -170,14 +163,7 @@ class phpbb_extension_metadata_manager */ private function validate_type() { - if ($this->metadata['type'] != 'phpbb3-extension') - { - return false; - } - else - { - return true; - } + return $this->metadata['type'] != 'phpbb3-extension'; } /** @@ -187,14 +173,7 @@ class phpbb_extension_metadata_manager */ private function validate_description() { - if(preg_match('^{10,}$', $this->metadata['description'])) - { - return true; - } - else - { - return false; - } + return preg_match('^{10,}$', $this->metadata['description']); } /** @@ -204,14 +183,7 @@ class phpbb_extension_metadata_manager */ private function validate_version() { - if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version'])) - { - return true; - } - else - { - return false; - } + return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version']); } /** @@ -221,14 +193,7 @@ class phpbb_extension_metadata_manager */ private function validate_license() { - if ($this->metadata['license'] != 'GPLv2') - { - return false; - } - else - { - return true; - } + return $this->metadata['license'] != 'GPLv2'; } /** @@ -238,14 +203,7 @@ class phpbb_extension_metadata_manager */ private function validate_require_phpbb() { - if(preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>') - { - return true; - } - else - { - return false; - } + return (preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>'); } /** @@ -255,14 +213,7 @@ class phpbb_extension_metadata_manager */ private function validate_extra_display_name() { - if(preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name'])) - { - return true; - } - else - { - return false; - } + return preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name']); } /** -- cgit v1.2.1 From 3e6761b0266dfc67f6b41fea50d377b7621dffe0 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:16:00 +0100 Subject: [ticket/10631] Fixing and finishing the extension metadata class. PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 52 ++++++++------------- phpBB/includes/extension/metadata_manager.php | 67 +++++++++++++++++---------- 2 files changed, 62 insertions(+), 57 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index bcc77dfb25..d52a65da67 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -25,7 +25,7 @@ class acp_extensions function main() { // Start the page - global $user, $template, $request, $phpbb_extension_manager, $db; + global $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path; $user->add_lang(array('install', 'acp/extensions')); @@ -42,11 +42,13 @@ class acp_extensions $this->list_enabled_exts($db, $template); $this->list_disabled_exts($db, $template); $this->list_available_exts($phpbb_extension_manager, $template); + $this->tpl_name = 'acp_ext_list'; break; case 'enable_pre': $this->tpl_name = 'acp_ext_enable'; + $template->assign_vars(array( 'PRE' => true, 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . $ext_name, @@ -55,7 +57,9 @@ class acp_extensions case 'enable': $phpbb_extension_manager->enable($ext_name); + $this->tpl_name = 'acp_ext_enable'; + $template->assign_vars(array( 'U_RETURN' => $this->u_action . '&action=list', )); @@ -63,6 +67,7 @@ class acp_extensions case 'disable_pre': $this->tpl_name = 'acp_ext_disable'; + $template->assign_vars(array( 'PRE' => true, 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name, @@ -71,7 +76,9 @@ class acp_extensions case 'disable': $phpbb_extension_manager->disable($ext_name); + $this->tpl_name = 'acp_ext_disable'; + $template->assign_vars(array( 'U_RETURN' => $this->u_action . '&action=list', )); @@ -79,6 +86,7 @@ class acp_extensions case 'purge_pre': $this->tpl_name = 'acp_ext_purge'; + $template->assign_vars(array( 'PRE' => true, 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name, @@ -87,7 +95,9 @@ class acp_extensions case 'purge': $phpbb_extension_manager->purge($ext_name); + $this->tpl_name = 'acp_ext_purge'; + $template->assign_vars(array( 'U_RETURN' => $this->u_action . '&action=list', )); @@ -95,6 +105,7 @@ class acp_extensions case 'delete_pre': $this->tpl_name = 'acp_ext_delete'; + $template->assign_vars(array( 'PRE' => true, 'U_DELETE' => $this->u_action . '&action=delete&ext_name=' . $ext_name, @@ -106,9 +117,10 @@ class acp_extensions break; case 'details': - $filepath = $phpbb_root_path . 'ext/' . $ext_name . '/extension.json'; + $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template); + $md_manager->get_all_meta_data('all', true); + $this->tpl_name = 'acp_ext_details'; - $this->parse_meta_info($ext_name, $phpbb_extension_manager); break; } } @@ -120,6 +132,7 @@ class acp_extensions WHERE ext_active = 1 ORDER BY ext_name ASC'; $result = $db->sql_query($sql); + // TODO: Use the display name from the composer.json while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('enabled', array( @@ -142,6 +155,7 @@ class acp_extensions WHERE ext_active = 0 ORDER BY ext_name ASC'; $result = $db->sql_query($sql); + // TODO: Use the display name from the composer.json while ($row = $db->sql_fetchrow($result)) { $template->assign_block_vars('disabled', array( @@ -165,6 +179,8 @@ class acp_extensions $all_configured = array_keys($phpbb_extension_manager->all_configured()); $uninstalled = array_diff($all_available, $all_configured); + // TODO: Use the display name from the composer.json + foreach ($uninstalled as $ext) { $template->assign_block_vars('disabled', array( @@ -178,34 +194,4 @@ class acp_extensions return; } - - function parse_meta_info($ext_name, $phpbb_extension_manager) - { - $phpbb_extension_manager->get_meta_data($ext_name); - - $template->assign_vars(array( - 'NAME' => $metadata['name'], - 'TYPE' => $metadata['type'], - 'DESCRIPTION' => $metadata['description'], - 'HOMEPAGE' => $metadata['homepage'], - 'VERSION' => $metadata['version'], - 'TIME' => $metadata['time'], - 'LICENSE' => $metadata['licence'], - 'REQUIRE_PHP' => $metadata['require']['php'], - 'REQUIRE_PHPBB' => $metadata['require']['phpbb'], - 'DISPLAY_NAME' => $metadata['extra']['display-name'], - )); - - foreach ($metadata['authors'] as $author) - { - $template->assign_block_vars('authors', array( - 'AUTHOR_NAME' => $author['name'], - 'AUTHOR_EMAIL' => $author['email'], - 'AUTHOR_HOMEPAGE' => $author['homepage'], - 'AUTHOR_ROLE' => $author['role'], - )); - } - - return $metadata; - } } diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index db8d09b696..6ec5a0f76d 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -28,7 +28,7 @@ class phpbb_extension_metadata_manager protected $phpbb_root_path; protected $ext_name; protected $template; - protected $metadata; + public $metadata; protected $metadata_file; /** @@ -55,13 +55,13 @@ class phpbb_extension_metadata_manager * Processes and gets the metadata requested * * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @param bool $template_output True if you want the requested metadata assigned to template vars + * @param boolean $template_output True if you want the requested metadata assigned to template vars * @return array Contains all of the requested metadata */ - public function get_meta_data($element = 'all', $template_output = false) + public function get_metadata($element = 'all', $template_output = false) { // TODO: Check ext_name exists and is an extension that exists - if (!$this->set_meta_data_file()) + if (!$this->set_metadata_file()) { return false; } @@ -99,7 +99,7 @@ class phpbb_extension_metadata_manager return false; } break; - // TODO: Add remaining cases + // TODO: Add remaining cases as needed } } @@ -108,7 +108,7 @@ class phpbb_extension_metadata_manager * * @return boolean Set to true if it exists */ - private function set_meta_data_file() + private function set_metadata_file() { $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); $metadata_filepath = $this->phpbb_root_path . $ext_filepath . '/composer.json'; @@ -141,15 +141,14 @@ class phpbb_extension_metadata_manager // TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors // $this->metadata = $metadata_finished; - $metadata_finished = $this->metadata; - return $metadata_finished; + return $this->metadata; } /** * Validates the contents of the name field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_name() { @@ -159,7 +158,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the type field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_type() { @@ -169,7 +168,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the description field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_description() { @@ -179,27 +178,28 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the version field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_version() { - return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['version']); + return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}', $this->metadata['version']); } /** * Validates the contents of the license field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_license() { - return $this->metadata['license'] != 'GPLv2'; + // Nothing to validate except existence + return isset($this->metadata['version']); } /** * Validates the contents of the phpbb requirement field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_require_phpbb() { @@ -209,7 +209,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the display name field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_extra_display_name() { @@ -232,41 +232,60 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the php requirement field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_require_php() { - + return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb'] } /** * Validates the contents of the time field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_time() { - + // Need to validate + return true; } /** * Validates the contents of the homepage field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_homepage() { - + return preg_match('([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']) } /** * Validates the contents of the authors field * - * @return bool True when passes validation + * @return boolean True when passes validation */ private function validate_authors() { + // Need to validate + $number_authors = sizeof($this->metadata['authors']); // Might be helpful later on + + if (!isset($this->metadata['authors']['1'])) + { + return false; + } + else + { + foreach ($this->metadata['authors'] as $author) + { + if (!isset($author['name'])) + { + return false; + } + } + } + return true; } /** -- cgit v1.2.1 From dd4f07f9bb864bdac8b6c4009d166f1df6411419 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:18:11 +0100 Subject: [ticket/10631] Template shouldn't be required PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 6ec5a0f76d..fea66c86fe 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -27,7 +27,6 @@ class phpbb_extension_metadata_manager protected $db; protected $phpbb_root_path; protected $ext_name; - protected $template; public $metadata; protected $metadata_file; @@ -39,14 +38,13 @@ class phpbb_extension_metadata_manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php') { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->phpEx = $phpEx; $this->extension_manager = $extension_manager; $this->ext_name = $ext_name; - $this->template = $template; $this->metadata = array(); $this->metadata_file = ''; } @@ -58,7 +56,7 @@ class phpbb_extension_metadata_manager * @param boolean $template_output True if you want the requested metadata assigned to template vars * @return array Contains all of the requested metadata */ - public function get_metadata($element = 'all', $template_output = false) + public function get_metadata($element = 'all', $template_output = false, phpbb_template $template) { // TODO: Check ext_name exists and is an extension that exists if (!$this->set_metadata_file()) @@ -77,7 +75,7 @@ class phpbb_extension_metadata_manager if ($template_output) { - $this->output_template_data(); + $this->output_template_data($template); } return $this->metadata; @@ -88,7 +86,7 @@ class phpbb_extension_metadata_manager { if ($template_output) { - $this->template->assign_vars(array( + $template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), )); } @@ -309,7 +307,7 @@ class phpbb_extension_metadata_manager * * @return null */ - public function output_template_data() + public function output_template_data(phpbb_template $template) { $template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), -- cgit v1.2.1 From 0c18b16e284bef904943697561c6749511ac35ba Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:25:51 +0100 Subject: [ticket/10631] Adding docblocks PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index d52a65da67..7e3792c1c5 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -125,6 +125,13 @@ class acp_extensions } } + /** + * Lists all the enabled extensions and dumps to the template + * + * @param $db A database connection + * @param $template An instance of the template engine + * @return null + */ private function list_enabled_exts($db, $template) { $sql = 'SELECT ext_name @@ -148,6 +155,13 @@ class acp_extensions return; } + /** + * Lists all the disabled extensions and dumps to the template + * + * @param $db A database connection + * @param $template An instance of the template engine + * @return null + */ private function list_disabled_exts($db, $template) { $sql = 'SELECT ext_name @@ -172,6 +186,13 @@ class acp_extensions return; } + /** + * Lists all the available extensions and dumps to the template + * + * @param $db A database connection + * @param $template An instance of the template engine + * @return null + */ function list_available_exts($phpbb_extension_manager, $template) { $phpbb_extension_manager->load_extensions(); -- cgit v1.2.1 From c45243a91e142f1aa7a10e78c5ef4e91c4e18d9d Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 15:47:45 +0100 Subject: [ticket/10631] Fix so it installs the module in the correct place PHPBB3-10631 --- phpBB/includes/acp/info/acp_extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/info/acp_extensions.php b/phpBB/includes/acp/info/acp_extensions.php index 87e30bf25d..f5953fb1dd 100644 --- a/phpBB/includes/acp/info/acp_extensions.php +++ b/phpBB/includes/acp/info/acp_extensions.php @@ -19,7 +19,7 @@ class acp_extensions_info 'title' => 'ACP_EXTENSIONS', 'version' => '1.0.0', 'modes' => array( - 'main' => array('title' => 'ACP_EXTENSIONS', 'auth' => 'acl_a_extensions', 'cat' => array('ACP_CAT_SYSTEM')), + 'main' => array('title' => 'ACP_EXTENSIONS', 'auth' => 'acl_a_extensions', 'cat' => array('ACP_GENERAL_TASKS')), ), ); } -- cgit v1.2.1 From 3ba59c6362c955d1f9b59278f7dd19cdacecff99 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 18:11:56 -0500 Subject: [ticket/10631] Various tidbits and cleanup on the acp extensions manager PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 95 ++++++++++++--------------- phpBB/includes/extension/manager.php | 13 ++++ phpBB/includes/extension/metadata_manager.php | 64 ++++++++++++------ 3 files changed, 97 insertions(+), 75 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 7e3792c1c5..fba4605a8e 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -25,7 +25,7 @@ class acp_extensions function main() { // Start the page - global $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path; + global $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; $user->add_lang(array('install', 'acp/extensions')); @@ -39,8 +39,8 @@ class acp_extensions { case 'list': default: - $this->list_enabled_exts($db, $template); - $this->list_disabled_exts($db, $template); + $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->tpl_name = 'acp_ext_list'; @@ -103,7 +103,7 @@ class acp_extensions )); break; - case 'delete_pre': + /*case 'delete_pre': $this->tpl_name = 'acp_ext_delete'; $template->assign_vars(array( @@ -114,11 +114,15 @@ class acp_extensions case 'delete': $this->tpl_name = 'acp_ext_delete'; - break; + break;*/ case 'details': $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template); - $md_manager->get_all_meta_data('all', true); + + if ($md_manager->get_metadata('all', true) === false) + { + trigger_error('EXTENSION_INVALID'); + } $this->tpl_name = 'acp_ext_details'; break; @@ -128,91 +132,74 @@ class acp_extensions /** * Lists all the enabled extensions and dumps to the template * - * @param $db A database connection - * @param $template An instance of the template engine + * @param $phpbb_extension_manager An instance of the extension manager + * @param $template An instance of the template engine * @return null */ - private function list_enabled_exts($db, $template) + private function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { - $sql = 'SELECT ext_name - FROM ' . EXT_TABLE . ' - WHERE ext_active = 1 - ORDER BY ext_name ASC'; - $result = $db->sql_query($sql); - // TODO: Use the display name from the composer.json - while ($row = $db->sql_fetchrow($result)) + foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { + $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); + $template->assign_block_vars('enabled', array( - 'EXT_NAME' => $row['ext_name'], + 'EXT_NAME' => $md_manager->get_metadata('name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $row['ext_name'], - 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $row['ext_name'], - 'U_DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $row['ext_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, )); } - $db->sql_freeresult($result); - - return; } /** * Lists all the disabled extensions and dumps to the template * - * @param $db A database connection - * @param $template An instance of the template engine + * @param $phpbb_extension_manager An instance of the extension manager + * @param $template An instance of the template engine * @return null */ - private function list_disabled_exts($db, $template) + private function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { - $sql = 'SELECT ext_name - FROM ' . EXT_TABLE . ' - WHERE ext_active = 0 - ORDER BY ext_name ASC'; - $result = $db->sql_query($sql); - // TODO: Use the display name from the composer.json - while ($row = $db->sql_fetchrow($result)) + foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { + $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); + $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $row['ext_name'], + 'EXT_NAME' => $md_manager->get_metadata('name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $row['ext_name'], - 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $row['ext_name'], - 'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $row['ext_name'], - 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $row['ext_name'], + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, + //'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $name, + 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); } - $db->sql_freeresult($result); - - return; } /** * Lists all the available extensions and dumps to the template * - * @param $db A database connection - * @param $template An instance of the template engine + * @param $phpbb_extension_manager An instance of the extension manager + * @param $template An instance of the template engine * @return null */ - function list_available_exts($phpbb_extension_manager, $template) + function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { - $phpbb_extension_manager->load_extensions(); $all_available = array_keys($phpbb_extension_manager->all_available()); $all_configured = array_keys($phpbb_extension_manager->all_configured()); $uninstalled = array_diff($all_available, $all_configured); - // TODO: Use the display name from the composer.json - - foreach ($uninstalled as $ext) + foreach ($uninstalled as $name => $location) { + $md_manager = $phpbb_extension_manager->get_extension_metadata($ext, $template); + $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $ext['ext_name'], + 'EXT_NAME' => $md_manager->get_metadata('name'), - 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $ext['ext_name'], - 'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $ext['ext_name'], - 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $ext['ext_name'], + 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, + //'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $name, + 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); } - - return; } } diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 86d8fab64b..e7ceef6ad5 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -22,6 +22,7 @@ if (!defined('IN_PHPBB')) */ class phpbb_extension_manager { + protected $db; protected $cache; protected $php_ext; protected $extensions; @@ -120,6 +121,18 @@ class phpbb_extension_manager } } + /** + * Instantiates the metadata manager for the extension with the given name + * + * @param string $name The extension name + * @param string $template The template manager + * @return phpbb_extension_metadata_manager Instance of the metadata manager + */ + public function get_extension_metadata($name, phpbb_template $template) + { + return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->phpEx, $template); + } + /** * Runs a step of the extension enabling process. * diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index fea66c86fe..a9dcd89592 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -26,6 +26,7 @@ class phpbb_extension_metadata_manager protected $extension_manager; protected $db; protected $phpbb_root_path; + protected $template; protected $ext_name; public $metadata; protected $metadata_file; @@ -38,11 +39,12 @@ class phpbb_extension_metadata_manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php') + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; $this->phpEx = $phpEx; + $this->template = $template; $this->extension_manager = $extension_manager; $this->ext_name = $ext_name; $this->metadata = array(); @@ -56,7 +58,7 @@ class phpbb_extension_metadata_manager * @param boolean $template_output True if you want the requested metadata assigned to template vars * @return array Contains all of the requested metadata */ - public function get_metadata($element = 'all', $template_output = false, phpbb_template $template) + public function get_metadata($element = 'all', $template_output = false) { // TODO: Check ext_name exists and is an extension that exists if (!$this->set_metadata_file()) @@ -64,6 +66,11 @@ class phpbb_extension_metadata_manager return false; } + if (!$this->fetch_metadata()) + { + return false; + } + switch ($element) { case 'all': @@ -82,7 +89,7 @@ class phpbb_extension_metadata_manager break; case 'name': - if ($this->validate_name) + if ($this->validate_name()) { if ($template_output) { @@ -90,6 +97,7 @@ class phpbb_extension_metadata_manager 'MD_NAME' => htmlspecialchars($this->metadata['name']), )); } + return $this->metadata['name']; } else @@ -129,7 +137,7 @@ class phpbb_extension_metadata_manager * @return array Contains the cleaned and validated metadata array */ private function clean_metadata_array() - { + { if (!$this->validate_name() || !$this->validate_type() || !$this->validate_license() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) { return false; @@ -150,7 +158,7 @@ class phpbb_extension_metadata_manager */ private function validate_name() { - return preg_match('^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$', $this->metadata['name']); + return preg_match('#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', $this->metadata['name']); } /** @@ -160,7 +168,7 @@ class phpbb_extension_metadata_manager */ private function validate_type() { - return $this->metadata['type'] != 'phpbb3-extension'; + return $this->metadata['type'] == 'phpbb3-extension'; } /** @@ -170,7 +178,7 @@ class phpbb_extension_metadata_manager */ private function validate_description() { - return preg_match('^{10,}$', $this->metadata['description']); + return preg_match('#^{10,}$#', $this->metadata['description']); } /** @@ -180,7 +188,7 @@ class phpbb_extension_metadata_manager */ private function validate_version() { - return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}', $this->metadata['version']); + return preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}#', $this->metadata['version']); } /** @@ -201,7 +209,7 @@ class phpbb_extension_metadata_manager */ private function validate_require_phpbb() { - return (preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb']), '3.1.0', '>'); + return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb'], '3.1.0', '>=')); } /** @@ -211,7 +219,7 @@ class phpbb_extension_metadata_manager */ private function validate_extra_display_name() { - return preg_match('^[a-zA-Z0-9_]{2,0}$', $this->metadata['name']); + return preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); } /** @@ -234,7 +242,7 @@ class phpbb_extension_metadata_manager */ private function validate_require_php() { - return preg_match('^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$', $this->metadata['require']['phpbb'] + return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['php']) && version_compare($this->metadata['require']['php'], phpversion(), '>=')); } /** @@ -255,7 +263,7 @@ class phpbb_extension_metadata_manager */ private function validate_homepage() { - return preg_match('([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']) + return preg_match('#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']); } /** @@ -287,19 +295,32 @@ class phpbb_extension_metadata_manager } /** - * Gets the contents of the composer.json file and can also assign template vars + * Gets the contents of the composer.json file * - * @return array Contains everything from the meta data file. Do not use without validating and cleaning first + * @return bool True of false (if loading succeeded or failed) */ private function fetch_metadata() { - // Read it - $metadata_file = file_get_contents($metadata_filepath); - $metadata = json_decode($metadata_file, true) - - $this->metadata = $metadata; - - return $metadata; + if (!file_exists($this->metadata_file)) + { + return false; + } + else + { + if (!($file_contents = file_get_contents($this->metadata_file))) + { + return false; + } + + if (($metadata = json_decode($file_contents, true)) === NULL) + { + return false; + } + + $this->metadata = $metadata; + + return true; + } } /** @@ -334,3 +355,4 @@ class phpbb_extension_metadata_manager return; } +} -- cgit v1.2.1 From 6b12f71b94faa8cf0d7d65661650bb2d1e5381d9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 19:44:35 -0500 Subject: [ticket/10631] Fix list_available_exts PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index fba4605a8e..b65be0c641 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -185,13 +185,11 @@ class acp_extensions */ function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { - $all_available = array_keys($phpbb_extension_manager->all_available()); - $all_configured = array_keys($phpbb_extension_manager->all_configured()); - $uninstalled = array_diff($all_available, $all_configured); + $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($ext, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); $template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('name'), -- cgit v1.2.1 From bf6e91b5f3f6d56c1a38cbff0ccf206f13202e50 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 20:24:20 -0500 Subject: [ticket/10631] Fixing some more issues PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 35 ++++++++++++++------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index a9dcd89592..ddec918732 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -82,7 +82,7 @@ class phpbb_extension_metadata_manager if ($template_output) { - $this->output_template_data($template); + $this->output_template_data(); } return $this->metadata; @@ -138,7 +138,7 @@ class phpbb_extension_metadata_manager */ private function clean_metadata_array() { - if (!$this->validate_name() || !$this->validate_type() || !$this->validate_license() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) + if (!$this->validate_name() || !$this->validate_type() || !$this->validate_licence() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) { return false; } @@ -178,7 +178,7 @@ class phpbb_extension_metadata_manager */ private function validate_description() { - return preg_match('#^{10,}$#', $this->metadata['description']); + return true;//preg_match('#^{10,}$#', $this->metadata['description']); } /** @@ -196,10 +196,10 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_license() + private function validate_licence() { // Nothing to validate except existence - return isset($this->metadata['version']); + return isset($this->metadata['licence']); } /** @@ -219,7 +219,7 @@ class phpbb_extension_metadata_manager */ private function validate_extra_display_name() { - return preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); + return true;//preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); } /** @@ -328,31 +328,32 @@ class phpbb_extension_metadata_manager * * @return null */ - public function output_template_data(phpbb_template $template) + public function output_template_data() { - $template->assign_vars(array( + + $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), 'MD_DESCRIPTION' => htmlspecialchars($this->metadata['description']), - 'MD_HOMEPAGE' => $this->metadata['homepage'], + 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', 'MD_VERSION' => htmlspecialchars($this->metadata['version']), 'MD_TIME' => htmlspecialchars($this->metadata['time']), - 'MD_LICENSE' => htmlspecialchars($this->metadata['license']), - 'MD_REQUIRE_PHP' => htmlspecialchars($this->metadata['require']['php']), - 'MD_REQUIRE_PHPBB' => htmlspecialchars($this->metadata['require']['phpbb']), - 'MD_DISPLAY_NAME' => htmlspecialchars($this->metadata['extra']['display-name']), + 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), + 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); foreach ($this->metadata['authors'] as $author) { - $template->assign_block_vars('md_authors', array( + $this->template->assign_block_vars('md_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), 'AUTHOR_EMAIL' => $author['email'], - 'AUTHOR_HOMEPAGE' => $author['homepage'], - 'AUTHOR_ROLE' => htmlspecialchars($author['role']), + 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', + 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - + return; } } -- cgit v1.2.1 From 28ca2d6a5fe8f8f1d8733af70951fa1191336eb6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 22:54:27 -0500 Subject: [ticket/10631] Stagger the enable/disable/purge for extensions PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index b65be0c641..8cb6685d9f 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -56,7 +56,12 @@ class acp_extensions break; case 'enable': - $phpbb_extension_manager->enable($ext_name); + if ($phpbb_extension_manager->enable_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); + + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . $ext_name); + } $this->tpl_name = 'acp_ext_enable'; @@ -75,7 +80,12 @@ class acp_extensions break; case 'disable': - $phpbb_extension_manager->disable($ext_name); + if ($phpbb_extension_manager->disable_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); + + meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . $ext_name); + } $this->tpl_name = 'acp_ext_disable'; @@ -94,7 +104,12 @@ class acp_extensions break; case 'purge': - $phpbb_extension_manager->purge($ext_name); + if ($phpbb_extension_manager->purge_step($ext_name)) + { + $template->assign_var('S_NEXT_STEP', true); + + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . $ext_name); + } $this->tpl_name = 'acp_ext_purge'; -- cgit v1.2.1 From 74492b3cdda9538263484a6f2a2042ac1900228a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 14:01:13 -0500 Subject: [ticket/10631] Use display name if available PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 6 +++--- phpBB/includes/extension/metadata_manager.php | 19 ++++++++----------- 2 files changed, 11 insertions(+), 14 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 8cb6685d9f..c4d9497956 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -158,7 +158,7 @@ class acp_extensions $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); $template->assign_block_vars('enabled', array( - 'EXT_NAME' => $md_manager->get_metadata('name'), + '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, @@ -181,7 +181,7 @@ class acp_extensions $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('name'), + '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, @@ -207,7 +207,7 @@ class acp_extensions $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('name'), + 'EXT_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, //'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $name, diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index ddec918732..6af02e47b7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -55,7 +55,7 @@ class phpbb_extension_metadata_manager * Processes and gets the metadata requested * * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @param boolean $template_output True if you want the requested metadata assigned to template vars + * @param boolean $template_output True if you want the requested metadata assigned to template vars (only works on the 'all" case * @return array Contains all of the requested metadata */ public function get_metadata($element = 'all', $template_output = false) @@ -89,20 +89,17 @@ class phpbb_extension_metadata_manager break; case 'name': - if ($this->validate_name()) + return ($this->validate_name()) ? $this->metadata['name'] : false; + break; + + case 'display-name': + if ($this->validate_extra_display_name()) { - if ($template_output) - { - $template->assign_vars(array( - 'MD_NAME' => htmlspecialchars($this->metadata['name']), - )); - } - - return $this->metadata['name']; + return $this->metadata['extra']['display-name']; } else { - return false; + return ($this->validate_name()) ? $this->metadata['name'] : false; } break; // TODO: Add remaining cases as needed -- cgit v1.2.1 From 8bbab088dd5830d8dd1151a3684dde5c197ba268 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:17:42 -0500 Subject: [ticket/10631] Validation for extensions PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 53 +++-- phpBB/includes/extension/manager.php | 7 +- phpBB/includes/extension/metadata_manager.php | 298 ++++++++++++++++---------- 3 files changed, 219 insertions(+), 139 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index c4d9497956..ce32640c33 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -25,7 +25,7 @@ class acp_extensions function main() { // Start the page - global $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; + global $config, $user, $template, $request, $phpbb_extension_manager, $db, $phpbb_root_path, $phpEx; $user->add_lang(array('install', 'acp/extensions')); @@ -34,6 +34,17 @@ class acp_extensions $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); + // If they've specificed an extension, let's load the metadata manager and validate it. + if ($ext_name) + { + $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'); + } + } + // What are we doing? switch ($action) { @@ -47,6 +58,11 @@ class acp_extensions break; case 'enable_pre': + if (!$md_manager->validate_enable()) + { + trigger_error('EXTENSION_NOT_AVAILABLE'); + } + $this->tpl_name = 'acp_ext_enable'; $template->assign_vars(array( @@ -56,10 +72,15 @@ class acp_extensions break; case 'enable': + if (!$md_manager->validate_enable()) + { + trigger_error('EXTENSION_NOT_AVAILABLE'); + } + if ($phpbb_extension_manager->enable_step($ext_name)) { $template->assign_var('S_NEXT_STEP', true); - + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . $ext_name); } @@ -76,14 +97,14 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name, - )); - break; + )); + break; case 'disable': if ($phpbb_extension_manager->disable_step($ext_name)) { $template->assign_var('S_NEXT_STEP', true); - + meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . $ext_name); } @@ -101,13 +122,13 @@ class acp_extensions 'PRE' => true, 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name, )); - break; + break; case 'purge': if ($phpbb_extension_manager->purge_step($ext_name)) { $template->assign_var('S_NEXT_STEP', true); - + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . $ext_name); } @@ -132,12 +153,8 @@ class acp_extensions break;*/ case 'details': - $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template); - - if ($md_manager->get_metadata('all', true) === false) - { - trigger_error('EXTENSION_INVALID'); - } + // Output it to the template + $md_manager->output_template_data(); $this->tpl_name = 'acp_ext_details'; break; @@ -146,7 +163,7 @@ class acp_extensions /** * Lists all the enabled extensions and dumps to the template - * + * * @param $phpbb_extension_manager An instance of the extension manager * @param $template An instance of the template engine * @return null @@ -156,7 +173,7 @@ class acp_extensions foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); - + $template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -169,7 +186,7 @@ class acp_extensions /** * Lists all the disabled extensions and dumps to the template - * + * * @param $phpbb_extension_manager An instance of the extension manager * @param $template An instance of the template engine * @return null @@ -179,7 +196,7 @@ class acp_extensions foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); - + $template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -193,7 +210,7 @@ class acp_extensions /** * Lists all the available extensions and dumps to the template - * + * * @param $phpbb_extension_manager An instance of the extension manager * @param $template An instance of the template engine * @return null diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index e7ceef6ad5..9dfc0a067c 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -23,6 +23,7 @@ if (!defined('IN_PHPBB')) class phpbb_extension_manager { protected $db; + protected $config; protected $cache; protected $php_ext; protected $extensions; @@ -34,16 +35,18 @@ class phpbb_extension_manager * Creates a manager and loads information from database * * @param dbal $db A database connection + * @param phpbb_config $config phpbb_config * @param string $extension_table The name of the table holding extensions * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $php_ext php file extension * @param phpbb_cache_driver_interface $cache A cache instance or null * @param string $cache_name The name of the cache variable, defaults to _ext */ - public function __construct(dbal $db, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') + public function __construct(dbal $db, phpbb_config $config, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext') { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; + $this->config = $config; $this->cache = $cache; $this->php_ext = $php_ext; $this->extension_table = $extension_table; @@ -130,7 +133,7 @@ class phpbb_extension_manager */ public function get_extension_metadata($name, phpbb_template $template) { - return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->phpEx, $template); + return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } /** diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 6af02e47b7..0e0b609a68 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -31,18 +31,71 @@ class phpbb_extension_metadata_manager public $metadata; protected $metadata_file; + /** + * Array of validation regular expressions, see __call() + * + * @var mixed + */ + protected $validation = array( + 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', + 'type' => '#^phpbb3-extension$#', + 'description' => '#.*#', + 'version' => '#.+#', + 'licence' => '#.+#', + 'extra' => array( + 'display-name' => '#.*#', + ), + ); + + /** + * Magic method to catch validation calls + * + * @param string $name + * @param mixed $arguments + * @return int + */ + public function __call($name, $arguments) + { + // Validation Magic methods + if (strpos($name, 'validate_') === 0) + { + // Remove validate_ + $name = substr($name, 9); + + // Replace underscores with dashes (underscores are not used) + $name = str_replace('_', '-', $name); + + if (strpos($name, 'extra-') === 0) + { + // Remove extra_ + $name = substr($name, 6); + + if (isset($this->validation['extra'][$name])) + { + // Extra means it's optional, so return true if it does not exist + return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; + } + } + else if (isset($this->validation[$name])) + { + return preg_match($this->validation[$name], $this->metadata[$name]); + } + } + } + /** * Creates the metadata manager - * + * * @param dbal $db A database connection * @param string $extension_manager An instance of the phpbb extension manager * @param string $phpbb_root_path Path to the phpbb includes directory. * @param string $phpEx php file extension */ - public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template) + public function __construct($ext_name, dbal $db, phpbb_extension_manager $extension_manager, $phpbb_root_path, $phpEx = '.php', phpbb_template $template, phpbb_config $config) { $this->phpbb_root_path = $phpbb_root_path; $this->db = $db; + $this->config = $config; $this->phpEx = $phpEx; $this->template = $template; $this->extension_manager = $extension_manager; @@ -53,12 +106,11 @@ class phpbb_extension_metadata_manager /** * Processes and gets the metadata requested - * - * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @param boolean $template_output True if you want the requested metadata assigned to template vars (only works on the 'all" case - * @return array Contains all of the requested metadata + * + * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. + * @return bool|array Contains all of the requested metadata or bool False if not valid */ - public function get_metadata($element = 'all', $template_output = false) + public function get_metadata($element = 'all') { // TODO: Check ext_name exists and is an extension that exists if (!$this->set_metadata_file()) @@ -66,34 +118,37 @@ class phpbb_extension_metadata_manager return false; } + // Fetch the metadata if (!$this->fetch_metadata()) { return false; } - switch ($element) + // Clean the metadata + if (!$this->clean_metadata_array()) + { + return false; + } + + switch ($element) { case 'all': default: - if (!$this->clean_metadata_array()) + // Validate the metadata + if (!$this->validate_metadata_array()) { return false; } - if ($template_output) - { - $this->output_template_data(); - } - return $this->metadata; break; - + case 'name': return ($this->validate_name()) ? $this->metadata['name'] : false; break; - + case 'display-name': - if ($this->validate_extra_display_name()) + if (isset($this->metadata['extra']['display-name']) && $this->validate_extra_display_name()) { return $this->metadata['extra']['display-name']; } @@ -108,7 +163,7 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file - * + * * @return boolean Set to true if it exists */ private function set_metadata_file() @@ -129,122 +184,156 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation and cleaning of the array - * - * @return array Contains the cleaned and validated metadata array + * Gets the contents of the composer.json file + * + * @return bool True of false (if loading succeeded or failed) */ - private function clean_metadata_array() - { - if (!$this->validate_name() || !$this->validate_type() || !$this->validate_licence() || !$this->validate_description() || !$this->validate_version() || !$this->validate_require_phpbb() || !$this->validate_extra_display_name()) + private function fetch_metadata() + { + if (!file_exists($this->metadata_file)) { return false; } - - $this->check_for_optional(true); + else + { + if (!($file_contents = file_get_contents($this->metadata_file))) + { + return false; + } -// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors -// $this->metadata = $metadata_finished; + if (($metadata = json_decode($file_contents, true)) === NULL) + { + return false; + } - return $this->metadata; - } + $this->metadata = $metadata; - /** - * Validates the contents of the name field - * - * @return boolean True when passes validation - */ - private function validate_name() - { - return preg_match('#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', $this->metadata['name']); + return true; + } } /** - * Validates the contents of the type field - * - * @return boolean True when passes validation + * This array handles the validation and cleaning of the array + * + * @return array Contains the cleaned and validated metadata array */ - private function validate_type() + private function clean_metadata_array() { - return $this->metadata['type'] == 'phpbb3-extension'; - } +// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors +// $this->metadata = $metadata_finished; - /** - * Validates the contents of the description field - * - * @return boolean True when passes validation - */ - private function validate_description() - { - return true;//preg_match('#^{10,}$#', $this->metadata['description']); + return $this->metadata; } /** - * Validates the contents of the version field - * - * @return boolean True when passes validation + * This array handles the validation of strings + * + * @return bool True if validation succeeded, False if failed */ - private function validate_version() + public function validate_metadata_array() { - return preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}#', $this->metadata['version']); + $validate = array( + 'name', + 'type', + 'licence', + 'description', + 'version', + 'extra_display-name', + ); + + foreach ($validate as $type) + { + $type = 'validate_' . $type; + + if (!$this->$type()) + { + return false; + } + } + + return true; } /** - * Validates the contents of the license field - * - * @return boolean True when passes validation + * This array handles the verification that this extension can be enabled on this board + * + * @return bool True if validation succeeded, False if failed */ - private function validate_licence() + public function validate_enable() { - // Nothing to validate except existence - return isset($this->metadata['licence']); + $validate = array( + 'require_phpbb', + 'require_php', + ); + + foreach ($validate as $type) + { + $type = 'validate_' . $type; + + if (!$this->$type()) + { + return false; + } + } + + return true; } + /** * Validates the contents of the phpbb requirement field - * + * * @return boolean True when passes validation */ private function validate_require_phpbb() { - return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['phpbb']) && version_compare($this->metadata['require']['phpbb'], '3.1.0', '>=')); + if (!isset($this->metadata['require']['phpbb'])) + { + return true; + } + + return $this->_validate_version($this->metadata['require']['phpbb'], $this->config['version']); } /** - * Validates the contents of the display name field - * + * Validates the contents of the php requirement field + * * @return boolean True when passes validation */ - private function validate_extra_display_name() + private function validate_require_php() { - return true;//preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); + if (!isset($this->metadata['require']['php'])) + { + return true; + } + + return $this->_validate_version($this->metadata['require']['php'], phpversion()); } /** - * Checks which optional fields exist - * - * @return boolean False if any that exist fail validation, otherwise true. - */ - public function check_for_optional() + * Version validation helper + * + * @param string $string The string for comparing to a version + * @param string $current_version The version to compare to + * @return bool True/False if meets version requirements + */ + private function _validate_version($string, $current_version) { - if ((isset($this->metadata['require']['php']) && !$this->validate_require_php()) || (isset($this->metadata['time']) && !$this->validate_time()) || (isset($this->metadata['validate_homepage']) && !$this->validate_homepage())) + // Allow them to specify their own comparison operator (ex: <3.1.2, >=3.1.0) + $comparison_matches = false; + preg_match('#[=<>]+#', $string, $comparison_matches); + + if (!empty($comparison_matches)) { - return false; + return version_compare($current_version, str_replace(array($comparison_matches[0], ' '), '', $string), $comparison_matches[0]); } - } - /** - * Validates the contents of the php requirement field - * - * @return boolean True when passes validation - */ - private function validate_require_php() - { - return (preg_match('#^[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{1,2}$#', $this->metadata['require']['php']) && version_compare($this->metadata['require']['php'], phpversion(), '>=')); + return version_compare($current_version, $string, '>='); } /** * Validates the contents of the time field - * + * * @return boolean True when passes validation */ private function validate_time() @@ -255,7 +344,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the homepage field - * + * * @return boolean True when passes validation */ private function validate_homepage() @@ -265,7 +354,7 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the authors field - * + * * @return boolean True when passes validation */ private function validate_authors() @@ -291,38 +380,9 @@ class phpbb_extension_metadata_manager return true; } - /** - * Gets the contents of the composer.json file - * - * @return bool True of false (if loading succeeded or failed) - */ - private function fetch_metadata() - { - if (!file_exists($this->metadata_file)) - { - return false; - } - else - { - if (!($file_contents = file_get_contents($this->metadata_file))) - { - return false; - } - - if (($metadata = json_decode($file_contents, true)) === NULL) - { - return false; - } - - $this->metadata = $metadata; - - return true; - } - } - /** * Outputs the metadata into the template - * + * * @return null */ public function output_template_data() @@ -350,7 +410,7 @@ class phpbb_extension_metadata_manager 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - + return; } } -- cgit v1.2.1 From 4314284de12ceac5ae0792f3f4014b765d75d332 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:22:48 -0500 Subject: [ticket/10631] Remove code duplication PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 33 ++++++++++++++++----------- 1 file changed, 20 insertions(+), 13 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 0e0b609a68..c5e9baf1e7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -232,22 +232,29 @@ class phpbb_extension_metadata_manager */ public function validate_metadata_array() { - $validate = array( - 'name', - 'type', - 'licence', - 'description', - 'version', - 'extra_display-name', - ); - - foreach ($validate as $type) + foreach ($this->validation as $name => $regex) { - $type = 'validate_' . $type; + if (is_array($regex)) + { + foreach ($regex as $extra_name => $extra_regex) + { + $type = 'validate_' . $name . '_' . $extra_name; - if (!$this->$type()) + if (!$this->$type()) + { + return false; + } + } + } + else { - return false; + + $type = 'validate_' . $name; + + if (!$this->$type()) + { + return false; + } } } -- cgit v1.2.1 From 8df9963fcc7e2962b6b4e1e32e809f2d8fe00835 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:39:13 -0500 Subject: [ticket/10631] Additional validation PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 76 +++++++++------------------ 1 file changed, 25 insertions(+), 51 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index c5e9baf1e7..d2dc72e5fc 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -42,6 +42,7 @@ class phpbb_extension_metadata_manager 'description' => '#.*#', 'version' => '#.+#', 'licence' => '#.+#', + //'homepage' => '#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(? array( 'display-name' => '#.*#', ), @@ -76,7 +77,7 @@ class phpbb_extension_metadata_manager return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; } } - else if (isset($this->validation[$name])) + else if (isset($this->validation[$name]) && isset($this->metadata[$name])) { return preg_match($this->validation[$name], $this->metadata[$name]); } @@ -258,6 +259,29 @@ class phpbb_extension_metadata_manager } } + return $this->validate_authors(); + } + + /** + * Validates the contents of the authors field + * + * @return boolean True when passes validation + */ + private function validate_authors() + { + if (empty($this->metadata['authors'])) + { + return false; + } + + foreach ($this->metadata['authors'] as $author) + { + if (!isset($author['name'])) + { + return false; + } + } + return true; } @@ -338,55 +362,6 @@ class phpbb_extension_metadata_manager return version_compare($current_version, $string, '>='); } - /** - * Validates the contents of the time field - * - * @return boolean True when passes validation - */ - private function validate_time() - { - // Need to validate - return true; - } - - /** - * Validates the contents of the homepage field - * - * @return boolean True when passes validation - */ - private function validate_homepage() - { - return preg_match('#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(?metadata['homepage']); - } - - /** - * Validates the contents of the authors field - * - * @return boolean True when passes validation - */ - private function validate_authors() - { - // Need to validate - $number_authors = sizeof($this->metadata['authors']); // Might be helpful later on - - if (!isset($this->metadata['authors']['1'])) - { - return false; - } - else - { - foreach ($this->metadata['authors'] as $author) - { - if (!isset($author['name'])) - { - return false; - } - } - } - - return true; - } - /** * Outputs the metadata into the template * @@ -394,7 +369,6 @@ class phpbb_extension_metadata_manager */ public function output_template_data() { - $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), -- cgit v1.2.1 From 2273ae2b34071160ff930ca8d49326b8dd308899 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 17:05:03 -0500 Subject: [ticket/10631] Remove references to delete extension PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index ce32640c33..0e1d5c88a8 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -139,19 +139,6 @@ class acp_extensions )); break; - /*case 'delete_pre': - $this->tpl_name = 'acp_ext_delete'; - - $template->assign_vars(array( - 'PRE' => true, - 'U_DELETE' => $this->u_action . '&action=delete&ext_name=' . $ext_name, - )); - break; - - case 'delete': - $this->tpl_name = 'acp_ext_delete'; - break;*/ - case 'details': // Output it to the template $md_manager->output_template_data(); @@ -202,7 +189,6 @@ class acp_extensions 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, 'U_PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, - //'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $name, 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); } @@ -227,7 +213,6 @@ class acp_extensions 'EXT_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . $name, - //'U_DELETE' => $this->u_action . '&action=delete_pre&ext_name=' . $name, 'U_ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); } -- cgit v1.2.1 From 106c105113886f9a9e603dbb11549c06049b255f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 18:22:35 -0500 Subject: [ticket/10631] Fix some issues as noted in github comments, significantly simplified validation PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 12 +-- phpBB/includes/extension/manager.php | 2 +- phpBB/includes/extension/metadata_manager.php | 144 ++++++++------------------ 3 files changed, 50 insertions(+), 108 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 0e1d5c88a8..0e825514e6 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -155,11 +155,11 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - private function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); $template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -178,11 +178,11 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - private function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); $template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -201,13 +201,13 @@ class acp_extensions * @param $template An instance of the template engine * @return null */ - function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) + public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager, phpbb_template $template) { $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($name, $template); + $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $template); $template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 9dfc0a067c..9342c936f9 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -131,7 +131,7 @@ class phpbb_extension_manager * @param string $template The template manager * @return phpbb_extension_metadata_manager Instance of the metadata manager */ - public function get_extension_metadata($name, phpbb_template $template) + public function get_extension_metadata_manager($name, phpbb_template $template) { return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index d2dc72e5fc..aa163b1190 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -28,62 +28,9 @@ class phpbb_extension_metadata_manager protected $phpbb_root_path; protected $template; protected $ext_name; - public $metadata; + protected $metadata; protected $metadata_file; - /** - * Array of validation regular expressions, see __call() - * - * @var mixed - */ - protected $validation = array( - 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', - 'type' => '#^phpbb3-extension$#', - 'description' => '#.*#', - 'version' => '#.+#', - 'licence' => '#.+#', - //'homepage' => '#([\d\w-.]+?\.(a[cdefgilmnoqrstuwz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvxyz]|d[ejkmnoz]|e[ceghrst]|f[ijkmnor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdghklmnopqrstuvwxyz]|n[acefgilopruz]|om|p[aefghklmnrstwy]|qa|r[eouw]|s[abcdeghijklmnortuvyz]|t[cdfghjkmnoprtvwz]|u[augkmsyz]|v[aceginu]|w[fs]|y[etu]|z[amw]|aero|arpa|biz|com|coop|edu|info|int|gov|mil|museum|name|net|org|pro)(\b|\W(? array( - 'display-name' => '#.*#', - ), - ); - - /** - * Magic method to catch validation calls - * - * @param string $name - * @param mixed $arguments - * @return int - */ - public function __call($name, $arguments) - { - // Validation Magic methods - if (strpos($name, 'validate_') === 0) - { - // Remove validate_ - $name = substr($name, 9); - - // Replace underscores with dashes (underscores are not used) - $name = str_replace('_', '-', $name); - - if (strpos($name, 'extra-') === 0) - { - // Remove extra_ - $name = substr($name, 6); - - if (isset($this->validation['extra'][$name])) - { - // Extra means it's optional, so return true if it does not exist - return (isset($this->metadata['extra'][$name])) ? preg_match($this->validation['extra'][$name], $this->metadata['extra'][$name]) : true; - } - } - else if (isset($this->validation[$name]) && isset($this->metadata[$name])) - { - return preg_match($this->validation[$name], $this->metadata[$name]); - } - } - } - /** * Creates the metadata manager * @@ -136,7 +83,7 @@ class phpbb_extension_metadata_manager case 'all': default: // Validate the metadata - if (!$this->validate_metadata_array()) + if (!$this->validate()) { return false; } @@ -145,17 +92,17 @@ class phpbb_extension_metadata_manager break; case 'name': - return ($this->validate_name()) ? $this->metadata['name'] : false; + return ($this->validate('name')) ? $this->metadata['name'] : false; break; case 'display-name': - if (isset($this->metadata['extra']['display-name']) && $this->validate_extra_display_name()) + if (isset($this->metadata['extra']['display-name'])) { return $this->metadata['extra']['display-name']; } else { - return ($this->validate_name()) ? $this->metadata['name'] : false; + return ($this->validate('name')) ? $this->metadata['name'] : false; } break; // TODO: Add remaining cases as needed @@ -216,7 +163,7 @@ class phpbb_extension_metadata_manager /** * This array handles the validation and cleaning of the array * - * @return array Contains the cleaned and validated metadata array + * @return array Contains the cleaned metadata array */ private function clean_metadata_array() { @@ -227,40 +174,44 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation of strings - * - * @return bool True if validation succeeded, False if failed - */ - public function validate_metadata_array() - { - foreach ($this->validation as $name => $regex) - { - if (is_array($regex)) - { - foreach ($regex as $extra_name => $extra_regex) - { - $type = 'validate_' . $name . '_' . $extra_name; + * Validate fields + * + * @param string $name ("all" for display and enable validation + * "display" for name, type, and authors + * "name", "type") + * @return Bool False if validation fails, true if valid + */ + public function validate($name = 'display') + { + // Basic fields + $fields = array( + 'name' => '#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', + 'type' => '#^phpbb3-extension$#', + 'licence' => '#.+#', + 'version' => '#.+#', + ); + + if (isset($fields[$name])) + { + return (isset($this->metadata[$name])) ? (bool) preg_match($this->validation[$name], $this->metadata[$name]) : false; + } - if (!$this->$type()) - { - return false; - } - } - } - else + // Validate all fields + if ($name == 'all') + { + foreach ($fields as $field => $data) { - - $type = 'validate_' . $name; - - if (!$this->$type()) + if (!$this->validate($field)) { return false; } } + + return $this->validate_authors(); } - return $this->validate_authors(); - } + return true; + } /** * Validates the contents of the authors field @@ -292,19 +243,10 @@ class phpbb_extension_metadata_manager */ public function validate_enable() { - $validate = array( - 'require_phpbb', - 'require_php', - ); - - foreach ($validate as $type) + // Check for phpBB, PHP versions + if (!$this->validate_require_phpbb || !$this->validate_require_php) { - $type = 'validate_' . $type; - - if (!$this->$type()) - { - return false; - } + return false; } return true; @@ -372,10 +314,10 @@ class phpbb_extension_metadata_manager $this->template->assign_vars(array( 'MD_NAME' => htmlspecialchars($this->metadata['name']), 'MD_TYPE' => htmlspecialchars($this->metadata['type']), - 'MD_DESCRIPTION' => htmlspecialchars($this->metadata['description']), + 'MD_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', - 'MD_VERSION' => htmlspecialchars($this->metadata['version']), - 'MD_TIME' => htmlspecialchars($this->metadata['time']), + 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', + 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', @@ -386,7 +328,7 @@ class phpbb_extension_metadata_manager { $this->template->assign_block_vars('md_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), - 'AUTHOR_EMAIL' => $author['email'], + 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); -- cgit v1.2.1 From 89f4cf6a8c10f9b0875cf7f278016aff67eb38fc Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 19:46:21 -0500 Subject: [ticket/10631] Use exceptions for errors. Build action list dynamically. PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 111 +++++++++++++++++++------- phpBB/includes/exception/metadata.php | 69 ++++++++++++++++ phpBB/includes/extension/metadata_manager.php | 72 ++++++++--------- 3 files changed, 188 insertions(+), 64 deletions(-) create mode 100644 phpBB/includes/exception/metadata.php (limited to 'phpBB/includes') 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, )); } } diff --git a/phpBB/includes/exception/metadata.php b/phpBB/includes/exception/metadata.php new file mode 100644 index 0000000000..93cc337f55 --- /dev/null +++ b/phpBB/includes/exception/metadata.php @@ -0,0 +1,69 @@ +code = $code; + $this->field_name = $field_name; + } + + public function __toString() + { + return sprintf($this->getErrorMessage(), $this->field_name); + } + + public function getErrorMessage() + { + switch ($this->code) + { + case self::NOT_SET: + return 'The "%s" meta field has not been set.'; + break; + + case self::INVALID: + return 'The "%s" meta field is not valid.'; + break; + + case self::FILE_GET_CONTENTS: + return 'file_get_contents failed on %s'; + break; + + case self::JSON_DECODE: + return 'json_decode failed on %s'; + break; + + case self::FILE_DOES_NOT_EXIST: + return 'Required file does not exist at %s'; + break; + + default: + return 'An unexpected error has occurred.'; + break; + } + } +} \ No newline at end of file diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index aa163b1190..126331ce1c 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -56,27 +56,18 @@ class phpbb_extension_metadata_manager * Processes and gets the metadata requested * * @param string $element All for all metadata that it has and is valid, otherwise specify which section you want by its shorthand term. - * @return bool|array Contains all of the requested metadata or bool False if not valid + * @return array Contains all of the requested metadata, throws an exception on failure */ public function get_metadata($element = 'all') { // TODO: Check ext_name exists and is an extension that exists - if (!$this->set_metadata_file()) - { - return false; - } + $this->set_metadata_file(); // Fetch the metadata - if (!$this->fetch_metadata()) - { - return false; - } + $this->fetch_metadata(); // Clean the metadata - if (!$this->clean_metadata_array()) - { - return false; - } + $this->clean_metadata_array(); switch ($element) { @@ -112,46 +103,42 @@ class phpbb_extension_metadata_manager /** * Sets the filepath of the metadata file * - * @return boolean Set to true if it exists + * @return boolean Set to true if it exists, throws an exception on failure */ private function set_metadata_file() { $ext_filepath = $this->extension_manager->get_extension_path($this->ext_name); - $metadata_filepath = $this->phpbb_root_path . $ext_filepath . '/composer.json'; + $metadata_filepath = $this->phpbb_root_path . $ext_filepath . 'composer.json'; $this->metadata_file = $metadata_filepath; if (!file_exists($this->metadata_file)) { - return false; - } - else - { - return true; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); } } /** * Gets the contents of the composer.json file * - * @return bool True of false (if loading succeeded or failed) + * @return bool True if success, throws an exception on failure */ private function fetch_metadata() { if (!file_exists($this->metadata_file)) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_GET_CONTENTS, $this->metadata_file); } if (($metadata = json_decode($file_contents, true)) === NULL) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::JSON_DECODE, $this->metadata_file); } $this->metadata = $metadata; @@ -161,7 +148,7 @@ class phpbb_extension_metadata_manager } /** - * This array handles the validation and cleaning of the array + * This array handles the cleaning of the array * * @return array Contains the cleaned metadata array */ @@ -179,7 +166,7 @@ class phpbb_extension_metadata_manager * @param string $name ("all" for display and enable validation * "display" for name, type, and authors * "name", "type") - * @return Bool False if validation fails, true if valid + * @return Bool True if valid, throws an exception if invalid */ public function validate($name = 'display') { @@ -193,21 +180,34 @@ class phpbb_extension_metadata_manager if (isset($fields[$name])) { - return (isset($this->metadata[$name])) ? (bool) preg_match($this->validation[$name], $this->metadata[$name]) : false; + if (!isset($this->metadata[$name])) + { + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, $name); + } + + if (!preg_match($fields[$name], $this->metadata[$name])) + { + throw new phpbb_exception_metadata(phpbb_exception_metadata::INVALID, $name); + } } // Validate all fields if ($name == 'all') + { + $this->validate('display'); + + $this->validate_enable(); + } + + // Validate display fields + if ($name == 'display') { foreach ($fields as $field => $data) { - if (!$this->validate($field)) - { - return false; - } + $this->validate($field); } - return $this->validate_authors(); + $this->validate_authors(); } return true; @@ -216,20 +216,20 @@ class phpbb_extension_metadata_manager /** * Validates the contents of the authors field * - * @return boolean True when passes validation + * @return boolean True when passes validation, throws exception if invalid */ private function validate_authors() { if (empty($this->metadata['authors'])) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'authors'); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - return false; + throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'author name'); } } @@ -244,7 +244,7 @@ class phpbb_extension_metadata_manager public function validate_enable() { // Check for phpBB, PHP versions - if (!$this->validate_require_phpbb || !$this->validate_require_php) + if (!$this->validate_require_phpbb() || !$this->validate_require_php()) { return false; } -- cgit v1.2.1 From 2a7e1292919ed1397a3f1951e510d84565d002d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:28:04 -0500 Subject: [ticket/10631] Simplify exceptions PHPBB-10631 --- phpBB/includes/acp/acp_extensions.php | 28 +++++++---- phpBB/includes/exception/metadata.php | 69 --------------------------- phpBB/includes/extension/exception.php | 27 +++++++++++ phpBB/includes/extension/metadata_manager.php | 16 +++---- 4 files changed, 55 insertions(+), 85 deletions(-) delete mode 100644 phpBB/includes/exception/metadata.php create mode 100644 phpBB/includes/extension/exception.php (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index a833c8c482..287074395d 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -49,9 +49,12 @@ class acp_extensions { $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); - try{ + try + { $md_manager->get_metadata('all'); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { trigger_error($e); } } @@ -172,7 +175,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('enabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -183,7 +187,9 @@ class acp_extensions 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . $name, 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); @@ -204,7 +210,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -215,7 +222,9 @@ class acp_extensions 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); @@ -238,7 +247,8 @@ class acp_extensions { $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); - try { + try + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $md_manager->get_metadata('display-name'), @@ -248,7 +258,9 @@ class acp_extensions $this->output_actions('disabled', array( 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, )); - } catch( Exception $e ) { + } + catch(phpbb_extension_exception $e) + { $this->template->assign_block_vars('disabled', array( 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); diff --git a/phpBB/includes/exception/metadata.php b/phpBB/includes/exception/metadata.php deleted file mode 100644 index 93cc337f55..0000000000 --- a/phpBB/includes/exception/metadata.php +++ /dev/null @@ -1,69 +0,0 @@ -code = $code; - $this->field_name = $field_name; - } - - public function __toString() - { - return sprintf($this->getErrorMessage(), $this->field_name); - } - - public function getErrorMessage() - { - switch ($this->code) - { - case self::NOT_SET: - return 'The "%s" meta field has not been set.'; - break; - - case self::INVALID: - return 'The "%s" meta field is not valid.'; - break; - - case self::FILE_GET_CONTENTS: - return 'file_get_contents failed on %s'; - break; - - case self::JSON_DECODE: - return 'json_decode failed on %s'; - break; - - case self::FILE_DOES_NOT_EXIST: - return 'Required file does not exist at %s'; - break; - - default: - return 'An unexpected error has occurred.'; - break; - } - } -} \ No newline at end of file diff --git a/phpBB/includes/extension/exception.php b/phpBB/includes/extension/exception.php new file mode 100644 index 0000000000..e08a8912ea --- /dev/null +++ b/phpBB/includes/extension/exception.php @@ -0,0 +1,27 @@ +getMessage(); + } +} \ No newline at end of file diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 126331ce1c..27b04d4c08 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -114,7 +114,7 @@ class phpbb_extension_metadata_manager if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } } @@ -127,18 +127,18 @@ class phpbb_extension_metadata_manager { if (!file_exists($this->metadata_file)) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_DOES_NOT_EXIST, $this->metadata_file); + throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file); } else { if (!($file_contents = file_get_contents($this->metadata_file))) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::FILE_GET_CONTENTS, $this->metadata_file); + throw new phpbb_extension_exception('file_get_contents failed on ' . $this->metadata_file); } if (($metadata = json_decode($file_contents, true)) === NULL) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::JSON_DECODE, $this->metadata_file); + throw new phpbb_extension_exception('json_decode failed on ' . $this->metadata_file); } $this->metadata = $metadata; @@ -182,12 +182,12 @@ class phpbb_extension_metadata_manager { if (!isset($this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, $name); + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); } if (!preg_match($fields[$name], $this->metadata[$name])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::INVALID, $name); + throw new phpbb_extension_exception("Meta field '$name' is invalid."); } } @@ -222,14 +222,14 @@ class phpbb_extension_metadata_manager { if (empty($this->metadata['authors'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'authors'); + throw new phpbb_extension_exception("Required meta field 'authors' has not been set."); } foreach ($this->metadata['authors'] as $author) { if (!isset($author['name'])) { - throw new phpbb_exception_metadata(phpbb_exception_metadata::NOT_SET, 'author name'); + throw new phpbb_extension_exception("Required meta field 'author name' has not been set."); } } -- cgit v1.2.1 From 747c16240fd56be0e24b4c54f01c82aa0a78b91e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:40:54 -0500 Subject: [ticket/10631] get_extension_metadata_manager -> create_extension_metadata_manager PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 6 +++--- phpBB/includes/extension/manager.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 287074395d..4f59ea309b 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -173,7 +173,7 @@ class acp_extensions { foreach ($phpbb_extension_manager->all_enabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); try { @@ -208,7 +208,7 @@ class acp_extensions { foreach ($phpbb_extension_manager->all_disabled() as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); try { @@ -245,7 +245,7 @@ class acp_extensions foreach ($uninstalled as $name => $location) { - $md_manager = $phpbb_extension_manager->get_extension_metadata_manager($name, $this->template); + $md_manager = $phpbb_extension_manager->create_extension_metadata_manager($name, $this->template); try { diff --git a/phpBB/includes/extension/manager.php b/phpBB/includes/extension/manager.php index 9342c936f9..9a518c215f 100644 --- a/phpBB/includes/extension/manager.php +++ b/phpBB/includes/extension/manager.php @@ -131,7 +131,7 @@ class phpbb_extension_manager * @param string $template The template manager * @return phpbb_extension_metadata_manager Instance of the metadata manager */ - public function get_extension_metadata_manager($name, phpbb_template $template) + public function create_extension_metadata_manager($name, phpbb_template $template) { return new phpbb_extension_metadata_manager($name, $this->db, $this, $this->phpbb_root_path, $this->php_ext, $template, $this->config); } -- cgit v1.2.1 From 500879520c40a71f0b83799ab3e59c86c12a801a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 28 Jul 2012 14:59:55 -0500 Subject: [ticket/10631] Metadata manager tests PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 59 ++++++++++++++------------- 1 file changed, 30 insertions(+), 29 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 27b04d4c08..c7f52b7c02 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -178,36 +178,37 @@ class phpbb_extension_metadata_manager 'version' => '#.+#', ); - if (isset($fields[$name])) + switch ($name) { - if (!isset($this->metadata[$name])) - { - throw new phpbb_extension_exception("Required meta field '$name' has not been set."); - } - - if (!preg_match($fields[$name], $this->metadata[$name])) - { - throw new phpbb_extension_exception("Meta field '$name' is invalid."); - } - } - - // Validate all fields - if ($name == 'all') - { - $this->validate('display'); + case 'all': + $this->validate('display'); - $this->validate_enable(); - } + $this->validate_enable(); + break; - // Validate display fields - if ($name == 'display') - { - foreach ($fields as $field => $data) - { - $this->validate($field); - } + case 'display': + foreach ($fields as $field => $data) + { + $this->validate($field); + } - $this->validate_authors(); + $this->validate_authors(); + break; + + default: + if (isset($fields[$name])) + { + if (!isset($this->metadata[$name])) + { + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); + } + + if (!preg_match($fields[$name], $this->metadata[$name])) + { + throw new phpbb_extension_exception("Meta field '$name' is invalid."); + } + } + break; } return true; @@ -218,7 +219,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation, throws exception if invalid */ - private function validate_authors() + public function validate_authors() { if (empty($this->metadata['authors'])) { @@ -258,7 +259,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_require_phpbb() + public function validate_require_phpbb() { if (!isset($this->metadata['require']['phpbb'])) { @@ -273,7 +274,7 @@ class phpbb_extension_metadata_manager * * @return boolean True when passes validation */ - private function validate_require_php() + public function validate_require_php() { if (!isset($this->metadata['require']['php'])) { -- cgit v1.2.1 From 36465c9a205c356b0662e45b4fded79c4b476547 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 29 Jul 2012 20:08:30 -0500 Subject: [ticket/10631] Functional acp_extensions test, cleanup PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 38 ++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 4f59ea309b..c4d9f0c0e0 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -72,7 +72,7 @@ class acp_extensions break; case 'enable_pre': - if (!$md_manager->validate_enable()) + if (!$md_manager->validate_enable() || $phpbb_extension_manager->enabled($ext_name)) { trigger_error('EXTENSION_NOT_AVAILABLE'); } @@ -81,7 +81,7 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, - 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . $ext_name, + 'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name), )); break; @@ -95,7 +95,7 @@ class acp_extensions { $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . $ext_name); + meta_refresh(0, $this->u_action . '&action=enable&ext_name=' . urlencode($ext_name)); } $this->tpl_name = 'acp_ext_enable'; @@ -106,11 +106,16 @@ class acp_extensions break; case 'disable_pre': + if (!$phpbb_extension_manager->enabled($ext_name)) + { + trigger_error('EXTENSION_NOT_AVAILABLE'); + } + $this->tpl_name = 'acp_ext_disable'; $template->assign_vars(array( 'PRE' => true, - 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name, + 'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name), )); break; @@ -119,7 +124,7 @@ class acp_extensions { $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . $ext_name); + meta_refresh(0, $this->u_action . '&action=disable&ext_name=' . urlencode($ext_name)); } $this->tpl_name = 'acp_ext_disable'; @@ -134,7 +139,7 @@ class acp_extensions $template->assign_vars(array( 'PRE' => true, - 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name, + 'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name), )); break; @@ -143,7 +148,7 @@ class acp_extensions { $template->assign_var('S_NEXT_STEP', true); - meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . $ext_name); + meta_refresh(0, $this->u_action . '&action=purge&ext_name=' . urlencode($ext_name)); } $this->tpl_name = 'acp_ext_purge'; @@ -166,7 +171,6 @@ class acp_extensions * Lists all the enabled extensions and dumps to the template * * @param $phpbb_extension_manager An instance of the extension manager - * @param $template An instance of the template engine * @return null */ public function list_enabled_exts(phpbb_extension_manager $phpbb_extension_manager) @@ -180,12 +184,12 @@ class acp_extensions $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_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($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, + 'DISABLE' => $this->u_action . '&action=disable_pre&ext_name=' . urlencode($name), + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . urlencode($name), )); } catch(phpbb_extension_exception $e) @@ -201,7 +205,6 @@ class acp_extensions * Lists all the disabled extensions and dumps to the template * * @param $phpbb_extension_manager An instance of the extension manager - * @param $template An instance of the template engine * @return null */ public function list_disabled_exts(phpbb_extension_manager $phpbb_extension_manager) @@ -215,12 +218,12 @@ class acp_extensions $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_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($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, + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name), + 'PURGE' => $this->u_action . '&action=purge_pre&ext_name=' . urlencode($name), )); } catch(phpbb_extension_exception $e) @@ -236,7 +239,6 @@ class acp_extensions * Lists all the available extensions and dumps to the template * * @param $phpbb_extension_manager An instance of the extension manager - * @param $template An instance of the template engine * @return null */ public function list_available_exts(phpbb_extension_manager $phpbb_extension_manager) @@ -252,11 +254,11 @@ class acp_extensions $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_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); $this->output_actions('disabled', array( - 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . $name, + 'ENABLE' => $this->u_action . '&action=enable_pre&ext_name=' . urlencode($name), )); } catch(phpbb_extension_exception $e) -- cgit v1.2.1 From dce04b2d03f93c9237b743afbcbd89fb6405f836 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 19:30:49 -0500 Subject: [ticket/10631] Various front-end fixes (extensions manager) Add Back button from details Add cancel button from actions Correct language strings PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index c4d9f0c0e0..1a9d51505a 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -43,6 +43,13 @@ class acp_extensions $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); + + // Cancel action + if ($request->is_set_post('cancel')) + { + $action = 'list'; + $ext_name = ''; + } // If they've specificed an extension, let's load the metadata manager and validate it. if ($ext_name) @@ -162,6 +169,8 @@ class acp_extensions // Output it to the template $md_manager->output_template_data(); + $template->assign_var('U_BACK', $this->u_action . '&action=list'); + $this->tpl_name = 'acp_ext_details'; break; } -- cgit v1.2.1 From 7b643fe8a5fd3b92bb4db9eacb27645417004709 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 5 Aug 2012 19:00:20 -0500 Subject: [ticket/10631] Make failure to meet ext enable requirements clearer Turn the blocks red on the details page if requirement is not met. Also changing a how the errors come up when trying to enable/disable an extension when they cannot be. PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 15 ++++++++++----- phpBB/includes/extension/metadata_manager.php | 9 +++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 1a9d51505a..8dde6bc36c 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -43,7 +43,7 @@ class acp_extensions $action = $request->variable('action', 'list'); $ext_name = $request->variable('ext_name', ''); - + // Cancel action if ($request->is_set_post('cancel')) { @@ -79,9 +79,14 @@ class acp_extensions break; case 'enable_pre': - if (!$md_manager->validate_enable() || $phpbb_extension_manager->enabled($ext_name)) + if (!$md_manager->validate_enable()) + { + trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); + } + + if ($phpbb_extension_manager->enabled($ext_name)) { - trigger_error('EXTENSION_NOT_AVAILABLE'); + redirect($this->u_action); } $this->tpl_name = 'acp_ext_enable'; @@ -95,7 +100,7 @@ class acp_extensions case 'enable': if (!$md_manager->validate_enable()) { - trigger_error('EXTENSION_NOT_AVAILABLE'); + trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); } if ($phpbb_extension_manager->enable_step($ext_name)) @@ -115,7 +120,7 @@ class acp_extensions case 'disable_pre': if (!$phpbb_extension_manager->enabled($ext_name)) { - trigger_error('EXTENSION_NOT_AVAILABLE'); + redirect($this->u_action); } $this->tpl_name = 'acp_ext_disable'; diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index c7f52b7c02..8a68e464a7 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -320,8 +320,13 @@ class phpbb_extension_metadata_manager 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), - 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', - 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + + 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'MD_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), + + 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'MD_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), + 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); -- cgit v1.2.1 From 323bbf9b523984a592dc17bf35d2bb91a435be1b Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:06:23 +0100 Subject: [ticket/10631] Adjust prefixes to be easier to understand PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 12 ++++++------ phpBB/includes/extension/metadata_manager.php | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 19 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 8dde6bc36c..5a537aaa42 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -196,7 +196,7 @@ class acp_extensions try { $this->template->assign_block_vars('enabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); @@ -209,7 +209,7 @@ class acp_extensions catch(phpbb_extension_exception $e) { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); } } @@ -230,7 +230,7 @@ class acp_extensions try { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); @@ -243,7 +243,7 @@ class acp_extensions catch(phpbb_extension_exception $e) { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); } } @@ -266,7 +266,7 @@ class acp_extensions try { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $md_manager->get_metadata('display-name'), + 'META_DISPLAY_NAME' => $md_manager->get_metadata('display-name'), 'U_DETAILS' => $this->u_action . '&action=details&ext_name=' . urlencode($name), )); @@ -278,7 +278,7 @@ class acp_extensions catch(phpbb_extension_exception $e) { $this->template->assign_block_vars('disabled', array( - 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + 'META_DISPLAY_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), )); } } diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 8a68e464a7..1e3bbe48c9 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -313,26 +313,26 @@ class phpbb_extension_metadata_manager public function output_template_data() { $this->template->assign_vars(array( - 'MD_NAME' => htmlspecialchars($this->metadata['name']), - 'MD_TYPE' => htmlspecialchars($this->metadata['type']), - 'MD_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', - 'MD_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', - 'MD_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', - 'MD_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', - 'MD_LICENCE' => htmlspecialchars($this->metadata['licence']), + 'META_NAME' => htmlspecialchars($this->metadata['name']), + 'META_TYPE' => htmlspecialchars($this->metadata['type']), + 'META_DESCRIPTION' => (isset($this->metadata['description'])) ? htmlspecialchars($this->metadata['description']) : '', + 'META_HOMEPAGE' => (isset($this->metadata['homepage'])) ? $this->metadata['homepage'] : '', + 'META_VERSION' => (isset($this->metadata['version'])) ? htmlspecialchars($this->metadata['version']) : '', + 'META_TIME' => (isset($this->metadata['time'])) ? htmlspecialchars($this->metadata['time']) : '', + 'META_LICENCE' => htmlspecialchars($this->metadata['licence']), - 'MD_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', - 'MD_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), + 'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '', + 'META_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), - 'MD_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', - 'MD_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), + 'META_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '', + 'META_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), - 'MD_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', + 'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? htmlspecialchars($this->metadata['extra']['display-name']) : '', )); foreach ($this->metadata['authors'] as $author) { - $this->template->assign_block_vars('md_authors', array( + $this->template->assign_block_vars('meta_authors', array( 'AUTHOR_NAME' => htmlspecialchars($author['name']), 'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '', 'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '', -- cgit v1.2.1 From f05a175e3955d1dc1d2b85b9929ca4b30340ad4a Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:38:03 +0100 Subject: [ticket/10631] Fixing a few extension admin issues PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 3 --- 1 file changed, 3 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 1e3bbe48c9..8c570830fe 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -60,7 +60,6 @@ class phpbb_extension_metadata_manager */ public function get_metadata($element = 'all') { - // TODO: Check ext_name exists and is an extension that exists $this->set_metadata_file(); // Fetch the metadata @@ -339,7 +338,5 @@ class phpbb_extension_metadata_manager 'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '', )); } - - return; } } -- cgit v1.2.1 From 0c35ee2769d3945f25275d5ee7a130b7596d289f Mon Sep 17 00:00:00 2001 From: "Michael C." Date: Sat, 1 Sep 2012 17:32:59 +0200 Subject: [ticket/10631] Fix a spelling typo PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index 5a537aaa42..a0bcf62ecc 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -51,7 +51,7 @@ class acp_extensions $ext_name = ''; } - // If they've specificed an extension, let's load the metadata manager and validate it. + // If they've specified an extension, let's load the metadata manager and validate it. if ($ext_name) { $md_manager = new phpbb_extension_metadata_manager($ext_name, $db, $phpbb_extension_manager, $phpbb_root_path, ".$phpEx", $template, $config); -- cgit v1.2.1 From 81f7f28cc33d896973c2912097103ea84fa14114 Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Sat, 1 Sep 2012 21:30:35 +0100 Subject: [ticket/10631] Removing un-needed TODOs that are no longer needed. PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 4 ---- 1 file changed, 4 deletions(-) (limited to 'phpBB/includes') diff --git a/phpBB/includes/extension/metadata_manager.php b/phpBB/includes/extension/metadata_manager.php index 8c570830fe..ea85bd3c4e 100644 --- a/phpBB/includes/extension/metadata_manager.php +++ b/phpBB/includes/extension/metadata_manager.php @@ -95,7 +95,6 @@ class phpbb_extension_metadata_manager return ($this->validate('name')) ? $this->metadata['name'] : false; } break; - // TODO: Add remaining cases as needed } } @@ -153,9 +152,6 @@ class phpbb_extension_metadata_manager */ private function clean_metadata_array() { -// TODO: Remove all parts of the array we don't want or shouldn't be there due to nub mod authors -// $this->metadata = $metadata_finished; - return $this->metadata; } -- cgit v1.2.1