From 69927fc15c744bd3602fe7d404af6a80130a1ce9 Mon Sep 17 00:00:00 2001
From: Heshan <heshan@heidisoft.com>
Date: Fri, 18 Mar 2011 00:13:45 +0530
Subject: Fixed the JS issues and Select players and trasncoders

---
 js/video.js                           | 182 ++++++++++++++++------------------
 modules/video_ui/video.admin.inc      |  26 +++--
 transcoders/video_ffmpeg.inc          |   4 +-
 transcoders/video_phpvideotoolkit.inc |  30 +++++-
 video.install                         |   2 +
 video.module                          |  13 +--
 6 files changed, 137 insertions(+), 120 deletions(-)

diff --git a/js/video.js b/js/video.js
index 4a23b53..fc2fa7f 100644
--- a/js/video.js
+++ b/js/video.js
@@ -5,119 +5,105 @@
  *
  */
 (function($){
-
-  $(document).ready(function() {
-    //lets see if we have any jmedia movies
-    if($.fn.media) {
-      $('.jmedia').media();
-    }
+  Drupal.behaviors.video = {
+    attach: function (context, settings) {
+      //lets see if we have any jmedia movies
+      if($.fn.media) {
+        $('.jmedia').media();
+      }
 	
-    video_hide_all_options();
-    $("input[name='video_convertor']").change(function() {
       video_hide_all_options();
-    });
+      $("input[name='video_convertor']").change(function() {
+        video_hide_all_options();
+      });
 
-    // change metadata options
-    video_hide_all__metadata_options();
-    $("input[name='video_metadata']").change(function() {
+      // change metadata options
       video_hide_all__metadata_options();
-    });
-
-    // change metadata options
-    video_hide_all__filesystem_options();
-    $("input[name='video_filesystem']").change(function() {
-      video_hide_all__filesystem_options();
-    });
+      $("input[name='video_metadata']").change(function() {
+        video_hide_all__metadata_options();
+      });
 
-    $('.video_select').each(function() {
-      var ext = $(this).attr('rel');
-      $('select', this).change(function() {
-        if($(this).val() == 'video_play_flv') {
+      $('.video_select').each(function() {
+        var ext = $(this).attr('rel');
+        $('select', this).change(function() {
+          if($(this).val() == 'video_play_flv') {
+            $('#flv_player_'+ext).show();
+          } else {
+            $('#flv_player_'+ext).hide();
+          }
+        });
+        if($('select', this).val() == 'video_play_flv') {
           $('#flv_player_'+ext).show();
-        } else {
-          $('#flv_player_'+ext).hide();
         }
       });
-      if($('select', this).val() == 'video_play_flv') {
-        $('#flv_player_'+ext).show();
-      }
-    });
 	
-    if(Drupal.settings.video) {
-      $.fn.media.defaults.flvPlayer = Drupal.settings.video.flvplayer;
+      if(settings.video) {
+        $.fn.media.defaults.flvPlayer = settings.video.flvplayer;
 
-    }
+      }
 	
-    //lets setup our colorbox videos
-    $('.video-box').each(function() {
-      var url = $(this).attr('href');
-      var data = $(this).metadata();
-      var width = data.width;
-      var height= data.height;
-      var player = Drupal.settings.video.player; //player can be either jwplayer or flowplayer.
-      $(this).colorbox({
-        html: '<a id="video-overlay" href="'+url+'" style="height:'+height+'; width:'+width+'; display: block;"></a>',
-        onComplete:function() {
-          if(player == 'flowplayer') {
-            flowplayer("video-overlay", Drupal.settings.video.flvplayer, {
-              clip: {
-                autoPlay: Drupal.settings.video.autoplay,
-                autoBuffering: Drupal.settings.video.autobuffer
-              }
-            });
-          } else {
-            $('#video-overlay').media({
-              flashvars: {
-                autostart: Drupal.settings.video.autoplay
-              },
-              width:width,
-              height:height
-            });
+      //lets setup our colorbox videos
+      $('.video-box').each(function() {
+        var url = $(this).attr('href');
+        var data = $(this).metadata();
+        var width = data.width;
+        var height= data.height;
+        var player = settings.video.player; //player can be either jwplayer or flowplayer.
+        $(this).colorbox({
+          html: '<a id="video-overlay" href="'+url+'" style="height:'+height+'; width:'+width+'; display: block;"></a>',
+          onComplete:function() {
+            if(player == 'flowplayer') {
+              flowplayer("video-overlay", settings.video.flvplayer, {
+                clip: {
+                  autoPlay: settings.video.autoplay,
+                  autoBuffering: settings.video.autobuffer
+                }
+              });
+            } else {
+              $('#video-overlay').media({
+                flashvars: {
+                  autostart: settings.video.autoplay
+                },
+                width:width,
+                height:height
+              });
+            }
           }
-        }
+        });
       });
-    });
-  });
-})(jQuery);
-
-function video_hide_all_options() {
-  $("input[name='video_convertor']").each(function() {
-    var id = $(this).val();
-    $('#'+id).hide();
-    if ($(this).is(':checked')) {
-      $('#' + id).show();
     }
-  });
-}
+  };
 
-function videoftp_thumbnail_change() {
-  // Add handlers for the video thumbnail radio buttons to update the large thumbnail onchange.
-  $(".video-thumbnails input").each(function() {
-    var path = $(this).val();
-    if($(this).is(':checked')) {
-      var holder = $(this).attr('rel');
-      $('.'+holder+' img').attr('src', Drupal.settings.basePath + path);
-    }
-  });
 
-}
+  function video_hide_all_options() {
+    $("input[name='video_convertor']").each(function() {
+      var id = $(this).val();
+      $('#'+id).hide();
+      if ($(this).is(':checked')) {
+        $('#' + id).show();
+      }
+    });
+  }
+
+  function videoftp_thumbnail_change() {
+    // Add handlers for the video thumbnail radio buttons to update the large thumbnail onchange.
+    $(".video-thumbnails input").each(function() {
+      var path = $(this).val();
+      if($(this).is(':checked')) {
+        var holder = $(this).attr('rel');
+        $('.'+holder+' img').attr('src', settings.basePath + path);
+      }
+    });
 
-function video_hide_all__metadata_options() {
-  $("input[name='video_metadata']").each(function() {
-    var id = $(this).val();
-    $('#'+id).hide();
-    if ($(this).is(':checked')) {
-      $('#' + id).show();
-    }
-  });
-}
+  }
 
-function video_hide_all__filesystem_options() {
-  $("input[name='video_filesystem']").each(function() {
-    var id = $(this).val();
-    $('#'+id).hide();
-    if ($(this).is(':checked')) {
-      $('#' + id).show();
-    }
-  });
-}
+  function video_hide_all__metadata_options() {
+    $("input[name='video_metadata']").each(function() {
+      var id = $(this).val();
+      $('#'+id).hide();
+      if ($(this).is(':checked')) {
+        $('#' + id).show();
+      }
+    });
+  }
+})(jQuery);
\ No newline at end of file
diff --git a/modules/video_ui/video.admin.inc b/modules/video_ui/video.admin.inc
index 32fc5e8..ed76a20 100644
--- a/modules/video_ui/video.admin.inc
+++ b/modules/video_ui/video.admin.inc
@@ -112,15 +112,23 @@ function video_players_admin_settings() {
       '#suffix' => '</div>',
     );
 
-    $form['extensions']['video_extension_' . $ext . '_flash_player'] = array(
-      '#type' => !empty($flv_players) ? 'radios' : 'markup',
-      '#title' => t('Flash Player for') . ' ' . $ext,
-      '#value' => !empty($flv_players) ? '' : t('No flash players detected.<br />You need to install !swf_tools or !flowplayer.', array('!swf_tools' => l(t('SWF Tools'), 'http://www.drupal.org/project/swftools'), '!flowplayer' => l(t('Flowplayer'), 'http://www.drupal.org/project/flowplayer'))),
-      '#options' => $flv_players,
-      '#default_value' => variable_get('video_extension_' . $ext . '_flash_player', ''),
-      '#prefix' => '<div class="admin_flv_player_wrapper" id="flv_player_' . $ext . '">',
-      '#suffix' => '</div>',
-    );
+    if (!empty($flv_players)) {
+      $form['extensions']['video_extension_' . $ext . '_flash_player'] = array(
+        '#type' => 'radios',
+        '#title' => t('Flash Player for') . ' ' . $ext,
+        '#options' => $flv_players,
+        '#default_value' => variable_get('video_extension_' . $ext . '_flash_player', ''),
+        '#prefix' => '<div class="admin_flv_player_wrapper" id="flv_player_' . $ext . '">',
+        '#suffix' => '</div>',
+      );
+    } else {
+      $form['extensions']['video_extension_' . $ext . '_flash_player'] = array(
+        '#type' => 'markup',
+        '#markup' => t('No flash players detected.<br />You need to install !swf_tools or !flowplayer.', array('!swf_tools' => l(t('SWF Tools'), 'http://www.drupal.org/project/swftools'), '!flowplayer' => l(t('Flowplayer'), 'http://www.drupal.org/project/flowplayer'))),
+        '#prefix' => '<div class="admin_flv_player_wrapper" id="flv_player_' . $ext . '">',
+        '#suffix' => '</div>',
+      );
+    }
   }
   return system_settings_form($form);
 }
diff --git a/transcoders/video_ffmpeg.inc b/transcoders/video_ffmpeg.inc
index cf2ff7f..2cdf417 100644
--- a/transcoders/video_ffmpeg.inc
+++ b/transcoders/video_ffmpeg.inc
@@ -296,7 +296,7 @@ class video_ffmpeg implements transcoder_interface {
     $form = array();
     $form['video_ffmpeg_start'] = array(
       '#type' => 'markup',
-      '#value' => '<div id="video_ffmpeg">',
+      '#markup' => '<div id="video_ffmpeg">',
     );
     $form['video_ffmpeg_nice_enable'] = array(
       '#type' => 'checkbox',
@@ -410,7 +410,7 @@ class video_ffmpeg implements transcoder_interface {
 
     $form['video_ffmpeg_end'] = array(
       '#type' => 'markup',
-      '#value' => '</div>',
+      '#markup' => '</div>',
     );
     return $form;
   }
diff --git a/transcoders/video_phpvideotoolkit.inc b/transcoders/video_phpvideotoolkit.inc
index abd18e0..c9a27a4 100644
--- a/transcoders/video_phpvideotoolkit.inc
+++ b/transcoders/video_phpvideotoolkit.inc
@@ -405,7 +405,7 @@ class video_phpvideotoolkit implements transcoder_interface {
    * @see sites/all/modules/video/includes/transcoder_interface#get_help()
    */
   public function get_help() {
-    return l(t('FFMPEG Online Manual'), 'http://www.ffmpeg.org/');
+    return l(t('PHP Video Toolkit online documentation'), 'http://sourceforge.net/projects/phpvideotoolkit/');
   }
 
   /**
@@ -414,6 +414,34 @@ class video_phpvideotoolkit implements transcoder_interface {
    */
   public function admin_settings() {
     $form = array();
+    $form = array();
+    $form['video_ffmpeg_toolkit_start'] = array(
+      '#type' => 'markup',
+      '#markup' => '<div id="video_phpvideotoolkit">',
+    );
+    $form['phpvideotoolkit']['video_ffmpeg_nice_enable'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Enable the use of <b>nice</b> when calling the command.'),
+      '#default_value' => variable_get('video_ffmpeg_nice_enable', TRUE),
+      '#description' => t('The nice command Invokes a command with an altered scheduling priority.  This option may not be available on windows machines, so disable it.')
+    );
+    // FFMPEG
+    $form['phpvideotoolkit']['transcoders'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Path to Transcoder Executables'),
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE
+    );
+    $form['phpvideotoolkit']['transcoders']['video_ffmpeg_path'] = array(
+      '#type' => 'textfield',
+      '#title' => t('FFMPEG'),
+      '#description' => t('Absolute path to ffmpeg executable. This will provide a token of !ffmpeg to preset commands.'),
+      '#default_value' => variable_get('video_ffmpeg_path', '/usr/bin/ffmpeg'),
+    );
+    $form['video_ffmpeg_toolkit_end'] = array(
+      '#type' => 'markup',
+      '#markup' => '</div>',
+    );
     return $form;
   }
 
diff --git a/video.install b/video.install
index 51d9202..0d1c8e7 100644
--- a/video.install
+++ b/video.install
@@ -195,6 +195,8 @@ function video_install() {
  */
 function video_uninstall() {
   drupal_uninstall_schema('video');
+  // remove variables
+  db_query("DELETE FROM {variable} WHERE name LIKE 'video_%'");
   // Remove the video directory and generated images.
   file_unmanaged_delete_recursive(file_default_scheme() . '://videos');
 }
\ No newline at end of file
diff --git a/video.module b/video.module
index 4f23168..52391cb 100644
--- a/video.module
+++ b/video.module
@@ -256,16 +256,9 @@ function video_thumb_process(&$element, &$form_state) {
  * Implementation of hook_file_delete().
  */
 function video_file_delete($file) {
-  // @TODO : check for enable trancoder
-  // delete the transcoder job
-  $transcoder = new video_transcoder;
-  $transcoder->delete_job($file);
-
-  //now lets delete our video thumbnails and folder.
-  $video_thumb_path = variable_get('video_thumb_path', 'videos/thumbnails');
-  $thumb_folder = file_default_scheme() . ':/' . $video_thumb_path . '/' . $file->fid;
-  // Recursively delete our folder and files
-  rmdirr($thumb_folder);
+  db_delete('video_files')
+      ->condition('fid', $file->fid)
+      ->execute();
 }
 
 /**
-- 
cgit v1.2.3