Module: KalturaFu::ViewHelpers

Defined in:
lib/kaltura_fu/view_helpers.rb

Overview

The ViewHelpers module provides extensions to Rails ActionView class that allow interactions with Kaltura on rails view layer.

Author:

  • Patrick Robertson

Constant Summary collapse

DEFAULT_KPLAYER =

default UI Conf ID of the kdp player

'1339442'
PLAYER_WIDTH =

default embedded KDP width

'400'
PLAYER_HEIGHT =

default embedded KDP height

'330'

Instance Method Summary collapse

Instance Method Details

#include_kaltura_fu(*args) ⇒ Object

Convienence to include SWFObject and the required Kaltura upload embed javascripts.



19
20
21
22
23
# File 'lib/kaltura_fu/view_helpers.rb', line 19

def include_kaltura_fu(*args)
  content = javascript_include_tag('kaltura_upload')
  content << "\n#{javascript_include_tag('http://ajax.googleapis.com' + 
		 '/ajax/libs/swfobject/2.2/swfobject.js')}" 
end

#kaltura_player_embed(entry_id, options = {}) ⇒ String

Returns the code needed to embed a KDPv3 player.

Parameters:

  • entry_id (String)

    Kaltura entry_id

  • options (Hash) (defaults to: {})

    the embed code options.

Options Hash (options):

  • :div_id (String) — default: 'kplayer'

    The div element that the flash object will be inserted into.

  • :size (Array) — default: []

    The [width,wight] of the player.

  • :use_url (Boolean) — default: false

    flag to determine whether entry_id is an entry or a URL of a flash file.

  • :player_conf_id (String) — default: KalturaFu.config(:player_conf_id)

    A UI Conf ID to override the player with.

Returns:

  • (String)

    returns a string representation of the html/javascript necessary to play a Kaltura entry.



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/kaltura_fu/view_helpers.rb', line 75

def kaltura_player_embed(entry_id,options={})
  player_conf_parameter = "/ui_conf_id/"
  options[:div_id] ||= "kplayer"
  options[:size] ||= []
  options[:use_url] ||= false
  width = PLAYER_WIDTH
  height = PLAYER_HEIGHT
  source_type = "entryId"

  unless options[:size].empty?
   width = options[:size].first
   height = options[:size].last
  end
    
  if options[:use_url] == true
    source_type = "url"
  end

  unless options[:player_conf_id].nil?
    player_conf_parameter += "#{options[:player_conf_id]}"
  else
    unless KalturaFu.config[:player_conf_id].nil?
      player_conf_parameter += "#{KalturaFu.config[:player_conf_id]}"
   else
     player_conf_parameter += "#{DEFAULT_KPLAYER}"
    end
  end
  
  "<div id=\"#{options[:div_id]}\"></div>
  <script type=\"text/javascript\">
  	var params= {
  		allowscriptaccess: \"always\",
  		allownetworking: \"all\",
  		allowfullscreen: \"true\",
  		wmode: \"opaque\"
  	};
  	var flashVars = {};
  	flashVars.sourceType = \"#{source_type}\";      	  
  	flashVars.entryId = \"#{entry_id}\";
  	flashVars.emptyF = \"onKdpEmpty\";
		flashVars.readyF = \"onKdpReady\";
  		
  	var attributes = {
      id: \"#{options[:div_id]}\",
      name: \"#{options[:div_id]}\"
  	};

  	swfobject.embedSWF(\"#{KalturaFu.config[:service_url]}/kwidget/wid/_#{KalturaFu.config[:partner_id]}" + player_conf_parameter + "\",\"#{options[:div_id]}\",\"#{width}\",\"#{height}\",\"10.0.0\",\"http://ttv.mit.edu/swfs/expressinstall.swf\",flashVars,params,attributes);
  </script>"
end

Creates a link_to tag that seeks to a certain time on a KDPv3 player.

Parameters:

  • content (String)

    The text in the link tag.

  • seek_time (Integer)

    The time in seconds to seek the player to.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :div_id (String) — default: 'kplayer'

    The div of the KDP player.



172
173
174
175
176
177
178
# File 'lib/kaltura_fu/view_helpers.rb', line 172

def kaltura_seek_link(content,seek_time,options={})
  options[:div_id] ||= "kplayer"

  options[:onclick] = "$(#{options[:div_id]}).get(0).sendNotification('doSeek',#{seek_time});window.scrollTo(0,0);return false;"
  options.delete(:div_id)
  link_to(content,"#", options)
end

#kaltura_thumbnail(entry_id, options = {}) ⇒ String

Returns the thumbnail of the provided Kaltura Entry.

Parameters:

  • entry_id (String)

    Kaltura entry_id

  • options (Hash) (defaults to: {})

    the options for the thumbnail parameters.

Options Hash (options):

  • :size (Array) — default: []

    an array of [width,height]

  • :second (String) — default: nil

    the second of the Kaltura entry that the thumbnail should be of.

Returns:

  • (String)

    Image tag of the thumbnail resource.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/kaltura_fu/view_helpers.rb', line 34

def kaltura_thumbnail(entry_id,options={})
  options[:size] ||= []
  size_parameters = ""
  seconds_parameter = ""
  
  unless options[:size].empty?
    size_parameters = "/width/#{options[:size].first}/height/" +
 "#{options[:size].last}"
  else
    # if the thumbnail width and height are defined in the config,
   # use it, assuming it wasn't locally overriden
    if KalturaFu.config[:thumb_width] && KalturaFu.config[:thumb_height]
      size_parameters = "/width/#{KalturaFu.config[:thumb_width]}/height/" +
   "#{KalturaFu.config[:thumb_height]}"
    end
  end
  
  unless options[:second].nil?
    seconds_parameter = "/vid_sec/#{options[:second]}"
  else
    seconds_parameter = "/vid_sec/5"
  end
  
  image_tag("#{KalturaFu.config[:service_url]}/p/#{KalturaFu.config[:partner_id]}" +
		"/thumbnail/entry_id/#{entry_id}" + 
		seconds_parameter + 
		size_parameters)
end

#kaltura_upload_embed(options = {}) ⇒ Object

Returns the html/javascript necessary for a KSU widget.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :div_id (String) — default: 'uploader'

    div that the flash object will be inserted into.



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/kaltura_fu/view_helpers.rb', line 132

def kaltura_upload_embed(options={})
  options[:div_id] ||="uploader"
  "<div id=\"#{options[:div_id]}\"></div>
		<script type=\"text/javascript\">

		var params = {
			allowScriptAccess: \"always\",
			allowNetworking: \"all\",
			wmode: \"transparent\"
		};
		var attributes = {
			id: \"uploader\",
			name: \"KUpload\"
		};
		var flashVars = {
			uid: \"ANONYMOUS\",
			partnerId: \"#{KalturaFu.config[:partner_id]}\",
			subPId: \"#{KalturaFu.config[:subpartner_id]}\",
			entryId: \"-1\",
			ks: \"#{KalturaFu.session_key}\",
			uiConfId: '1103',
			jsDelegate: \"delegate\",
			maxFileSize: \"999999999\",
			maxTotalSize: \"999999999\"
		};

    swfobject.embedSWF(\"#{KalturaFu.config[:service_url]}/kupload/ui_conf_id/1103\", \"uploader\", \"160\", \"26\", \"9.0.0\", \"expressInstall.swf\", flashVars, params,attributes);

	</script>"
end