From 5e6b4c7192a80dc29382ad06976e9ce6d5c16efd Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Wed, 29 Feb 2012 21:23:50 +0000 Subject: [PATCH 01/48] [ticket/10631] Adding an extensions admin PHPBB3-10631 --- phpBB/adm/style/acp_ext_delete.html | 27 ++ phpBB/adm/style/acp_ext_disable.html | 27 ++ phpBB/adm/style/acp_ext_enable.html | 27 ++ phpBB/adm/style/acp_ext_list.html | 60 +++++ phpBB/adm/style/acp_ext_purge.html | 27 ++ phpBB/includes/acp/acp_extensions.php | 265 ++++++++++++++++++++ phpBB/includes/acp/info/acp_extensions.php | 34 +++ phpBB/install/schemas/schema_data.sql | 1 + phpBB/language/en/acp/common.php | 1 + phpBB/language/en/acp/customisations.php | 100 ++++++++ phpBB/language/en/acp/permissions_phpbb.php | 1 + 11 files changed, 570 insertions(+) create mode 100644 phpBB/adm/style/acp_ext_delete.html create mode 100644 phpBB/adm/style/acp_ext_disable.html create mode 100644 phpBB/adm/style/acp_ext_enable.html create mode 100644 phpBB/adm/style/acp_ext_list.html create mode 100644 phpBB/adm/style/acp_ext_purge.html create mode 100644 phpBB/includes/acp/acp_extensions.php create mode 100644 phpBB/includes/acp/info/acp_extensions.php create mode 100644 phpBB/language/en/acp/customisations.php diff --git a/phpBB/adm/style/acp_ext_delete.html b/phpBB/adm/style/acp_ext_delete.html new file mode 100644 index 0000000000..1ce99b8905 --- /dev/null +++ b/phpBB/adm/style/acp_ext_delete.html @@ -0,0 +1,27 @@ + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+

{L_ENABLE_EXPLAIN}

+ + +

{L_DELETE_CONFIRM}

+ +
+
+ {L_DELETE} + +
+
+ +
+

{L_DELETE_SUCESS}

+
+

{L_RETURN}

+
+ + + \ No newline at end of file diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html new file mode 100644 index 0000000000..2198db09a1 --- /dev/null +++ b/phpBB/adm/style/acp_ext_disable.html @@ -0,0 +1,27 @@ + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+

{L_ENABLE_EXPLAIN}

+ + +

{L_DISABLE_CONFIRM}

+ +
+
+ {L_DISABLE} + +
+
+ +
+

{L_DISABLE_SUCESS}

+
+

{L_RETURN}

+
+ + + \ No newline at end of file diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html new file mode 100644 index 0000000000..4c94ce7b2b --- /dev/null +++ b/phpBB/adm/style/acp_ext_enable.html @@ -0,0 +1,27 @@ + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+

{L_ENABLE_EXPLAIN}

+ + +

{L_ENABLE_CONFIRM}

+ +
+
+ {L_ENABLE} + +
+
+ +
+

{L_ENABLE_SUCESS}

+
+

{L_RETURN}

+
+ + + \ No newline at end of file diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html new file mode 100644 index 0000000000..7058c9c7f7 --- /dev/null +++ b/phpBB/adm/style/acp_ext_list.html @@ -0,0 +1,60 @@ + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{L_EXTENSION_NAME}{L_EXTENSION_OPTIONS}{L_EXTENSION_ACTIONS}
+ {L_ENABLED} {L_EXTENSIONS} +
{enabled.EXT_NAME}{L_DETAILS}{L_DISABLE} | {L_PURGE}
{L_DISABLED} {L_EXTENSIONS}
{disabled.EXT_NAME}{L_DETAILS}{L_ENABLE} | {L_PURGE} | {L_DELETE}
{L_AVALIABLE} {L_EXTENSIONS}
{avaliable.EXT_NAME}{L_DETAILS}{L_ENABLE} | {L_DELETE}
+ + \ No newline at end of file diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html new file mode 100644 index 0000000000..c73bbe6e00 --- /dev/null +++ b/phpBB/adm/style/acp_ext_purge.html @@ -0,0 +1,27 @@ + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+

{L_ENABLE_EXPLAIN}

+ + +

{L_PURGE_CONFIRM}

+ +
+
+ {L_PURGE} + +
+
+ +
+

{L_PURGE_SUCESS}

+
+

{L_RETURN}

+
+ + + \ No newline at end of file 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() + { + } +} diff --git a/phpBB/install/schemas/schema_data.sql b/phpBB/install/schemas/schema_data.sql index ea7864bd4c..ae7b9fcba3 100644 --- a/phpBB/install/schemas/schema_data.sql +++ b/phpBB/install/schemas/schema_data.sql @@ -345,6 +345,7 @@ INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_board', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_bots', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_clearlogs', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_email', 1); +INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_extensions', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_fauth', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_forum', 1); INSERT INTO phpbb_acl_options (auth_option, is_global) VALUES ('a_forumadd', 1); diff --git a/phpBB/language/en/acp/common.php b/phpBB/language/en/acp/common.php index 04df897dba..5eb10d50b3 100644 --- a/phpBB/language/en/acp/common.php +++ b/phpBB/language/en/acp/common.php @@ -81,6 +81,7 @@ $lang = array_merge($lang, array( 'ACP_EMAIL_SETTINGS' => 'Email settings', 'ACP_EXTENSION_GROUPS' => 'Manage extension groups', + 'ACP_EXTENSIONS' => 'Manage board extensions', 'ACP_FORUM_BASED_PERMISSIONS' => 'Forum based permissions', 'ACP_FORUM_LOGS' => 'Forum logs', diff --git a/phpBB/language/en/acp/customisations.php b/phpBB/language/en/acp/customisations.php new file mode 100644 index 0000000000..7ba463bc81 --- /dev/null +++ b/phpBB/language/en/acp/customisations.php @@ -0,0 +1,100 @@ + 'Extension', + 'EXTENSIONS' => 'Extensions', + 'EXTENSIONS_ADMIN' => 'Extensions Admin', + 'EXTENSIONS_EXPLAIN' => 'The Extensions Admin is a tool in your phpBB Board which allows you to manage all of your extensions. For more information about extensions please visit this page on phpBBs Offical Website.', + + 'DETAILS' => 'Details', + + 'AVALIABLE' => 'Avaliable', + 'ENABLED' => 'Enabled', + 'DISBALED' => 'Disabled', + + 'ENABLE' => 'Enable', + 'DISABLE' => 'Disable', + 'PURGE' => 'Purge', + 'DELETE' => 'Delete', + + 'ENABLED' => 'Enabled', + 'DISABLED' => 'Disabled', + 'PURGED' => 'Purged', + 'DELETED' => 'Deleted', + + 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', + 'DISABLE_EXPLAIN' => 'Disabling an extension keeps the files and data intact but is not working on your board.', + 'PURGE_EXPLAIN' => 'Purging an extension keeps the files but not the data on your board.', + 'DELETE_EXPLAIN' => 'Deleting an extension removes all traces of the extension except from your logs.', + + 'ENABLE_SUCESS' => 'Your extension was enabled sucessfully', + 'DISABLE_SUCESS' => 'Your extension was disabled sucessfully', + 'PURGE_SUCESS' => 'Your extension was purged sucessfully', + 'DELETE_SUCESS' => 'Your extension was deleted sucessfully', + + 'ENABLE_FAIL' => 'Your extension could not be enabled', + 'DISABLE_FAIL' => 'Your extension could not be disabled', + 'PURGE_FAIL' => 'Your extension could not be purged', + 'DELETE_FAIL' => 'Your extension could not be deleted', + + 'EXTENSION_NAME' => 'Extension Name', + 'EXTENSION_ACTIONS' => 'Actions', + 'EXTENSION_OPTIONS' => 'Options', + + 'ENABLE_CONFIRM' => 'Are you sure you wish to enable this extension?', + 'DISABLE_CONFIRM' => 'Are your sure you wish to disable this extension?', + 'PURGE_CONFIRM' => 'Are you sure you wish to purge (and not disable) this extension? This action will wipe the extension data on this board and is not reversible.', + 'DELETE_CONFIRM' => 'Are you sure you wish to delete (and not purge or disable) this extension? This action will remove the extension and all of its data from this board and is not reversible.', + + 'WARNING' => 'Warning', + 'RETURN' => 'Return', + + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', + '' => '', +)); + +?> \ No newline at end of file diff --git a/phpBB/language/en/acp/permissions_phpbb.php b/phpBB/language/en/acp/permissions_phpbb.php index 17649693fa..bb068e625f 100644 --- a/phpBB/language/en/acp/permissions_phpbb.php +++ b/phpBB/language/en/acp/permissions_phpbb.php @@ -226,6 +226,7 @@ $lang = array_merge($lang, array( 'acl_a_switchperm' => array('lang' => 'Can use others permissions', 'cat' => 'permissions'), 'acl_a_styles' => array('lang' => 'Can manage styles', 'cat' => 'misc'), + 'acl_a_extensions' => array('lang' => 'Can manage extensions', 'cat' => 'misc'), 'acl_a_viewlogs' => array('lang' => 'Can view logs', 'cat' => 'misc'), 'acl_a_clearlogs' => array('lang' => 'Can clear logs', 'cat' => 'misc'), 'acl_a_modules' => array('lang' => 'Can manage modules', 'cat' => 'misc'), From 8824ccb3921345359eec56eabc64d7a7bbf18c52 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 4 Mar 2012 15:40:40 +0000 Subject: [PATCH 02/48] [ticket/10631] Add an extension details page PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 97 ++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 phpBB/adm/style/acp_ext_details.html diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html new file mode 100644 index 0000000000..397610d83b --- /dev/null +++ b/phpBB/adm/style/acp_ext_details.html @@ -0,0 +1,97 @@ + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+ +
+ {L_EXT_DETAILS} +
+
+
{DISPLAY_NAME}
+
+
+
+
{NAME}
+
+
+
+

{TYPE}

+
+
+
+

{DESCRIPTION}

+
+
+
+

{VERSION}

+
+
+
+

{HOMEPAGE}

+
+ +
+
+

{TIME}

+
+
+
+

{LICENCE}

+
+
+ +
+ {L_REQUIREMENTS} + +
+
+

{REQUIRE_PHPBB}

+
+ + +
+
+

{REQUIRE_PHP}

