mirror of
https://github.com/phpbb/phpbb.git
synced 2025-02-24 12:03:21 +01:00
[feature/avatars] Rewrite drivers to use full class name
* Use full driver class name as avatar_type value * Move avatar drivers to core namespace * Make avatars installable through extensions PHPBB3-10018
This commit is contained in:
parent
13f4bfabbe
commit
df16bd1c49
@ -130,7 +130,7 @@ $phpbb_style = new phpbb_style($phpbb_root_path, $phpEx, $config, $user, $phpbb_
|
||||
$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);
|
||||
$phpbb_subscriber_loader->load();
|
||||
|
||||
$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver());
|
||||
$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver());
|
||||
|
||||
// Add own hook handler
|
||||
require($phpbb_root_path . 'includes/hooks/index.' . $phpEx);
|
||||
|
@ -82,7 +82,7 @@ if (isset($_GET['avatar']))
|
||||
$phpbb_subscriber_loader = new phpbb_event_extension_subscriber_loader($phpbb_dispatcher, $phpbb_extension_manager);
|
||||
$phpbb_subscriber_loader->load();
|
||||
|
||||
$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $cache->get_driver());
|
||||
$phpbb_avatar_manager = new phpbb_avatar_manager($phpbb_root_path, $phpEx, $config, $request, $phpbb_extension_manager, $cache->get_driver());
|
||||
|
||||
$filename = request_var('avatar', '');
|
||||
$avatar_group = false;
|
||||
|
@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))
|
||||
* Handles avatars selected from the board gallery
|
||||
* @package avatars
|
||||
*/
|
||||
class phpbb_avatar_driver_local extends phpbb_avatar_driver
|
||||
class phpbb_avatar_driver_core_local extends phpbb_avatar_driver
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))
|
||||
* Handles avatars hosted remotely
|
||||
* @package avatars
|
||||
*/
|
||||
class phpbb_avatar_driver_remote extends phpbb_avatar_driver
|
||||
class phpbb_avatar_driver_core_remote extends phpbb_avatar_driver
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))
|
||||
* Handles avatars uploaded to the board
|
||||
* @package avatars
|
||||
*/
|
||||
class phpbb_avatar_driver_upload extends phpbb_avatar_driver
|
||||
class phpbb_avatar_driver_core_upload extends phpbb_avatar_driver
|
||||
{
|
||||
/**
|
||||
* @inheritdoc
|
@ -119,4 +119,25 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
**/
|
||||
public function is_enabled()
|
||||
{
|
||||
$driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this));
|
||||
|
||||
return $this->config["allow_avatar_$driver"];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
**/
|
||||
public function get_template_name()
|
||||
{
|
||||
$driver = preg_replace('#^phpbb_avatar_driver_core_#', '', get_class($this));
|
||||
$template = "ucp_avatar_options_$driver.html";
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +57,14 @@ interface phpbb_avatar_driver_interface
|
||||
* @TODO
|
||||
**/
|
||||
public function delete($row);
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function is_enabled();
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function get_template_name();
|
||||
}
|
||||
|
@ -24,25 +24,27 @@ class phpbb_avatar_manager
|
||||
private $phpEx;
|
||||
private $config;
|
||||
private $request;
|
||||
private $extension_manager;
|
||||
private $cache;
|
||||
private static $valid_drivers = false;
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_cache_driver_interface $cache = null)
|
||||
public function __construct($phpbb_root_path, $phpEx, phpbb_config $config, phpbb_request $request, phpbb_extension_manager $extension_manager, phpbb_cache_driver_interface $cache = null)
|
||||
{
|
||||
$this->phpbb_root_path = $phpbb_root_path;
|
||||
$this->phpEx = $phpEx;
|
||||
$this->config = $config;
|
||||
$this->request = $request;
|
||||
$this->extension_manager = $extension_manager;
|
||||
$this->cache = $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @TODO
|
||||
**/
|
||||
public function get_driver($avatar_type, $new = false)
|
||||
public function get_driver($avatar_type)
|
||||
{
|
||||
if (self::$valid_drivers === false)
|
||||
{
|
||||
@ -53,30 +55,33 @@ class phpbb_avatar_manager
|
||||
switch ($avatar_type)
|
||||
{
|
||||
case AVATAR_GALLERY:
|
||||
$avatar_type = 'local';
|
||||
$avatar_type = 'phpbb_avatar_driver_local';
|
||||
break;
|
||||
case AVATAR_UPLOAD:
|
||||
$avatar_type = 'upload';
|
||||
$avatar_type = 'phpbb_avatar_driver_upload';
|
||||
break;
|
||||
case AVATAR_REMOTE:
|
||||
$avatar_type = 'remote';
|
||||
$avatar_type = 'phpbb_avatar_driver_remote';
|
||||
break;
|
||||
}
|
||||
|
||||
if (isset(self::$valid_drivers[$avatar_type]))
|
||||
{
|
||||
if ($new || !is_object(self::$valid_drivers[$avatar_type]))
|
||||
{
|
||||
$class_name = 'phpbb_avatar_driver_' . $avatar_type;
|
||||
self::$valid_drivers[$avatar_type] = new $class_name($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache);
|
||||
}
|
||||
|
||||
return self::$valid_drivers[$avatar_type];
|
||||
}
|
||||
else
|
||||
if (false === array_search($avatar_type, self::$valid_drivers))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
$r = new ReflectionClass($avatar_type);
|
||||
|
||||
if ($r->isSubClassOf('phpbb_avatar_driver')) {
|
||||
$driver = new $avatar_type($this->config, $this->request, $this->phpbb_root_path, $this->phpEx, $this->cache);
|
||||
} else if ($r->implementsInterface('phpbb_avatar_driver')) {
|
||||
$driver = new $avatar_type();
|
||||
} else {
|
||||
$message = "Invalid avatar driver class name '%s' provided. It must implement phpbb_avatar_driver_interface.";
|
||||
trigger_error(sprintf($message, $avatar_type));
|
||||
}
|
||||
|
||||
return $driver;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,18 +98,12 @@ class phpbb_avatar_manager
|
||||
{
|
||||
self::$valid_drivers = array();
|
||||
|
||||
$iterator = new DirectoryIterator($this->phpbb_root_path . 'includes/avatar/driver');
|
||||
$finder = $this->extension_manager->get_finder();
|
||||
|
||||
foreach ($iterator as $file)
|
||||
{
|
||||
// Match all files that appear to be php files
|
||||
if (preg_match("/^(.*)\.{$this->phpEx}$/", $file, $match))
|
||||
{
|
||||
self::$valid_drivers[] = $match[1];
|
||||
}
|
||||
}
|
||||
|
||||
self::$valid_drivers = array_flip(self::$valid_drivers);
|
||||
self::$valid_drivers = $finder
|
||||
->extension_directory('/avatar/driver/')
|
||||
->core_path('includes/avatar/driver/core/')
|
||||
->get_classes();
|
||||
|
||||
if ($this->cache)
|
||||
{
|
||||
@ -123,7 +122,7 @@ class phpbb_avatar_manager
|
||||
$this->load_valid_drivers();
|
||||
}
|
||||
|
||||
return array_keys(self::$valid_drivers);
|
||||
return self::$valid_drivers;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -623,18 +623,18 @@ class ucp_profile
|
||||
}
|
||||
|
||||
$focused_driver = request_var('avatar_driver', $user->data['user_avatar_type']);
|
||||
|
||||
|
||||
foreach ($avatar_drivers as $driver)
|
||||
{
|
||||
if ($config["allow_avatar_$driver"])
|
||||
$avatar = $phpbb_avatar_manager->get_driver($driver);
|
||||
|
||||
if ($avatar->is_enabled())
|
||||
{
|
||||
$avatars_enabled = true;
|
||||
$template->set_filenames(array(
|
||||
'avatar' => "ucp_avatar_options_$driver.html",
|
||||
'avatar' => $avatar->get_template_name(),
|
||||
));
|
||||
|
||||
$avatar = $phpbb_avatar_manager->get_driver($driver);
|
||||
|
||||
if ($avatar->prepare_form($template, $avatar_data, $error))
|
||||
{
|
||||
$driver_u = strtoupper($driver);
|
||||
|
Loading…
x
Reference in New Issue
Block a user