aboutsummaryrefslogtreecommitdiff
path: root/types/video_upload/video_upload.module
blob: 5ad1a837651dfeed21ac774ad7490a962a2ec13b (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
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
<?php
// $Id$
/**
 * @file video.module
 *
 * @author Heshan Wanigasooriya <heshan at heidisoft dot com>
 *                              <heshanmw at gmail dot com>
 * @author Glen Marianko Twitter@demoforum <glenm at demoforum dot com>
 * @todo implement the help of the video upload (Implement the internal hook for the help video_upload_v_help()).
 * @todo GMM: video upload allowed extensions broken, all uploads allowed
 * Ajax based upload
 * Progress bar on upload
 */


/**
 * Implementation of hook_menu
*/
function video_upload_menu() {
  $items = array();

  $items['node/add/video/upload'] = array(
    'title' => 'Upload',
    'access arguments' => array('create video')
  );
  $items['admin/settings/video/upload'] = array(
    'title' => 'Upload',
    'description' => 'Configure various settings of the video upload plugin.',
    'access arguments' => array('administer site configuration'),
    'page callback' => 'drupal_get_form',
    'page arguments' => array('video_upload_admin_settings'),
    'type' => MENU_NORMAL_ITEM,
  );
  return $items;
}


/**
 * Setting form for video_upload
*/
function video_upload_admin_settings() {
  $form = array();

  $form['video_upload_allowed_extensions'] = array(
    '#type' => 'textfield',
    '#title' => t('Allowed extensions'),
    '#description' => t('A comma separated list of video extesions uploadable with the video upload feature. Do not insert any space.'),
    '#default_value' => variable_get('video_upload_allowed_extensions', 'mov,flv,wmv'),
  );

  $form['video_upload_path_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Pattern for the file prefix'),
    '#description' => t('Specify the pattern to prefix to file names uploaded with the video_upload module.  It will be appended after the site files directory (e.g., files) but before the file name itself.  Do not include a leading or trailing slash.  Spaces will be converted to underscores to avoid file system issues.'),
    '#default_value' => variable_get('video_upload_path_prefix', 'videos'),
  );

  $form['token_help'] = array(
    '#title' => t('Replacement patterns'),
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#description' => t('Prefer raw-text replacements for text to avoid problems with HTML entities!'),
  );
  $form['token_help']['help'] = array(
    '#value' => theme('token_help', 'node'),
  );

  return system_settings_form($form);
}


/**
 * Implementation of hook_cron().
 * Look for uploaded videos which have not been submitted (only previews) and
 * delete them
 */
function video_upload_cron() {
  /* look for crusty files */
  $temppath = file_directory_temp() . '/video/';
  $files = file_scan_directory(file_create_path($temppath), '.*');
  foreach ($files as $file => $info) {
    if (time() - filemtime($file) > 60*60*6) {
      db_query("DELETE FROM {files} WHERE filename LIKE 'video_upload_temp.%' AND nid = 1 AND filepath = '%s'", $file);
      file_delete($file);
    }
  }
}




/**
 * Implementation of hook_v_help
*/
function video_upload_v_help() {

  $help = array();
  $help['upload']['data'] = '<b>' . t('Upload support') . '</b>';
  $help['upload']['children'] = array(t('You can upload a video file from your computer to this website.'));

  return $help;
}


/**
 * Implementation of hook_v_info()
*/
function video_upload_v_info() {
  $info['upload'] = array(
    '#name' => 'Upload Video',
    '#description' => t('Post a video available on your computer as a file to this website.'),
    '#downloadable' => true,
    '#autothumbable' => module_exists('video_ffmpeg_helper') && variable_get('video_image_auto_thumbnail', false),
    '#autoresolution' => module_exists('video_ffmpeg_helper') && variable_get('video_ffmpeg_helper_auto_resolution', false),
    '#autoplaytime' => module_exists('video_ffmpeg_helper') && variable_get('video_ffmpeg_helper_auto_playtime', false),
  );

  return $info;
}


