From e43034f08f2961ceddd3801efaca00c904c43d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Fri, 11 Sep 2015 00:23:52 +0200 Subject: [PATCH] Revert "FEATURE: SVG letter avatars (based on @eviltrout's spike)" This reverts commit cd774657889f38749a23f72d402835c57af8f60e. --- .../discourse/lib/avatar-template.js.es6 | 14 +++++++--- app/controllers/user_avatars_controller.rb | 26 +---------------- app/models/user.rb | 5 ++-- config/locales/server.en.yml | 2 -- config/routes.rb | 1 - config/site_settings.yml | 3 -- lib/email/styles.rb | 2 ++ lib/letter_avatar.rb | 28 +++++++++---------- 8 files changed, 29 insertions(+), 52 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/avatar-template.js.es6 b/app/assets/javascripts/discourse/lib/avatar-template.js.es6 index 15948aba2a6..542e9795961 100644 --- a/app/assets/javascripts/discourse/lib/avatar-template.js.es6 +++ b/app/assets/javascripts/discourse/lib/avatar-template.js.es6 @@ -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); } diff --git a/app/controllers/user_avatars_controller.rb b/app/controllers/user_avatars_controller.rb index f1d6e7d1db5..ed8f31e4af0 100644 --- a/app/controllers/user_avatars_controller.rb +++ b/app/controllers/user_avatars_controller.rb @@ -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 - - - #{username[0].capitalize} - - 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) diff --git a/app/models/user.rb b/app/models/user.rb index cd23445641f..2861fff881a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 921edd59ed4..fcd190dc8e4 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -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." diff --git a/config/routes.rb b/config/routes.rb index f5b5aa1b3db..66125570f49 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 } diff --git a/config/site_settings.yml b/config/site_settings.yml index 0c4950ad843..754e067b827 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -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: diff --git a/lib/email/styles.rb b/lib/email/styles.rb index e82106b96d1..22f9ffe1e89 100644 --- a/lib/email/styles.rb +++ b/lib/email/styles.rb @@ -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']}" diff --git a/lib/letter_avatar.rb b/lib/letter_avatar.rb index e49ab6c417a..abde76ec080 100644 --- a/lib/letter_avatar.rb +++ b/lib/letter_avatar.rb @@ -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