|
From: FlorinCB <ory...@us...> - 2008-09-12 05:18:03
|
Update of /cvsroot/mxbb/core/includes/sessions/phpbb3 In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9295/core/includes/sessions/phpbb3 Modified Files: core.php Log Message: function get_username_string() Index: core.php =================================================================== RCS file: /cvsroot/mxbb/core/includes/sessions/phpbb3/core.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** core.php 27 Aug 2008 07:32:56 -0000 1.12 --- core.php 12 Sep 2008 05:17:57 -0000 1.13 *************** *** 813,816 **** --- 813,916 ---- return $sql; } + + /** + * Get username details for placing into templates. + * + * @param string $mode Can be profile (for getting an url to the profile), username (for obtaining the username), colour (for obtaining the user colour) or full (for obtaining a html string representing a coloured link to the users profile). + * @param int $user_id The users id + * @param string $username The users name + * @param string $username_colour The users colour + * @param string $guest_username optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then. + * @param string $custom_profile_url optional parameter to specify a profile url. The user id get appended to this url as &u={user_id} + * + * @return string A string consisting of what is wanted based on $mode. + */ + function get_username_string($mode, $user_id, $username = false, $username_colour = '', $guest_username = false, $custom_profile_url = false) + { + global $phpbb_root_path, $mx_root_path, $phpEx, $mx_user, $phpbb_auth; + + $profile_url = ''; + + //Added by OryNider + if (($username == false) || ($username_colour == false)) + { + $this_userdata = mx_get_userdata($user_id, false); + $user_id = $this_userdata['user_id']; + $username = $this_userdata['username']; + $username_colour = $this_userdata['user_colour']; + } + //Added Ends + + $username_colour = ($username_colour) ? '#' . $username_colour : ''; + + if ($guest_username === false) + { + $username = ($username) ? $username : $mx_user->lang['GUEST']; + } + else + { + $username = ($user_id && $user_id != ANONYMOUS) ? $username : ((!empty($guest_username)) ? $guest_username : $mx_user->lang['GUEST']); + } + + // Only show the link if not anonymous + if ($user_id && $user_id != ANONYMOUS) + { + // Do not show the link if the user is already logged in but do not have u_viewprofile permissions (relevant for bots mostly). + // For all others the link leads to a login page or the profile. + if ($mx_user->data['user_id'] != ANONYMOUS && !$phpbb_auth->acl_get('u_viewprofile')) + { + $profile_url = ''; + } + else + { + $profile_url = ($custom_profile_url !== false) ? $custom_profile_url : mx_append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile'); + $profile_url .= '&u=' . (int) $user_id; + } + } + else + { + $profile_url = ''; + } + + switch ($mode) + { + case 'profile': + return $profile_url; + break; + + case 'username': + return $username; + break; + + case 'colour': + return $username_colour; + break; + + case 'full': + default: + + $tpl = ''; + if (!$profile_url && !$username_colour) + { + $tpl = '{USERNAME}'; + } + else if (!$profile_url && $username_colour) + { + $tpl = '<span style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</span>'; + } + else if ($profile_url && !$username_colour) + { + $tpl = '<a href="{PROFILE_URL}">{USERNAME}</a>'; + } + else if ($profile_url && $username_colour) + { + $tpl = '<a href="{PROFILE_URL}" style="color: {USERNAME_COLOUR};" class="username-coloured">{USERNAME}</a>'; + } + + return str_replace(array('{PROFILE_URL}', '{USERNAME_COLOUR}', '{USERNAME}'), array($profile_url, $username_colour, $username), $tpl); + break; + } + } + } |