1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-07-31 14:00:31 +02:00

[feature/avatars] Simplify clean_row, move it to avatar manager

PHPBB3-10018
This commit is contained in:
Igor Wiedler
2012-04-08 21:29:52 +02:00
parent 81fb4268cd
commit 3b71e81cfb
7 changed files with 24 additions and 57 deletions

View File

@@ -119,45 +119,4 @@ abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface
{
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;
}
}

View File

@@ -21,12 +21,6 @@ if (!defined('IN_PHPBB'))
*/
interface phpbb_avatar_driver_interface
{
/**
* @TODO
*/
const FROM_USER = 0;
const FROM_GROUP = 1;
/**
* Get the avatar url and dimensions
*
@@ -63,9 +57,4 @@ interface phpbb_avatar_driver_interface
* @TODO
**/
public function delete($row);
/**
* @TODO
**/
public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER);
}

View File

@@ -125,4 +125,23 @@ class phpbb_avatar_manager
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);
}
}