# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: contributions/modules/ffmpeg_converter/ffmpeg_converter.css
--- contributions/modules/ffmpeg_converter/ffmpeg_converter.css Base (1.1)
+++ contributions/modules/ffmpeg_converter/ffmpeg_converter.css Locally Deleted
@@ -1,13 +0,0 @@
-@CHARSET "UTF-8";
-
-/* $Id: ffmpeg_converter.css,v 1.1 2009/01/26 17:12:41 zoo33 Exp $ */
-
-.ffmpeg-converter-snapshot-selection .form-radios .form-item {
-  width: 140px;
-  margin-right: 10px;
-  float: left;
-}
-
-.ffmpeg-converter-snapshot-selection .description {
-  clear: both;
-}
Index: contributions/modules/ffmpeg_converter/ffmpeg_converter.module
--- contributions/modules/ffmpeg_converter/ffmpeg_converter.module Base (1.42)
+++ contributions/modules/ffmpeg_converter/ffmpeg_converter.module Locally Modified (Based On 1.42)
@@ -80,266 +80,6 @@
 
 
 /**
- * Implementation of hook_theme().
- */
-function ffmpeg_converter_theme($existing, $type, $theme, $path) {
-  return array(
-    'ffmpeg_converter_video' => array(
-      'template' => 'ffmpeg_converter_video',
-      'arguments' => array(
-        'file' => NULL,
-        'file_path' => NULL,
-        'snapshot' => NULL,
-        'snapshot_path' => NULL,
-        'description' => NULL,
-        'nid' => NULL,
-        'width' => NULL,
-        'height' => NULL,
-        'link_href' => NULL,
-      ),
-    ),
-    'ffmpeg_converter_messages' => array(
-      'template' => 'ffmpeg_converter_messages',
-      'arguments' => array(
-        'messages' => NULL,
-      ),
-    ),
-    'ffmpeg_converter_widget' => array(
-      'arguments' => array('element' => NULL),
-      'file' => 'ffmpeg_converter_theme.inc',
-    ),
-  );
-}
-
-
-/**
- * Implementation of hook_form_alter().
- */
-function ffmpeg_converter_form_alter(&$form, $form_state, $form_id) {
-  if ($form_id == 'content_field_edit_form' && $form['type']['#value'] == 'filefield') {
-    // Add FFmpeg setting to this field type.
-    ffmpeg_converter_field_settings($form, $form_state);
-  }
-  elseif ($form['#id'] == 'node-form' && !empty($form['#field_info'])) {
-    // Check for FFmpeg Converter enabled file fields and alter their behavior.
-    ffmpeg_converter_nodeform($form, $form_state);
-  }
-}
-
-
-/**
- * Add settings to the field settings form.
- *
- * @param $form
- * @param $form_state
- */
-function ffmpeg_converter_field_settings(&$form, $form_state) {
-  
-  $form_item_id = 'ffmpeg_converter_' . $form['#field']['field_name'];
-  
-  $presets = array('disabled' => '<' . t('Disabled') . '>');
-  $presets = array_merge($presets, ffmpeg_converter_presets());
-  
-  $default_field_setting = variable_get($form_item_id, array('preset' => 'disabled', 'hide_original' => 1));
-  
-  $form['field'][$form_item_id] = array(
-    '#type' => 'fieldset',
-    '#title' => 'Automatic FFmpeg conversion',
-    '#description' => t('Use these options to automatically process media files that are uploaded to this field.'),
-    '#collapsible' => true,
-    '#tree' => true,
-  );
-  $form['field'][$form_item_id]['preset'] = array(
-    '#type' => 'select',
-    '#title' => t('FFmpeg Converter preset'),
-    '#description' => t('Choose the <a href="@config_page">FFmpeg Converter preset</a> that you want to use for this field.', array('@config_page' => url('admin/build/ffmpeg_converter'))),
-    '#options' => $presets,
-    '#default_value' => $default_field_setting['preset'],
-  );
-  // TODO: Add option to hide original files.
-  
-  $form['#validate'][] = 'ffmpeg_converter_fieldconfig_validate';
-  $form['#submit'][] = 'ffmpeg_converter_fieldconfig_submit';
-}
-
-
-/**
- * validate submitted field configuration forms.
- */
-function ffmpeg_converter_fieldconfig_validate($form, &$form_state) {
-  $form_item_id = 'ffmpeg_converter_' . $form['#field']['field_name'];
-  if ($form_state['values'][$form_item_id]['preset'] != 'disabled') {
-    if ($form_state['values']['multiple'] != 1 && $form_state['values']['multiple'] < 5) {
-      form_set_error('multiple', t('In order to use a FFmpeg Converter preset with this field, the Multiple value has to be at least 5 or Unlimited. You must either change the Multiple value or disable the FFmpeg Converter setting.'));
-    }
-  }
-}
-  
-
-/**
- * Handle submitted field configuration forms and save FFmpeg field setting.
- */
-function ffmpeg_converter_fieldconfig_submit($form, &$form_state) {
-  $form_item_id = 'ffmpeg_converter_' . $form['#field']['field_name'];
-  variable_set($form_item_id, $form_state['values'][$form_item_id]);
-  // TODO: Add option to hide original files.
-}
-
-
-/**
- * Alter node forms that have file fields that are enabled for this module.
- * We can't alter the output of each file field instance here, so we save the 
- * values we need in the $form array and pick them up later.
- *
- * @param $form
- * @param $form_state
- */
-function ffmpeg_converter_nodeform(&$form, $form_state) {
-
-  // Define custom form attributes.
-  $form['#ffmpeg_converter_files'] = array();
-  $form['#ffmpeg_converter_selected_snapshots'] = array();
-  
-  foreach ($form['#field_info'] as $field_def) {
-    $preset_key = ffmpeg_converter_preset_by_field($field_def['field_name']);
-    if ($preset_key) {
-
-      $field = &$form[$field_def['field_name']];
-      
-      // Define custom theme function for this form field.
-      $field['#theme'] = 'ffmpeg_converter_widget';
-
-      // Wrap the field in a fieldset.
-      $prefix = '<fieldset class="collapsible">';
-      $prefix .= '<legend>' . t('!title:', array('!title' => $field['#title'])) . "</legend>\n";
-      $field['#prefix'] = empty($field['#prefix']) ? '' : $field['#prefix'];
-      $field['#prefix'] = $prefix . $field['#prefix'];
-      $field['#suffix'] = empty($field['#suffix']) ? '' : $field['#suffix'];
-      $field['#suffix'] .= "</fieldset>\n";
-      
-      // Examine the existing files in this field.
-      $form['#ffmpeg_converter_files'][$field_def['field_name']] = array();
-      foreach($field as $field_instance => &$file) {
-        if (is_numeric($field_instance)) {
-          if (isset($file['#default_value']['data']['ffmpeg_converter_file'])) {
-            // Override the filefield widget for this instance. This will 
-            // hide the file completely. We pick up and save the default 
-            // values in ffmpeg_converter_nodeform_validate().
-            $file['#type'] = 'value';
-            
-            // Save custom file information.
-            $form['#ffmpeg_converter_files'][$field_def['field_name']][$field_instance] = $file['#default_value']['data']['ffmpeg_converter_file'];
-            
-            // Save snapshot data. (No longer needed?)
-            if (!empty($file['#default_value']['data']['ffmpeg_converter_snapshot_selected'])) {
-              $form['#ffmpeg_converter_selected_snapshots'][$field_def['field_name']] = $field_instance;
-            }
-          }
-        }
-      }
-      
-      // Add options to clear converted files and select one of the tree snapshot images.
-      if (!empty($form['nid']['#value'])) {
-        
-        if (ffmpeg_converter_file_is_queued($form['nid']['#value'], $field_def['field_name'])) {
-          $field['ffmpeg_converter_queued'] = array(
-            '#type' => 'markup',
-            '#value' => t('<p><strong>Note:</strong> This file has been added to the !job_queue and will be converted on the next available cron run.</p>', array('!job_queue' => l(t('job queue'), 'admin/reports/job_queue'))),
-          );
-        }
-        elseif (!empty($form['#ffmpeg_converter_files'][$field_def['field_name']])) {
-          $field['ffmpeg_converter_delete'] = array(
-            '#type' => 'checkbox',
-            '#title' => t('Delete converted files'),
-            '#description' => t('Check this box and click Save if you want to delete all converted files and reconvert the original.'),
-            '#weight' => 8,
-          );
-          $snapshots = array();
-          foreach ($form['#ffmpeg_converter_files'][$field_def['field_name']] as $instance => $type) {
-            if ($type == 'snapshot') {
-              $i = image_get_info($field[$instance]['#default_value']['filepath']);
-              if ($i) {
-                if ($i['width'] > $i['height']) {
-                  $w = 100;
-                  $h = round($i['height'] / $i['width'] * 100);
-                }
-                else {
-                  $h = 100;
-                  $w = round($i['width'] / $i['height'] * 100);
-                }
-                $snapshots[$instance] = theme('image', $field[$instance]['#default_value']['filepath'], '', '', array('width' => $w, 'height' => $h), false);
-              }
-              else {
-                $snapshots[$instance] = $field[$instance]['#default_value']['filename'];
-              }
-            }
-          }
-          $field['ffmpeg_converter_snapshot'] = array(
-            '#type' => 'radios',
-            '#options' => $snapshots,
-            '#title' => t('Snapshot image'),
-            '#description' => t('Choose which snapshot image you would like to use to preview the video.'),
-            '#weight' => 9,
-            '#prefix' => '<div class="ffmpeg-converter-snapshot-selection clear-block">',
-            '#suffix' => '</div>',
-          );
-          if (is_numeric($form_state['values'][$field_def['field_name']]['ffmpeg_converter_snapshot'])) {
-            $field['ffmpeg_converter_snapshot']['#default_value'] = $form_state['values'][$field_def['field_name']]['ffmpeg_converter_snapshot'];
-          }
-          elseif (is_int($form['#ffmpeg_converter_selected_snapshots'][$field_def['field_name']])) {
-            $field['ffmpeg_converter_snapshot']['#default_value'] = $form['#ffmpeg_converter_selected_snapshots'][$field_def['field_name']];
-          }
-        }
-      }
-    }
-  }
-  // Add validate and submit handlers to take care of custom file data and delete operations.
-  $form['#validate'][] = 'ffmpeg_converter_nodeform_validate';
-
-}
-
-
-/**
- * Validate submitted node forms and save custom file data.
- */
-function ffmpeg_converter_nodeform_validate($form, &$form_state) {
-  // Examine the file information saved in ffmpeg_converter_form_alter().
-  if (!empty($form['#ffmpeg_converter_files'])) {
-    foreach ($form['#ffmpeg_converter_files'] as $field_name => $field) {
-      $form_value = &$form_state['values'][$field_name];
-      foreach ($field as $field_instance => $file_type) {
-        // Restore field instances that were changed to #type=value in _form_alter().
-        $form_value[$field_instance] = $form[$field_name][$field_instance]['#default_value'];
-        // Delete converted files if requested.
-        if ($form_value['ffmpeg_converter_delete']) {
-          $form_value[$field_instance]['fid'] = 0;
-          $form_value[$field_instance]['data'] = array();
-          $form_value[$field_instance]['filepath'] = '';
-          $form_value[$field_instance]['filename'] = '';
-          $form_value[$field_instance]['filemime'] = '';
-          $form_value[$field_instance]['filesize'] = 0;
-        }
-        else {
-          // Put ffmpeg_converter's file data into $form_state to have it saved to the database. TODO: (No longer needed?)
-          $form_value[$field_instance]['data']['ffmpeg_converter_file'] = $file_type;
-          // Look for the selected snapshot.
-          if ($file_type == 'snapshot') {
-            if (is_numeric($form_value['ffmpeg_converter_snapshot']) && $form_value['ffmpeg_converter_snapshot'] == $field_instance) {
-              $form_value[$field_instance]['data']['ffmpeg_converter_snapshot_selected'] = 1;
-            }
-            else {
-              $form_value[$field_instance]['data']['ffmpeg_converter_snapshot_selected'] = 0;
-            }
-          }
-        }
-      }
-    }
-  }
-  
-}
-
-
-/**
  * Load one preset or all presets.
  *
  * @param $name
@@ -483,99 +223,6 @@
 
 
 /**
- * Get a FFmpeg Converter preset by file field
- *
- * @param $field
- *   The name of the file field.
- * @return
- *   A preset key if the field has one assigned, false otherwise.
- */
-function ffmpeg_converter_preset_by_field($field) {
-  $setting = variable_get('ffmpeg_converter_' . $field, array('preset' => 'disabled'));
-  if (!empty($setting['preset']) && $setting['preset'] != 'disabled') {
-    return $setting['preset'];
-  }
-  else {
-    return false;
-  }
-}
-
-
-/**
- * Implementation of hook_nodeapi().
- */
-function ffmpeg_converter_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
-  if (in_array($op, array('insert', 'update', 'view'))) {
-    
-    $view_messages = array();
-    
-    // Get this node type's fields and look for FFmpeg Converter files.
-    if (function_exists('content_fields')) {
-      $fields = content_fields();
-      foreach ($fields as $field) {
-        // Check if this field has a FFmpeg Converter preset.
-        $preset_key = ffmpeg_converter_preset_by_field($field['field_name']);
-        if ($preset_key && isset($node->{$field['field_name']})) {
-          // Examine files (we assume this is a file field).
-          $original = array();
-          $converted = array();
-          foreach($node->$field['field_name'] as $field_instance => $file) {
-            // $file may be an array with empty values.
-            if (!empty($file['fid'])) {
-              if (!empty($file['data']['ffmpeg_converter_file'])) {
-                $converted[] = array($field_instance, $file);
-              }
-              else {
-                $original[] = array($field_instance, $file);
-              }
-            }
-          }
-          // Act on the collected file data.
-          switch ($op) {
-            case 'insert':
-            case 'update':
-              // Look for new files.
-              if (!empty($original) && empty($converted) && !ffmpeg_converter_file_is_queued($node->nid, $field['field_name'])) {
-                list($field_instance, $file) = array_pop($original);
-                if (ffmpeg_converter_check_file($file['filename'], $preset_key)) {
-                  // Queue file for processing.
-                  ffmpeg_converter_queue_filefield($node->nid, $field['field_name'], 0, $preset_key);
-                  drupal_set_message(t('The file %file was added to the job queue.', array('%file' => check_plain($file['filename']))));
-                }
-              }
-              break;
-            case 'view':
-              // Look for unconverted files and hide from display.
-              // TODO: Respect user's option to hide or show original files.
-              if (!empty($original) && empty($converted)) {
-                list($field_instance, $file) = array_pop($original);
-                // Make sure that original file even needs to be converted.
-                if(ffmpeg_converter_check_file($file['filename'], $preset_key)) {
-                  unset($node->content[$field['field_name']]['field']['items'][$field_instance]);
-                  // Add message to node content for files that are being converted.
-                  $view_messages[] = array(
-                    'message' => t('The file %file is waiting to be converted.', array('%file' => $file['filename'])),
-                    'filename' => $file['filename'],
-                  );
-                }
-              }
-              break;
-          }      
-        }
-      }
-    }
-    
-    if ($op = 'view' && !empty($view_messages)) {
-      $node->content['ffmpeg_converter_messages'] = array(
-        '#value' => theme('ffmpeg_converter_messages', $view_messages)
-      );
-    }
-  }
-
-}
-
-
-/**
  * Check if a file should be converted.
  *
  * @param $filename
@@ -610,8 +257,10 @@
  *
  * @param $nid
  *   The id of the container node.
- * @param $field_name
+ * @param $source_field
  *   The name of the field that contains the source file.
+ * @param $dest_field
+ *   The name of the field that will recieve the converted file.
  * @param $field_instance
  *   The field instance as an integer representing the key in the 
  *   $node->{$field_name} array.
@@ -620,10 +269,10 @@
  * @return
  *   FALSE if Job queue is unavailable, NULL otherwise.
  */
