mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 02:13:47 +08:00
Revert "FEATURE: SVG letter avatars (based on @eviltrout's spike)"
This reverts commit cd77465788
.
This commit is contained in:
parent
cd77465788
commit
e43034f08f
|
@ -4,7 +4,6 @@ let _splitAvatars;
|
|||
|
||||
function defaultAvatar(username) {
|
||||
const defaultAvatars = Discourse.SiteSettings.default_avatars;
|
||||
|
||||
if (defaultAvatars && defaultAvatars.length) {
|
||||
_splitAvatars = _splitAvatars || defaultAvatars.split("\n");
|
||||
|
||||
|
@ -14,13 +13,20 @@ function defaultAvatar(username) {
|
|||
}
|
||||
}
|
||||
|
||||
const extension = Discourse.SiteSettings.svg_letter_avatars ? "svg" : "png";
|
||||
return Discourse.getURLWithCDN(`/letter_avatar/${username.toLowerCase()}/{size}/${Discourse.LetterAvatarVersion}.${extension}`);
|
||||
return Discourse.getURLWithCDN("/letter_avatar/" +
|
||||
username.toLowerCase() +
|
||||
"/{size}/" +
|
||||
Discourse.LetterAvatarVersion + ".png");
|
||||
}
|
||||
|
||||
export default function(username, uploadedAvatarId) {
|
||||
if (uploadedAvatarId) {
|
||||
return Discourse.getURLWithCDN(`/user_avatar/${Discourse.BaseUrl}/${username.toLowerCase()}/{size}/${uploadedAvatarId}.png`);
|
||||
return Discourse.getURLWithCDN("/user_avatar/" +
|
||||
Discourse.BaseUrl +
|
||||
"/" +
|
||||
username.toLowerCase() +
|
||||
"/{size}/" +
|
||||
uploadedAvatarId + ".png");
|
||||
}
|
||||
return defaultAvatar(username);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ require_dependency 'letter_avatar'
|
|||
class UserAvatarsController < ApplicationController
|
||||
DOT = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
||||
|
||||
skip_before_filter :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter, :show_letter_svg]
|
||||
skip_before_filter :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :show_letter]
|
||||
|
||||
def refresh_gravatar
|
||||
user = User.find_by(username_lower: params[:username].downcase)
|
||||
|
@ -19,30 +19,6 @@ class UserAvatarsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def show_letter_svg
|
||||
params.require(:username)
|
||||
params.require(:version)
|
||||
params.require(:size)
|
||||
|
||||
no_cookies
|
||||
|
||||
size = params[:size].to_i
|
||||
username = params[:username]
|
||||
|
||||
identity = LetterAvatar::Identity.from_username(username)
|
||||
color = identity.color
|
||||
|
||||
svg = <<-SVG
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="#{size}" height="#{size}">
|
||||
<rect width="100%" height="100%" fill="rgb(#{color[0]},#{color[1]},#{color[2]})" />
|
||||
<text font-size="#{size * 0.7}" font-weight="normal" font-family="Helvetica, sans-serif" fill="#FFF" fill-opacity=".8" text-anchor="middle" x="50%" y="75%">#{username[0].capitalize}</text>
|
||||
</svg>
|
||||
SVG
|
||||
|
||||
expires_in 1.year, public: true
|
||||
render inline: svg, content_type: "image/svg+xml"
|
||||
end
|
||||
|
||||
def show_letter
|
||||
params.require(:username)
|
||||
params.require(:version)
|
||||
|
|
|
@ -457,7 +457,7 @@ class User < ActiveRecord::Base
|
|||
avatar_template = split_avatars[hash.abs % split_avatars.size]
|
||||
end
|
||||
else
|
||||
letter_avatar_template(username)
|
||||
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.png"
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -469,8 +469,7 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.letter_avatar_template(username)
|
||||
extension = SiteSetting.svg_letter_avatars ? "svg" : "png"
|
||||
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.#{extension}"
|
||||
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.png"
|
||||
end
|
||||
|
||||
def avatar_template
|
||||
|
|
|
@ -979,8 +979,6 @@ en:
|
|||
|
||||
avatar_sizes: "List of automatically generated avatar sizes."
|
||||
|
||||
svg_letter_avatars: "Use SVG for letter avatars"
|
||||
|
||||
enable_flash_video_onebox: "Enable embedding of swf and flv (Adobe Flash) links in oneboxes. WARNING: may introduce security risks."
|
||||
|
||||
default_invitee_trust_level: "Default trust level (0-4) for invited users."
|
||||
|
|
|
@ -299,7 +299,6 @@ Discourse::Application.routes.draw do
|
|||
get "user-badges/:username" => "user_badges#username", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
|
||||
post "user_avatar/:username/refresh_gravatar" => "user_avatars#refresh_gravatar", constraints: {username: USERNAME_ROUTE_FORMAT}
|
||||
get "letter_avatar/:username/:size/:version.svg" => "user_avatars#show_letter_svg", format: :svg, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: USERNAME_ROUTE_FORMAT}
|
||||
get "letter_avatar/:username/:size/:version.png" => "user_avatars#show_letter", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: USERNAME_ROUTE_FORMAT}
|
||||
get "user_avatar/:hostname/:username/:size/:version.png" => "user_avatars#show", format: false, constraints: { hostname: /[\w\.-]+/, size: /\d+/, username: USERNAME_ROUTE_FORMAT }
|
||||
|
||||
|
|
|
@ -572,9 +572,6 @@ files:
|
|||
avatar_sizes:
|
||||
default: '20|25|32|45|60|120'
|
||||
type: list
|
||||
svg_letter_avatars:
|
||||
default: false
|
||||
client: true
|
||||
|
||||
trust:
|
||||
default_trust_level:
|
||||
|
|
|
@ -30,6 +30,7 @@ module Email
|
|||
|
||||
# images
|
||||
@fragment.css('img').each do |img|
|
||||
|
||||
next if img['class'] == 'site-logo'
|
||||
|
||||
if img['class'] == "emoji" || img['src'] =~ /plugins\/emoji/
|
||||
|
@ -57,6 +58,7 @@ module Email
|
|||
|
||||
# attachments
|
||||
@fragment.css('a.attachment').each do |a|
|
||||
|
||||
# ensure all urls are absolute
|
||||
if a['href'] =~ /^\/[^\/]/
|
||||
a['href'] = "#{Discourse.base_url}#{a['href']}"
|
||||
|
|
|
@ -7,21 +7,21 @@ class LetterAvatar
|
|||
FULLSIZE = 120 * 3
|
||||
POINTSIZE = 280
|
||||
|
||||
class Identity
|
||||
attr_accessor :color, :letter
|
||||
|
||||
def self.from_username(username)
|
||||
identity = new
|
||||
identity.color = LetterAvatar::COLORS[
|
||||
Digest::MD5.hexdigest(username)[0...15].to_i(16) % LetterAvatar::COLORS.length
|
||||
]
|
||||
identity.letter = username[0].upcase
|
||||
identity
|
||||
end
|
||||
end
|
||||
|
||||
class << self
|
||||
|
||||
class Identity
|
||||
attr_accessor :color, :letter
|
||||
|
||||
def self.from_username(username)
|
||||
identity = new
|
||||
identity.color = LetterAvatar::COLORS[
|
||||
Digest::MD5.hexdigest(username)[0...15].to_i(16) % LetterAvatar::COLORS.length
|
||||
]
|
||||
identity.letter = username[0].upcase
|
||||
identity
|
||||
end
|
||||
end
|
||||
|
||||
def version
|
||||
"#{VERSION}_#{image_magick_version}"
|
||||
end
|
||||
|
@ -32,7 +32,7 @@ class LetterAvatar
|
|||
|
||||
def generate(username, size, opts = nil)
|
||||
DistributedMutex.synchronize("letter_avatar_#{version}_#{username}") do
|
||||
identity = LetterAvatar::Identity.from_username(username)
|
||||
identity = Identity.from_username(username)
|
||||
|
||||
cache = true
|
||||
cache = false if opts && opts[:cache] == false
|
||||
|
|
Loading…
Reference in New Issue
Block a user