We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

New Plugin: EEGravatar

Development and Programming

Les Jenkins's avatar
Les Jenkins
44 posts
20 years ago
Les Jenkins's avatar Les Jenkins

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.

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
20 years ago
Lisa Wess's avatar Lisa Wess

I never even heard of this service, but that’s pretty neaet now that I’ve read about it. Thanks, Les! =)

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
20 years ago
Lisa Wess's avatar Lisa Wess

Les, just a quick question - if someone does not have a default avatar, will this be a big X? I ask because the entire image code isn’t wrapped in the plugin tags so want to know if I must put a default to avoid a broken image image… =)

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
20 years ago
Lisa Wess's avatar Lisa Wess

Nevermind, I should know better. Works perfectly =) Thank you, Les!

       
Les Jenkins's avatar
Les Jenkins
44 posts
20 years ago
Les Jenkins's avatar Les Jenkins

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.

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
20 years ago
Lisa Wess's avatar Lisa Wess

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. 😉

       
Les Jenkins's avatar
Les Jenkins
44 posts
20 years ago
Les Jenkins's avatar Les Jenkins

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.

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
20 years ago
Lisa Wess's avatar Lisa Wess

Will do, sankoo sir. =)

       
Les Jenkins's avatar
Les Jenkins
44 posts
20 years ago
Les Jenkins's avatar Les Jenkins

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.

       
Chris Curtis's avatar
Chris Curtis
17 posts
20 years ago
Chris Curtis's avatar Chris Curtis

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]

       
Lisa Wess's avatar
Lisa Wess
20,502 posts
20 years ago
Lisa Wess's avatar Lisa Wess

Les, I think it’s a fantastic plugin. A great first one, for sure. I’m just a terrible pain in the rear, I’m sure the staff can attest to that. 😉

       
Les Jenkins's avatar
Les Jenkins
44 posts
20 years ago
Les Jenkins's avatar Les Jenkins

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. 😊

       
Les Jenkins's avatar
Les Jenkins
44 posts
20 years ago
Les Jenkins's avatar Les Jenkins

Hmmm. Tried to submit to the EE Plugins site, but even after I’ve logged in it acts as though I haven’t when I try to submit something.

       
Les Jenkins's avatar
Les Jenkins
44 posts
20 years ago
Les Jenkins's avatar Les Jenkins

Nevermind, it appears to be letting me in now. 😊 Plugin has been submitted.

       
Mr Adams's avatar
Mr Adams
18 posts
20 years ago
Mr Adams's avatar Mr Adams

The same thing happened to me a few times when trying to submit a plugin… it asked me to login again.

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.