aboutsummaryrefslogtreecommitdiff
path: root/includes/common.inc
blob: ce9d89ca71b489f5b81b72436769b79b95ab0d87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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
61
62
63
64
65
66
67
68
69
70
71
72
73
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
125
126
127
128
129
130
131
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
<?php
//$Id$
/**
 * @file
 * Add some common functions for the various video types supported
 *
 * @todo   Configure default players by video filetype (user configurable?)
 */


/**
 * Get the object for the suitable player for the parameter resource
 */
function _video_common_get_player($element) {
  $field = content_fields($element['#field_name'], $element['#type_name']);
  $resolution = array_filter(explode(':', $field['widget']['default_resolution']));
  $element['#item']['data']['height'] = $element['#item']['data']['width'] * ($resolution[1]/$resolution[0]);

  $op = _video_get_filetype($element['#item']['filename']);
  //play HQ mp4 videos in flash player
  if(variable_get('mp4_play_in_flowplayer', FALSE) && $op == 'mp4'){
    $op = 'mp4f';
  }
  switch ($op) {
    case 'divx':
      return theme('video_play_divx', $element);
    case 'mov':
    case '3gp':
    case '3g2':
    case 'mp4': // video/mp4
      return theme('video_play_quicktime', $element);
    case 'rm':
      return theme('video_play_realmedia', $element);
    case 'mp4f':
    case 'f4v' :
    case 'flv' : // flowplayer also supprts MP4, H.264 (.extension?)
      return theme('video_play_flash', $element);
    case 'swf':
      return theme('video_play_swf', $element);
    case 'dir':
    case 'dcr':
      return theme('video_play_dcr', $element);
    case 'asf':
    case 'wmv':
    case 'avi':
    case 'mpg':
    case 'mpeg':
      return theme('video_play_windowsmedia', $element);
    case 'ogg':
      return theme('video_play_ogg_theora', $element);
    default:
      drupal_set_message('No video player is configured for ' .$op, 'error');
      break;
  }
}


/**
 * Pull the file extension from a filename
 *
 * @param $vidfile
 *   string filename to get the filetype from.
 *
 * @return
 *   string value of file type or boolean FALSE on error
 */
function _video_get_filetype($vidfile) {
  if (strstr($vidfile, '.')) { //If file contains a "." then get the file extension after the ".
    $file_type = end(explode('.', $vidfile));
  }
  else {
    $file_type = FALSE;
  }

  return strtolower($file_type);
}

/*********************************************************************
 * Themeable functions for playing videos. They print a page with a player embedded.
 *********************************************************************/

/**
 * Play videos from in FLV Flash video format
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_play_flash($element) {
//TODO : remove item height set in here
  $video = file_create_url($element['#item']['filepath']);
  //  echo file_create_url($element['#item']['filepath']);
  $width = isset($element['#item']['data']['width']) ? $element['#item']['data']['width'] : '';
  $height = isset($element['#item']['data']['height']) ? $element['#item']['data']['height'] : '';
  $width = empty($width) ? '350px' : $width .'px';
  $height = empty($height) ? '285px' : $height .'px';
  $id = $element['#formatter'];

  if (module_exists('flowplayer')) {
    $output = theme('flowplayer', array(
        'clip' => array(
        'url' =>  $video,
        //TODO: Make settings for this
        'autoPlay' => variable_get('video_autoplay', TRUE), // Turn autoplay off
        'autoBuffering' => variable_get('video_autobuffering', TRUE),
        ),
        ),
        $id, array(
        'style' => "width: $width; height: $height",
        )
    );
  }
  else {
    $output='<p>Use <b>SwfTools Module</b> to play FLV files if you only convert/upload FLV videos or <b>FlowPlayer Module</b> must be enabled in order to play FLV videos with other types.</p>';
  }
  return $output;
}

/**
 * Play Flash .swf files.
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_play_swf($element) {

  $video = file_create_url($element['#item']['filepath']);
  $width = isset($element['#item']['data']['width']) ? $element['#item']['data']['width'] : '';
  $height = isset($element['#item']['data']['height']) ? $element['#item']['data']['height'] : '';
  $width = empty($width) ? '350px' : $width .'px';
  $height = empty($height) ? '285px' : $height .'px';


  // this will be executed by not Internet Explorer browsers
  $output = '<!--[if !IE]> <-->
            <object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
            data="'. $video .'">
            <!--> <![endif]-->' . "\n";

  // this will be executed by Internet Explorer
  $output .= '<!--[if IE]>
             <object type="application/x-shockwave-flash" width="'. $width .'" height="'. $height .'"
             classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
             codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
             <![endif]-->' . "\n";

  // params will be passed to both IE or not IE browsers
  $output .=  '<param name="movie" value="'. $video .'" />'. "\n" .
              '<param name="wmode" value="transparent" />' . "\n"
              . //_video_get_parameters($node) .
              '<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
              </object>';
/*
  $output = theme('video_format_play', $output, t('http://www.macromedia.com/go/getflashplayer'), t('Link to Flash player download'), t('Download the latest Flash player'));*/
  return $output;
}



/**
 * Play Director .dcr/.dir files.
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */

