Creative Web Specialist - An online portfolio and resource site of Warren Buckley

Latest Posts

Mar10th

Gravatar Umbraco Package

Author
Warren Buckley

Hello all,
This evening I have decided to create a nice quick package to help use Gravatar easily on your umbraco blog/site. There have been snippets on other blogs to help you achieve this, I have just created two XSLT Extensions to use in your XSLT and an example XSLT file to show how you can use the helpers.

If you haven't heard of Gravatar before, it is a service that allows you to upload an image so you can have a globally recgonised avatar on the web that is associated to your email address. The most useful scenario is on your Umbraco blog to display Gravatar images of visitors who have left comments, but you may think of some other creative scenarios you may want to use it in.

This is my Gravatar
Warren Buckleys Gravatar

The two methods available are
getGravatarImageURL and FormatStringToMD5

The first method getGravatarImageURL expects two parameters, which are below.

stringForGravatar: the email address that you want the Gravatar image for.
defaultImage: this is an absolute URL to a default image if the Gravatar image does not exist.

This Returns: a full absolute URL to an the Gravatar image.

The second method FormatStringToMD5 expects one parameter, which is below.

stringToFormat: this is the string you wish to format as a MD5 hash.

This Returns: an MD5 hashed string, which you can use manually to build up the Gravatar URL if you prefer, of for MD5 hashing other strings.

This package installs the following files:

  • bin/CWSHelperGravatar.dll
  • xslt/CWS_Example_DisplayYourGravatar.xslt
  • /usercontrols/Installer/CWSGravatar/cwsGravatarInstaller.ascx

The installer usercontrol cwsGravatarInstaller.ascx is used to modify the /config/xsltExtensions.config
to setup my custom XSLT extension to allow us to do the MD5 hashe & create the full Gravatar URL.

The actual package installs the following into umbraco:

  • Macro: [XSLT] CWS:Display Your Gravatar Example
  • XSLT: CWS_Example_DisplayYourGravatar.xslt

To use this package just install this package, to do this take the following steps.

  1. Login to umbraco
  2. Goto the Developer section
  3. Right click the Macros node
  4. Select Import Package
  5. Press Browse and find the zip package file you have downloaded
  6. Follow the steps in the wizard
  7. Once installed insert the macro into your XHTML template
  8. Insert your email address and the Absolute URL to an image you want to use for a default image.

So enough with the ranting, here is the link to the file your after......
Download Creative Website Specialist - Gravatar Package v1.0.0

I look forward to any feedback or comments and credit goes to Per Ploug Hansen as his original code has been used for the FormatStringToMD5 method.

13 comments
11th March, 2008
Just wondering if I set a gravatar up before. Seem to remember I did. I guess it will display if I post a comment…
11th March, 2008
Sweet feature, I’ve actually never heard of it before. Guess I’ll have to go test it on my own blog now…
11th March, 2008
Hi Darren, this is not an umbraco site I plan to do a redesign of this site and at the same time move it over to the wonderful world of Umbraco.

Soeren, let me know when it is live on your site.
11th March, 2008
Ok, I’ve put it online on my blog. Didn’t take more than a couple of minutes!

You can view it here: http://www.afdeling18.dk/
It’s in Danish I’m afraid, but it follows a pretty standardized blog layout. So you should be able to find a post with a couple of comments :-)

I’ve got the following comments:

- It doesn’t seem like the “default image” works. It just displays some ugly, blue Gravatar thingy.

- I’d like to link the image to a users web page, if they’ve filled out an URL and they have a Gravatar. If not, then just link to Gravatar.com. But I don’t see how I can test if a certain email has an associated Gravatar?
11th March, 2008
…Here’s a good example with a lot of comments:
http://www.afdeling18.dk/blog/alternativer-til-thorborgs-e-pusher.aspx#comments

Apparently none of my readers has heard of Gravatars :-)
11th March, 2008
One more comment:

- Any chance of adding size as a parameter too? The default 80×80 is a big too big for my liking.
12th March, 2008
I’ve removed the Gravatar’s from my blog again.
All of a sudden the default, blue Gravatar disapeared and just showed an invalid image instead.

Doesn’t seem to me that the service is stable enough?
13th March, 2008
Hi Soren,
Feel free to email me about this problem, so I can help you look at it and improve it.

My email should be very obvious :)
19th June, 2008
Hi Warren I'm getting an error when saving my XSLT.

I've checked that your dll has been installed and it is also configured in xsltExtensions.config.

Any ideas?

Error occured
System.Xml.Xsl.XsltException: Prefix 'CWSHelper.gravatar' is not defined.
at System.Xml.Xsl.XsltOld.InputScopeManager.ResolveNonEmptyPrefix(String prefix)
at System.Xml.Xsl.XsltOld.XsltCompileContext.LookupNamespace(String prefix)
at System.Xml.Xsl.XsltOld.XsltCompileContext.ResolveFunction(String prefix, String name, XPathResultType[] argTypes)
at MS.Internal.Xml.XPath.FunctionQuery.SetXsltContext(XsltContext context)
at System.Xml.Xsl.XsltOld.Processor.GetCompiledQuery(Int32 key)
at System.Xml.Xsl.XsltOld.Processor.RunQuery(ActionFrame context, Int32 key)
at System.Xml.Xsl.XsltOld.VariableAction.Execute(Processor processor, ActionFrame frame)
at System.Xml.Xsl.XsltOld.ActionFrame.Execute(Processor processor)
at System.Xml.Xsl.XsltOld.Processor.Execute()
at System.Xml.Xsl.XsltOld.Processor.Execute(TextWriter writer)
at System.Xml.Xsl.XslTransform.Transform(XPathNavigator input, XsltArgumentList args, TextWriter output, XmlResolver resolver)
at System.Xml.Xsl.XslTransform.Transform(IXPathNavigable input, XsltArgumentList args, TextWriter output, XmlResolver resolver)
at umbraco.presentation.webservices.codeEditorSave.SaveXslt(String fileName, String fileContents, Boolean ignoreDebugging)
24th June, 2008
Hey Warren, just testing to see if my gravatar shows up on your blog.
24th June, 2008
@Darren are you using my example XSLT as this should not error.

@Bob it works fine!
22nd July, 2008
... is testing :)
21st September, 2008
... is also testing :o)
Post a comment »

Comment's have been disabled, due to getting hit badly with comment form spam

My Skill Set

This is a quick list of my skill set to date

  • XHTML
  • CSS
  • Photoshop (Slicing)
  • XSLT
  • ASP.NET
  • Umbraco .NET CMS

My del.icio.us

My Last.FM

I am listening to:

  • Ain't Pretending by CowbellOh Girl29 Jul 2010, 10:37
  • Just Want Your Love by CowbellOh Girl29 Jul 2010, 10:33
  • Oh Girl by CowbellOh Girl29 Jul 2010, 10:31
Warren Buckley is an umbraco MVP 2008/2009 Warren Buckley is an umbraco level 1 certified developer

Photo of Warren Buckley Warren Buckley is a Creative Web Specialist based in Leigh on Sea, Essex , UK.