-function ffmpeg_converter_queue_filefield($nid, $field_name, $field_instance, $preset_key) {
+function ffmpeg_converter_queue_filefield($nid, $source_field, $dest_field, $field_instance, $preset_key) {
   if (function_exists('job_queue_add')) {
     cache_clear_all('ffmpeg_converter_queued_files', 'cache');
-    return job_queue_add('ffmpeg_converter_convert_filefield', t('Convert a file field with FFmpeg.'), array($nid, $field_name, $field_instance, $preset_key));
+    return job_queue_add('ffmpeg_converter_convert_filefield', t('Convert a file field with FFmpeg.'), array($nid, $source_field, $dest_field, $field_instance, $preset_key));
   }
   else {
     return false;
@@ -636,12 +285,17 @@
  *
  * @param $nid
  *   The nid of the node containing the file.
- * @param $field
- *   The name of the field containing the file.
+ * @param $source_field
+ *   The name of the field containing the source file.
+ * @param $dest_field
+ *   The name of the field where the converted file should be saved.
+ * @param $field_instance
+ *   The field instance as an integer representing the key in the
+ *   $node->{$source_field} array.
  * @return 
  *   TRUE or FALSE.
  */
-function ffmpeg_converter_file_is_queued($nid, $field) {
+function ffmpeg_converter_file_is_queued($nid, $source_field, $dest_field, $field_instance = 0) {
   $cache = cache_get('ffmpeg_converter_queued_files');
   
   if ($cache) {
@@ -652,38 +306,16 @@
     $files = array();
     while ($job = db_fetch_array($jobs)) {
       $args = unserialize($job['arguments']);
-      $files[] = $args[0] . '-' . $args[1];
+      $files[] = $args[0] . '-' . $args[1] . '-' . $args[2] . '-' . $args[3];
     }
     cache_set('ffmpeg_converter_queued_files', $files);
   }
   
-  return in_array($nid . '-' . $field, $files);
+  return in_array($nid . '-' . $source_field . '-' . $dest_field . '-' . $field_instance, $files);
 }
 
 
 /**
- * Add a Drupal file to the process queue.
- *
- * @param $fid
- *   The file object id.
- * @param $preset_key
- *   The key of the FFmpeg Converter preset to use.
- * @param $link
- *   Optional HTML link tag, to the source node or similar, for log messages.
- * @return
- *   FALSE if Job queue is unavailable, NULL otherwise.
- */
-function ffmpeg_converter_queue_drupalfile($fid, $preset_key, $link = '') {
-  if (function_exists('job_queue_add')) {
-    return job_queue_add('ffmpeg_converter_convert_drupalfile', t('Convert a Drupal file with FFmpeg.'), array($fid, $nid, $preset_key, $link));
-  }
-  else {
-    return false;
-  }
-}
-
-
-/**
  * Return a file name based on a source name and a destination suffix.
  *
  * @param $source_file
@@ -706,23 +338,25 @@
  *
  * @param $nid
  *   The id of the container node.
- * @param $field_name
+ * @param $source_field
  *   The name of the field that contains the source file.
+ * @param $dest_field
+ *   The name of the field that will recieve the converted file.
  * @param $field_instance
  *   The field instance as an integer representing the key in the 
- *   $node->{$field_name} array.
+ *   $node->{$source_field} array.
  * @param $preset_key
  *   The key of the FFmpeg Converter preset to use.
  */
-function ffmpeg_converter_convert_filefield($nid, $field_name, $field_instance, $preset_key) {
+function ffmpeg_converter_convert_filefield($nid, $source_field, $dest_field, $field_instance, $preset_key) {
   
-  $node = node_load($nid);
+  $node = node_load($nid, null, true);
   
   // Clear the cached list of queued files.
   cache_clear_all('ffmpeg_converter_queued_files', 'cache');
   
   // Check the necessary prerequisites.
-  if (empty($node) || empty($node->{$field_name}[$field_instance]['fid']) || !function_exists('content_fields')) {
+  if (empty($node) || empty($node->{$source_field}[$field_instance]['fid']) || !function_exists('content_fields')) {
     return false;
   }
   
@@ -734,14 +368,15 @@
     return false;
   }
   
-  // Load the CCK field.
-  $field = content_fields($field_name, $node->type);
+   // Load the CCK fields.
+   $source_filefield_field = content_fields($source_field, $node->type);
+   $dest_filefield_field = content_fields($dest_field, $node->type);
   
   // Get preset configuration.
   $preset = ffmpeg_converter_preset_load($preset_key);
   
   // Setup paths.
-  $input_file = $node->{$field_name}[$field_instance]['filepath'];
+  $input_file = $node->{$source_field}[$field_instance]['filepath'];
   $output_file = ffmpeg_converter_filename($input_file, $preset->ffmpeg_wrapper['ffmpeg_output_type']);
   $output_file = file_directory_temp() . '/' . basename($output_file);
   
@@ -757,8 +392,8 @@
   // conversions will fail inexplicably.
   $validators = array();
   
-  // Create the file object using the same filepath as the input file.
-  $destination_path = str_replace('/' . $node->{$field_name}[$field_instance]['filename'], '', $node->{$field_name}[$field_instance]['filepath']);
+  // Create the file object.
+  $destination_path = filefield_widget_file_path($dest_filefield_field);
   $file = field_file_save_file($output_file, $validators, $destination_path);
 
   if (!is_array($file['data'])) {
@@ -766,11 +401,11 @@
   }
 
   // Copy file description from original to destination file.
-  if (!empty($node->{$field_name}[$field_instance]['data']['description'])) {
-    $file['data']['description'] = $node->{$field_name}[$field_instance]['data']['description'];
+  if (!empty($node->{$source_field}[$field_instance]['data']['description'])) {
+    $file['data']['description'] = $node->{$source_field}[$field_instance]['data']['description'];
   }
   
-  // Leave a note that this is a converted file.
+  // Leave a note that this is a converted file. TODO: remove this, or can it be useful?
   $file['data']['ffmpeg_converter_file'] = 'converted';
   
   // Attempt to get MIME type with mimedetect.  
@@ -779,58 +414,13 @@
   }
   
   // Add the file to the node.
-  $node->{$field_name}[] = $file;
+  $node->{$dest_field}[$field_instance] = $file;
   
-  // Try to get video duration and determine if this is a video file.
-  $duration = ffmpeg_wrapper_file_duration($input_file, false);
+  // Before saving the node, add a flag to the node object which will inform
+  // node actions in Rules etc. that this node save should not trigger new
+  // conversion jobs.
+  $node->_ffmpeg_converter_ignore = TRUE;
   
-  if ($duration) {
-    
-    // Take three snapshot images of the film.
-    $duration = ffmpeg_wrapper_file_duration($input_file, false);
-    $offsets = array(
-      round($duration / 4),
-      round($duration / 2),
-      round($duration * 3 / 4),
-    );
-    
-    foreach ($offsets as $offset) {
-      // Format time code.
-      $timecode = str_pad($offset / 3600 % 24, 2, '0', STR_PAD_LEFT);
-      $timecode .= ':' . str_pad($offset / 60 % 60, 2, '0', STR_PAD_LEFT);
-      $timecode .= ':' . str_pad($offset % 60, 2, '0', STR_PAD_LEFT);
-      
-      // Create snapshot image.
-      $size = $preset->ffmpeg_wrapper[$preset->ffmpeg_wrapper['ffmpeg_video_size'] == 'other' ? 'ffmpeg_video_size_other' : 'ffmpeg_video_size'];
-      if ($snapshot = ffmpeg_converter_create_snapshot($input_file, file_directory_temp(), $timecode, $size)) {
-      
-        // Create the snapshot file object.
-        $s_file = field_file_save_file($snapshot, $validators, $destination_path);
-        
-        if (is_array($s_file)) {
-        
-          if (!is_array($s_file['data'])) {
-            $s_file['data'] = array();
-          }
-  
-          // Copy file description from original to snapshot image.
-          if (!empty($node->{$field_name}[$field_instance]['data']['description'])) {
-            $s_file['data']['description'] = $node->{$field_name}[$field_instance]['data']['description'];
-          }
-    
-          // Leave a note that this is a snapshot image file.
-          $s_file['data']['ffmpeg_converter_file'] = 'snapshot';
-          
-          // Add the snapshot image file to the node.
-          $node->{$field_name}[] = $s_file;
-      
-        
-        }
-      }
-      
-    }
-  }
-  
   // Save the node.
   $node = node_submit($node);
   node_save($node);
@@ -842,81 +432,6 @@
 
 
 /**
- * Convert a Drupal file with FFmpeg.
- * The original file will be replaced by the converted one.
- *
- * @param $fid
- *   The file object id.
- * @param $preset_key
- *   The key of the FFmpeg Converter preset to use.
- * @param $link
- *   Optional HTML link tag, to the source node or similar, for log messages.
- * @return
- *   A file object on success, false on failure.
- */
-function ffmpeg_converter_convert_drupalfile($fid, $preset_key, $link = '') {
-  
-  // Get the file object from the database.
-  $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
-  $file = db_fetch_object($result);
-  
-  $input_file = file_create_path($file->filepath);
-  
-  // Get preset configuration.
-  $preset = ffmpeg_converter_preset_load($preset_key);
-  
-  // Construct output file path.
-  $output_type = $preset->ffmpeg_wrapper['ffmpeg_output_type'];
-  $output_file = ffmpeg_converter_filename($input_file, $output_type);
-  $output_file = file_directory_temp() . '/' . basename($output_file);
-  
-  // Run conversion and check result.
-  $result = ffmpeg_converter_convert($input_file, $output_file, $preset->ffmpeg_wrapper, $link);
-  if (!$result) {
-    return false;
-  }
-  
-  // Move temp file to permanent location.
-  $permanent_path = file_destination(str_replace($file->filename, '', $file->filepath) . basename($output_file), FILE_EXISTS_RENAME);
-  if (!file_move($output_file, str_replace('/' . $file->filename, '', $file->filepath), FILE_EXISTS_RENAME)) {
-    watchdog('ffmpeg_converter', 'Could not save converted file %file, keeping original.', array('%file' => $output_file), WATCHDOG_WARNING, $link);
-    return false;
-  }
-  
-  // Prepare new file attributes.
-  $file->filepath = str_replace($file->filename, basename($output_file), $file->filepath);
-  $file->filename = basename($output_file);
-  $file->filesize = filesize($output_file);
-  
-  // Get MIME type.  
-  if (function_exists('mimedetect_mime')) {
-    $file->filemime = mimedetect_mime($output_file);
-  }
-  else {
-    $file->filemime = file_get_mimetype(basename($output_file));
-  }
-
-  // Save changes to database.
-  if (!db_query("UPDATE {files} SET filename = '%s', filepath = '%s', filesize = %d, filemime = '%s', timestamp = %d WHERE fid = %d", 
-                $file->filename, $file->filepath, $file->filesize, $file->filemime, time(), $file->fid)) {
-    watchdog('ffmpeg_converter', 'Could not save converted file %file to the database, keeping original.',
-             array('%file' => $output_file), WATCHDOG_WARNING, $link);
-    return false;
-  }
-  content_update(&$node);
-  
-  // Clear content cache.
-  cache_clear_all('content:', 'cache_content', true);
-  
-  watchdog('ffmpeg_converter','FFmpeg converted the file %file to @format.',
-           array('%file' => basename($input_file), '@format' => $output_type), 
-           WATCHDOG_NOTICE, $link);
-               
-  return $file;
-  
-}
-
-/**
  * Convert a file with FFmpeg Wrapper.
  *
  * @param $input_file
@@ -1044,64 +559,6 @@
 
 
 /**
- * Create a snapshot image from a video file.
- * 
- * Based on video_thumbnailer_create_thumb() in Video Thumbnailer.
- * 
- * @param $file
- *   Path to the input video file.
- * @param $output_path
- *   Path to the directory where the image will be saved.
- * @param $offset
- *   A time code in the format hh:mm:ss where the snapshot will be taken.
- * @param $width
- *   The destination size expressed as WIDTHxHEIGHT.
- * @return
- *   Filepath if successfull, FALSE otherwise.
- */
-function ffmpeg_converter_create_snapshot($file, $output_path, $offset, $size = '320x240') {
-  
-  // Create output file path.
-  $output_file = explode('.', basename($file));
-  array_pop($output_file);
-  $output_file = join('.', $output_file) . '-snapshot-' . $offset . '.jpg';
-  $output_file = str_replace(':', '-', $output_file);
-  $output_file = str_replace(' ', '_', $output_file);
-  $output_file = file_create_filename($output_file, $output_path);
-
-  // Calculate an output frame size and padding based on the proportions of the
-  // source file.
-  $pad = ffmpeg_converter_get_padded_size($file, $size, 'padding');
-  $size = ffmpeg_converter_get_padded_size($file, $size, 'size');
-  
-  // Prepare FFmpeg options.
-  $options = array();
-  $options[] = "-ss $offset";  
-  $options[] = "-i '$file'";
-  $options[] = "-vcodec mjpeg -vframes 1 -an -f rawvideo -s '$size'";
-  $options[] = $pad;
-  $options[] = "'$output_file'";
- 
-  $command = implode(" ", $options);
-
-  // Run the command.
-  $output = ffmpeg_wrapper_run_command($command);
-  
-  if (variable_get('ffmpeg_converter_debug', 0)) {
-    watchdog('ffmpeg_converter', 'FFmpeg was invoked with these options: %command',
-             array('%command' => $command), WATCHDOG_DEBUG, $link);
-  }
-  
-  if (file_exists($output_file)) {
-    return $output_file;
-  }
-  else {
-    return FALSE;
-  }
-}
-
-
-/**
  * Calculate an output size and a padding value for a media file.
  * 
  * This function has been moved to FFmpeg Wrapper, and it will eventually be 
@@ -1186,148 +643,3 @@
     return ($return == 'size') ? $size : $pad;
   }
 }
-
-
-/**
- * Implementation of hook_theme_registry_alter().
- */
-function ffmpeg_converter_theme_registry_alter(&$theme_registry) {
-  // Insert our own preprocess funtion before CCKs theme_content_field().
-  if (isset($theme_registry['content_field']['preprocess functions'])) {
-    foreach ($theme_registry['content_field']['preprocess functions'] as $key => $function) {
-      if ($function == 'content_preprocess_content_field') {
-        unset($theme_registry['content_field']['preprocess functions'][$key]);
-      }
-    }
-    $theme_registry['content_field']['preprocess functions'][] = 'ffmpeg_converter_preprocess_content_field';
-    $theme_registry['content_field']['preprocess functions'][] = 'content_preprocess_content_field';
-  }
-}
-
-
-/**
- * Preprocess CCK field template.
- * If this field has an FFmpeg converter preset, we do some processing to 
- * enable a custom view of video files.
- */
-function ffmpeg_converter_preprocess_content_field(&$variables) {
-  $element =& $variables['element'];
-  
-  $preset_key = ffmpeg_converter_preset_by_field($element['#field_name']);
-  if ($preset_key) {
-    $instance_keys = element_children($element['items']);
-    
-    // This field has a preset. Check if it has been converted.
-    if (count($instance_keys) > 1) {
-      
-      // Look for converted file and snapshot images.
-      $converted = array();
-      $snapshot = array();
-      foreach ($instance_keys as $key) {
-        $item = &$element['items'][$key];
-        if (is_array($item['#item']) ) {
-          if (is_array($item['#item']['data']) && isset($item['#item']['data']['ffmpeg_converter_file'])) {
-            if ($item['#item']['data']['ffmpeg_converter_file'] == 'converted') {
-              $converted = $item;
-            }
-            elseif ($item['#item']['data']['ffmpeg_converter_file'] == 'snapshot') {
-              if (!empty($item['#item']['data']['ffmpeg_converter_snapshot_selected'])) {
-                $snapshot = $item['#item'];
-              }
-              elseif (empty($snapshot)) {
-                $snapshot = $item['#item'];
-              }
-              
-            }
-          }
-        }
-        
-      }
-      
-      // If this is a converted video file, replace the field items with a 
-      // linked snapshot image.
-      if (!empty($converted) && !empty($snapshot)) {
-        
-        // Set template variables.
-        $converted_path = base_path() . $converted['#item']['filepath'];
-        $nid = $element['#node']->nid;
-        
-        $link_href = '';
-        $snapshot_path = '';
-        $width = '';
-        $height = '';
-        
-        // Check field display settings.
-        if (isset($element['items'][0]['#formatter'])) {
-          $format = $element['items'][0]['#formatter'];
-        }
-        else {
-          $field = content_fields($element['#field_name']);
-          $format = $field['display_settings']['full']['format'];
-        }
-        $parts =  explode('_', $format);
-        $link_style = array_pop($parts);
-        $presetname = implode('_', $parts);
-        
-        // Define where the image should link to.
-        switch ($link_style) {
-          case 'nodelink':
-          case 'linked':
-            $link_href = url('node/' . $nid);
-            break;
-          case 'imagelink':
-            $link_href = $converted_path;
-            break;
-        }
-        
-        // Check if the standard image should be displayed.
-        if ($presetname == 'image') {
-          $preset = ffmpeg_converter_preset_load($preset_key);
-          if ($preset->ffmpeg_wrapper['ffmpeg_video_advanced']) {
-            $size = $preset->ffmpeg_wrapper[$preset->ffmpeg_wrapper['ffmpeg_video_size'] == 'other' ? 'ffmpeg_video_size_other' : 'ffmpeg_video_size'];
-          }
-          elseif ($preset->ffmpeg_wrapper['ffmpeg_video_custom']) {
-            $matches = array();
-            preg_match("/-s ([0-9]+x[0-9]+)/", $preset->ffmpeg_wrapper['ffmpeg_video_custom_command'], $matches);
-            if (!empty($matches[1])) {
-              $size = $matches[1];
-            }
-          }
-          if (empty($size)) {
-            $size = '320x240';
-          }
-          list($width, $height) = explode('x', $size);
-          
-          $snapshot_path = base_path() . $snapshot['filepath'];
-        }
-        
-        // Check if an Imagecache preset should be used.
-        if (empty($snapshot_path) && function_exists('imagecache_presets')) {
-          foreach (imagecache_presets() as $preset) {
-            if ($preset['presetname'] == $presetname) {
-              $snapshot_path = base_path() . imagecache_create_path($preset['presetname'], $snapshot['filepath']);
-              $width = NULL;
-              $height = NULL;
-              foreach ($preset['actions'] as $action) {
-                if (isset($action['data']['width'])) {
-                  $width = $action['data']['width'];
-                }
-                if (isset($action['data']['height'])) {
-                  $height = $action['data']['height'];
-                }
-              }
-              
-              break;
-            }
-          }
-        }
-        
-        if (!empty($snapshot_path)) {
-          // Replace the field display with a custom template.
-          $converted['#children'] = theme('ffmpeg_converter_video', $converted['#item'], $converted_path, $snapshot, $snapshot_path, check_plain($converted['#item']['data']['description']), $nid, $width, $height, $link_href);
-          $element['items'] = array($converted);
-        }
-      }
-    }
-  }
-}
Index: contributions/modules/ffmpeg_converter/ffmpeg_converter.rules.inc
--- contributions/modules/ffmpeg_converter/ffmpeg_converter.rules.inc No Base Revision
+++ contributions/modules/ffmpeg_converter/ffmpeg_converter.rules.inc Locally New
@@ -0,0 +1,131 @@
+<?php
+
+// $Id$
+
+/**
+ * @file
+ * Rules integration for the ffmpeg_converter module.
+ */
+
+/**
+ * Implementation of hook_rules_action_info().
+ * @ingroup rules
+ */
+function ffmpeg_converter_rules_action_info() {
+  return array(
+    'ffmpeg_converter_action_queue_filefield' => array(
+      'label' => t('Queue file field for conversion'),
+      'arguments' => array(
+        'node' => array('type' => 'node', 'label' => t('Content')),
+      ),
+      'module' => 'ffmpeg_converter',
+    ),
+  );
+}
+
+/**
+ * Configuration form for the queue filefield action.
+ */
+function ffmpeg_converter_action_queue_filefield_form($settings, &$form) {
+  $settings += array(
+    'source' => '',
+    'destination' => '',
+    'preset' => '',
+  );
+
+  // Load CCK fields and make a list of available file fields.
+  $fields = content_fields();
+  $file_field_options = array();
+  foreach ($fields as $field) {
+    if ($field['type'] == 'filefield') {
+      $file_field_options[$field['field_name']] = $field['widget']['label'];
+    }
+  }
+
+  $form['settings']['source'] = array(
+    '#type' => 'select',
+    '#title' => t('Source field'),
+    '#options' => $file_field_options,
+    '#default_value' => $settings['source'],
+  );
+
+  $form['settings']['destination'] = array(
+    '#type' => 'select',
+    '#title' => t('Destination field'),
+    '#options' => $file_field_options,
+    '#default_value' => $settings['destination'],
+  );
+
+  $form['settings']['preset'] = array(
+    '#type' => 'select',
+    '#title' => t('Preset'),
+    '#options' => ffmpeg_converter_presets(),
+    '#default_value' => $settings['preset'],
+  );
+
+}
+
+/**
+ * Validate the configuration form.
+ */
+function ffmpeg_converter_action_queue_filefield_validate($form, $form_state) {
+  if ($form_state['values']['settings']['source'] == $form_state['values']['settings']['destination']) {
+    form_set_error('settings][destination', t('The source and destination cannot be the same field.'));
+  }
+}
+
+/**
+ * Help text for the configuration form.
+ */
+function ffmpeg_converter_action_queue_filefield_help() {
+  return t('Please specify which field contains the source file(s) and which field should recieve the converted file(s). Both of these fields need to exist in the same node type. Also choose the <a href="@url">FFmpeg Converter preset</a> you want to use for this conversion.', array('@url' => url('admin/settings/ffmpeg_converter')));
+}
+
+/**
+ * Run the queue filefield action.
+ */
+function ffmpeg_converter_action_queue_filefield(&$node, $settings) {
+  $source_field = $settings['source'];
+  $dest_field = $settings['destination'];
+  $preset_key = $settings['preset'];
+
+  // Look for the ignore flag set by running conversion jobs.
+  if (empty($node->_ffmpeg_converter_ignore)) {
+
+    // Check all the necessary prerequisites.
+    $source_field_def = content_fields($source_field, $node->type);
+    $dest_field_def = content_fields($dest_field, $node->type);
+    $presets = ffmpeg_converter_presets();
+
+    if (!$source_field_def) {
+      drupal_set_message(t('This content could not be converted with FFmpeg Converter since the source field doesn\'t exist in this content type.'), 'error');
+    }
+    elseif (!$dest_field_def) {
+      drupal_set_message(t('This content could not be converted with FFmpeg Converter since the destination field doesn\'t exist in this content type.'), 'error');
+    }
+    elseif ($source_field == $dest_field) {
+      drupal_set_message(t('This content could not be converted with FFmpeg Converter since the source and destination fields are the same.'), 'error');
+    }
+    elseif (!isset($presets[$preset_key])) {
+      drupal_set_message(t('This content could not be converted with FFmpeg Converter since the conversion preset doesn\'t exist.'), 'error');
+    }
+    else {
+      // Queue the source field's files for conversion.
+      foreach ($node->{$source_field} as $field_instance => $file) {
+        // Look for an existing destination file.
+        if (!empty($node->{$dest_field}[$field_instance]['filepath'])) {
+          drupal_set_message(t('The file %file will not be converted since there is already a file in the corresponding slot in the destination field. If you wish to replace it, please delete it first.', array('%file' => $file['filename'])));
+        }
+        elseif (is_array($file) && !empty($file['filepath']) && file_exists($file['filepath'])) {
+          if (!ffmpeg_converter_file_is_queued($node->nid, $source_field, $dest_field, $field_instance)) {
+            ffmpeg_converter_queue_filefield($node->nid, $source_field, $dest_field, $field_instance, $preset_key);
+            drupal_set_message(t('The file %file was queued for conversion.', array('%file' => $file['filename'])));
+          }
+          else {
+            drupal_set_message(t('The file %file is already in the job queue.', array('%file' => $file['filename'])));
+          }
+        }
+      }
+    }
+  }
+}
Index: contributions/modules/ffmpeg_converter/ffmpeg_converter_messages.tpl.php
--- contributions/modules/ffmpeg_converter/ffmpeg_converter_messages.tpl.php Base (1.1)
+++ contributions/modules/ffmpeg_converter/ffmpeg_converter_messages.tpl.php Locally Deleted
@@ -1,17 +0,0 @@
-<?php
-// $Id: ffmpeg_converter_messages.tpl.php,v 1.1 2009/02/08 02:03:55 zoo33 Exp $
-
-/**
- * @file
- * Template file for the message stating that a file is being converted.
- * 
- * Available variables:
- *   $messages - an array of arrays containing the keys 'message' and 'filename'
- */
-
-?>
-<div class="ffmpeg-converter-messages">
-  <?php foreach($messages as $message): ?>
-    <p><?php print $message['message']; ?></p>
-  <?php endforeach; ?>
-</div>
Index: contributions/modules/ffmpeg_converter/ffmpeg_converter_theme.inc
--- contributions/modules/ffmpeg_converter/ffmpeg_converter_theme.inc Base (1.1)
+++ contributions/modules/ffmpeg_converter/ffmpeg_converter_theme.inc Locally Deleted
@@ -1,61 +0,0 @@
-<?php
-
-// $Id: ffmpeg_converter_theme.inc,v 1.1 2009/01/26 23:40:30 zoo33 Exp $
-
-/**
- * @file
- * Theme functions for FFmpeg Converter.
- */
-
-
-/**
- * Theme the form elements of file fields that are used by ffmpeg_converter.
- * 
- * @param $element
- *   The form element array.
- */
-function theme_ffmpeg_converter_widget($element) {
-  
-  drupal_add_css(drupal_get_path('module', 'ffmpeg_converter'). '/ffmpeg_converter.css', 'module');
-  
-  $field_name = $element['#field_name'];
-  $field = content_fields($field_name);
-  
-  $output = '';
-  $render_fields = array();
-  $file_fields = array(
-    'empty' => array(),
-    'original' => array(),
-  );
-  
-  // Examine field instances.
-  foreach (element_children($element) as $key) {
-    
-    if (is_int($key)) {
-      if (!empty($element[$key]['#default_value']['fid'])) {
-        if (empty($element[$key]['#default_value']['data']['ffmpeg_converter_file'])) {
-          $file_fields['original'][] = $key;
-        }
-      }
-      else {
-        $file_fields['empty'][] = $key;
-      }
-      // Hide weight field.
-      $element[$key]['_weight']['#type'] = 'value';
-    }
-    else {
-      $render_fields[] = $key;
-    }
-  }
-  
-  // Determine which field instance to render.
-  $file_fields = array_merge($file_fields['original'], $file_fields['empty']);
-  $output .= drupal_render($element[array_shift($file_fields)]);
-  
-  // Render other form fields.
-  foreach ($render_fields as $key) {
-    $output .= drupal_render($element[$key]);
-  }
-  
-  return $output;
-}
Index: contributions/modules/ffmpeg_converter/ffmpeg_converter_video.tpl.php
--- contributions/modules/ffmpeg_converter/ffmpeg_converter_video.tpl.php Base (1.2)
+++ contributions/modules/ffmpeg_converter/ffmpeg_converter_video.tpl.php Locally Deleted
@@ -1,26 +0,0 @@
-<?php
-// $Id: ffmpeg_converter_video.tpl.php,v 1.2 2009/01/12 11:25:09 zoo33 Exp $
-
-/**
- * @file
- * Template file for converted video files.
- * 
- * Available variables:
- *   $file
- *   $file_path
- *   $snapshot
- *   $snapshot_path
- *   $description
- *   $nid
- *   $width
- *   $height
- *   $link_href
- */
-
-?>
-
-<?php if ($link_href): ?>
-  <a href="<?php print $link_href ?>" id="ffmpeg-converter-<?php print $nid ?>"><img src="<?php print $snapshot_path ?>" alt="<?php print $description ?>" /></a>
-<?php else: ?>
-  <img src="<?php print $snapshot_path ?>" alt="<?php print $description ?>" />
-<?php endif; ?>
