From 7030578bbe9e11c18b5becaf8b06e670e3c2e3cd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Sun, 14 Jul 2013 01:32:34 -0400 Subject: [ticket/11698] Moving all autoloadable files to phpbb/ PHPBB3-11698 --- phpBB/phpbb/avatar/manager.php | 309 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 309 insertions(+) create mode 100644 phpBB/phpbb/avatar/manager.php (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php new file mode 100644 index 0000000000..58d994c3c0 --- /dev/null +++ b/phpBB/phpbb/avatar/manager.php @@ -0,0 +1,309 @@ + '', + 'avatar_type' => '', + 'avatar_width' => '', + 'avatar_height' => '', + ); + + /** + * Construct an avatar manager object + * + * @param phpbb_config $config phpBB configuration + * @param array $avatar_drivers Avatar drivers passed via the service container + * @param object $container Container object + */ + public function __construct(phpbb_config $config, $avatar_drivers, $container) + { + $this->config = $config; + $this->avatar_drivers = $avatar_drivers; + $this->container = $container; + } + + /** + * Get the driver object specified by the avatar type + * + * @param string $avatar_type Avatar type; by default an avatar's service container name + * @param bool $load_enabled Load only enabled avatars + * + * @return object Avatar driver object + */ + public function get_driver($avatar_type, $load_enabled = true) + { + if (self::$enabled_drivers === false) + { + $this->load_enabled_drivers(); + } + + $avatar_drivers = ($load_enabled) ? self::$enabled_drivers : $this->get_all_drivers(); + + // Legacy stuff... + switch ($avatar_type) + { + case AVATAR_GALLERY: + $avatar_type = 'avatar.driver.local'; + break; + case AVATAR_UPLOAD: + $avatar_type = 'avatar.driver.upload'; + break; + case AVATAR_REMOTE: + $avatar_type = 'avatar.driver.remote'; + break; + } + + if (!isset($avatar_drivers[$avatar_type])) + { + return null; + } + + /* + * There is no need to handle invalid avatar types as the following code + * will cause a ServiceNotFoundException if the type does not exist + */ + $driver = $this->container->get($avatar_type); + + return $driver; + } + + /** + * Load the list of enabled drivers + * This is executed once and fills self::$enabled_drivers + */ + protected function load_enabled_drivers() + { + if (!empty($this->avatar_drivers)) + { + self::$enabled_drivers = array(); + foreach ($this->avatar_drivers as $driver) + { + if ($this->is_enabled($driver)) + { + self::$enabled_drivers[$driver->get_name()] = $driver->get_name(); + } + } + asort(self::$enabled_drivers); + } + } + + /** + * Get a list of all avatar drivers + * + * As this function will only be called in the ACP avatar settings page, it + * doesn't make much sense to cache the list of all avatar drivers like the + * list of the enabled drivers. + * + * @return array Array containing a list of all avatar drivers + */ + public function get_all_drivers() + { + $drivers = array(); + + if (!empty($this->avatar_drivers)) + { + foreach ($this->avatar_drivers as $driver) + { + $drivers[$driver->get_name()] = $driver->get_name(); + } + asort($drivers); + } + + return $drivers; + } + + /** + * Get a list of enabled avatar drivers + * + * @return array Array containing a list of the enabled avatar drivers + */ + public function get_enabled_drivers() + { + if (self::$enabled_drivers === false) + { + $this->load_enabled_drivers(); + } + + return self::$enabled_drivers; + } + + /** + * Strip out user_ and group_ prefixes from keys + * + * @param array $row User data or group data + * + * @return array User data or group data with keys that have been + * stripped from the preceding "user_" or "group_" + */ + static public function clean_row($row) + { + // Upon creation of a user/group $row might be empty + if (empty($row)) + { + return self::$default_row; + } + + $keys = array_keys($row); + $values = array_values($row); + + $keys = array_map(array('phpbb_avatar_manager', 'strip_prefix'), $keys); + + return array_combine($keys, $values); + } + + /** + * Strip prepending user_ or group_ prefix from key + * + * @param string Array key + * @return string Key that has been stripped from its prefix + */ + static protected function strip_prefix($key) + { + return preg_replace('#^(?:user_|group_)#', '', $key); + } + + /** + * Clean driver names that are returned from template files + * Underscores are replaced with dots + * + * @param string $name Driver name + * + * @return string Cleaned driver name + */ + static public function clean_driver_name($name) + { + return str_replace('_', '.', $name); + } + + /** + * Prepare driver names for use in template files + * Dots are replaced with underscores + * + * @param string $name Clean driver name + * + * @return string Prepared driver name + */ + static public function prepare_driver_name($name) + { + return str_replace('.', '_', $name); + } + + /** + * Check if avatar is enabled + * + * @param object $driver Avatar driver object + * + * @return bool True if avatar is enabled, false if it's disabled + */ + public function is_enabled($driver) + { + $config_name = $this->get_driver_config_name($driver); + + return $this->config["allow_avatar_{$config_name}"]; + } + + /** + * Get the settings array for enabling/disabling an avatar driver + * + * @param object $driver Avatar driver object + * + * @return array Array of configuration options as consumed by acp_board + */ + public function get_avatar_settings($driver) + { + $config_name = $this->get_driver_config_name($driver); + + return array( + 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper($config_name), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + ); + } + + /** + * Get the config name of an avatar driver + * + * @param object $driver Avatar driver object + * + * @return string Avatar driver config name + */ + public function get_driver_config_name($driver) + { + return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + } + + /** + * Replace "error" strings with their real, localized form + * + * @param phpbb_user phpBB User object + * @param array $error Array containing error strings + * Key values can either be a string with a language key or an array + * that will be passed to vsprintf() with the language key in the + * first array key. + * + * @return array Array containing the localized error strings + */ + public function localize_errors(phpbb_user $user, $error) + { + foreach ($error as $key => $lang) + { + if (is_array($lang)) + { + $lang_key = array_shift($lang); + $error[$key] = vsprintf($user->lang($lang_key), $lang); + } + else + { + $error[$key] = $user->lang("$lang"); + } + } + + return $error; + } +} -- cgit v1.2.1 From b95fdacdd378877d277e261465da73deb06e50da Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Tue, 10 Sep 2013 14:01:09 +0200 Subject: [ticket/11700] Move all recent code to namespaces PHPBB3-11700 --- phpBB/phpbb/avatar/manager.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 58d994c3c0..717ba00ed7 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -7,6 +7,8 @@ * */ +namespace phpbb\avatar; + /** * @ignore */ @@ -18,11 +20,11 @@ if (!defined('IN_PHPBB')) /** * @package avatar */ -class phpbb_avatar_manager +class manager { /** * phpBB configuration - * @var phpbb_config + * @var \phpbb\config\config */ protected $config; @@ -59,11 +61,11 @@ class phpbb_avatar_manager /** * Construct an avatar manager object * - * @param phpbb_config $config phpBB configuration + * @param \phpbb\config\config $config phpBB configuration * @param array $avatar_drivers Avatar drivers passed via the service container * @param object $container Container object */ - public function __construct(phpbb_config $config, $avatar_drivers, $container) + public function __construct(\phpbb\config\config $config, $avatar_drivers, $container) { $this->config = $config; $this->avatar_drivers = $avatar_drivers; @@ -194,7 +196,7 @@ class phpbb_avatar_manager $keys = array_keys($row); $values = array_values($row); - $keys = array_map(array('phpbb_avatar_manager', 'strip_prefix'), $keys); + $keys = array_map(array('\phpbb\avatar\manager', 'strip_prefix'), $keys); return array_combine($keys, $values); } @@ -281,7 +283,7 @@ class phpbb_avatar_manager /** * Replace "error" strings with their real, localized form * - * @param phpbb_user phpBB User object + * @param \phpbb\user phpBB User object * @param array $error Array containing error strings * Key values can either be a string with a language key or an array * that will be passed to vsprintf() with the language key in the @@ -289,7 +291,7 @@ class phpbb_avatar_manager * * @return array Array containing the localized error strings */ - public function localize_errors(phpbb_user $user, $error) + public function localize_errors(\phpbb\user $user, $error) { foreach ($error as $key => $lang) { -- cgit v1.2.1 From fcd36ddd1f7c8a8b224423dca7599addbdaf1f57 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 16 Sep 2013 05:36:21 +0200 Subject: [ticket/11700] Correctly generate lang key from avatar driver class PHPBB3-11700 --- phpBB/phpbb/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 717ba00ed7..5d7f8f1b8f 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -264,7 +264,7 @@ class manager $config_name = $this->get_driver_config_name($driver); return array( - 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper($config_name), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), + 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper(str_replace('\\', '_', $config_name)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), ); } -- cgit v1.2.1 From 6e6681fa59a55393c52350d0086806662ba820fd Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 16 Sep 2013 05:58:40 +0200 Subject: [ticket/11700] Load avatar explanations correctly from namespaces PHPBB3-11700 --- phpBB/phpbb/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 5d7f8f1b8f..894ed080e6 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -277,7 +277,7 @@ class manager */ public function get_driver_config_name($driver) { - return preg_replace('#^phpbb_avatar_driver_#', '', get_class($driver)); + return preg_replace('#^phpbb\\\\avatar\\\\driver\\\\#', '', get_class($driver)); } /** -- cgit v1.2.1 From 77ffd5c6ba02e5dabebc34c479aa964e05f4038d Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Mon, 16 Sep 2013 06:44:16 +0200 Subject: [ticket/11700] Use underscores in avatar driver template file names PHPBB3-11700 --- phpBB/phpbb/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 894ed080e6..0408467064 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -235,7 +235,7 @@ class manager */ static public function prepare_driver_name($name) { - return str_replace('.', '_', $name); + return str_replace(array('\\', '.'), '_', $name); } /** -- cgit v1.2.1 From 15413f43e48b317fda276d0f9bb42d122caacf3c Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 19 Sep 2013 15:45:35 +0200 Subject: [ticket/11700] Correctly handle avatar drivers with namespaces PHPBB3-11700 --- phpBB/phpbb/avatar/manager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 0408467064..11f401d9ed 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -222,7 +222,7 @@ class manager */ static public function clean_driver_name($name) { - return str_replace('_', '.', $name); + return str_replace(array('\\', '_'), '.', $name); } /** @@ -235,7 +235,7 @@ class manager */ static public function prepare_driver_name($name) { - return str_replace(array('\\', '.'), '_', $name); + return str_replace('.', '_', $name); } /** @@ -277,7 +277,7 @@ class manager */ public function get_driver_config_name($driver) { - return preg_replace('#^phpbb\\\\avatar\\\\driver\\\\#', '', get_class($driver)); + return preg_replace('#^phpbb\\avatar\\driver\\\\#', '', get_class($driver)); } /** -- cgit v1.2.1 From 40ea7422b12b618cf7eecc01868b462eaed462a9 Mon Sep 17 00:00:00 2001 From: Nils Adermann Date: Thu, 19 Sep 2013 16:21:38 +0200 Subject: [ticket/11700] Correctly load avatar templates for namespaced drivers PHPBB3-11700 --- phpBB/phpbb/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 11f401d9ed..c28380a401 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -277,7 +277,7 @@ class manager */ public function get_driver_config_name($driver) { - return preg_replace('#^phpbb\\avatar\\driver\\\\#', '', get_class($driver)); + return preg_replace('#^phpbb\\\\avatar\\\\driver\\\\#', '', get_class($driver)); } /** -- cgit v1.2.1 From 9d4d212e0f71789e1f0332046dd852d80ab9c8ba Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 24 Oct 2013 13:55:23 +0200 Subject: [ticket/11525] Only remove group or user prefix from given avatar data Until now, the user data had both user_id and group_id keys in the avatar data. As both group_ and user_ prefixes were removed the group_id was collapsed onto the user_id and therefore all users in the same group had the same prefix for their uploaded avatars. This patch will make sure that the correct id is used depending on whether it's a group's or user's avatar data. PHPBB3-11525 --- phpBB/phpbb/avatar/manager.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index c28380a401..f2bb1a5dbe 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -178,14 +178,15 @@ class manager } /** - * Strip out user_ and group_ prefixes from keys + * Strip out user_, group_, or other prefixes from array keys * * @param array $row User data or group data + * @param string $prefix Prefix of data keys * * @return array User data or group data with keys that have been * stripped from the preceding "user_" or "group_" */ - static public function clean_row($row) + static public function clean_row($row, $prefix = '') { // Upon creation of a user/group $row might be empty if (empty($row)) @@ -196,7 +197,7 @@ class manager $keys = array_keys($row); $values = array_values($row); - $keys = array_map(array('\phpbb\avatar\manager', 'strip_prefix'), $keys); + array_walk($keys, array('\phpbb\avatar\manager', 'strip_prefix'), $prefix); return array_combine($keys, $values); } @@ -205,11 +206,12 @@ class manager * Strip prepending user_ or group_ prefix from key * * @param string Array key - * @return string Key that has been stripped from its prefix + * @return void */ - static protected function strip_prefix($key) + static protected function strip_prefix(&$key, $null, $prefix) { - return preg_replace('#^(?:user_|group_)#', '', $key); + $regex = ($prefix !== '') ? "#^(?:{$prefix}_)#" : '#^(?:user_|group_)#'; + $key = preg_replace($regex, '', $key); } /** -- cgit v1.2.1 From b2f638b79359ee6df600ca940ffa2b1657235364 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 27 Oct 2013 09:52:09 +0100 Subject: [ticket/11857] Use passed service collection instead of container in manager The service collection that was already passed to the avatar manager should be used in the avatar manager method get_driver() instead of the container itself. PHPBB3-11857 --- phpBB/phpbb/avatar/manager.php | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index c28380a401..7c26bce5ae 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -41,12 +41,6 @@ class manager */ protected $avatar_drivers; - /** - * Service container object - * @var object - */ - protected $container; - /** * Default avatar data row * @var array @@ -63,13 +57,27 @@ class manager * * @param \phpbb\config\config $config phpBB configuration * @param array $avatar_drivers Avatar drivers passed via the service container - * @param object $container Container object */ - public function __construct(\phpbb\config\config $config, $avatar_drivers, $container) + public function __construct(\phpbb\config\config $config, $avatar_drivers) { $this->config = $config; - $this->avatar_drivers = $avatar_drivers; - $this->container = $container; + $this->register_avatar_drivers($avatar_drivers); + } + + /** + * Register avatar drivers + * + * @param array $avatar_drivers Service collection of avatar drivers + */ + protected function register_avatar_drivers($avatar_drivers) + { + if (!empty($avatar_drivers)) + { + foreach ($avatar_drivers as $driver) + { + $this->avatar_drivers[$driver->get_name()] = $driver; + } + } } /** @@ -112,7 +120,7 @@ class manager * There is no need to handle invalid avatar types as the following code * will cause a ServiceNotFoundException if the type does not exist */ - $driver = $this->container->get($avatar_type); + $driver = $this->avatar_drivers[$avatar_type]; return $driver; } -- cgit v1.2.1 From 7aa8f6461f1e85cf91931f56b95384e54fec07c2 Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Wed, 30 Oct 2013 13:05:28 +0100 Subject: [task/code-sniffer] Remove the IN_PHPBB check side-effect from class files. PHPBB3-11980 --- phpBB/phpbb/avatar/manager.php | 8 -------- 1 file changed, 8 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 7c26bce5ae..5fe5e2b0a1 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -9,14 +9,6 @@ namespace phpbb\avatar; -/** -* @ignore -*/ -if (!defined('IN_PHPBB')) -{ - exit; -} - /** * @package avatar */ -- cgit v1.2.1 From 47f2caff6b3f05f6703e359bf4712bd69d23c04c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 10 Nov 2013 22:19:06 +0100 Subject: [ticket/11525] Fix doc blocks PHPBB3-11525 --- phpBB/phpbb/avatar/manager.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index f2bb1a5dbe..90cd83898f 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -180,8 +180,8 @@ class manager /** * Strip out user_, group_, or other prefixes from array keys * - * @param array $row User data or group data - * @param string $prefix Prefix of data keys + * @param array $row User data or group data + * @param string $prefix Prefix of data keys (e.g. user), should not include the trailing underscore * * @return array User data or group data with keys that have been * stripped from the preceding "user_" or "group_" @@ -205,8 +205,11 @@ class manager /** * Strip prepending user_ or group_ prefix from key * - * @param string Array key - * @return void + * @param string $key Array key + * @param string $null Parameter is ignored by the function, just required by the array_walk + * @param string $prefix Prefix that should be stripped off from the keys (e.g. user) + * Should not include the trailing underscore + * @return null */ static protected function strip_prefix(&$key, $null, $prefix) { -- cgit v1.2.1 From aa84f7de04b0efdf871d75694aee60e5ecf37f56 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sun, 10 Nov 2013 23:07:07 +0100 Subject: [ticket/11525] Prefix id parameter with 'g' again when its a group avatar PHPBB3-11525 --- phpBB/phpbb/avatar/manager.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 90cd83898f..9f6a5fb089 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -183,8 +183,9 @@ class manager * @param array $row User data or group data * @param string $prefix Prefix of data keys (e.g. user), should not include the trailing underscore * - * @return array User data or group data with keys that have been - * stripped from the preceding "user_" or "group_" + * @return array User or group data with keys that have been + * stripped from the preceding "user_" or "group_" + * Also the group id is prefixed with g, when the prefix group is removed. */ static public function clean_row($row, $prefix = '') { @@ -198,8 +199,14 @@ class manager $values = array_values($row); array_walk($keys, array('\phpbb\avatar\manager', 'strip_prefix'), $prefix); + $row = array_combine($keys, $values); - return array_combine($keys, $values); + if ($prefix == 'group') + { + $row['id'] = 'g' . $row['id']; + } + + return $row; } /** -- cgit v1.2.1 From 13a4ceedb18ba938d3cd18e2f68707385bc9283a Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Wed, 13 Nov 2013 18:27:40 +0100 Subject: [ticket/11525] Use foreach instead of array_walk in method clean_row() This approach is cleaner and probably even faster the previous ways that included using array_walk() or array_map() and other helper functions and methods. PHPBB3-11525 --- phpBB/phpbb/avatar/manager.php | 32 +++++++++----------------------- 1 file changed, 9 insertions(+), 23 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 9f6a5fb089..12d7861cdf 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -195,33 +195,19 @@ class manager return self::$default_row; } - $keys = array_keys($row); - $values = array_values($row); - - array_walk($keys, array('\phpbb\avatar\manager', 'strip_prefix'), $prefix); - $row = array_combine($keys, $values); - - if ($prefix == 'group') + $output = array(); + foreach ($row as $key => $value) { - $row['id'] = 'g' . $row['id']; + $key = preg_replace("#^(?:{$prefix}_)#", '', $key); + $output[$key] = $value; } - return $row; - } + if ($prefix === 'group' && isset($output['id'])) + { + $output['id'] = 'g' . $output['id']; + } - /** - * Strip prepending user_ or group_ prefix from key - * - * @param string $key Array key - * @param string $null Parameter is ignored by the function, just required by the array_walk - * @param string $prefix Prefix that should be stripped off from the keys (e.g. user) - * Should not include the trailing underscore - * @return null - */ - static protected function strip_prefix(&$key, $null, $prefix) - { - $regex = ($prefix !== '') ? "#^(?:{$prefix}_)#" : '#^(?:user_|group_)#'; - $key = preg_replace($regex, '', $key); + return $output; } /** -- cgit v1.2.1 From a759704b39fc1c1353f865a633759b1369589b67 Mon Sep 17 00:00:00 2001 From: Yuriy Rusko Date: Tue, 27 May 2014 20:18:06 +0200 Subject: [ticket/12594] Remove @package tags and update file headers PHPBB3-12594 --- phpBB/phpbb/avatar/manager.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 6ce924d2eb..7cf136be2c 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -1,17 +1,18 @@ +* @license GNU General Public License, version 2 (GPL-2.0) +* +* For full copyright and license information, please see +* the docs/CREDITS.txt file. * */ namespace phpbb\avatar; -/** -* @package avatar -*/ class manager { /** -- cgit v1.2.1 From e0c2013bb921f04f032744c3bc351c015c759d8d Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Thu, 7 Aug 2014 17:19:08 +0200 Subject: [ticket/12822] Add method for deleting avatars and use confirm_box The method will take care of the actual deletion process in the avatar manager. Additionally, we'll be using a confirm box while deleting the avatar to prevent users from accidentally deleting their avatars. PHPBB3-12822 --- phpBB/phpbb/avatar/manager.php | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 7cf136be2c..42ae61a9a2 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -41,8 +41,8 @@ class manager static protected $default_row = array( 'avatar' => '', 'avatar_type' => '', - 'avatar_width' => '', - 'avatar_height' => '', + 'avatar_width' => 0, + 'avatar_height' => 0, ); /** @@ -307,4 +307,36 @@ class manager return $error; } + + /** + * Handle deleting avatars + * + * @param \phpbb\db\driver\driver_interface $db phpBB dbal + * @param \phpbb\user $user phpBB user object + * @param array $avatar_data Cleaned user data containing the user's + * avatar data + * @param string $table Database table from which the avatar should be deleted + * @param string $prefix Prefix of user data columns in database + * @return null + */ + public function handle_avatar_delete(\phpbb\db\driver\driver_interface $db, \phpbb\user $user, $avatar_data, $table, $prefix) + { + if ($driver = $this->get_driver($avatar_data['avatar_type'])) + { + $driver->delete($avatar_data); + } + + $result = self::$default_row; + + foreach ($result as $key => $value) + { + $result[$prefix . $key] = $value; + unset($result[$key]); + } + + $sql = 'UPDATE ' . $table . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE ' . $prefix . 'id = ' . (int) $avatar_data['id']; + $db->sql_query($sql); + } } -- cgit v1.2.1 From 1da1a7065086d451f61cf470777dbd69bec3ee79 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 25 Oct 2014 15:57:41 -0700 Subject: [ticket/13197] Also delete group avatar from users that have it set PHPBB3-13197 --- phpBB/phpbb/avatar/manager.php | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 42ae61a9a2..5d001c0f73 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -326,17 +326,41 @@ class manager $driver->delete($avatar_data); } - $result = self::$default_row; - - foreach ($result as $key => $value) - { - $result[$prefix . $key] = $value; - unset($result[$key]); - } + $result = $this->prefix_avatar_columns($prefix, self::$default_row); $sql = 'UPDATE ' . $table . ' SET ' . $db->sql_build_array('UPDATE', $result) . ' WHERE ' . $prefix . 'id = ' . (int) $avatar_data['id']; $db->sql_query($sql); + + // Make sure we also delete this avatar from the users + if ($prefix === 'group_') + { + $result = $this->prefix_avatar_columns('user_', self::$default_row); + + $sql = 'UPDATE ' . USERS_TABLE . ' + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE user_avatar = "' . $db->sql_escape($avatar_data['avatar']) . '"'; + $db->sql_query($sql); + } + } + + /** + * Prefix avatar columns + * + * @param string $prefix Column prefix + * @param array $data Column data + * + * @return array Column data with prefixed column names + */ + public function prefix_avatar_columns($prefix, $data) + { + foreach ($data as $key => $value) + { + $data[$prefix . $key] = $value; + unset($data[$key]); + } + + return $data; } } -- cgit v1.2.1 From 8dd32c2bb5d1f99e59051797570c7f59fb937565 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 9 Nov 2014 13:07:38 +0100 Subject: [ticket/13197] Correctly format sql query PHPBB3-13197 --- phpBB/phpbb/avatar/manager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 5d001c0f73..0ff762a944 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -339,8 +339,8 @@ class manager $result = $this->prefix_avatar_columns('user_', self::$default_row); $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE user_avatar = "' . $db->sql_escape($avatar_data['avatar']) . '"'; + SET ' . $db->sql_build_array('UPDATE', $result) . " + WHERE user_avatar = '" . $db->sql_escape($avatar_data['avatar']) . "'"; $db->sql_query($sql); } } -- cgit v1.2.1 From f23634d58053efd811c87baafb1623624abb6c36 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sun, 9 Nov 2014 13:43:26 +0100 Subject: [ticket/13197] Fix tabbing PHPBB3-13197 --- phpBB/phpbb/avatar/manager.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 0ff762a944..8d83152ed6 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -329,8 +329,8 @@ class manager $result = $this->prefix_avatar_columns($prefix, self::$default_row); $sql = 'UPDATE ' . $table . ' - SET ' . $db->sql_build_array('UPDATE', $result) . ' - WHERE ' . $prefix . 'id = ' . (int) $avatar_data['id']; + SET ' . $db->sql_build_array('UPDATE', $result) . ' + WHERE ' . $prefix . 'id = ' . (int) $avatar_data['id']; $db->sql_query($sql); // Make sure we also delete this avatar from the users @@ -339,8 +339,8 @@ class manager $result = $this->prefix_avatar_columns('user_', self::$default_row); $sql = 'UPDATE ' . USERS_TABLE . ' - SET ' . $db->sql_build_array('UPDATE', $result) . " - WHERE user_avatar = '" . $db->sql_escape($avatar_data['avatar']) . "'"; + SET ' . $db->sql_build_array('UPDATE', $result) . " + WHERE user_avatar = '" . $db->sql_escape($avatar_data['avatar']) . "'"; $db->sql_query($sql); } } -- cgit v1.2.1 From 14dc274e9e3568a276c654b0845252019525fb6f Mon Sep 17 00:00:00 2001 From: javiexin Date: Thu, 16 Jul 2015 10:47:04 +0200 Subject: [ticket/14387] Extend avatar-driver by extension in ACP not possible Create a driver method to provide the driver config name, and use it within the manager method. Default driver config name is the same as now. But new drivers are able to override the config name with their own. PHPBB3-14387 --- phpBB/phpbb/avatar/manager.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 8d83152ed6..5274ac6a26 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -276,7 +276,7 @@ class manager */ public function get_driver_config_name($driver) { - return preg_replace('#^phpbb\\\\avatar\\\\driver\\\\#', '', get_class($driver)); + return $driver->get_config_name(); } /** -- cgit v1.2.1 From 06f4b6926baaf27897b2f57f7938eed4acf5dedb Mon Sep 17 00:00:00 2001 From: javiexin Date: Thu, 30 Jul 2015 01:43:18 +0200 Subject: [ticket/14387] Extend avatar-driver by extension in ACP not possible Create two driver methods to provide the driver config name and the driver ACP template name, and use them within the manager method. Default driver config name and template name are the same as now. But new drivers are able to override the config name and template name with their own, including @vendor_extension. PHPBB3-14387 --- phpBB/phpbb/avatar/manager.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 5274ac6a26..5db9ab13fb 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -279,6 +279,18 @@ class manager return $driver->get_config_name(); } + /** + * Get the template name of an avatar driver + * + * @param object $driver Avatar driver object + * + * @return string Avatar driver template name + */ + public function get_driver_template_name($driver) + { + return $driver->get_acp_template_name(); + } + /** * Replace "error" strings with their real, localized form * -- cgit v1.2.1 From 917c864bbf51309da4c8bda7ad03e1e00afc0764 Mon Sep 17 00:00:00 2001 From: javiexin Date: Thu, 30 Jul 2015 10:48:39 +0200 Subject: [ticket/14387] Extend avatar-driver by extension in ACP not possible Create two driver methods to provide the driver config name and the driver ACP template name, and use them directly when required. Default driver config name and template name are the same as now. But new drivers are able to override the config name and template name with their own, including @vendor_extension. Simplified manager interface by reducing unneeded methods. PHPBB3-14387 --- phpBB/phpbb/avatar/manager.php | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) (limited to 'phpBB/phpbb/avatar/manager.php') diff --git a/phpBB/phpbb/avatar/manager.php b/phpBB/phpbb/avatar/manager.php index 5db9ab13fb..26eb17c265 100644 --- a/phpBB/phpbb/avatar/manager.php +++ b/phpBB/phpbb/avatar/manager.php @@ -246,7 +246,7 @@ class manager */ public function is_enabled($driver) { - $config_name = $this->get_driver_config_name($driver); + $config_name = $driver->get_config_name(); return $this->config["allow_avatar_{$config_name}"]; } @@ -260,37 +260,13 @@ class manager */ public function get_avatar_settings($driver) { - $config_name = $this->get_driver_config_name($driver); + $config_name = $driver->get_config_name(); return array( 'allow_avatar_' . $config_name => array('lang' => 'ALLOW_' . strtoupper(str_replace('\\', '_', $config_name)), 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => false), ); } - /** - * Get the config name of an avatar driver - * - * @param object $driver Avatar driver object - * - * @return string Avatar driver config name - */ - public function get_driver_config_name($driver) - { - return $driver->get_config_name(); - } - - /** - * Get the template name of an avatar driver - * - * @param object $driver Avatar driver object - * - * @return string Avatar driver template name - */ - public function get_driver_template_name($driver) - { - return $driver->get_acp_template_name(); - } - /** * Replace "error" strings with their real, localized form * -- cgit v1.2.1