/**
 * Implements the hook_v_auto_thumnail
*/
function video_upload_v_auto_thumbnail(&$node) {
  // as we rely on ffmpeg_helper, let's check if we have video_ffmpeg_helper_installed
  if(module_exists('video_ffmpeg_helper')) {
    return _video_ffmpeg_helper_auto_thumbnail($node);
  }
  return false;
}


/**
 * Implements the hook_v_auto_resolution
*/
function video_upload_v_auto_resolution(&$node) {
  // as we rely on ffmpeg_helper, let's check if we have video_ffmpeg_helper_installed
  if(module_exists('video_ffmpeg_helper')) {
    return _video_ffmpeg_helper_auto_resolution($node);
  }
  return false;
}


/**
 * Implements the hook_v_auto_resolution
*/
function video_upload_v_auto_playtime(&$node) {
  // as we rely on ffmpeg_helper, let's check if we have video_ffmpeg_helper_installed
  if(module_exists('video_ffmpeg_helper')) {
    return _video_ffmpeg_helper_auto_playtime($node);
  }
  return false;
}


/**
 * Implements the hook_v_download
*/
function video_upload_v_download($node) {
  // the code below comes from the audio.module

  // The mime_header_encode function does not (yet) support
  // quoted-string encoding of ASCII strings with special
  // characters.  See discussion at http://drupal.org/node/82614
  $filename = basename($node->current_video_upload_file->filename);
  // If the string contains non-ASCII characters, process it through
  // the mime_header_encode function.
  if (preg_match('/[^\x20-\x7E]/', $filename)) {
    $filename = mime_header_encode($filename);
  }
  // Otherwise, if the string contains special characters (like
  // space), perform quoted-string encoding.
  elseif (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $filename)) {
    $filename = '"'. str_replace('"', '\"', $filename) .'"';
  }
  $headers = array(
    'Content-Type: '. mime_header_encode($node->current_video_upload_file->filemime),
    'Content-Length: '. $node->current_video_upload_file->filesize,
    'Content-Disposition: attachment; filename='. $filename,
  );
  video_upload_file_transfer($node->current_video_upload_file->filepath, $headers);
}


/**
 * Variation on Drupal's file_transfer() function. The only difference
 * is that set_time_limit() is called to allow for large files.

 * This code comes from audio module
 *
 * @param $source File to transfer.
 * @param $headers An array of http headers to send along with file.
 */
function video_upload_file_transfer($source, $headers) {
  ob_end_clean();

  foreach ($headers as $header) {
    // To prevent HTTP header injection, we delete new lines that are
    // not followed by a space or a tab.
    // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.2
    $header = preg_replace('/\r?\n(?!\t| )/', '', $header);
    header($header);
  }

  $source = file_create_path($source);

  // Transfer file in 1024 byte chunks to save memory usage.
  if ($fd = fopen($source, 'rb')) {
    if (!ini_get('safe_mode')){
      set_time_limit(0);
    }
    while (!feof($fd)) {
      print fread($fd, 1024);
      ob_flush();
      flush();
    }
    fclose($fd);
  }
  else {
    drupal_not_found();
  }
  exit();
}


/**
 * Implementation of hook_v_form()
*/
function video_upload_v_form(&$node, &$form) {
  //print 'form';

  // add js stuff for the 'upload in progess' message
  theme('video_upload_get_script');
  // add hidden html used for the 'upload in progess' message
  $form['#suffix'] = theme('video_upload_busy');

  // required for upload to work
  $form['#attributes']['enctype'] = 'multipart/form-data';

  $form['video'] += _video_upload_form($node);

  return $form;
}



/**
 * Implementation of hook_nodeapi()
 */
function video_upload_nodeapi(&$node, $op, $teaser, $page) {


  if($node->type == 'video' && $node->vtype == 'upload') {
    switch ($op) {

      case 'load':
          //exit;
          //print_r($node);
          //exit;
        return _video_upload_load($node);
        break;

      case 'prepare':
          //exit;
        _video_upload_prepare($node);
        break;

      case 'validate':
          //exit;
         //_video_upload_validate($node);
        break;

      case 'presave':
          //exit;
        _video_upload_presave($node);
        break;

      case 'insert':

        _video_upload_insert($node);
        ////_video_upload_validate($node);
        break;

      case 'update':
         // exit;
        _video_upload_update($node);
        break;

      case 'delete':
          //exit;
        _video_upload_delete($node);
        break;

      case 'delete revision':
          //exit;
        video_upload_delete_revision($node);
        break;

      case 'view':
         // exit;
        _video_upload_view($node);
    }
  }
}



