Skip to content

Commit

Permalink
Fix 8254: Gravatar integration should handle empty email addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
giallu committed Oct 14, 2007
1 parent 6cfdf1a commit b5970a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
16 changes: 9 additions & 7 deletions core/print_api.php
Expand Up @@ -18,7 +18,7 @@
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.

# --------------------------------------------------------
# $Id: print_api.php,v 1.182.2.2 2007-10-13 22:35:39 giallu Exp $
# $Id: print_api.php,v 1.182.2.3 2007-10-14 20:50:58 giallu Exp $
# --------------------------------------------------------

$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -126,12 +126,14 @@ function print_avatar( $p_user_id ) {

if ( access_has_project_level( config_get( 'show_avatar_threshold' ), null, $p_user_id ) ) {
$t_avatar = user_get_avatar( $p_user_id );
$t_avatar_url = $t_avatar[0];
$t_width = $t_avatar[1];
$t_height = $t_avatar[2];
echo '<a rel="nofollow" href="http://site.gravatar.com">' .
'<img class="avatar" src="' . $t_avatar_url . '" alt="Gravatar image"' .
' width="' . $t_width . '" height="' . $t_height . '" /></a>';
if ( false !== $t_avatar ) {
$t_avatar_url = $t_avatar[0];
$t_width = $t_avatar[1];
$t_height = $t_avatar[2];
echo '<a rel="nofollow" href="http://site.gravatar.com">' .
'<img class="avatar" src="' . $t_avatar_url . '" alt="User avatar"' .
' width="' . $t_width . '" height="' . $t_height . '" /></a>';
}
}
}

Expand Down
23 changes: 15 additions & 8 deletions core/user_api.php
Expand Up @@ -18,7 +18,7 @@
# along with Mantis. If not, see <http://www.gnu.org/licenses/>.

# --------------------------------------------------------
# $Id: user_api.php,v 1.113.2.1 2007-10-13 22:35:46 giallu Exp $
# $Id: user_api.php,v 1.113.2.2 2007-10-14 20:50:58 giallu Exp $
# --------------------------------------------------------

$t_core_dir = dirname( __FILE__ ).DIRECTORY_SEPARATOR;
Expand Down Expand Up @@ -643,19 +643,26 @@ function user_get_name( $p_user_id ) {
}


# return the user avatar image
# return value is an array( URL, width, height )
# in this first implementation, only gravatar.com avatars are supported
/**
* Return the user avatar image URL
* in this first implementation, only gravatar.com avatars are supported
* @return array|bool an array( URL, width, height ) or false when the given user has no avatar
*/
function user_get_avatar( $p_user_id ) {
$t_email = strtolower( user_get_email( $p_user_id ) );
$t_default_image = "/images/gravatar_logo.gif";
$t_size = 80;
$t_avatar_url = "http://www.gravatar.com/avatar.php?gravatar_id=" . md5( $t_email ) .
if ( is_blank( $t_email ) ) {
$t_result = false;
} else {
$t_default_image = "/images/gravatar_logo.gif";
$t_size = 80;
$t_avatar_url = "http://www.gravatar.com/avatar.php?gravatar_id=" . md5( $t_email ) .
"&amp;default=" . urlencode( $t_default_image ) .
"&amp;size=" . $t_size .
"&amp;rating=G";
$t_result = array( $t_avatar_url, $t_size, $t_size );
}

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


Expand Down

0 comments on commit b5970a1

Please sign in to comment.