Commit 3d0b536ad874d130294e3799c75e780f2bbe1124

Authored by Evandro Jr
Committed by Rodrigo Souto
1 parent 671db6cb

Adds Video gallery and other video stuff (like video article and video gallery block)

Showing 29 changed files with 744 additions and 125 deletions   Show diff stats
plugins/video/README.md
... ... @@ -49,9 +49,10 @@ See Noosfero license.
49 49 AUTHORS
50 50 =======
51 51  
52   - Leandro Nunes dos Santos (leandronunes at gmail.com)
  52 + Leandro Nunes dos Santos (leandronunes at gmail.com) (Video Block)
  53 + Evandro Magalhães Leite Júnior (evandrojr at gmail.com) (Video Gallery & Video Content)
53 54  
54 55 ACKNOWLEDGMENTS
55 56 ===============
56 57  
57   -The author have been supported by Serpro
  58 +The authors have been supported by Serpro
... ...
plugins/video/lib/ext/article.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +require_dependency 'article'
  2 +
  3 +class Article
  4 +
  5 + scope :video_gallery, :conditions => ["articles.type = 'VideoPlugin::VideoGallery'"]
  6 +
  7 + #FIXME This should be done via hotspot
  8 + def self.folder_types_with_video
  9 + self.folder_types_without_video << 'VideoPlugin::VideoGallery'
  10 + end
  11 +
  12 + #FIXME This should be done via hotspot
  13 + class << self
  14 + alias_method_chain :folder_types, :video
  15 + end
  16 +
  17 + def self.owner_video_galleries(owner)
  18 + conditions = owner.kind_of?(Environment) ? [] : ["profile_id = ?", owner.id]
  19 + result = Article.video_gallery.find(
  20 + :all,
  21 + :order => 'created_at desc',
  22 + :conditions => conditions)
  23 + end
  24 +
  25 +end
  26 +
  27 +
  28 +
  29 +
  30 +
  31 +
... ...
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_plugin.rb
1   -require_dependency File.dirname(__FILE__) + '/video_block'
2   -
3 1 class VideoPlugin < Noosfero::Plugin
4 2  
5 3 def self.plugin_name
6   - "Video Block Plugin"
  4 + "Video Content type, Video Block and Video Gallery Plugin"
7 5 end
8 6  
9 7 def self.plugin_description
... ... @@ -11,8 +9,37 @@ class VideoPlugin &lt; Noosfero::Plugin
11 9 end
12 10  
13 11 def self.extra_blocks
  12 + { VideoPlugin::VideoBlock => {}, VideoPlugin::VideoGalleryBlock => {:position=>['1']} }
  13 + end
  14 +
  15 + def stylesheet?
  16 + true
  17 + end
  18 +
  19 + def content_types
  20 + [VideoPlugin::VideoGallery, VideoPlugin::Video]
  21 + end
  22 +
  23 + def content_remove_new(content)
  24 + if content.kind_of?(VideoPlugin::VideoGallery) or content.kind_of?(VideoPlugin::Video)
  25 + true
  26 + end
  27 + end
  28 +
  29 + def content_remove_upload(content)
  30 + if content.kind_of?(VideoPlugin::VideoGallery) or content.kind_of?(VideoPlugin::Video)
  31 + true
  32 + end
  33 + end
  34 +
  35 + def article_extra_toolbar_buttons(content)
  36 + return [] if !content.kind_of?(VideoPlugin::VideoGallery)
