2014-06-13 10:11:46 -04:00
|
|
|
class GravatarService
|
2015-01-08 12:53:35 -05:00
|
|
|
include Gitlab::CurrentSettings
|
|
|
|
|
2017-05-26 11:56:08 -04:00
|
|
|
def execute(email, size = nil, scale = 2, username: nil)
|
|
|
|
return unless current_application_settings.gravatar_enabled?
|
2014-06-13 10:11:46 -04:00
|
|
|
|
2017-05-26 11:56:08 -04:00
|
|
|
identifier = email.presence || username.presence
|
|
|
|
return unless identifier
|
|
|
|
|
|
|
|
hash = Digest::MD5.hexdigest(identifier.strip.downcase)
|
|
|
|
size = 40 unless size && size > 0
|
|
|
|
|
|
|
|
sprintf gravatar_url,
|
|
|
|
hash: hash,
|
|
|
|
size: size * scale,
|
|
|
|
email: ERB::Util.url_encode(email&.strip || ''),
|
|
|
|
username: ERB::Util.url_encode(username&.strip || '')
|
2014-06-13 10:11:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gitlab_config
|
|
|
|
Gitlab.config.gitlab
|
|
|
|
end
|
|
|
|
|
|
|
|
def gravatar_config
|
|
|
|
Gitlab.config.gravatar
|
|
|
|
end
|
|
|
|
|
|
|
|
def gravatar_url
|
|
|
|
if gitlab_config.https
|
|
|
|
gravatar_config.ssl_url
|
|
|
|
else
|
|
|
|
gravatar_config.plain_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|