Placed in: Home arrow Programming arrow Joomla arrow Enable Gravatar support in !JoomlaComment comprar viagra en espaƱa
comprar viagra online
comprar viagra generico barato
comprar cialis generico online
comprar cialis online seguro
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:


Around line 2222 you'll find the following code:

$display   = $this->_avatar;
$html      = JOSC_utils::checkBlock('BLOCK-avatar_picture', $display, $html);
if ($display){
      $path = "$mosConfig_live_site/images/comprofiler/tn$this->_avatar";
      $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),

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 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 = "";
// Set the size of the Gravatar image
$size = 50;
// Prepare the gravatar image
$totalGrav = "<img class=\"avatar\"
$size." alt=\"Gravatar image\" />";
// Write the Gravatar image to the template
$html = str_replace('{avatar_picture}', $totalGrav, $html);
// END 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' 

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.


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

< Prev   Next >