1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-10 18:54:08 +02:00

[ticket/15233] Standardize avatar output variables

PHPBB3-15233
This commit is contained in:
mrgoldy
2019-12-16 20:23:45 +01:00
committed by Marc Alexander
parent 3137070d50
commit 7e3d22063a
16 changed files with 182 additions and 50 deletions

View File

@@ -14,6 +14,7 @@
namespace phpbb\group;
use phpbb\auth\auth;
use phpbb\avatar\helper as avatar_helper;
use phpbb\cache\service as cache;
use phpbb\config\config;
use phpbb\language\language;
@@ -26,6 +27,9 @@ class helper
/** @var auth */
protected $auth;
/** @var avatar_helper */
protected $avatar_helper;
/** @var cache */
protected $cache;
@@ -54,6 +58,7 @@ class helper
* Constructor
*
* @param auth $auth Authentication object
* @param avatar_helper $avatar_helper Avatar helper object
* @param cache $cache Cache service object
* @param config $config Configuration object
* @param language $language Language object
@@ -61,9 +66,10 @@ class helper
* @param path_helper $path_helper Path helper object
* @param user $user User object
*/
public function __construct(auth $auth, cache $cache, config $config, language $language, dispatcher_interface $dispatcher, path_helper $path_helper, user $user)
public function __construct(auth $auth, avatar_helper $avatar_helper, cache $cache, config $config, language $language, dispatcher_interface $dispatcher, path_helper $path_helper, user $user)
{
$this->auth = $auth;
$this->avatar_helper = $avatar_helper;
$this->cache = $cache;
$this->config = $config;
$this->language = $language;
@@ -278,17 +284,17 @@ class helper
/**
* Get group avatar.
* Wrapper function for phpbb_get_group_avatar()
* Wrapper function for \phpbb\avatar\helper::get_group_avatar()
*
* @param array $group_row Row from the groups table
* @param string $alt Optional language string for alt tag within image, can be a language key or text
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
* @param bool $lazy If true, will be lazy loaded (requires JS)
*
* @return string Avatar html
* @return array Avatar data
*/
function get_avatar($group_row, $alt = 'GROUP_AVATAR', $ignore_config = false, $lazy = false)
{
return phpbb_get_group_avatar($group_row, $alt, $ignore_config, $lazy);
return $this->avatar_helper->get_group_avatar($group_row, $alt, $ignore_config, $lazy);
}
}

View File

@@ -284,10 +284,11 @@ abstract class base implements \phpbb\notification\type\type_interface
$u_mark_read = append_sid($this->phpbb_root_path . 'index.' . $this->php_ext, 'mark_notification=' . $this->notification_id . '&hash=' . $mark_hash . '&redirect=' . urlencode($redirect));
}
return array(
$avatar = $this->get_avatar();
return [
'NOTIFICATION_ID' => $this->notification_id,
'STYLING' => $this->get_style_class(),
'AVATAR' => $this->get_avatar(),
'FORMATTED_TITLE' => $this->get_title(),
'REFERENCE' => $this->get_reference(),
'FORUM' => $this->get_forum(),
@@ -295,8 +296,17 @@ abstract class base implements \phpbb\notification\type\type_interface
'URL' => $this->get_url(),
'TIME' => $this->user->format_date($this->notification_time),
'UNREAD' => !$this->notification_read,
'AVATAR' => $avatar ? $avatar['html'] : '',
'AVATAR_LAZY' => $avatar ? $avatar['lazy'] : true,
'AVATAR_SRC' => $avatar ? $avatar['src'] : '',
'AVATAR_TITLE' => $avatar ? $avatar['title'] : '',
'AVATAR_TYPE' => $avatar ? $avatar['type'] : '',
'AVATAR_WIDTH' => $avatar ? $avatar['width'] : 0,
'AVATAR_HEIGHT' => $avatar ? $avatar['height'] : 0,
'U_MARK_READ' => (!$this->notification_read) ? $u_mark_read : '',
);
];
}
/**
@@ -327,11 +337,11 @@ abstract class base implements \phpbb\notification\type\type_interface
/**
* Get the user's avatar (fall back)
*
* @return string
* @return array
*/
public function get_avatar()
{
return '';
return [];
}
/**

View File

@@ -23,6 +23,9 @@ namespace phpbb;
*/
class user_loader
{
/** @var \phpbb\avatar\helper */
protected $avatar_helper;
/** @var \phpbb\db\driver\driver_interface */
protected $db = null;
@@ -45,13 +48,15 @@ class user_loader
/**
* User loader constructor
*
* @param \phpbb\avatar\helper $avatar_helper Avatar helper object
* @param \phpbb\db\driver\driver_interface $db A database connection
* @param string $phpbb_root_path Path to the phpbb includes directory.
* @param string $php_ext php file extension
* @param string $users_table The name of the database table (phpbb_users)
*/
public function __construct(\phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext, $users_table)
public function __construct(\phpbb\avatar\helper $avatar_helper, \phpbb\db\driver\driver_interface $db, $phpbb_root_path, $php_ext, $users_table)
{
$this->avatar_helper = $avatar_helper;
$this->db = $db;
$this->phpbb_root_path = $phpbb_root_path;
@@ -182,23 +187,23 @@ class user_loader
* Typically this should be left as false and you should make sure
* you load users ahead of time with load_users()
* @param bool @lazy If true, will be lazy loaded (requires JS)
* @return string
* @return array
*/
public function get_avatar($user_id, $query = false, $lazy = false)
{
if (!($user = $this->get_user($user_id, $query)))
{
return '';
return [];
}
$row = array(
$row = [
'avatar' => $user['user_avatar'],
'avatar_type' => $user['user_avatar_type'],
'avatar_width' => $user['user_avatar_width'],
'avatar_height' => $user['user_avatar_height'],
);
];
return phpbb_get_avatar($row, 'USER_AVATAR', false, $lazy);
return $this->avatar_helper->get_avatar($row, 'USER_AVATAR', false, $lazy);
}
/**