function theme_video_play_dcr($element) {

  $video = file_create_url($element['#item']['filepath']);
  $width = isset($element['#item']['data']['width']) ? $element['#item']['data']['width'] : '';
  $height = isset($element['#item']['data']['height']) ? $element['#item']['data']['height'] : '';
  $width = empty($width) ? '350px' : $width .'px';
  $height = empty($height) ? '285px' : $height .'px';

  // this will be executed by not Internet Explorer browsers
  $output = '<!--[if !IE]> <-->
            <object type="application/x-director" width="'. $width .'" height="'. $height .'"
            data="'. $video .'">
            <!--> <![endif]-->' . "\n";

  // this will be executed by Internet Explorer
  $output .=  '<!--[if IE]>
              <object type="application/x-director" width="'. $width .'" height="'. $height .'"
              classid="clsid:166B1BCA-3F9C-11CF-8075-444553540000"
              codebase="http://download.macromedia.com/pub/shockwave/cabs/director/sw.cab#version=10,0,0,0">
              <![endif]-->' . "\n";

  // params will be passed to both IE or not IE browsers
  $output .=  '<param name="src" value="'. $video .'" />' . "\n"
              . //_video_get_parameters($node) .
              '<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
              </object>';
/*
  $output = theme('video_format_play', $output, t('http://www.macromedia.com/shockwave/download/'),
                                      t('Link to Macromedia Shockwave Player Download Page'),
                                      t('Download latest Shockwave Player'));*/
  return $output;
}

/**
 * Play videos from in DivX format
 *
 * @see http://developer.apple.com/internet/ieembedprep.html
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_play_divx($element) {
//Increase the height to accommodate the player controls on the bottom.
  $video = file_create_url($element['#item']['filepath']);
  $width = isset($element['#item']['data']['width']) ? $element['#item']['data']['width'] : '';
  $height = isset($element['#item']['data']['height']) ? $element['#item']['data']['height'] : '';
  $width = empty($width) ? '350px' : $width .'px';
  $height = empty($height) ? '285px' : $height .'px';

  //$url = _video_get_fileurl($node->vidfile);

  $output = '<!-- [if IE] -->
            <object classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616" width="'.$width.'" height="'.$height.'" codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab">
            <!--> <![endif]-->'. "\n";
  // this will be executed by not Internet Explorer browsers
  $output = '<!-- [if !IE] -->
            <object type="video/divx" data="'.$video.'" width="'.$width.'" height="'.$height.'" mode="zero">
            <!--> <![endif]-->'."\n";

  $output .= '<param name="src" value="'.$video.'"/>'."\n";
  $output .= '<param name="mode" value="zero"/>'."\n";
  $output .= '</object>';
  /*
  $output = theme('video_format_play', $output,t('http://www.divx.com/divx/webplayer/'),
                                     t('Link to DivX Download Page'),
                                     t('Download latest DivX Web Player'));*/
  return $output;
}

/**
 * Play videos from in Quicktime format
 *
 * @see http://developer.apple.com/internet/ieembedprep.html
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_play_quicktime($element) {
//Increase the height to accommodate the player controls on the bottom.
  $video = file_create_url($element['#item']['filepath']);
  $width = isset($element['#item']['data']['width']) ? $element['#item']['data']['width'] : '';
  $height = isset($element['#item']['data']['height']) ? $element['#item']['data']['height'] : '';
  $width = empty($width) ? '350px' : $width .'px';
  $height = empty($height) ? '285px' : $height .'px';


  // this will be executed by not Internet Explorer browsers
  $output = '<!--[if !IE]> <-->
            <object type="video/quicktime" width="'. $width .'" height="'. $height .'"
            data="'. $video .'">
            <!--> <![endif]-->' . "\n";

  // this will be executed by Internet Explorer
  $output .=  '<!--[if IE]>
              <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
              codebase="http://www.apple.com/qtactivex/qtplugin.cab"
              width="'. $width .'" height="'. $height .'" scale="tofit" >
              <![endif]-->' . "\n";

  // params will be passed to both IE or not IE browsers
  //GMM: kioskmode enabled so users don't bypass download security video through player
  $output .= '<param name="src" value="'. $video .'" />
              <param name="AUTOPLAY" value="'.(variable_get('video_autoplay', TRUE) ? TRUE : FALSE).'" />
              <param name="KIOSKMODE" value="true" />
              <param name="CONTROLLER" value="true" />' . "\n"
              . //_video_get_parameters($node) .
              '<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
              </object>'; // only one </object> needed becouse only one opening tag has been parsed by browsers

  return $output;
}

/**
 * Play videos from in Realmedia format
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_play_realmedia($element) {
// Real's embeded player includes the controls
// in the height
  $video = file_create_url($element['#item']['filepath']);
  $width = isset($element['#item']['data']['width']) ? $element['#item']['data']['width'] : '';
  $height = isset($element['#item']['data']['height']) ? $element['#item']['data']['height'] : '';
  $width = empty($width) ? '350px' : $width .'px';
  $height = empty($height) ? '285px' : $height .'px';

  // this will be executed by not Internet Explorer browsers
  $output = '<!--[if !IE]> <-->
            <object type="audio/x-pn-realaudio-plugin" width="'. $width .'" height="'. $height .'"
            data="'. $video .'">
            <!--> <![endif]-->' . "\n";

  // this will be executed by Internet Explorer
  $output .=  '<!--[if IE]>
              <object type="audio/x-pn-realaudio-plugin" width="'. $width .'" height="'. $height .'"
              classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" >
              <![endif]-->' . "\n";

  // params will be passed to both IE or not IE browsers
  $output .= '<param name="src" value="'. $video .'" />
              <param name="_ExtentX" value="7276" />
              <param name="" value="3307" />
              <param name="AUTOSTART" value="'.(variable_get('video_autoplay', TRUE) ? 'true' : 'false').'" />
              <param name="SHUFFLE" value="0" />
              <param name="PREFETCH" value="0" />
              <param name="NOLABELS" value="0" />
              <param name="CONTROLS" value="All" />
              <param name="CONSOLE" value="Clip1" />
              <param name="LOOP" value="0" />
              <param name="NUMLOOP" value="0" />
              <param name="CENTER" value="0" />
              <param name="MAINTAINASPECT" value="1" />
              <param name="BACKGROUNDCOLOR" value="#000000" />'
              . //_video_get_parameters($node) .
              '<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
              </object>'; // only one </object> needed becouse only one opening tag has been parsed by browsers

/*
  $output = theme('video_format_play', $output, t('http://www.real.com/'),
                                      t('Link to Real'),
                                      t('Download latest Realmedia Player'));*/
  return $output;
}