+
+ +
+ +
+ {L_AUTHOR_INFORMATION} + +
+
+
{authors.AUTHOR_NAME}
+
+
+
+
{authors.AUTHOR_USERNAME}
+
+ +
+
+
{authors.AUTHOR_EMAIL}
+
+ + +
+
+
{authors.AUTHOR_HOMEPAGE}
+
+ + +
+
+
{authors.AUTHOR_ROLE}
+
+ + +
+ + \ No newline at end of file From 29a9f3e70d0a165a33e50cce5d275e1a5090c989 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 4 Mar 2012 15:51:57 +0000 Subject: [PATCH 03/48] [ticket/10631] Update extensions admin language Added details page information, added a new line at end of file and removed some whitespace. PHPBB3-10631 --- phpBB/language/en/acp/customisations.php | 54 ++++++++++++++---------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/phpBB/language/en/acp/customisations.php b/phpBB/language/en/acp/customisations.php index 7ba463bc81..e45fcb843d 100644 --- a/phpBB/language/en/acp/customisations.php +++ b/phpBB/language/en/acp/customisations.php @@ -39,38 +39,38 @@ $lang = array_merge($lang, array( 'EXTENSIONS' => 'Extensions', 'EXTENSIONS_ADMIN' => 'Extensions Admin', 'EXTENSIONS_EXPLAIN' => 'The Extensions Admin is a tool in your phpBB Board which allows you to manage all of your extensions. For more information about extensions please visit this page on phpBBs Offical Website.', - + 'DETAILS' => 'Details', - + 'AVALIABLE' => 'Avaliable', 'ENABLED' => 'Enabled', 'DISBALED' => 'Disabled', - + 'ENABLE' => 'Enable', 'DISABLE' => 'Disable', 'PURGE' => 'Purge', 'DELETE' => 'Delete', - + 'ENABLED' => 'Enabled', 'DISABLED' => 'Disabled', 'PURGED' => 'Purged', 'DELETED' => 'Deleted', - + 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', 'DISABLE_EXPLAIN' => 'Disabling an extension keeps the files and data intact but is not working on your board.', 'PURGE_EXPLAIN' => 'Purging an extension keeps the files but not the data on your board.', 'DELETE_EXPLAIN' => 'Deleting an extension removes all traces of the extension except from your logs.', - + 'ENABLE_SUCESS' => 'Your extension was enabled sucessfully', 'DISABLE_SUCESS' => 'Your extension was disabled sucessfully', 'PURGE_SUCESS' => 'Your extension was purged sucessfully', 'DELETE_SUCESS' => 'Your extension was deleted sucessfully', - + 'ENABLE_FAIL' => 'Your extension could not be enabled', 'DISABLE_FAIL' => 'Your extension could not be disabled', 'PURGE_FAIL' => 'Your extension could not be purged', 'DELETE_FAIL' => 'Your extension could not be deleted', - + 'EXTENSION_NAME' => 'Extension Name', 'EXTENSION_ACTIONS' => 'Actions', 'EXTENSION_OPTIONS' => 'Options', @@ -79,22 +79,30 @@ $lang = array_merge($lang, array( 'DISABLE_CONFIRM' => 'Are your sure you wish to disable this extension?', 'PURGE_CONFIRM' => 'Are you sure you wish to purge (and not disable) this extension? This action will wipe the extension data on this board and is not reversible.', 'DELETE_CONFIRM' => 'Are you sure you wish to delete (and not purge or disable) this extension? This action will remove the extension and all of its data from this board and is not reversible.', - + 'WARNING' => 'Warning', 'RETURN' => 'Return', - - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', - '' => '', + + 'EXT_DETAILS' => 'Extension Details', + 'DISPLAY_NAME' => 'Display Name', + 'CLEAN_NAME' => 'Clean Name', + 'TYPE' => 'Type', + 'DESCRIPTION' => 'Description', + 'VERSION' => 'Version', + 'HOMEPAGE' => 'Homepage', + 'PATH' => 'File Path', + 'TIME' => 'Release Time', + 'LICENCE' => 'Licence', + + 'REQUIREMENTS' => 'Requirements', + 'PHPBB_VERSION' => 'phpBB Version', + 'PHP_VERSION' => 'php Version', + 'AUTHOR_INFORMATION' => 'Author Information', + 'AUTHOR_NAME' => 'Author Name', + 'AUTHOR_USERNAME' => 'Author Username', + 'AUTHOR_EMAIL' => 'Author Email', + 'AUTHOR_HOMEPAGE' => 'Author Homepage', + 'AUTHOR_ROLE' => 'Author Role', )); -?> \ No newline at end of file +?> From 305b5fe93906838b8b963570da077539715ad13f Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 4 Mar 2012 16:00:43 +0000 Subject: [PATCH 04/48] [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(-) 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"], )); } } From a51ef4444719c8a50f6fe8ea909ce55ec41e5835 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 4 Mar 2012 16:04:18 +0000 Subject: [PATCH 05/48] [ticket/10631] Some rewording of extensions admin language PHPBB3-10631 --- phpBB/language/en/acp/customisations.php | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/phpBB/language/en/acp/customisations.php b/phpBB/language/en/acp/customisations.php index e45fcb843d..5b15ae7655 100644 --- a/phpBB/language/en/acp/customisations.php +++ b/phpBB/language/en/acp/customisations.php @@ -57,19 +57,19 @@ $lang = array_merge($lang, array( 'DELETED' => 'Deleted', 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', - 'DISABLE_EXPLAIN' => 'Disabling an extension keeps the files and data intact but is not working on your board.', - 'PURGE_EXPLAIN' => 'Purging an extension keeps the files but not the data on your board.', - 'DELETE_EXPLAIN' => 'Deleting an extension removes all traces of the extension except from your logs.', + 'DISABLE_EXPLAIN' => 'Disabling an extension retains its files and settings but removes any functionality added by the extension.', + 'PURGE_EXPLAIN' => 'Purging an extension clears an extensions data while retaining its files.', + 'DELETE_EXPLAIN' => 'Deleting an extension removes all of its files and settings. Log entries will remain, although any language variables added by the extension will not be available.', - 'ENABLE_SUCESS' => 'Your extension was enabled sucessfully', - 'DISABLE_SUCESS' => 'Your extension was disabled sucessfully', - 'PURGE_SUCESS' => 'Your extension was purged sucessfully', - 'DELETE_SUCESS' => 'Your extension was deleted sucessfully', + 'ENABLE_SUCESS' => 'The extension was enabled sucessfully', + 'DISABLE_SUCESS' => 'The extension was disabled sucessfully', + 'PURGE_SUCESS' => 'The extension was purged sucessfully', + 'DELETE_SUCESS' => 'The extension was deleted sucessfully', - 'ENABLE_FAIL' => 'Your extension could not be enabled', - 'DISABLE_FAIL' => 'Your extension could not be disabled', - 'PURGE_FAIL' => 'Your extension could not be purged', - 'DELETE_FAIL' => 'Your extension could not be deleted', + 'ENABLE_FAIL' => 'The extension could not be enabled', + 'DISABLE_FAIL' => 'The extension could not be disabled', + 'PURGE_FAIL' => 'The extension could not be purged', + 'DELETE_FAIL' => 'The extension could not be deleted', 'EXTENSION_NAME' => 'Extension Name', 'EXTENSION_ACTIONS' => 'Actions', @@ -77,8 +77,8 @@ $lang = array_merge($lang, array( 'ENABLE_CONFIRM' => 'Are you sure you wish to enable this extension?', 'DISABLE_CONFIRM' => 'Are your sure you wish to disable this extension?', - 'PURGE_CONFIRM' => 'Are you sure you wish to purge (and not disable) this extension? This action will wipe the extension data on this board and is not reversible.', - 'DELETE_CONFIRM' => 'Are you sure you wish to delete (and not purge or disable) this extension? This action will remove the extension and all of its data from this board and is not reversible.', + 'PURGE_CONFIRM' => 'Are you sure you wish to purge this extensions data? This cannot be undone.', + 'DELETE_CONFIRM' => 'Are you sure you wish to data this extensions files and clear its data? This cannot be undone.', 'WARNING' => 'Warning', 'RETURN' => 'Return', From 85e871e902454d14321f69e162a92746c46f7d65 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 4 Mar 2012 16:21:11 +0000 Subject: [PATCH 06/48] [ticket/10631] Removing ?> at end of customisations language file PHPBB3-10631 --- phpBB/language/en/acp/customisations.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/phpBB/language/en/acp/customisations.php b/phpBB/language/en/acp/customisations.php index 5b15ae7655..e20806eac2 100644 --- a/phpBB/language/en/acp/customisations.php +++ b/phpBB/language/en/acp/customisations.php @@ -104,5 +104,3 @@ $lang = array_merge($lang, array( 'AUTHOR_HOMEPAGE' => 'Author Homepage', 'AUTHOR_ROLE' => 'Author Role', )); - -?> From 913b3fb0c113b9a9c281ec0f02fc259693c57e0c Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Mon, 5 Mar 2012 22:53:10 +0000 Subject: [PATCH 07/48] [ticket/10631] Changing Ext Admin List to conform to standards PHPBB3-10631 --- phpBB/adm/style/acp_ext_list.html | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index 7058c9c7f7..f5f5241234 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -7,7 +7,7 @@

{L_EXTENSIONS_EXPLAIN}

- + @@ -26,7 +26,8 @@ - + @@ -38,7 +39,9 @@ - + @@ -50,7 +53,8 @@ - + From 9cd0e09f5deba03ee0e5d329f5ff126006fd4c9c Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 9 Mar 2012 18:09:38 +0000 Subject: [PATCH 08/48] [ticket/10631] Rename language file to extensions.php PHPBB3-10631 --- phpBB/language/en/acp/{customisations.php => extensions.php} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename phpBB/language/en/acp/{customisations.php => extensions.php} (100%) diff --git a/phpBB/language/en/acp/customisations.php b/phpBB/language/en/acp/extensions.php similarity index 100% rename from phpBB/language/en/acp/customisations.php rename to phpBB/language/en/acp/extensions.php From e768d0066d6c19e2d32016cc87a93d0cc9a9bcf7 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 9 Mar 2012 18:12:45 +0000 Subject: [PATCH 09/48] [ticket/10631] Update extensions language file for some issues found PHPBB3-10631 --- phpBB/language/en/acp/extensions.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index e20806eac2..77d0b2f3cd 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -42,20 +42,18 @@ $lang = array_merge($lang, array( 'DETAILS' => 'Details', - 'AVALIABLE' => 'Avaliable', + 'AVAILABLE' => 'Available', 'ENABLED' => 'Enabled', - 'DISBALED' => 'Disabled', + 'DISABLED' => 'Disabled', + 'PURGED' => 'Purged', + 'DELETED' => 'Deleted', + 'UPLOADED' => 'Uploaded', 'ENABLE' => 'Enable', 'DISABLE' => 'Disable', 'PURGE' => 'Purge', 'DELETE' => 'Delete', - 'ENABLED' => 'Enabled', - 'DISABLED' => 'Disabled', - 'PURGED' => 'Purged', - 'DELETED' => 'Deleted', - 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', 'DISABLE_EXPLAIN' => 'Disabling an extension retains its files and settings but removes any functionality added by the extension.', 'PURGE_EXPLAIN' => 'Purging an extension clears an extensions data while retaining its files.', From 3a5843959c754b99e595ca6d1ffa30ad67d31209 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Fri, 9 Mar 2012 18:19:21 +0000 Subject: [PATCH 10/48] [ticket/10631] Fixing some extension admin issues found PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) 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) { From 7a954d352ef1fe84256ad691135b6c6bf0d4bcc5 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 28 Apr 2012 18:13:28 +0100 Subject: [PATCH 11/48] [ticket/10631] Fixing some items mentioned in PR PHPBB3-10631 --- phpBB/adm/style/acp_ext_delete.html | 4 +- phpBB/adm/style/acp_ext_details.html | 6 +- phpBB/adm/style/acp_ext_disable.html | 4 +- phpBB/adm/style/acp_ext_enable.html | 4 +- phpBB/adm/style/acp_ext_purge.html | 4 +- phpBB/includes/acp/acp_extensions.php | 113 +++++++++----------------- phpBB/includes/extension/manager.php | 64 +++++++++++++++ phpBB/language/en/acp/extensions.php | 2 +- 8 files changed, 112 insertions(+), 89 deletions(-) diff --git a/phpBB/adm/style/acp_ext_delete.html b/phpBB/adm/style/acp_ext_delete.html index 1ce99b8905..f9a52861e5 100644 --- a/phpBB/adm/style/acp_ext_delete.html +++ b/phpBB/adm/style/acp_ext_delete.html @@ -18,10 +18,10 @@
-

{L_DELETE_SUCESS}

+

{L_DELETE_SUCCESS}


{L_RETURN}

- \ No newline at end of file + diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index 397610d83b..bc5fda7cc2 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -69,10 +69,6 @@
{authors.AUTHOR_NAME}
-
-
-
{authors.AUTHOR_USERNAME}
-
@@ -94,4 +90,4 @@ - \ No newline at end of file + diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html index 2198db09a1..c7de43a611 100644 --- a/phpBB/adm/style/acp_ext_disable.html +++ b/phpBB/adm/style/acp_ext_disable.html @@ -18,10 +18,10 @@
-

{L_DISABLE_SUCESS}

+

{L_DISABLE_SUCCESS}


{L_RETURN}

- \ No newline at end of file + diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html index 4c94ce7b2b..dd892d3477 100644 --- a/phpBB/adm/style/acp_ext_enable.html +++ b/phpBB/adm/style/acp_ext_enable.html @@ -18,10 +18,10 @@
-

{L_ENABLE_SUCESS}

+

{L_ENABLE_SUCCESS}


{L_RETURN}

- \ No newline at end of file + diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html index c73bbe6e00..55a648a3e3 100644 --- a/phpBB/adm/style/acp_ext_purge.html +++ b/phpBB/adm/style/acp_ext_purge.html @@ -18,10 +18,10 @@
-

{L_PURGE_SUCESS}

+

{L_PURGE_SUCCESS}


{L_RETURN}

- \ No newline at end of file + 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) + + private function list_enabled_exts($db, $template) { - 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) - { - 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; + } } diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 77d0b2f3cd..37cabe477b 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -38,7 +38,7 @@ $lang = array_merge($lang, array( 'EXTENSION' => 'Extension', 'EXTENSIONS' => 'Extensions', 'EXTENSIONS_ADMIN' => 'Extensions Admin', - 'EXTENSIONS_EXPLAIN' => 'The Extensions Admin is a tool in your phpBB Board which allows you to manage all of your extensions. For more information about extensions please visit this page on phpBBs Offical Website.', + 'EXTENSIONS_EXPLAIN' => 'The Extensions Admin is a tool in your phpBB Board which allows you to manage all of your extensions. For more information about extensions please visit this page on phpBB's Offical Website.', 'DETAILS' => 'Details', From 4cbfa6175303d23d35aaa06f8f68d9a3d7d0beb2 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 29 Apr 2012 00:34:50 +0100 Subject: [PATCH 12/48] [ticket/10631] A few more extension admin changes PHPBB3-10631 --- phpBB/adm/style/acp_ext_list.html | 2 +- phpBB/includes/acp/acp_extensions.php | 5 ++-- phpBB/language/en/acp/extensions.php | 33 +++++++++++++-------------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index f5f5241234..f16d347285 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -61,4 +61,4 @@
{L_EXTENSION_NAME}
{enabled.EXT_NAME} {L_DETAILS}{L_DISABLE} | {L_PURGE}{L_DISABLE}  + | {L_PURGE}
{disabled.EXT_NAME} {L_DETAILS}{L_ENABLE} | {L_PURGE} | {L_DELETE}{L_ENABLE}  + | {L_PURGE}  + | {L_DELETE}
{avaliable.EXT_NAME} {L_DETAILS}{L_ENABLE} | {L_DELETE}{L_ENABLE}  + | {L_DELETE}
- \ No newline at end of file + 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) { diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 37cabe477b..728ab40ee9 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -1,7 +1,7 @@ 'Extension', 'EXTENSIONS' => 'Extensions', - 'EXTENSIONS_ADMIN' => 'Extensions Admin', - 'EXTENSIONS_EXPLAIN' => 'The Extensions Admin is a tool in your phpBB Board which allows you to manage all of your extensions. For more information about extensions please visit this page on phpBB's Offical Website.', + 'EXTENSIONS_ADMIN' => 'Extensions Manager', + 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', 'DETAILS' => 'Details', @@ -59,10 +59,10 @@ $lang = array_merge($lang, array( 'PURGE_EXPLAIN' => 'Purging an extension clears an extensions data while retaining its files.', 'DELETE_EXPLAIN' => 'Deleting an extension removes all of its files and settings. Log entries will remain, although any language variables added by the extension will not be available.', - 'ENABLE_SUCESS' => 'The extension was enabled sucessfully', - 'DISABLE_SUCESS' => 'The extension was disabled sucessfully', - 'PURGE_SUCESS' => 'The extension was purged sucessfully', - 'DELETE_SUCESS' => 'The extension was deleted sucessfully', + 'ENABLE_SUCESS' => 'The extension was enabled successfully', + 'DISABLE_SUCESS' => 'The extension was disabled successfully', + 'PURGE_SUCESS' => 'The extension was purged successfully', + 'DELETE_SUCESS' => 'The extension was deleted successfully', 'ENABLE_FAIL' => 'The extension could not be enabled', 'DISABLE_FAIL' => 'The extension could not be disabled', @@ -73,10 +73,10 @@ $lang = array_merge($lang, array( 'EXTENSION_ACTIONS' => 'Actions', 'EXTENSION_OPTIONS' => 'Options', - 'ENABLE_CONFIRM' => 'Are you sure you wish to enable this extension?', - 'DISABLE_CONFIRM' => 'Are your sure you wish to disable this extension?', - 'PURGE_CONFIRM' => 'Are you sure you wish to purge this extensions data? This cannot be undone.', - 'DELETE_CONFIRM' => 'Are you sure you wish to data this extensions files and clear its data? This cannot be undone.', + 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', + 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', + 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', + 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', 'WARNING' => 'Warning', 'RETURN' => 'Return', @@ -94,11 +94,10 @@ $lang = array_merge($lang, array( 'REQUIREMENTS' => 'Requirements', 'PHPBB_VERSION' => 'phpBB Version', - 'PHP_VERSION' => 'php Version', + 'PHP_VERSION' => 'PHP Version', 'AUTHOR_INFORMATION' => 'Author Information', - 'AUTHOR_NAME' => 'Author Name', - 'AUTHOR_USERNAME' => 'Author Username', - 'AUTHOR_EMAIL' => 'Author Email', - 'AUTHOR_HOMEPAGE' => 'Author Homepage', - 'AUTHOR_ROLE' => 'Author Role', + 'AUTHOR_NAME' => 'Name', + 'AUTHOR_EMAIL' => 'Email', + 'AUTHOR_HOMEPAGE' => 'Homepage', + 'AUTHOR_ROLE' => 'Role', )); From a0e283d7b025325476c3c44f033410b47a87c621 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 19:56:02 +0100 Subject: [PATCH 13/48] [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 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; + } From ac883e26528736c74f96b5bc692f685bdb25fd57 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 19:57:02 +0100 Subject: [PATCH 14/48] [ticket/10631] Remove the now un-used method PHPBB3-10631 --- phpBB/includes/extension/manager.php | 65 ---------------------------- 1 file changed, 65 deletions(-) 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; - } -} From 10cba1426d7119a98c55cbefe2cfb1fd7de9b057 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 19 May 2012 23:32:34 +0100 Subject: [PATCH 15/48] [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(-) 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']); } /** From 3e6761b0266dfc67f6b41fea50d377b7621dffe0 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:16:00 +0100 Subject: [PATCH 16/48] [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(-) 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; } /** From dd4f07f9bb864bdac8b6c4009d166f1df6411419 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:18:11 +0100 Subject: [PATCH 17/48] [ticket/10631] Template shouldn't be required PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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']), From 0c18b16e284bef904943697561c6749511ac35ba Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:25:51 +0100 Subject: [PATCH 18/48] [ticket/10631] Adding docblocks PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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(); From 18cd1262b2ee3c5098f0446e4d382844a8fa2acf Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:31:31 +0100 Subject: [PATCH 19/48] [ticket/10631] Fixing up the template PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 64 ++++++++++++++-------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index bc5fda7cc2..b8302de329 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -9,85 +9,85 @@
{L_EXT_DETAILS}
-
-
{DISPLAY_NAME}
+
+
{MD_DISPLAY_NAME}
-
-
{NAME}
+
+
{MD_NAME}
-
-

{TYPE}

+
+

{MD_TYPE}

-
-

{DESCRIPTION}

+
+

{MD_DESCRIPTION}

-
-

{VERSION}

+
+

{MD_VERSION}

-
-

{HOMEPAGE}

+
+

{MD_HOMEPAGE}

-
-

{TIME}

+
+

{MD_TIME}

-
-

{LICENCE}

+
+

{MD_LICENSE}

{L_REQUIREMENTS} - +
-

{REQUIRE_PHPBB}

+

{MD_REQUIRE_PHPBB}

- +
-

{REQUIRE_PHP}

+

{MD_REQUIRE_PHP}

{L_AUTHOR_INFORMATION} - +
-
-
{authors.AUTHOR_NAME}
+
+
{md_authors.AUTHOR_NAME}
- +
-
-
{authors.AUTHOR_EMAIL}
+
+
{md_authors.AUTHOR_EMAIL}
- +
-
-
{authors.AUTHOR_HOMEPAGE}
+
+
{md_authors.AUTHOR_HOMEPAGE}
- +
-
{authors.AUTHOR_ROLE}
+
{md_authors.AUTHOR_ROLE}
- +
From c45243a91e142f1aa7a10e78c5ef4e91c4e18d9d Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 15:47:45 +0100 Subject: [PATCH 20/48] [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(-) 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')), ), ); } From 3ba59c6362c955d1f9b59278f7dd19cdacecff99 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 18:11:56 -0500 Subject: [PATCH 21/48] [ticket/10631] Various tidbits and cleanup on the acp extensions manager PHPBB3-10631 --- phpBB/adm/style/acp_ext_list.html | 115 +++++----- phpBB/includes/acp/acp_extensions.php | 97 ++++---- phpBB/includes/extension/manager.php | 13 ++ phpBB/includes/extension/metadata_manager.php | 64 ++++-- phpBB/language/en/acp/extensions.php | 207 +++++++++--------- 5 files changed, 253 insertions(+), 243 deletions(-) diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index f16d347285..ef3bbb87cc 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -1,64 +1,51 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
{L_EXTENSION_NAME}{L_EXTENSION_OPTIONS}{L_EXTENSION_ACTIONS}
- {L_ENABLED} {L_EXTENSIONS} -
{enabled.EXT_NAME}{L_DETAILS}{L_DISABLE}  - | {L_PURGE}
{L_DISABLED} {L_EXTENSIONS}
{disabled.EXT_NAME}{L_DETAILS}{L_ENABLE}  - | {L_PURGE}  - | {L_DELETE}
{L_AVALIABLE} {L_EXTENSIONS}
{avaliable.EXT_NAME}{L_DETAILS}{L_ENABLE}  - | {L_DELETE}
- - + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{L_EXTENSION_NAME}{L_EXTENSION_OPTIONS}{L_EXTENSION_ACTIONS}
+ {L_ENABLED} {L_EXTENSIONS} +
{enabled.EXT_NAME}{L_DETAILS}{L_DISABLE}  + | {L_PURGE}
{L_DISABLED} {L_EXTENSIONS}
{disabled.EXT_NAME}{L_DETAILS}{L_ENABLE}  + {L_PURGE}  + {L_DELETE}
+ + 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) { - $template->assign_block_vars('disabled', array( - 'EXT_NAME' => $ext['ext_name'], + $md_manager = $phpbb_extension_manager->get_extension_metadata($ext, $template); - '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'], + $template->assign_block_vars('disabled', array( + 'EXT_NAME' => $md_manager->get_metadata('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; } +} diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 728ab40ee9..950f3b5332 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -1,103 +1,104 @@ - 'Extension', - 'EXTENSIONS' => 'Extensions', - 'EXTENSIONS_ADMIN' => 'Extensions Manager', - 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', - - 'DETAILS' => 'Details', - - 'AVAILABLE' => 'Available', - 'ENABLED' => 'Enabled', - 'DISABLED' => 'Disabled', - 'PURGED' => 'Purged', - 'DELETED' => 'Deleted', - 'UPLOADED' => 'Uploaded', - - 'ENABLE' => 'Enable', - 'DISABLE' => 'Disable', - 'PURGE' => 'Purge', - 'DELETE' => 'Delete', - - 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', - 'DISABLE_EXPLAIN' => 'Disabling an extension retains its files and settings but removes any functionality added by the extension.', - 'PURGE_EXPLAIN' => 'Purging an extension clears an extensions data while retaining its files.', - 'DELETE_EXPLAIN' => 'Deleting an extension removes all of its files and settings. Log entries will remain, although any language variables added by the extension will not be available.', - - 'ENABLE_SUCESS' => 'The extension was enabled successfully', - 'DISABLE_SUCESS' => 'The extension was disabled successfully', - 'PURGE_SUCESS' => 'The extension was purged successfully', - 'DELETE_SUCESS' => 'The extension was deleted successfully', - - 'ENABLE_FAIL' => 'The extension could not be enabled', - 'DISABLE_FAIL' => 'The extension could not be disabled', - 'PURGE_FAIL' => 'The extension could not be purged', - 'DELETE_FAIL' => 'The extension could not be deleted', - - 'EXTENSION_NAME' => 'Extension Name', - 'EXTENSION_ACTIONS' => 'Actions', - 'EXTENSION_OPTIONS' => 'Options', - - 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', - 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', - 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', - 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', - - 'WARNING' => 'Warning', - 'RETURN' => 'Return', - - 'EXT_DETAILS' => 'Extension Details', - 'DISPLAY_NAME' => 'Display Name', - 'CLEAN_NAME' => 'Clean Name', - 'TYPE' => 'Type', - 'DESCRIPTION' => 'Description', - 'VERSION' => 'Version', - 'HOMEPAGE' => 'Homepage', - 'PATH' => 'File Path', - 'TIME' => 'Release Time', - 'LICENCE' => 'Licence', - - 'REQUIREMENTS' => 'Requirements', - 'PHPBB_VERSION' => 'phpBB Version', - 'PHP_VERSION' => 'PHP Version', - 'AUTHOR_INFORMATION' => 'Author Information', - 'AUTHOR_NAME' => 'Name', - 'AUTHOR_EMAIL' => 'Email', - 'AUTHOR_HOMEPAGE' => 'Homepage', - 'AUTHOR_ROLE' => 'Role', -)); + 'Extension', + 'EXTENSIONS' => 'Extensions', + 'EXTENSIONS_ADMIN' => 'Extensions Manager', + 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', + 'EXTENSION_INVALID' => 'The selected extension is not valid.', + + 'DETAILS' => 'Details', + + 'AVAILABLE' => 'Available', + 'ENABLED' => 'Enabled', + 'DISABLED' => 'Disabled', + 'PURGED' => 'Purged', + 'DELETED' => 'Deleted', + 'UPLOADED' => 'Uploaded', + + 'ENABLE' => 'Enable', + 'DISABLE' => 'Disable', + 'PURGE' => 'Purge', + 'DELETE' => 'Delete', + + 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', + 'DISABLE_EXPLAIN' => 'Disabling an extension retains its files and settings but removes any functionality added by the extension.', + 'PURGE_EXPLAIN' => 'Purging an extension clears an extensions data while retaining its files.', + 'DELETE_EXPLAIN' => 'Deleting an extension removes all of its files and settings. Log entries will remain, although any language variables added by the extension will not be available.', + + 'ENABLE_SUCESS' => 'The extension was enabled successfully', + 'DISABLE_SUCESS' => 'The extension was disabled successfully', + 'PURGE_SUCESS' => 'The extension was purged successfully', + 'DELETE_SUCESS' => 'The extension was deleted successfully', + + 'ENABLE_FAIL' => 'The extension could not be enabled', + 'DISABLE_FAIL' => 'The extension could not be disabled', + 'PURGE_FAIL' => 'The extension could not be purged', + 'DELETE_FAIL' => 'The extension could not be deleted', + + 'EXTENSION_NAME' => 'Extension Name', + 'EXTENSION_ACTIONS' => 'Actions', + 'EXTENSION_OPTIONS' => 'Options', + + 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', + 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', + 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', + 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', + + 'WARNING' => 'Warning', + 'RETURN' => 'Return', + + 'EXT_DETAILS' => 'Extension Details', + 'DISPLAY_NAME' => 'Display Name', + 'CLEAN_NAME' => 'Clean Name', + 'TYPE' => 'Type', + 'DESCRIPTION' => 'Description', + 'VERSION' => 'Version', + 'HOMEPAGE' => 'Homepage', + 'PATH' => 'File Path', + 'TIME' => 'Release Time', + 'LICENCE' => 'Licence', + + 'REQUIREMENTS' => 'Requirements', + 'PHPBB_VERSION' => 'phpBB Version', + 'PHP_VERSION' => 'PHP Version', + 'AUTHOR_INFORMATION' => 'Author Information', + 'AUTHOR_NAME' => 'Name', + 'AUTHOR_EMAIL' => 'Email', + 'AUTHOR_HOMEPAGE' => 'Homepage', + 'AUTHOR_ROLE' => 'Role', +)); From 6b12f71b94faa8cf0d7d65661650bb2d1e5381d9 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 19:44:35 -0500 Subject: [PATCH 22/48] [ticket/10631] Fix list_available_exts PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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'), From bf6e91b5f3f6d56c1a38cbff0ccf206f13202e50 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 20:24:20 -0500 Subject: [PATCH 23/48] [ticket/10631] Fixing some more issues PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 186 +++++++++--------- phpBB/includes/extension/metadata_manager.php | 35 ++-- 2 files changed, 111 insertions(+), 110 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index b8302de329..776c44711c 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -1,93 +1,93 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

- -
- {L_EXT_DETAILS} -
-
-
{MD_DISPLAY_NAME}
-
-
-
-
{MD_NAME}
-
-
-
-

{MD_TYPE}

-
-
-
-

{MD_DESCRIPTION}

-
-
-
-

{MD_VERSION}

-
-
-
-

{MD_HOMEPAGE}

-
- -
-
-

{MD_TIME}

-
-
-
-

{MD_LICENSE}

-
-
- -
- {L_REQUIREMENTS} - -
-
-

{MD_REQUIRE_PHPBB}

-
- - -
-
-

{MD_REQUIRE_PHP}

-
- -
- -
- {L_AUTHOR_INFORMATION} - -
-
-
{md_authors.AUTHOR_NAME}
-
- -
-
-
{md_authors.AUTHOR_EMAIL}
-
- - -
-
-
{md_authors.AUTHOR_HOMEPAGE}
-
- - -
-
-
{md_authors.AUTHOR_ROLE}
-
- - -
- - + + + + +

{L_EXTENSIONS_ADMIN}

+ +
+ {L_EXT_DETAILS} +
+
+
{MD_DISPLAY_NAME}
+
+
+
+
{MD_NAME}
+
+
+
+

{MD_TYPE}

+
+
+
+

{MD_DESCRIPTION}

+
+
+
+

{MD_VERSION}

+
+
+
+

{MD_HOMEPAGE}

+
+ +
+
+

{MD_TIME}

+
+
+
+

{MD_LICENCE}

+
+
+ +
+ {L_REQUIREMENTS} + +
+
+

{MD_REQUIRE_PHPBB}

+
+ + +
+
+

{MD_REQUIRE_PHP}

+
+ +
+ +
+ {L_AUTHOR_INFORMATION} + +
+
+
{md_authors.AUTHOR_NAME}
+
+ +
+
+
{md_authors.AUTHOR_EMAIL}
+
+ + +
+
+
{md_authors.AUTHOR_HOMEPAGE}
+
+ + +
+
+
{md_authors.AUTHOR_ROLE}
+
+ + +

+ +
+ + 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; } } From 28ca2d6a5fe8f8f1d8733af70951fa1191336eb6 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 22 Jul 2012 22:54:27 -0500 Subject: [PATCH 24/48] [ticket/10631] Stagger the enable/disable/purge for extensions PHPBB3-10631 --- phpBB/adm/style/acp_ext_disable.html | 58 ++++++++++++++------------- phpBB/adm/style/acp_ext_enable.html | 58 ++++++++++++++------------- phpBB/adm/style/acp_ext_purge.html | 58 ++++++++++++++------------- phpBB/includes/acp/acp_extensions.php | 21 ++++++++-- phpBB/language/en/acp/extensions.php | 11 +++-- 5 files changed, 118 insertions(+), 88 deletions(-) diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html index c7de43a611..e47ba2d8b9 100644 --- a/phpBB/adm/style/acp_ext_disable.html +++ b/phpBB/adm/style/acp_ext_disable.html @@ -1,27 +1,31 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

- - -

{L_DISABLE_CONFIRM}

- -
-
- {L_DISABLE} - -
-
- -
-

{L_DISABLE_SUCCESS}

-
-

{L_RETURN}

-
- - - + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+

{L_ENABLE_EXPLAIN}

+ + +

{L_DISABLE_CONFIRM}

+ +
+
+ {L_DISABLE} + +
+
+ +
+

{L_DISABLE_IN_PROGRESS}

+
+ +
+

{L_DISABLE_SUCCESS}

+
+

{L_RETURN}

+
+ + + diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html index dd892d3477..4b0f8bfdd7 100644 --- a/phpBB/adm/style/acp_ext_enable.html +++ b/phpBB/adm/style/acp_ext_enable.html @@ -1,27 +1,31 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

- - -

{L_ENABLE_CONFIRM}

- -
-
- {L_ENABLE} - -
-
- -
-

{L_ENABLE_SUCCESS}

-
-

{L_RETURN}

-
- - - + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+

{L_ENABLE_EXPLAIN}

+ + +

{L_ENABLE_CONFIRM}

+ +
+
+ {L_ENABLE} + +
+
+ +
+

{L_ENABLE_IN_PROGRESS}

+
+ +
+

{L_ENABLE_SUCCESS}

+
+

{L_RETURN}

+
+ + + diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html index 55a648a3e3..7255057d04 100644 --- a/phpBB/adm/style/acp_ext_purge.html +++ b/phpBB/adm/style/acp_ext_purge.html @@ -1,27 +1,31 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

- - -

{L_PURGE_CONFIRM}

- -
-
- {L_PURGE} - -
-
- -
-

{L_PURGE_SUCCESS}

-
-

{L_RETURN}

-
- - - + + + + +

{L_EXTENSIONS_ADMIN}

+ +

{L_EXTENSIONS_EXPLAIN}

+

{L_ENABLE_EXPLAIN}

+ + +

{L_PURGE_CONFIRM}

+ +
+
+ {L_PURGE} + +
+
+ +
+

{L_PURGE_IN_PROGRESS}

+
+ +
+

{L_PURGE_SUCCESS}

+
+

{L_RETURN}

+
+ + + 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'; diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 950f3b5332..66f3665757 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -60,10 +60,13 @@ $lang = array_merge($lang, array( 'PURGE_EXPLAIN' => 'Purging an extension clears an extensions data while retaining its files.', 'DELETE_EXPLAIN' => 'Deleting an extension removes all of its files and settings. Log entries will remain, although any language variables added by the extension will not be available.', - 'ENABLE_SUCESS' => 'The extension was enabled successfully', - 'DISABLE_SUCESS' => 'The extension was disabled successfully', - 'PURGE_SUCESS' => 'The extension was purged successfully', - 'DELETE_SUCESS' => 'The extension was deleted successfully', + 'DISABLE_IN_PROGRESS' => 'The extension is currently being disabled, please do not leave this page or refresh until it is completed.', + 'ENABLE_IN_PROGRESS' => 'The extension is currently being installed, please do not leave this page or refresh until it is completed.', + 'PURGE_IN_PROGRESS' => 'The extension is currently being purged, please do not leave this page or refresh until it is completed.', + 'ENABLE_SUCCESS' => 'The extension was enabled successfully', + 'DISABLE_SUCCESS' => 'The extension was disabled successfully', + 'PURGE_SUCCESS' => 'The extension was purged successfully', + 'DELETE_SUCCESS' => 'The extension was deleted successfully', 'ENABLE_FAIL' => 'The extension could not be enabled', 'DISABLE_FAIL' => 'The extension could not be disabled', From 74492b3cdda9538263484a6f2a2042ac1900228a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 14:01:13 -0500 Subject: [PATCH 25/48] [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(-) 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 From 8bbab088dd5830d8dd1151a3684dde5c197ba268 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:17:42 -0500 Subject: [PATCH 26/48] [ticket/10631] Validation for extensions PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 8 +- phpBB/common.php | 2 +- phpBB/download/file.php | 2 +- phpBB/includes/acp/acp_extensions.php | 53 ++- phpBB/includes/extension/manager.php | 7 +- phpBB/includes/extension/metadata_manager.php | 310 +++++++++++------- phpBB/install/database_update.php | 4 +- phpBB/install/install_install.php | 6 +- phpBB/language/en/acp/extensions.php | 41 +-- 9 files changed, 258 insertions(+), 175 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index 776c44711c..5af9603a75 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -6,10 +6,12 @@
{L_EXT_DETAILS} +
{MD_DISPLAY_NAME}
+
{MD_NAME}
@@ -43,7 +45,7 @@

{MD_LICENCE}

- +
{L_REQUIREMENTS} @@ -85,9 +87,9 @@
{md_authors.AUTHOR_ROLE}
- +

- + diff --git a/phpBB/common.php b/phpBB/common.php index c7c5859c25..fc2b9ae21e 100644 --- a/phpBB/common.php +++ b/phpBB/common.php @@ -119,7 +119,7 @@ set_config(null, null, null, $config); set_config_count(null, null, null, $config); // load extensions -$phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); +$phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); // Initialize style $phpbb_style_resource_locator = new phpbb_style_resource_locator(); diff --git a/phpBB/download/file.php b/phpBB/download/file.php index b56d729a7b..706df6abab 100644 --- a/phpBB/download/file.php +++ b/phpBB/download/file.php @@ -77,7 +77,7 @@ if (isset($_GET['avatar'])) set_config_count(null, null, null, $config); // load extensions - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); + $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx", $cache->get_driver()); $phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager); $phpbb_subscriber_loader->load(); 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,19 +184,41 @@ 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; + } + if (($metadata = json_decode($file_contents, true)) === NULL) + { + return false; + } + + $this->metadata = $metadata; + + 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() + { // 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; @@ -149,102 +226,114 @@ class phpbb_extension_metadata_manager } /** - * Validates the contents of the name 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_name() + public function validate_metadata_array() { - return preg_match('#^[a-zA-Z0-9_\x7f-\xff]{2,}/[a-zA-Z0-9_\x7f-\xff]{2,}$#', $this->metadata['name']); + $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 type 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_type() + public function validate_enable() { - return $this->metadata['type'] == 'phpbb3-extension'; + $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 description field - * - * @return boolean True when passes validation - */ - private function validate_description() - { - return true;//preg_match('#^{10,}$#', $this->metadata['description']); - } - - /** - * Validates the contents of the version field - * - * @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']); - } - - /** - * Validates the contents of the license field - * - * @return boolean True when passes validation - */ - private function validate_licence() - { - // Nothing to validate except existence - return isset($this->metadata['licence']); - } /** * 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', '>=')); - } - - /** - * Validates the contents of the display name field - * - * @return boolean True when passes validation - */ - private function validate_extra_display_name() - { - return true;//preg_match('#^[a-zA-Z0-9_]{2,0}$#', $this->metadata['name']); - } - - /** - * 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())) + if (!isset($this->metadata['require']['phpbb'])) { - return false; + return true; } + + return $this->_validate_version($this->metadata['require']['phpbb'], $this->config['version']); } /** * 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(), '>=')); + if (!isset($this->metadata['require']['php'])) + { + return true; + } + + return $this->_validate_version($this->metadata['require']['php'], phpversion()); + } + + /** + * 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) + { + // 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 version_compare($current_version, str_replace(array($comparison_matches[0], ' '), '', $string), $comparison_matches[0]); + } + + 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; } } diff --git a/phpBB/install/database_update.php b/phpBB/install/database_update.php index 502b3bb1a4..0b470ced26 100644 --- a/phpBB/install/database_update.php +++ b/phpBB/install/database_update.php @@ -683,12 +683,12 @@ function _write_result($no_updates, $errored, $error_ary) function _add_modules($modules_to_install) { - global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager; + global $phpbb_root_path, $phpEx, $db, $phpbb_extension_manager, $config; // modules require an extension manager if (empty($phpbb_extension_manager)) { - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx"); + $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx"); } include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); diff --git a/phpBB/install/install_install.php b/phpBB/install/install_install.php index 23593ee51f..9162d5ab60 100644 --- a/phpBB/install/install_install.php +++ b/phpBB/install/install_install.php @@ -250,7 +250,7 @@ class install_install extends module 'S_EXPLAIN' => true, 'S_LEGEND' => false, )); - + // Check for php json support if (@extension_loaded('json')) { @@ -1481,12 +1481,12 @@ class install_install extends module */ function add_modules($mode, $sub) { - global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager; + global $db, $lang, $phpbb_root_path, $phpEx, $phpbb_extension_manager, $config; // modules require an extension manager if (empty($phpbb_extension_manager)) { - $phpbb_extension_manager = new phpbb_extension_manager($db, EXT_TABLE, $phpbb_root_path, ".$phpEx"); + $phpbb_extension_manager = new phpbb_extension_manager($db, $config, EXT_TABLE, $phpbb_root_path, ".$phpEx"); } include_once($phpbb_root_path . 'includes/acp/acp_modules.' . $phpEx); diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 66f3665757..547d14d2b9 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -1,11 +1,11 @@ 'Extension', - 'EXTENSIONS' => 'Extensions', - 'EXTENSIONS_ADMIN' => 'Extensions Manager', - 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', - 'EXTENSION_INVALID' => 'The selected extension is not valid.', + 'EXTENSION' => 'Extension', + 'EXTENSIONS' => 'Extensions', + 'EXTENSIONS_ADMIN' => 'Extensions Manager', + 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', + 'EXTENSION_INVALID' => 'The selected extension is not valid.', + 'EXTENSION_NOT_AVAILABLE' => 'The selected extension is not available for this board, please verify your phpBB and PHP versions are allowed (see the details page).', 'DETAILS' => 'Details', @@ -63,27 +64,27 @@ $lang = array_merge($lang, array( 'DISABLE_IN_PROGRESS' => 'The extension is currently being disabled, please do not leave this page or refresh until it is completed.', 'ENABLE_IN_PROGRESS' => 'The extension is currently being installed, please do not leave this page or refresh until it is completed.', 'PURGE_IN_PROGRESS' => 'The extension is currently being purged, please do not leave this page or refresh until it is completed.', - 'ENABLE_SUCCESS' => 'The extension was enabled successfully', + 'ENABLE_SUCCESS' => 'The extension was enabled successfully', 'DISABLE_SUCCESS' => 'The extension was disabled successfully', 'PURGE_SUCCESS' => 'The extension was purged successfully', - 'DELETE_SUCCESS' => 'The extension was deleted successfully', + 'DELETE_SUCCESS' => 'The extension was deleted successfully', 'ENABLE_FAIL' => 'The extension could not be enabled', 'DISABLE_FAIL' => 'The extension could not be disabled', 'PURGE_FAIL' => 'The extension could not be purged', 'DELETE_FAIL' => 'The extension could not be deleted', - 'EXTENSION_NAME' => 'Extension Name', - 'EXTENSION_ACTIONS' => 'Actions', - 'EXTENSION_OPTIONS' => 'Options', + 'EXTENSION_NAME' => 'Extension Name', + 'EXTENSION_ACTIONS' => 'Actions', + 'EXTENSION_OPTIONS' => 'Options', - 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', - 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', - 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', - 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', + 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', + 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', + 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', + 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', - 'WARNING' => 'Warning', - 'RETURN' => 'Return', + 'WARNING' => 'Warning', + 'RETURN' => 'Return', 'EXT_DETAILS' => 'Extension Details', 'DISPLAY_NAME' => 'Display Name', From 4314284de12ceac5ae0792f3f4014b765d75d332 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:22:48 -0500 Subject: [PATCH 27/48] [ticket/10631] Remove code duplication PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) 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 (!$this->$type()) + if (is_array($regex)) { - return false; + foreach ($regex as $extra_name => $extra_regex) + { + $type = 'validate_' . $name . '_' . $extra_name; + + if (!$this->$type()) + { + return false; + } + } + } + else + { + + $type = 'validate_' . $name; + + if (!$this->$type()) + { + return false; + } } } From 8df9963fcc7e2962b6b4e1e32e809f2d8fe00835 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 15:39:13 -0500 Subject: [PATCH 28/48] [ticket/10631] Additional validation PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 76 ++++++------------- 1 file changed, 25 insertions(+), 51 deletions(-) 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']), From 9c0cd2693fd61c9528aa5fcbc3dff9de73515ebe Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 16:04:29 -0500 Subject: [PATCH 29/48] [ticket/10631] Make the enable/disable/purge notices more visable. PHPBB3-10631 --- phpBB/adm/style/acp_ext_disable.html | 12 +++++++----- phpBB/adm/style/acp_ext_enable.html | 12 +++++++----- phpBB/adm/style/acp_ext_purge.html | 12 +++++++----- phpBB/language/en/acp/extensions.php | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html index e47ba2d8b9..1f0bbe14c8 100644 --- a/phpBB/adm/style/acp_ext_disable.html +++ b/phpBB/adm/style/acp_ext_disable.html @@ -6,13 +6,15 @@

{L_EXTENSIONS_EXPLAIN}

{L_ENABLE_EXPLAIN}

- - -

{L_DISABLE_CONFIRM}

- + + +
+

{L_DISABLE_CONFIRM}

+
+
- {L_DISABLE} + {L_DISABLE}
diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html index 4b0f8bfdd7..9f278bfbe0 100644 --- a/phpBB/adm/style/acp_ext_enable.html +++ b/phpBB/adm/style/acp_ext_enable.html @@ -6,13 +6,15 @@

{L_EXTENSIONS_EXPLAIN}

{L_ENABLE_EXPLAIN}

- - -

{L_ENABLE_CONFIRM}

- + + +
+

{L_ENABLE_CONFIRM}

+
+
- {L_ENABLE} + {L_ENABLE}
diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html index 7255057d04..816fd872b9 100644 --- a/phpBB/adm/style/acp_ext_purge.html +++ b/phpBB/adm/style/acp_ext_purge.html @@ -6,13 +6,15 @@

{L_EXTENSIONS_EXPLAIN}

{L_ENABLE_EXPLAIN}

- - -

{L_PURGE_CONFIRM}

- + + +
+

{L_PURGE_CONFIRM}

+
+
- {L_PURGE} + {L_PURGE}
diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 547d14d2b9..a16e13d979 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -80,7 +80,7 @@ $lang = array_merge($lang, array( 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', - 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This cannot be undone.', + 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This will remove all settings stored for this extension and cannot be undone!', 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', 'WARNING' => 'Warning', From 2273ae2b34071160ff930ca8d49326b8dd308899 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 17:05:03 -0500 Subject: [PATCH 30/48] [ticket/10631] Remove references to delete extension PHPBB3-10631 --- phpBB/adm/style/acp_ext_delete.html | 27 --------------------------- phpBB/adm/style/acp_ext_list.html | 5 ++--- phpBB/includes/acp/acp_extensions.php | 15 --------------- phpBB/language/en/acp/extensions.php | 5 ----- 4 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 phpBB/adm/style/acp_ext_delete.html diff --git a/phpBB/adm/style/acp_ext_delete.html b/phpBB/adm/style/acp_ext_delete.html deleted file mode 100644 index f9a52861e5..0000000000 --- a/phpBB/adm/style/acp_ext_delete.html +++ /dev/null @@ -1,27 +0,0 @@ - - - - -

{L_EXTENSIONS_ADMIN}

- -

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

- - -

{L_DELETE_CONFIRM}

- -
-
- {L_DELETE} - -
-
- -
-

{L_DELETE_SUCCESS}

-
-

{L_RETURN}

-
- - - diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index ef3bbb87cc..b3b1b84949 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -40,12 +40,11 @@ {disabled.EXT_NAME} {L_DETAILS} {L_ENABLE}  - {L_PURGE}  - {L_DELETE} + {L_PURGE}  - + 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, )); } diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index a16e13d979..903ec249a8 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -48,13 +48,11 @@ $lang = array_merge($lang, array( 'ENABLED' => 'Enabled', 'DISABLED' => 'Disabled', 'PURGED' => 'Purged', - 'DELETED' => 'Deleted', 'UPLOADED' => 'Uploaded', 'ENABLE' => 'Enable', 'DISABLE' => 'Disable', 'PURGE' => 'Purge', - 'DELETE' => 'Delete', 'ENABLE_EXPLAIN' => 'Enabling an extension allows you to use it on your board.', 'DISABLE_EXPLAIN' => 'Disabling an extension retains its files and settings but removes any functionality added by the extension.', @@ -67,12 +65,10 @@ $lang = array_merge($lang, array( 'ENABLE_SUCCESS' => 'The extension was enabled successfully', 'DISABLE_SUCCESS' => 'The extension was disabled successfully', 'PURGE_SUCCESS' => 'The extension was purged successfully', - 'DELETE_SUCCESS' => 'The extension was deleted successfully', 'ENABLE_FAIL' => 'The extension could not be enabled', 'DISABLE_FAIL' => 'The extension could not be disabled', 'PURGE_FAIL' => 'The extension could not be purged', - 'DELETE_FAIL' => 'The extension could not be deleted', 'EXTENSION_NAME' => 'Extension Name', 'EXTENSION_ACTIONS' => 'Actions', @@ -81,7 +77,6 @@ $lang = array_merge($lang, array( 'ENABLE_CONFIRM' => 'Are you sure that you wish to enable this extension?', 'DISABLE_CONFIRM' => 'Are you sure that you wish to disable this extension?', 'PURGE_CONFIRM' => 'Are you sure that you wish to purge this extension's data? This will remove all settings stored for this extension and cannot be undone!', - 'DELETE_CONFIRM' => 'Are you sure that you wish to data this extension's files and clear its data? This cannot be undone.', 'WARNING' => 'Warning', 'RETURN' => 'Return', From 106c105113886f9a9e603dbb11549c06049b255f Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 18:22:35 -0500 Subject: [PATCH 31/48] [ticket/10631] Fix some issues as noted in github comments, significantly simplified validation PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 64 ++++---- phpBB/includes/acp/acp_extensions.php | 12 +- phpBB/includes/extension/manager.php | 2 +- phpBB/includes/extension/metadata_manager.php | 146 ++++++------------ 4 files changed, 83 insertions(+), 141 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index 5af9603a75..7408e88758 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -16,36 +16,35 @@
{MD_NAME}
-
-
-

{MD_TYPE}

-
+

{MD_DESCRIPTION}

+

{MD_VERSION}

+

{MD_HOMEPAGE}

- + +

{MD_TIME}

+

{MD_LICENCE}

+
{L_REQUIREMENTS} @@ -61,34 +60,35 @@
+
{L_AUTHOR_INFORMATION} -
-
-
{md_authors.AUTHOR_NAME}
-
- -
-
-
{md_authors.AUTHOR_EMAIL}
-
- - -
-
-
{md_authors.AUTHOR_HOMEPAGE}
-
- - -
-
-
{md_authors.AUTHOR_ROLE}
-
- - -

+
+
+
+
{md_authors.AUTHOR_NAME}
+
+ +
+
+
{md_authors.AUTHOR_EMAIL}
+
+ + +
+
+
{md_authors.AUTHOR_HOMEPAGE}
+
+ + +
+
+
{md_authors.AUTHOR_ROLE}
+
+ +
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)) + * 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; + } + + // Validate all fields + if ($name == 'all') + { + foreach ($fields as $field => $data) { - foreach ($regex as $extra_name => $extra_regex) - { - $type = 'validate_' . $name . '_' . $extra_name; - - if (!$this->$type()) - { - return false; - } - } - } - else - { - - $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']) : '', )); From 89f4cf6a8c10f9b0875cf7f278016aff67eb38fc Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 19:46:21 -0500 Subject: [PATCH 32/48] [ticket/10631] Use exceptions for errors. Build action list dynamically. PHPBB3-10631 --- phpBB/adm/style/acp_ext_list.html | 21 +++- phpBB/includes/acp/acp_extensions.php | 111 +++++++++++++----- phpBB/includes/exception/metadata.php | 69 +++++++++++ phpBB/includes/extension/metadata_manager.php | 72 ++++++------ phpBB/language/en/acp/extensions.php | 2 +- 5 files changed, 205 insertions(+), 70 deletions(-) create mode 100644 phpBB/includes/exception/metadata.php diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index b3b1b84949..65051cbae0 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -26,11 +26,16 @@ {enabled.EXT_NAME} {L_DETAILS} - {L_DISABLE}  - | {L_PURGE} + + + {enabled.actions.L_ACTION} +  |  + + + {L_DISABLED} {L_EXTENSIONS} @@ -38,9 +43,15 @@ {disabled.EXT_NAME} - {L_DETAILS} - {L_ENABLE}  - {L_PURGE}  + + {L_DETAILS} + + + + {disabled.actions.L_ACTION} +  |  + + 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); - $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_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, + )); + } catch( Exception $e ) { + $this->template->assign_block_vars('disabled', array( + 'EXT_NAME' => $this->user->lang('EXTENSION_INVALID_LIST', $name, $e), + )); + } + } + } + + /** + * 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; } diff --git a/phpBB/language/en/acp/extensions.php b/phpBB/language/en/acp/extensions.php index 903ec249a8..0adaff10c8 100644 --- a/phpBB/language/en/acp/extensions.php +++ b/phpBB/language/en/acp/extensions.php @@ -39,7 +39,7 @@ $lang = array_merge($lang, array( 'EXTENSIONS' => 'Extensions', 'EXTENSIONS_ADMIN' => 'Extensions Manager', 'EXTENSIONS_EXPLAIN' => 'The Extensions Manager is a tool in your phpBB Board which allows you to manage all of your extensions statuses and view information about them.', - 'EXTENSION_INVALID' => 'The selected extension is not valid.', + 'EXTENSION_INVALID_LIST' => 'The "%s" extension is not valid.

%s

', 'EXTENSION_NOT_AVAILABLE' => 'The selected extension is not available for this board, please verify your phpBB and PHP versions are allowed (see the details page).', 'DETAILS' => 'Details', From 2a7e1292919ed1397a3f1951e510d84565d002d7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:28:04 -0500 Subject: [PATCH 33/48] [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 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."); } } From fd5ed30052a03d812cfdf95f4e86b0c997b5aa10 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:34:47 -0500 Subject: [PATCH 34/48] [ticket/10631] Update tests PHPBB3-10631 --- tests/extension/manager_test.php | 2 ++ tests/test_framework/phpbb_functional_test_case.php | 1 + 2 files changed, 3 insertions(+) diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index 45bed247ae..df7f9f3029 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -27,6 +27,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $this->extension_manager = new phpbb_extension_manager( $this->new_dbal(), + new phpbb_config(array()) 'phpbb_ext', dirname(__FILE__) . '/', '.php', @@ -90,6 +91,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case { $extension_manager = new phpbb_extension_manager( $this->new_dbal(), + new phpbb_config(array()), 'phpbb_ext', dirname(__FILE__) . '/', '.php' diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index b953017d0a..a1deeb2b63 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -125,6 +125,7 @@ class phpbb_functional_test_case extends phpbb_test_case { $this->extension_manager = new phpbb_extension_manager( $this->get_db(), + new phpbb_config(), self::$config['table_prefix'] . 'ext', $phpbb_root_path, ".$phpEx", From 747c16240fd56be0e24b4c54f01c82aa0a78b91e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 23 Jul 2012 20:40:54 -0500 Subject: [PATCH 35/48] [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(-) 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); } From 1de061c4defd405da279cb1f398d7d2e4e75c573 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 24 Jul 2012 20:48:38 -0500 Subject: [PATCH 36/48] [ticket/10631] Fixing an error in the test script PHPBB3-10631 --- tests/extension/manager_test.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/extension/manager_test.php b/tests/extension/manager_test.php index df7f9f3029..5cde5bccdb 100644 --- a/tests/extension/manager_test.php +++ b/tests/extension/manager_test.php @@ -27,7 +27,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case $this->extension_manager = new phpbb_extension_manager( $this->new_dbal(), - new phpbb_config(array()) + new phpbb_config(array()), 'phpbb_ext', dirname(__FILE__) . '/', '.php', From c39f11750fa73007edd936bf600ea53ac8f95f3a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Tue, 24 Jul 2012 21:08:11 -0500 Subject: [PATCH 37/48] [ticket/10631] A _start_ on a metadata manager test. No idea if it runs without errors, I do not have the testing stuff setup. PHPBB3-10631 --- .../phpbb_extension_metadata_manager_test.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/extension/phpbb_extension_metadata_manager_test.php diff --git a/tests/extension/phpbb_extension_metadata_manager_test.php b/tests/extension/phpbb_extension_metadata_manager_test.php new file mode 100644 index 0000000000..7a7f7a785d --- /dev/null +++ b/tests/extension/phpbb_extension_metadata_manager_test.php @@ -0,0 +1,55 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->extension_manager = new phpbb_extension_manager( + $this->new_dbal(), + new phpbb_config(array()), + 'phpbb_ext', + dirname(__FILE__) . '/', + '.php', + new phpbb_mock_cache + ); + } + + public function test_bar() + { + $phpbb_extension_metadata_manager = new phpbb_extension_metadata_manager( + 'bar', + $this->new_dbal(), + new phpbb_config(array()), + $this->extension_manager, + dirname(__FILE__) . '/', + '.php', + new phpbb_template( + dirname(__FILE__) . '/', + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_mock_cache + ); + + //$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); + } +} \ No newline at end of file From 8c5786636a534baf28b4820a730f85948c3dccf4 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Wed, 25 Jul 2012 22:14:38 -0500 Subject: [PATCH 38/48] [ticket/10631] Fix class construct arguments in test PHPBB3-10631 --- tests/extension/phpbb_extension_metadata_manager_test.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/extension/phpbb_extension_metadata_manager_test.php b/tests/extension/phpbb_extension_metadata_manager_test.php index 7a7f7a785d..0d115d37eb 100644 --- a/tests/extension/phpbb_extension_metadata_manager_test.php +++ b/tests/extension/phpbb_extension_metadata_manager_test.php @@ -36,7 +36,6 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case $phpbb_extension_metadata_manager = new phpbb_extension_metadata_manager( 'bar', $this->new_dbal(), - new phpbb_config(array()), $this->extension_manager, dirname(__FILE__) . '/', '.php', @@ -47,7 +46,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case new phpbb_user(), new phpbb_style_resource_locator() ), - new phpbb_mock_cache + new phpbb_config(array()) ); //$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); From 500879520c40a71f0b83799ab3e59c86c12a801a Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 28 Jul 2012 14:59:55 -0500 Subject: [PATCH 39/48] [ticket/10631] Metadata manager tests PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 55 +-- tests/extension/ext/foo/composer.json | 22 ++ tests/extension/metadata_manager_test.php | 374 ++++++++++++++++++ .../phpbb_extension_metadata_manager_test.php | 54 --- 4 files changed, 424 insertions(+), 81 deletions(-) create mode 100644 tests/extension/ext/foo/composer.json create mode 100644 tests/extension/metadata_manager_test.php delete mode 100644 tests/extension/phpbb_extension_metadata_manager_test.php 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."); - } + case 'all': + $this->validate('display'); - if (!preg_match($fields[$name], $this->metadata[$name])) - { - throw new phpbb_extension_exception("Meta field '$name' is invalid."); - } - } + $this->validate_enable(); + break; - // Validate all fields - if ($name == 'all') - { - $this->validate('display'); + case 'display': + foreach ($fields as $field => $data) + { + $this->validate($field); + } - $this->validate_enable(); - } + $this->validate_authors(); + break; - // Validate display fields - if ($name == 'display') - { - foreach ($fields as $field => $data) - { - $this->validate($field); - } + default: + if (isset($fields[$name])) + { + if (!isset($this->metadata[$name])) + { + throw new phpbb_extension_exception("Required meta field '$name' has not been set."); + } - $this->validate_authors(); + 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'])) { diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json new file mode 100644 index 0000000000..14af677dac --- /dev/null +++ b/tests/extension/ext/foo/composer.json @@ -0,0 +1,22 @@ +{ + "name": "foo/example", + "type": "phpbb3-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "licence": "GNU GPL v2", + "authors": [{ + "name": "Nathan Guse", + "username": "EXreaction", + "email": "nathaniel.guse@gmail.com", + "homepage": "http://lithiumstudios.org", + "role": "N/A" + }], + "require": { + "php": ">=5.3", + "phpbb": "3.1.0-dev" + }, + "extra": { + "display-name": "phpBB Foo Extension" + } +} diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php new file mode 100644 index 0000000000..67630e9f36 --- /dev/null +++ b/tests/extension/metadata_manager_test.php @@ -0,0 +1,374 @@ +createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->phpbb_root_path = dirname(__FILE__) . '/'; + + $this->extension_manager = new phpbb_extension_manager( + $this->new_dbal(), + new phpbb_config(array()), + 'phpbb_ext', + $this->phpbb_root_path, + '.php', + new phpbb_mock_cache + ); + } + + // Should fail from missing composer.json + public function test_bar() + { + $ext_name = 'bar'; + + $manager = new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + '.php', + new phpbb_template( + $this->phpbb_root_path, + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_config(array()) + ); + + try + { + $manager->get_metadata(); + } + catch(phpbb_extension_exception $e){} + + $this->assertEquals((string) $e, 'The required file does not exist: ' . $this->phpbb_root_path . $this->extension_manager->get_extension_path($ext_name) . 'composer.json'); + } + + // Should be the same as a direct json_decode of the composer.json file + public function test_foo() + { + $ext_name = 'foo'; + + $manager = new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + '.php', + new phpbb_template( + $this->phpbb_root_path, + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_config(array()) + ); + + try + { + $metadata = $manager->get_metadata(); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + $json = json_decode(file_get_contents($this->phpbb_root_path . 'ext/foo/composer.json'), true); + + $this->assertEquals($metadata, $json); + } + + public function test_validator() + { + $ext_name = 'validator'; + + $manager = new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + '.php', + new phpbb_template( + $this->phpbb_root_path, + '.php', + new phpbb_config(array()), + new phpbb_user(), + new phpbb_style_resource_locator() + ), + new phpbb_config(array( + 'version' => '3.1.0', + )) + ); + + // Non-existant data + try + { + $manager->validate('name'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); + + try + { + $manager->validate('type'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); + + try + { + $manager->validate('licence'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); + + try + { + $manager->validate('version'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); + + try + { + $manager->validate_authors(); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); + + $manager->merge_metadata(array( + 'authors' => array( + array(), + ), + )); + + try + { + $manager->validate_authors(); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); + + + // Invalid data + $manager->set_metadata(array( + 'name' => 'asdf', + 'type' => 'asdf', + 'licence' => '', + 'version' => '', + )); + + try + { + $manager->validate('name'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); + + try + { + $manager->validate('type'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); + + try + { + $manager->validate('licence'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); + + try + { + $manager->validate('version'); + } + catch(phpbb_extension_exception $e) {} + $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); + + + // Valid data + $manager->set_metadata(array( + 'name' => 'test/foo', + 'type' => 'phpbb3-extension', + 'licence' => 'GPL v2', + 'version' => '1.0.0', + )); + + try + { + $this->assertEquals(true, $manager->validate('enable')); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '10.0.0', + 'phpbb' => '3.2.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '5.3.0', + 'phpbb' => '3.1.0-beta', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '>' . phpversion(), + 'phpbb' => '>3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Too high of current install + $manager->merge_metadata(array( + 'require' => array( + 'php' => '<' . phpversion(), + 'phpbb' => '<3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(false, $manager->validate_require_php()); + $this->assertEquals(false, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => phpversion(), + 'phpbb' => '3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '>=' . phpversion(), + 'phpbb' => '>=3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + + + // Matching requirements + $manager->merge_metadata(array( + 'require' => array( + 'php' => '<=' . phpversion(), + 'phpbb' => '<=3.1.0', // config is set to 3.1.0 + ), + )); + + try + { + $this->assertEquals(true, $manager->validate_require_php()); + $this->assertEquals(true, $manager->validate_require_phpbb()); + } + catch(phpbb_extension_exception $e) + { + $this->fail($e); + } + } +} + +class phpbb_extension_metadata_manager_test extends phpbb_extension_metadata_manager +{ + public function set_metadata($metadata) + { + $this->metadata = $metadata; + } + + public function merge_metadata($metadata) + { + $this->metadata = array_merge($this->metadata, $metadata); + } +} \ No newline at end of file diff --git a/tests/extension/phpbb_extension_metadata_manager_test.php b/tests/extension/phpbb_extension_metadata_manager_test.php deleted file mode 100644 index 0d115d37eb..0000000000 --- a/tests/extension/phpbb_extension_metadata_manager_test.php +++ /dev/null @@ -1,54 +0,0 @@ -createXMLDataSet(dirname(__FILE__) . '/fixtures/extensions.xml'); - } - - protected function setUp() - { - parent::setUp(); - - $this->extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), - 'phpbb_ext', - dirname(__FILE__) . '/', - '.php', - new phpbb_mock_cache - ); - } - - public function test_bar() - { - $phpbb_extension_metadata_manager = new phpbb_extension_metadata_manager( - 'bar', - $this->new_dbal(), - $this->extension_manager, - dirname(__FILE__) . '/', - '.php', - new phpbb_template( - dirname(__FILE__) . '/', - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array()) - ); - - //$this->assertEquals(array('bar', 'foo', 'vendor/moo'), array_keys($this->extension_manager->all_available())); - } -} \ No newline at end of file From 36465c9a205c356b0662e45b4fded79c4b476547 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 29 Jul 2012 20:08:30 -0500 Subject: [PATCH 40/48] [ticket/10631] Functional acp_extensions test, cleanup PHPBB3-10631 --- phpBB/adm/style/acp_ext_list.html | 4 +- phpBB/includes/acp/acp_extensions.php | 38 +-- tests/extension/acp.php | 226 ++++++++++++++++++ tests/extension/ext/foo/composer.json | 2 +- tests/extension/ext/vendor/moo/composer.json | 22 ++ tests/extension/metadata_manager_test.php | 99 ++++---- .../phpbb_functional_test_case.php | 54 +++++ .../phpbb_test_case_helpers.php | 108 +++++++++ 8 files changed, 481 insertions(+), 72 deletions(-) create mode 100644 tests/extension/acp.php create mode 100644 tests/extension/ext/vendor/moo/composer.json diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index 65051cbae0..b654a80caa 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -23,7 +23,7 @@ - + {enabled.EXT_NAME} {L_DETAILS} @@ -41,7 +41,7 @@ {L_DISABLED} {L_EXTENSIONS} - + {disabled.EXT_NAME} {L_DETAILS} 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) diff --git a/tests/extension/acp.php b/tests/extension/acp.php new file mode 100644 index 0000000000..c078a3f7b4 --- /dev/null +++ b/tests/extension/acp.php @@ -0,0 +1,226 @@ +copy_dir($phpbb_root_path . 'ext/', $phpbb_root_path . 'store/temp_ext/'); + + // Then empty the ext/ directory on the board (for accurate test cases) + self::$helper->empty_dir($phpbb_root_path . 'ext/'); + + // Copy our ext/ files from the test case to the board + self::$copied_files = array_merge(self::$copied_files, self::$helper->copy_dir(dirname(__FILE__) . '/ext/', $phpbb_root_path . 'ext/')); + } + + public function setUp() + { + parent::setUp(); + + $this->get_db(); + + // Clear the phpbb_ext table + $this->db->sql_query('DELETE FROM phpbb_ext'); + + // Insert our base data + $insert_rows = array( + array( + 'ext_name' => 'foo', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'vendor/moo', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + + // do not exist + array( + 'ext_name' => 'test2', + 'ext_active' => true, + 'ext_state' => 'b:0;', + ), + array( + 'ext_name' => 'test3', + 'ext_active' => false, + 'ext_state' => 'b:0;', + ), + ); + $this->db->sql_multi_insert('phpbb_ext', $insert_rows); + + $this->login(); + $this->admin_login(); + + $this->add_lang('acp/extensions'); + } + + /** + * This should only be called once after the tests are run. + * This is used to remove the files copied to the phpBB install + */ + static public function tearDownAfterClass() + { + global $phpbb_root_path; + + // Copy back the board installed extensions from the temp directory + self::$helper->copy_dir($phpbb_root_path . 'store/temp_ext/', $phpbb_root_path . 'ext/'); + + self::$copied_files[] = $phpbb_root_path . 'store/temp_ext/'; + + // Remove all of the files we copied around (from board ext -> temp_ext, from test ext -> board ext) + self::$helper->remove_files(self::$copied_files); + } + + public function test_list() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid); + + $this->assertCount(1, $crawler->filter('.ext_enabled')); + $this->assertCount(4, $crawler->filter('.ext_disabled')); + + $this->assertContains('phpBB Foo Extension', $crawler->filter('.ext_enabled')->eq(0)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_enabled')->eq(0)->text()); + + $this->assertContains('The "test2" extension is not valid.', $crawler->filter('.ext_disabled')->eq(0)->text()); + + $this->assertContains('The "test3" extension is not valid.', $crawler->filter('.ext_disabled')->eq(1)->text()); + + $this->assertContains('phpBB Moo Extension', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('DETAILS', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('ENABLE', $crawler->filter('.ext_disabled')->eq(2)->text()); + $this->assertContainsLang('PURGE', $crawler->filter('.ext_disabled')->eq(2)->text()); + + $this->assertContains('The "bar" extension is not valid.', $crawler->filter('.ext_disabled')->eq(3)->text()); + } + + public function test_details() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); + + for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) + { + $text = $crawler->filter('dl')->eq($i)->text(); + + switch (true) + { + case (strpos($text, $this->lang('DISPLAY_NAME')) === 0): + $this->assertContains('phpBB Foo Extension', $text); + break; + + case (strpos($text, $this->lang('CLEAN_NAME')) === 0): + $this->assertContains('foo/example', $text); + break; + + case (strpos($text, $this->lang('DESCRIPTION')) === 0): + $this->assertContains('An example/sample extension to be used for testing purposes in phpBB Development.', $text); + break; + + case (strpos($text, $this->lang('VERSION')) === 0): + $this->assertContains('1.0.0', $text); + break; + + case (strpos($text, $this->lang('TIME')) === 0): + $this->assertContains('2012-02-15 01:01:01', $text); + break; + + case (strpos($text, $this->lang('LICENCE')) === 0): + $this->assertContains('GNU GPL v2', $text); + break; + + case (strpos($text, $this->lang('PHPBB_VERSION')) === 0): + $this->assertContains('3.1.0-dev', $text); + break; + + case (strpos($text, $this->lang('PHP_VERSION')) === 0): + $this->assertContains('>=5.3', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_NAME')) === 0): + $this->assertContains('Nathan Guse', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_EMAIL')) === 0): + $this->assertContains('email@phpbb.com', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_HOMEPAGE')) === 0): + $this->assertContains('http://lithiumstudios.org', $text); + break; + + case (strpos($text, $this->lang('AUTHOR_ROLE')) === 0): + $this->assertContains('N/A', $text); + break; + } + } + } + + public function test_enable_pre() + { + // Foo is already enabled (error) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_disable_pre() + { + // Moo is not enabled (error) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_purge_pre() + { + // test2 is not available (error) + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=test2&sid=' . $this->sid); + $this->assertContains('The required file does not exist', $crawler->filter('html')->text()); + + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge_pre&ext_name=foo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text()); + } + + public function test_enable() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text()); + } + + public function test_disable() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text()); + } + + public function test_purge() + { + $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid); + $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text()); + } +} \ No newline at end of file diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json index 14af677dac..4b5150461f 100644 --- a/tests/extension/ext/foo/composer.json +++ b/tests/extension/ext/foo/composer.json @@ -8,7 +8,7 @@ "authors": [{ "name": "Nathan Guse", "username": "EXreaction", - "email": "nathaniel.guse@gmail.com", + "email": "email@phpbb.com", "homepage": "http://lithiumstudios.org", "role": "N/A" }], diff --git a/tests/extension/ext/vendor/moo/composer.json b/tests/extension/ext/vendor/moo/composer.json new file mode 100644 index 0000000000..c91a5e027b --- /dev/null +++ b/tests/extension/ext/vendor/moo/composer.json @@ -0,0 +1,22 @@ +{ + "name": "moo/example", + "type": "phpbb3-extension", + "description": "An example/sample extension to be used for testing purposes in phpBB Development.", + "version": "1.0.0", + "time": "2012-02-15 01:01:01", + "licence": "GNU GPL v2", + "authors": [{ + "name": "Nathan Guse", + "username": "EXreaction", + "email": "email@phpbb.com", + "homepage": "http://lithiumstudios.org", + "role": "N/A" + }], + "require": { + "php": ">=5.3", + "phpbb": "3.1.0-dev" + }, + "extra": { + "display-name": "phpBB Moo Extension" + } +} diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 67630e9f36..d1e60ad268 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -11,7 +11,14 @@ class metadata_manager_test extends phpbb_database_test_case { protected $class_loader; protected $extension_manager; + + protected $cache; + protected $config; + protected $db; protected $phpbb_root_path; + protected $phpEx; + protected $template; + protected $user; public function getDataSet() { @@ -22,15 +29,30 @@ class metadata_manager_test extends phpbb_database_test_case { parent::setUp(); + $this->cache = new phpbb_mock_cache(); + $this->config = new phpbb_config(array( + 'version' => '3.1.0', + )); + $this->db = $this->new_dbal(); $this->phpbb_root_path = dirname(__FILE__) . '/'; + $this->phpEx = '.php'; + $this->user = new phpbb_user(); + + $this->template = new phpbb_template( + $this->phpbb_root_path, + $this->phpEx, + $this->config, + $this->user, + new phpbb_style_resource_locator() + ); $this->extension_manager = new phpbb_extension_manager( - $this->new_dbal(), - new phpbb_config(array()), + $this->db(), + $this->config, 'phpbb_ext', $this->phpbb_root_path, - '.php', - new phpbb_mock_cache + $this->phpEx, + $this->cache ); } @@ -39,21 +61,7 @@ class metadata_manager_test extends phpbb_database_test_case { $ext_name = 'bar'; - $manager = new phpbb_extension_metadata_manager_test( - $ext_name, - $this->new_dbal(), - $this->extension_manager, - $this->phpbb_root_path, - '.php', - new phpbb_template( - $this->phpbb_root_path, - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array()) - ); + $manager = $this->get_metadata_manager($ext_name); try { @@ -69,21 +77,7 @@ class metadata_manager_test extends phpbb_database_test_case { $ext_name = 'foo'; - $manager = new phpbb_extension_metadata_manager_test( - $ext_name, - $this->new_dbal(), - $this->extension_manager, - $this->phpbb_root_path, - '.php', - new phpbb_template( - $this->phpbb_root_path, - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array()) - ); + $manager = $this->get_metadata_manager($ext_name); try { @@ -103,23 +97,7 @@ class metadata_manager_test extends phpbb_database_test_case { $ext_name = 'validator'; - $manager = new phpbb_extension_metadata_manager_test( - $ext_name, - $this->new_dbal(), - $this->extension_manager, - $this->phpbb_root_path, - '.php', - new phpbb_template( - $this->phpbb_root_path, - '.php', - new phpbb_config(array()), - new phpbb_user(), - new phpbb_style_resource_locator() - ), - new phpbb_config(array( - 'version' => '3.1.0', - )) - ); + $manager = $this->get_metadata_manager($ext_name); // Non-existant data try @@ -358,6 +336,25 @@ class metadata_manager_test extends phpbb_database_test_case $this->fail($e); } } + + /** + * Get an instance of the metadata manager + * + * @param string $ext_name + * @return phpbb_extension_metadata_manager_test + */ + private function get_metadata_manager($ext_name) + { + return new phpbb_extension_metadata_manager_test( + $ext_name, + $this->new_dbal(), + $this->extension_manager, + $this->phpbb_root_path, + $this->phpEx, + $this->template, + $this->config + ); + } } class phpbb_extension_metadata_manager_test extends phpbb_extension_metadata_manager diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index a1deeb2b63..6b4c0b6883 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -252,6 +252,48 @@ class phpbb_functional_test_case extends phpbb_test_case } } + /** + * Login to the ACP + * You must run login() before calling this. + */ + protected function admin_login() + { + $this->add_lang('acp/common'); + + // Requires login first! + if (empty($this->sid)) + { + $this->fail('$this->sid is empty. Make sure you call login() before admin_login()'); + return; + } + + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assertContains($this->lang('LOGIN_ADMIN_CONFIRM'), $crawler->filter('html')->text()); + + $form = $crawler->selectButton($this->lang('LOGIN'))->form(); + + foreach ($form->getValues() as $field => $value) + { + if (strpos($field, 'password_') === 0) + { + $login = $this->client->submit($form, array('username' => 'admin', $field => 'admin')); + + $cookies = $this->cookieJar->all(); + + // The session id is stored in a cookie that ends with _sid - we assume there is only one such cookie + foreach ($cookies as $cookie); + { + if (substr($cookie->getName(), -4) == '_sid') + { + $this->sid = $cookie->getValue(); + } + } + + break; + } + } + } + protected function add_lang($lang_file) { if (is_array($lang_file)) @@ -288,4 +330,16 @@ class phpbb_functional_test_case extends phpbb_test_case return call_user_func_array('sprintf', $args); } + + /** + * assertContains for language strings + * + * @param string $needle Search string + * @param string $haystack Search this + * @param string $message Optional failure message + */ + public function assertContainsLang($needle, $haystack, $message = null) + { + $this->assertContains(html_entity_decode($this->lang($needle), ENT_QUOTES), $haystack, $message); + } } diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 46feef550a..d10645a732 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -115,4 +115,112 @@ class phpbb_test_case_helpers return $config; } + + /** + * Recursive directory copying function + * + * @param string $source + * @param string $dest + * @return array list of files copied + */ + public function copy_dir($source, $dest) + { + $source = (substr($source, -1) == '/') ? $source : $source . '/'; + $dest = (substr($dest, -1) == '/') ? $dest : $dest . '/'; + + $copied_files = array(); + + if (!is_dir($dest)) + { + $this->makedirs($dest); + } + + $files = scandir($source); + foreach ($files as $file) + { + if ($file == '.' || $file == '..') + { + continue; + } + + if (is_dir($source . $file)) + { + $created_dir = false; + if (!is_dir($dest . $file)) + { + $created_dir = true; + $this->makedirs($dest . $file); + } + + $copied_files = array_merge($copied_files, self::copy_dir($source . $file, $dest . $file)); + + if ($created_dir) + { + $copied_files[] = $dest . $file; + } + } + else + { + if (!file_exists($dest . $file)) + { + copy($source . $file, $dest . $file); + + $copied_files[] = $dest . $file; + } + } + } + + return $copied_files; + } + + /** + * Remove files/directories that are listed in an array + * Designed for use with $this->copy_dir() + * + * @param array $file_list + */ + public function remove_files($file_list) + { + foreach ($file_list as $file) + { + if (is_dir($file)) + { + rmdir($file); + } + else + { + unlink($file); + } + } + } + + /** + * Empty directory (remove any subdirectories/files below) + * + * @param array $file_list + */ + public function empty_dir($path) + { + $path = (substr($path, -1) == '/') ? $path : $path . '/'; + + $files = scandir($path); + foreach ($files as $file) + { + if ($file == '.' || $file == '..') + { + continue; + } + + if (is_dir($path . $file)) + { + $this->empty_dir($path . $file); + + rmdir($path . $file); + } + else + { + unlink($path . $file); + } + } + } } From 47898cb37a1c1f517b5e6ae95427807ea5de11da Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 13:36:51 -0500 Subject: [PATCH 41/48] [ticket/10631] Fix metadata_manager_test PHPBB3-10631 --- tests/extension/metadata_manager_test.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index d1e60ad268..801d4dbeca 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -47,7 +47,7 @@ class metadata_manager_test extends phpbb_database_test_case ); $this->extension_manager = new phpbb_extension_manager( - $this->db(), + $this->db, $this->config, 'phpbb_ext', $this->phpbb_root_path, @@ -347,7 +347,7 @@ class metadata_manager_test extends phpbb_database_test_case { return new phpbb_extension_metadata_manager_test( $ext_name, - $this->new_dbal(), + $this->db, $this->extension_manager, $this->phpbb_root_path, $this->phpEx, From dce04b2d03f93c9237b743afbcbd89fb6405f836 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 30 Jul 2012 19:30:49 -0500 Subject: [PATCH 42/48] [ticket/10631] Various front-end fixes (extensions manager) Add Back button from details Add cancel button from actions Correct language strings PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 2 ++ phpBB/adm/style/acp_ext_disable.html | 5 +++-- phpBB/adm/style/acp_ext_enable.html | 3 ++- phpBB/adm/style/acp_ext_purge.html | 5 +++-- phpBB/includes/acp/acp_extensions.php | 9 +++++++++ 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index 7408e88758..e927e9de18 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -2,6 +2,8 @@ + « {L_BACK} +

{L_EXTENSIONS_ADMIN}

diff --git a/phpBB/adm/style/acp_ext_disable.html b/phpBB/adm/style/acp_ext_disable.html index 1f0bbe14c8..7dc3f6ec97 100644 --- a/phpBB/adm/style/acp_ext_disable.html +++ b/phpBB/adm/style/acp_ext_disable.html @@ -5,7 +5,7 @@

{L_EXTENSIONS_ADMIN}

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

+

{L_DISABLE_EXPLAIN}

@@ -15,7 +15,8 @@
{L_DISABLE} - + +
diff --git a/phpBB/adm/style/acp_ext_enable.html b/phpBB/adm/style/acp_ext_enable.html index 9f278bfbe0..3f7be2c847 100644 --- a/phpBB/adm/style/acp_ext_enable.html +++ b/phpBB/adm/style/acp_ext_enable.html @@ -15,7 +15,8 @@
{L_ENABLE} - + +
diff --git a/phpBB/adm/style/acp_ext_purge.html b/phpBB/adm/style/acp_ext_purge.html index 816fd872b9..00a58721cb 100644 --- a/phpBB/adm/style/acp_ext_purge.html +++ b/phpBB/adm/style/acp_ext_purge.html @@ -5,7 +5,7 @@

{L_EXTENSIONS_ADMIN}

{L_EXTENSIONS_EXPLAIN}

-

{L_ENABLE_EXPLAIN}

+

{L_PURGE_EXPLAIN}

@@ -15,7 +15,8 @@
{L_PURGE} - + +
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; } From 7b643fe8a5fd3b92bb4db9eacb27645417004709 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sun, 5 Aug 2012 19:00:20 -0500 Subject: [PATCH 43/48] [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/adm/style/acp_ext_details.html | 6 +++--- phpBB/adm/style/admin.css | 10 ++++++++++ phpBB/includes/acp/acp_extensions.php | 15 +++++++++----- phpBB/includes/extension/metadata_manager.php | 9 +++++++-- tests/extension/acp.php | 20 +++++++++---------- 5 files changed, 39 insertions(+), 21 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index e927e9de18..f477b452b7 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -3,7 +3,7 @@ « {L_BACK} - +

{L_EXTENSIONS_ADMIN}

@@ -50,13 +50,13 @@
{L_REQUIREMENTS} -
+ class="requirements_not_met">

{MD_REQUIRE_PHPBB}

-
+ class="requirements_not_met">

{MD_REQUIRE_PHP}

diff --git a/phpBB/adm/style/admin.css b/phpBB/adm/style/admin.css index 08613de0dd..585707600d 100644 --- a/phpBB/adm/style/admin.css +++ b/phpBB/adm/style/admin.css @@ -1718,3 +1718,13 @@ fieldset.permissions .padding { .phpinfo td, .phpinfo th, .phpinfo h2, .phpinfo h1 { text-align: left; } + +.requirements_not_met { + padding: 5px; + background-color: #BC2A4D; +} + +.requirements_not_met dt label, .requirements_not_met dd p { + color: #FFFFFF; + font-size: 1.4em; +} \ No newline at end of file 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('EXTENSION_NOT_AVAILABLE'); + trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action)); + } + + if ($phpbb_extension_manager->enabled($ext_name)) + { + 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']) : '', )); diff --git a/tests/extension/acp.php b/tests/extension/acp.php index c078a3f7b4..78a770343b 100644 --- a/tests/extension/acp.php +++ b/tests/extension/acp.php @@ -178,9 +178,11 @@ class acp_test extends phpbb_functional_test_case public function test_enable_pre() { - // Foo is already enabled (error) + // Foo is already enabled (redirect to list) $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=foo&sid=' . $this->sid); - $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('ENABLE_CONFIRM', $crawler->filter('html')->text()); @@ -188,9 +190,11 @@ class acp_test extends phpbb_functional_test_case public function test_disable_pre() { - // Moo is not enabled (error) + // Moo is not enabled (redirect to list) $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=vendor%2Fmoo&sid=' . $this->sid); - $this->assertContainsLang('EXTENSION_NOT_AVAILABLE', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_NAME', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_OPTIONS', $crawler->filter('html')->text()); + $this->assertContainsLang('EXTENSION_ACTIONS', $crawler->filter('html')->text()); $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable_pre&ext_name=foo&sid=' . $this->sid); $this->assertContainsLang('DISABLE_CONFIRM', $crawler->filter('html')->text()); @@ -206,20 +210,14 @@ class acp_test extends phpbb_functional_test_case $this->assertContainsLang('PURGE_CONFIRM', $crawler->filter('html')->text()); } - public function test_enable() + public function test_actions() { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=enable&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('ENABLE_SUCCESS', $crawler->filter('html')->text()); - } - public function test_disable() - { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=disable&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('DISABLE_SUCCESS', $crawler->filter('html')->text()); - } - public function test_purge() - { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=purge&ext_name=vendor%2Fmoo&sid=' . $this->sid); $this->assertContainsLang('PURGE_SUCCESS', $crawler->filter('html')->text()); } From 323bbf9b523984a592dc17bf35d2bb91a435be1b Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:06:23 +0100 Subject: [PATCH 44/48] [ticket/10631] Adjust prefixes to be easier to understand PHPBB3-10631 --- phpBB/adm/style/acp_ext_details.html | 74 +++++++++---------- phpBB/adm/style/acp_ext_list.html | 4 +- phpBB/includes/acp/acp_extensions.php | 12 +-- phpBB/includes/extension/metadata_manager.php | 26 +++---- 4 files changed, 58 insertions(+), 58 deletions(-) diff --git a/phpBB/adm/style/acp_ext_details.html b/phpBB/adm/style/acp_ext_details.html index f477b452b7..e7532691ad 100644 --- a/phpBB/adm/style/acp_ext_details.html +++ b/phpBB/adm/style/acp_ext_details.html @@ -8,57 +8,57 @@
{L_EXT_DETAILS} - +
-
-
{MD_DISPLAY_NAME}
+
+
{META_DISPLAY_NAME}
-
-
{MD_NAME}
+
+
{META_NAME}
- +
-
-

{MD_DESCRIPTION}

+
+

{META_DESCRIPTION}

-
-

{MD_VERSION}

+
+

{META_VERSION}

- +
-
-

{MD_HOMEPAGE}

+
+

{META_HOMEPAGE}

- +
-
-

{MD_TIME}

+
+

{META_TIME}

-
-

{MD_LICENCE}

+
+

{META_LICENCE}

- +
{L_REQUIREMENTS} - - class="requirements_not_met"> + + class="requirements_not_met">
-

{MD_REQUIRE_PHPBB}

+

{META_REQUIRE_PHPBB}

- - class="requirements_not_met"> + + class="requirements_not_met">
-

{MD_REQUIRE_PHP}

+

{META_REQUIRE_PHP}

@@ -66,32 +66,32 @@
{L_AUTHOR_INFORMATION} - +
-
-
{md_authors.AUTHOR_NAME}
+
+
{meta_authors.AUTHOR_NAME}
- +
-
-
{md_authors.AUTHOR_EMAIL}
+
+
{meta_authors.AUTHOR_EMAIL}
- +
-
-
{md_authors.AUTHOR_HOMEPAGE}
+
+
{meta_authors.AUTHOR_HOMEPAGE}
- +
-
{md_authors.AUTHOR_ROLE}
+
{meta_authors.AUTHOR_ROLE}
- +
diff --git a/phpBB/adm/style/acp_ext_list.html b/phpBB/adm/style/acp_ext_list.html index b654a80caa..53de0b4d12 100644 --- a/phpBB/adm/style/acp_ext_list.html +++ b/phpBB/adm/style/acp_ext_list.html @@ -24,7 +24,7 @@ - {enabled.EXT_NAME} + {enabled.META_DISPLAY_NAME} {L_DETAILS} @@ -42,7 +42,7 @@ - {disabled.EXT_NAME} + {disabled.META_DISPLAY_NAME} {L_DETAILS} 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'] : '', From f05a175e3955d1dc1d2b85b9929ca4b30340ad4a Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Fri, 17 Aug 2012 14:38:03 +0100 Subject: [PATCH 45/48] [ticket/10631] Fixing a few extension admin issues PHPBB3-10631 --- phpBB/includes/extension/metadata_manager.php | 3 --- tests/extension/ext/foo/composer.json | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) 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; } } diff --git a/tests/extension/ext/foo/composer.json b/tests/extension/ext/foo/composer.json index 4b5150461f..744f7be625 100644 --- a/tests/extension/ext/foo/composer.json +++ b/tests/extension/ext/foo/composer.json @@ -4,7 +4,7 @@ "description": "An example/sample extension to be used for testing purposes in phpBB Development.", "version": "1.0.0", "time": "2012-02-15 01:01:01", - "licence": "GNU GPL v2", + "licence": "GPL-2.0", "authors": [{ "name": "Nathan Guse", "username": "EXreaction", From a9b4f2a190777612762966476ac5af9ac2a78fd0 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Mon, 27 Aug 2012 17:39:32 -0500 Subject: [PATCH 46/48] [ticket/10631] Some cleanup of the test cases The acp test case was not actually validating things correctly. Now is does PHPBB3-10631 --- tests/extension/acp.php | 73 ++++++--------- tests/extension/metadata_manager_test.php | 105 +++++++++++++++++----- 2 files changed, 109 insertions(+), 69 deletions(-) diff --git a/tests/extension/acp.php b/tests/extension/acp.php index 78a770343b..790df77c0d 100644 --- a/tests/extension/acp.php +++ b/tests/extension/acp.php @@ -119,59 +119,40 @@ class acp_test extends phpbb_functional_test_case { $crawler = $this->request('GET', 'adm/index.php?i=acp_extensions&mode=main&action=details&ext_name=foo&sid=' . $this->sid); + $validation = array( + 'DISPLAY_NAME' => 'phpBB Foo Extension', + 'CLEAN_NAME' => 'foo/example', + 'DESCRIPTION' => 'An example/sample extension to be used for testing purposes in phpBB Development.', + 'VERSION' => '1.0.0', + 'TIME' => '2012-02-15 01:01:01', + 'LICENCE' => 'GPL-2.0', + 'PHPBB_VERSION' => '3.1.0-dev', + 'PHP_VERSION' => '>=5.3', + 'AUTHOR_NAME' => 'Nathan Guse', + 'AUTHOR_EMAIL' => 'email@phpbb.com', + 'AUTHOR_HOMEPAGE' => 'http://lithiumstudios.org', + 'AUTHOR_ROLE' => 'N/A', + ); + for ($i = 0; $i < $crawler->filter('dl')->count(); $i++) { $text = $crawler->filter('dl')->eq($i)->text(); - switch (true) + $match = false; + + foreach ($validation as $language_key => $expected) { - case (strpos($text, $this->lang('DISPLAY_NAME')) === 0): - $this->assertContains('phpBB Foo Extension', $text); - break; + if (strpos($text, $this->lang($language_key)) === 0) + { + $match = true; - case (strpos($text, $this->lang('CLEAN_NAME')) === 0): - $this->assertContains('foo/example', $text); - break; + $this->assertContains($expected, $text); + } + } - case (strpos($text, $this->lang('DESCRIPTION')) === 0): - $this->assertContains('An example/sample extension to be used for testing purposes in phpBB Development.', $text); - break; - - case (strpos($text, $this->lang('VERSION')) === 0): - $this->assertContains('1.0.0', $text); - break; - - case (strpos($text, $this->lang('TIME')) === 0): - $this->assertContains('2012-02-15 01:01:01', $text); - break; - - case (strpos($text, $this->lang('LICENCE')) === 0): - $this->assertContains('GNU GPL v2', $text); - break; - - case (strpos($text, $this->lang('PHPBB_VERSION')) === 0): - $this->assertContains('3.1.0-dev', $text); - break; - - case (strpos($text, $this->lang('PHP_VERSION')) === 0): - $this->assertContains('>=5.3', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_NAME')) === 0): - $this->assertContains('Nathan Guse', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_EMAIL')) === 0): - $this->assertContains('email@phpbb.com', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_HOMEPAGE')) === 0): - $this->assertContains('http://lithiumstudios.org', $text); - break; - - case (strpos($text, $this->lang('AUTHOR_ROLE')) === 0): - $this->assertContains('N/A', $text); - break; + if (!$match) + { + $this->fail('Unexpected field: "' . $text . '"'); } } } diff --git a/tests/extension/metadata_manager_test.php b/tests/extension/metadata_manager_test.php index 801d4dbeca..9865f14314 100644 --- a/tests/extension/metadata_manager_test.php +++ b/tests/extension/metadata_manager_test.php @@ -93,7 +93,7 @@ class metadata_manager_test extends phpbb_database_test_case $this->assertEquals($metadata, $json); } - public function test_validator() + public function test_validator_non_existant() { $ext_name = 'validator'; @@ -103,37 +103,57 @@ class metadata_manager_test extends phpbb_database_test_case try { $manager->validate('name'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'name\' has not been set.'); try { $manager->validate('type'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'type\' has not been set.'); try { $manager->validate('licence'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'licence\' has not been set.'); try { $manager->validate('version'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'version\' has not been set.'); try { $manager->validate_authors(); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'authors\' has not been set.'); $manager->merge_metadata(array( 'authors' => array( @@ -144,10 +164,21 @@ class metadata_manager_test extends phpbb_database_test_case try { $manager->validate_authors(); - } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Required meta field \'author name\' has not been set.'); + } + } + + + public function test_validator_invalid() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); // Invalid data $manager->set_metadata(array( @@ -160,31 +191,53 @@ class metadata_manager_test extends phpbb_database_test_case try { $manager->validate('name'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'name\' is invalid.'); try { $manager->validate('type'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'type\' is invalid.'); try { $manager->validate('licence'); + + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'licence\' is invalid.'); try { $manager->validate('version'); - } - catch(phpbb_extension_exception $e) {} - $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); + $this->fail('Exception not triggered'); + } + catch(phpbb_extension_exception $e) + { + $this->assertEquals((string) $e, 'Meta field \'version\' is invalid.'); + } + } + + public function test_validator_valid() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); // Valid data $manager->set_metadata(array( @@ -202,8 +255,14 @@ class metadata_manager_test extends phpbb_database_test_case { $this->fail($e); } + } + public function test_validator_requirements() + { + $ext_name = 'validator'; + + $manager = $this->get_metadata_manager($ext_name); // Too high of requirements $manager->merge_metadata(array( 'require' => array( From 0c35ee2769d3945f25275d5ee7a130b7596d289f Mon Sep 17 00:00:00 2001 From: "Michael C." Date: Sat, 1 Sep 2012 17:32:59 +0200 Subject: [PATCH 47/48] [ticket/10631] Fix a spelling typo PHPBB3-10631 --- phpBB/includes/acp/acp_extensions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From 81f7f28cc33d896973c2912097103ea84fa14114 Mon Sep 17 00:00:00 2001 From: Unknown Bliss Date: Sat, 1 Sep 2012 21:30:35 +0100 Subject: [PATCH 48/48] [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(-) 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; }