mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/10631] Fixing and finishing the extension metadata class.
PHPBB3-10631
This commit is contained in:
parent
10cba1426d
commit
3e6761b026
2 changed files with 62 additions and 57 deletions
|
@ -25,7 +25,7 @@ class acp_extensions
|
||||||
function main()
|
function main()
|
||||||
{
|
{
|
||||||
// Start the page
|
// 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'));
|
$user->add_lang(array('install', 'acp/extensions'));
|
||||||
|
|
||||||
|
@ -42,11 +42,13 @@ class acp_extensions
|
||||||
$this->list_enabled_exts($db, $template);
|
$this->list_enabled_exts($db, $template);
|
||||||
$this->list_disabled_exts($db, $template);
|
$this->list_disabled_exts($db, $template);
|
||||||
$this->list_available_exts($phpbb_extension_manager, $template);
|
$this->list_available_exts($phpbb_extension_manager, $template);
|
||||||
|
|
||||||
$this->tpl_name = 'acp_ext_list';
|
$this->tpl_name = 'acp_ext_list';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'enable_pre':
|
case 'enable_pre':
|
||||||
$this->tpl_name = 'acp_ext_enable';
|
$this->tpl_name = 'acp_ext_enable';
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'PRE' => true,
|
'PRE' => true,
|
||||||
'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . $ext_name,
|
'U_ENABLE' => $this->u_action . '&action=enable&ext_name=' . $ext_name,
|
||||||
|
@ -55,7 +57,9 @@ class acp_extensions
|
||||||
|
|
||||||
case 'enable':
|
case 'enable':
|
||||||
$phpbb_extension_manager->enable($ext_name);
|
$phpbb_extension_manager->enable($ext_name);
|
||||||
|
|
||||||
$this->tpl_name = 'acp_ext_enable';
|
$this->tpl_name = 'acp_ext_enable';
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'U_RETURN' => $this->u_action . '&action=list',
|
'U_RETURN' => $this->u_action . '&action=list',
|
||||||
));
|
));
|
||||||
|
@ -63,6 +67,7 @@ class acp_extensions
|
||||||
|
|
||||||
case 'disable_pre':
|
case 'disable_pre':
|
||||||
$this->tpl_name = 'acp_ext_disable';
|
$this->tpl_name = 'acp_ext_disable';
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'PRE' => true,
|
'PRE' => true,
|
||||||
'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name,
|
'U_DISABLE' => $this->u_action . '&action=disable&ext_name=' . $ext_name,
|
||||||
|
@ -71,7 +76,9 @@ class acp_extensions
|
||||||
|
|
||||||
case 'disable':
|
case 'disable':
|
||||||
$phpbb_extension_manager->disable($ext_name);
|
$phpbb_extension_manager->disable($ext_name);
|
||||||
|
|
||||||
$this->tpl_name = 'acp_ext_disable';
|
$this->tpl_name = 'acp_ext_disable';
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'U_RETURN' => $this->u_action . '&action=list',
|
'U_RETURN' => $this->u_action . '&action=list',
|
||||||
));
|
));
|
||||||
|
@ -79,6 +86,7 @@ class acp_extensions
|
||||||
|
|
||||||
case 'purge_pre':
|
case 'purge_pre':
|
||||||
$this->tpl_name = 'acp_ext_purge';
|
$this->tpl_name = 'acp_ext_purge';
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'PRE' => true,
|
'PRE' => true,
|
||||||
'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name,
|
'U_PURGE' => $this->u_action . '&action=purge&ext_name=' . $ext_name,
|
||||||
|
@ -87,7 +95,9 @@ class acp_extensions
|
||||||
|
|
||||||
case 'purge':
|
case 'purge':
|
||||||
$phpbb_extension_manager->purge($ext_name);
|
$phpbb_extension_manager->purge($ext_name);
|
||||||
|
|
||||||
$this->tpl_name = 'acp_ext_purge';
|
$this->tpl_name = 'acp_ext_purge';
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'U_RETURN' => $this->u_action . '&action=list',
|
'U_RETURN' => $this->u_action . '&action=list',
|
||||||
));
|
));
|
||||||
|
@ -95,6 +105,7 @@ class acp_extensions
|
||||||
|
|
||||||
case 'delete_pre':
|
case 'delete_pre':
|
||||||
$this->tpl_name = 'acp_ext_delete';
|
$this->tpl_name = 'acp_ext_delete';
|
||||||
|
|
||||||
$template->assign_vars(array(
|
$template->assign_vars(array(
|
||||||
'PRE' => true,
|
'PRE' => true,
|
||||||
'U_DELETE' => $this->u_action . '&action=delete&ext_name=' . $ext_name,
|
'U_DELETE' => $this->u_action . '&action=delete&ext_name=' . $ext_name,
|
||||||
|
@ -106,9 +117,10 @@ class acp_extensions
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'details':
|
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->tpl_name = 'acp_ext_details';
|
||||||
$this->parse_meta_info($ext_name, $phpbb_extension_manager);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,6 +132,7 @@ class acp_extensions
|
||||||
WHERE ext_active = 1
|
WHERE ext_active = 1
|
||||||
ORDER BY ext_name ASC';
|
ORDER BY ext_name ASC';
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
// TODO: Use the display name from the composer.json
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$template->assign_block_vars('enabled', array(
|
$template->assign_block_vars('enabled', array(
|
||||||
|
@ -142,6 +155,7 @@ class acp_extensions
|
||||||
WHERE ext_active = 0
|
WHERE ext_active = 0
|
||||||
ORDER BY ext_name ASC';
|
ORDER BY ext_name ASC';
|
||||||
$result = $db->sql_query($sql);
|
$result = $db->sql_query($sql);
|
||||||
|
// TODO: Use the display name from the composer.json
|
||||||
while ($row = $db->sql_fetchrow($result))
|
while ($row = $db->sql_fetchrow($result))
|
||||||
{
|
{
|
||||||
$template->assign_block_vars('disabled', array(
|
$template->assign_block_vars('disabled', array(
|
||||||
|
@ -165,6 +179,8 @@ class acp_extensions
|
||||||
$all_configured = array_keys($phpbb_extension_manager->all_configured());
|
$all_configured = array_keys($phpbb_extension_manager->all_configured());
|
||||||
$uninstalled = array_diff($all_available, $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 $ext)
|
||||||
{
|
{
|
||||||
$template->assign_block_vars('disabled', array(
|
$template->assign_block_vars('disabled', array(
|
||||||
|
@ -178,34 +194,4 @@ class acp_extensions
|
||||||
|
|
||||||
return;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ class phpbb_extension_metadata_manager
|
||||||
protected $phpbb_root_path;
|
protected $phpbb_root_path;
|
||||||
protected $ext_name;
|
protected $ext_name;
|
||||||
protected $template;
|
protected $template;
|
||||||
protected $metadata;
|
public $metadata;
|
||||||
protected $metadata_file;
|
protected $metadata_file;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,13 +55,13 @@ class phpbb_extension_metadata_manager
|
||||||
* Processes and gets the metadata requested
|
* 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 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
|
* @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
|
// TODO: Check ext_name exists and is an extension that exists
|
||||||
if (!$this->set_meta_data_file())
|
if (!$this->set_metadata_file())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ class phpbb_extension_metadata_manager
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
break;
|
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
|
* @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);
|
$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';
|
||||||
|
@ -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
|
// 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;
|
// $this->metadata = $metadata_finished;
|
||||||
$metadata_finished = $this->metadata;
|
|
||||||
|
|
||||||
return $metadata_finished;
|
return $this->metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the name field
|
* Validates the contents of the name field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_name()
|
private function validate_name()
|
||||||
{
|
{
|
||||||
|
@ -159,7 +158,7 @@ class phpbb_extension_metadata_manager
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the type field
|
* Validates the contents of the type field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_type()
|
private function validate_type()
|
||||||
{
|
{
|
||||||
|
@ -169,7 +168,7 @@ class phpbb_extension_metadata_manager
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the description field
|
* Validates the contents of the description field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_description()
|
private function validate_description()
|
||||||
{
|
{
|
||||||
|
@ -179,27 +178,28 @@ class phpbb_extension_metadata_manager
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the version field
|
* Validates the contents of the version field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_version()
|
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
|
* Validates the contents of the license field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_license()
|
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
|
* 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()
|
private function validate_require_phpbb()
|
||||||
{
|
{
|
||||||
|
@ -209,7 +209,7 @@ class phpbb_extension_metadata_manager
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the display name field
|
* 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()
|
private function validate_extra_display_name()
|
||||||
{
|
{
|
||||||
|
@ -232,41 +232,60 @@ class phpbb_extension_metadata_manager
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the php requirement field
|
* 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()
|
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
|
* Validates the contents of the time field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_time()
|
private function validate_time()
|
||||||
{
|
{
|
||||||
|
// Need to validate
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the homepage field
|
* Validates the contents of the homepage field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_homepage()
|
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(?<!&|=)(?!\.\s|\.{3}).*?))(\s|$)', $this->metadata['homepage'])
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the contents of the authors field
|
* Validates the contents of the authors field
|
||||||
*
|
*
|
||||||
* @return bool True when passes validation
|
* @return boolean True when passes validation
|
||||||
*/
|
*/
|
||||||
private function validate_authors()
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue