From 630c8265456bed5ab2b3a00a80c236fd43fecdc8 Mon Sep 17 00:00:00 2001 From: Aurélio A. Heckert Date: Thu, 17 Oct 2013 15:59:05 -0300 Subject: [PATCH] Adds user icon for null avatar on user menu --- app/controllers/public/account_controller.rb | 2 +- app/helpers/application_helper.rb | 17 +++++++---------- app/models/user.rb | 9 +++++++-- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index d52652e..36ad1b1 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -262,7 +262,7 @@ class AccountController < ApplicationController def user_data user_data = if logged_in? - current_user.data_hash + current_user.data_hash self else { } end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7a3bdfc..27731cc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -356,7 +356,8 @@ module ApplicationHelper end def theme_path - if session[:theme] + if ( respond_to?(:session) && session[:theme] ) || + ( @controller && @controller.session[:theme] ) '/user_themes/' + current_theme else '/designs/themes/' + current_theme @@ -366,7 +367,8 @@ module ApplicationHelper def current_theme @current_theme ||= begin - if (session[:theme]) + if ( respond_to?(:session) && session[:theme] ) || + ( @controller && @controller.session[:theme] ) session[:theme] else # utility for developers: set the theme to 'random' in development mode and @@ -375,7 +377,7 @@ module ApplicationHelper if ENV['RAILS_ENV'] == 'development' && environment.theme == 'random' @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand @random_theme - elsif ENV['RAILS_ENV'] == 'development' && params[:theme] && File.exists?(File.join(Rails.root, 'public/designs/themes', params[:theme])) + elsif ENV['RAILS_ENV'] == 'development' && respond_to?(:params) && params[:theme] && File.exists?(File.join(Rails.root, 'public/designs/themes', params[:theme])) params[:theme] else if profile && !profile.theme.nil? @@ -600,15 +602,10 @@ module ApplicationHelper def str_gravatar_url_for(email, options = {}) default = theme_option['gravatar'] || NOOSFERO_CONF['gravatar'] || nil - url = 'http://www.gravatar.com/avatar.php?gravatar_id=' + - Digest::MD5.hexdigest(email.to_s) - { + "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s)}?" + { :only_path => false, :d => default - }.merge(options).each { |k,v| - url += ( '&%s=%s' % [ k,v ] ) - } - url + }.merge(options).map{|k,v| '%s=%s' % [ k,v ] }.join('&') end def gravatar_profile_url(email) diff --git a/app/models/user.rb b/app/models/user.rb index 746709c..0e85b8f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -275,7 +275,10 @@ class User < ActiveRecord::Base end end - def data_hash + include ApplicationHelper + + def data_hash(controller=nil) + @controller ||= controller friends_list = {} enterprises = person.enterprises.map { |e| { 'name' => e.short_name, 'identifier' => e.identifier } } self.person.friends.online.map do |person| @@ -286,9 +289,11 @@ class User < ActiveRecord::Base 'status' => person.user.chat_status, } end + avatar = self.person.profile_custom_icon + avatar = str_gravatar_url_for(self.email, :size=>20) if avatar.blank? { 'login' => self.login, - 'avatar' => person.profile_custom_icon, + 'avatar' => avatar, 'is_admin' => self.person.is_admin?, 'since_month' => self.person.created_at.month, 'since_year' => self.person.created_at.year, -- libgit2 0.21.2