Avatar Anonymous

Gravatar Implementation in WebDNA

I have created a simple to use WebDNA function that will generate the URL string for retrieving an avatar image from Gravatar. The function will accept parameters directly or via FormVariables. See below for the WebDNA code. Click the button to the right to see implementation examples.

The Code

[function name=gravatar]
	
	Source https://www.network13.net/webdna/

	Generates a Gravatar URL for a specified email address and optional parameters.
	
	Generate MD5 hash from cleaned up email address...
	[text]grav_hash=[encrypt method=APOP][lowercase][listwords words=[email_in]&delimiters= ][word][/listwords][/lowercase][/encrypt][/text]
	
	The following parameters can be set here as a default template for your deployment.
	Each can be overridden by supplying values when calling the function.
	
	grav_size - Size in pixels, defaults to 80px { 1 - 2048 }
	
	grav_default - Default image or imageset to use { URL | 404 | mm | identicon | monsterid | wavatar }
	
	grav_rating - Maximum rating (inclusive), defaults to g { g | pg | r | x }
	
	Generate the string of args
	[text]grav_string=[showif [url][grav_size][/url]!]s=[grav_size][/showif][/text]
	[showif [url][grav_rating][/url]!]
		[text]grav_string=[grav_string]|r=[grav_rating][/text]
	[/showif]
	[showif [url][grav_default][/url]!]
		[text]grav_string=[grav_string]|d=[url][grav_default][/url][/text]
	[/showif]
	[showif [url][grav_string][/url]!]
		[text]grav_string=?[listwords words=[grav_string]&delimiters=|][hideif [index]=1]&[/hideif][word][/listwords][/text]
	[/showif]
	
	[return]//www.gravatar.com/avatar/[grav_hash][grav_string][/return]
	
[/function]