1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-29 02:29:21 +02:00

Merge branch '3.2.x'

This commit is contained in:
Marc Alexander 2017-03-19 15:53:27 +01:00
commit adc2ea3f0c
No known key found for this signature in database
GPG Key ID: 50E0D2423696F995
2 changed files with 33 additions and 57 deletions

View File

@ -145,14 +145,13 @@ class acp_extensions
break; break;
case 'enable_pre': case 'enable_pre':
if (!$md_manager->validate_dir()) try
{ {
trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); $md_manager->validate_enable();
} }
catch (\phpbb\extension\exception $e)
if (!$md_manager->validate_enable())
{ {
trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($e . adm_back_link($this->u_action), E_USER_WARNING);
} }
$extension = $phpbb_extension_manager->get_extension($ext_name); $extension = $phpbb_extension_manager->get_extension($ext_name);
@ -176,14 +175,13 @@ class acp_extensions
break; break;
case 'enable': case 'enable':
if (!$md_manager->validate_dir()) try
{ {
trigger_error($user->lang['EXTENSION_DIR_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); $md_manager->validate_enable();
} }
catch (\phpbb\extension\exception $e)
if (!$md_manager->validate_enable())
{ {
trigger_error($user->lang['EXTENSION_NOT_AVAILABLE'] . adm_back_link($this->u_action), E_USER_WARNING); trigger_error($e . adm_back_link($this->u_action), E_USER_WARNING);
} }
$extension = $phpbb_extension_manager->get_extension($ext_name); $extension = $phpbb_extension_manager->get_extension($ext_name);

View File

@ -93,29 +93,18 @@ class metadata_manager
{ {
case 'all': case 'all':
default: default:
// Validate the metadata $this->validate();
if (!$this->validate())
{
return false;
}
return $this->metadata; return $this->metadata;
break; break;
case 'version': case 'version':
case 'name': case 'name':
return ($this->validate($element)) ? $this->metadata[$element] : false; $this->validate($element);
return $this->metadata[$element];
break; break;
case 'display-name': case 'display-name':
if (isset($this->metadata['extra']['display-name'])) return (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : $this->get_metadata('name');
{
return $this->metadata['extra']['display-name'];
}
else
{
return ($this->validate('name')) ? $this->metadata['name'] : false;
}
break; break;
} }
} }
@ -212,23 +201,8 @@ class metadata_manager
switch ($name) switch ($name)
{ {
case 'all': case 'all':
$this->validate('display'); $this->validate_enable();
// no break
if (!$this->validate_dir())
{
throw new \phpbb\extension\exception('EXTENSION_DIR_INVALID');
}
if (!$this->validate_require_phpbb())
{
throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('soft-require'));
}
if (!$this->validate_require_php())
{
throw new \phpbb\extension\exception('META_FIELD_NOT_SET', array('require php'));
}
break;
case 'display': case 'display':
foreach ($fields as $field => $data) foreach ($fields as $field => $data)
@ -285,40 +259,43 @@ class metadata_manager
/** /**
* This array handles the verification that this extension can be enabled on this board * This array handles the verification that this extension can be enabled on this board
* *
* @return bool True if validation succeeded, False if failed * @return bool True if validation succeeded, throws an exception if invalid
* @throws \phpbb\extension\exception
*/ */
public function validate_enable() public function validate_enable()
{ {
// Check for valid directory & phpBB, PHP versions // Check for valid directory & phpBB, PHP versions
if (!$this->validate_dir() || !$this->validate_require_phpbb() || !$this->validate_require_php()) return $this->validate_dir() && $this->validate_require_phpbb() && $this->validate_require_php();
{
return false;
}
return true;
} }
/** /**
* Validates the most basic directory structure to ensure it follows <vendor>/<ext> convention. * Validates the most basic directory structure to ensure it follows <vendor>/<ext> convention.
* *
* @return boolean True when passes validation * @return boolean True when passes validation, throws an exception if invalid
* @throws \phpbb\extension\exception
*/ */
public function validate_dir() public function validate_dir()
{ {
return (substr_count($this->ext_name, '/') === 1 && $this->ext_name == $this->get_metadata('name')); if (substr_count($this->ext_name, '/') !== 1 || $this->ext_name != $this->get_metadata('name'))
{
throw new \phpbb\extension\exception($this->user->lang('EXTENSION_DIR_INVALID'));
}
return true;
} }
/** /**
* Validates the contents of the phpbb requirement field * Validates the contents of the phpbb requirement field
* *
* @return boolean True when passes validation * @return boolean True when passes validation, throws an exception if invalid
* @throws \phpbb\extension\exception
*/ */
public function validate_require_phpbb() public function validate_require_phpbb()
{ {
if (!isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) if (!isset($this->metadata['extra']['soft-require']['phpbb/phpbb']))
{ {
return false; throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'soft-require'));
} }
return true; return true;
@ -327,13 +304,14 @@ class metadata_manager
/** /**
* Validates the contents of the php requirement field * Validates the contents of the php requirement field
* *
* @return boolean True when passes validation * @return boolean True when passes validation, throws an exception if invalid
* @throws \phpbb\extension\exception
*/ */
public function validate_require_php() public function validate_require_php()
{ {
if (!isset($this->metadata['require']['php'])) if (!isset($this->metadata['require']['php']))
{ {
return false; throw new \phpbb\extension\exception($this->user->lang('META_FIELD_NOT_SET', 'require php'));
} }
return true; return true;
@ -356,10 +334,10 @@ class metadata_manager
'META_LICENSE' => $this->metadata['license'], 'META_LICENSE' => $this->metadata['license'],
'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '', 'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? $this->metadata['require']['php'] : '',
'META_REQUIRE_PHP_FAIL' => !$this->validate_require_php(), 'META_REQUIRE_PHP_FAIL' => (isset($this->metadata['require']['php'])) ? false : true,
'META_REQUIRE_PHPBB' => (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? $this->metadata['extra']['soft-require']['phpbb/phpbb'] : '', 'META_REQUIRE_PHPBB' => (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? $this->metadata['extra']['soft-require']['phpbb/phpbb'] : '',
'META_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(), 'META_REQUIRE_PHPBB_FAIL' => (isset($this->metadata['extra']['soft-require']['phpbb/phpbb'])) ? false : true,
'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '', 'META_DISPLAY_NAME' => (isset($this->metadata['extra']['display-name'])) ? $this->metadata['extra']['display-name'] : '',
)); ));