diff options
author | Marc Alexander <admin@m-a-styles.de> | 2013-10-24 13:55:23 +0200 |
---|---|---|
committer | Marc Alexander <admin@m-a-styles.de> | 2013-10-24 13:55:23 +0200 |
commit | 9d4d212e0f71789e1f0332046dd852d80ab9c8ba (patch) | |
tree | e3de96df60d80c913414cc7ac54952de7a78c955 | |
parent | 2adf3d7a3473fe8d01e850329bd935e97f09668d (diff) | |
download | forums-9d4d212e0f71789e1f0332046dd852d80ab9c8ba.tar forums-9d4d212e0f71789e1f0332046dd852d80ab9c8ba.tar.gz forums-9d4d212e0f71789e1f0332046dd852d80ab9c8ba.tar.bz2 forums-9d4d212e0f71789e1f0332046dd852d80ab9c8ba.tar.xz forums-9d4d212e0f71789e1f0332046dd852d80ab9c8ba.zip |
[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
-rw-r--r-- | phpBB/includes/acp/acp_groups.php | 2 | ||||
-rw-r--r-- | phpBB/includes/acp/acp_users.php | 2 | ||||
-rw-r--r-- | phpBB/includes/functions_display.php | 4 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_groups.php | 2 | ||||
-rw-r--r-- | phpBB/includes/ucp/ucp_profile.php | 2 | ||||
-rw-r--r-- | phpBB/phpbb/avatar/manager.php | 14 | ||||
-rw-r--r-- | tests/avatar/manager_test.php | 44 |
7 files changed, 55 insertions, 15 deletions
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index ad29a5521b..8f417e753c 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -324,7 +324,7 @@ class acp_groups $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the group_ prefix - $avatar_data = \phpbb\avatar\manager::clean_row($group_row); + $avatar_data = \phpbb\avatar\manager::clean_row($group_row, 'group'); } diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 8853200ddc..9feb1074d0 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1742,7 +1742,7 @@ class acp_users $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the user_ prefix - $avatar_data = \phpbb\avatar\manager::clean_row($user_row); + $avatar_data = \phpbb\avatar\manager::clean_row($user_row, 'user'); if ($submit) { diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index c6ab5df90f..f03e4c01d0 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1352,7 +1352,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank */ function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false) { - $row = \phpbb\avatar\manager::clean_row($user_row); + $row = \phpbb\avatar\manager::clean_row($user_row, 'user'); return phpbb_get_avatar($row, $alt, $ignore_config); } @@ -1367,7 +1367,7 @@ function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = */ function phpbb_get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false) { - $row = \phpbb\avatar\manager::clean_row($user_row); + $row = \phpbb\avatar\manager::clean_row($user_row, 'group'); return phpbb_get_avatar($row, $alt, $ignore_config); } diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index a75d2e9bfc..32b27b55b4 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -465,7 +465,7 @@ class ucp_groups $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the group_ prefix - $avatar_data = \phpbb\avatar\manager::clean_row($group_row); + $avatar_data = \phpbb\avatar\manager::clean_row($group_row, 'group'); } // Did we submit? diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 3f58ce20b4..f7c6aca9e8 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -567,7 +567,7 @@ class ucp_profile $avatar_drivers = $phpbb_avatar_manager->get_enabled_drivers(); // This is normalised data, without the user_ prefix - $avatar_data = \phpbb\avatar\manager::clean_row($user->data); + $avatar_data = \phpbb\avatar\manager::clean_row($user->data, 'user'); if ($submit) { 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); } /** diff --git a/tests/avatar/manager_test.php b/tests/avatar/manager_test.php index 4afa594beb..f687f7bc86 100644 --- a/tests/avatar/manager_test.php +++ b/tests/avatar/manager_test.php @@ -201,20 +201,58 @@ class phpbb_avatar_manager_test extends PHPUnit_Framework_TestCase 'foobar_avatar_height' => '', ), ), + array( + array( + 'user_avatar' => '', + 'user_id' => 5, + 'group_id' => 4, + ), + array( + 'avatar' => '', + 'id' => 4, + ), + ), + array( + array( + 'user_avatar' => '', + 'user_id' => 5, + 'group_id' => 4, + ), + array( + 'avatar' => '', + 'id' => 5, + 'group_id' => 4, + ), + 'user', + ), + array( + array( + 'group_avatar' => '', + 'user_id' => 5, + 'group_id' => 4, + ), + array( + 'avatar' => '', + 'id' => 4, + 'user_id' => 5, + ), + 'group', + ), ); } /** * @dataProvider database_row_data */ - public function test_clean_row(array $input, array $output) + public function test_clean_row(array $input, array $output, $prefix = '') { $cleaned_row = array(); - $cleaned_row = \phpbb\avatar\manager::clean_row($input); - foreach ($output as $key => $null) + $cleaned_row = \phpbb\avatar\manager::clean_row($input, $prefix); + foreach ($output as $key => $value) { $this->assertArrayHasKey($key, $cleaned_row); + $this->assertEquals($output[$key], $value); } } |