/**
 * Play videos from in WindowsMediaVideo format
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_play_windowsmedia($element) {
// Windows Media's embeded player includes the controls in the height
  $video = file_create_url($element['#item']['filepath']);
  $width = isset($element['#item']['data']['width']) ? $element['#item']['data']['width'] : '';
  $height = isset($element['#item']['data']['height']) ? $element['#item']['data']['height'] : '';
  $width = empty($width) ? '350px' : $width .'px';
  $height = empty($height) ? '285px' : $height .'px';

  // this will be executed by not Internet Explorer browsers
  $output = '<!--[if !IE]> <-->
            <object type="application/x-mplayer2" width="'. $width .'" height="'. $height .'"
            data="'. $video .'">
            <!--> <![endif]-->' . "\n";

  // this will be executed by Internet Explorer
  $output .=  '<!--[if IE]>
              <object type="application/x-oleobject" width="'. $width .'" height="'. $height .'"
              classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" >
              <![endif]-->' . "\n";

  // params will be passed to both IE or not IE browsers
  $output .= '<param name="src" value="'. $video .'" />
              <param name="URL" value="'.$video.'" />
              <param name="animationatStart" value="true" />
              <param name="transparentatStart" value="true" />
              <param name="autoStart" value="'.(variable_get('video_autoplay', TRUE) ? 'true' : 'false').'" />
              <param name="showControls" value="true" />
              <param name="loop" value="true" />'
              . //_video_get_parameters($node) .
              '<p>'. t('Your browser is not able to display this multimedia content.') .'</p>
              </object>'; // only one </object> needed becouse only one opening tag has been parsed by browsers

  return $output;
}




/**
 * Play Ogg Theora videos with Cortado Applet
 *
 * @param $node
 *   object with node information
 *
 * @return
 *   string of content to display
 */
function theme_video_play_ogg_theora($element) {
  global $base_url;
  $cortado_location = variable_get('video_cortado', $base_url . '/cortado.jar');
  //$url = _video_get_fileurl($node->vidfile);
  $video = file_create_url($element['#item']['filepath']);

  $width = ($node->video_scaled_x ? $node->video_scaled_x : '425');
  $height = ($node->video_scaled_y ? $node->video_scaled_y : '350');

  $output = '
  <!--[if !IE]>-->
  <object classid="java:com.fluendo.player.Cortado.class"
          type="application/x-java-applet"
          archive="' . $cortado_location . '"
          width="' . $width . '" height="' . $height . '" >
  <!--<![endif]-->
    <object classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
              codebase="http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab"
              width="' . $width . '" height="' . $height . '" >
        <param name="code" value="com.fluendo.player.Cortado" />
    <!--[if !IE]>-->
    </object>
    <!--<![endif]-->
      <!-- IE and Konqueror browser need the archive param -->
      <param name="archive" value="' . $cortado_location . '" />
      <param name="url" value="' . $video . '"/>
      <param name="local" value="false" />
      <param name="keepaspect" value="true" />
      <param name="video" value="true" />
      <param name="audio" value="true" />
      <param name="seekable" value="true" />
      <param name="duration" value="' . $node->playtime_seconds . '" />
      <param name="bufferSize" value="200" />
      <strong>
          This browser does not have a Java Plug-in.<br />
          <a href="http://java.com/download/">
            Get the latest Java Plug-in here.
          </a>
      </strong>
  </object>
  ';
/*
  $output = theme('video_format_play', $output,
    t('http://java.com/download/'), t('Link to java.com'), t('Download Java'));*/
  return $output;
}