function _video_upload_load(&$node) {

  $fileBuf = db_fetch_object(db_query('SELECT fid FROM {video_upload} WHERE nid = %d', $node->nid));
  $output = array();
  $output['video_fid'] = $fileBuf->fid;
  $file = _video_upload_get_file($output['video_fid']);
  //GMM: If original file is deleted from {files} refer to the encoded file
    if($node->serial_data['video_encoded_fid'])
	$node->encoded_video_upload_file = _video_upload_get_file($node->serial_data['video_encoded_fid']);
    if(!$file) {
	$output['video_fid'] = $node->serial_data['video_encoded_fid'];
	$file = $node->encoded_video_upload_file;
    }
  $output['current_video_upload_file'] = $file;
  $output['vidfile'] = file_create_url($file->filepath);
  // set the filesize
  $output['size'] = $file->filesize;
  //print_r($output);
  return $output;
}


/*
The following hooks implementation is pretty Drupal voodoo :-) .. you should be
pretty confortable on drupal apis. See
http://www.varesano.net/blog/fabio/understanding+drupal+hook+nodeapi+execution+order
for some hints
*/

function _video_upload_prepare(&$node) {

  if (!count($_POST))
    return;
}

/**
* Create video upload specific form fields
*/
function _video_upload_form(&$node) {
  _video_upload_check_settings();

  $form = array();

  if($node->new_video_upload_file) { // there is a newly uploaded file (this has been initialized by _prepare())
    $form['new_video_upload_file_fid'] = array('#type' => 'hidden', '#value' => $node->new_video_upload_file->fid);
    $form['new_video_upload_file_info'] = array('#type' => 'item', '#value' => theme('video_upload_file_info_form', $node->new_video_upload_file, $node), '#weight' => -10);

    $we_have_video = true;
  }
  else {
    //$form['new_video_upload_file_fid'] = array('#type' => 'hidden', '#value' => 0);
    if($node->current_video_upload_file) { // we don't have a new file
      $form['current_video_upload_file_fid'] = array('#type' => 'hidden', '#value' => $node->current_video_upload_file->fid);
      $form['current_video_upload_file_info'] = array('#type' => 'item', '#value' => theme('video_upload_file_info_form', $node->current_video_upload_file, $node), '#weight' => -10);

      $we_have_video = true;
    }
  }
  $form['new_video_upload_file_fid'] = array('#type' => 'hidden', '#value' => 0);
  $form['video_upload_file'] = array(
    '#type' => 'file',
    '#title' => $we_have_video ? t('Replace with') : t('Upload video file'),
    '#size' => 40,
    '#weight' => -9,
    '#description' => t('Choose a video file from your pc.<br /><b>NOTE:</b> The max upload size is') . ' ' . format_size(file_upload_max_size()) . '.',
    // no need to set this as required as we do validation in the validate nodeapi hook
  );

  return $form;
}


/**
 * Validate video file
 */
function video_upload_v_validate(&$node) {
  // in Drupal 6 version all file size and the type validations are done by the file API's
}


