Commit 57338c4f4d287bb7e99ff70bb13e66b2c44db8b0
1 parent
df7f320c
Exists in
staging
and in
4 other branches
Using plugin namespace on video_plugin models
Showing
14 changed files
with
331 additions
and
333 deletions
Show diff stats
plugins/video/lib/ext/article.rb
| ... | ... | @@ -2,10 +2,12 @@ require_dependency 'article' |
| 2 | 2 | |
| 3 | 3 | class Article |
| 4 | 4 | |
| 5 | + #FIXME This should be done via hotspot | |
| 5 | 6 | def self.folder_types_with_video |
| 6 | - self.folder_types_without_video << 'VideoGallery' | |
| 7 | + self.folder_types_without_video << 'VideoPugin::VideoGallery' | |
| 7 | 8 | end |
| 8 | 9 | |
| 10 | + #FIXME This should be done via hotspot | |
| 9 | 11 | class << self |
| 10 | 12 | alias_method_chain :folder_types, :video |
| 11 | 13 | end | ... | ... |
plugins/video/lib/video.rb
| ... | ... | @@ -1,145 +0,0 @@ |
| 1 | -require 'noosfero/translatable_content' | |
| 2 | -require 'application_helper' | |
| 3 | -require 'net/http' | |
| 4 | - | |
| 5 | -class Video < Article | |
| 6 | - | |
| 7 | - settings_items :video_url, :type => :string, :default => 'http://' | |
| 8 | - settings_items :video_width, :type => :integer, :default => 499 | |
| 9 | - settings_items :video_height, :type => :integer, :default => 353 | |
| 10 | - #youtube, vimeo, file | |
| 11 | - settings_items :video_provider, :type => :string | |
| 12 | - settings_items :video_format, :type => :string | |
| 13 | - settings_items :video_id, :type => :string | |
| 14 | - settings_items :video_thumbnail_url, :type => :string, :default => '/plugins/video/images/video_generic_thumbnail.jpg' | |
| 15 | - settings_items :video_thumbnail_width, :type=> :integer | |
| 16 | - settings_items :video_thumbnail_height, :type=> :integer | |
| 17 | - settings_items :video_duration, :type=> :integer, :default => 0 | |
| 18 | - | |
| 19 | - attr_accessible :video_url | |
| 20 | - | |
| 21 | - before_save :detect_video | |
| 22 | - | |
| 23 | - def self.type_name | |
| 24 | - _('Video') | |
| 25 | - end | |
| 26 | - | |
| 27 | - def can_display_versions? | |
| 28 | - true | |
| 29 | - end | |
| 30 | - | |
| 31 | - def self.short_description | |
| 32 | - _('Embedded Video') | |
| 33 | - end | |
| 34 | - | |
| 35 | - def self.description | |
| 36 | - _('Display embedded videos.') | |
| 37 | - end | |
| 38 | - | |
| 39 | - include ActionView::Helpers::TagHelper | |
| 40 | - def to_html(options={}) | |
| 41 | - article = self | |
| 42 | - proc do | |
| 43 | - render :partial => 'content_viewer/video', :locals => {:article => article} | |
| 44 | - end | |
| 45 | - end | |
| 46 | - | |
| 47 | - def fitted_width | |
| 48 | - 499 | |
| 49 | - end | |
| 50 | - | |
| 51 | - def fitted_height | |
| 52 | - ((fitted_width * self.video_height) / self.video_width).to_i | |
| 53 | - end | |
| 54 | - | |
| 55 | - def thumbnail_fitted_width | |
| 56 | - 80 | |
| 57 | - end | |
| 58 | - | |
| 59 | - def thumbnail_fitted_height | |
| 60 | - ((thumbnail_fitted_width * self.video_thumbnail_height) / self.video_thumbnail_width).to_i | |
| 61 | - end | |
| 62 | - | |
| 63 | - def no_browser_support_message | |
| 64 | - '<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>' | |
| 65 | - end | |
| 66 | - | |
| 67 | - private | |
| 68 | - | |
| 69 | - YOUTUBE_ID_FORMAT = '\w-' | |
| 70 | - | |
| 71 | - def detect_video | |
| 72 | - if is_youtube? | |
| 73 | - self.video_provider = 'youtube' | |
| 74 | - self.video_id = extract_youtube_id | |
| 75 | - url = "http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D#{self.video_id}&format=json" | |
| 76 | - resp = Net::HTTP.get_response(URI.parse(url)) | |
| 77 | - buffer = resp.body | |
| 78 | - vid = JSON.parse(buffer) | |
| 79 | - self.video_thumbnail_url = vid['thumbnail_url'] | |
| 80 | - self.video_width = vid['width'] | |
| 81 | - self.video_height = vid['height'] | |
| 82 | - self.video_thumbnail_width = vid['thumbnail_width'] | |
| 83 | - self.video_thumbnail_height = vid['thumbnail_height'] | |
| 84 | - url = "http://gdata.youtube.com/feeds/api/videos/#{self.video_id}?alt=json"; | |
| 85 | - resp = Net::HTTP.get_response(URI.parse(url)) | |
| 86 | - buffer = resp.body | |
| 87 | - vid = JSON.parse(buffer) | |
| 88 | - self.video_duration = vid['entry']['media$group']['media$content'][0]['duration'] | |
| 89 | - elsif is_vimeo? | |
| 90 | - self.video_provider = 'vimeo' | |
| 91 | - self.video_id = extract_vimeo_id | |
| 92 | - url = "http://vimeo.com/api/v2/video/#{self.video_id}.json" | |
| 93 | - resp = Net::HTTP.get_response(URI.parse(url)) | |
| 94 | - buffer = resp.body | |
| 95 | - vid = JSON.parse(buffer) | |
| 96 | - vid = vid[0] | |
| 97 | - #raise vid.to_yaml | |
| 98 | - self.video_thumbnail_url = vid['thumbnail_large'] | |
| 99 | - self.video_width = vid['width'] | |
| 100 | - self.video_height = vid['height'] | |
| 101 | - self.video_thumbnail_width = 640 | |
| 102 | - self.video_thumbnail_height = 360 | |
| 103 | - elsif true | |
| 104 | - self.video_format = detect_format | |
| 105 | - self.video_provider = 'file' | |
| 106 | - end | |
| 107 | - end | |
| 108 | - | |
| 109 | - def detect_format | |
| 110 | - video_type = 'video/unknown' | |
| 111 | - if /.mp4/i =~ self.video_url or /.mov/i =~ self.video_url | |
| 112 | - video_type='video/mp4' | |
| 113 | - elsif /.webm/i =~ self.video_url | |
| 114 | - video_type='video/webm' | |
| 115 | - elsif /.og[vg]/i =~ self.video_url | |
| 116 | - video_type='video/ogg' | |
| 117 | - end | |
| 118 | - video_type | |
| 119 | - end | |
| 120 | - | |
| 121 | - def is_youtube? | |
| 122 | - video_url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false | |
| 123 | - end | |
| 124 | - | |
| 125 | - def is_vimeo? | |
| 126 | - video_url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/([A-z]|\/)*[[:digit:]]+/) ? true : false | |
| 127 | - end | |
| 128 | - | |
| 129 | - def is_video_file? | |
| 130 | - video_url.match(/\.(mp4|ogg|ogv|webm)/) ? true : false | |
| 131 | - end | |
| 132 | - | |
| 133 | - def extract_youtube_id | |
| 134 | - return nil unless is_youtube? | |
| 135 | - youtube_match = video_url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") | |
| 136 | - youtube_match ||= video_url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") | |
| 137 | - youtube_match[1] unless youtube_match.nil? | |
| 138 | - end | |
| 139 | - | |
| 140 | - def extract_vimeo_id | |
| 141 | - return nil unless is_vimeo? | |
| 142 | - vimeo_match = video_url.match('([[:digit:]]*)$') | |
| 143 | - vimeo_match[1] unless vimeo_match.nil? | |
| 144 | - end | |
| 145 | -end | |
| 146 | 0 | \ No newline at end of file |
plugins/video/lib/video_block.rb
| ... | ... | @@ -1,62 +0,0 @@ |
| 1 | -class VideoBlock < Block | |
| 2 | - | |
| 3 | - attr_accessible :url, :width, :height | |
| 4 | - | |
| 5 | - settings_items :url, :type => :string, :default => "" | |
| 6 | - settings_items :width, :type => :integer, :default => 400 | |
| 7 | - settings_items :height, :type => :integer, :default => 315 | |
| 8 | - | |
| 9 | - YOUTUBE_ID_FORMAT = '\w-' | |
| 10 | - | |
| 11 | - def is_youtube? | |
| 12 | - url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false | |
| 13 | - end | |
| 14 | - | |
| 15 | - def is_vimeo? | |
| 16 | - url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]+/) ? true : false | |
| 17 | - end | |
| 18 | - | |
| 19 | - def is_video_file? | |
| 20 | - url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false | |
| 21 | - end | |
| 22 | - | |
| 23 | - def format_embed_video_url_for_youtube | |
| 24 | - "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" if is_youtube? | |
| 25 | - end | |
| 26 | - | |
| 27 | - def format_embed_video_url_for_vimeo | |
| 28 | - "//player.vimeo.com/video/#{extract_vimeo_id}" if is_vimeo? | |
| 29 | - end | |
| 30 | - | |
| 31 | - def self.description | |
| 32 | - _('Display a Video') | |
| 33 | - end | |
| 34 | - | |
| 35 | - def help | |
| 36 | - _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') | |
| 37 | - end | |
| 38 | - | |
| 39 | - def content(args={}) | |
| 40 | - block = self | |
| 41 | - | |
| 42 | - proc do | |
| 43 | - render :file => 'video_block', :locals => { :block => block } | |
| 44 | - end | |
| 45 | - end | |
| 46 | - | |
| 47 | - private | |
| 48 | - | |
| 49 | - def extract_youtube_id | |
| 50 | - return nil unless is_youtube? | |
| 51 | - youtube_match = url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") | |
| 52 | - youtube_match ||= url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") | |
| 53 | - youtube_match[1] unless youtube_match.nil? | |
| 54 | - end | |
| 55 | - | |
| 56 | - def extract_vimeo_id | |
| 57 | - return nil unless is_vimeo? | |
| 58 | - vimeo_match = url.match('([[:digit:]]*)$') | |
| 59 | - vimeo_match[1] unless vimeo_match.nil? | |
| 60 | - end | |
| 61 | - | |
| 62 | -end |
plugins/video/lib/video_gallery.rb
| ... | ... | @@ -1,63 +0,0 @@ |
| 1 | -class VideoGallery < Folder | |
| 2 | - | |
| 3 | - def self.type_name | |
| 4 | - _('Video Gallery') | |
| 5 | - end | |
| 6 | - | |
| 7 | - settings_items :thumbnail_width, :type => :integer, :default => 50 | |
| 8 | - settings_items :thumbnail_height, :type => :integer, :default => 50 | |
| 9 | - settings_items :videos_per_row, :type => :integer, :default => 5 | |
| 10 | - | |
| 11 | - validate :not_belong_to_blog | |
| 12 | - | |
| 13 | - def not_belong_to_blog | |
| 14 | - errors.add(:parent, "A video gallery should not belong to a blog.") if parent && parent.blog? | |
| 15 | - end | |
| 16 | - | |
| 17 | - acts_as_having_settings :field => :setting | |
| 18 | - | |
| 19 | - xss_terminate :only => [ :body ], :with => 'white_list', :on => 'validation' | |
| 20 | - | |
| 21 | - include WhiteListFilter | |
| 22 | - filter_iframes :body | |
| 23 | - def iframe_whitelist | |
| 24 | - profile && profile.environment && profile.environment.trusted_sites_for_iframe | |
| 25 | - end | |
| 26 | - | |
| 27 | - def self.short_description | |
| 28 | - _('Video Gallery') | |
| 29 | - end | |
| 30 | - | |
| 31 | - def self.description | |
| 32 | - _('A gallery of link to videos that are hosted elsewhere.') | |
| 33 | - end | |
| 34 | - | |
| 35 | - include ActionView::Helpers::TagHelper | |
| 36 | - def to_html(options = {}) | |
| 37 | - video_gallery = self | |
| 38 | - proc do | |
| 39 | - render :partial => 'content_viewer/video_gallery', :locals => {:video_gallery => video_gallery} | |
| 40 | - end | |
| 41 | - end | |
| 42 | - | |
| 43 | - def video_gallery? | |
| 44 | - true | |
| 45 | - end | |
| 46 | - | |
| 47 | - def can_display_hits? | |
| 48 | - false | |
| 49 | - end | |
| 50 | - | |
| 51 | - def accept_comments? | |
| 52 | - false | |
| 53 | - end | |
| 54 | - | |
| 55 | - def self.icon_name(article = nil) | |
| 56 | - 'Video gallery' | |
| 57 | - end | |
| 58 | - | |
| 59 | - def news(limit = 30, highlight = false) | |
| 60 | - profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) | |
| 61 | - end | |
| 62 | - | |
| 63 | -end |
plugins/video/lib/video_gallery_helper.rb
| ... | ... | @@ -1,18 +0,0 @@ |
| 1 | -module VideoGalleryHelper | |
| 2 | - | |
| 3 | - def list_videos(configure={}) | |
| 4 | - configure[:recursive] ||= false | |
| 5 | - configure[:list_type] ||= :folder | |
| 6 | - if !configure[:contents].blank? | |
| 7 | - configure[:contents] = configure[:contents].paginate( | |
| 8 | - :order => "updated_at DESC", | |
| 9 | - :per_page => 16, | |
| 10 | - :page => params[:npage] | |
| 11 | - ) | |
| 12 | - render :file => 'shared/video_list', :locals => configure | |
| 13 | - else | |
| 14 | - content_tag('em', _('(empty folder)')) | |
| 15 | - end | |
| 16 | - end | |
| 17 | - | |
| 18 | -end | |
| 19 | 0 | \ No newline at end of file |
plugins/video/lib/video_plugin.rb
| 1 | -require_dependency File.dirname(__FILE__) + '/video_block' | |
| 2 | -require_dependency File.dirname(__FILE__) + '/video' | |
| 3 | -require_dependency File.dirname(__FILE__) + '/video_gallery' | |
| 4 | - | |
| 5 | 1 | class VideoPlugin < Noosfero::Plugin |
| 6 | 2 | |
| 7 | 3 | def self.plugin_name |
| ... | ... | @@ -14,7 +10,7 @@ class VideoPlugin < Noosfero::Plugin |
| 14 | 10 | |
| 15 | 11 | def self.extra_blocks |
| 16 | 12 | { |
| 17 | - VideoBlock => {} | |
| 13 | + VideoPlugin::VideoBlock => {} | |
| 18 | 14 | } |
| 19 | 15 | end |
| 20 | 16 | ... | ... |
| ... | ... | @@ -0,0 +1,145 @@ |
| 1 | +require 'noosfero/translatable_content' | |
| 2 | +require 'application_helper' | |
| 3 | +require 'net/http' | |
| 4 | + | |
| 5 | +class VideoPlugin::Video < Article | |
| 6 | + | |
| 7 | + settings_items :video_url, :type => :string, :default => 'http://' | |
| 8 | + settings_items :video_width, :type => :integer, :default => 499 | |
| 9 | + settings_items :video_height, :type => :integer, :default => 353 | |
| 10 | + #youtube, vimeo, file | |
| 11 | + settings_items :video_provider, :type => :string | |
| 12 | + settings_items :video_format, :type => :string | |
| 13 | + settings_items :video_id, :type => :string | |
| 14 | + settings_items :video_thumbnail_url, :type => :string, :default => '/plugins/video/images/video_generic_thumbnail.jpg' | |
| 15 | + settings_items :video_thumbnail_width, :type=> :integer | |
| 16 | + settings_items :video_thumbnail_height, :type=> :integer | |
| 17 | + settings_items :video_duration, :type=> :integer, :default => 0 | |
| 18 | + | |
| 19 | + attr_accessible :video_url | |
| 20 | + | |
| 21 | + before_save :detect_video | |
| 22 | + | |
| 23 | + def self.type_name | |
| 24 | + _('Video') | |
| 25 | + end | |
| 26 | + | |
| 27 | + def can_display_versions? | |
| 28 | + true | |
| 29 | + end | |
| 30 | + | |
| 31 | + def self.short_description | |
| 32 | + _('Embedded Video') | |
| 33 | + end | |
| 34 | + | |
| 35 | + def self.description | |
| 36 | + _('Display embedded videos.') | |
| 37 | + end | |
| 38 | + | |
| 39 | + include ActionView::Helpers::TagHelper | |
| 40 | + def to_html(options={}) | |
| 41 | + article = self | |
| 42 | + proc do | |
| 43 | + render :partial => 'content_viewer/video', :locals => {:article => article} | |
| 44 | + end | |
| 45 | + end | |
| 46 | + | |
| 47 | + def fitted_width | |
| 48 | + 499 | |
| 49 | + end | |
| 50 | + | |
| 51 | + def fitted_height | |
| 52 | + ((fitted_width * self.video_height) / self.video_width).to_i | |
| 53 | + end | |
| 54 | + | |
| 55 | + def thumbnail_fitted_width | |
| 56 | + 80 | |
| 57 | + end | |
| 58 | + | |
| 59 | + def thumbnail_fitted_height | |
| 60 | + ((thumbnail_fitted_width * self.video_thumbnail_height) / self.video_thumbnail_width).to_i | |
| 61 | + end | |
| 62 | + | |
| 63 | + def no_browser_support_message | |
| 64 | + '<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>' | |
| 65 | + end | |
| 66 | + | |
| 67 | + private | |
| 68 | + | |
| 69 | + YOUTUBE_ID_FORMAT = '\w-' | |
| 70 | + | |
| 71 | + def detect_video | |
| 72 | + if is_youtube? | |
| 73 | + self.video_provider = 'youtube' | |
| 74 | + self.video_id = extract_youtube_id | |
| 75 | + url = "http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D#{self.video_id}&format=json" | |
| 76 | + resp = Net::HTTP.get_response(URI.parse(url)) | |
| 77 | + buffer = resp.body | |
| 78 | + vid = JSON.parse(buffer) | |
| 79 | + self.video_thumbnail_url = vid['thumbnail_url'] | |
| 80 | + self.video_width = vid['width'] | |
| 81 | + self.video_height = vid['height'] | |
| 82 | + self.video_thumbnail_width = vid['thumbnail_width'] | |
| 83 | + self.video_thumbnail_height = vid['thumbnail_height'] | |
| 84 | + url = "http://gdata.youtube.com/feeds/api/videos/#{self.video_id}?alt=json"; | |
| 85 | + resp = Net::HTTP.get_response(URI.parse(url)) | |
| 86 | + buffer = resp.body | |
| 87 | + vid = JSON.parse(buffer) | |
| 88 | + self.video_duration = vid['entry']['media$group']['media$content'][0]['duration'] | |
| 89 | + elsif is_vimeo? | |
| 90 | + self.video_provider = 'vimeo' | |
| 91 | + self.video_id = extract_vimeo_id | |
| 92 | + url = "http://vimeo.com/api/v2/video/#{self.video_id}.json" | |
| 93 | + resp = Net::HTTP.get_response(URI.parse(url)) | |
| 94 | + buffer = resp.body | |
| 95 | + vid = JSON.parse(buffer) | |
| 96 | + vid = vid[0] | |
| 97 | + #raise vid.to_yaml | |
| 98 | + self.video_thumbnail_url = vid['thumbnail_large'] | |
| 99 | + self.video_width = vid['width'] | |
| 100 | + self.video_height = vid['height'] | |
| 101 | + self.video_thumbnail_width = 640 | |
| 102 | + self.video_thumbnail_height = 360 | |
| 103 | + elsif true | |
| 104 | + self.video_format = detect_format | |
| 105 | + self.video_provider = 'file' | |
| 106 | + end | |
| 107 | + end | |
| 108 | + | |
| 109 | + def detect_format | |
| 110 | + video_type = 'video/unknown' | |
| 111 | + if /.mp4/i =~ self.video_url or /.mov/i =~ self.video_url | |
| 112 | + video_type='video/mp4' | |
| 113 | + elsif /.webm/i =~ self.video_url | |
| 114 | + video_type='video/webm' | |
| 115 | + elsif /.og[vg]/i =~ self.video_url | |
| 116 | + video_type='video/ogg' | |
| 117 | + end | |
| 118 | + video_type | |
| 119 | + end | |
| 120 | + | |
| 121 | + def is_youtube? | |
| 122 | + video_url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false | |
| 123 | + end | |
| 124 | + | |
| 125 | + def is_vimeo? | |
| 126 | + video_url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/([A-z]|\/)*[[:digit:]]+/) ? true : false | |
| 127 | + end | |
| 128 | + | |
| 129 | + def is_video_file? | |
| 130 | + video_url.match(/\.(mp4|ogg|ogv|webm)/) ? true : false | |
| 131 | + end | |
| 132 | + | |
| 133 | + def extract_youtube_id | |
| 134 | + return nil unless is_youtube? | |
| 135 | + youtube_match = video_url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") | |
| 136 | + youtube_match ||= video_url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") | |
| 137 | + youtube_match[1] unless youtube_match.nil? | |
| 138 | + end | |
| 139 | + | |
| 140 | + def extract_vimeo_id | |
| 141 | + return nil unless is_vimeo? | |
| 142 | + vimeo_match = video_url.match('([[:digit:]]*)$') | |
| 143 | + vimeo_match[1] unless vimeo_match.nil? | |
| 144 | + end | |
| 145 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,62 @@ |
| 1 | +class VideoPlugin::VideoBlock < Block | |
| 2 | + | |
| 3 | + attr_accessible :url, :width, :height | |
| 4 | + | |
| 5 | + settings_items :url, :type => :string, :default => "" | |
| 6 | + settings_items :width, :type => :integer, :default => 400 | |
| 7 | + settings_items :height, :type => :integer, :default => 315 | |
| 8 | + | |
| 9 | + YOUTUBE_ID_FORMAT = '\w-' | |
| 10 | + | |
| 11 | + def is_youtube? | |
| 12 | + url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false | |
| 13 | + end | |
| 14 | + | |
| 15 | + def is_vimeo? | |
| 16 | + url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/[[:digit:]]+/) ? true : false | |
| 17 | + end | |
| 18 | + | |
| 19 | + def is_video_file? | |
| 20 | + url.match(/.*(mp4|ogg|ogv|webm)$/) ? true : false | |
| 21 | + end | |
| 22 | + | |
| 23 | + def format_embed_video_url_for_youtube | |
| 24 | + "//www.youtube-nocookie.com/embed/#{extract_youtube_id}?rel=0&wmode=transparent" if is_youtube? | |
| 25 | + end | |
| 26 | + | |
| 27 | + def format_embed_video_url_for_vimeo | |
| 28 | + "//player.vimeo.com/video/#{extract_vimeo_id}" if is_vimeo? | |
| 29 | + end | |
| 30 | + | |
| 31 | + def self.description | |
| 32 | + _('Display a Video') | |
| 33 | + end | |
| 34 | + | |
| 35 | + def help | |
| 36 | + _('This block presents a video from youtube, vimeo and some video formats (mp4, ogg, ogv and webm)') | |
| 37 | + end | |
| 38 | + | |
| 39 | + def content(args={}) | |
| 40 | + block = self | |
| 41 | + | |
| 42 | + proc do | |
| 43 | + render :file => 'video_block', :locals => { :block => block } | |
| 44 | + end | |
| 45 | + end | |
| 46 | + | |
| 47 | + private | |
| 48 | + | |
| 49 | + def extract_youtube_id | |
| 50 | + return nil unless is_youtube? | |
| 51 | + youtube_match = url.match("v=([#{YOUTUBE_ID_FORMAT}]*)") | |
| 52 | + youtube_match ||= url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)") | |
| 53 | + youtube_match[1] unless youtube_match.nil? | |
| 54 | + end | |
| 55 | + | |
| 56 | + def extract_vimeo_id | |
| 57 | + return nil unless is_vimeo? | |
| 58 | + vimeo_match = url.match('([[:digit:]]*)$') | |
| 59 | + vimeo_match[1] unless vimeo_match.nil? | |
| 60 | + end | |
| 61 | + | |
| 62 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,63 @@ |
| 1 | +class VideoPlugin::VideoGallery < Folder | |
| 2 | + | |
| 3 | + def self.type_name | |
| 4 | + _('Video Gallery') | |
| 5 | + end | |
| 6 | + | |
| 7 | + settings_items :thumbnail_width, :type => :integer, :default => 50 | |
| 8 | + settings_items :thumbnail_height, :type => :integer, :default => 50 | |
| 9 | + settings_items :videos_per_row, :type => :integer, :default => 5 | |
| 10 | + | |
| 11 | + validate :not_belong_to_blog | |
| 12 | + | |
| 13 | + def not_belong_to_blog | |
| 14 | + errors.add(:parent, "A video gallery should not belong to a blog.") if parent && parent.blog? | |
| 15 | + end | |
| 16 | + | |
| 17 | + acts_as_having_settings :field => :setting | |
| 18 | + | |
| 19 | + xss_terminate :only => [ :body ], :with => 'white_list', :on => 'validation' | |
| 20 | + | |
| 21 | + include WhiteListFilter | |
| 22 | + filter_iframes :body | |
| 23 | + def iframe_whitelist | |
| 24 | + profile && profile.environment && profile.environment.trusted_sites_for_iframe | |
| 25 | + end | |
| 26 | + | |
| 27 | + def self.short_description | |
| 28 | + _('Video Gallery') | |
| 29 | + end | |
| 30 | + | |
| 31 | + def self.description | |
| 32 | + _('A gallery of link to videos that are hosted elsewhere.') | |
| 33 | + end | |
| 34 | + | |
| 35 | + include ActionView::Helpers::TagHelper | |
| 36 | + def to_html(options = {}) | |
| 37 | + video_gallery = self | |
| 38 | + proc do | |
| 39 | + render :partial => 'content_viewer/video_gallery', :locals => {:video_gallery => video_gallery} | |
| 40 | + end | |
| 41 | + end | |
| 42 | + | |
| 43 | + def video_gallery? | |
| 44 | + true | |
| 45 | + end | |
| 46 | + | |
| 47 | + def can_display_hits? | |
| 48 | + false | |
| 49 | + end | |
| 50 | + | |
| 51 | + def accept_comments? | |
| 52 | + false | |
| 53 | + end | |
| 54 | + | |
| 55 | + def self.icon_name(article = nil) | |
| 56 | + 'Video gallery' | |
| 57 | + end | |
| 58 | + | |
| 59 | + def news(limit = 30, highlight = false) | |
| 60 | + profile.recent_documents(limit, ["articles.type != ? AND articles.highlighted = ? AND articles.parent_id = ?", 'Folder', highlight, id]) | |
| 61 | + end | |
| 62 | + | |
| 63 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,18 @@ |
| 1 | +module VideoPlugin::VideoGalleryHelper | |
| 2 | + | |
| 3 | + def list_videos(configure={}) | |
| 4 | + configure[:recursive] ||= false | |
| 5 | + configure[:list_type] ||= :folder | |
| 6 | + if !configure[:contents].blank? | |
| 7 | + configure[:contents] = configure[:contents].paginate( | |
| 8 | + :order => "updated_at DESC", | |
| 9 | + :per_page => 16, | |
| 10 | + :page => params[:npage] | |
| 11 | + ) | |
| 12 | + render :file => 'shared/video_list', :locals => configure | |
| 13 | + else | |
| 14 | + content_tag('em', _('(empty folder)')) | |
| 15 | + end | |
| 16 | + end | |
| 17 | + | |
| 18 | +end | ... | ... |
plugins/video/test/functional/video_plugin_environment_design_controller_test.rb
| ... | ... | @@ -21,9 +21,9 @@ class EnvironmentDesignControllerTest < ActionController::TestCase |
| 21 | 21 | @environment.enabled_plugins = ['VideoPlugin'] |
| 22 | 22 | @environment.save! |
| 23 | 23 | |
| 24 | - VideoBlock.delete_all | |
| 24 | + VideoPlugin::VideoBlock.delete_all | |
| 25 | 25 | |
| 26 | - @block = VideoBlock.new | |
| 26 | + @block = VideoPlugin::VideoBlock.new | |
| 27 | 27 | @block.box = @environment.boxes.first |
| 28 | 28 | @block.save! |
| 29 | 29 | end | ... | ... |
plugins/video/test/functional/video_plugin_profile_design_controller_test.rb
| ... | ... | @@ -18,11 +18,11 @@ class ProfileDesignControllerTest < ActionController::TestCase |
| 18 | 18 | @environment.enabled_plugins = ['VideoPlugin'] |
| 19 | 19 | @environment.save! |
| 20 | 20 | |
| 21 | - VideoBlock.delete_all | |
| 21 | + VideoPlugin::VideoBlock.delete_all | |
| 22 | 22 | @box1 = Box.create!(:owner => @profile) |
| 23 | 23 | @profile.boxes = [@box1] |
| 24 | 24 | |
| 25 | - @block = VideoBlock.new | |
| 25 | + @block = VideoPlugin::VideoBlock.new | |
| 26 | 26 | @block.box = @box1 |
| 27 | 27 | @block.save! |
| 28 | 28 | ... | ... |
plugins/video/test/unit/video_block_test.rb
| ... | ... | @@ -4,94 +4,94 @@ class VideoBlockTest < ActiveSupport::TestCase |
| 4 | 4 | ### Tests for YouTube |
| 5 | 5 | |
| 6 | 6 | should "is_youtube return true when the url contains http://youtube.com" do |
| 7 | - block = VideoBlock.new | |
| 7 | + block = VideoPlugin::VideoBlock.new | |
| 8 | 8 | block.url = "http://youtube.com/?v=XXXXX" |
| 9 | 9 | assert block.is_youtube? |
| 10 | 10 | end |
| 11 | 11 | |
| 12 | 12 | should "is_youtube return true when the url contains https://youtube.com" do |
| 13 | - block = VideoBlock.new | |
| 13 | + block = VideoPlugin::VideoBlock.new | |
| 14 | 14 | block.url = "https://youtube.com/?v=XXXXX" |
| 15 | 15 | assert block.is_youtube? |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | 18 | should "is_youtube return true when the url contains https://www.youtube.com" do |
| 19 | - block = VideoBlock.new | |
| 19 | + block = VideoPlugin::VideoBlock.new | |
| 20 | 20 | block.url = "https://www.youtube.com/?v=XXXXX" |
| 21 | 21 | assert block.is_youtube? |
| 22 | 22 | end |
| 23 | 23 | |
| 24 | 24 | should "is_youtube return true when the url contains www.youtube.com" do |
| 25 | - block = VideoBlock.new | |
| 25 | + block = VideoPlugin::VideoBlock.new | |
| 26 | 26 | block.url = "www.youtube.com/?v=XXXXX" |
| 27 | 27 | assert block.is_youtube? |
| 28 | 28 | end |
| 29 | 29 | |
| 30 | 30 | should "is_youtube return true when the url contains youtube.com" do |
| 31 | - block = VideoBlock.new | |
| 31 | + block = VideoPlugin::VideoBlock.new | |
| 32 | 32 | block.url = "youtube.com/?v=XXXXX" |
| 33 | 33 | assert block.is_youtube? |
| 34 | 34 | end |
| 35 | 35 | |
| 36 | 36 | should "is_youtube return false when the url not contains youtube video ID" do |
| 37 | - block = VideoBlock.new | |
| 37 | + block = VideoPlugin::VideoBlock.new | |
| 38 | 38 | block.url = "youtube.com/" |
| 39 | 39 | assert !block.is_youtube? |
| 40 | 40 | end |
| 41 | 41 | |
| 42 | 42 | should "is_youtube return false when the url contains empty youtube video ID" do |
| 43 | - block = VideoBlock.new | |
| 43 | + block = VideoPlugin::VideoBlock.new | |
| 44 | 44 | block.url = "youtube.com/?v=" |
| 45 | 45 | assert !block.is_youtube? |
| 46 | 46 | end |
| 47 | 47 | |
| 48 | 48 | should "is_youtube return false when the url contains an invalid youtube link" do |
| 49 | - block = VideoBlock.new | |
| 49 | + block = VideoPlugin::VideoBlock.new | |
| 50 | 50 | block.url = "http://www.yt.com/?v=XXXXX" |
| 51 | 51 | assert !block.is_youtube? |
| 52 | 52 | end |
| 53 | 53 | |
| 54 | 54 | should "format embed video for youtube videos" do |
| 55 | - block = VideoBlock.new | |
| 55 | + block = VideoPlugin::VideoBlock.new | |
| 56 | 56 | block.url = "youtube.com/?v=XXXXX" |
| 57 | 57 | assert_match /\/\/www.youtube-nocookie.com\/embed/, block.format_embed_video_url_for_youtube |
| 58 | 58 | end |
| 59 | 59 | |
| 60 | 60 | should "format embed video return nil if is not a youtube url" do |
| 61 | - block = VideoBlock.new | |
| 61 | + block = VideoPlugin::VideoBlock.new | |
| 62 | 62 | block.url = "http://www.yt.com/?v=XXXXX" |
| 63 | 63 | assert_nil block.format_embed_video_url_for_youtube |
| 64 | 64 | end |
| 65 | 65 | |
| 66 | 66 | should "extract youtube id from youtube video url's if it's a valid youtube full url" do |
| 67 | - block = VideoBlock.new | |
| 67 | + block = VideoPlugin::VideoBlock.new | |
| 68 | 68 | id = 'oi43jre2d2' |
| 69 | 69 | block.url = "youtube.com/?v=#{id}" |
| 70 | 70 | assert_equal id, block.send('extract_youtube_id') |
| 71 | 71 | end |
| 72 | 72 | |
| 73 | 73 | should "extract youtube id from youtube video url's if it has underline and hyphen" do |
| 74 | - block = VideoBlock.new | |
| 74 | + block = VideoPlugin::VideoBlock.new | |
| 75 | 75 | id = 'oi43_re-d2' |
| 76 | 76 | block.url = "youtube.com/?v=#{id}" |
| 77 | 77 | assert_equal id, block.send('extract_youtube_id') |
| 78 | 78 | end |
| 79 | 79 | |
| 80 | 80 | should "extract youtube id from youtube video url's if it's a valid youtube short url" do |
| 81 | - block = VideoBlock.new | |
| 81 | + block = VideoPlugin::VideoBlock.new | |
| 82 | 82 | id = 'oi43jre2d2' |
| 83 | 83 | block.url = "youtu.be/#{id}" |
| 84 | 84 | assert_equal id, block.send('extract_youtube_id') |
| 85 | 85 | end |
| 86 | 86 | |
| 87 | 87 | should "extract_youtube_id return nil if the url it's not a valid youtube url" do |
| 88 | - block = VideoBlock.new | |
| 88 | + block = VideoPlugin::VideoBlock.new | |
| 89 | 89 | block.url = "http://www.yt.com/?v=XXXXX" |
| 90 | 90 | assert_nil block.send('extract_youtube_id') |
| 91 | 91 | end |
| 92 | 92 | |
| 93 | 93 | should "extract_youtube_id return nil if youtue url there is no id" do |
| 94 | - block = VideoBlock.new | |
| 94 | + block = VideoPlugin::VideoBlock.new | |
| 95 | 95 | block.url = "youtube.com/" |
| 96 | 96 | assert_nil block.send('extract_youtube_id') |
| 97 | 97 | end |
| ... | ... | @@ -99,111 +99,111 @@ class VideoBlockTest < ActiveSupport::TestCase |
| 99 | 99 | #### Tests for Vimeo Videos |
| 100 | 100 | |
| 101 | 101 | should "is_vimeo return true when the url contains http://vimeo.com" do |
| 102 | - block = VideoBlock.new | |
| 102 | + block = VideoPlugin::VideoBlock.new | |
| 103 | 103 | block.url = "http://vimeo.com/98979" |
| 104 | 104 | assert block.is_vimeo? |
| 105 | 105 | end |
| 106 | 106 | |
| 107 | 107 | should "is_vimeo return true when the url contains https://vimeo.com" do |
| 108 | - block = VideoBlock.new | |
| 108 | + block = VideoPlugin::VideoBlock.new | |
| 109 | 109 | block.url = "https://vimeo.com/989798" |
| 110 | 110 | assert block.is_vimeo? |
| 111 | 111 | end |
| 112 | 112 | |
| 113 | 113 | should "is_vimeo return true when the url contains https://www.vimeo.com" do |
| 114 | - block = VideoBlock.new | |
| 114 | + block = VideoPlugin::VideoBlock.new | |
| 115 | 115 | block.url = "https://www.vimeo.com/98987" |
| 116 | 116 | assert block.is_vimeo? |
| 117 | 117 | end |
| 118 | 118 | |
| 119 | 119 | should "is_vimeo return true when the url contains www.vimeo.com" do |
| 120 | - block = VideoBlock.new | |
| 120 | + block = VideoPlugin::VideoBlock.new | |
| 121 | 121 | block.url = "www.vimeo.com/989798" |
| 122 | 122 | assert block.is_vimeo? |
| 123 | 123 | end |
| 124 | 124 | |
| 125 | 125 | should "is_vimeo return true when the url contains vimeo.com" do |
| 126 | - block = VideoBlock.new | |
| 126 | + block = VideoPlugin::VideoBlock.new | |
| 127 | 127 | block.url = "vimeo.com/09898" |
| 128 | 128 | assert block.is_vimeo? |
| 129 | 129 | end |
| 130 | 130 | |
| 131 | 131 | should "is_vimeo return false when the url not contains vimeo video ID" do |
| 132 | - block = VideoBlock.new | |
| 132 | + block = VideoPlugin::VideoBlock.new | |
| 133 | 133 | block.url = "vimeo.com/home" |
| 134 | 134 | assert !block.is_vimeo? |
| 135 | 135 | end |
| 136 | 136 | |
| 137 | 137 | should "is_vimeo return false when the url contains empty vimeo video ID" do |
| 138 | - block = VideoBlock.new | |
| 138 | + block = VideoPlugin::VideoBlock.new | |
| 139 | 139 | block.url = "vimeo.com/" |
| 140 | 140 | assert !block.is_vimeo? |
| 141 | 141 | end |
| 142 | 142 | |
| 143 | 143 | should "is_vimeo return false when the url contains an invalid vimeo link" do |
| 144 | - block = VideoBlock.new | |
| 144 | + block = VideoPlugin::VideoBlock.new | |
| 145 | 145 | block.url = "http://www.vmsd.com/98979" |
| 146 | 146 | assert !block.is_vimeo? |
| 147 | 147 | end |
| 148 | 148 | |
| 149 | 149 | should "format embed video for vimeo videos" do |
| 150 | - block = VideoBlock.new | |
| 150 | + block = VideoPlugin::VideoBlock.new | |
| 151 | 151 | block.url = "vimeo.com/09898" |
| 152 | 152 | assert_match /\/\/player.vimeo.com\/video\/[[:digit:]]+/, block.format_embed_video_url_for_vimeo |
| 153 | 153 | end |
| 154 | 154 | |
| 155 | 155 | should "format embed video return nil if is not a vimeo url" do |
| 156 | - block = VideoBlock.new | |
| 156 | + block = VideoPlugin::VideoBlock.new | |
| 157 | 157 | block.url = "http://www.yt.com/?v=XXXXX" |
| 158 | 158 | assert_nil block.format_embed_video_url_for_vimeo |
| 159 | 159 | end |
| 160 | 160 | |
| 161 | 161 | should "extract vimeo id from vimeo video url's if it's a valid vimeo url" do |
| 162 | - block = VideoBlock.new | |
| 162 | + block = VideoPlugin::VideoBlock.new | |
| 163 | 163 | id = '23048239432' |
| 164 | 164 | block.url = "vimeo.com/#{id}" |
| 165 | 165 | assert_equal id, block.send('extract_vimeo_id') |
| 166 | 166 | end |
| 167 | 167 | |
| 168 | 168 | should "extract_vimeo_id return nil if the url it's not a valid vimeo url" do |
| 169 | - block = VideoBlock.new | |
| 169 | + block = VideoPlugin::VideoBlock.new | |
| 170 | 170 | block.url = "http://www.yt.com/XXXXX" |
| 171 | 171 | assert_nil block.send('extract_vimeo_id') |
| 172 | 172 | end |
| 173 | 173 | |
| 174 | 174 | should "extract_vimeo_id return nil if vimeo url there is no id" do |
| 175 | - block = VideoBlock.new | |
| 175 | + block = VideoPlugin::VideoBlock.new | |
| 176 | 176 | block.url = "vimeo.com/" |
| 177 | 177 | assert_nil block.send('extract_youtube_id') |
| 178 | 178 | end |
| 179 | 179 | |
| 180 | 180 | # Other video formats |
| 181 | 181 | should "is_video return true if url ends with mp4" do |
| 182 | - block = VideoBlock.new | |
| 182 | + block = VideoPlugin::VideoBlock.new | |
| 183 | 183 | block.url = "http://www.vmsd.com/98979.mp4" |
| 184 | 184 | assert block.is_video_file? |
| 185 | 185 | end |
| 186 | 186 | |
| 187 | 187 | should "is_video return true if url ends with ogg" do |
| 188 | - block = VideoBlock.new | |
| 188 | + block = VideoPlugin::VideoBlock.new | |
| 189 | 189 | block.url = "http://www.vmsd.com/98979.ogg" |
| 190 | 190 | assert block.is_video_file? |
| 191 | 191 | end |
| 192 | 192 | |
| 193 | 193 | should "is_video return true if url ends with ogv" do |
| 194 | - block = VideoBlock.new | |
| 194 | + block = VideoPlugin::VideoBlock.new | |
| 195 | 195 | block.url = "http://www.vmsd.com/98979.ogv" |
| 196 | 196 | assert block.is_video_file? |
| 197 | 197 | end |
| 198 | 198 | |
| 199 | 199 | should "is_video return true if url ends with webm" do |
| 200 | - block = VideoBlock.new | |
| 200 | + block = VideoPlugin::VideoBlock.new | |
| 201 | 201 | block.url = "http://www.vmsd.com/98979.webm" |
| 202 | 202 | assert block.is_video_file? |
| 203 | 203 | end |
| 204 | 204 | |
| 205 | 205 | should "is_video return false if url ends without mp4, ogg, ogv, webm" do |
| 206 | - block = VideoBlock.new | |
| 206 | + block = VideoPlugin::VideoBlock.new | |
| 207 | 207 | block.url = "http://www.vmsd.com/98979.mp4r" |
| 208 | 208 | assert !block.is_video_file? |
| 209 | 209 | block.url = "http://www.vmsd.com/98979.oggr" |
| ... | ... | @@ -215,7 +215,7 @@ class VideoBlockTest < ActiveSupport::TestCase |
| 215 | 215 | end |
| 216 | 216 | |
| 217 | 217 | should 'display video block partial' do |
| 218 | - block = VideoBlock.new | |
| 218 | + block = VideoPlugin::VideoBlock.new | |
| 219 | 219 | self.expects(:render).with(:file => 'video_block', :locals => { |
| 220 | 220 | :block => block |
| 221 | 221 | }) | ... | ... |
plugins/video/test/unit/video_plugin_test.rb
| ... | ... | @@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/../test_helper' |
| 2 | 2 | class VideoPluginTest < ActiveSupport::TestCase |
| 3 | 3 | |
| 4 | 4 | should "return VideoBlock in extra_blocks class method" do |
| 5 | - assert VideoPlugin.extra_blocks.keys.include?(VideoBlock) | |
| 5 | + assert VideoPlugin.extra_blocks.keys.include?(VideoPlugin::VideoBlock) | |
| 6 | 6 | end |
| 7 | 7 | |
| 8 | 8 | end | ... | ... |