Patch #7664 » add-gravatars-like-themes.patch
| app/controllers/settings_controller.rb | ||
|---|---|---|
|
@guessed_host_and_path << ('/'+ Redmine::Utils.relative_url_root.gsub(%r{^\/}, '')) unless Redmine::Utils.relative_url_root.blank?
|
||
|
|
||
|
Redmine::Themes.rescan
|
||
|
Redmine::Gravatars.rescan
|
||
|
end
|
||
|
def plugin
|
||
| app/helpers/application_helper.rb | ||
|---|---|---|
|
# +user+ can be a User or a string that will be scanned for an email address (eg. 'joe <joe@foo.bar>')
|
||
|
def avatar(user, options = { })
|
||
|
if Setting.gravatar_enabled?
|
||
|
options.merge!({:ssl => (defined?(request) && request.ssl?), :default => Setting.gravatar_default})
|
||
|
default = Redmine::Gravatar.gravatar(Setting.gravatar_default)
|
||
|
options.merge!({:ssl => (defined?(request) && request.ssl?), :default => default})
|
||
|
email = nil
|
||
|
if user.respond_to?(:mail)
|
||
|
email = user.mail
|
||
| app/helpers/settings_helper.rb | ||
|---|---|---|
|
l_or_humanize(notifiable.name, :prefix => 'label_'),
|
||
|
:class => notifiable.parent.present? ? "parent" : '')
|
||
|
end
|
||
|
def options_for_gravatar_default
|
||
|
Redmine::Gravatars.gravatars
|
||
|
end
|
||
|
end
|
||
| app/views/settings/_display.rhtml | ||
|---|---|---|
|
<p><%= setting_check_box :gravatar_enabled %></p>
|
||
|
<p><%= setting_select :gravatar_default, [["Wavatars", 'wavatar'], ["Identicons", 'identicon'], ["Monster ids", 'monsterid'], ["Retro", "retro"]], :blank => :label_none %></p>
|
||
|
<p><%= setting_select :gravatar_default, options_for_gravatar_default, :blank => :label_none %></p>
|
||
|
</div>
|
||
|
<%= submit_tag l(:button_save) %>
|
||
| lib/redmine/gravatars.rb | ||
|---|---|---|
|
# redMine - project management software
|
||
|
# Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
module Redmine
|
||
|
module Gravatars
|
||
|
WELL_KNOWN_GRAVATARS = [["Wavatars", 'wavatar'], ["Identicons", 'identicon'], ["Monster ids", 'monsterid'], ["Retro", "retro"]]
|
||
|
# Return an array of installed gravatars
|
||
|
def self.gravatars
|
||
|
@@installed_gravatars ||= scan_gravatars
|
||
|
end
|
||
|
# Rescan gravatars directory
|
||
|
def self.rescan
|
||
|
@@installed_gravatars = scan_gravatars
|
||
|
end
|
||
|
# Return gravatar for given id, or nil if it's not found
|
||
|
def self.gravatar(id, options = {})
|
||
|
return nil if id.blank?
|
||
|
found = gravatars.find {|g| g.id == id}
|
||
|
if found.nil? && options[:rescan] != false
|
||
|
rescan
|
||
|
found = gravatar(id, :rescan => false)
|
||
|
end
|
||
|
found
|
||
|
end
|
||
|
# Class used to represent a gravatar
|
||
|
class Gravatar
|
||
|
include Comparable
|
||
|
def initialize(value)
|
||
|
@value = value
|
||
|
end
|
||
|
def label
|
||
|
value
|
||
|
end
|
||
|
def id
|
||
|
value
|
||
|
end
|
||
|
def <=>(g)
|
||
|
if Gravatar === g
|
||
|
self.id <=> g.id
|
||
|
else
|
||
|
nil
|
||
|
end
|
||
|
end
|
||
|
def to_api_option
|
||
|
"#{Setting.protocol}://#{Setting.host_name}/gravatars/#{value}"
|
||
|
end
|
||
|
private
|
||
|
attr_reader :value
|
||
|
end
|
||
|
class WellKnownGravatar < Gravatar
|
||
|
def initialize(label, value)
|
||
|
@label = label
|
||
|
super(value)
|
||
|
end
|
||
|
attr_reader :label
|
||
|
def to_api_option
|
||
|
value
|
||
|
end
|
||
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def self.scan_gravatars
|
||
|
found = Dir.glob("#{Rails.public_path}/gravatars/*").select{|f|
|
||
|
File.readable?(f)
|
||
|
}.map{|f|
|
||
|
Gravatar.new(File.basename(f))
|
||
|
}
|
||
|
WELL_KNOWN_GRAVATARS.map{|label, value|
|
||
|
WellKnownGravatar.new(label, value)
|
||
|
} + found
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| public/gravatars/.gitignore | ||
|---|---|---|
|
/*
|
||
|
!/.gitignore
|
||
| test/unit/lib/redmine/gravatars_test.rb | ||
|---|---|---|
|
# Redmine - project management software
|
||
|
# Copyright (C) 2006-2010 Jean-Philippe Lang
|
||
|
#
|
||
|
# This program is free software; you can redistribute it and/or
|
||
|
# modify it under the terms of the GNU General Public License
|
||
|
# as published by the Free Software Foundation; either version 2
|
||
|
# of the License, or (at your option) any later version.
|
||
|
#
|
||
|
# This program is distributed in the hope that it will be useful,
|
||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
# GNU General Public License for more details.
|
||
|
#
|
||
|
# You should have received a copy of the GNU General Public License
|
||
|
# along with this program; if not, write to the Free Software
|
||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
|
require File.expand_path('../../../../test_helper', __FILE__)
|
||
|
class Redmine::GravatarsTest < ActiveSupport::TestCase
|
||
|
def setup
|
||
|
Redmine::Gravatars.rescan
|
||
|
end
|
||
|
|
||
|
def test_gravatars
|
||
|
gravatars = Redmine::Gravatars.gravatars
|
||
|
assert_kind_of Array, gravatars
|
||
|
gravatars.each do |gravatar|
|
||
|
assert_kind_of Redmine::Gravatars::Gravatar, gravatar
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def test_rescan
|
||
|
Redmine::Gravatars.gravatars.pop
|
||
|
|
||
|
assert_difference 'Redmine::Gravatars.gravatars.size' do
|
||
|
Redmine::Gravatars.rescan
|
||
|
end
|
||
|
end
|
||
|
|
||
|
def test_gravatar_loaded
|
||
|
gravatar = Redmine::Gravatars.gravatars.last
|
||
|
|
||
|
assert_equal gravatar, Redmine::Gravatars.gravatar(gravatar.id)
|
||
|
end
|
||
|
|
||
|
def test_gravatar_loaded_without_rescan
|
||
|
gravatar = Redmine::Gravatars.gravatars.last
|
||
|
|
||
|
assert_equal gravatar, Redmine::Gravatars.gravatar(gravatar.id, :rescan => false)
|
||
|
end
|
||
|
|
||
|
def test_gravatar_not_loaded
|
||
|
gravatar = Redmine::Gravatars.gravatars.pop
|
||
|
|
||
|
assert_equal gravatar, Redmine::Gravatars.gravatar(gravatar.id)
|
||
|
end
|
||
|
|
||
|
def test_gravatar_not_loaded_without_rescan
|
||
|
gravatar = Redmine::Gravatars.gravatars.pop
|
||
|
|
||
|
assert_nil Redmine::Gravatars.gravatar(gravatar.id, :rescan => false)
|
||
|
end
|
||
|
end
|
||
- « Previous
- 1
- 2
- 3
- Next »