Fork me on GitHub
Current releases are 2.1.1 (2 Aug 2014) and 2.0.18.13 (5 Aug 2014)
Ready for 2.1? Find out if your favorite plugins are compatible.
The 2.0 branch will no longer receive updates after Dec 2014.

'In This Discussion' user avatars not using Gravatar

edited March 2012 in Vanilla 2.0 Help

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 ☯ hasta luego :) In-Flight 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')

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    badlearner

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

    badlearner
  • 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 ☯ hasta luego :) In-Flight 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)

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    badlearner
  • peregrineperegrine ☯ hasta luego :) In-Flight MVP

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

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    badlearner
  • @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 ☯ hasta luego :) In-Flight 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.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • 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 ☯ hasta luego :) In-Flight 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.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    badlearner
  • 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 ☯ hasta luego :) In-Flight 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"

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    badlearner
  • peregrineperegrine ☯ hasta luego :) In-Flight MVP

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

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

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

  • 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 ☯ hasta luego :) In-Flight 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.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

  • 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. :)

    peregrineAolee
  • peregrineperegrine ☯ hasta luego :) In-Flight MVP

    nice.

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    badlearner
  • 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();
        ?>
        
    
    >

    <?php echo T('In this Discussion'); ?>

    >
      > <?php > foreach ($this->_UserData->Result() as $User) { > ?> >
    • > <?php > echo UserAnchor($User, 'UserLink'); > ?> > <?php > echo Gdn_Format::Date($User->DateLastActive); > ?> >
    • > <?php > } > ?> >
    >
        <?php
    >         $String = ob_get_contents();
    >         @ob_end_clean();
    >         return $String;
    >      }
    > 
    > With this:
    > 
    >      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); > } > ?> >
    >
        <?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". :)

  • 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();
        ?>
        
    
    >

    <?php echo T('In this Discussion'); ?>

    >
      > <?php > foreach ($this->_UserData->Result() as $User) { > ?> >
    • > <?php > echo UserAnchor($User, 'UserLink'); > ?> > <?php > echo Gdn_Format::Date($User->DateLastActive); > ?> >
    • > <?php > } > ?> >
    >
        <?php
    >         $String = ob_get_contents();
    >         @ob_end_clean();
    >         return $String;
    >      }
    > 
    > With this:
    > 
    >      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); > } > ?> >
    >
        <?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". :)


    Check out my other Plugins here

  • @Aolee : I don't understand. I don't see anything missing. ('u.Email' is there in the 3rd instruction. see?)

  • AoleeAolee Hobbyist & Coder ✭✭
    edited March 2012

    badlearner said: @Aolee : I don't understand. I don't see anything missing. ('u.Email' is there in the 3rd instruction. see?)

    nothing wrong with your mod. :) what i mean was the missing attribute i mentioned before was the Email. Email is needed by the Gravatar to work, same thing i encountered before in modding the whosonline to show the avatar. :) good job! :)


    Check out my other Plugins here

    badlearner
  • peregrineperegrine ☯ hasta luego :) In-Flight MVP
    edited March 2012

    @Aolee - please don't take offense....

    I know there are some brilliant people on this discussionboard and some trying to earn a buck, nothing wrong with that. And it can be tiresome for long time users to answer the same old questions that are exact duplicated questions (because somebody failed to search for the question or read the documentation). At times you may want the questioner to do a little work, so they will learn. But sometimes it is just as easy and perhaps better to provide the answer without making it a cryptic riddle. It can be a teaching tool and just as useful to provide newcomers some detailed answers. So pardon my vent, I just had to get this off my mind and I hope I don't insult anybody. Just want to add my thoughts for this specific situation. A constructive critique if you will. But let me preface it that you did provide some help and clues which is better than silence, but then that's why they call this a forum.

    case in point http://vanillaforums.org/discussion/comment/156272#Comment_156272

    "are you using any other plugin that's using the UserPhoto Function?" you could have also given a learning experience by teaching saying grep -r UserPhoto * in the vanilla directory to find a file where it is located and list the file name.

    "indexphotos?"

    ""check the content of the $User" you could have said var_dump($User), and you will notice there is no email value, it needs to be added.

    "and compare it to the $User of the one u edited in inthisdiscussionmodule.php" you could have said we need to put the e-mail in the object you can do this by adding it to the Select('u.UserID, u.Name, u.Photo, u.Email'). We know it is available from theuser table in the vanilla database by using phpmyadmin and browse the structure of the database, that is why we are adding u for user in u.Email.

    "there might be a missing attribute." yep, there might be - but you could have said there is a missing attribute it is called email.

    Also check out the whosonline plugin for an example of how I did it.


    leave the koans for the zen buddhists and the cryptic riddles for Oedipus to solve when the sphinx poses a riddle.

    I personally think it could benefit the whole user community and the addition of alot of useful plugins, if one were to step through ideas, provide an explanation, give some documentation before instead of after as a followup.

    Personally, I think the documentation badlearner provided is more useful and a better learning tool than a cryptic answer. Oh well, I've upset and alienated alll the people who could give me answers and help me :)

    Monetary Donations will be appreciated if you use my plugins. Thanks in Advance.
    As a waiter gets a tip for a good meal, tips for successful solutions appreciated as well. Peregrine

    badlearner
  • UnderDogUnderDog Moderator
    edited March 2012

    peregrine said: @Aolee - please don't take offense....

    I know there are some brilliant people on this discussionboard and some trying to earn a buck, nothing wrong with that. And it can be tiresome for long time users to answer the same old questions that are exact duplicated questions (because somebody failed to search for the question or read the documentation). At times you may want the questioner to do a little work, so they will learn.

    As a fellow-forum-user I'm saying: That's a good start.

    But sometimes it is just as easy and perhaps better to provide the answer without making it a cryptic riddle. It can be a teaching tool and just as useful to provide newcomers some detailed answers. So pardon my vent, I just had to get this off my mind and I hope I don't insult anybody. Just want to add my thoughts for this specific situation. A constructive critique if you will. But let me preface it that you did provide some help and clues which is better than silence, but then that's why they call this a forum.

    As a fellow-forum-user I'm saying: Actually, you don't want to ask the brilliant programmers to explain the cryptic riddle. (That's my Opinion). You want the semi-programmers and documentation-writing-happy users to write documentation about those riddles.

    Don't we have the Vanilla Wiki to make that documentation now?

    http://vanillawiki.homebrewforums.net/index.php/Main_Page (If @hbf needs more help, just let us know)

    if one were to step through ideas, provide an explanation, give some documentation before instead of after as a followup.

    Can you give some examples of what you mean?

    Personally, I think the documentation badlearner provided is more useful and a better learning tool than a cryptic answer. Oh well, I've upset and alienated alll the people who could give me answers and help me :)

    Good, a new documentation specialist is born (documentalist, good word?)

  • AoleeAolee Hobbyist & Coder ✭✭

    no worries no offense taken.

    badlearner
Sign In or Register to comment.