diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 78fb4a328..81d81a966 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,6 +21,7 @@ require 'forwardable' module ApplicationHelper include Redmine::WikiFormatting::Macros::Definitions + include GravatarHelper::PublicMethods extend Forwardable def_delegators :wiki_helper, :wikitoolbar_for, :heads_for_wiki_formatter @@ -561,9 +562,17 @@ module ApplicationHelper (@has_content && @has_content[name]) || false end - def gravatar_for_mail(mail, options = { }) + # Returns the avatar image tag for the given +user+ if avatars are enabled + # +user+ can be a User or a string that will be scanned for an email address (eg. 'joe ') + def avatar(user, options = { }) if Setting.gravatar_enabled? - return gravatar(mail.to_s.downcase, options) rescue nil + email = nil + if user.respond_to?(:mail) + email = user.mail + elsif user.to_s =~ %r{<(.+?)>} + email = $1 + end + return gravatar(email.to_s.downcase, options) unless email.blank? rescue nil end end diff --git a/app/views/account/show.rhtml b/app/views/account/show.rhtml index 305629a9c..175a11c75 100644 --- a/app/views/account/show.rhtml +++ b/app/views/account/show.rhtml @@ -2,7 +2,7 @@ <%= link_to(l(:button_edit), {:controller => 'users', :action => 'edit', :id => @user}, :class => 'icon icon-edit') if User.current.admin? %> -

<%= gravatar_for_mail @user.mail unless @user.mail.empty? %> <%=h @user.name %>

+

<%= avatar @user %> <%=h @user.name %>

<%= mail_to(h(@user.mail)) unless @user.pref.hide_mail %> diff --git a/app/views/issues/_history.rhtml b/app/views/issues/_history.rhtml index e65c4d4d6..2b30dadc5 100644 --- a/app/views/issues/_history.rhtml +++ b/app/views/issues/_history.rhtml @@ -4,7 +4,7 @@

<%= link_to "##{journal.indice}", :anchor => "note-#{journal.indice}" %>
<%= content_tag('a', '', :name => "note-#{journal.indice}")%> <%= format_time(journal.created_on) %> - <%= journal.user.name %>

- <%= gravatar_for_mail(journal.user.mail.blank? ? "" : journal.user.mail, :size => "32") %> + <%= avatar(journal.user, :size => "32") %>