From 3e6761b0266dfc67f6b41fea50d377b7621dffe0 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sun, 20 May 2012 14:16:00 +0100 Subject: [PATCH] [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; } /**