Commit 630c8265456bed5ab2b3a00a80c236fd43fecdc8
1 parent
817df70a
Exists in
master
and in
28 other branches
Adds user icon for null avatar on user menu
That commit makes gravatar helper to work on this context.
Showing
3 changed files
with
15 additions
and
13 deletions
Show diff stats
app/controllers/public/account_controller.rb
@@ -262,7 +262,7 @@ class AccountController < ApplicationController | @@ -262,7 +262,7 @@ class AccountController < ApplicationController | ||
262 | def user_data | 262 | def user_data |
263 | user_data = | 263 | user_data = |
264 | if logged_in? | 264 | if logged_in? |
265 | - current_user.data_hash | 265 | + current_user.data_hash self |
266 | else | 266 | else |
267 | { } | 267 | { } |
268 | end | 268 | end |
app/helpers/application_helper.rb
@@ -356,7 +356,8 @@ module ApplicationHelper | @@ -356,7 +356,8 @@ module ApplicationHelper | ||
356 | end | 356 | end |
357 | 357 | ||
358 | def theme_path | 358 | def theme_path |
359 | - if session[:theme] | 359 | + if ( respond_to?(:session) && session[:theme] ) || |
360 | + ( @controller && @controller.session[:theme] ) | ||
360 | '/user_themes/' + current_theme | 361 | '/user_themes/' + current_theme |
361 | else | 362 | else |
362 | '/designs/themes/' + current_theme | 363 | '/designs/themes/' + current_theme |
@@ -366,7 +367,8 @@ module ApplicationHelper | @@ -366,7 +367,8 @@ module ApplicationHelper | ||
366 | def current_theme | 367 | def current_theme |
367 | @current_theme ||= | 368 | @current_theme ||= |
368 | begin | 369 | begin |
369 | - if (session[:theme]) | 370 | + if ( respond_to?(:session) && session[:theme] ) || |
371 | + ( @controller && @controller.session[:theme] ) | ||
370 | session[:theme] | 372 | session[:theme] |
371 | else | 373 | else |
372 | # utility for developers: set the theme to 'random' in development mode and | 374 | # utility for developers: set the theme to 'random' in development mode and |
@@ -375,7 +377,7 @@ module ApplicationHelper | @@ -375,7 +377,7 @@ module ApplicationHelper | ||
375 | if ENV['RAILS_ENV'] == 'development' && environment.theme == 'random' | 377 | if ENV['RAILS_ENV'] == 'development' && environment.theme == 'random' |
376 | @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand | 378 | @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand |
377 | @random_theme | 379 | @random_theme |
378 | - elsif ENV['RAILS_ENV'] == 'development' && params[:theme] && File.exists?(File.join(Rails.root, 'public/designs/themes', params[:theme])) | 380 | + elsif ENV['RAILS_ENV'] == 'development' && respond_to?(:params) && params[:theme] && File.exists?(File.join(Rails.root, 'public/designs/themes', params[:theme])) |
379 | params[:theme] | 381 | params[:theme] |
380 | else | 382 | else |
381 | if profile && !profile.theme.nil? | 383 | if profile && !profile.theme.nil? |
@@ -600,15 +602,10 @@ module ApplicationHelper | @@ -600,15 +602,10 @@ module ApplicationHelper | ||
600 | 602 | ||
601 | def str_gravatar_url_for(email, options = {}) | 603 | def str_gravatar_url_for(email, options = {}) |
602 | default = theme_option['gravatar'] || NOOSFERO_CONF['gravatar'] || nil | 604 | default = theme_option['gravatar'] || NOOSFERO_CONF['gravatar'] || nil |
603 | - url = 'http://www.gravatar.com/avatar.php?gravatar_id=' + | ||
604 | - Digest::MD5.hexdigest(email.to_s) | ||
605 | - { | 605 | + "http://www.gravatar.com/avatar/#{Digest::MD5.hexdigest(email.to_s)}?" + { |
606 | :only_path => false, | 606 | :only_path => false, |
607 | :d => default | 607 | :d => default |
608 | - }.merge(options).each { |k,v| | ||
609 | - url += ( '&%s=%s' % [ k,v ] ) | ||
610 | - } | ||
611 | - url | 608 | + }.merge(options).map{|k,v| '%s=%s' % [ k,v ] }.join('&') |
612 | end | 609 | end |
613 | 610 | ||
614 | def gravatar_profile_url(email) | 611 | def gravatar_profile_url(email) |
app/models/user.rb
@@ -275,7 +275,10 @@ class User < ActiveRecord::Base | @@ -275,7 +275,10 @@ class User < ActiveRecord::Base | ||
275 | end | 275 | end |
276 | end | 276 | end |
277 | 277 | ||
278 | - def data_hash | 278 | + include ApplicationHelper |
279 | + | ||
280 | + def data_hash(controller=nil) | ||
281 | + @controller ||= controller | ||
279 | friends_list = {} | 282 | friends_list = {} |
280 | enterprises = person.enterprises.map { |e| { 'name' => e.short_name, 'identifier' => e.identifier } } | 283 | enterprises = person.enterprises.map { |e| { 'name' => e.short_name, 'identifier' => e.identifier } } |
281 | self.person.friends.online.map do |person| | 284 | self.person.friends.online.map do |person| |
@@ -286,9 +289,11 @@ class User < ActiveRecord::Base | @@ -286,9 +289,11 @@ class User < ActiveRecord::Base | ||
286 | 'status' => person.user.chat_status, | 289 | 'status' => person.user.chat_status, |
287 | } | 290 | } |
288 | end | 291 | end |
292 | + avatar = self.person.profile_custom_icon | ||
293 | + avatar = str_gravatar_url_for(self.email, :size=>20) if avatar.blank? | ||
289 | { | 294 | { |
290 | 'login' => self.login, | 295 | 'login' => self.login, |
291 | - 'avatar' => person.profile_custom_icon, | 296 | + 'avatar' => avatar, |
292 | 'is_admin' => self.person.is_admin?, | 297 | 'is_admin' => self.person.is_admin?, |
293 | 'since_month' => self.person.created_at.month, | 298 | 'since_month' => self.person.created_at.month, |
294 | 'since_year' => self.person.created_at.year, | 299 | 'since_year' => self.person.created_at.year, |