diff --git a/phpBB/adm/style/acp_groups.html b/phpBB/adm/style/acp_groups.html index 8651b63b7f..8d53ae459c 100644 --- a/phpBB/adm/style/acp_groups.html +++ b/phpBB/adm/style/acp_groups.html @@ -113,7 +113,7 @@ {L_GROUP_AVATAR}

{L_AVATAR_EXPLAIN}
-
{AVATAR}
+
{% if AVATAR_HTML %}{{ AVATAR_HTML }}{% else %}{% endif %}
diff --git a/phpBB/adm/style/acp_users_avatar.html b/phpBB/adm/style/acp_users_avatar.html index 8466985fb3..5e3fb04bee 100644 --- a/phpBB/adm/style/acp_users_avatar.html +++ b/phpBB/adm/style/acp_users_avatar.html @@ -5,7 +5,7 @@

{ERROR}


{L_AVATAR_EXPLAIN}
-
{AVATAR}
+
{% if AVATAR_HTML %}{{ AVATAR_HTML }}{% else %}{% endif %}
diff --git a/phpBB/includes/acp/acp_groups.php b/phpBB/includes/acp/acp_groups.php index 8cb8e778b7..b24014cb39 100644 --- a/phpBB/includes/acp/acp_groups.php +++ b/phpBB/includes/acp/acp_groups.php @@ -721,8 +721,6 @@ class acp_groups } } - $group_avatar = $group_helper->get_avatar($group_row, 'GROUP_AVATAR', true); - if (isset($phpbb_avatar_manager) && !$update) { // Merge any avatar errors into the primary error array @@ -742,6 +740,12 @@ class acp_groups break; } + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $group_avatar = $avatar_helper->get_group_avatar($group_row, 'GROUP_AVATAR', true); + $template->assign_vars($avatar_helper->get_template_vars($group_avatar)); + $template->assign_vars(array( 'S_EDIT' => true, 'S_ADD_GROUP' => ($action == 'add') ? true : false, @@ -771,13 +775,6 @@ 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($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'], 'GROUP_TYPE_FREE' => GROUP_FREE, diff --git a/phpBB/includes/acp/acp_users.php b/phpBB/includes/acp/acp_users.php index e3045ffe19..4a041886b7 100644 --- a/phpBB/includes/acp/acp_users.php +++ b/phpBB/includes/acp/acp_users.php @@ -1972,24 +1972,17 @@ class acp_users $avatar_helper = $phpbb_container->get('avatar.helper'); $avatar = $avatar_helper->get_user_avatar($user_row, 'USER_AVATAR', true); + $template->assign_vars($avatar_helper->get_template_vars($avatar)); $template->assign_vars(array( - 'S_AVATAR' => true, - 'ERROR' => (!empty($error)) ? implode('
', $error) : '', - - '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_AVATAR' => true, + 'ERROR' => !empty($error) ? implode('
', $error) : '', 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', 'L_AVATAR_EXPLAIN' => $user->lang(($config['avatar_filesize'] == 0) ? 'AVATAR_EXPLAIN_NO_FILESIZE' : 'AVATAR_EXPLAIN', $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024), - 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), + 'S_AVATARS_ENABLED' => ($config['allow_avatar'] && $avatars_enabled), )); break; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index f8122c4272..0f3ec942be 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -3872,6 +3872,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id = $avatar_helper = $phpbb_container->get('avatar.helper'); $avatar = $avatar_helper->get_user_avatar($user->data); + $template->assign_vars($avatar_helper->get_template_vars($avatar, 'CURRENT_USER_')); // The following assigns all _common_ variables that may be used at any point in a template. $template->assign_vars(array( @@ -3886,14 +3887,8 @@ function page_header($page_title = '', $display_online_list = false, $item_id = 'LOGGED_IN_USER_LIST' => $online_userlist, 'RECORD_USERS' => $l_online_record, + 'NO_AVATAR_SOURCE' => $avatar_helper->get_no_avatar_source(), 'PRIVATE_MESSAGE_COUNT' => (!empty($user->data['user_unread_privmsg'])) ? $user->data['user_unread_privmsg'] : 0, - '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 b4ab8a9c7a..cec42ddfd9 100644 --- a/phpBB/includes/functions_display.php +++ b/phpBB/includes/functions_display.php @@ -1657,9 +1657,10 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl $avatar_helper = $phpbb_container->get('avatar.helper'); $avatar = $avatar_helper->get_user_avatar($data); + $avatar_vars = $avatar_helper->get_template_vars($avatar); // Dump it out to the template - $template_data = array( + $template_data = array_merge($avatar_vars, [ 'AGE' => $age, 'RANK_TITLE' => $user_rank_data['title'], 'JOINED' => $user->format_date($data['user_regdate']), @@ -1674,14 +1675,6 @@ 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' => $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'], @@ -1703,7 +1696,7 @@ function phpbb_show_profile($data, $user_notes_enabled = false, $warn_user_enabl 'L_SEND_EMAIL_USER' => $user->lang('SEND_EMAIL_USER', $username), 'L_CONTACT_USER' => $user->lang('CONTACT_USER', $username), 'L_VIEWING_PROFILE' => $user->lang('VIEWING_PROFILE', $username), - ); + ]); /** * Preparing a user's data before displaying it in profile and memberlist diff --git a/phpBB/includes/mcp/mcp_notes.php b/phpBB/includes/mcp/mcp_notes.php index 4690790dab..5ba6999d2c 100644 --- a/phpBB/includes/mcp/mcp_notes.php +++ b/phpBB/includes/mcp/mcp_notes.php @@ -185,19 +185,6 @@ class mcp_notes trigger_error($msg . '

