Commit 630c8265456bed5ab2b3a00a80c236fd43fecdc8
1 parent
817df70a
Exists in
master
and in
29 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
app/helpers/application_helper.rb
| ... | ... | @@ -356,7 +356,8 @@ module ApplicationHelper |
| 356 | 356 | end |
| 357 | 357 | |
| 358 | 358 | def theme_path |
| 359 | - if session[:theme] | |
| 359 | + if ( respond_to?(:session) && session[:theme] ) || | |
| 360 | + ( @controller && @controller.session[:theme] ) | |
| 360 | 361 | '/user_themes/' + current_theme |
| 361 | 362 | else |
| 362 | 363 | '/designs/themes/' + current_theme |
| ... | ... | @@ -366,7 +367,8 @@ module ApplicationHelper |
| 366 | 367 | def current_theme |
| 367 | 368 | @current_theme ||= |
| 368 | 369 | begin |
| 369 | - if (session[:theme]) | |
| 370 | + if ( respond_to?(:session) && session[:theme] ) || | |
| 371 | + ( @controller && @controller.session[:theme] ) | |
| 370 | 372 | session[:theme] |
| 371 | 373 | else |
| 372 | 374 | # utility for developers: set the theme to 'random' in development mode and |
| ... | ... | @@ -375,7 +377,7 @@ module ApplicationHelper |
| 375 | 377 | if ENV['RAILS_ENV'] == 'development' && environment.theme == 'random' |
| 376 | 378 | @random_theme ||= Dir.glob('public/designs/themes/*').map { |f| File.basename(f) }.rand |
| 377 | 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 | 381 | params[:theme] |
| 380 | 382 | else |
| 381 | 383 | if profile && !profile.theme.nil? |
| ... | ... | @@ -600,15 +602,10 @@ module ApplicationHelper |
| 600 | 602 | |
| 601 | 603 | def str_gravatar_url_for(email, options = {}) |
| 602 | 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 | 606 | :only_path => false, |
| 607 | 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 | 609 | end |
| 613 | 610 | |
| 614 | 611 | def gravatar_profile_url(email) | ... | ... |
app/models/user.rb
| ... | ... | @@ -275,7 +275,10 @@ class User < ActiveRecord::Base |
| 275 | 275 | end |
| 276 | 276 | end |
| 277 | 277 | |
| 278 | - def data_hash | |
| 278 | + include ApplicationHelper | |
| 279 | + | |
| 280 | + def data_hash(controller=nil) | |
| 281 | + @controller ||= controller | |
| 279 | 282 | friends_list = {} |
| 280 | 283 | enterprises = person.enterprises.map { |e| { 'name' => e.short_name, 'identifier' => e.identifier } } |
| 281 | 284 | self.person.friends.online.map do |person| |
| ... | ... | @@ -286,9 +289,11 @@ class User < ActiveRecord::Base |
| 286 | 289 | 'status' => person.user.chat_status, |
| 287 | 290 | } |
| 288 | 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 | 295 | 'login' => self.login, |
| 291 | - 'avatar' => person.profile_custom_icon, | |
| 296 | + 'avatar' => avatar, | |
| 292 | 297 | 'is_admin' => self.person.is_admin?, |
| 293 | 298 | 'since_month' => self.person.created_at.month, |
| 294 | 299 | 'since_year' => self.person.created_at.year, | ... | ... |