function _video_upload_presave(&$node) {
  //print 'submit';

  //print_r($node); die;
  // ####### Prepare by moving file to the temp location and then checking the validations of fields

  if (is_object($node->video_upload_file)) {
    $file_field = $node->video_upload_file;
  } else {
    $file_field = 'video_upload_file';
  }

  // get extention array
  $extensions = explode(",",variable_get('video_upload_allowed_extensions', 'mov,flv,wmv'));

  $validators = array(
    'file_validate_extensions' => array( 'csv' ),
  );
  // TODO : add file size validation
  // 'file_validate_size' => array($limits['file_size'], $limits['user_size']),


  //GMM: Fix hard-coded allowed extensions
  if (count($_POST) && $file = file_save_upload($file_field , array('file_validate_extensions' => array(implode(" ",$extensions))))) { // a file has been uploaded
    $node->new_video_upload_file = $file;
    $node->new_video_upload_file_fid = $file->fid;
      //print_r($file);
  //exit;
  }
  else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Submit') {
    $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
  }
  else if (($node->new_video_upload_file_fid || $_POST['new_video_upload_file_fid']) && $_POST['op'] == 'Preview') {
    $node->new_video_upload_file = _video_upload_get_file($_POST['new_video_upload_file_fid']);
  }
  //$node->new_video_upload_file_fid = $file->fid;

  //

  // ####### Start Perpare to save ###############
  if($node->new_video_upload_file_fid) {
    $fid = $node->new_video_upload_file_fid;
  }
  else {
    $fid = $node->current_video_upload_file_fid;
  }
  $node->serial_data['video_fid'] = $fid;
  //GMM: corrected reference from >path to >filepath
  $node->vidfile =  $node->new_video_upload_file->filepath;
  $node->size = $node->new_video_upload_file->filesize;
 // _video_upload_insert($file,$node);
}

function _video_upload_insert(&$node) {
    //print "insert";
    //print_r($node);
    //exit;
  if($node->new_video_upload_file_fid && $file = _video_upload_get_file($node->new_video_upload_file_fid)) { // there is a new file uploaded (now stored on the temp path); need to store in the final directory

    _video_upload_store_file($file, $node);
  }
}

function _video_upload_update(&$node) {

  if($node->new_video_upload_file_fid && $file = _video_upload_get_file($node->new_video_upload_file_fid)) { // there is a new file uploaded (now stored on the temp path)
    //need to store in the final directory
    //exit;
    if($node->current_video_upload_file_fid) {
      // let's delete the old video
      _video_upload_delete_file($node->current_video_upload_file_fid);
    }
    _video_upload_store_file($file, $node);
  }

}

/**
 * Delete files associated to this video node
 */
function _video_upload_delete(&$node) {
  //print 'delete';

  // delete file
  // file_delete($node->current_video_upload_file->path);

  // delete file information from database
  db_query('DELETE FROM {video_upload} WHERE fid = %d', $node->current_video_upload_file->fid);
  //GMM: set original file to be deleted by Drupal cron file garbage collection
    db_query('UPDATE {files} SET status = %d WHERE fid = %d', FILE_STATUS_TEMPORARY, $node->current_video_upload_file->fid);
  //db_query('DELETE FROM {files} WHERE fid = %d', $node->current_video_upload_file->fid);
}


/**
 *
*/
function _video_upload_view(&$node) {
  //print 'view';
}


/**
 * Move a temp file into the final directory associating it with the node
*/
function _video_upload_store_file(&$file, &$node) {

  $file->filename = _video_get_original_filename($file->filename);

  _video_upload_get_path($file, $node);

  if (file_move($file, file_directory_path())) { // file moved successfully
  //GMM: Set uploaded file as permanent if no ffmpeg conversion
    if(variable_get('video_ffmpeg_helper_auto_conversion', false) && !$node->video_ffmpeg_helper_convertion_bypass )
      $status = FILE_STATUS_TEMPORARY; // ffmpeg will use file as source, so let drupal delete the file later
    else
      $status = FILE_STATUS_PERMANENT; // ffmpeg will not be called, this video file will play as-is
    // update the file db entry
    db_query("UPDATE {files} SET filename = '%s', filepath = '%s', filemime = '%s', filesize = %d, status = %d WHERE fid = %d", $file->filename, $file->filepath, $file->filemime, $file->filesize, $status, $file->fid);
    //GMM: delete previous revision, if there was one
      db_query("DELETE FROM {video_upload} WHERE vid = %d AND nid = %d",$node->vid, $node->nid);
    // add an entry in the file_revisions table
    db_query("INSERT INTO {video_upload} (vid, nid, fid) VALUES (%d, %d, %d)", $node->vid, $node->nid, $file->fid);
    // update the file db entry
    //GMM: Remove the serialized encoded fid information in case we're replacing an already encoded video
      if (isset($node->serial_data['video_encoded_fid'])) {
	  //GMM: set rendered video to delete by Drupal cron
            db_query('UPDATE {files} SET status = %d WHERE fid = %d', FILE_STATUS_TEMPORARY, $node->serial_data['video_encoded_fid']);
          $node->serial_data['video_encoded_fid'] = 0;
          db_query("UPDATE {video} SET serialized_data = '%s' WHERE vid = %d", serialize($node->serial_data), $node->vid);
      }
  }
  else {
    drupal_set_message(t('An error occurred during file saving. Your video file has not been stored.'), 'error');
    $rep = array(
      '!path' => $file,
      '!dest' => $dest_path,
    );
    watchdog('video_upload', 'moving file !path to !dest failed', $rep);
  }
}


