Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

'In This Discussion' user avatars not using Gravatar

edited March 2012 in Vanilla 2.0 - 2.8

Hi,

I installed the 'Gravatar' plugin which Implements Gravatar avatars for all users who haven't uploaded their own custom profile picture on my forum.

Then I installed and modded the 'In This Discussion' plugin to show the avatars of users participating in a discussion, instead of their names (i.e., user avatar instead of text).

I did it by editing '/vanilla-root-directory/plugins/VanillaInThisDiscussion/class.inthisdiscussionmodule.php' to use the following code:

         <div class="PhotoGrid">
         <?php
         foreach ($this->_UserData->Result() as $User) {
            ?>
            <?php echo UserPhoto($User); ?>
            <?php
         }
         ?>

The problem is, the 'In This Discussion' panel box shows user avatars but doesn't use their Gravtar — it only uses either the avatar uploaded by the user or the default forum avatar.

Why is this happening? What am I possibly doing wrong? Should I be using something else instead of <?php echo UserPhoto($User); ?> ??

Best Answer

  • peregrineperegrine MVP
    edited March 2012 Answer ✓

    The problem I have is I haven't signed up for gravatars but was just checking the url and other variables. But one more attempt.

    It seems to be missing the email in the object you are sending. So the sql in the top of the "class.inthisdiscussionmodule.php" needs to be changed.

    I hope it will work with this fix - I added u.Email and it looks like it would work based on my echo statements.
    Select('u.UserID, u.Name, u.Photo, u.Email')

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

«1

