Placed in: Home arrow Programming arrow Joomla arrow Enable Gravatar support in !JoomlaComment

Cialis Online

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.
klickjobs - Only for *.PNG avatars?   2010-07-09 13:12:08
Gravatar image Hello,
i am so happy that i found this site here. Thank you soo much. It worked with your describtion.

But i have a question: i noticed that only *.png avatars are visible but no *.jpg.

Not sure if i missed something.
Is it because of the default avatar? Its a PNG.
I hope you have a solution for me for this.
You would be my god :D

Thanks in advance!
greetings from germany
klickjobs
klickjobs   2010-07-09 13:29:27
Gravatar image hmm... ok, not true .. not really.
I tried it but it won't work.

Maybe you have the time to take a quick look at my website.
The avatars are only working for 1 person, but not for the others.
I don't know. The pic of this user is 120*120 and 11kb and a png.

I tried it also with these domensions but it won't work.
If you have the time pls take a look if you need to
www.klickjobs.biz

thanks a lot!
Daniel Dimitrov - klickjobs - update please   2010-07-09 13:45:29
Gravatar image Hey klickjobs,
I have no idea what marco will say, but first you are using 3.26 - this version is already 2 years old. It is vulnerable to XSS attacks. Go to compojoom.com, register and download at least 4.0RC1. If you have 24
klickjobs   2010-07-09 13:48:13
Gravatar image Oh i use 3.23 :dry:

Hmm, i hoped not hear that because i was happy to get a free comment tool. But i heard that also support is no longer available for this version.

I think i need to buy the compojoom comments :(
Anyway... many thanks for your fast reply.
If anyone has a solution would be great but i think i need to buy the latest version

thanks!
klickjobs   2010-07-09 13:49:13
Gravatar image i mean 3.26 ... sorry
Daniel Dimitrov   2010-07-09 14:00:36
Gravatar image The free version is still available on compojoom. And the latest free version is just 3 months old. We will introduce another free version based on compojoomComment in the next months. So anyway - you can update and 4.0 has gravatar support in the core.

P.S. Marco, I hope you don't mind my replies here :)
klickjobs   2010-07-09 14:18:21
Gravatar image Oh! This are great news! *happy* :kiss:
Maybe i will buy the full version because there are so many free plugins/components outthere and i think i should support one of them :)

Many thanks!
I disabled my comments for guest because i don't want to be hacked by XSS attacks.

Thanks for your help so far
klickjobs   2010-07-09 18:54:00
Gravatar image Hello,
sorry for distrubing again :s
I updated now on 4.0 RC1. Seems working good but the avatar problem is still the same. The avatar is showing only for 1 user.

Should i undo the changes i made from the describtion above?

And another problem appears:
The page navigation for the comments () brakes the first comment. You can see it in my page right now.

I hope anyone can help me or give me a link with a solution to your forum.

Thanks, and sorry for asking again
klickjobs   2010-07-09 19:39:11
Gravatar image Only FYI
The navigation problem is solved through your FAQ. Thanks for the great flash help.

But the avatar problem is really strange. Maybe i act like a noobie, sorry, but i don't get it. I registered for me and for another Admin a avatar at gravatar. It worked for these accounts. But i think this is not the right solution.
I thought the comment tool grabs the avatars from my CBE.
For some pics it works, but for some not.

Sorry for annoying questions but i haven't found any info in your forum/FAQ about this.

greetings
kj
Netkrali   2010-09-21 10:15:41
Gravatar image Video Sytes.
Digital Extreme Media Group - Nice job!   2010-11-02 01:19:02
Gravatar image Thanks for sharing, good job.
Trouwjurken - adsa   2011-08-19 08:36:33
Gravatar image abendkleider abendkleider günstig cocktailkleider günstig abendkleider 2011 cocktailkleider brautjungfernkleider günstig brautkleider 2011 brautkleider brautkleider günstig hochzeitskleider günstig hochzeitskleider hochzeitskleider 2011 abiballkleider abiballkleider 2011 abschlussballkleider kleider für hochzeitsgäste galajurken avondjurken trouwjurken cocktailjurken bruidsjurken jurken online avondjurken online cocktailjurkjes galajurken avondjurken trouwjurken cocktailjurken bruidsjurken avondjurken online galajurken online vestidos de cerimonia vestidos de cerimonia baratos vestidos de noiva 2011 vestidos de noiva vestidos de noiva baratos vestidos de noite vestidos de gala vestidos cocktail vestidos de festa vestidos de baile vestidos de fiesta vestidos de fiesta 2011 vestidos de fiesta baratos vestidos de novia 2011 vestidos de novia vestidos de novia baratos vestidos de noche baratos vestidos de noche vestidos dama de honor vestidos de coctel vestidos de coctel 2011 vestidos de baile galajurken gala jurken galajurk galakleding bruidsjurken bruidsjurk bruidskleding trouwjurken trouwjurk trouwkleding goedkope trouwjurken trouwjurken 2011 Goedkope Schoenen Schoenen Online Kopen Bruidsschoenen Trouwschoenen bruidsaccessoires Bruidssieraden Trouwaccessoires Haaraccesoires Bruid Bruidslingerie Bruidssluiers Bruidstasjes Bruidshandschoenen dameskleding dames kleding dameskleding online goedkope dameskleding lingerie sexy lingerie jurken rokken sportkleding positiekleding herenkleding kinderkleding kinderkleding outlet outlet kinderkleding kinderkleding online online kinderkleding herenschoenen damesschoenen online damesschoenen dames schoenen hoge hakken pumps sleehak sandalen slippers cinderella schoenen laarzen kinderschoenen kinderschoenen outlet kinderschoenen online kinders choenen outlet kinderkleding online goedkope kinderschoenen kinderschoenen sale tassen tas tassen online damestassen goedkope tassen tassen online shop schoudertassen schoudertas rugzak rugzakken rugtas handtassen handtas handtassen online messenger tas
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:
 
Security Image
Please input the anti-spam code that you can read in the image.
Unsubscribe from e-mail notifications.
 
< Prev   Next >
Subscribe

7440 people are subscribed for free to receive high quality articles.