/**
 * Gets the definitive path for stored videos
*/
function _video_upload_get_path(&$file, &$node) {
  // this code is from uploadpath.module
  $file_name = str_replace(array(' ', "\n", "\t"), '_', token_replace(variable_get('video_upload_path_prefix', 'videos') . '/', 'node', $node)) . $file->filename;

  // Create the directory if it doesn't exist yet.
  $dirs = explode('/', dirname($file_name));
  $directory = file_directory_path();
  while (count($dirs)) {
    $directory .= '/' . array_shift($dirs);
    file_check_directory($directory, FILE_CREATE_DIRECTORY);
  }
  $file->filename = $file_name;
}


/**
 * Get the file object with the given $fid. This function cache its results
*/
function _video_upload_get_file($fid) {
  static $files = array();

  if (!$fid) {
    return NULL;
  }
  if (!isset($files[$fid])) {
    $files[$fid] = db_fetch_object(db_query('SELECT * from {files} WHERE fid = %d', $fid));
  }
  return $files[$fid];
}


/**
 * Delete a file
*/
function _video_upload_delete_file($fid) {

  //GMM: delete file if one requested
  if($fid) {
    //GMM: file_delete($file);
  // delete file information from database
    db_query('DELETE FROM {video_upload} WHERE fid = %d', $fid);
    //GMM: set original file to be deleted by Drupal cron file garbage collection
    db_query('UPDATE {files} SET status = %d WHERE fid = %d', FILE_STATUS_TEMPORARY, $fid);
  }
}


/**
 * Display informations about already uploaded file
 */
function theme_video_upload_file_info_form($file, $node) {
//GMM: let user know we're showing uploaded video stats
  if($node->serial_data['video_encoded_fid']) {
	$ext = split ("\.", basename($node->encoded_video_upload_file->filename));
	$encoded = $ext[count($ext)-1];
  }
// create array containing uploaded file informations
$items = array(
  '<b>'. t('file name') .':</b> ' . _video_get_original_filename(basename($file->filename)) . ($encoded ? '&nbsp;&nbsp;('.t('Auto-encoded to @ext', array("@ext" => strtoupper($encoded))).')' : '' ), // do not display parent folders
  '<b>'. t('file size') .':</b> ' . format_size($file->filesize) . ($node->serial_data['video_encoded_fid']&&$node->serial_data['video_encoded_fid']!=$file->fid ? '&nbsp;&nbsp;('.format_size($node->encoded_video_upload_file->filesize).' '.t('encoded').')' : '') ,
  );

  // create information list
  $output .= theme_item_list($items, t('uploaded video information:'));

  return $output;
}


/**
 * Return the original filename (without 'video_upload_temp.')
*/
function _video_get_original_filename($filename) {
  if(strpos($filename, 'video_upload_temp.') === 0) {
    return substr($filename, strlen('video_upload_temp.'));
  }
  return $filename;
}


/**
 * Verify the video_upload module settings.
 */
function _video_upload_check_settings() {

  /*
  // File paths
  $video_path = file_create_path(variable_get('video_upload_default_path', 'videos'));
  $temp_path = rtrim($video_path, '/') . '/temp';

  if (!file_check_directory($video_path, FILE_CREATE_DIRECTORY, 'video_upload_default_path')) {
    return false;
  }
  if (!file_check_directory($temp_path, FILE_CREATE_DIRECTORY, 'video_upload_default_path')) {
    return false;
  }
  */
  return true;

}



