mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
change get_username_string() again. This time we do not try to "guess" something. We also do not cache the modes. Instead we try to only run required code and pre-compile the URL and TPL. This should give the optimal performance given the circumstances.
Additionally fix a small bug with profile urls if the RokBridge is used. git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@9217 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
6b19ba450e
commit
516734979c
1 changed files with 69 additions and 54 deletions
|
@ -1159,27 +1159,42 @@ function truncate_string($string, $max_length = 60, $max_store_length = 255, $al
|
||||||
function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false)
|
function get_username_string($mode, $user_id, $username, $username_colour = '', $guest_username = false, $custom_profile_url = false)
|
||||||
{
|
{
|
||||||
static $_profile_cache;
|
static $_profile_cache;
|
||||||
static $_base_profile_url;
|
|
||||||
|
|
||||||
$cache_key = $user_id;
|
// We cache some common variables we need within this function
|
||||||
|
if (empty($_profile_cache))
|
||||||
|
{
|
||||||
|
global $phpbb_root_path, $phpEx;
|
||||||
|
|
||||||
// If the get_username_string() function had been executed once with an (to us) unkown mode, all modes are pre-filled and we can just grab it.
|
$_profile_cache['base_url'] = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u={USER_ID}');
|
||||||
if ($user_id && $user_id != ANONYMOUS && isset($_profile_cache[$cache_key][$mode]))
|
$_profile_cache['tpl_noprofile'] = '{USERNAME}';
|
||||||
{
|
$_profile_cache['tpl_noprofile_colour'] = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
|
||||||
// If the mode is 'no_profile', we simply construct the TPL code due to calls to this mode being very very rare
|
$_profile_cache['tpl_profile'] = '<a href="{PROFILE_URL}">{USERNAME}</a>';
|
||||||
if ($mode == 'no_profile')
|
$_profile_cache['tpl_profile_colour'] = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
|
||||||
{
|
|
||||||
$tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
|
|
||||||
return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $_profile_cache[$cache_key][$mode];
|
global $user, $auth;
|
||||||
}
|
|
||||||
|
|
||||||
global $phpbb_root_path, $phpEx, $user, $auth;
|
// This switch makes sure we only run code required for the mode
|
||||||
|
switch ($mode)
|
||||||
|
{
|
||||||
|
case 'full':
|
||||||
|
case 'noprofile':
|
||||||
|
case 'colour':
|
||||||
|
|
||||||
|
// Build correct username colour
|
||||||
$username_colour = ($username_colour) ? '#' . $username_colour : '';
|
$username_colour = ($username_colour) ? '#' . $username_colour : '';
|
||||||
|
|
||||||
|
// Return colour
|
||||||
|
if ($mode == 'colour')
|
||||||
|
{
|
||||||
|
return $username_colour;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no break;
|
||||||
|
|
||||||
|
case 'username':
|
||||||
|
|
||||||
|
// Build correct username
|
||||||
if ($guest_username === false)
|
if ($guest_username === false)
|
||||||
{
|
{
|
||||||
$username = ($username) ? $username : $user->lang['GUEST'];
|
$username = ($username) ? $username : $user->lang['GUEST'];
|
||||||
|
@ -1189,42 +1204,42 @@ function get_username_string($mode, $user_id, $username, $username_colour = '',
|
||||||
$username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']);
|
$username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $user->lang['GUEST']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build cache for all modes
|
// Return username
|
||||||
$_profile_cache[$cache_key]['colour'] = $username_colour;
|
if ($mode == 'username')
|
||||||
$_profile_cache[$cache_key]['username'] = $username;
|
{
|
||||||
$_profile_cache[$cache_key]['no_profile'] = true;
|
return $username;
|
||||||
|
}
|
||||||
|
|
||||||
// Profile url - only show if not anonymous and permission to view profile if registered user
|
// no break;
|
||||||
|
|
||||||
|
case 'profile':
|
||||||
|
|
||||||
|
// Build correct profile url - only show if not anonymous and permission to view profile if registered user
|
||||||
// For anonymous the link leads to a login page.
|
// For anonymous the link leads to a login page.
|
||||||
if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile')))
|
if ($user_id && $user_id != ANONYMOUS && ($user->data['user_id'] == ANONYMOUS || $auth->acl_get('u_viewprofile')))
|
||||||
{
|
{
|
||||||
if (empty($_base_profile_url))
|
$profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace(array('={USER_ID}', '=%7BUSER_ID%7D'), '=' . (int) $user_id, $_profile_cache['base_url']);
|
||||||
{
|
|
||||||
$_base_profile_url = append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&u={USER_ID}');
|
|
||||||
}
|
|
||||||
|
|
||||||
$profile_url = ($custom_profile_url !== false) ? $custom_profile_url . '&u=' . (int) $user_id : str_replace('={USER_ID}', '=' . (int) $user_id, $_base_profile_url);
|
|
||||||
$tpl = (!$username_colour) ? '<a href="{PROFILE_URL}">{USERNAME}</a>' : '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>';
|
|
||||||
$_profile_cache[$cache_key]['full'] = str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$tpl = (!$username_colour) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
|
|
||||||
$_profile_cache[$cache_key]['full'] = str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), $tpl);
|
|
||||||
$profile_url = '';
|
$profile_url = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the profile url from above
|
// Return profile
|
||||||
$_profile_cache[$cache_key]['profile'] = $profile_url;
|
if ($mode == 'profile')
|
||||||
|
|
||||||
// If - by any chance - no_profile is called before any other mode, we need to do the calculation here
|
|
||||||
if ($mode == 'no_profile')
|
|
||||||
{
|
{
|
||||||
$tpl = (!$_profile_cache[$cache_key]['colour']) ? '{USERNAME}' : '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>';
|
return $profile_url;
|
||||||
return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($_profile_cache[$cache_key]['colour'], $_profile_cache[$cache_key]['username']), $tpl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $_profile_cache[$cache_key][$mode];
|
// no break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($mode == 'full' && !$profile_url) || $mode == 'no_profile')
|
||||||
|
{
|
||||||
|
return str_replace(array('{USERNAME_COLOUR}', '{USERNAME}'), array($username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_noprofile'] : $_profile_cache['tpl_noprofile_colour']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), (!$username_colour) ? $_profile_cache['tpl_profile'] : $_profile_cache['tpl_profile_colour']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue