mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 22:10:45 +02:00
[ticket/10631] Various tidbits and cleanup on the acp extensions manager
PHPBB3-10631
This commit is contained in:
committed by
Unknown Bliss
parent
c45243a91e
commit
3ba59c6362
@@ -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(?<!&|=)(?!\.\s|\.{3}).*?))(\s|$)', $this->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(?<!&|=)(?!\.\s|\.{3}).*?))(\s|$)#', $this->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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user