mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
[feature/avatars] Simplify clean_row, move it to avatar manager
PHPBB3-10018
This commit is contained in:
parent
81fb4268cd
commit
3b71e81cfb
7 changed files with 24 additions and 57 deletions
|
@ -293,7 +293,7 @@ class acp_groups
|
||||||
sort($avatar_drivers);
|
sort($avatar_drivers);
|
||||||
|
|
||||||
// This is normalised data, without the group_ prefix
|
// This is normalised data, without the group_ prefix
|
||||||
$avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP);
|
$avatar_data = phpbb_avatar_manager::clean_row($group_row);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1692,7 +1692,7 @@ class acp_users
|
||||||
sort($avatar_drivers);
|
sort($avatar_drivers);
|
||||||
|
|
||||||
// This is normalised data, without the user_ prefix
|
// This is normalised data, without the user_ prefix
|
||||||
$avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER);
|
$avatar_data = phpbb_avatar_manager::clean_row($user_row);
|
||||||
|
|
||||||
if ($submit)
|
if ($submit)
|
||||||
{
|
{
|
||||||
|
|
|
@ -119,45 +119,4 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @inheritdoc
|
|
||||||
**/
|
|
||||||
public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER)
|
|
||||||
{
|
|
||||||
$return = array();
|
|
||||||
$prefix = false;
|
|
||||||
|
|
||||||
if ($src == phpbb_avatar_driver_interface::FROM_USER)
|
|
||||||
{
|
|
||||||
$prefix = 'user_';
|
|
||||||
}
|
|
||||||
else if ($src == phpbb_avatar_driver_interface::FROM_GROUP)
|
|
||||||
{
|
|
||||||
$prefix = 'group_';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($prefix)
|
|
||||||
{
|
|
||||||
$len = strlen($prefix);
|
|
||||||
foreach ($row as $key => $val)
|
|
||||||
{
|
|
||||||
$sub = substr($key, 0, $len);
|
|
||||||
if ($sub == $prefix)
|
|
||||||
{
|
|
||||||
$return[substr($key, $len)] = $val;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$return[$key] = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$return = $row;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,12 +21,6 @@ if (!defined('IN_PHPBB'))
|
||||||
*/
|
*/
|
||||||
interface phpbb_avatar_driver_interface
|
interface phpbb_avatar_driver_interface
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @TODO
|
|
||||||
*/
|
|
||||||
const FROM_USER = 0;
|
|
||||||
const FROM_GROUP = 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the avatar url and dimensions
|
* Get the avatar url and dimensions
|
||||||
*
|
*
|
||||||
|
@ -63,9 +57,4 @@ interface phpbb_avatar_driver_interface
|
||||||
* @TODO
|
* @TODO
|
||||||
**/
|
**/
|
||||||
public function delete($row);
|
public function delete($row);
|
||||||
|
|
||||||
/**
|
|
||||||
* @TODO
|
|
||||||
**/
|
|
||||||
public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,4 +125,23 @@ class phpbb_avatar_manager
|
||||||
|
|
||||||
return array_keys(self::$valid_drivers);
|
return array_keys(self::$valid_drivers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Strip out user_ and group_ prefixes from keys
|
||||||
|
**/
|
||||||
|
public static function clean_row($row)
|
||||||
|
{
|
||||||
|
$keys = array_keys($row);
|
||||||
|
$values = array_values($row);
|
||||||
|
|
||||||
|
$keys = array_map(
|
||||||
|
function ($key)
|
||||||
|
{
|
||||||
|
return preg_replace('(user_|group_)', '', $key);
|
||||||
|
},
|
||||||
|
$row
|
||||||
|
);
|
||||||
|
|
||||||
|
return array_combine($keys, $values);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1281,7 +1281,7 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank
|
||||||
*/
|
*/
|
||||||
function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false)
|
function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false)
|
||||||
{
|
{
|
||||||
$row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER);
|
$row = phpbb_avatar_manager::clean_row($user_row);
|
||||||
return get_avatar($row, $alt, $ignore_config);
|
return get_avatar($row, $alt, $ignore_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1296,7 +1296,7 @@ function get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false
|
||||||
*/
|
*/
|
||||||
function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false)
|
function get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false)
|
||||||
{
|
{
|
||||||
$row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP);
|
$row = phpbb_avatar_manager::clean_row($user_row);
|
||||||
return get_avatar($row, $alt, $ignore_config);
|
return get_avatar($row, $alt, $ignore_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -557,7 +557,7 @@ class ucp_profile
|
||||||
sort($avatar_drivers);
|
sort($avatar_drivers);
|
||||||
|
|
||||||
// This is normalised data, without the user_ prefix
|
// This is normalised data, without the user_ prefix
|
||||||
$avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER);
|
$avatar_data = phpbb_avatar_manager::clean_row($user->data);
|
||||||
|
|
||||||
if ($submit)
|
if ($submit)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue