blob: 11fd7af3420ff95efe06ff99c4589f524e0d7a13 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 | module UsersHelper
  def user_gravatar_image_tag(user, size = 64)
      image_tag user_image(user), :alt => "", :class => "preview", :width => size, :height => size
  end
#  def user_default_avatar
#    return "#{authenticated_root_url}#{image_path('icons/user.png')}" if Rails.application.config.relative_url_root.blank?
#   relative_url_root = Rails.application.config.relative_url_root.gsub( /\//, '')
#    "#{authenticated_root_url}#{image_path('icons/user.png')}".
#      sub( Regexp.new("/#{relative_url_root}/#{relative_url_root}/"), "/#{relative_url_root}/").
#      sub( Regexp.new("/#{relative_url_root}//#{relative_url_root}/"), "/#{relative_url_root}/")
#  end
  def gravatar_hash(user)
    Digest::MD5.hexdigest( user.email)
  end
  def gravatar_url( user)
    "http://www.gravatar.com/avatar/#{gravatar_hash(user)}?d=404"
  end
  def user_image(user)
    begin
      gravatar_resource = RestClient.get( gravatar_url( user)){|response, request, result| response }
    rescue
      # Happens if network is not available
      return 'icons/user.png'
    end
    if gravatar_resource.code == 404
      # Happens if user has not registered to gravatar
      'icons/user.png'
    else
      gravatar_url( user)
    end
  end
end
 |