bradygaster.com

fewer resources, less time, more features

Graffiti + Gravatar (a Gravatar Widget)

February 21 2008
Posted to: ,

As promised, I'm trying to ramp up the Graffiti content floating around on the Internets. This post will reflect my first attempt at creating a Graffiti Widget. This particular Widget will allow you to enter in your email address (or the email address of the poor sap who's picture will be displayed on your Graffiti-powered site), then will take said email address and perform the MD5 hash described here by Jon Galloway to get the proper Gravatar icon. The code for this Widget can be seen below. Feel free to steal it, optimize it, and do anything else you think might make it better.

 

using System;
using System.Collections.Specialized;
using System.Web;
using Graffiti.Core;
using System.Web.UI;
using System.Web.Security; 

 

namespace Bmg.Graffiti.Extensions {     [WidgetInfo("3FD5239E-D91A-4ec1-B93A-01F27089A1BF",         "Gravatar Icon",         "Displays a Gravatar icon for a specific email address.")]     public class GravatarWidget : Widget     {         public string HTML;         public override string RenderData()         {             return HTML;         } 

        public override string Name         {             get { return "Gravatar Icon Widget"; }         } 

        protected string GetGravatarUrl(string emailAddress)         {             string hash = FormsAuthentication.HashPasswordForStoringInConfigFile(emailAddress.Trim(), "MD5");             hash = hash.Trim().ToLower();             string gravatarUrl =                 string.Format("http://www.gravatar.com/avatar.php?gravatar_id={0}&rating=G&size=60", hash);             return gravatarUrl;         }

        protected override NameValueCollection DataAsNameValueCollection()         {             NameValueCollection nvc = base.DataAsNameValueCollection();             return nvc;         }

 

        public override StatusType SetValues(HttpContext context,             NameValueCollection nvc)         {             base.SetValues(context, nvc);             string email = nvc["Email"];             string imgUrl = GetGravatarUrl(email);             HTML = string.Format("<img src=\"{0}\"/>", imgUrl);             return StatusType.Success;         } 

        protected override FormElementCollection AddFormElements()         {             FormElementCollection fec = new FormElementCollection();             fec.Add(new TextFormElement("Email", "Email Address",                 "Enter the email address for the Gravatar icon you wish to display."));             return fec;         }     } }

 

Happy Coding! 

Comments Email Permalink Bookmark and Share kick it

Comments

7/19/2009 9:49:38 PM #

government grants

Great coding, thanks for sharing

government grants

8/2/2009 7:02:16 AM #

ligtv izle

thanks for informationLaughing

ligtv izle

8/12/2009 1:58:40 PM #

Уеб Дизайн

Hi mate,
I was looking for that solution nearly all day.Can i copy this article into my blog?If you  are agree,we can exchange useful articles in the future?

Best Regards,
Chris

Уеб Дизайн

8/22/2009 10:04:06 PM #

Cheap Auto Insurance Quotes

thanks for this.. great widget

Cheap Auto Insurance Quotes

9/2/2009 2:37:32 PM #

fix blue screen

If for some reason you do not, I ask you to please subscribe from the new site.

fix blue screen

10/27/2009 5:21:53 PM #

personal loans for people with bad credit

humm ..thanks for sharing

personal loans for people with bad credit