Placed in: Home arrow Programming arrow Joomla arrow Enable Gravatar support in !JoomlaComment buy propecia 5mgbuy accutane with no prescriptionbuy zithromax onlinebuy cialis overnight
Enable Gravatar support in !JoomlaComment

!JoomlaComment is one of the leading free commenting components for Joomla!. I've been using the component since the beginning of my website.

Still, !JoomlaComment isn't perfect (yet) in my opinion (And I'm not the only one). I would really like to see Trackback support and the ability to edit your own post in 120 seconds. For my website, I wanted to add Gravatar support, so I went editing the !JoomlaComment code to show those globally recognized avatars.

Gravatar for JoomlaComment

One of the strangest things is that !JoomlaComment already supports most things needed for Gravatar. There is already avatar support for Community Builder. The only thing needed for support Gravatar on a PHP platform is an email address. !JoomlaComment has the build-in functionality to ask the user for his email.

So let's edit the PHP code and let's add Gravatar support! This tutorial is written on the latest release of !JoomlaComment at this moment: 3.23.

1. Customizing the PHP code

First, open the !JoomlaComment class file with your favorite PHP editor (Dreamweaver, Notepad++, but Notepad will do too). I'm talking about the following file:

components/com_comment/joscomment/comment.class.php

Around line 2222 you'll find the following code:

 
$display   = $this->_avatar;
$html      = JOSC_utils::checkBlock('BLOCK-avatar_picture', $display, $html);
if ($display){
   if(strpos($this->_avatar,"gallery/")===false) 
      $path = "$mosConfig_live_site/images/comprofiler/tn$this->_avatar";
   else
      $path = "$mosConfig_live_site/images/comprofiler/$this->_avatar";
      $html    = str_replace('{avatar_picture}', $this->profileLink
      ("<img class='avatar' src='$path' alt='avatar' />", $this->_user_id),
         $html);
}

Now delete (or comment out) the total IF statement, starting with if ($display). Add the following code directly after the the statement. I added comments in the code so you'll be able to understand it.

$display   = $this->_avatar;
$html      = JOSC_utils::checkBlock('BLOCK-avatar_picture', $display, $html);
// START Marcofolio.net Enable Gravatar
// Retrieve emailaddress given by user
$email = $this->_item['email'];
 
// Set the default avatar if the email address is not know by Gravatar
$default = "http://www.marcofolio.net/images/logo/gravatar-default.png";
 
// Set the size of the Gravatar image
$size = 50;
 
// Prepare the gravatar image
$totalGrav = "<img class=\"avatar\"
src=http://www.gravatar.com/avatar.php?gravatar_id=".
md5($email)."&default=".
urlencode($default)."&size=".
$size." alt=\"Gravatar image\" />";
 
// Write the Gravatar image to the template
$html = str_replace('{avatar_picture}', $totalGrav, $html);
// END Marcofolio.net Enable Gravatar 

You'll need to change $default to the location where your default avatar is located. Change $size to the width & height of the avatars.

Save the file and overwrite your old comment.class.php with this one (Make a backup before overwriting).

2. Customizing the template

Now let's change your template file to show the actual avatar. Open the index.html of your template (Found in components/com_comment/joscomment/templates/YOUR-TEMPLATE/). I'll be using the default template called default-emotop. Search for the following code found around line 151.

{BLOCK-avatar_picture}<td class='avatarcontainer' width='1' 
  align='center'>{avatar_picture}</td>{/BLOCK-avatar_picture}

Remove the {BLOCK-avatar_picture} and {/BLOCK-avatar_picture} to always show the avatar.

Save the file and overwrite your old index.html from your template file (Make a backup before overwriting).

You're done! Reload your website (with comments) to see the Gravatar support and try it for yourself.

Conclusion

As you could have guessed, this technique will override the Community Builder avatar support. I also changed the code for the URL link support: By clicking on the avatar image, you'll go to the website of the user, instead of clicking on the little "world" image. To do so, you'll need to make further changes to the class file and your template file.

You can download my modified code in the download section. This includes the gravatar to website linking part.

Anyway, I hope Gravatar support will be added automatically in one of the next releases of !JoomlaComment, where the admin will need to set the $default and $size parameters in the back-end.


Tags:  gravatar customize joomlacomment joomla

Interested in this topic? You might enjoy another article I've written called

