1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-12 03:34:04 +02:00

[feature/avatars] Make avatars generic

Adding a cleaning function for data coming from the users/groups
tables so drivers only deal with clean data (ideally). Refactored
get_user_avatar() and get_group_avatar() to use an underlying
get_avatar() function.

PHPBB3-10018
This commit is contained in:
Cullen Walsh
2011-06-18 22:50:52 -07:00
parent d0bb14ded1
commit a06380c69a
6 changed files with 141 additions and 78 deletions

View File

@@ -24,14 +24,14 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function get_data($user_row, $ignore_config = false)
public function get_data($row, $ignore_config = false)
{
if ($ignore_config || $this->config['allow_avatar_local'])
{
return array(
'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $user_row['user_avatar'],
'width' => $user_row['user_avatar_width'],
'height' => $user_row['user_avatar_height'],
'src' => $this->phpbb_root_path . $this->config['avatar_gallery_path'] . '/' . $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
else
@@ -47,7 +47,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function prepare_form($template, $user_row, &$error)
public function prepare_form($template, $row, &$error)
{
$avatar_list = $this->get_avatar_list();
$category = request_var('av_local_cat', '');
@@ -83,7 +83,7 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function process_form($template, $user_row, &$error)
public function process_form($template, $row, &$error)
{
$avatar_list = $this->get_avatar_list();
$category = request_var('av_local_cat', '');
@@ -96,9 +96,9 @@ class phpbb_avatar_driver_local extends phpbb_avatar_driver
}
return array(
'user_avatar' => $category . '/' . $file,
'user_avatar_width' => $avatar_list[$category][urldecode($file)]['width'],
'user_avatar_height' => $avatar_list[$category][urldecode($file)]['height'],
'avatar' => $category . '/' . $file,
'avatar_width' => $avatar_list[$category][urldecode($file)]['width'],
'avatar_height' => $avatar_list[$category][urldecode($file)]['height'],
);
}

View File

@@ -24,14 +24,14 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function get_data($user_row, $ignore_config = false)
public function get_data($row, $ignore_config = false)
{
if ($ignore_config || $this->config['allow_avatar_remote'])
{
return array(
'src' => $user_row['user_avatar'],
'width' => $user_row['user_avatar_width'],
'height' => $user_row['user_avatar_height'],
'src' => $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
else
@@ -47,12 +47,12 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function prepare_form($template, $user_row, &$error)
public function prepare_form($template, $row, &$error)
{
$template->assign_vars(array(
'AV_REMOTE_WIDTH' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_width']) ? $user_row['user_avatar_width'] : request_var('av_local_width', 0),
'AV_REMOTE_HEIGHT' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar_height']) ? $user_row['user_avatar_height'] : request_var('av_local_width', 0),
'AV_REMOTE_URL' => (($user_row['user_avatar_type'] == AVATAR_REMOTE || $user_row['user_avatar_type'] == 'remote') && $user_row['user_avatar']) ? $user_row['user_avatar'] : '',
'AV_REMOTE_WIDTH' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_width']) ? $row['avatar_width'] : request_var('av_local_width', 0),
'AV_REMOTE_HEIGHT' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar_height']) ? $row['avatar_height'] : request_var('av_local_width', 0),
'AV_REMOTE_URL' => (($row['avatar_type'] == AVATAR_REMOTE || $row['avatar_type'] == 'remote') && $row['avatar']) ? $row['avatar'] : '',
));
return true;
@@ -61,7 +61,7 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function process_form($template, $user_row, &$error)
public function process_form($template, $row, &$error)
{
$url = request_var('av_remote_url', '');
$width = request_var('av_remote_width', 0);
@@ -155,9 +155,9 @@ class phpbb_avatar_driver_remote extends phpbb_avatar_driver
}
return array(
'user_avatar' => $url,
'user_avatar_width' => $width,
'user_avatar_height' => $height,
'avatar' => $url,
'avatar_width' => $width,
'avatar_height' => $height,
);
}
}

View File

@@ -24,14 +24,14 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function get_data($user_row, $ignore_config = false)
public function get_data($row, $ignore_config = false)
{
if ($ignore_config || $this->config['allow_avatar_upload'])
{
return array(
'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $user_row['user_avatar'],
'width' => $user_row['user_avatar_width'],
'height' => $user_row['user_avatar_height'],
'src' => $this->phpbb_root_path . 'download/file.' . $this->phpEx . '?avatar=' . $row['avatar'],
'width' => $row['avatar_width'],
'height' => $row['avatar_height'],
);
}
else
@@ -47,7 +47,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function prepare_form($template, $user_row, &$error)
public function prepare_form($template, $row, &$error)
{
if (!$this->can_upload())
{
@@ -65,7 +65,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
/**
* @inheritdoc
*/
public function process_form($template, $user_row, &$error)
public function process_form($template, $row, &$error)
{
if (!$this->can_upload())
{
@@ -88,7 +88,7 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
}
$prefix = $this->config['avatar_salt'] . '_';
$file->clean_filename('avatar', $prefix, $user_row['user_id']);
$file->clean_filename('avatar', $prefix, $row['id']);
$destination = $this->config['avatar_path'];
@@ -115,19 +115,19 @@ class phpbb_avatar_driver_upload extends phpbb_avatar_driver
}
return array(
'user_avatar' => $user_row['user_id'] . '_' . time() . '.' . $file->get('extension'),
'user_avatar_width' => $file->get('width'),
'user_avatar_height' => $file->get('height'),
'avatar' => $row['id'] . '_' . time() . '.' . $file->get('extension'),
'avatar_width' => $file->get('width'),
'avatar_height' => $file->get('height'),
);
}
/**
* @inheritdoc
*/
public function delete($user_row)
public function delete($row)
{
$ext = substr(strrchr($user_row['user_avatar'], '.'), 1);
$filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $user_row['user_id'] . '.' . $ext;
$ext = substr(strrchr($row['avatar'], '.'), 1);
$filename = $this->phpbb_root_path . $this->config['avatar_path'] . '/' . $this->config['avatar_salt'] . '_' . $row['id'] . '.' . $ext;
if (file_exists($filename))
{