14 37 {
15   - VideoBlock => {}
  38 + :id=>"new-video-btn",
  39 + :class=>"button with-text icon-new",
  40 + :url=> {:action => 'new', :type=>'VideoPlugin::Video', :controller=>'cms', :parent_id => content.id},
  41 + :title=>_("New Video"),
  42 + :icon => :new
16 43 }
17 44 end
18 45  
... ...
plugins/video/lib/video_plugin/video.rb 0 → 100644
... ... @@ -0,0 +1,180 @@
  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 + #Video Providers are: 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 :fill_video_properties
  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 + def is_youtube?
  40 + VideoPlugin::Video.is_youtube?(self.video_url)
  41 + end
  42 +
  43 + def is_vimeo?
  44 + VideoPlugin::Video.is_vimeo?(self.video_url)
  45 + end
  46 +
  47 + include ActionView::Helpers::TagHelper
  48 + def to_html(options={})
  49 + article = self
  50 + proc do
  51 + render :partial => 'content_viewer/video_plugin/video', :locals => {:article => article}
  52 + end
  53 + end
  54 +
  55 + def fitted_width
  56 + 499
  57 + end
  58 +
  59 + def fitted_height
  60 + ((fitted_width * self.video_height) / self.video_width).to_i
  61 + end
  62 +
  63 + def thumbnail_fitted_width
  64 + 80
  65 + end
  66 +
  67 + def thumbnail_fitted_height
  68 + ((thumbnail_fitted_width * self.video_thumbnail_height) / self.video_thumbnail_width).to_i
  69 + end
  70 +
  71 + def no_browser_support_message
  72 + '<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>'
  73 + end
  74 +
  75 + def self.is_youtube?(video_url)
  76 + video_url.match(/.*(youtube.com.*v=[#{YOUTUBE_ID_FORMAT}]+|youtu.be\/[#{YOUTUBE_ID_FORMAT}]+).*/) ? true : false
  77 + end
  78 +
  79 + def self.is_vimeo?(video_url)
  80 + video_url.match(/^(http[s]?:\/\/)?(www.)?(vimeo.com|player.vimeo.com\/video)\/([A-z]|\/)*[[:digit:]]+/) ? true : false
  81 + end
  82 +
  83 + def self.is_video_file?(video_url)
  84 + video_url.match(/\.(mp4|ogg|ogv|webm)/) ? true : false
  85 + end
  86 +
  87 + def self.format_embed_video_url_for_youtube(video_url)
  88 + "//www.youtube-nocookie.com/embed/#{extract_youtube_id(video_url)}?rel=0&wmode=transparent" if is_youtube?(video_url)
  89 + end
  90 +
  91 + def self.format_embed_video_url_for_vimeo(video_url)
  92 + "//player.vimeo.com/video/#{extract_vimeo_id(video_url)}" if is_vimeo?(video_url)
  93 + end
  94 +
  95 + def format_embed_video_url_for_youtube
  96 + VideoPlugin::Video.format_embed_video_url_for_youtube(self.video_url)
  97 + end
  98 +
  99 + def format_embed_video_url_for_vimeo
  100 + VideoPlugin::Video.format_embed_video_url_for_vimeo(self.video_url)
  101 + end
  102 +
  103 + def self.extract_youtube_id(video_url)
  104 + return nil unless self.is_youtube?(video_url)
  105 + youtube_match = video_url.match("v=([#{YOUTUBE_ID_FORMAT}]*)")
  106 + youtube_match ||= video_url.match("youtu.be\/([#{YOUTUBE_ID_FORMAT}]*)")
  107 + youtube_match[1] unless youtube_match.nil?
  108 + end
  109 +
  110 + def self.extract_vimeo_id(video_url)
  111 + return nil unless self.is_vimeo?(video_url)
  112 + vimeo_match = video_url.match('([[:digit:]]*)$')
  113 + vimeo_match[1] unless vimeo_match.nil?
  114 + end
  115 +
  116 + private
  117 +
  118 + YOUTUBE_ID_FORMAT = '\w-'
  119 +
  120 + def fill_video_properties
  121 + if is_youtube?
  122 + fill_youtube_video_properties
  123 + elsif is_vimeo?
  124 + fill_vimeo_video_properties
  125 + elsif true
  126 + self.video_format = detect_file_format
  127 + self.video_provider = 'file'
  128 + end
  129 + end
  130 +
  131 + def fill_youtube_video_properties
  132 + self.video_provider = 'youtube'
  133 + self.video_id = extract_youtube_id
  134 + url = "http://www.youtube.com/oembed?url=http%3A//www.youtube.com/watch?v%3D#{self.video_id}&format=json"
  135 + resp = Net::HTTP.get_response(URI.parse(url))
  136 + buffer = resp.body
  137 + vid = JSON.parse(buffer)
  138 + self.video_thumbnail_url = vid['thumbnail_url']
  139 + self.video_width = vid['width']
  140 + self.video_height = vid['height']
  141 + self.video_thumbnail_width = vid['thumbnail_width']
  142 + self.video_thumbnail_height = vid['thumbnail_height']
  143 + end
  144 +
  145 + def fill_vimeo_video_properties
  146 + self.video_provider = 'vimeo'
  147 + self.video_id = extract_vimeo_id
  148 + url = "http://vimeo.com/api/v2/video/#{self.video_id}.json"
  149 + resp = Net::HTTP.get_response(URI.parse(url))
  150 + buffer = resp.body
  151 + vid = JSON.parse(buffer)
  152 + vid = vid[0]
  153 + self.video_thumbnail_url = vid['thumbnail_large']
  154 + self.video_width = vid['width']
  155 + self.video_height = vid['height']
  156 + self.video_thumbnail_width = 640
  157 + self.video_thumbnail_height = 360
  158 + end
  159 +
  160 + def detect_file_format
  161 + video_type = 'video/unknown'
  162 + if /.mp4/i =~ self.video_url or /.mov/i =~ self.video_url
  163 + video_type='video/mp4'
  164 + elsif /.webm/i =~ self.video_url
  165 + video_type='video/webm'
  166 + elsif /.og[vg]/i =~ self.video_url
  167 + video_type='video/ogg'
  168 + end
  169 + video_type
  170 + end
  171 +
  172 + def extract_youtube_id
  173 + VideoPlugin::Video.extract_youtube_id(self.video_url)
  174 + end
  175 +
  176 + def extract_vimeo_id
  177 + VideoPlugin::Video.extract_vimeo_id(self.video_url)
  178 + end
  179 +
  180 +end
... ...
plugins/video/lib/video_plugin/video_block.rb 0 → 100644
... ... @@ -0,0 +1,57 @@
  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 + VideoPlugin::Video.is_youtube?(url)
  13 + end
  14 +
  15 + def is_vimeo?
  16 + VideoPlugin::Video.is_vimeo?(url)
  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 + VideoPlugin::Video.format_embed_video_url_for_youtube(url)
  25 + end
  26 +
  27 + def format_embed_video_url_for_vimeo
  28 + VideoPlugin::Video.format_embed_video_url_for_vimeo(url)
  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 + VideoPlugin::Video.extract_youtube_id(url)
  51 + end
  52 +
  53 + def extract_vimeo_id
  54 + VideoPlugin::Video.extract_vimeo_id(url)
  55 + end
  56 +
  57 +end
... ...
plugins/video/lib/video_plugin/video_gallery.rb 0 → 100644
... ... @@ -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_plugin/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_plugin/video_gallery_block.rb 0 → 100644
... ... @@ -0,0 +1,31 @@
  1 +class VideoPlugin::VideoGalleryBlock < Block
  2 +
  3 + settings_items :video_gallery_id, :type => :integer
  4 + attr_accessible :video_gallery_id
  5 +
  6 + include ActionView::Helpers
  7 + include Rails.application.routes.url_helpers
  8 +
  9 + def self.description
  10 + _('Display a Video Gallery')
  11 + end
  12 +
  13 + def help
  14 + _('This block presents a video gallery')
  15 + end
  16 +
  17 + def content(args={})
  18 + block = self
  19 + if video_gallery_id.present?
  20 + video_gallery = VideoPlugin::VideoGallery.find(video_gallery_id)
  21 + proc do
  22 + render :partial => 'content_viewer/video_plugin/video_gallery', :locals => {:video_gallery => video_gallery}
  23 + end
  24 + end
  25 + end
  26 +
  27 + def list_my_galleries
  28 + Article.owner_video_galleries(owner)
  29 + end
  30 +
  31 +end
... ...
plugins/video/lib/video_plugin/video_gallery_helper.rb 0 → 100644
... ... @@ -0,0 +1,17 @@
  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 + :per_page => 17,
  9 + :page => params[:npage]
  10 + ).order("updated_at DESC")
  11 + render :file => 'shared/video_list', :locals => configure
  12 + else
  13 + content_tag('em', _('(empty folder)'))
  14 + end
  15 + end
  16 +
  17 +end
... ...
plugins/video/public/images/video_generic_thumbnail.jpg 0 → 100644

4.49 KB

plugins/video/public/style.css 0 → 100644
... ... @@ -0,0 +1,66 @@
  1 +.video-gallery-thumbnail {
  2 + position: relative;
  3 + display: inline-block;
  4 + width: 95px;
  5 + height: 115px;
  6 + margin: 1em;
  7 + border: solid #F0F0F0 1px;
  8 + vertical-align: top;
  9 + text-align: left;
  10 + overflow: hidden;
  11 + padding-top: 7px;
  12 + margin-botton: 10px;
  13 + text-overflow: ellipsis;
  14 +}
  15 +
  16 +.video-gallery-top-box{
  17 + height: 73px;
  18 +}
  19 +
  20 +.video-duration{
  21 + position: absolute;
  22 + bottom: 0px;
  23 + background-color: black;
  24 + font-size: 1em;
  25 + text-color: white;
  26 +}
  27 +
  28 +.video-title{
  29 + width: 100%;
  30 + overflow: hidden;
  31 + text-overflow: ellipsis;
  32 +}
  33 +
  34 +.video-author{
  35 + display: none;
  36 + overflow: hidden;
  37 + text-overflow: ellipsis;
  38 +}
  39 +
  40 +.video-gallery-thumbnail:hover div{
  41 + display: inline-block;
  42 +}
  43 +
  44 +.video-gallery-table-big{
  45 + width: 100%;
  46 + overflow: hidden;
  47 +}
  48 +
  49 +.video-gallery-left-column-big{
  50 + width: 350px;
  51 + float: left;
  52 +}
  53 +
  54 +.video-gallery-right-column-big{
  55 + margin-left: 370px;
  56 +}
  57 +
  58 +.video-title-big{
  59 + font-size: 2em;
  60 +}
  61 +
  62 +.video-block-center{
  63 + width: 100%;
  64 + margin-left: auto;
  65 + margin-right: auto;
  66 +}
0 67 \ No newline at end of file
... ...
plugins/video/test/functional/video_plugin_environment_design_controller_test.rb
... ... @@ -18,9 +18,9 @@ class EnvironmentDesignControllerTest &lt; 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  
23   - @block = VideoBlock.new
  23 + @block = VideoPlugin::VideoBlock.new
24 24 @block.box = @environment.boxes.first
25 25 @block.save!
26 26 end
... ...
plugins/video/test/functional/video_plugin_profile_design_controller_test.rb
... ... @@ -15,11 +15,11 @@ class ProfileDesignControllerTest &lt; ActionController::TestCase
15 15 @environment.enabled_plugins = ['VideoPlugin']
16 16 @environment.save!
17 17  
18   - VideoBlock.delete_all
  18 + VideoPlugin::VideoBlock.delete_all
19 19 @box1 = Box.create!(:owner => @profile)
20 20 @profile.boxes = [@box1]
21 21  
22   - @block = VideoBlock.new
  22 + @block = VideoPlugin::VideoBlock.new
23 23 @block.box = @box1
24 24 @block.save!
25 25  
... ...
plugins/video/test/unit/video_block_test.rb
... ... @@ -4,94 +4,88 @@ class VideoBlockTest &lt; 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   - should "is_youtube return true when the url contains https://www.youtube.com" do
19   - block = VideoBlock.new
20   - block.url = "https://www.youtube.com/?v=XXXXX"
21   - assert block.is_youtube?
22   - end
23   -
24 18 should "is_youtube return true when the url contains www.youtube.com" do
25   - block = VideoBlock.new
  19 + block = VideoPlugin::VideoBlock.new
26 20 block.url = "www.youtube.com/?v=XXXXX"
27 21 assert block.is_youtube?
28 22 end
29 23  
30 24 should "is_youtube return true when the url contains youtube.com" do
31   - block = VideoBlock.new
  25 + block = VideoPlugin::VideoBlock.new
32 26 block.url = "youtube.com/?v=XXXXX"
33 27 assert block.is_youtube?
34 28 end
35 29  
36 30 should "is_youtube return false when the url not contains youtube video ID" do
37   - block = VideoBlock.new
  31 + block = VideoPlugin::VideoBlock.new
38 32 block.url = "youtube.com/"
39 33 refute block.is_youtube?
40 34 end
41 35  
42 36 should "is_youtube return false when the url contains empty youtube video ID" do
43   - block = VideoBlock.new
  37 + block = VideoPlugin::VideoBlock.new
44 38 block.url = "youtube.com/?v="
45 39 refute block.is_youtube?
46 40 end
47 41  
48 42 should "is_youtube return false when the url contains an invalid youtube link" do
49   - block = VideoBlock.new
  43 + block = VideoPlugin::VideoBlock.new
50 44 block.url = "http://www.yt.com/?v=XXXXX"
51 45 refute block.is_youtube?
52 46 end
53 47  
54 48 should "format embed video for youtube videos" do
55   - block = VideoBlock.new
  49 + block = VideoPlugin::VideoBlock.new
56 50 block.url = "youtube.com/?v=XXXXX"
57 51 assert_match /\/\/www.youtube-nocookie.com\/embed/, block.format_embed_video_url_for_youtube
58 52 end
59 53  
60 54 should "format embed video return nil if is not a youtube url" do
61   - block = VideoBlock.new
  55 + block = VideoPlugin::VideoBlock.new
62 56 block.url = "http://www.yt.com/?v=XXXXX"
63 57 assert_nil block.format_embed_video_url_for_youtube
64 58 end
65 59  
66 60 should "extract youtube id from youtube video url's if it's a valid youtube full url" do
67   - block = VideoBlock.new
  61 + block = VideoPlugin::VideoBlock.new
68 62 id = 'oi43jre2d2'
69 63 block.url = "youtube.com/?v=#{id}"
70 64 assert_equal id, block.send('extract_youtube_id')
71 65 end
72 66  
73 67 should "extract youtube id from youtube video url's if it has underline and hyphen" do
74   - block = VideoBlock.new
  68 + block = VideoPlugin::VideoBlock.new
75 69 id = 'oi43_re-d2'
76 70 block.url = "youtube.com/?v=#{id}"
77 71 assert_equal id, block.send('extract_youtube_id')
78 72 end
79 73  
80 74 should "extract youtube id from youtube video url's if it's a valid youtube short url" do
81   - block = VideoBlock.new
  75 + block = VideoPlugin::VideoBlock.new
82 76 id = 'oi43jre2d2'
83 77 block.url = "youtu.be/#{id}"
84 78 assert_equal id, block.send('extract_youtube_id')
85 79 end
86 80  
87 81 should "extract_youtube_id return nil if the url it's not a valid youtube url" do
88   - block = VideoBlock.new
  82 + block = VideoPlugin::VideoBlock.new
89 83 block.url = "http://www.yt.com/?v=XXXXX"
90 84 assert_nil block.send('extract_youtube_id')
91 85 end
92 86  
93 87 should "extract_youtube_id return nil if youtue url there is no id" do
94   - block = VideoBlock.new
  88 + block = VideoPlugin::VideoBlock.new
95 89 block.url = "youtube.com/"
96 90 assert_nil block.send('extract_youtube_id')
97 91 end
... ... @@ -99,111 +93,111 @@ class VideoBlockTest &lt; ActiveSupport::TestCase
99 93 #### Tests for Vimeo Videos
100 94  
101 95 should "is_vimeo return true when the url contains http://vimeo.com" do
102   - block = VideoBlock.new
  96 + block = VideoPlugin::VideoBlock.new
103 97 block.url = "http://vimeo.com/98979"
104 98 assert block.is_vimeo?
105 99 end
106 100  
107 101 should "is_vimeo return true when the url contains https://vimeo.com" do
108   - block = VideoBlock.new
  102 + block = VideoPlugin::VideoBlock.new
109 103 block.url = "https://vimeo.com/989798"
110 104 assert block.is_vimeo?
111 105 end
112 106  
113 107 should "is_vimeo return true when the url contains https://www.vimeo.com" do
114   - block = VideoBlock.new
  108 + block = VideoPlugin::VideoBlock.new
115 109 block.url = "https://www.vimeo.com/98987"
116 110 assert block.is_vimeo?
117 111 end
118 112  
119 113 should "is_vimeo return true when the url contains www.vimeo.com" do
120   - block = VideoBlock.new
  114 + block = VideoPlugin::VideoBlock.new
121 115 block.url = "www.vimeo.com/989798"
122 116 assert block.is_vimeo?
123 117 end
124 118  
125 119 should "is_vimeo return true when the url contains vimeo.com" do
126   - block = VideoBlock.new
  120 + block = VideoPlugin::VideoBlock.new
127 121 block.url = "vimeo.com/09898"
128 122 assert block.is_vimeo?
129 123 end
130 124  
131 125 should "is_vimeo return false when the url not contains vimeo video ID" do
132   - block = VideoBlock.new
  126 + block = VideoPlugin::VideoBlock.new
133 127 block.url = "vimeo.com/home"
134 128 refute block.is_vimeo?
135 129 end
136 130  
137 131 should "is_vimeo return false when the url contains empty vimeo video ID" do
138   - block = VideoBlock.new
  132 + block = VideoPlugin::VideoBlock.new
139 133 block.url = "vimeo.com/"
140 134 refute block.is_vimeo?
141 135 end
142 136  
143 137 should "is_vimeo return false when the url contains an invalid vimeo link" do
144   - block = VideoBlock.new
  138 + block = VideoPlugin::VideoBlock.new
145 139 block.url = "http://www.vmsd.com/98979"
146 140 refute block.is_vimeo?
147 141 end
148 142  
149 143 should "format embed video for vimeo videos" do
150   - block = VideoBlock.new
  144 + block = VideoPlugin::VideoBlock.new
151 145 block.url = "vimeo.com/09898"
152 146 assert_match /\/\/player.vimeo.com\/video\/[[:digit:]]+/, block.format_embed_video_url_for_vimeo
153 147 end
154 148  
155 149 should "format embed video return nil if is not a vimeo url" do
156   - block = VideoBlock.new
  150 + block = VideoPlugin::VideoBlock.new
157 151 block.url = "http://www.yt.com/?v=XXXXX"
158 152 assert_nil block.format_embed_video_url_for_vimeo
159 153 end
160 154  
161 155 should "extract vimeo id from vimeo video url's if it's a valid vimeo url" do
162   - block = VideoBlock.new
  156 + block = VideoPlugin::VideoBlock.new
163 157 id = '23048239432'
164 158 block.url = "vimeo.com/#{id}"
165 159 assert_equal id, block.send('extract_vimeo_id')
166 160 end
167 161  
168 162 should "extract_vimeo_id return nil if the url it's not a valid vimeo url" do
169   - block = VideoBlock.new
  163 + block = VideoPlugin::VideoBlock.new
170 164 block.url = "http://www.yt.com/XXXXX"
171 165 assert_nil block.send('extract_vimeo_id')
172 166 end
173 167  
174 168 should "extract_vimeo_id return nil if vimeo url there is no id" do
175   - block = VideoBlock.new
  169 + block = VideoPlugin::VideoBlock.new
176 170 block.url = "vimeo.com/"
177 171 assert_nil block.send('extract_youtube_id')
178 172 end
179 173  
180 174 # Other video formats
181 175 should "is_video return true if url ends with mp4" do
182   - block = VideoBlock.new
  176 + block = VideoPlugin::VideoBlock.new
183 177 block.url = "http://www.vmsd.com/98979.mp4"
184 178 assert block.is_video_file?
185 179 end
186 180  
187 181 should "is_video return true if url ends with ogg" do
188   - block = VideoBlock.new
  182 + block = VideoPlugin::VideoBlock.new
189 183 block.url = "http://www.vmsd.com/98979.ogg"
190 184 assert block.is_video_file?
191 185 end
192 186  
193 187 should "is_video return true if url ends with ogv" do
194   - block = VideoBlock.new
  188 + block = VideoPlugin::VideoBlock.new
195 189 block.url = "http://www.vmsd.com/98979.ogv"
196 190 assert block.is_video_file?
197 191 end
198 192  
199 193 should "is_video return true if url ends with webm" do
200   - block = VideoBlock.new
  194 + block = VideoPlugin::VideoBlock.new
201 195 block.url = "http://www.vmsd.com/98979.webm"
202 196 assert block.is_video_file?
203 197 end
204 198  
205 199 should "is_video return false if url ends without mp4, ogg, ogv, webm" do
206   - block = VideoBlock.new
  200 + block = VideoPlugin::VideoBlock.new
207 201 block.url = "http://www.vmsd.com/98979.mp4r"
208 202 refute block.is_video_file?
209 203 block.url = "http://www.vmsd.com/98979.oggr"
... ... @@ -215,7 +209,7 @@ class VideoBlockTest &lt; ActiveSupport::TestCase
215 209 end
216 210  
217 211 should 'display video block partial' do
218   - block = VideoBlock.new
  212 + block = VideoPlugin::VideoBlock.new
219 213 self.expects(:render).with(:file => 'video_block', :locals => {
220 214 :block => block
221 215 })
... ...
plugins/video/test/unit/video_galery_block_test.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +class VideoGaleryBlockTest < ActiveSupport::TestCase
  3 +
  4 + should "define its description" do
  5 + assert_equal VideoPlugin::VideoGalleryBlock.description, _('Display a Video Gallery')
  6 + end
  7 +
  8 + should "define its help description" do
  9 + assert_equal VideoPlugin::VideoGalleryBlock.new.help, _('This block presents a video gallery')
  10 + end
  11 +
  12 +end
... ...
plugins/video/test/unit/video_galery_test.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +class VideoGaleryTest < ActiveSupport::TestCase
  3 +
  4 + should "define its type_name as Video Gallery" do
  5 + assert_equal VideoPlugin::VideoGallery.type_name, _('Video Gallery')
  6 + end
  7 +
  8 + should "define its short_description" do
  9 + assert_equal VideoPlugin::VideoGallery.short_description, _('Video Gallery')
  10 + end
  11 +
  12 + should "define its description" do
  13 + assert_equal VideoPlugin::VideoGallery.description, _('A gallery of link to videos that are hosted elsewhere.')
  14 + end
  15 +
  16 +end
... ...
plugins/video/test/unit/video_plugin_test.rb
... ... @@ -2,7 +2,7 @@ require_relative &#39;../test_helper&#39;
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
... ...
plugins/video/test/unit/video_test.rb 0 → 100644
... ... @@ -0,0 +1,90 @@
  1 +require File.dirname(__FILE__) + '/../test_helper'
  2 +class VideoTest < ActiveSupport::TestCase
  3 +
  4 + include AuthenticatedTestHelper
  5 + fixtures :users, :environments
  6 +
  7 + def setup
  8 + @video = VideoPlugin::Video.new
  9 + end
  10 +
  11 + should "define its type_name as video" do
  12 + assert_equal VideoPlugin::Video.type_name, _('Video')
  13 + end
  14 +
  15 + should "display version" do
  16 + assert @video.can_display_versions?
  17 + end
  18 +
  19 + should "define its short_description" do
  20 + assert_equal VideoPlugin::Video.short_description, _('Embedded Video')
  21 + end
  22 +
  23 + should "define its description" do
  24 + assert_equal VideoPlugin::Video.description, _('Display embedded videos.')
  25 + end
  26 +
  27 + should "define a fitted_width" do
  28 + assert_equal @video.fitted_width, 499
  29 + end
  30 +
  31 + should "eval a fitted_height" do
  32 + @video.video_height = 1000
  33 + @video.video_width = 2000
  34 + fitted_height = ((@video.fitted_width * @video.video_height) / @video.video_width).to_i
  35 + assert_equal fitted_height, @video.fitted_height
  36 + end
  37 +
  38 + should "define a thumbnail_fitted_width" do
  39 + assert_equal @video.thumbnail_fitted_width, 80
  40 + end
  41 +
  42 + should "eval a thumbnail_fitted_height" do
  43 + @video.video_thumbnail_height = 60
  44 + @video.video_thumbnail_width = 30
  45 + thumbnail_fitted_height = ((@video.thumbnail_fitted_width * @video.video_thumbnail_height) / @video.video_thumbnail_width).to_i
  46 + assert_equal thumbnail_fitted_height, @video.thumbnail_fitted_height
  47 + end
  48 +
  49 + should "show a no_browser_support_message" do
  50 + assert_equal @video.no_browser_support_message, '<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>'
  51 + end
  52 +
  53 +
  54 + ### Tests for YouTube
  55 +
  56 + should "is_youtube return true when the url contains http://youtube.com" do
  57 + @video.video_url = "http://youtube.com/?v=XXXXX"
  58 + assert @video.is_youtube?
  59 + end
  60 +
  61 + should "is_youtube return true when the url contains https://youtube.com" do
  62 + @video.video_url = "https://youtube.com/?v=XXXXX"
  63 + assert @video.is_youtube?
  64 + end
  65 +
  66 + should "is_youtube return false when the url contains an invalid youtube link" do
  67 + @video.video_url = "http://www.yt.com/?v=XXXXX"
  68 + assert !@video.is_youtube?
  69 + end
  70 +
  71 + ### Tests for vimeo
  72 +
  73 + should "is_vimeo return true when the url contains vimeo.com" do
  74 + @video.video_url = "vimeo.com/09898"
  75 + assert @video.is_vimeo?
  76 + end
  77 +
  78 + should "is_vimeo return false when the url not contains vimeo video ID" do
  79 + @video.video_url = "vimeo.com/home"
  80 + assert !@video.is_vimeo?
  81 + end
  82 +
  83 + should "is_vimeo return true for https://vimeo.com/channels/staffpicks/XXXXXXXXXX" do
  84 + @video.video_url = "https://vimeo.com/channels/staffpicks/122325664"
  85 + assert @video.is_vimeo?
  86 + end
  87 +
  88 +
  89 +
  90 +end
... ...
plugins/video/views/box_organizer/_html5_video_block.html.erb
1   -<video controls preload="auto" width='<%="#{width}px"%>' height='<%="#{height}px"%>'>
  1 +<video class="video-block-center" controls preload="auto" width='<%="#{width}px"%>' height='<%="#{height}px"%>'>
2 2 <source src=<%= "#{url}" %>>
3 3 </video>
... ...
plugins/video/views/box_organizer/_iframe_video_block.html.erb
1   -<iframe width='<%="#{width}px"%>' height='<%="#{height}px"%>' src='<%= "#{url}" %>' frameborder="0" allowfullscreen></iframe>
  1 +<iframe class="video-block-center" width='<%="#{width}px"%>' height='<%="#{height}px"%>' src='<%= "#{url}" %>' frameborder="0" allowfullscreen></iframe>
2 2 \ No newline at end of file
... ...
plugins/video/views/box_organizer/_video_block.html.erb
... ... @@ -1,11 +0,0 @@
1   -<label for="url" class="formlabel"> Video URL: </label>
2   -
3   -<div class="formfield type-text">
4   - <%= text_field_tag 'block[url]', @block.url, :class => 'video-url', :maxlength => 255 %>
5   -</div>
6   -<div class="formfield type-text">
7   - <label for="width" class="formlabel"> Width: </label>
8   - <%= text_field_tag 'block[width]', @block.width, :size => 7, :class => 'video-width', :maxlength => 5 %>
9   - <label for="height" class="formlabel"> Height: </label>
10   - <%= text_field_tag 'block[height]', @block.height, :size => 7, :class => 'video-height', :maxlength => 5 %>
11   -</div>
plugins/video/views/box_organizer/video_plugin/_video_block.html.erb 0 → 100644
... ... @@ -0,0 +1,11 @@
  1 +<label for="url" class="formlabel"> Video URL: </label>
  2 +
  3 +<div class="formfield type-text">
  4 + <%= text_field_tag 'block[url]', @block.url, :class => 'video-url', :maxlength => 255 %>
  5 +</div>
  6 +<div class="formfield type-text">
  7 + <label for="width" class="formlabel"> Width: </label>
  8 + <%= text_field_tag 'block[width]', @block.width, :size => 7, :class => 'video-width', :maxlength => 5 %>
  9 + <label for="height" class="formlabel"> Height: </label>
  10 + <%= text_field_tag 'block[height]', @block.height, :size => 7, :class => 'video-height', :maxlength => 5 %>
  11 +</div>
... ...
plugins/video/views/box_organizer/video_plugin/_video_gallery_block.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<div id='edit-video-gallery-block'>
  2 + <%= labelled_select(_('Video gallery')+' ', 'block[video_gallery_id]', :id, :name, @block.video_gallery_id, @block.list_my_galleries) %>
  3 +</div>
0 4 \ No newline at end of file
... ...
plugins/video/views/cms/video_plugin/_video.html.erb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +<%= required_fields_message %>
  2 +
  3 +<div>
  4 +<%= required f.text_field('name', :size => '64', :maxlength => 150) %>
  5 +<%= required labelled_form_field _('URL of the video'), text_field(:article, :video_url, :size => 80) %>
  6 +<%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %>
  7 +<%= render :partial => 'general_fields' %>
  8 +<%= render :partial => 'translatable' %>
  9 +</div>
  10 +
  11 +
  12 +
... ...
plugins/video/views/cms/video_plugin/_video_gallery.html.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<%= required_fields_message %>
  2 +
  3 +<%= required f.text_field('name', :size => '64', :maxlength => 150) %>
  4 +<%= render :partial => 'general_fields' %>
  5 +
  6 +<%= labelled_form_field(_('Description:'), text_area(:article, :body, :rows => 3, :cols => 64)) %>
... ...
plugins/video/views/content_viewer/video_plugin/_video.html.erb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +<div>
  2 +<%if @page.video_provider=='youtube' %>
  3 + <iframe class="video-block-center" width='<%="#{@page.fitted_width}px"%>' height='<%="#{@page.fitted_height}px"%>' src='<%= "#{@page.format_embed_video_url_for_youtube}" %>' frameborder="0" allowfullscreen></iframe>
  4 +<% elsif @page.video_provider=='vimeo' %>
  5 + <iframe class="video-block-center" width='<%="#{@page.fitted_width}px"%>' height='<%="#{@page.fitted_height}px"%>' src='<%= "#{@page.format_embed_video_url_for_vimeo}" %>' frameborder="0" allowfullscreen></iframe>
  6 +<% elsif @page.video_provider=='file' %>
  7 + <video class="video-block-center" controls preload="auto" height="353" width="499" type='<%= @page.video_format %>'>
  8 + <source src=<%= "#{@page.video_url}" %>>
  9 + </video>
  10 +<% end %>
  11 +<br style="clear:both" />
  12 +</div>
  13 +<% _("Description:") %>
  14 +<%= @page.body %>
... ...
plugins/video/views/content_viewer/video_plugin/_video_gallery.html.erb 0 → 100644
... ... @@ -0,0 +1,14 @@
  1 +<% extend VideoPlugin::VideoGalleryHelper %>
  2 +
  3 +<% unless video_gallery.body.blank? %>
  4 + <div>
  5 + <%= video_gallery.body %>
  6 + </div>
  7 + <hr/>
  8 +<% end %>
  9 +
  10 +<% if video_gallery.children.empty? %>
  11 + <em><%= _('(empty video gallery)') %></em>
  12 +<% else %>
  13 + <%= list_videos(:contents=>video_gallery.children) %>
  14 +<% end %>
... ...
plugins/video/views/shared/video_list.html.erb 0 → 100644
... ... @@ -0,0 +1,40 @@
  1 +<div>
  2 + <%
  3 + first_video = contents[0]
  4 + first_video_arr = Array.new
  5 + first_video_arr.push(first_video)
  6 + other_videos = contents - first_video_arr %>
  7 + <% if first_video.display_to?(user) %>
  8 + <div class="video-gallery-table-big">
  9 + <div class="video-gallery-left-column-big">
  10 + <%= link_to first_video.view_url do %>
  11 + <img width="320" height="320" src='<%= first_video.video_thumbnail_url %>' class="disable-zoom"/>
  12 + <% end %>
  13 + </div>
  14 + <div class="video-gallery-right-column-big">
  15 + <div class="video-title-big"><%= first_video.title %></div>
  16 + <div class="video-author-big">
  17 + <%= _("by") %> <%= first_video.author_name %> <%= _("updated at") %> <%= time_ago_in_words(first_video.updated_at) %>
  18 + </div>
  19 + </div>
  20 + </div>
  21 + <% end %>
  22 + <% other_videos.each do |content| %>
  23 + <% if content.display_to?(user) %>
  24 + <div class="video-gallery-thumbnail">
  25 + <div class="video-gallery-top-box">
  26 + <%= link_to content.view_url do %>
  27 + <img width="<%= content.thumbnail_fitted_width %>" height="<%= content.thumbnail_fitted_height %>" src='<%= content.video_thumbnail_url %>' class="disable-zoom"/>
  28 + <% end %>
  29 + </div>
  30 + <div class="video-gallery-botton-box">
  31 + <div class="video-author">
  32 + <%= _("by") %> <%= content.author_name %> <%= _("updated at") %> <%= time_ago_in_words(content.updated_at) %>
  33 + </div>
  34 + <div class="video-title"><%= content.title %></div>
  35 + </div>
  36 + </div>
  37 + <% end %>
  38 + <% end %>
  39 +<p><%= pagination_links contents, :param_name => 'npage', :page_links => true %></p>
  40 +</div>
... ...
plugins/video/views/video_gallery_block.html.erb 0 → 100644
... ... @@ -0,0 +1,7 @@
  1 +<%#
  2 +# To change this license header, choose License Headers in Project Properties.
  3 +# To change this template file, choose Tools | Templates
  4 +# and open the template in the editor.
  5 +%>
  6 +
  7 +<%= "video_gallery_block.html" %>
... ...