mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 06:23:43 +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) {
|
function defaultAvatar(username) {
|
||||||
const defaultAvatars = Discourse.SiteSettings.default_avatars;
|
const defaultAvatars = Discourse.SiteSettings.default_avatars;
|
||||||
|
|
||||||
if (defaultAvatars && defaultAvatars.length) {
|
if (defaultAvatars && defaultAvatars.length) {
|
||||||
_splitAvatars = _splitAvatars || defaultAvatars.split("\n");
|
_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/" +
|
||||||
return Discourse.getURLWithCDN(`/letter_avatar/${username.toLowerCase()}/{size}/${Discourse.LetterAvatarVersion}.${extension}`);
|
username.toLowerCase() +
|
||||||
|
"/{size}/" +
|
||||||
|
Discourse.LetterAvatarVersion + ".png");
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function(username, uploadedAvatarId) {
|
export default function(username, uploadedAvatarId) {
|
||||||
if (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);
|
return defaultAvatar(username);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ require_dependency 'letter_avatar'
|
||||||
class UserAvatarsController < ApplicationController
|
class UserAvatarsController < ApplicationController
|
||||||
DOT = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
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
|
def refresh_gravatar
|
||||||
user = User.find_by(username_lower: params[:username].downcase)
|
user = User.find_by(username_lower: params[:username].downcase)
|
||||||
|
@ -19,30 +19,6 @@ class UserAvatarsController < ApplicationController
|
||||||
end
|
end
|
||||||
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
|
def show_letter
|
||||||
params.require(:username)
|
params.require(:username)
|
||||||
params.require(:version)
|
params.require(:version)
|
||||||
|
|
|
@ -457,7 +457,7 @@ class User < ActiveRecord::Base
|
||||||
avatar_template = split_avatars[hash.abs % split_avatars.size]
|
avatar_template = split_avatars[hash.abs % split_avatars.size]
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
letter_avatar_template(username)
|
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.png"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -469,8 +469,7 @@ class User < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.letter_avatar_template(username)
|
def self.letter_avatar_template(username)
|
||||||
extension = SiteSetting.svg_letter_avatars ? "svg" : "png"
|
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.png"
|
||||||
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.#{extension}"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def avatar_template
|
def avatar_template
|
||||||
|
|
|
@ -979,8 +979,6 @@ en:
|
||||||
|
|
||||||
avatar_sizes: "List of automatically generated avatar sizes."
|
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."
|
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."
|
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}
|
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}
|
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 "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 }
|
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:
|
avatar_sizes:
|
||||||
default: '20|25|32|45|60|120'
|
default: '20|25|32|45|60|120'
|
||||||
type: list
|
type: list
|
||||||
svg_letter_avatars:
|
|
||||||
default: false
|
|
||||||
client: true
|
|
||||||
|
|
||||||
trust:
|
trust:
|
||||||
default_trust_level:
|
default_trust_level:
|
||||||
|
|
|
@ -30,6 +30,7 @@ module Email
|
||||||
|
|
||||||
# images
|
# images
|
||||||
@fragment.css('img').each do |img|
|
@fragment.css('img').each do |img|
|
||||||
|
|
||||||
next if img['class'] == 'site-logo'
|
next if img['class'] == 'site-logo'
|
||||||
|
|
||||||
if img['class'] == "emoji" || img['src'] =~ /plugins\/emoji/
|
if img['class'] == "emoji" || img['src'] =~ /plugins\/emoji/
|
||||||
|
@ -57,6 +58,7 @@ module Email
|
||||||
|
|
||||||
# attachments
|
# attachments
|
||||||
@fragment.css('a.attachment').each do |a|
|
@fragment.css('a.attachment').each do |a|
|
||||||
|
|
||||||
# ensure all urls are absolute
|
# ensure all urls are absolute
|
||||||
if a['href'] =~ /^\/[^\/]/
|
if a['href'] =~ /^\/[^\/]/
|
||||||
a['href'] = "#{Discourse.base_url}#{a['href']}"
|
a['href'] = "#{Discourse.base_url}#{a['href']}"
|
||||||
|
|
|
@ -7,6 +7,8 @@ class LetterAvatar
|
||||||
FULLSIZE = 120 * 3
|
FULLSIZE = 120 * 3
|
||||||
POINTSIZE = 280
|
POINTSIZE = 280
|
||||||
|
|
||||||
|
class << self
|
||||||
|
|
||||||
class Identity
|
class Identity
|
||||||
attr_accessor :color, :letter
|
attr_accessor :color, :letter
|
||||||
|
|
||||||
|
@ -20,8 +22,6 @@ class LetterAvatar
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class << self
|
|
||||||
|
|
||||||
def version
|
def version
|
||||||
"#{VERSION}_#{image_magick_version}"
|
"#{VERSION}_#{image_magick_version}"
|
||||||
end
|
end
|
||||||
|
@ -32,7 +32,7 @@ class LetterAvatar
|
||||||
|
|
||||||
def generate(username, size, opts = nil)
|
def generate(username, size, opts = nil)
|
||||||
DistributedMutex.synchronize("letter_avatar_#{version}_#{username}") do
|
DistributedMutex.synchronize("letter_avatar_#{version}_#{username}") do
|
||||||
identity = LetterAvatar::Identity.from_username(username)
|
identity = Identity.from_username(username)
|
||||||
|
|
||||||
cache = true
|
cache = true
|
||||||
cache = false if opts && opts[:cache] == false
|
cache = false if opts && opts[:cache] == false
|
||||||
|
|
Loading…
Reference in New Issue
Block a user