mirror of
https://github.com/phpbb/phpbb.git
synced 2025-07-31 14:00:31 +02:00
Merge remote-tracking branch 'upstream/develop' into ticket/11015
* upstream/develop: (666 commits) [ticket/11077] Remove code from old global announcements system [ticket/11189] Replace DEBUG_EXTRA with DEBUG [ticket/11189] Always log critical errors when in cron or in image output [ticket/11187] Added a blank array to fix errors in functional tests [ticket/10780] Make L_COLON available in the installer. [ticket/11183] Remove $load_extensions and weird dl() calls [ticket/10970] Added extra documentation to parse_dynamic_path. [ticket/10939] Added documentation for phpbb_request::file [ticket/10865] Use code tags for install/database_update.php. [ticket/10865] Should have been a slash. [ticket/10780] Use L_COLON on LDAP page. [ticket/10780] Use L_COLON on search backend ACP pages. [ticket/10780] Use L_COLON for "download all attachments". [ticket/10780] Use colon from language in ucp_pm_compose.php where possible. [ticket/10780] Replace colons in phpBB/adm/style/acp_ext_details.html. [ticket/10780] Replace colon usage in adm template output with {L_COLON} [ticket/10780] Replace colon usage in template output with {L_COLON} [ticket/11181] Bump PHP requirement to 5.3.3 (from 5.3.2) [develop-olympus] [ticket/11181] Bump PHP requirement to 5.3.3 (from 5.3.2) [ticket/10172] Show prosilver birthday list even if there are no birthdays. ... Conflicts: phpBB/common.php phpBB/download/file.php phpBB/includes/db/dbal.php phpBB/includes/db/firebird.php phpBB/includes/db/mssql.php phpBB/includes/db/mssql_odbc.php phpBB/includes/db/mssqlnative.php phpBB/includes/db/mysql.php phpBB/includes/db/mysqli.php phpBB/includes/db/oracle.php phpBB/includes/db/postgres.php phpBB/includes/db/sqlite.php phpBB/includes/extension/manager.php phpBB/install/database_update.php
This commit is contained in:
@@ -23,37 +23,44 @@ if (!defined('IN_PHPBB'))
|
||||
abstract class phpbb_extension_controller implements phpbb_extension_controller_interface
|
||||
{
|
||||
/**
|
||||
* @var phpbb_request Request class object
|
||||
* Request class object
|
||||
* @var phpbb_request
|
||||
*/
|
||||
protected $request;
|
||||
|
||||
/**
|
||||
* @var dbal DBAL class object
|
||||
* DBAL class object
|
||||
* @var dbal
|
||||
*/
|
||||
protected $db;
|
||||
|
||||
/**
|
||||
* @var user User class object
|
||||
* User class object
|
||||
* @var phpbb_user
|
||||
*/
|
||||
protected $user;
|
||||
|
||||
/**
|
||||
* @var phpbb_template Template class object
|
||||
* Template class object
|
||||
* @var phpbb_template
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* @var array Config array
|
||||
* Config object
|
||||
* @var phpbb_config
|
||||
*/
|
||||
protected $config;
|
||||
|
||||
/**
|
||||
* @var string PHP Extension
|
||||
* PHP Extension
|
||||
* @var string
|
||||
*/
|
||||
protected $php_ext;
|
||||
|
||||
/**
|
||||
* @var string Relative path to board root
|
||||
* Relative path to board root
|
||||
* @var string
|
||||
*/
|
||||
protected $phpbb_root_path;
|
||||
|
||||
@@ -64,14 +71,14 @@ abstract class phpbb_extension_controller implements phpbb_extension_controller_
|
||||
public function __construct()
|
||||
{
|
||||
global $request, $db, $user, $template, $config;
|
||||
global $php_ext, $phpbb_root_path;
|
||||
global $phpEx, $phpbb_root_path;
|
||||
|
||||
$this->request = $request;
|
||||
$this->db = $db;
|
||||
$this->user = $user;
|
||||
$this->template = $template;
|
||||
$this->config = $config;
|
||||
$this->php_ext = $php_ext;
|
||||
$this->php_ext = $phpEx;
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
}
|
||||
}
|
||||
|
27
phpBB/includes/extension/exception.php
Normal file
27
phpBB/includes/extension/exception.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package extension
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class for metadata
|
||||
*/
|
||||
class phpbb_extension_exception extends UnexpectedValueException
|
||||
{
|
||||
public function __toString()
|
||||
{
|
||||
return $this->getMessage();
|
||||
}
|
||||
}
|
@@ -22,6 +22,8 @@ if (!defined('IN_PHPBB'))
|
||||
*/
|
||||
class phpbb_extension_manager
|
||||
{
|
||||
protected $db;
|
||||
protected $config;
|
||||
protected $cache;
|
||||
protected $php_ext;
|
||||
protected $extensions;
|
||||
@@ -33,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(phpbb_db_driver $db, $extension_table, $phpbb_root_path, $php_ext = '.php', phpbb_cache_driver_interface $cache = null, $cache_name = '_ext')
|
||||
public function __construct(phpbb_db_driver $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;
|
||||
@@ -63,6 +67,17 @@ class phpbb_extension_manager
|
||||
*/
|
||||
public function load_extensions()
|
||||
{
|
||||
$this->extensions = array();
|
||||
|
||||
// Do not try to load any extensions when installing or updating
|
||||
// Note: database updater invokes this code, and in 3.0
|
||||
// there is no extension table therefore the rest of this function
|
||||
// fails
|
||||
if (defined('IN_INSTALL'))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = 'SELECT *
|
||||
FROM ' . $this->extension_table;
|
||||
|
||||
@@ -70,7 +85,6 @@ class phpbb_extension_manager
|
||||
$extensions = $this->db->sql_fetchrowset($result);
|
||||
$this->db->sql_freeresult($result);
|
||||
|
||||
$this->extensions = array();
|
||||
foreach ($extensions as $extension)
|
||||
{
|
||||
$extension['ext_path'] = $this->get_extension_path($extension['ext_name']);
|
||||
@@ -120,6 +134,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 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a step of the extension enabling process.
|
||||
*
|
||||
|
338
phpBB/includes/extension/metadata_manager.php
Normal file
338
phpBB/includes/extension/metadata_manager.php
Normal file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* @package extension
|
||||
* @copyright (c) 2012 phpBB Group
|
||||
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ignore
|
||||
*/
|
||||
if (!defined('IN_PHPBB'))
|
||||
{
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* The extension metadata manager validates and gets meta-data for extensions
|
||||
*
|
||||
* @package extension
|
||||
*/
|
||||
class phpbb_extension_metadata_manager
|
||||
{
|
||||
protected $phpEx;
|
||||
protected $extension_manager;
|
||||
protected $db;
|
||||
protected $phpbb_root_path;
|
||||
protected $template;
|
||||
protected $ext_name;
|
||||
protected $metadata;
|
||||
protected $metadata_file;
|
||||
|
||||
/**
|
||||
* 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, phpbb_db_driver $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;
|
||||
$this->ext_name = $ext_name;
|
||||
$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.
|
||||
* @return array Contains all of the requested metadata, throws an exception on failure
|
||||
*/
|
||||
public function get_metadata($element = 'all')
|
||||
{
|
||||
$this->set_metadata_file();
|
||||
|
||||
// Fetch the metadata
|
||||
$this->fetch_metadata();
|
||||
|
||||
// Clean the metadata
|
||||
$this->clean_metadata_array();
|
||||
|
||||
switch ($element)
|
||||
{
|
||||
case 'all':
|
||||
default:
|
||||
// Validate the metadata
|
||||
if (!$this->validate())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->metadata;
|
||||
break;
|
||||
|
||||
case 'name':
|
||||
return ($this->validate('name')) ? $this->metadata['name'] : false;
|
||||
break;
|
||||
|
||||
case 'display-name':
|
||||
if (isset($this->metadata['extra']['display-name']))
|
||||
{
|
||||
return $this->metadata['extra']['display-name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
return ($this->validate('name')) ? $this->metadata['name'] : false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the filepath of the metadata file
|
||||
*
|
||||
* @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';
|
||||
|
||||
$this->metadata_file = $metadata_filepath;
|
||||
|
||||
if (!file_exists($this->metadata_file))
|
||||
{
|
||||
throw new phpbb_extension_exception('The required file does not exist: ' . $this->metadata_file);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the contents of the composer.json file
|
||||
*
|
||||
* @return bool True if success, throws an exception on failure
|
||||
*/
|
||||
private function fetch_metadata()
|
||||
{
|
||||
if (!file_exists($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_extension_exception('file_get_contents failed on ' . $this->metadata_file);
|
||||
}
|
||||
|
||||
if (($metadata = json_decode($file_contents, true)) === NULL)
|
||||
{
|
||||
throw new phpbb_extension_exception('json_decode failed on ' . $this->metadata_file);
|
||||
}
|
||||
|
||||
$this->metadata = $metadata;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This array handles the cleaning of the array
|
||||
*
|
||||
* @return array Contains the cleaned metadata array
|
||||
*/
|
||||
private function clean_metadata_array()
|
||||
{
|
||||
return $this->metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate fields
|
||||
*
|
||||
* @param string $name ("all" for display and enable validation
|
||||
* "display" for name, type, and authors
|
||||
* "name", "type")
|
||||
* @return Bool True if valid, throws an exception if invalid
|
||||
*/
|
||||
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' => '#.+#',
|
||||
);
|
||||
|
||||
switch ($name)
|
||||
{
|
||||
case 'all':
|
||||
$this->validate('display');
|
||||
|
||||
$this->validate_enable();
|
||||
break;
|
||||
|
||||
case 'display':
|
||||
foreach ($fields as $field => $data)
|
||||
{
|
||||
$this->validate($field);
|
||||
}
|
||||
|
||||
$this->validate_authors();
|
||||
break;
|
||||
|
||||
default:
|
||||
if (isset($fields[$name]))
|
||||
{
|
||||
if (!isset($this->metadata[$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_extension_exception("Meta field '$name' is invalid.");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the contents of the authors field
|
||||
*
|
||||
* @return boolean True when passes validation, throws exception if invalid
|
||||
*/
|
||||
public function validate_authors()
|
||||
{
|
||||
if (empty($this->metadata['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_extension_exception("Required meta field 'author name' has not been set.");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This array handles the verification that this extension can be enabled on this board
|
||||
*
|
||||
* @return bool True if validation succeeded, False if failed
|
||||
*/
|
||||
public function validate_enable()
|
||||
{
|
||||
// Check for phpBB, PHP versions
|
||||
if (!$this->validate_require_phpbb() || !$this->validate_require_php())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Validates the contents of the phpbb requirement field
|
||||
*
|
||||
* @return boolean True when passes validation
|
||||
*/
|
||||
public function validate_require_phpbb()
|
||||
{
|
||||
if (!isset($this->metadata['require']['phpbb']))
|
||||
{
|
||||
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
|
||||
*/
|
||||
public function validate_require_php()
|
||||
{
|
||||
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, '>=');
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs the metadata into the template
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function output_template_data()
|
||||
{
|
||||
$this->template->assign_vars(array(
|
||||
'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']),
|
||||
|
||||
'META_REQUIRE_PHP' => (isset($this->metadata['require']['php'])) ? htmlspecialchars($this->metadata['require']['php']) : '',
|
||||
'META_REQUIRE_PHP_FAIL' => !$this->validate_require_php(),
|
||||
|
||||
'META_REQUIRE_PHPBB' => (isset($this->metadata['require']['phpbb'])) ? htmlspecialchars($this->metadata['require']['phpbb']) : '',
|
||||
'META_REQUIRE_PHPBB_FAIL' => !$this->validate_require_phpbb(),
|
||||
|
||||
'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('meta_authors', array(
|
||||
'AUTHOR_NAME' => htmlspecialchars($author['name']),
|
||||
'AUTHOR_EMAIL' => (isset($author['email'])) ? $author['email'] : '',
|
||||
'AUTHOR_HOMEPAGE' => (isset($author['homepage'])) ? $author['homepage'] : '',
|
||||
'AUTHOR_ROLE' => (isset($author['role'])) ? htmlspecialchars($author['role']) : '',
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
@@ -16,7 +16,15 @@ if (!defined('IN_PHPBB'))
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides a set of items found in extensions
|
||||
* Provides a set of items found in extensions.
|
||||
*
|
||||
* This abstract class is essentially a wrapper around item-specific
|
||||
* finding logic. It handles storing the extension manager via constructor
|
||||
* for the finding logic to use to find the items, and provides an
|
||||
* iterator interface over the items found by the finding logic.
|
||||
*
|
||||
* Items could be anything, for example template paths or cron task names.
|
||||
* Derived classes completely define what the items are.
|
||||
*
|
||||
* @package extension
|
||||
*/
|
||||
@@ -45,7 +53,7 @@ abstract class phpbb_extension_provider implements IteratorAggregate
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds template paths using the extension manager.
|
||||
* Finds items using the extension manager.
|
||||
*
|
||||
* @return array List of task names
|
||||
*/
|
||||
|
Reference in New Issue
Block a user