mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
FIX: Inline avatar style for onebox when embedding secure images (#11229)
When embedding secure images that are inline-avatars for oneboxes we weren't applying the correct sizing/style.
This commit is contained in:
@ -451,28 +451,36 @@ module PrettyText
|
||||
|
||||
width = img['width']
|
||||
height = img['height']
|
||||
oneboxed = img.ancestors.css(".onebox-body").any? || img.classes.include?("onebox-avatar")
|
||||
onebox_type = nil
|
||||
|
||||
if img.ancestors.css(".onebox-body").any?
|
||||
if img.classes.include?("onebox-avatar-inline")
|
||||
onebox_type = "avatar-inline"
|
||||
else
|
||||
onebox_type = "thumbnail"
|
||||
end
|
||||
end
|
||||
|
||||
# we always want this to be tiny and without any special styles
|
||||
if img.classes.include?('site-icon')
|
||||
oneboxed = false
|
||||
onebox_type = nil
|
||||
width = 16
|
||||
height = 16
|
||||
end
|
||||
|
||||
if Upload.secure_media_url?(url)
|
||||
img.add_next_sibling secure_media_placeholder(doc, url, oneboxed: oneboxed, width: width, height: height)
|
||||
img.add_next_sibling secure_media_placeholder(doc, url, onebox_type: onebox_type, width: width, height: height)
|
||||
img.remove
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.secure_media_placeholder(doc, url, oneboxed: false, width: nil, height: nil)
|
||||
def self.secure_media_placeholder(doc, url, onebox_type: false, width: nil, height: nil)
|
||||
data_width = width ? "data-width=#{width}" : ''
|
||||
data_height = height ? "data-height=#{height}" : ''
|
||||
data_oneboxed = oneboxed ? "data-oneboxed=true" : ''
|
||||
data_onebox_type = onebox_type ? "data-onebox-type='#{onebox_type}'" : ''
|
||||
<<~HTML
|
||||
<div class="secure-media-notice" data-stripped-secure-media="#{url}" #{data_oneboxed} #{data_width} #{data_height}>
|
||||
<div class="secure-media-notice" data-stripped-secure-media="#{url}" #{data_onebox_type} #{data_width} #{data_height}>
|
||||
#{I18n.t('emails.secure_media_placeholder')} <a class='stripped-secure-view-media' href="#{url}">#{I18n.t("emails.view_redacted_media")}</a>.
|
||||
</div>
|
||||
HTML
|
||||
|
Reference in New Issue
Block a user