1 ralfh Dec 31, 2010 13:15
3 ralfh Jan 01, 2011 15:39
Thanks for your answer. I changed this file, but it didn't work.
The system creates such a link to gravatar.
http://www.gravatar.com/avatar.php?gravatar_id=b6d3aac09cab47825fc61f8d97a9c9cb&size=48&default=http%3A%2F%2Fdialoge.info%2Fb2%2Frsc%2Fimg%2Fdefault_avatar.jpg
Where can I change this?
4 bushleaguecritic Jan 01, 2011 17:56
Are you using B2evo 4.0.1 by any chance?
From what I've seen of the code... you can't change it for comments. The avatar you're seeing is the default avatar from gravatar.com.
The get_avatar() function in /inc/comments/model/_comment.class.php is not building the Gravatar image URL properly. You can see it by viewing the page source. It's hosed up with extra '&'s and an invalid 'default' parameter.
In fact, the way it's coded (in version 4.0.1 anyway), b2evo's default avatar will never be displayed. If a b2evo user doesn't have an avatar, gravatar's big, blue G will always be displayed. Because, Gravatar does not accept a url for an image passed via the 'default' parameter. That's not how it was intended to be used. When passing parameters to gravatar... the only acceptable values for the 'default' parameter are: 'wavatar', 'monsterid', or 'identicon'. Passing the url for an image will NOT display that image.
In the skin code (_item_comment.inc.php, you should be able to do something like this:
$Comment->avatar( 'crop-64x64', 'bCommentAvatar', array(
'rating' => 'g'
'default' => 'wavatar',
) );
to change the style of gravatar's randomly generated avatar image. But something needs to be fixed in that get_avatar() function before that can ever happen... or before b2evo's default user avatar even has a chance at being displayed in a comment.
It may be fixed in 4.0.3, but I've not looked yet.
5 bushleaguecritic Jan 01, 2011 21:00
OK. I have a quick and dirty fix that works for me. It involves modifying a core file ( /inc/comments/model/_comment.class.php). So if you're going to try it, PLEASE back up the file before you make any changes to it.
The avatar() function and the get_avatar() function should be changed to look like the following:
/**
* Template function: display the avatar of the comment's author.
*
*/
function avatar( $params = array(), $size = 'crop-64x64', $class = 'bCommentAvatar' )
{
if( $r = $this->get_avatar( $params, $size, $class ) )
{
echo $r;
}
}
/**
* Get the avatar of the comment's author.
*
* @return string
*/
function get_avatar( $params = array(), $size = 'crop-64x64', $class = 'bCommentAvatar' )
{
global $Plugins, $default_avatar;
if( $comment_author_User = & $this->get_author_User() )
{ // Author is a user
if( $r = $comment_author_User->get_avatar_imgtag( $size, $class ) )
{ // Got an image
return $r;
}
// User doesn't have an avatar... use b2evo default.
else
{
$params = array_merge( array(
'size' => '64',
), $params );
$img_params = array(
'src' => $default_avatar,
'width' => $params['size'],
'height' => $params['size'],
);
if( $class )
{ // add class
$img_params['class'] = $class;
}
$imgtag = '<img'.get_field_attribs_as_string($img_params).' />';
return $imgtag;
}
}
// TODO> add new event
// See if plugin supplies an image
// $img_url = $Plugins->trigger_event( 'GetCommentAvatar', array( 'Comment' => & $this, 'size' => $size ) );
if( empty($img_url) )
{ // Use gravatar
$params = array_merge( array(
'default' => '',
'size' => '64',
), $params );
$img_url = 'http://www.gravatar.com/avatar.php?gravatar_id='.md5( $this->get_author_email() );
if( !empty($params['rating']) )
$img_url .= '&rating='.$params['rating'];
if( !empty($params['size']) )
$img_url .='&size='.$params['size'];
if( !empty($params['default']) )
$img_url .= '&default='.$params['default'];
}
$img_params = array(
'src' => $img_url,
'alt' => $this->get_author_name(),
'title' => $this->get_author_name(),
'width' => $params['size'], // dh> NOTE: works with gravatar, check if extending
'height' => $params['size'], // dh> NOTE: works with gravatar, check if extending
);
if( $class )
{ // add class
$img_params['class'] = $class;
}
$imgtag = '<img'.get_field_attribs_as_string($img_params).' />';
return $imgtag;
}
Those changes alone would allow you to replace the '/rsc/img/default_avatar.jpg' image with whatever image you want... and it will be used by registered users who don't have an avatar when they leave a comment.
If you want to be able to tweak the default gravatar that's shown for unregistered commenters... look for the following code in your skin's '_item_comment.inc.php' file:
$Comment->avatar();
and change it to look like this:
$Comment->avatar( array(
'rating' => 'g',
'size' => '64',
'default' => 'identicon',
) );
You don't need to use all of those parameters if you don't need them. The 'default' parameter can be 'identicon', 'wavatar', or 'monsterid'...which will generate different styles of gravatars based on the commenter's email address (if they don't have a gravatar account of their own).
6 bushleaguecritic Jan 02, 2011 18:15
This bug exists in all 4.0.x versions.
The code in the get_avatar() function of the /inc/comments/model/_comment.class.php is written in such a way that b2evo's default avatar (/rsc/img/default_avatar.jpg) will never be displayed. Because of that, users can't substitute their own default avatar.
It will always display Gravatar's default avatar when a b2evo user doesn't have their own avatar. The problem is that b2evo's default avatar url is being included (via the 'default' parameter) in the gravatar image tag that is being generated by the get_avatar function. The 'default' parameter in that image src href is not meant to include a url. It is meant to be used to tell gravatar which style of automatically-generated avatar to return. 'wavatar', 'identicon', and 'monsterid' are the only acceptable values for the 'default' parameter
Also, there is something wrong with the way gravatar image tag is being built in the get_avatar function. You should be able to pass an alternate 'default' parameter from the skin file (_item_comment.inc.php) and change which style of avatar gravatar returns. This functionality doesn't work. It will always return gravatar's default (big blue G) when a commenter doesn't have a gravatar account.
There is some discussion in this thread about it - with a very hack-ish (and not to be trusted) solution of mine that should shed some light on the problem.
http://forums.b2evolution.net/viewtopic.php?t=21921
7 sam2kb Jan 02, 2011 19:17
ralfh wrote:
Thanks for your answer. I changed this file, but it didn't work.
The system creates such a link to gravatar.
http://www.gravatar.com/avatar.php?gravatar_id=b6d3aac09cab47825fc61f8d97a9c9cb&size=48&default=http%3A%2F%2Fdialoge.info%2Fb2%2Frsc%2Fimg%2Fdefault_avatar.jpgWhere can I change this?
This is a bug in b2evo. Edit the file /inc/comments/model/_comment.class.php:400 and replace
if( !empty($params['rating']) )
$img_url .= '&rating='.$params['rating'];
if( !empty($params['size']) )
$img_url .='&size='.$params['size'];
if( !empty($params['default']) )
$img_url .= '&default='.urlencode($params['default']);
with this
if( !empty($params['rating']) )
$img_url .= '&rating='.$params['rating'];
if( !empty($params['size']) )
$img_url .='&size='.$params['size'];
if( !empty($params['default']) )
$img_url .= '&default='.urlencode($params['default']);
Fixed in CVS
8 sam2kb Jan 02, 2011 19:38
@BushLeagueCritic
I merged your post into this thread. This bug is already fixed.
9 bushleaguecritic Jan 02, 2011 20:14
Thanks! Works great. :)
Also has the added benefit of being able to properly change the default avatar behavior via the skin code:
$Comment->avatar( 'crop-32x32', 'bCommentAvatar', array(
'size' => '32'
'rating' => 'r'
'default' => 'identicon',
) );
10 gerardp Jan 12, 2011 05:32
What if I don't want any avatars? a.k.a the previous version?
11 sam2kb Jan 15, 2011 03:56
GerardP wrote:
What if I don't want any avatars? a.k.a the previous version?
Then disable them on Users > User settings
12 gerardp Jan 15, 2011 05:31
I may be totally lost, but in user settings there is no option to enable/disable avatars.
Just one option: Allow users to upload avatars.
13 sam2kb Jan 15, 2011 20:10
This option disables avatars completely
14 gerardp Jan 15, 2011 21:09
If you are referring to "Allow users to upload avatars", it does not disable anything, apparently.
THX
15 sam2kb Jan 15, 2011 21:37
You may need to fix this bug first
http://forums.b2evolution.net//viewtopic.php?p=106570#106570
It's in here