Module: KalturaBox::ViewHelpers

Defined in:
lib/kaltura_box/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_box(*args) ⇒ Object

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



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

def include_kaltura_box(*args)
  content = javascript_include_tag('kaltura_upload')
  content << javascript_include_tag('//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: KalturaBox.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.



74
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_box/view_helpers.rb', line 74

def kaltura_player_embed(entry_id,options={})
  player_conf_parameter = "/uiconf_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 KalturaBox.config.player_conf_id.nil?
      player_conf_parameter += "#{KalturaBox.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\",
      bgcolor: \"#000000\"
    };
    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(\"#{KalturaBox.config.service_url}/kwidget/wid/_#{KalturaBox.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>".html_safe
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.



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

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.



33
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
# File 'lib/kaltura_box/view_helpers.rb', line 33

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 KalturaBox.config.thumb_width && KalturaBox.config.thumb_height
      size_parameters = "/width/#{KalturaBox.config.thumb_width}/height/" +
      "#{KalturaBox.config.thumb_height}"
    end
  end

  unless options[:second].nil?
    seconds_parameter = "/vid_sec/#{options[:second]}"
  else
    seconds_parameter = "/vid_sec/5"
  end

  image_tag("#{KalturaBox.config.service_url}/p/#{KalturaBox.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
162
# File 'lib/kaltura_box/view_helpers.rb', line 132

def kaltura_upload_embed(options={})
  client = KalturaBox::Client.update_session
  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: \"#{KalturaBox.config.partner_id}\",
      subPId: \"#{KalturaBox.config.partner_id}00\",
      entryId: \"-1\",
      ks: \"#{client.session_key}\",
      uiConfId: '4211621',
      jsDelegate: \"delegate\",
      maxFileSize: \"999999999\",
      maxTotalSize: \"999999999\"
    };

    swfobject.embedSWF(\"#{KalturaBox.config.service_url}/kupload/ui_conf_id/4211621\", \"uploader\", \"160\", \"26\", \"9.0.0\", \"expressInstall.swf\", flashVars, params,attributes);

  </script>".html_safe
end