/**
 * Import the video_upload.js script
 */
function theme_video_upload_get_script() {
  drupal_add_js(drupal_get_path('module', 'video_upload') . '/video_upload.js');
}


/**
 * Renders a 'upload in progress' message
*/
function theme_video_upload_busy() {
  return '<div id="sending" style="display: none;">
         <h3>' . t('Sending video... please wait.') . '</h3>
            <img src="'. base_path() . drupal_get_path('module', 'video_upload') . '/busy.gif'.'" alt="' . t('Sending video... please wait.') . '"/>
            <p>'. t('Please wait while your video is uploading.') . '<br /><a href="#" id="video_upload_cancel_link">' . t('abort upload.') . '</a></p>
            </div>';
}


/**
 * Implementation of hook_v_play
*/
function video_upload_v_play($node) {
  module_load_include('inc', 'video', '/includes/common');
  return _video_common_get_player($node);
}


/**
 * Function to other modules to use to create image nodes.
 *
 * @param $filepath
 *   String filepath of an image file. Note that this file will be moved into
 *   the image module's images directory.
 * @param $title
 *   String to be used as the node's title. If this is ommitted the filename
 *   will be used.
 * @param $body
 *   String to be used as the node's body.
 * @param $taxonomy
 *   Taxonomy terms to assign to the node if the taxonomy.module is installed.
 * @return
 *   A node object if the node is created successfully or FALSE on error.
 */
function video_upload_create_node_from($filepath, $title = NULL, $body = '', $taxonomy = NULL) {
  global $user;

  if (!user_access('create video')) {
    drupal_access_denied();
  }

  if (!is_object($filepath)) {
    $p = $filepath;
    $filepath = new stdClass();
    $filepath->filepath = $p;
    $filepath->filename = basename($p);
    $filepath->filesize = filesize($p);
  }

  // Ensure it's a valid video
  //if (!$image_info = image_get_info($filepath)) {
  //  return FALSE;
  //}

  // Build the node.
  $node = new stdClass();
  $node->type = 'video';
  $node->vtype = 'upload';
  $node->uid = $user->uid;
  $node->name = $user->name;
  $node->title = isset($title) ? $title : basename($filepath);
  $node->body = $body;

  // Set the node's defaults... (copied this from node and comment.module)
  $node_options = variable_get('node_options_'. $node->type, array('status', 'promote'));
  $node->status = in_array('status', $node_options);
  $node->promote = in_array('promote', $node_options);
  if (module_exists('comment')) {
    $node->comment = variable_get("comment_$node->type", COMMENT_NODE_READ_WRITE);
  }
  if (module_exists('taxonomy')) {
    $node->taxonomy = $taxonomy;
  }
  $node->video_upload_file = $filepath;
  node_invoke_nodeapi($node, 'prepare');
  $node->new_video_upload_file_fid = $node->new_video_upload_file->fid;

  // Save the node.
  $node = node_submit($node);
  node_save($node);

  // Remove the original image now that the import has completed.
  file_delete($original_path);

  return $node;
}

/**
 * Implementation of hook_theme().
 */
function video_upload_theme() {
  return array(
    'video_upload_busy' => array(
      'arguments' => array(),
    ),
    'video_upload_file_info_form' => array(
      'arguments' => array('file' => NULL,'node' => NULL),
    ),
    'video_upload_get_script' => array(
      'arguments' => array(),
    ),
        'video_play_dcr' => array(
      'arguments' => array('node' => NULL),
    ),
        'video_play_divx' => array(
      'arguments' => array('node' => NULL),
    ),
        'video_play_flash' => array(
      'arguments' => array('node' => NULL),
    ),
        'video_play_ogg_theora' => array(
      'arguments' => array('node' => NULL),
    ),
        'video_play_quicktime' => array(
      'arguments' => array('node' => NULL),
    ),
       'video_play_realmedia' => array(
      'arguments' => array('node' => NULL),
    ),
      'video_play_swf' => array(
      'arguments' => array('node' => NULL),
    ),
      'video_play_windowsmedia' => array(
      'arguments' => array('node' => NULL),
    ),
  );
}