Gravatar Macro
Displays a Gravatar profile image |
Type | XAR |
Category | |
Developed by | |
Active Installs | 11 |
Rating | |
License | GNU Lesser General Public License 2.1 |
Table of contents
Description
Display a Gravatar profile image.
If you wish to set gravatar images for all users not having avatars defined yet, see this code snippet.
Usage
Where:
Parameter | Optional | Value |
---|---|---|
No | Email value, e.g. john@doe.com | |
size | Yes | From 1px to 512px, e.g. "50" |
default | Yes | Image to use when no profile is found for the passed email. Valid values are: "mm", "identicon", "monsterid", "wavatar", "retro" or an URL-encoded URL to an image. See the Gravatar documenation for more details. |
Example 1
Display a gravatar:
Result
Example 2
Use the gravatar macro in the user profile to display gravatar instead of avatars found in XWiki. You'll need to edit the XWiki.XWikiUserSheet page in wiki mode and replace the following:
(((
#if($request.xpage == 'edituser')
{{html clean="false"}}
#resizedUserAvatar($doc.fullName 180)
{{/html}}
#else
## By specifying the image width we enable server side resizing. The width value we use is greater than the
## available space because we don't want to loose too much of the image quality (we rely on the browser to fit the
## image in the available space).
{{attachmentSelector classname="XWiki.XWikiUsers" object="$obj.number" property="avatar" #if ($isMyProfile) savemode="direct" #end defaultValue="XWiki.XWikiUserSheet@noavatar.png" width="180" alternateText="$xwiki.getUserName($doc.fullName, false)" buttontext="$services.localization.render('platform.core.profile.changePhoto')" displayImage="true" filter="png,jpg,gif"/}}
#end
)))
With:
(((
#set ($obj = $doc.getObject("XWiki.XWikiUsers"))
{{gravatar email="$obj.getValue('email')" size="180" default="monsterid"/}}
)))
Source Code
For those interested, here's the macro source code:
def hash = org.apache.commons.codec.digest.DigestUtils.md5Hex(xcontext.macro.params.email)
def url = "image:http://www.gravatar.com/avatar/${hash}"
def size = xcontext.macro.params.size
if (size) {
url = "${url}?s=${size}"
}
def d = xcontext.macro.params.default
if (size && d) {
url = "${url}&d=${d}"
} else if (size) {
url = "${url}?d=${d}"
}
println url
{{/groovy}}
Prerequisites & Installation Instructions
We recommend using the Extension Manager to install this extension (Make sure that the text "Installable with the Extension Manager" is displayed at the top right location on this page to know if this extension can be installed with the Extension Manager). Note that installing Extensions when being offline is currently not supported and you'd need to use some complex manual method.
You can also use the following manual method, which is useful if this extension cannot be installed with the Extension Manager or if you're using an old version of XWiki that doesn't have the Extension Manager:
- Log in the wiki with a user having Administration rights
- Go to the Administration page and select the Import category
- Follow the on-screen instructions to upload the downloaded XAR
- Click on the uploaded XAR and follow the instructions
- You'll also need to install all dependent Extensions that are not already installed in your wiki
Release Notes
v1.0
Initial version