' . sprintf($user->lang['RETURN_PAGE'], '', '')); } - if (!function_exists('phpbb_get_user_rank')) - { - include($phpbb_root_path . 'includes/functions_display.' . $phpEx); - } - - // Generate the appropriate user information for the user we are looking at - $rank_data = phpbb_get_user_rank($userrow, $userrow['user_posts']); - - /** @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']); $sort_by_sql = array('a' => 'u.username_clean', 'b' => 'l.log_time', 'c' => 'l.log_ip', 'd' => 'l.log_operation'); @@ -235,6 +222,20 @@ class mcp_notes $base_url = $this->u_action . "&$u_sort_param$keywords_param"; $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start); + if (!function_exists('phpbb_get_user_rank')) + { + include($phpbb_root_path . 'includes/functions_display.' . $phpEx); + } + + // Generate the appropriate user information for the user we are looking at + $rank_data = phpbb_get_user_rank($userrow, $userrow['user_posts']); + + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar = $avatar_helper->get_user_avatar($userrow); + $template->assign_vars($avatar_helper->get_template_vars($avatar)); + $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, 'S_CLEAR_ALLOWED' => ($auth->acl_get('a_clearlogs')) ? true : false, @@ -256,13 +257,6 @@ 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['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 1e146bb004..f22e3f2c5e 100644 --- a/phpBB/includes/mcp/mcp_warn.php +++ b/phpBB/includes/mcp/mcp_warn.php @@ -347,6 +347,7 @@ class mcp_warn $avatar_helper = $phpbb_container->get('avatar.helper'); $avatar = $avatar_helper->get_user_avatar($user_row); + $template->assign_vars($avatar_helper->get_template_vars($avatar)); $template->assign_vars(array( 'U_POST_ACTION' => $this->u_action, @@ -359,13 +360,6 @@ 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['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"), @@ -506,6 +500,7 @@ class mcp_warn $avatar_helper = $phpbb_container->get('avatar.helper'); $avatar = $avatar_helper->get_user_avatar($user_row); + $template->assign_vars($avatar_helper->get_template_vars($avatar)); // OK, they didn't submit a warning so lets build the page for them to do so $template->assign_vars(array( @@ -521,13 +516,6 @@ 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['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 92c9ee6078..dd14f9072a 100644 --- a/phpBB/includes/ucp/ucp_groups.php +++ b/phpBB/includes/ucp/ucp_groups.php @@ -431,7 +431,11 @@ class ucp_groups $group_name = $group_row['group_name']; $group_type = $group_row['group_type']; - $group_avatar = $group_helper->get_avatar($group_row, 'GROUP_AVATAR', true); + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $group_avatar = $avatar_helper->get_group_avatar($group_row, 'GROUP_AVATAR', true); + $template->assign_vars($avatar_helper->get_template_vars($group_avatar)); $template->assign_vars(array( 'GROUP_NAME' => $group_helper->get_name($group_name), @@ -439,15 +443,6 @@ class ucp_groups 'GROUP_COLOUR' => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '', '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($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 d1c5b16b4c..b2f0bc5344 100644 --- a/phpBB/includes/ucp/ucp_pm_viewmessage.php +++ b/phpBB/includes/ucp/ucp_pm_viewmessage.php @@ -221,13 +221,6 @@ 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' => !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") : '', @@ -279,6 +272,15 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row) 'U_FORWARD_PM' => ($config['forward_pm'] && $auth->acl_get('u_sendpm') && $auth->acl_get('u_pm_forward')) ? "$url&mode=compose&action=forward&f=$folder_id&p=" . $message_row['msg_id'] : '', ); + if (!empty($user_info['avatar'])) + { + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $avatar_data = $avatar_helper->get_template_vars($user_info['avatar'], 'AUTHOR_'); + $msg_data = array_merge($msg_data, $avatar_data); + } + /** * Modify pm and sender data before it is assigned to the template * diff --git a/phpBB/includes/ucp/ucp_profile.php b/phpBB/includes/ucp/ucp_profile.php index 2394cc5667..51ab5eddac 100644 --- a/phpBB/includes/ucp/ucp_profile.php +++ b/phpBB/includes/ucp/ucp_profile.php @@ -761,16 +761,10 @@ class ucp_profile $avatar_helper = $phpbb_container->get('avatar.helper'); $avatar = $avatar_helper->get_user_avatar($user->data, 'USER_AVATAR', true); + $template->assign_vars($avatar_helper->get_template_vars($avatar)); $template->assign_vars(array( - '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'], + 'ERROR' => !empty($error) ? implode('
', $error) : '', 'S_FORM_ENCTYPE' => ' enctype="multipart/form-data"', diff --git a/phpBB/memberlist.php b/phpBB/memberlist.php index b5122b93ab..3140ba22b3 100644 --- a/phpBB/memberlist.php +++ b/phpBB/memberlist.php @@ -1290,8 +1290,6 @@ switch ($mode) break; } - $avatar = $group_helper->get_avatar($group_row); - // ... same for group rank $group_rank_data = array( 'title' => null, @@ -1331,6 +1329,12 @@ switch ($mode) 'U_BREADCRUMB' => append_sid("{$phpbb_root_path}memberlist.$phpEx", "mode=group&g=$group_id"), )); + /** @var \phpbb\avatar\helper $avatar_helper */ + $avatar_helper = $phpbb_container->get('avatar.helper'); + + $group_avatar = $avatar_helper->get_group_avatar($group_row); + $template->assign_vars($avatar_helper->get_template_vars($group_avatar)); + $template->assign_vars(array( 'GROUP_DESC' => generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']), 'GROUP_NAME' => $group_helper->get_name($group_row['group_name']), @@ -1338,14 +1342,6 @@ switch ($mode) 'GROUP_TYPE' => $user->lang['GROUP_IS_' . $group_row['l_group_type']], 'GROUP_RANK' => $group_rank_data['title'], - '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/avatar/helper.php b/phpBB/phpbb/avatar/helper.php index 2780fe3c57..a0f9b6e99a 100644 --- a/phpBB/phpbb/avatar/helper.php +++ b/phpBB/phpbb/avatar/helper.php @@ -13,43 +13,55 @@ namespace phpbb\avatar; +use phpbb\avatar\driver\driver_interface; +use phpbb\config\config; +use phpbb\event\dispatcher; +use phpbb\language\language; +use phpbb\path_helper; +use phpbb\user; + +/** + * Avatar helper object. + * + * Generates avatars and their variables for display. + */ class helper { - /** @var \phpbb\config\config */ + /** @var config */ protected $config; - /** @var \phpbb\event\dispatcher */ + /** @var dispatcher */ protected $dispatcher; - /** @var \phpbb\language\language */ + /** @var language */ protected $language; - /** @var \phpbb\avatar\manager */ + /** @var manager */ protected $manager; - /** @var \phpbb\path_helper */ + /** @var path_helper */ protected $path_helper; - /** @var \phpbb\user */ + /** @var user */ protected $user; /** * Constructor. * - * @param \phpbb\config\config $config Config object - * @param \phpbb\event\dispatcher $dispatcher Event dispatcher object - * @param \phpbb\language\language $language Language object - * @param \phpbb\avatar\manager $manager Avatar manager object - * @param \phpbb\path_helper $path_helper Path helper object - * @param \phpbb\user $user User object + * @param config $config Config object + * @param dispatcher $dispatcher Event dispatcher object + * @param language $language Language object + * @param manager $manager Avatar manager object + * @param path_helper $path_helper Path helper object + * @param user $user User object */ public function __construct( - \phpbb\config\config $config, - \phpbb\event\dispatcher $dispatcher, - \phpbb\language\language $language, + config $config, + dispatcher $dispatcher, + language $language, manager $manager, - \phpbb\path_helper $path_helper, - \phpbb\user $user + path_helper $path_helper, + user $user ) { $this->config = $config; @@ -60,6 +72,32 @@ class helper $this->user = $user; } + /** + * Get an avatar's template variables. + * + * @param array $avatar The avatar's data + * @param string $prefix The variables' prefix + * @return array The avatar's template variables + */ + public function get_template_vars(array $avatar, string $prefix = ''): array + { + $prefix = $prefix && substr($prefix, -1) !== '_' ? "{$prefix}_" : $prefix; + + return [ + "{$prefix}AVATAR" => $avatar, + + "{$prefix}AVATAR_SOURCE" => $avatar['src'], + "{$prefix}AVATAR_TITLE" => $avatar['title'], + "{$prefix}AVATAR_TYPE" => $avatar['type'], + + "{$prefix}AVATAR_WIDTH" => $avatar['width'], + "{$prefix}AVATAR_HEIGHT" => $avatar['height'], + + "{$prefix}AVATAR_LAZY" => $avatar['lazy'], + "{$prefix}AVATAR_HTML" => $avatar['html'], + ]; + } + /** * Get user avatar data. * @@ -69,9 +107,9 @@ class helper * @param bool $lazy Indicator whether the avatar should be lazy loaded (requires JS) or not * @return array The avatar data array */ - public function get_user_avatar(array $row, $title = 'USER_AVATAR', $ignore_config = false, $lazy = false) + public function get_user_avatar(array $row, string $title = 'USER_AVATAR', bool $ignore_config = false, bool $lazy = false): array { - $row = $this->manager->clean_row($row, 'user'); + $row = manager::clean_row($row, 'user'); return $this->get_avatar($row, $title, $ignore_config, $lazy); } @@ -85,9 +123,9 @@ class helper * @param bool $lazy Indicator whether the avatar should be lazy loaded (requires JS) or not * @return array The avatar data array */ - public function get_group_avatar(array $row, $title = 'GROUP_AVATAR', $ignore_config = false, $lazy = false) + public function get_group_avatar(array $row, string $title = 'GROUP_AVATAR', bool $ignore_config = false, bool $lazy = false): array { - $row = $this->manager->clean_row($row, 'group'); + $row = manager::clean_row($row, 'group'); return $this->get_avatar($row, $title, $ignore_config, $lazy); } @@ -101,7 +139,7 @@ class helper * @param bool $lazy Indicator whether the avatar should be lazy loaded (requires JS) or not * @return array The avatar data array */ - public function get_avatar(array $row, $title, $ignore_config = false, $lazy = false) + public function get_avatar(array $row, string $title, bool $ignore_config = false, bool $lazy = false): array { if (!$this->config['allow_avatar'] && !$ignore_config) { @@ -126,7 +164,7 @@ class helper 'html' => '', ]; - /** @var \phpbb\avatar\driver\driver_interface $driver */ + /** @var driver_interface $driver */ $driver = $this->manager->get_driver($row['avatar_type'], !$ignore_config); if ($driver !== null) @@ -182,6 +220,24 @@ class helper return $data; } + /** + * Get the "no avatar" source string. + * + * @return string The "no avatar" source string + */ + public function get_no_avatar_source(): string + { + /** + * We need to correct the phpBB root path in case this is called from a controller, + * because the web path will be incorrect otherwise. + */ + $board_url = defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH; + $web_path = $board_url ? generate_board_url() . '/' : $this->path_helper->get_web_root_path(); + $style_path = rawurlencode($this->user->style['style_path']); + + return "{$web_path}styles/{$style_path}/theme/images/no_avatar.gif"; + } + /** * Get an avatar's HTML element. * @@ -193,21 +249,11 @@ class helper * @param array $data The avatar data array * @return string The avatar's HTML element */ - protected function get_avatar_html(array $data) + private function get_avatar_html(array $data): string { if ($data['lazy']) { - /** - * We need to correct the phpBB root path in case this is called from a controller, - * because the web path will be incorrect otherwise. - */ - $board_url = defined('PHPBB_USE_BOARD_URL_PATH') && PHPBB_USE_BOARD_URL_PATH; - $web_path = $board_url ? generate_board_url() . '/' : $this->path_helper->get_web_root_path(); - $style_path = rawurlencode($this->user->style['style_path']); - - $theme = "{$web_path}styles/{$style_path}/theme"; - - $data['src'] = $theme . '/images/no_avatar.gif" data-src="' . $data['src']; + $data['src'] = $this->get_no_avatar_source() . ' data-src="' . $data['src']; } $src = ' src="' . $data['src'] . '"'; diff --git a/phpBB/phpbb/notification/type/base.php b/phpBB/phpbb/notification/type/base.php index e59c5b9638..5c1a6137ec 100644 --- a/phpBB/phpbb/notification/type/base.php +++ b/phpBB/phpbb/notification/type/base.php @@ -297,14 +297,16 @@ abstract class base implements \phpbb\notification\type\type_interface '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_SOURCE' => $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, + 'AVATAR_HTML' => $avatar ? $avatar['html'] : '', + 'AVATAR_LAZY' => $avatar ? $avatar['lazy'] : true, + 'U_MARK_READ' => (!$this->notification_read) ? $u_mark_read : '', ]; } diff --git a/phpBB/styles/prosilver/template/mcp_notes_user.html b/phpBB/styles/prosilver/template/mcp_notes_user.html index 448021eb8f..83c3485356 100644 --- a/phpBB/styles/prosilver/template/mcp_notes_user.html +++ b/phpBB/styles/prosilver/template/mcp_notes_user.html @@ -11,7 +11,7 @@
-
{AVATAR_IMG}
+
{AVATAR_HTML}
diff --git a/phpBB/styles/prosilver/template/mcp_warn_post.html b/phpBB/styles/prosilver/template/mcp_warn_post.html index 11395eea59..0e37e6bd9a 100644 --- a/phpBB/styles/prosilver/template/mcp_warn_post.html +++ b/phpBB/styles/prosilver/template/mcp_warn_post.html @@ -11,7 +11,7 @@
-
{AVATAR_IMG}
+
{AVATAR_HTML}
diff --git a/phpBB/styles/prosilver/template/mcp_warn_user.html b/phpBB/styles/prosilver/template/mcp_warn_user.html index 022763ba82..b1c24c18e9 100644 --- a/phpBB/styles/prosilver/template/mcp_warn_user.html +++ b/phpBB/styles/prosilver/template/mcp_warn_user.html @@ -11,7 +11,7 @@
-
{AVATAR_IMG}
+
{AVATAR_HTML}
diff --git a/phpBB/styles/prosilver/template/memberlist_body.html b/phpBB/styles/prosilver/template/memberlist_body.html index 551c168d1e..402917befe 100644 --- a/phpBB/styles/prosilver/template/memberlist_body.html +++ b/phpBB/styles/prosilver/template/memberlist_body.html @@ -26,7 +26,7 @@ {% EVENT memberlist_body_group_desc_after %}

