[feature/avatars] Introduce an avatar driver interface

PHPBB3-10018
This commit is contained in:
Igor Wiedler 2012-04-08 16:40:19 +02:00
parent eea2ec5052
commit 81fb4268cd
6 changed files with 87 additions and 33 deletions

View file

@ -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::FROM_GROUP); $avatar_data = phpbb_avatar_driver::clean_row($group_row, phpbb_avatar_driver_interface::FROM_GROUP);
} }

View file

@ -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::FROM_USER); $avatar_data = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER);
if ($submit) if ($submit)
{ {

View file

@ -19,7 +19,7 @@ if (!defined('IN_PHPBB'))
* Base class for avatar drivers * Base class for avatar drivers
* @package avatars * @package avatars
*/ */
abstract class phpbb_avatar_driver abstract class phpbb_avatar_driver implements phpbb_avatar_driver_interface
{ {
/** /**
* Current board configuration * Current board configuration
@ -51,12 +51,6 @@ abstract class phpbb_avatar_driver
*/ */
protected $cache; protected $cache;
/**
* @TODO
*/
const FROM_USER = 0;
const FROM_GROUP = 1;
/** /**
* This flag should be set to true if the avatar requires a nonstandard image * This flag should be set to true if the avatar requires a nonstandard image
* tag, and will generate the html itself. * tag, and will generate the html itself.
@ -83,12 +77,7 @@ abstract class phpbb_avatar_driver
} }
/** /**
* Get the avatar url and dimensions * @inheritdoc
*
* @param $ignore_config Whether this function should respect the users prefs
* and board configuration configuration option, or should just render
* the avatar anyways. Useful for the ACP.
* @return array Avatar data
*/ */
public function get_data($row, $ignore_config = false) public function get_data($row, $ignore_config = false)
{ {
@ -100,13 +89,7 @@ abstract class phpbb_avatar_driver
} }
/** /**
* Returns custom html for displaying this avatar. * @inheritdoc
* Only called if $custom_html is true.
*
* @param $ignore_config Whether this function should respect the users prefs
* and board configuration configuration option, or should just render
* the avatar anyways. Useful for the ACP.
* @return string HTML
*/ */
public function get_custom_html($row, $ignore_config = false) public function get_custom_html($row, $ignore_config = false)
{ {
@ -114,7 +97,7 @@ abstract class phpbb_avatar_driver
} }
/** /**
* @TODO * @inheritdoc
**/ **/
public function prepare_form($template, $row, &$error, &$override_focus) public function prepare_form($template, $row, &$error, &$override_focus)
{ {
@ -122,7 +105,7 @@ abstract class phpbb_avatar_driver
} }
/** /**
* @TODO * @inheritdoc
**/ **/
public function process_form($template, $row, &$error) public function process_form($template, $row, &$error)
{ {
@ -130,7 +113,7 @@ abstract class phpbb_avatar_driver
} }
/** /**
* @TODO * @inheritdoc
**/ **/
public function delete($row) public function delete($row)
{ {
@ -138,18 +121,18 @@ abstract class phpbb_avatar_driver
} }
/** /**
* @TODO * @inheritdoc
**/ **/
public static function clean_row($row, $src = phpbb_avatar_driver::FROM_USER) public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER)
{ {
$return = array(); $return = array();
$prefix = false; $prefix = false;
if ($src == phpbb_avatar_driver::FROM_USER) if ($src == phpbb_avatar_driver_interface::FROM_USER)
{ {
$prefix = 'user_'; $prefix = 'user_';
} }
else if ($src == phpbb_avatar_driver::FROM_GROUP) else if ($src == phpbb_avatar_driver_interface::FROM_GROUP)
{ {
$prefix = 'group_'; $prefix = 'group_';
} }

View file

@ -0,0 +1,71 @@
<?php
/**
*
* @package avatar
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
/**
* Interface for avatar drivers
* @package avatars
*/
interface phpbb_avatar_driver_interface
{
/**
* @TODO
*/
const FROM_USER = 0;
const FROM_GROUP = 1;
/**
* Get the avatar url and dimensions
*
* @param $ignore_config Whether this function should respect the users prefs
* and board configuration configuration option, or should just render
* the avatar anyways. Useful for the ACP.
* @return array Avatar data, must have keys src, width and height, e.g.
* ['src' => '', 'width' => 0, 'height' => 0]
*/
public function get_data($row, $ignore_config = false);
/**
* Returns custom html for displaying this avatar.
* Only called if $custom_html is true.
*
* @param $ignore_config Whether this function should respect the users prefs
* and board configuration configuration option, or should just render
* the avatar anyways. Useful for the ACP.
* @return string HTML
*/
public function get_custom_html($row, $ignore_config = false);
/**
* @TODO
**/
public function prepare_form($template, $row, &$error, &$override_focus);
/**
* @TODO
**/
public function process_form($template, $row, &$error);
/**
* @TODO
**/
public function delete($row);
/**
* @TODO
**/
public static function clean_row($row, $src = phpbb_avatar_driver_interface::FROM_USER);
}

View file

@ -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::FROM_USER); $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_USER);
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::FROM_GROUP); $row = phpbb_avatar_driver::clean_row($user_row, phpbb_avatar_driver_interface::FROM_GROUP);
return get_avatar($row, $alt, $ignore_config); return get_avatar($row, $alt, $ignore_config);
} }

View file

@ -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::FROM_USER); $avatar_data = phpbb_avatar_driver::clean_row($user->data, phpbb_avatar_driver_interface::FROM_USER);
if ($submit) if ($submit)
{ {