Skip to content

Commit ddbdde5

Browse files
committed
[ticket/9758] Adds global template variable CURRENT_USER_AVATAR
PHPBB3-9758
1 parent 0be6582 commit ddbdde5

11 files changed

Lines changed: 111 additions & 94 deletions

File tree

phpBB/includes/functions.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4619,6 +4619,92 @@ function phpbb_build_hidden_fields_for_query_params($request, $exclude = null)
46194619
return $hidden;
46204620
}
46214621

4622+
/**
4623+
* Get user avatar
4624+
*
4625+
* @param array $user_row Row from the users table
4626+
* @param string $alt Optional language string for alt tag within image, can be a language key or text
4627+
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
4628+
*
4629+
* @return string Avatar html
4630+
*/
4631+
function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false)
4632+
{
4633+
$row = \phpbb\avatar\manager::clean_row($user_row, 'user');
4634+
return phpbb_get_avatar($row, $alt, $ignore_config);
4635+
}
4636+
4637+
/**
4638+
* Get group avatar
4639+
*
4640+
* @param array $group_row Row from the groups table
4641+
* @param string $alt Optional language string for alt tag within image, can be a language key or text
4642+
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
4643+
*
4644+
* @return string Avatar html
4645+
*/
4646+
function phpbb_get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false)
4647+
{
4648+
$row = \phpbb\avatar\manager::clean_row($user_row, 'group');
4649+
return phpbb_get_avatar($row, $alt, $ignore_config);
4650+
}
4651+
4652+
/**
4653+
* Get avatar
4654+
*
4655+
* @param array $row Row cleaned by \phpbb\avatar\driver\driver::clean_row
4656+
* @param string $alt Optional language string for alt tag within image, can be a language key or text
4657+
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
4658+
*
4659+
* @return string Avatar html
4660+
*/
4661+
function phpbb_get_avatar($row, $alt, $ignore_config = false)
4662+
{
4663+
global $user, $config, $cache, $phpbb_root_path, $phpEx;
4664+
global $request;
4665+
global $phpbb_container;
4666+
4667+
if (!$config['allow_avatar'] && !$ignore_config)
4668+
{
4669+
return '';
4670+
}
4671+
4672+
$avatar_data = array(
4673+
'src' => $row['avatar'],
4674+
'width' => $row['avatar_width'],
4675+
'height' => $row['avatar_height'],
4676+
);
4677+
4678+
$phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
4679+
$driver = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config);
4680+
$html = '';
4681+
4682+
if ($driver)
4683+
{
4684+
$html = $driver->get_custom_html($user, $row, $alt);
4685+
if (!empty($html))
4686+
{
4687+
return $html;
4688+
}
4689+
4690+
$avatar_data = $driver->get_data($row, $ignore_config);
4691+
}
4692+
else
4693+
{
4694+
$avatar_data['src'] = '';
4695+
}
4696+
4697+
if (!empty($avatar_data['src']))
4698+
{
4699+
$html = '<img src="' . $avatar_data['src'] . '" ' .
4700+
($avatar_data['width'] ? ('width="' . $avatar_data['width'] . '" ') : '') .
4701+
($avatar_data['height'] ? ('height="' . $avatar_data['height'] . '" ') : '') .
4702+
'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
4703+
}
4704+
4705+
return $html;
4706+
}
4707+
46224708
/**
46234709
* Generate page header
46244710
*/
@@ -4830,6 +4916,7 @@ function page_header($page_title = '', $display_online_list = false, $item_id =
48304916

48314917
// The following assigns all _common_ variables that may be used at any point in a template.
48324918
$template->assign_vars(array(
4919+
'CURRENT_USER_AVATAR' => phpbb_get_user_avatar($user->data),
48334920
'SITENAME' => $config['sitename'],
48344921
'SITE_DESCRIPTION' => $config['site_desc'],
48354922
'PAGE_TITLE' => $page_title,

phpBB/includes/functions_compatibility.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function get_user_avatar($avatar, $avatar_type, $avatar_width, $avatar_height, $
4343
{
4444
global $phpbb_root_path, $phpEx;
4545

46-
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
46+
include($phpbb_root_path . 'includes/functions.' . $phpEx);
4747
}
4848

4949
return phpbb_get_avatar($row, $alt, $ignore_config);

phpBB/includes/functions_display.php

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,92 +1376,6 @@ function get_user_rank($user_rank, $user_posts, &$rank_title, &$rank_img, &$rank
13761376
}
13771377
}
13781378

1379-
/**
1380-
* Get user avatar
1381-
*
1382-
* @param array $user_row Row from the users table
1383-
* @param string $alt Optional language string for alt tag within image, can be a language key or text
1384-
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
1385-
*
1386-
* @return string Avatar html
1387-
*/
1388-
function phpbb_get_user_avatar($user_row, $alt = 'USER_AVATAR', $ignore_config = false)
1389-
{
1390-
$row = \phpbb\avatar\manager::clean_row($user_row, 'user');
1391-
return phpbb_get_avatar($row, $alt, $ignore_config);
1392-
}
1393-
1394-
/**
1395-
* Get group avatar
1396-
*
1397-
* @param array $group_row Row from the groups table
1398-
* @param string $alt Optional language string for alt tag within image, can be a language key or text
1399-
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
1400-
*
1401-
* @return string Avatar html
1402-
*/
1403-
function phpbb_get_group_avatar($user_row, $alt = 'GROUP_AVATAR', $ignore_config = false)
1404-
{
1405-
$row = \phpbb\avatar\manager::clean_row($user_row, 'group');
1406-
return phpbb_get_avatar($row, $alt, $ignore_config);
1407-
}
1408-
1409-
/**
1410-
* Get avatar
1411-
*
1412-
* @param array $row Row cleaned by \phpbb\avatar\driver\driver::clean_row
1413-
* @param string $alt Optional language string for alt tag within image, can be a language key or text
1414-
* @param bool $ignore_config Ignores the config-setting, to be still able to view the avatar in the UCP
1415-
*
1416-
* @return string Avatar html
1417-
*/
1418-
function phpbb_get_avatar($row, $alt, $ignore_config = false)
1419-
{
1420-
global $user, $config, $cache, $phpbb_root_path, $phpEx;
1421-
global $request;
1422-
global $phpbb_container;
1423-
1424-
if (!$config['allow_avatar'] && !$ignore_config)
1425-
{
1426-
return '';
1427-
}
1428-
1429-
$avatar_data = array(
1430-
'src' => $row['avatar'],
1431-
'width' => $row['avatar_width'],
1432-
'height' => $row['avatar_height'],
1433-
);
1434-
1435-
$phpbb_avatar_manager = $phpbb_container->get('avatar.manager');
1436-
$driver = $phpbb_avatar_manager->get_driver($row['avatar_type'], $ignore_config);
1437-
$html = '';
1438-
1439-
if ($driver)
1440-
{
1441-
$html = $driver->get_custom_html($user, $row, $alt);
1442-
if (!empty($html))
1443-
{
1444-
return $html;
1445-
}
1446-
1447-
$avatar_data = $driver->get_data($row, $ignore_config);
1448-
}
1449-
else
1450-
{
1451-
$avatar_data['src'] = '';
1452-
}
1453-
1454-
if (!empty($avatar_data['src']))
1455-
{
1456-
$html = '<img src="' . $avatar_data['src'] . '" ' .
1457-
($avatar_data['width'] ? ('width="' . $avatar_data['width'] . '" ') : '') .
1458-
($avatar_data['height'] ? ('height="' . $avatar_data['height'] . '" ') : '') .
1459-
'alt="' . ((!empty($user->lang[$alt])) ? $user->lang[$alt] : $alt) . '" />';
1460-
}
1461-
1462-
return $html;
1463-
}
1464-
14651379
/**
14661380
* Generate a list of archive types available for compressing attachments
14671381
*

phpBB/includes/mcp/mcp_notes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function mcp_notes_user_view($action)
176176
// Generate the appropriate user information for the user we are looking at
177177
if (!function_exists('phpbb_get_user_avatar'))
178178
{
179-
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
179+
include($phpbb_root_path . 'includes/functions.' . $phpEx);
180180
}
181181

182182
$rank_title = $rank_img = '';

phpBB/includes/mcp/mcp_warn.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ function mcp_warn_post_view($action)
295295
// Generate the appropriate user information for the user we are looking at
296296
if (!function_exists('phpbb_get_user_avatar'))
297297
{
298-
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
298+
include($phpbb_root_path . 'includes/functions.' . $phpEx);
299299
}
300300

301301
get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src);
@@ -400,7 +400,7 @@ function mcp_warn_user_view($action)
400400
// Generate the appropriate user information for the user we are looking at
401401
if (!function_exists('phpbb_get_user_avatar'))
402402
{
403-
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
403+
include($phpbb_root_path . 'includes/functions.' . $phpEx);
404404
}
405405

406406
get_user_rank($user_row['user_rank'], $user_row['user_posts'], $rank_title, $rank_img, $rank_img_src);

phpBB/includes/ucp/ucp_pm_viewmessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ function get_user_information($user_id, $user_row)
340340

341341
if (!function_exists('phpbb_get_user_avatar'))
342342
{
343-
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
343+
include($phpbb_root_path . 'includes/functions.' . $phpEx);
344344
}
345345

346346
$user_row['avatar'] = ($user->optionget('viewavatars')) ? phpbb_get_user_avatar($user_row) : '';

phpBB/includes/ucp/ucp_profile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ function main($id, $mode)
517517
case 'avatar':
518518
if (!function_exists('phpbb_get_user_avatar'))
519519
{
520-
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
520+
include($phpbb_root_path . 'includes/functions.' . $phpEx);
521521
}
522522

523523
add_form_key('ucp_avatar');

phpBB/memberlist.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,12 @@
547547
$parse_flags = ($member['user_sig_bbcode_bitfield'] ? OPTION_FLAG_BBCODE : 0) | OPTION_FLAG_SMILIES;
548548
$member['user_sig'] = generate_text_for_display($member['user_sig'], $member['user_sig_bbcode_uid'], $member['user_sig_bbcode_bitfield'], $parse_flags, true);
549549
}
550-
550+
551+
if (!function_exists('phpbb_get_user_avatar'))
552+
{
553+
include($phpbb_root_path . 'includes/functions.' . $phpEx);
554+
}
555+
551556
$poster_avatar = phpbb_get_user_avatar($member);
552557

553558
// We need to check if the modules 'zebra' ('friends' & 'foes' mode), 'notes' ('user_notes' mode) and 'warn' ('warn_user' mode) are accessible to decide if we can display appropriate links

phpBB/styles/prosilver/template/overall_header.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ <h1>{SITENAME}</h1>
163163

164164
<!-- EVENT overall_header_navigation_append -->
165165
<!-- IF not S_IS_BOT -->
166-
<li class="small-icon icon-logout rightside no-bulletin"><a href="{U_LOGIN_LOGOUT}" title="{L_LOGIN_LOGOUT}" accesskey="x">{L_LOGIN_LOGOUT}</a></li>
166+
<li class="small-icon icon-logout rightside no-bulletin"><a href="{U_LOGIN_LOGOUT}" title="{L_LOGIN_LOGOUT}" accesskey="x">{L_LOGIN_LOGOUT}</a> <span class="avatar-index">{CURRENT_USER_AVATAR}</span></li>
167167
<!-- IF not S_USER_LOGGED_IN and S_REGISTER_ENABLED and not (S_SHOW_COPPA or S_REGISTRATION) --><li class="small-icon icon-register rightside no-bulletin"><a href="{U_REGISTER}">{L_REGISTER}</a></li><!-- ENDIF -->
168168
<!-- IF S_DISPLAY_MEMBERLIST --><li class="small-icon icon-members rightside no-bulletin"><a href="{U_MEMBERLIST}" title="{L_MEMBERLIST_EXPLAIN}">{L_MEMBERLIST}</a></li><!-- ENDIF -->
169169
<!-- ENDIF -->

phpBB/styles/prosilver/theme/common.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,13 @@ ul.linklist.bulletin li.no-bulletin:before {
444444
display: none !important;
445445
}
446446

447+
/* Avatar in overall_header.html */
448+
span.avatar-index img {
449+
max-height: 25px;
450+
vertical-align: top;
451+
width: auto;
452+
}
453+
447454
/* Dropdown menu
448455
----------------------------------------*/
449456
.dropdown-container {

0 commit comments

Comments
 (0)