From 7e3d22063a0807640bb9838ba7b6c6bda507a943 Mon Sep 17 00:00:00 2001 From: mrgoldy Date: Mon, 16 Dec 2019 20:23:45 +0100 Subject: [PATCH] [ticket/15233] Standardize avatar output variables PHPBB3-15233 --- phpBB/config/default/container/services.yml | 1 + .../default/container/services_user.yml | 1 + phpBB/includes/acp/acp_groups.php | 12 ++++--- phpBB/includes/acp/acp_users.php | 14 ++++++-- phpBB/includes/functions.php | 19 ++++++++++- phpBB/includes/functions_display.php | 16 ++++++++-- phpBB/includes/mcp/mcp_notes.php | 15 +++++++-- phpBB/includes/mcp/mcp_warn.php | 32 +++++++++++++++---- phpBB/includes/ucp/ucp_groups.php | 14 +++++--- phpBB/includes/ucp/ucp_pm_viewmessage.php | 15 +++++++-- phpBB/includes/ucp/ucp_profile.php | 15 +++++++-- phpBB/memberlist.php | 11 +++++-- phpBB/phpbb/group/helper.php | 14 +++++--- phpBB/phpbb/notification/type/base.php | 20 +++++++++--- phpBB/phpbb/user_loader.php | 17 ++++++---- phpBB/viewtopic.php | 16 +++++++--- 16 files changed, 182 insertions(+), 50 deletions(-) diff --git a/phpBB/config/default/container/services.yml b/phpBB/config/default/container/services.yml index b34e5306e3..05f50d1622 100644 --- a/phpBB/config/default/container/services.yml +++ b/phpBB/config/default/container/services.yml @@ -123,6 +123,7 @@ services: class: phpbb\group\helper arguments: - '@auth' + - '@avatar.helper' - '@cache' - '@config' - '@language' diff --git a/phpBB/config/default/container/services_user.yml b/phpBB/config/default/container/services_user.yml index 7e634c60c3..154e9aebf6 100644 --- a/phpBB/config/default/container/services_user.yml +++ b/phpBB/config/default/container/services_user.yml @@ -14,6 +14,7 @@ services: user_loader: class: phpbb\user_loader arguments: + - '@avatar.helper' - '@dbal.conn' - '%core.root_path%' - '%core.php_ext%' diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 7b1dc706db..8cb8e778b7 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -721,7 +721,7 @@ class acp_groups } } - $avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true); + $group_avatar = $group_helper->get_avatar($group_row, 'GROUP_AVATAR', true); if (isset($phpbb_avatar_manager) && !$update) { @@ -771,10 +771,14 @@ class acp_groups 'S_RANK_OPTIONS' => $rank_options, 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)), - 'AVATAR' => empty($avatar) ? '' : $avatar, + 'AVATAR' => empty($group_avatar['html']) ? '' : $group_avatar['html'], + 'AVATAR_LAZY' => $group_avatar['lazy'], + 'AVATAR_SRC' => $group_avatar['src'], + 'AVATAR_TITLE' => $group_avatar['title'], + 'AVATAR_TYPE' => $group_avatar['type'], + 'AVATAR_WIDTH' => $group_avatar['width'], + 'AVATAR_HEIGHT' => $group_avatar['height'], 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'], - 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '', - 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '', 'GROUP_TYPE_FREE' => GROUP_FREE, 'GROUP_TYPE_OPEN' => GROUP_OPEN, diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index 94a9e50a7b..e3045ffe19 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1968,12 +1968,22 @@ class acp_users $error = $phpbb_avatar_manager->localize_errors($user, $error); } - $avatar = phpbb_get_user_avatar($user_row, 'USER_AVATAR', true); + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($user_row, 'USER_AVATAR', true); $template->assign_vars(array( 'S_AVATAR' => true, 'ERROR' => (!empty($error)) ? implode('
', $error) : '', - 'AVATAR' => (empty($avatar) ? '' : $avatar), + + 'AVATAR' => empty($avatar['html']) ? '' : $avatar['html'], + 'AVATAR_LAZY' => $avatar['lazy'], + 'AVATAR_SOURCE' => $avatar['src'], + 'AVATAR_TITLE' => $avatar['title'], + 'AVATAR_TYPE' => $avatar['type'], + 'AVATAR_WIDTH' => $avatar['width'], + 'AVATAR_HEIGHT' => $avatar['height'], 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index db6704ce86..f8122c4272 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3523,6 +3523,8 @@ function phpbb_quoteattr($data, $entities = null) /** * Get user avatar * +* @deprecated 4.0.0 Use \phpbb\avatar\helper::get_user_avatar() instead +* * @param array $user_row Row from the users 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 @@ -3539,6 +3541,8 @@ function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = /** * Get group avatar * +* @deprecated 4.0.0 Use \phpbb\avatar\helper::get_group_avatar() instead +* * @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 @@ -3555,6 +3559,8 @@ function phpbb_get_group_avatar($group_row, $alt = 'GROUP_AVATAR', $ignore_confi /** * Get avatar * +* @deprecated 4.0.0 Use \phpbb\avatar\helper::get_avatar() instead +* * @param array $row Row cleaned by \phpbb\avatar\manager::clean_row * @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 @@ -3862,6 +3868,11 @@ function page_header($page_title = '', $display_online_list = false, $item_id = // Add form token for login box, in case page is presenting a login form. add_form_key('login', '_LOGIN'); + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($user->data); + // The following assigns all _common_ variables that may be used at any point in a template. $template->assign_vars(array( 'SITENAME' => $config['sitename'], @@ -3876,7 +3887,13 @@ function page_header($page_title = '', $display_online_list = false, $item_id = 'RECORD_USERS' => $l_online_record, 'PRIVATE_MESSAGE_COUNT' => (!empty($user->data['user_unread_privmsg'])) ? $user->data['user_unread_privmsg'] : 0, - 'CURRENT_USER_AVATAR' => phpbb_get_user_avatar($user->data), + 'CURRENT_USER_AVATAR' => $avatar['html'], + 'CURRENT_USER_AVATAR_LAZY' => $avatar['lazy'], + 'CURRENT_USER_AVATAR_SOURCE' => $avatar['src'], + 'CURRENT_USER_AVATAR_TITLE' => $avatar['title'], + 'CURRENT_USER_AVATAR_TYPE' => $avatar['type'], + 'CURRENT_USER_AVATAR_WIDTH' => $avatar['width'], + 'CURRENT_USER_AVATAR_HEIGHT' => $avatar['height'], 'CURRENT_USERNAME_SIMPLE' => get_username_string('no_profile', $user->data['user_id'], $user->data['username'], $user->data['user_colour']), 'CURRENT_USERNAME_FULL' => get_username_string('full', $user->data['user_id'], $user->data['username'], $user->data['user_colour']), 'CURRENT_USER_GROUP_COLOR' => $user->data['user_colour'], diff --git a/phpBB/includes/functions_display.php b/phpBB/includes/functions_display.php index db6ae7e6f1..b4ab8a9c7a 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1570,7 +1570,7 @@ function phpbb_get_user_rank($user_data, $user_posts) */ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabled = false, $check_can_receive_pm = true) { - global $config, $auth, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher; + global $config, $auth, $user, $phpEx, $phpbb_root_path, $phpbb_dispatcher, $phpbb_container; $username = $data['username']; $user_id = $data['user_id']; @@ -1653,6 +1653,11 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl (($auth->acl_gets('a_', 'm_') || $auth->acl_getf_global('m_')) || $data['user_allow_pm']) ); + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($data); + // Dump it out to the template $template_data = array( 'AGE' => $age, @@ -1669,7 +1674,14 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl 'A_USERNAME' => addslashes(get_username_string('username', $user_id, $username, $data['user_colour'])), - 'AVATAR_IMG' => phpbb_get_user_avatar($data), + 'AVATAR_IMG' => $avatar['html'], + 'AVATAR_LAZY' => $avatar['lazy'], + 'AVATAR_SOURCE' => $avatar['src'], + 'AVATAR_TITLE' => $avatar['title'], + 'AVATAR_TYPE' => $avatar['type'], + 'AVATAR_WIDTH' => $avatar['width'], + 'AVATAR_HEIGHT' => $avatar['height'], + 'ONLINE_IMG' => (!$config['load_onlinetrack']) ? '' : (($online) ? $user->img('icon_user_online', 'ONLINE') : $user->img('icon_user_offline', 'OFFLINE')), 'S_ONLINE' => ($config['load_onlinetrack'] && $online) ? true : false, 'RANK_IMG' => $user_rank_data['img'], diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php index 47dc97cc8b..4690790dab 100644 --- a/phpBB/includes/mcp/mcp_notes.php +++ b/phpBB/includes/mcp/mcp_notes.php @@ -192,7 +192,11 @@ class mcp_notes // Generate the appropriate user information for the user we are looking at $rank_data = phpbb_get_user_rank($userrow, $userrow['user_posts']); - $avatar_img = phpbb_get_user_avatar($userrow); + + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($userrow); $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']); $sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_IP'], 'd' => $user->lang['SORT_ACTION']); @@ -252,10 +256,15 @@ class mcp_notes 'USERNAME' => get_username_string('username', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), 'U_PROFILE' => get_username_string('profile', $userrow['user_id'], $userrow['username'], $userrow['user_colour']), - 'AVATAR_IMG' => $avatar_img, + 'AVATAR_IMG' => $avatar['html'], + 'AVATAR_LAZY' => $avatar['lazy'], + 'AVATAR_SOURCE' => $avatar['src'], + 'AVATAR_TITLE' => $avatar['title'], + 'AVATAR_TYPE' => $avatar['type'], + 'AVATAR_WIDTH' => $avatar['width'], + 'AVATAR_HEIGHT' => $avatar['height'], 'RANK_IMG' => $rank_data['img'], 'RANK_TITLE' => $rank_data['title'], )); } - } diff --git a/phpBB/includes/mcp/mcp_warn.php b/phpBB/includes/mcp/mcp_warn.php index 74d6346ffd..1e146bb004 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -190,7 +190,7 @@ class mcp_warn function mcp_warn_post_view($action) { global $phpEx, $phpbb_root_path, $config, $request; - global $template, $db, $user, $phpbb_dispatcher; + global $template, $db, $user, $phpbb_dispatcher, $phpbb_container; $post_id = $request->variable('p', 0); $forum_id = $request->variable('f', 0); @@ -342,7 +342,11 @@ class mcp_warn } $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']); - $avatar_img = phpbb_get_user_avatar($user_row); + + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($user_row); $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, @@ -355,7 +359,13 @@ class mcp_warn 'POSTS' => ($user_row['user_posts']) ? $user_row['user_posts'] : 0, 'WARNINGS' => ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0, - 'AVATAR_IMG' => $avatar_img, + 'AVATAR_IMG' => $avatar['html'], + 'AVATAR_LAZY' => $avatar['lazy'], + 'AVATAR_SOURCE' => $avatar['src'], + 'AVATAR_TITLE' => $avatar['title'], + 'AVATAR_TYPE' => $avatar['type'], + 'AVATAR_WIDTH' => $avatar['width'], + 'AVATAR_HEIGHT' => $avatar['height'], 'RANK_IMG' => $user_rank_data['img'], 'L_WARNING_POST_DEFAULT' => sprintf($user->lang['WARNING_POST_DEFAULT'], generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&p=$post_id#p$post_id"), @@ -370,7 +380,7 @@ class mcp_warn function mcp_warn_user_view($action) { global $phpEx, $phpbb_root_path, $config, $request; - global $template, $db, $user, $phpbb_dispatcher; + global $template, $db, $user, $phpbb_dispatcher, $phpbb_container; $user_id = $request->variable('u', 0); $username = $request->variable('username', '', true); @@ -491,7 +501,11 @@ class mcp_warn include($phpbb_root_path . 'includes/functions_display.' . $phpEx); } $user_rank_data = phpbb_get_user_rank($user_row, $user_row['user_posts']); - $avatar_img = phpbb_get_user_avatar($user_row); + + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($user_row); // OK, they didn't submit a warning so lets build the page for them to do so $template->assign_vars(array( @@ -507,7 +521,13 @@ class mcp_warn 'USERNAME' => get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour']), 'U_PROFILE' => get_username_string('profile', $user_row['user_id'], $user_row['username'], $user_row['user_colour']), - 'AVATAR_IMG' => $avatar_img, + 'AVATAR_IMG' => $avatar['html'], + 'AVATAR_LAZY' => $avatar['lazy'], + 'AVATAR_SOURCE' => $avatar['src'], + 'AVATAR_TITLE' => $avatar['title'], + 'AVATAR_TYPE' => $avatar['type'], + 'AVATAR_WIDTH' => $avatar['width'], + 'AVATAR_HEIGHT' => $avatar['height'], 'RANK_IMG' => $user_rank_data['img'], 'S_CAN_NOTIFY' => $s_can_notify, diff --git a/phpBB/includes/ucp/ucp_groups.php b/phpBB/includes/ucp/ucp_groups.php index 79842a08b4..92c9ee6078 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -431,7 +431,7 @@ class ucp_groups $group_name = $group_row['group_name']; $group_type = $group_row['group_type']; - $avatar = phpbb_get_group_avatar($group_row, 'GROUP_AVATAR', true); + $group_avatar = $group_helper->get_avatar($group_row, 'GROUP_AVATAR', true); $template->assign_vars(array( 'GROUP_NAME' => $group_helper->get_name($group_name), @@ -440,10 +440,14 @@ class ucp_groups 'GROUP_DESC_DISP' => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']), 'GROUP_TYPE' => $group_row['group_type'], - 'AVATAR' => !empty($avatar) ? $avatar : '', - 'AVATAR_IMAGE' => !empty($avatar) ? $avatar : '', - 'AVATAR_WIDTH' => isset($group_row['group_avatar_width']) ? $group_row['group_avatar_width'] : '', - 'AVATAR_HEIGHT' => isset($group_row['group_avatar_height']) ? $group_row['group_avatar_height'] : '', + 'AVATAR' => empty($group_avatar['html']) ? '' : $group_avatar['html'], + 'AVATAR_IMAGE' => empty($group_avatar['html']) ? '' : $group_avatar['html'], + 'AVATAR_LAZY' => $group_avatar['lazy'], + 'AVATAR_SRC' => $group_avatar['src'], + 'AVATAR_TITLE' => $group_avatar['title'], + 'AVATAR_TYPE' => $group_avatar['type'], + 'AVATAR_WIDTH' => $group_avatar['width'], + 'AVATAR_HEIGHT' => $group_avatar['height'], )); } diff --git a/phpBB/includes/ucp/ucp_pm_viewmessage.php b/phpBB/includes/ucp/ucp_pm_viewmessage.php index 6657aa4fd2..d1c5b16b4c 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -221,7 +221,13 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'RANK_TITLE' => $user_info['rank_title'], 'RANK_IMG' => $user_info['rank_image'], - 'AUTHOR_AVATAR' => (isset($user_info['avatar'])) ? $user_info['avatar'] : '', + 'AUTHOR_AVATAR' => !empty($user_info['avatar']) ? $user_info['avatar']['html'] : '', + 'AUTHOR_AVATAR_LAZY' => !empty($user_info['avatar']) ? $user_info['avatar']['lazy'] : false, + 'AUTHOR_AVATAR_SOURCE' => !empty($user_info['avatar']) ? $user_info['avatar']['src'] : '', + 'AUTHOR_AVATAR_TITLE' => !empty($user_info['avatar']) ? $user_info['avatar']['title'] : '', + 'AUTHOR_AVATAR_TYPE' => !empty($user_info['avatar']) ? $user_info['avatar']['type'] : '', + 'AUTHOR_AVATAR_WIDTH' => !empty($user_info['avatar']) ? $user_info['avatar']['width'] : 0, + 'AUTHOR_AVATAR_HEIGHT' => !empty($user_info['avatar']) ? $user_info['avatar']['height'] : 0, 'AUTHOR_JOINED' => $user->format_date($user_info['user_regdate']), 'AUTHOR_POSTS' => (int) $user_info['user_posts'], 'U_AUTHOR_POSTS' => ($config['load_search'] && $auth->acl_get('u_search')) ? append_sid("{$phpbb_root_path}search.$phpEx", "author_id=$author_id&sr=posts") : '', @@ -409,7 +415,7 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) */ function get_user_information($user_id, $user_row) { - global $db, $auth, $user; + global $db, $auth, $user, $phpbb_container; global $phpbb_root_path, $phpEx, $config; if (!$user_id) @@ -449,7 +455,10 @@ function get_user_information($user_id, $user_row) } } - $user_row['avatar'] = ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($user_row) : ''; + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $user_row['avatar'] = ($user->optionget('viewavatars')) ? $avatar_helper->get_user_avatar($user_row) : []; if (!function_exists('phpbb_get_user_rank')) { diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 229f3fc06a..2394cc5667 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -757,11 +757,20 @@ class ucp_profile $error = $phpbb_avatar_manager->localize_errors($user, $error); } - $avatar = phpbb_get_user_avatar($user->data, 'USER_AVATAR', true); + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($user->data, 'USER_AVATAR', true); $template->assign_vars(array( - 'ERROR' => (count($error)) ? implode('
', $error) : '', - 'AVATAR' => $avatar, + 'ERROR' => (count($error)) ? implode('
', $error) : '', + 'AVATAR' => $avatar['html'], + 'AVATAR_LAZY' => $avatar['lazy'], + 'AVATAR_SOURCE' => $avatar['src'], + 'AVATAR_TITLE' => $avatar['title'], + 'AVATAR_TYPE' => $avatar['type'], + 'AVATAR_WIDTH' => $avatar['width'], + 'AVATAR_HEIGHT' => $avatar['height'], 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index fb4f82f38c..b5122b93ab 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1290,7 +1290,7 @@ switch ($mode) break; } - $avatar_img = phpbb_get_group_avatar($group_row); + $avatar = $group_helper->get_avatar($group_row); // ... same for group rank $group_rank_data = array( @@ -1338,7 +1338,14 @@ switch ($mode) 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']], 'GROUP_RANK' => $group_rank_data['title'], - 'AVATAR_IMG' => $avatar_img, + 'AVATAR_IMG' => $avatar['html'], + 'AVATAR_LAZY' => $avatar['lazy'], + 'AVATAR_SRC' => $avatar['src'], + 'AVATAR_TITLE' => $avatar['title'], + 'AVATAR_TYPE' => $avatar['type'], + 'AVATAR_WIDTH' => $avatar['width'], + 'AVATAR_HEIGHT' => $avatar['height'], + 'RANK_IMG' => $group_rank_data['img'], 'RANK_IMG_SRC' => $group_rank_data['img_src'], diff --git a/phpBB/phpbb/group/helper.php b/phpBB/phpbb/group/helper.php index 639315c960..92dd71384f 100644 --- a/phpBB/phpbb/group/helper.php +++ b/phpBB/phpbb/group/helper.php @@ -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); } } diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index b5238a0e9a..e59c5b9638 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -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 []; } /** diff --git a/phpBB/phpbb/user_loader.php b/phpBB/phpbb/user_loader.php index 3dacf07ff5..4a682ffbad 100644 --- a/phpBB/phpbb/user_loader.php +++ b/phpBB/phpbb/user_loader.php @@ -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); } /** diff --git a/phpBB/viewtopic.php b/phpBB/viewtopic.php index 3d9de55a84..7bfa29d70d 100644 --- a/phpBB/viewtopic.php +++ b/phpBB/viewtopic.php @@ -1179,6 +1179,9 @@ if (!empty($topic_data['poll_start'])) unset($poll_end, $poll_info, $poll_options_template_data, $poll_template_data, $voted_id); } +/** @var \phpbb\avatar\helper $avatar_helper */ +$avatar_helper = $phpbb_container->get('avatar.helper'); + // If the user is trying to reach the second half of the topic, fetch it starting from the end $store_reverse = false; $sql_limit = $config['posts_per_page']; @@ -1417,7 +1420,7 @@ while ($row = $db->sql_fetchrow($result)) 'sig_bbcode_bitfield' => '', 'online' => false, - 'avatar' => ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($row) : '', + 'avatar' => ($user->optionget('viewavatars')) ? $avatar_helper->get_user_avatar($row) : [], 'rank_title' => '', 'rank_image' => '', 'rank_image_src' => '', @@ -1481,7 +1484,7 @@ while ($row = $db->sql_fetchrow($result)) 'viewonline' => $row['user_allow_viewonline'], 'allow_pm' => $row['user_allow_pm'], - 'avatar' => ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($row) : '', + 'avatar' => ($user->optionget('viewavatars')) ? $this->get_user_avatar($row) : [], 'age' => '', 'rank_title' => '', @@ -2026,7 +2029,6 @@ for ($i = 0, $end = count($post_list); $i < $end; ++$i) $u_pm = append_sid("{$phpbb_root_path}ucp.$phpEx", 'i=pm&mode=compose&action=quotepost&p=' . $row['post_id']); } - // $post_row = array( 'POST_AUTHOR_FULL' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_full'] : get_username_string('full', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), 'POST_AUTHOR_COLOUR' => ($poster_id != ANONYMOUS) ? $user_cache[$poster_id]['author_colour'] : get_username_string('colour', $poster_id, $row['username'], $row['user_colour'], $row['post_username']), @@ -2038,7 +2040,13 @@ for ($i = 0, $end = count($post_list); $i < $end; ++$i) 'RANK_IMG_SRC' => $user_cache[$poster_id]['rank_image_src'], 'POSTER_JOINED' => $user_cache[$poster_id]['joined'], 'POSTER_POSTS' => $user_cache[$poster_id]['posts'], - 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'], + 'POSTER_AVATAR' => $user_cache[$poster_id]['avatar'] ? $user_cache[$poster_id]['avatar']['html'] : '', + 'POSTER_AVATAR_LAZY' => $user_cache[$poster_id]['avatar'] ? $user_cache[$poster_id]['avatar']['lazy'] : false, + 'POSTER_AVATAR_SOURCE' => $user_cache[$poster_id]['avatar'] ? $user_cache[$poster_id]['avatar']['src'] : '', + 'POSTER_AVATAR_TITLE' => $user_cache[$poster_id]['avatar'] ? $user_cache[$poster_id]['avatar']['title'] : '', + 'POSTER_AVATAR_TYPE' => $user_cache[$poster_id]['avatar'] ? $user_cache[$poster_id]['avatar']['type'] : '', + 'POSTER_AVATAR_WIDTH' => $user_cache[$poster_id]['avatar'] ? $user_cache[$poster_id]['avatar']['width'] : 0, + 'POSTER_AVATAR_HEIGHT' => $user_cache[$poster_id]['avatar'] ? $user_cache[$poster_id]['avatar']['height'] : 0, 'POSTER_WARNINGS' => $auth->acl_get('m_warn') ? $user_cache[$poster_id]['warnings'] : '', 'POSTER_AGE' => $user_cache[$poster_id]['age'], 'CONTACT_USER' => $user_cache[$poster_id]['contact_user'],