How use Gravatar on ImpressCMS sites

Another day I met a very interesting feature called Gravatar (Globally Recognized Avatars). The idea is have an avatar linked to your email address to be able to use it in various sites. For more information about what is and how Gravatar works click here.

Okay, after this brief introduction will direct to the point. How can you use the resources of Gravatar on your ImpressCMS site and still save space and traffic of your server?

I will show you the way to use this nice functionality on the user profile and then you can make your own changes to use it where you want.

The first step is make a simple hack in the system kernel, more tailored in the user class, so that this feature is available throughout the site.

To do this open the file ROOT/kernel/user.php in a text editor and include the code above on line 433 (or on the end of the XoopsUser class):

gravatar function on kernel/user.php

Save the file and now we can start to play :)

As I said before, our aim is to show the gravatar in the user’s profile. For this, open the file ROOT/userinfo.php in a text editor and on the line 90, change this:

$xoopsTpl->assign(’user_avatarurl’, ‘uploads/’.$thisUser->getVar(’user_avatar’));

for this:

$xoopsTpl->assign(’user_avatarurl’, $thisUser->gravatar());

Save the file and see the result.

Now, if the user has an avatar on the site it will be show else the gravatar will be show. So, if the user has not an avatar and an gravatar the gravatar logo will be show.

As you can see on the gravatar function it have some optional parameters, with this parameters you can set the size and border color of the gravatar and yet define a default image to show instead the logo of gravatar when the user have not the avatar or gravatar.

Click here to download the files used in this hack already with the necessary changes. Only unpack the file and copy the content of the htdocs folder under your ImpressCMS site root folder overwriting the files.

So far is only that, I hope they have enjoyed.

If you have any questions or wish that this feature is included by default in ImpressCMS leave your comment.

Cheers

The comments are owned by the poster. We aren't responsible for their content.