Answers

  • AoleeAolee Hobbyist & Coder ✭✭
    edited March 2012

    are you using any other plugin that's using the UserPhoto Function?

    indexphotos?

    check the content of the $User

    and compare it to the $User of the one u edited in inthisdiscussionmodule.php

    there might be a missing attribute.



    Check out my other Plugins here

  • edited March 2012

    @Aolee : I checked it out. It uses:

    $this->DisplayPhoto($Sender);
    

    and:

          $FirstUser = UserBuilder($Sender->EventArguments['Discussion'], 'First');
          echo UserPhoto($FirstUser);
    

    I tried various combinations of them with mine. None worked.

  • peregrineperegrine MVP
    edited March 2012

    Just an idea. In any event it will show you how it works.

    identify where the gravatar icons are and build a link to them that is basically what User Photo does.

    you could break out the components to see what the value of $PhotoUrl
    in library/core/functions.render.php to get an idea.

    write your link and anchor based on the value of $url (with the gravatar.com) in function of plugins/gravatar/

    so instead of echo UserPhoto($User);
    echo (the linked image you built yourself)

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • also maybe this will help you
    http://en.gravatar.com/site/implement/hash/

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine : Thanks for trying to help. Yeah, I guess the problem is with hashing the email address. I will check it and let you know if it works. Thanks.

  • edited March 2012

    @peregrine : And finally, after trying for at least one whole day, I give up. It was close. The 'In This Discussion' plugin was showing the user uploaded avatar. But I could not get it to show user's gravatar. :(

  • peregrineperegrine MVP
    edited March 2012

    If you decide to return to it. I wasn't sure if gravatars work anywhere on your site besides the default gravitar icon? I assume your phpinfo shows md5 support.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited March 2012

    @peregrine: Take a look at this thread. User 'Aahan' has uploaded his own avatar, so it shows that. User 'Krish' hasn't, so it shows his Gravatar.

    EDIT: I have disabled the 'In This Discussion' plugin in the sidebar (Panel).

  • peregrineperegrine MVP
    edited March 2012

    I copied from your site hard coded it into this discussions on my site and it showed the same gravatar as on your site.

    
     http://www.gravatar.com/avatar
    /951ae80ef8b74221dc49b5090271fbbe?size=50&default=http%3A%2F%2F(put your website  here)%2Fplugins%2FGravatar%2Fdefault.gif
    
    

    next I just replaced the function with this code.

     public function ToString() {
          if ($this->_UserData->NumRows() == 0)
             return '';
          
          $String = '';
          ob_start();
          ?>
          
             <?php echo T('In this Discussion'); ?>
         
                   
                   <?php
                    foreach ($this->_UserData->Result() as $User) {
                      echo UserPhoto($User);
                     }
                     ?>
             
          
          

    And it worked. Just swap this into the discussion module. It really should work since you have the gravatars working in one place.

    I am not using the vanilla icons plugin only the gravatar plugin.

    --
    If it doesn't work for you goto the gravatar.php plugin - echo or write to a message log.

    Insert :
    echo $Url;
    before this statement at the bottom of the plugin
    if (C('Plugins.Gravatar.UseVanillicon', FALSE))

    and echo $Url right before the return and compare them.

    At least that way you see if it is hitting that plugin - which it needs to do.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited March 2012

    Using the code you provided gives me this error:

    Parse error: syntax error, unexpected '<' in /home/xxxx/public_html/groups/plugins/VanillaInThisDiscussion/class.inthisdiscussionmodule.php on line 59
    

    I am using Gravatar plugin only. I don't use Vanillicons.

    I will check the Gravatar plugin... Thanks.

  • edited March 2012

    -- If it doesn't work for you goto the gravatar.php plugin - echo or write to a message log.

    Insert : echo $Url; before this statement at the bottom of the plugin if (C('Plugins.Gravatar.UseVanillicon', FALSE))

    and echo $Url right before the return and compare them.

    I checked that. If echo $Url; is added before if (C('Plugins.Gravatar.UseVanillicon', FALSE)) it shows this: http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&size=50

    If echo $Url; is added before the return, it shows this: http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&amp;size=50&amp;default=http://groups.boygeek.in/plugins/Gravatar/default.gif

    So, it isn't working, right?

    EDIT: And by the way, I have enabled the 'In This Discussion' plugin now. You can take a look at it here — in the sidebar (panel).

    I modified your code to this to that it retains proper styling:

       public function ToString() {
          if ($this->_UserData->NumRows() == 0)
             return '';
    
          $String = '';
          ob_start();
          ?>
          <div class="Box">
             <h4><?php echo T('In this Discussion'); ?></h4>
             <div class="PhotoGrid">
             <?php
             foreach ($this->_UserData->Result() as $User) {
                echo UserPhoto($User);
                }
                ?>
             </div>
          </div>
          <?php
          $String = ob_get_contents();
          @ob_end_clean();
          return $String;
       }
    
  • peregrineperegrine MVP
    edited March 2012

    Are you sure that user has a gravatar signed up for that e-mail addess.
    same format as the final url with a different md5 conversion.

    It appears to me each user has to sign up for a gravatar, it is not the same as vanilla icons which will work for all users.

    this works same url format (your orginal hash that works on your site for that user.

    • if the md5 hash is not on record at gravatar you will get the default gif.

    http://www.gravatar.com/avatar.php?gravatar_id=951ae80ef8b74221dc49b5090271fbbe&size=50&default
    =http%3A%2F%2Fgroups.boygeek.in%2Fplugins%2FGravatar%2Fdefault.gif

    what's odd is the same user has two different hashes try echoing the $User in the same places.
    and see if its not picking up the user correctly. same with the e-mail.

    (from the comment)
    http://www.gravatar.com/avatar.php?gravatar_id=951ae80ef8b74221dc49b5090271fbbe&amp;size=50&amp;default=http://groups.boygeek.in/plugins/Gravatar/default.gif"

    (from in the discussions
    http://www.gravatar.com/avatar.php?gravatar_id=d41d8cd98f00b204e9800998ecf8427e&amp;size=50&amp;default=http://groups.boygeek.in/plugins/Gravatar/default.gif"

    from your profile it shows this
    http://www.gravatar.com/avatar.php?gravatar_id=951ae80ef8b74221dc49b5090271fbbe&amp;size=50&amp;default=http://groups.boygeek.in/plugins/Gravatar/default.gif"

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I see the problem. Two different $User one an object with e-mail and the other not.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • @peregrine : I was away, and just got back. So, do you know the fix now?

  • peregrineperegrine MVP
    edited March 2012 Answer ✓

    The problem I have is I haven't signed up for gravatars but was just checking the url and other variables. But one more attempt.

    It seems to be missing the email in the object you are sending. So the sql in the top of the "class.inthisdiscussionmodule.php" needs to be changed.

    I hope it will work with this fix - I added u.Email and it looks like it would work based on my echo statements.
    Select('u.UserID, u.Name, u.Photo, u.Email')

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited March 2012

    OMG! @peregrine you got it. That's solves the problem! I will write a full how-to for everyone shortly. Thanks a lot peregrine! (You can check it here.)

  • peregrineperegrine MVP
    edited March 2012

    Glad it helped :). I appreciate and I am sure others will appreciate your how-to.

    We need more complete how-to's in my opinion.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • edited March 2012

    How to show Avatars (Photo / Gravatar) of Users participating in a discussion?

    [1] First enable the 'In This Discussion' and 'Gravatar' plugins on your forum

    [2] Open '/vanilla-forum-root/plugins/VanillaInThisDiscussion/class.inthisdiscussionmodule.php' and replace this block of code:

       public function ToString() {
          if ($this->_UserData->NumRows() == 0)
             return '';
    
          $String = '';
          ob_start();
          ?>
          <div class="Box">
             <h4><?php echo T('In this Discussion'); ?></h4>
             <ul class="PanelInfo">
             <?php
             foreach ($this->_UserData->Result() as $User) {
                ?>
                <li>
                   <strong><?php
                      echo UserAnchor($User, 'UserLink');
                   ?></strong>
                   <?php
                      echo Gdn_Format::Date($User->DateLastActive);
                   ?>
                </li>
                <?php
             }
             ?>
             </ul>
          </div>
          <?php
          $String = ob_get_contents();
          @ob_end_clean();
          return $String;
       }
    

    With this:

       public function ToString() {
          if ($this->_UserData->NumRows() == 0)
             return '';
    
          $String = '';
          ob_start();
          ?>
          <div class="Box">
             <h4><?php echo T('In this Discussion'); ?></h4>
             <div class="PhotoGrid">
             <?php
             foreach ($this->_UserData->Result() as $User) {
                echo UserPhoto($User);
                }
                ?>
             </div>
          </div>
          <?php
          $String = ob_get_contents();
          @ob_end_clean();
          return $String;
       }
    

    You've thereby modded the 'In This Discussion' plugin to output user avatar (the photo he uploaded to your forum, and if he hasn't, his Gravatar) instead of the username and date.

    [3] Now in the same file, change this line:

             ->Select('u.UserID, u.Name, u.Photo')
    

    to this:

             ->Select('u.UserID, u.Name, u.Photo, u.Email')
    

    That's it. And now your discussions should show something like this in the panel (sidebar) — the image below shows that 2 users are participating in the discussion:

    BEFORE:

    Imgur

    AFTER:

    Imgur

    Happy modding! All credit to peregrine.

    @peregrine : Thanks for your time. :)

  • nice.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • AoleeAolee Hobbyist & Coder ✭✭

    badlearner said:
    How to show Avatars (Photo / Gravatar) of Users participating in a discussion?

    [1] First enable the 'In This Discussion' and 'Gravatar' plugins on your forum

    [2] Open '/vanilla-forum-root/plugins/VanillaInThisDiscussion/class.inthisdiscussionmodule.php' and replace this block of code:

     public function ToString() {
        if ($this->_UserData->NumRows() == 0)
           return '';
        
        $String = '';
        ob_start();
        ?>
        <div class="Box">
           <h4><?php echo T('In this Discussion'); ?></h4>
           <ul class="PanelInfo">
           <?php
           foreach ($this->_UserData->Result() as $User) {
              ?>
              <li>
                 <strong><?php
                    echo UserAnchor($User, 'UserLink');
                 ?></strong>
                 <?php
                    echo Gdn_Format::Date($User->DateLastActive);
                 ?>
              </li>
              <?php
           }
           ?>
           </ul>
        </div>
        <?php
        $String = ob_get_contents();
        @ob_end_clean();
        return $String;
     }
    

    With this:

     public function ToString() {
        if ($this->_UserData->NumRows() == 0)
           return '';
        
        $String = '';
        ob_start();
        ?>
        <div class="Box">
           <h4><?php echo T('In this Discussion'); ?></h4>
           <div class="PhotoGrid">
           <?php
           foreach ($this->_UserData->Result() as $User) {
              echo UserPhoto($User);
              }
              ?>
           </div>
        </div>
        <?php
        $String = ob_get_contents();
        @ob_end_clean();
        return $String;
     }
    

    You've thereby modding the 'In This Discussion' plugin to output user avatar (the photo he uploaded to your forum, and if he hasn't, his Gravatar) instead of the username and date.

    [3] Now in the same file, change this line:

             ->Select('u.UserID, u.Name, u.Photo')
    

    to this:

             ->Select('u.UserID, u.Name, u.Photo, u.Email')
    

    That's it. And now your discussions should show something like this in the panel (sidebar) — the image below shows that 2 users are participating in the discussion:

    ![http://i.imgur.com/ftWQe.png]

    Happy modding! All credit to peregrine.

    @peregrine : Thanks for your time. :)

    that's the missing attribute "u.Email". :)

Sign In or Register to comment.