Skip to content

Commit 06b7b96

Browse files
committedAug 15, 2012
Allow custom default avatar icons
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
1 parent babcb8b commit 06b7b96

File tree

4 files changed

+70
-28
lines changed

4 files changed

+70
-28
lines changed
 

‎config_defaults_inc.php

+19-6
Original file line numberDiff line numberDiff line change
@@ -1000,12 +1000,25 @@
10001000
$g_sort_by_last_name = OFF;
10011001

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

‎core/print_api.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ function print_successful_redirect( $p_redirect_to ) {
169169

170170
# Print avatar image for the given user ID
171171
function print_avatar( $p_user_id, $p_size = 80 ) {
172-
if ( OFF == config_get( 'show_avatar' ) ) {
172+
if ( OFF === config_get( 'show_avatar' ) ) {
173173
return;
174174
}
175175

‎core/user_api.php

+18-17
Original file line numberDiff line numberDiff line change
@@ -808,28 +808,29 @@ function user_get_name( $p_user_id ) {
808808
* @return array|bool an array( URL, width, height ) or false when the given user has no avatar
809809
*/
810810
function user_get_avatar( $p_user_id, $p_size = 80 ) {
811-
$t_email = utf8_strtolower( trim( user_get_email( $p_user_id ) ) );
812-
if( is_blank( $t_email ) ) {
813-
$t_result = false;
814-
} else {
815-
$t_size = $p_size;
811+
$t_default_avatar = config_get( 'show_avatar' );
816812

817-
if( http_is_protocol_https() ) {
818-
$t_gravatar_domain = 'https://secure.gravatar.com/';
819-
} else {
820-
$t_gravatar_domain = 'http://www.gravatar.com/';
821-
}
813+
if( OFF === $t_default_avatar ) {
814+
# Avatars are not used
815+
return false;
816+
}
822817

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

825-
$t_result = array(
826-
$t_avatar_url,
827-
$t_size,
828-
$t_size,
829-
);
823+
$t_email_hash = md5( utf8_strtolower( trim( user_get_email( $p_user_id ) ) ) );
824+
825+
# Build Gravatar URL
826+
if( http_is_protocol_https() ) {
827+
$t_avatar_url = 'https://secure.gravatar.com/';
828+
} else {
829+
$t_avatar_url = 'http://www.gravatar.com/';
830830
}
831+
$t_avatar_url .= "avatar/$t_email_hash?d=$t_default_avatar&r=$t_rating&s=$p_size";
831832

832-
return $t_result;
833+
return array( $t_avatar_url, $p_size, $p_size );
833834
}
834835

835836
# --------------------

‎docbook/Admin_Guide/en-US/Configuration.xml

+32-4
Original file line numberDiff line numberDiff line change
@@ -941,10 +941,38 @@
941941
<varlistentry>
942942
<term>$g_show_avatar</term>
943943
<listitem>
944-
<para>Show user avatar (default OFF); the current implementation is based on http://www.gravatar.com,
945-
users will need to register there with the same email address used in
946-
this MantisBT installation to have their avatar shown.</para>
947-
<note><para>Upon registration or avatar change, it takes some time for the updated gravatar images to show on sites.</para></note>
944+
<para>Show the user's avatar
945+
</para>
946+
<para>The current implementation is based on
947+
<ulink url="http://www.gravatar.com">Gravatar</ulink>;
948+
Users will need to register there the same email address
949+
used in this MantisBT installation to have their avatar
950+
shown.
951+
Please note: upon registration or avatar change, it may
952+
take some time for the updated gravatar images to show
953+
on sites
954+
</para>
955+
<para>The config can be either set to OFF (avatars disabled),
956+
or to a string defining the default avatar to be used
957+
when none is associated with the user's email.
958+
Valid values are:
959+
<itemizedlist>
960+
<listitem><para>OFF (default)</para>
961+
</listitem>
962+
<listitem><para>One of Gravatar's defaults
963+
(mm, identicon, monsterid, wavatar, retro);
964+
refer to
965+
<ulink url="http://en.gravatar.com/site/implement/images/">
966+
Image Requests documentation
967+
</ulink>
968+
for further details.
969+
</para></listitem>
970+
<listitem><para>An URL to the default image to be used
971+
(for example, "http:/path/to/unknown.jpg"
972+
or "%path%images/no_avatar.png").
973+
</para></listitem>
974+
</itemizedlist>
975+
</para>
948976
</listitem>
949977
</varlistentry>
950978
<varlistentry>

0 commit comments

Comments
 (0)
Please sign in to comment.