Comments
Add NewSearchRSS
Randal   2008-05-12 12:06:43
Gravatar image Oh Thanks for this solution! Now users JoomlaComment need only a trackback/ping feature, and JoomlaComment will be strong rivalry to JomComment. I'm wrong?

PS. Oh, maybe you can send this solution to author JoomlaComment to adding this feature in new version?
Marco   2008-05-12 14:21:02
Gravatar image Yes, indeed.

Another thing that !JoomlaComment needs is the maximum width of an image of using the [img] tag. Maybe something like automatic linking the avatar (or name of the user) to the website, instead of the "globe" image. Or what about the "safe user details" so the user will be remembered and doesnt need to enter his details again every time he visits the site (just with a cookie).

I already contacted the developer of !JoomlaComment, but haven't got any reactions yet.

Hope you implemented it successfully on your website.

Greetings,,,
Mr.Q   2008-07-04 18:54:04
Gravatar image Thx for Gravatar
mrtn - hi   2008-10-24 19:55:22
Gravatar image great stuff guys
Suwahadi - Thanks...   2008-10-28 06:49:49
Gravatar image Thank you for this tips.
I had written this with our similar language in http://suwahadi.net/content/view/170/121/
Marco - Thanks   2008-10-28 08:07:24
Gravatar image Thanks for the translation, great work :) . I hope it now spreads to a great number of people!
ridhoyp - please help me   2008-11-09 15:17:03
Gravatar image mate, i ve an error.. when i overwrite the comment.class.php with your code :(
ridhoyp - thanx a lot ive done   2008-11-09 15:39:16
Gravatar image thanx a lot mate ,ive done with it.. nice job.. i loved it so much.. !!!!!!!
Marco - Great!   2008-11-09 16:57:27
Gravatar image I assume that you got it working now? Congrats!

I do wonder: What kind of error did you get and what did you do to fix it? You could help others if they get this in the future too.

Greetings,,
watchmath - I will try this!   2008-11-23 04:19:08
Gravatar image I will try this in my joomla site. Thanks for the tips!.
gonzaunit - thank   2009-01-01 21:43:34
Gravatar image Posted image
Renato - Thak you!   2009-02-25 01:38:05
Gravatar image Thank You!!!
ridhoyp - want to ask something   2009-03-07 08:36:45
Gravatar image hi mark.. :) how about the comment module.. hmm.. are the joomla comment module can display the gravatar too? :) i want it so much.. so everybody who have commented to my article can see at the right of my pages :) thanx before.. :) btw can i change the emoticon too? :) thanx so much...
Daniel Dimitrov   2009-04-16 21:41:50
Gravatar image Thank you very much for the tutorial marco :)
I followed and changed quite a few things :)
http://compojoom.com/blog/8-news/70-joomla-comment-and-gravatar.html

!joomlacomment 4.0 Beta1 coming soon :) Stay tuned...
Marco - Great!   2009-04-17 09:18:13
Gravatar image Great Daniel! If you can, you should add trackback/pingback support to the next version of !JoomlaComment - That would make it an even more pretty complete and awesome component!

Anyway, good to see that this article (including the other one with Akismet) is going to be implemented in the next releases of !JoomlaComment . Please don't forget the credits ;) !

Greetings,,,
Robintel - Nice!   2009-04-18 13:44:37
Gravatar image @Marco

Thank you! I've been trying to find a way to include gravatar in JC for quite some time now. Unfortunately I don't have the necessary expertise. But you have! And you really helped.

Thank you!

@Daniel Dimitrov

It would be nice to have JC remember the web of the registered users. Or design the form so that autocomplete could be used.

@Both

Keep up the excellent work, guys!
Marco - Great!   2009-04-18 19:50:34
Gravatar image Great to see that my articles actually helped other people and it's even cooler to see my code actually implemented in the next release of !JoomlaComment.

Thank you for leaving those kind words!
Daniel Dimitrov   2009-04-18 14:00:47
Gravatar image @robintel
I'm planning to implement a cookie based form that will save the user data if selected.

Everything needs time :) so please be patient and help joomlacomment grow (don't forget the adnetwork - that is nothing more, than a way to finance the project, but more for it with beta1 next week)
bisugo - implementing gravatar   2009-06-18 14:54:00
Gravatar image will try to implement the codes, in our site. very informative guide. thank you.
Read more...
Name:
Email:
  Gravatar enabled.
Website:
Title:
UBBCode:
[b] [i] [u] [url] [quote] [code] [img] 
 
 
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
 
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

Get updates from this website along with 4724 others.