summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2013-05-19 20:48:36 -0400
committerJames Moger <james.moger@gitblit.com>2013-05-19 20:48:36 -0400
commitd551f9dfdb305f1f4c72d79d1577a1feac41eda7 (patch)
tree72ef6bfa6713a285d32da37bee999520a1fccb87
parent6ef8d7cd37dcf8b742f23d461266ea7e94f0312d (diff)
downloadgitblit-d551f9dfdb305f1f4c72d79d1577a1feac41eda7.tar.gz
gitblit-d551f9dfdb305f1f4c72d79d1577a1feac41eda7.zip
Use mm gravatar icon for user menu
-rw-r--r--src/main/java/com/gitblit/utils/ActivityUtils.java21
-rw-r--r--src/main/java/com/gitblit/wicket/pages/RootPage.java3
-rw-r--r--src/main/java/com/gitblit/wicket/panels/GravatarImage.java11
3 files changed, 30 insertions, 5 deletions
diff --git a/src/main/java/com/gitblit/utils/ActivityUtils.java b/src/main/java/com/gitblit/utils/ActivityUtils.java
index 732fdeb1..1792bf26 100644
--- a/src/main/java/com/gitblit/utils/ActivityUtils.java
+++ b/src/main/java/com/gitblit/utils/ActivityUtils.java
@@ -165,7 +165,7 @@ public class ActivityUtils {
* size of thumbnail. if width <= 0, the default of 50 is used.
* @return
*/
- public static String getGravatarThumbnailUrl(String email, int width) {
+ public static String getGravatarIdenticonUrl(String email, int width) {
if (width <= 0) {
width = 50;
}
@@ -174,6 +174,25 @@ public class ActivityUtils {
"https://www.gravatar.com/avatar/{0}?s={1,number,0}&d=identicon", emailHash, width);
return url;
}
+
+ /**
+ * Creates a Gravatar thumbnail url from the specified email address.
+ *
+ * @param email
+ * address to query Gravatar
+ * @param width
+ * size of thumbnail. if width <= 0, the default of 50 is used.
+ * @return
+ */
+ public static String getGravatarThumbnailUrl(String email, int width) {
+ if (width <= 0) {
+ width = 50;
+ }
+ String emailHash = StringUtils.getMD5(email);
+ String url = MessageFormat.format(
+ "https://www.gravatar.com/avatar/{0}?s={1,number,0}&d=mm", emailHash, width);
+ return url;
+ }
/**
* Returns the Gravatar profile, if available, for the specified hashcode.
diff --git a/src/main/java/com/gitblit/wicket/pages/RootPage.java b/src/main/java/com/gitblit/wicket/pages/RootPage.java
index 47fcc720..30251516 100644
--- a/src/main/java/com/gitblit/wicket/pages/RootPage.java
+++ b/src/main/java/com/gitblit/wicket/pages/RootPage.java
@@ -500,7 +500,8 @@ public abstract class RootPage extends BasePage {
boolean standardLogin = session.authenticationType.isStandard();
if (GitBlit.getBoolean(Keys.web.allowGravatar, true)) {
- add(new GravatarImage("username", user.getDisplayName(), user.emailAddress, "navbarGravatar", 20, false));
+ add(new GravatarImage("username", user.getDisplayName(),
+ user.emailAddress, "navbarGravatar", 20, false, false));
} else {
add(new Label("username", user.getDisplayName()));
}
diff --git a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java b/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
index 80dbddba..da20e9b8 100644
--- a/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
+++ b/src/main/java/com/gitblit/wicket/panels/GravatarImage.java
@@ -50,10 +50,10 @@ public class GravatarImage extends Panel {
}
public GravatarImage(String id, PersonIdent person, int width, boolean linked) {
- this(id, person.getName(), person.getEmailAddress(), "gravatar", width, linked);
+ this(id, person.getName(), person.getEmailAddress(), "gravatar", width, linked, true);
}
- public GravatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean linked) {
+ public GravatarImage(String id, String username, String emailaddress, String cssClass, int width, boolean linked, boolean identicon) {
super(id);
String email = emailaddress == null ? username.toLowerCase() : emailaddress.toLowerCase();
@@ -61,7 +61,12 @@ public class GravatarImage extends Panel {
Link<Void> link = new BookmarkablePageLink<Void>("link", GravatarProfilePage.class,
WicketUtils.newObjectParameter(hash));
link.add(new SimpleAttributeModifier("target", "_blank"));
- String url = ActivityUtils.getGravatarThumbnailUrl(email, width);
+ String url;
+ if (identicon) {
+ url = ActivityUtils.getGravatarIdenticonUrl(email, width);
+ } else {
+ url = ActivityUtils.getGravatarThumbnailUrl(email, width);
+ }
ExternalImage image = new ExternalImage("image", url);
if (cssClass != null) {
WicketUtils.setCssClass(image, cssClass);