Every gravatar in my comments looks just the same. I was under the impression from using gravatars in Wordpress that each commenter would get a unique gravatar. Not sure if I have done something wrong or if something is just broken.

Comments

Dave Reid’s picture

What kind of default gravatar image option do you have selected? Only the Identicon, Wavatar and MonsterId options are uniquely generated for users that don't have a Gravatar.

stephencarr’s picture

Sorry, I should clarify I am testing with MonsterId against anonymous user comments. I can see that registered users get unique gravatars, or a gravatar associated with their email address.

Dave Reid’s picture

Most likely then, your anonymous user comments don't have an email, so a blank string is used. If you edit one of the comments you should be able to see if an e-mail address was entered. You can also force users to enter in their e-mail address by enabling the "Anonymous posters must leave their contact information" option on http://example.com/admin/content/node-type/story (or whichever content type you use).

stephencarr’s picture

Ah, yes you are right! But I took a look at the code and see that from the $variables array you can extract 'hostname' which is the commenter's IP address and I think this could be used as an alternate fallback hash seed for anonymous users who do not provide an email address.

If you could tell me how to get 'hostname' from that array I could implement it myself. So far I have tried

$variables['account']->hostname;

But this is always empty, which is odd because $variables['account']->mail; supposedly carries the email address string from the same array.

Dave Reid’s picture

It appears that when a comment is loaded for display, the hostname column is not included in the SQL query, so we cannot make any use of it in the Gravatar module.

stephencarr’s picture

My php is really rusty so I might be wrong, but when I put a print_r($variables); in gravatar.module gravatar_preprocess_user_picture() I get the array spitting out and including 'hostname' with the correct value. I am probably wrong but I just assumed if I can echo out that full array from the gravatar.module it must have access to the full array.

Dave Reid’s picture

The $variables['user']->hostname is for the current user (you) not the comment. We can't use that information. The information about the commenter is in $variables['account'].

stephencarr’s picture

OK, it's probably no big deal to most but this is how I got round this, it might help others who want individual gravatars for anons who don't want to leave any email address:

Find:

      // Load mail/homepage variable from an anonymous comment.

      if (empty($account->mail) && !empty($variables['account']->mail)) {
        $account->mail = $variables['account']->mail;
      } 
      if (empty($account->homepage) && !empty($variables['account']->homepage)) {
        $account->homepage = $variables['account']->homepage;
      }

And replace it with

      // Load mail/homepage variable from an anonymous comment.

      if (empty($account->mail) && !empty($variables['account']->mail)) {
        $account->mail = $variables['account']->mail;
      } elseif (empty($account->mail)){
      	 $account->mail = $variables['account']->name;
      }
      if (empty($account->homepage) && !empty($variables['account']->homepage)) {
        $account->homepage = $variables['account']->homepage;
      }

It hashes on the name they provide which for me is as good a fall back as I think I am going to get.

Dave Reid’s picture

I submitted a patch for Drupal core to provide the hostname field in comments so it can be used by Gravatar. I'm doubtful that it will be backported to Drupal 6, but at least it can be used when Gravatar is ported to Drupal 7.

EDIT: Forgot the link to the issue: #514928: Provide {comment}.hostname in comment_render()

Dave Reid’s picture

Status: Active » Postponed

Until this can be fixed in Drupal core, I'm marking this as postponed.

darktygur-1’s picture

Status: Postponed » Active

If you really want to use hostname, feel free to change this back to postponed, but I'm not sure that hostname is such a good idea. I'd suggest doing some combination of name, mail (if available), and/or homepage (again, if available).

Hostname (at least, just hostname anyway) seems bad to me because it'd give the same avatar to two people that post from the same ip address (maybe the same library, same office building, same home, same internet cafe, for some examples). It can especially happen if a website is visited by a lot of people that live close together. You would get two (or more?) different anonymous posters that share the same avatar.

Dave Reid’s picture

Version: 6.x-1.7 » 7.x-1.x-dev
Category: bug » feature

The current code now falls back to hostname if available, homepage if available, or the result of serialize($account);.

I guess if an e-mail address isn't available, mashing up 'name', 'homepage', and 'hostname' would be good rather than our separate fallbacks. Moving to a feature request now.

Dave Reid’s picture

Title: All my gravatars look the same » Update logic if anonymous comments' e-mail is not available