- {AVATAR_IMG} + {AVATAR_HTML} {% EVENT memberlist_body_group_rank_before %} {% if RANK_IMG %}{{ RANK_IMG }}{% endif %} {% if GROUP_RANK %} diff --git a/phpBB/styles/prosilver/template/memberlist_view.html b/phpBB/styles/prosilver/template/memberlist_view.html index 69988e57f2..c5d2794ce4 100644 --- a/phpBB/styles/prosilver/template/memberlist_view.html +++ b/phpBB/styles/prosilver/template/memberlist_view.html @@ -8,9 +8,9 @@

- +
-
{AVATAR_IMG}
+
{AVATAR_HTML}
{RANK_TITLE}
{RANK_IMG}
@@ -29,7 +29,7 @@ [ {L_USER_BAN} ] [ {L_USE_PERMISSIONS} ] - +
{L_RANK}{L_COLON}
{RANK_TITLE}
 {L_RANK}{L_COLON}
{RANK_IMG}
diff --git a/phpBB/styles/prosilver/template/navbar_header.html b/phpBB/styles/prosilver/template/navbar_header.html index 88807f9c16..eaf61f2518 100644 --- a/phpBB/styles/prosilver/template/navbar_header.html +++ b/phpBB/styles/prosilver/template/navbar_header.html @@ -106,11 +106,11 @@ {% if S_REGISTERED_USER %} {% EVENT navbar_header_user_profile_prepend %} -
  • +
  • {% EVENT navbar_header_username_prepend %}