diff --git a/app/models/site_setting.rb b/app/models/site_setting.rb index 3d157a1a8..6396179a4 100644 --- a/app/models/site_setting.rb +++ b/app/models/site_setting.rb @@ -172,6 +172,8 @@ class SiteSetting < ActiveRecord::Base setting(:s3_region, '', enum: 'S3RegionSiteSetting') setting(:s3_upload_bucket, '') + setting(:enable_flash_video_onebox, false) + setting(:default_trust_level, 0) setting(:default_invitee_trust_level, 1) diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index faa881a9f..ae46c891f 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -583,6 +583,8 @@ en: s3_secret_access_key: "The Amazon S3 secret access key that will be used to upload images" s3_region: "The Amazon S3 region name that will be used to upload images" + enable_flash_video_onebox: "Enable embedding of swf and flv links in oneboxes (may introduce a security risk, caution advised)" + default_invitee_trust_level: "Default trust level (0-4) for invited users" default_trust_level: "Default trust level (0-4) for users" diff --git a/lib/oneboxer/flash_video_onebox.rb b/lib/oneboxer/flash_video_onebox.rb new file mode 100644 index 000000000..96555b1d7 --- /dev/null +++ b/lib/oneboxer/flash_video_onebox.rb @@ -0,0 +1,17 @@ +require_dependency 'oneboxer/base_onebox' + +module Oneboxer + class FlashVideoOnebox < BaseOnebox + + matcher /^https?:\/\/.*\.(swf|flv)$/ + + def onebox + if SiteSetting.enable_flash_video_onebox + "" + else + "#{@url}" + end + end + + end +end diff --git a/spec/components/oneboxer/flash_video_onebox_spec.rb b/spec/components/oneboxer/flash_video_onebox_spec.rb new file mode 100644 index 000000000..4bedd7409 --- /dev/null +++ b/spec/components/oneboxer/flash_video_onebox_spec.rb @@ -0,0 +1,33 @@ +require 'spec_helper' +require 'oneboxer' +require 'oneboxer/flash_video_onebox' + +describe Oneboxer::FlashVideoOnebox do + before do + @o = Oneboxer::FlashVideoOnebox.new('http://player.56.com/v_OTMyNTk1MzE.swf') + end + + context "when SiteSetting.enable_flash_video_onebox is true" do + before do + SiteSetting.stubs(:enable_flash_video_onebox).returns(true) + end + + it "generates a flash video" do + expect(@o.onebox).to match_html( + "" + ) + end + end + + context "when SiteSetting.enable_flash_video_onebox is false" do + before do + SiteSetting.stubs(:enable_flash_video_onebox).returns(false) + end + + it "generates a link" do + expect(@o.onebox).to match_html( + "http://player.56.com/v_OTMyNTk1MzE.swf" + ) + end + end +end