From b0405d7cfad736385c8eb0a654c7e751dda11493 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 9 Apr 2014 16:57:45 -0400 Subject: [PATCH] Adds a Site Setting to whitelist onebox domains --- config/locales/client.en.yml | 1 + config/locales/server.en.yml | 1 + config/site_settings.yml | 9 +++++++-- lib/oneboxer.rb | 14 ++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 89ef0ee58ca..f14463be6a8 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1682,6 +1682,7 @@ en: files: 'Files' trust: 'Trust Levels' security: 'Security' + onebox: "Onebox" seo: 'SEO' spam: 'Spam' rate_limits: 'Rate Limits' diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 691a4515379..9856f1e4644 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -610,6 +610,7 @@ en: post_excerpt_maxlength: "Maximum length in chars of a post's excerpt" post_onebox_maxlength: "Maximum length of a oneboxed Discourse post" + onebox_domains_whitelist: "A list of domains to whitelist for oneboxing. (Example: eviltrout.com)" category_post_template: "The post template used when you create a new category" logo_url: "The logo for your site eg: http://example.com/logo.png" diff --git a/config/site_settings.yml b/config/site_settings.yml index d5f32d6009d..a4e1b32ba0d 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -228,7 +228,6 @@ posting: default: -1 hidden: true post_excerpt_maxlength: 300 - post_onebox_maxlength: 500 display_name_on_posts: client: true default: false @@ -336,12 +335,18 @@ trust: regular_requires_topic_reply_count: 3 security: - enable_flash_video_onebox: false use_https: false enable_escaped_fragments: true allow_index_in_robots_txt: true enable_noscript_support: true +onebox: + enable_flash_video_onebox: false + post_onebox_maxlength: 500 + onebox_domains_whitelist: + default: '' + list: true + spam: add_rel_nofollow_to_user_content: true exclude_rel_nofollow_domains: diff --git a/lib/oneboxer.rb b/lib/oneboxer.rb index 72ffbba3d8e..7930cd4b5a8 100644 --- a/lib/oneboxer.rb +++ b/lib/oneboxer.rb @@ -99,9 +99,23 @@ module Oneboxer "onebox__#{url}" end + def self.add_discourse_whitelists + # Add custom domain whitelists + if SiteSetting.onebox_domains_whitelist.present? + domains = SiteSetting.onebox_domains_whitelist.split('|') + whitelist = Onebox::Engine::WhitelistedGenericOnebox.whitelist + whitelist.concat(domains) + whitelist.uniq! + end + end + def self.onebox_raw(url) Rails.cache.fetch(onebox_cache_key(url)){ begin + + # This might be able to move to whenever the SiteSetting changes? + Oneboxer.add_discourse_whitelists + r = Onebox.preview(url, cache: {}) { onebox: r.to_s,