Skip to content

Commit

Permalink
Allow custom default avatar icons
Browse files Browse the repository at this point in the history
Following implementation of #13992, it was no longer possible for
administrators to define a custom default avatar, as Mantis forced use
of Gravatar's 'identicon'.

This commit reintroduces that functionality, and allows use of either
one of Gravatar's default images or a custom one (identified by an URL),
through appropriate configuration of $g_show_avatar.

Fixes #14032
  • Loading branch information
dregad committed Aug 15, 2012
1 parent babcb8b commit 06b7b96
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 28 deletions.
25 changes: 19 additions & 6 deletions config_defaults_inc.php
Expand Up @@ -1000,12 +1000,25 @@
$g_sort_by_last_name = OFF;

/**
* Show user avatar. The current implementation is based on
* http://www.gravatar.com. Users will need to register there the same address
* used in this MantisBT installation to have their avatar shown. Please note:
* upon registration or avatar change, it takes some time for the updated
* gravatar images to show on sites
* @global int $g_show_avatar
* Show user avatar
*
* The current implementation is based on http://www.gravatar.com
* Users will need to register there the same email address used in this
* MantisBT installation to have their avatar shown.
* Please note: upon registration or avatar change, it takes some time for
* the updated gravatar images to show on sites
*
* The config can be either set to OFF (avatars disabled) or set to a string
* defining the default avatar to be used when none is associated with the
* user's email. Valid values:
* - OFF (default)
* - One of Gravatar's defaults (mm, identicon, monsterid, wavatar, retro)
* @link http://en.gravatar.com/site/implement/images/
* - An URL to the default image to be used (for example,
* "http:/path/to/unknown.jpg" or "%path%images/no_avatar.png")
*
* @global int|string $g_show_avatar
* @see $g_show_avatar_threshold
*/
$g_show_avatar = OFF;

Expand Down
2 changes: 1 addition & 1 deletion core/print_api.php
Expand Up @@ -169,7 +169,7 @@ function print_successful_redirect( $p_redirect_to ) {

# Print avatar image for the given user ID
function print_avatar( $p_user_id, $p_size = 80 ) {
if ( OFF == config_get( 'show_avatar' ) ) {
if ( OFF === config_get( 'show_avatar' ) ) {
return;
}

Expand Down
35 changes: 18 additions & 17 deletions core/user_api.php
Expand Up @@ -808,28 +808,29 @@ function user_get_name( $p_user_id ) {
* @return array|bool an array( URL, width, height ) or false when the given user has no avatar
*/
function user_get_avatar( $p_user_id, $p_size = 80 ) {
$t_email = utf8_strtolower( trim( user_get_email( $p_user_id ) ) );
if( is_blank( $t_email ) ) {
$t_result = false;
} else {
$t_size = $p_size;
$t_default_avatar = config_get( 'show_avatar' );

if( http_is_protocol_https() ) {
$t_gravatar_domain = 'https://secure.gravatar.com/';
} else {
$t_gravatar_domain = 'http://www.gravatar.com/';
}
if( OFF === $t_default_avatar ) {
# Avatars are not used
return false;
}

$t_avatar_url = $t_gravatar_domain . 'avatar/' . md5( $t_email ) . '?d=identicon&r=G&s=' . $t_size;
# Default avatar is either one of Gravatar's options, or
# assumed to be an URL to a default avatar image
$t_default_avatar = urlencode( $t_default_avatar );
$t_rating = 'G';

$t_result = array(
$t_avatar_url,
$t_size,
$t_size,
);
$t_email_hash = md5( utf8_strtolower( trim( user_get_email( $p_user_id ) ) ) );

# Build Gravatar URL
if( http_is_protocol_https() ) {
$t_avatar_url = 'https://secure.gravatar.com/';
} else {
$t_avatar_url = 'http://www.gravatar.com/';
}
$t_avatar_url .= "avatar/$t_email_hash?d=$t_default_avatar&r=$t_rating&s=$p_size";

return $t_result;
return array( $t_avatar_url, $p_size, $p_size );
}

# --------------------
Expand Down
36 changes: 32 additions & 4 deletions docbook/Admin_Guide/en-US/Configuration.xml
Expand Up @@ -941,10 +941,38 @@
<varlistentry>
<term>$g_show_avatar</term>
<listitem>
<para>Show user avatar (default OFF); the current implementation is based on http://www.gravatar.com,
users will need to register there with the same email address used in
this MantisBT installation to have their avatar shown.</para>
<note><para>Upon registration or avatar change, it takes some time for the updated gravatar images to show on sites.</para></note>
<para>Show the user's avatar
</para>
<para>The current implementation is based on
<ulink url="http://www.gravatar.com">Gravatar</ulink>;
Users will need to register there the same email address
used in this MantisBT installation to have their avatar
shown.
Please note: upon registration or avatar change, it may
take some time for the updated gravatar images to show
on sites
</para>
<para>The config can be either set to OFF (avatars disabled),
or to a string defining the default avatar to be used
when none is associated with the user's email.
Valid values are:
<itemizedlist>
<listitem><para>OFF (default)</para>
</listitem>
<listitem><para>One of Gravatar's defaults
(mm, identicon, monsterid, wavatar, retro);
refer to
<ulink url="http://en.gravatar.com/site/implement/images/">
Image Requests documentation
</ulink>
for further details.
</para></listitem>
<listitem><para>An URL to the default image to be used
(for example, "http:/path/to/unknown.jpg"
or "%path%images/no_avatar.png").
</para></listitem>
</itemizedlist>
</para>
</listitem>
</varlistentry>
<varlistentry>
Expand Down

0 comments on commit 06b7b96

Please sign in to comment.