Code source wiki de GravatarImport
Modifié par Vincent Massol le 2011/08/10 17:20
Afficher les derniers auteurs
author | version | line-number | content |
---|---|---|---|
1 | {{groovy}} | ||
2 | // Find all users with no avatar | ||
3 | println "Recherche de Gravatars pour les membres de l'OSSGTP qui n'ont pas encore d'avatar sur leur profil:" | ||
4 | |||
5 | if (request.getParameter("confirm") == "1") { | ||
6 | println "|=Gravatar|=User Name|=Status" | ||
7 | } else { | ||
8 | println "|=Gravatar|=User Name" | ||
9 | } | ||
10 | |||
11 | xwiki.getQueryManager().xwql("from doc.object(XWiki.XWikiUsers) as user").execute().each() { | ||
12 | def userDoc = xwiki.getDocument(it) | ||
13 | def userObj = userDoc.getObject("XWiki.XWikiUsers") | ||
14 | def avatarProp = userObj.getProperty("avatar") | ||
15 | if (avatarProp == null || avatarProp.getValue().trim().length() == 0) { | ||
16 | // Get their email and if there's one try to find a gravatar | ||
17 | def email = userObj.getProperty("email").getValue() | ||
18 | if (email.trim().length() == 0) { | ||
19 | email = it | ||
20 | } | ||
21 | def hash = org.apache.commons.codec.digest.DigestUtils.md5Hex(email) | ||
22 | def url = "http://www.gravatar.com/avatar/${hash}?d=monsterid&s=120" | ||
23 | if (request.getParameter("confirm") == "1") { | ||
24 | userDoc.addAttachment("gravatar.png", new java.net.URL(url).openStream()) | ||
25 | userObj.set("avatar", "gravatar.png") | ||
26 | userDoc.save("Set Gravatar as avatar", true) | ||
27 | println "|[[image:${url}]]|[[${it}]]|Gravatar imported into profile!" | ||
28 | } else { | ||
29 | println "|[[image:${url}]]|[[${it}]]" | ||
30 | } | ||
31 | } | ||
32 | } | ||
33 | {{/groovy}} |