I’ve written my first plugin in PHP for ExpressionEngine called EEGravatar:
The EEGravatar Plugin allows you to easily insert a “globally recognized avatar” image from Gravatar (http://www.gravatar.com/).
The plugin is designed to be used within either the {exp:weblog:entries} or the {exp:comment:entries} loop and has one required parameter: {email}. It returns a properly formatted URL for use in an IMG tag as follows:
{exp:gravatar}{email}{/exp:gravatar}
== OPTIONAL PARAMETERS ==
default=”http://www.somesite.com/someimage.jpg”
Defines a default avatar if there isn’t one associated with the email address or if it exceeds the rating.
rating=”[G | PG | R | X]”
Allows you to limit gravatars to the appropriate rating. Anything exceeding the rating will use the default (if supplied) or not display.
size=”[1..80]”
Allows you to define how big the gravatar will be in pixels. Any size other than 80 will cause the original gravatar image to be downsampled using bicubic resampling before output
border=”[hex color]”
Puts a border of the specified color around the gravatar.
== POSSIBLE EXAMPLES ==
Here’s a few examples that you might use:
{exp:gravatar rating=
Only displays gravatars of PG rating or lower.
{exp:gravatar rating=
Displays 40x40 pixel gravatars of R rating or lower with a red border around them.
{exp:gravatar size=
Displays gravatars of 70x70 pixels or a default graphic for users without a gravatar. Put’s the user’s name in the alt and title tags and styles the image using a class called “avatar.”
You can download a copy of the plugin by clicking here.
As it turns out, I’ve hit my first bug with that very aspect of this plugin. Currently specifying a default avatar doesn’t work as the urlencoding of the address isn’t working as expected. I suspect it’s something internal to EE that’s causing the problem, but right now it doesn’t matter if you make use of that parameter as it’s currently not working.
The real answer to your question is, though, that it doesn’t leave a big X if there’s no default. It just doesn’t show any image at all. I’m assuming the folks at Gravatar just return a small 1x1 transparent .gif or something if there’s no avatar associated with it.
nods I was about to make a 1x1 .gif to do that, but noticed there’s no big fat X so didn’t worry about it. I wonder, though, Les… does this do any caching? I always hate using external services because if they go down then your site does too, so in a nervous paranoia, I am wondering if you built in anything to avoid an incident along those lines. 😉
Hmmm. Well, turns out the bug isn’t in EE, just seems the urlencode wasn’t needed afterall despite what the Gravatar site says. I took it out and the default parameter is working just fine. So this is already bumped to revision 1.1. If you’ve downloaded it earlier then grab the updated copy.
Damn, I keep replying just after you’ve posted something new.
No, at this point I’m not doing any caching, though it is something I’d like to figure out how to do. The idea of Gravatar running into issues did occur to me as well and so I plan to see what I might do in that regard, but for the moment I’m just happy to have cobbled this together as it’s my first plugin in PHP ever.
Not that it was terribly difficult or anything.
Sounds pretty cool, Les. As far as caching and Plugins go, I know that Paul does some caching in his Gmail and (I believe) Netflix Plugins. You might want to grab those and take a look at the code to see how it’s done. Caching sounds like it would certainly be welcome with something like this pulling in images from externally.
Oh, and don’t forget to submit it to the EE Plugins site… [grin]
Thanks Chris, I’ll definitely take a look at Paul’s plugins and see if I can wrap my brain around his secrets. 😊 And I’ll be sure to submit this to the plugins page once I get a more substantial “additional information” page cooked up.
LisaJill, not a problem. I knew I’d be opening myself up to some feedback and comments when I wrote this, but I’m a glutton for punishment. 😊
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.