Index: README.txt
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/mediafield/README.txt,v
retrieving revision 1.8
diff -u -p -r1.8 README.txt
--- README.txt	2 Jul 2008 21:37:51 -0000	1.8
+++ README.txt	17 Apr 2009 16:28:13 -0000
@@ -1,10 +1,8 @@
+$Id$
+
 Media Field
 -----------
-Currently consists of two media fields: audio field and video field.
-Both of them were developed for CCK module and depend on it.
-
-At the moment these fields use multimediafile.inc file with common functions.
-It is planned to move them into filefield.module in the future.
+Provides audio and video widgets for file fields. It depends on FileField.
 
 
 Installing
@@ -12,14 +10,11 @@ Installing
 
 1. Put this package into your Drupal modules directory.
 
-2. Download and enabled the Getid3 module http://drupal.org/project/getid3 
-   remembering to install the getID3() PHP library from http://www.getid3.org/ 
-
-3. Enable audiofield.module or videofield.module on 'admin/build/modules' page
-   (CCK section) depending on what exactly fields you need.
+2. Enable Media field on 'admin/build/modules' page (CCK section).
 
-4. Go to 'admin/content/types' page, choose a desired content type, click edit
-   and add audio or video field.
+3. Go to 'admin/content/types' page, choose a desired content type, click edit,
+   add a file field, and choose the audio or video widget type. Choose the audio
+   or video formatter for field display.
 
 
 Created by ARDAS group <info AT ardas DOT dp DOT ua>
Index: audiofield.css
===================================================================
RCS file: audiofield.css
diff -N audiofield.css
--- audiofield.css	10 Feb 2007 15:20:15 -0000	1.5
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,9 +0,0 @@
-div.audiofield-icon {
-  float: left;
-}
-
-
-
-
-
-
Index: audiofield.info
===================================================================
RCS file: audiofield.info
diff -N audiofield.info
--- audiofield.info	26 Jun 2008 08:55:12 -0000	1.4
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,5 +0,0 @@
-; $Id: audiofield.info,v 1.4 2008/06/26 08:55:12 acm Exp $
-name = Audio Field
-description = Defines audio field type for CCK content.
-dependencies = content getid3
-package = CCK
Index: audiofield.module
===================================================================
RCS file: audiofield.module
diff -N audiofield.module
--- audiofield.module	26 Jun 2008 09:38:36 -0000	1.11
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,532 +0,0 @@
-<?php
-
-/**
- * Implementation of hook_field_info().
- */
-function audiofield_field_info() {
-  return array(
-    'file_audio' => array('label' => 'Audio file'),
-  );
-}
-
-/**
- * Implementation of hook_field_settings().
- */
-function audiofield_field_settings($op, $field) {
-  switch ($op) {
-    case 'form':
-      $form = array();
-      return $form;
-
-    case 'validate':
-      break;
-
-    case 'save':
-      return array('sample_rate', 'bitrate', 'channel_mode', 'playtime');
-
-    case 'database columns':
-      $columns = array(
-        'fid' => array('type' => 'int', 'not null' => TRUE, 'default' => '0'),
-        'sample_rate' => array('type' => 'int', length => 10, 'not null' => FALSE),
-        'bitrate' => array('type' => 'float unsigned', 'not null' => FALSE),
-        'channel_mode' => array('type' => 'varchar', length => 10, 'not null' => FALSE),
-        'playtime' => array('type' => 'varchar', length => 10, 'not null' => FALSE),
-      );
-      return $columns;
-  }
-}
-
-/**
- * Implementation of hook_field().
- */
-function audiofield_field($op, $node, $field, &$node_field, $a1, $a2) {
-  require_once(drupal_get_path('module', 'audiofield') .'/multimediafile.inc');
-  $fieldname = $field['field_name'];
-  switch ($op) {
-    case 'load':
-      $output = array();
-      if (count($node_field)) {
-        $values = array();
-        foreach ($node_field as $delta => $file) {
-          if (!empty($file)) {
-            $values[$delta]  = array_merge($node_field[$delta], _field_file_load($file['fid']));
-            $node_field[$delta] = $values[$delta];
-          }
-          $output = array($fieldname => $values);
-        }
-      }
-      break;
-
-    case 'view':
-      $files = array();
-      foreach ($node_field as $delta => $item) {
-          $node_field[$delta]['view'] = content_format($field, $item, 'default');
-      }
-      $output = theme('field', $node, $field, $node_field, $a1, $a2);
-      break;
-
-    case 'insert':
-      foreach ($node_field as  $delta => $item) {
-        $node_field[$delta] = _field_file_insert($node, $item, $field);
-      }
-      break;
-
-    case 'update':
-      foreach ($node_field as $delta => $item) {
-        $node_field[$delta] = _field_file_update($node, $item, $field);
-      }
-      break;
-
-    case 'delete':
-      foreach ($node_field as $delta => $item) {
-        _field_file_delete($item, $field['field_name'], $field['type']);
-      }
-      break;
-  }
-  return $output;
-}
-
-/**
- * Implementation of hook_widget_info().
- */
-function audiofield_widget_info() {
-  return array(
-    'audio' => array(
-      'label' => 'Audio file',
-      'field types' => array('file_audio'),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_widget_settings().
- */
-function audiofield_widget_settings($op, $widget) {
-  require_once(drupal_get_path('module', 'audiofield') .'/multimediafile.inc');
-  switch ($op) {
-    case 'form':
-      $form = array();
-      $form['upload_path'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Path to save uploaded file to'),
-        '#default_value' => $widget['upload_path'] ? $widget['upload_path'] : '',
-        '#size' => 64,
-        '#description' => t('A directory where all files uploaded for this field instance will be saved. Example %ex.', array('%ex' => 'media/funny')),
-        '#after_build' => array('_file_form_check_directory')
-      );
-      $form['file_extensions'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Permitted uploaded file extensions'),
-        '#default_value' => $widget['file_extensions'] ? $widget['file_extensions'] : 'mp3 wav mid',
-        '#size' => 64,
-        '#description' => t('Extensions a user can upload to this field. Enter separate extensions, in lower case, separating them with a space and do not include the leading dot.')
-      );
-      return $form;
-    case 'validate':
-      break;
-    case 'save':
-      return array('file_extensions', 'upload_path');
-  }
-}
-
-function _audiofield_widget_prepare_form_values(&$node, $field, &$node_field) {
-  $fieldname = $field['field_name'];
-  $type = $field['type'];
-  if (!count($_POST)) {
-    _field_clear_session($field['type']);
-  }
-
-  if ($file = file_check_upload($fieldname.'_upload')) {
-    $file = (array)$file;
-
-    $ext = strtolower(array_pop(explode('.', $file['filename'])));;
-    $allowed_extensions = array_unique(explode(' ', trim($field['widget']['file_extensions'])));
-    if (!in_array($ext, $allowed_extensions)) {
-      form_set_error($field['field_name'] .'_upload', t('Files with the extension %ext are not allowed. Please upload a file with an extension from the following list: %allowed_extensions.', array('%ext' => $ext, '%allowed_extensions' => $field['widget']['file_extensions'])));
-      return FALSE;
-    }
-
-    $file['upload_path'] = trim($field['widget']['upload_path']);
-
-    $file['fid'] = 'upload';
-    if (!$field['multiple']) {
-      if (is_array($node_field)) {
-	foreach ($node_field as $delta => $session_file) {
-	  $node_field[$delta]['flags']['delete'] = TRUE;
-	}
-      }
-      _field_clear_field_session($fieldname, $field['type']);
-    }
-
-    // Add the file to the session
-    $file['sessionid'] = count($node_field) + count($_SESSION[$type][$fieldname]);
-    $_SESSION[$type][$fieldname][$file['sessionid']] = $file;
-  }
-
-  if (is_array($_SESSION[$type][$fieldname]) && count($_SESSION[$type][$fieldname])) {
-    foreach ($_SESSION[$type][$fieldname] as $delta => $file) {
-      $node_field[] = $file;
-    }
-  }
-}
-
-function _audiofield_widget_validate(&$node, $field, &$node_field) {
-  if ($field['required']) {
-    if (!count($node_field)) {
-      form_set_error($fieldname, t('Field %name is required', array('%name' => $field['widget']['label'])));
-    }
-  }
-}
-
-/**
- * Implementation of hook_widget().
- */
-function audiofield_widget($op, &$node, $field, &$node_field) {
-  $fieldname = $field['field_name'];
-  $type = $field['type'];
-  require_once(drupal_get_path('module', 'audiofield') .'/multimediafile.inc');
-  switch ($op) {
-    case 'prepare form values':
-      _audiofield_widget_prepare_form_values($node, $field, $node_field);
-      break;
-
-    case 'form':
-      $form = _audiofield_widget_form($node, $field, $node_field);
-      return $form;
-
-    case 'validate':
-      _audiofield_widget_validate($node, $field, $node_field);
-      return;
-
-    case 'process form values':
-        break;
-  }
-}
-
-/**
- * A helper function to build a widget form.
- */
-function _audiofield_widget_form($node, $field, &$node_field) {
-  drupal_add_js('misc/progress.js');
-  drupal_add_js('misc/upload.js');
-
-  $fieldname = $field['field_name'];
-  drupal_add_css(drupal_get_path('module', 'audiofield') .'/audiofield.css');
-
-  $form = array();
-  $form[$fieldname] = array(
-    '#type' => 'fieldset',
-    '#title' => t($field['widget']['label']),
-    '#weight' => $field['widget']['weight'],
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-    '#tree' => TRUE,
-    '#prefix' => '<div id="'. form_clean_id($fieldname .'-attach-wrapper') .'">',
-    '#suffix' => '</div>',
-    '#theme' => 'audiofield_current',
-  );
-
-  $form[$fieldname]['new'] = array(
-    '#tree' => FALSE,
-    '#prefix' => '<div id="'. form_clean_id($fieldname .'-attach-hide') .'">',
-    '#suffix' => '</div>',
-    '#weight' => 100,
-  );
-
-  $form[$fieldname]['new'][$fieldname .'_upload'] = array(
-    '#type'  => 'file',
-    '#description' => ($field['widget']['description'] ? $field['widget']['description']. '<br/>' : ''). t('Allowed extensions: %ext.', array('%ext' => $field['widget']['file_extensions'])),
-    '#weight' => 9,
-    '#tree' => FALSE,
-  );
-
-  $form[$fieldname]['new']['upload'] = array(
-    '#type' => 'button',
-    '#value' => t('Upload'),
-    '#name' => 'cck_audiofield_'. $fieldname .'_op',
-    '#id' => form_clean_id($fieldname .'-attach-button'),
-    '#tree' => FALSE,
-    '#weight' => 10,
-  );
-
-  if (is_array($node_field) && count($node_field)) {
-    foreach ($node_field as $delta => $file) {
-      if ($file['filepath'] && !$file['flags']['delete']) {
-        $form[$fieldname][$delta]['flags']['delete'] = array(
-          '#type' => 'checkbox',
-          '#default_value' => 0,
-        );
-
-        if ($file['filepath'])  {
-          $form[$fieldname][$delta]['icon'] = array(
-            '#type' => 'markup',
-            '#value' => theme('audiofield_icon', $file),
-          );
-
-          if (strpos($file['fid'], 'upload') === false) {
-            $filepath =  $file['filepath'];
-          } else {
-            $filepath =  file_create_filename($file['filename'], file_create_path());
-          }
-
-          $path = $filepath;
-          if (strpos($file['fid'], 'upload') !== false) {
-            $path =  $file['filepath'];
-          }
-
-          $info = audio_getid3_info($path);
-
-          $description = file_create_url($filepath);
-          $description = "<small>". check_plain($description) ."</small>";
-          $form[$fieldname][$delta]['name'] = array('#type' => 'markup', '#value' => (strlen($file['description'])) ? $file['description'] : $file['filename'], '#maxlength' => 256, '#description' => $description );
-          $form[$fieldname][$delta]['size'] = array('#type' => 'markup', '#value' => format_filesize($file['filesize']));
-
-          $form[$fieldname][$delta]['msample_rate'] = array('#type' => 'markup', '#value' => format_samplerate($info['sample_rate']));
-          $form[$fieldname][$delta]['mbitrate'] = array('#type' => 'markup', '#value' => format_bitrate($info['bitrate']));
-          $form[$fieldname][$delta]['mchannel_mode'] = array('#type' => 'markup', '#value' => $info['channelmode']);
-          $form[$fieldname][$delta]['mplaytime'] = array('#type' => 'markup', '#value' => $info['playtime'] .' min');
-
-          $form[$fieldname][$delta]['filename'] = array('#type' => 'value',  '#value' => $file['filename']);
-          $form[$fieldname][$delta]['filepath'] = array('#type' => 'value',  '#value' => $file['filepath']);
-          $form[$fieldname][$delta]['filemime'] = array('#type' => 'value',  '#value' => $file['filemime']);
-          $form[$fieldname][$delta]['filesize'] = array('#type' => 'value',  '#value' => $file['filesize']);
-          $form[$fieldname][$delta]['fid'] = array('#type' => 'value',  '#value' => $file['fid']);
-
-          $form[$fieldname][$delta]['sample_rate'] = array('#type' => 'value', '#value' => $info['sample_rate']);
-          $form[$fieldname][$delta]['bitrate'] = array('#type' => 'value', '#value' => $info['bitrate']);
-          $form[$fieldname][$delta]['channel_mode'] = array('#type' => 'value', '#value' => $info['channelmode']);
-          $form[$fieldname][$delta]['playtime'] = array('#type' => 'value', '#value' => $info['playtime']);
-
-          // Special handling for single value fields
-          if (!$field['multiple']) {
-            $form[$fieldname][$delta]['replace'] = array(
-              '#type' => 'markup',
-              '#value' => t('If a new file is chosen, the current file will be replaced upon submitting the form.'),
-            );
-          }
-        }
-      } elseif ($file['filepath'] && $file['flags']['delete']) {
-        $form[$fieldname][$delta]['flags']['delete'] = array(
-          '#type' => 'hidden', // A value type will not persist here, must be hidden
-          '#value' => $file['flags']['delete'],
-        );
-      }
-    }
-  }
-  // The class triggers the js upload behaviour.
-  $form[$fieldname.'-attach-url'] = array(
-    '#type' => 'hidden',
-    '#value' => url('audiofield/js', NULL, NULL, TRUE),
-    '#attributes' => array('class' => 'upload'),
-  );
-
-  // Some useful info for our js callback.
-  $form['vid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->vid,
-    '#tree' => FALSE,
-  );
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid,
-    '#tree' => FALSE,
-  );
-  $form['type'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->type,
-    '#tree' => FALSE,
-  );
-  return $form;
-}
-
-/**
- * Implementation of hook_field_formatter_info().
- */
-function audiofield_field_formatter_info() {
-  $formatters = array(
-    'default' => array(
-      'label' => t('Default'),
-      'field types' => array('file_audio'),
-    ),
-  );
-  return $formatters;
-}
-
-/**
- * Implementation of hook_field_formatter().
- */
-function audiofield_field_formatter($field, $item, $formatter) {
-  require_once(drupal_get_path('module', 'audiofield') .'/multimediafile.inc');
-  if (!isset($item['fid'])) {
-    return '';
-  }
-  $file = _field_file_load($item['fid']);
-  return theme('audiofield', $file, $item, $field);
-}
-
-/**
- * Read media information from the specified file.
- */
-function audio_getid3_info($path) {
-  $info = &mediafield_getid3_analyze($path);
-
-  $result['format_name']     = @$info['fileformat'];
-  $result['encoder_version'] = @$info['audio']['encoder'];
-  $result['encoder_options'] = @$info['audio']['encoder_options'];
-  $result['bitrate_mode']    = @$info['audio']['bitrate_mode'];
-  $result['bitrate']         = @$info['audio']['bitrate'];
-  $result['channelmode']     = @$info['audio']['channelmode'];
-  $result['sample_rate']     = @$info['audio']['sample_rate'];
-  $result['bits_per_sample'] = @$info['audio']['bits_per_sample'];
-  $result['playtime']        = @$info['playtime_string'];
-  $result['tags']            = @$info['tags'];
-  $result['comments']        = @$info['comments'];
-  $result['warning']         = @$info['warning'];
-
-  return $result;
-}
-
-/**
- * A themed output for a currently uploaded file (used on a node edit form).
- *
- * @param array $form
- *   A form array.
- */
-function theme_audiofield_current(&$form) {
-  $header = array(t('Type'), t('Filename'), t('Sample rate'), t('Bitrate'), t('Channels'), t('Playtime'), t('Size'), t('Delete'));
-  $output = '';
-
-  foreach (element_children($form) as $key) {
-    if (is_numeric($key)) {
-      if (!($form[$key]['flags']['delete']['#type'] == 'hidden')) {
-        $row = array();
-        $row[] = drupal_render($form[$key]['icon']);
-        $row[] = drupal_render($form[$key]['name']);
-        $row[] = drupal_render($form[$key]['msample_rate']);
-        $row[] = drupal_render($form[$key]['mbitrate']);
-        $row[] = drupal_render($form[$key]['mchannel_mode']);
-        $row[] = drupal_render($form[$key]['mplaytime']);
-        $row[] = drupal_render($form[$key]['size']);
-        $row[] = drupal_render($form[$key]['flags']);
-        $rows[] = $row;
-      } else {
-        $output = drupal_render($form[$key]['flags']);
-      }
-    }
-  }
-  if (count($rows)) {
-    $output .= theme('table', $header, $rows);
-  }
-  if (count($rows) == 1) {
-    $output .= drupal_render($form[0]['replace']);
-  }
-
-  $output .= drupal_render($form);
-  return $output;
-}
-
-/**
- * A themed output for an icon representing a file type.
- *
- * @param unknown_type $file
- * @return unknown
- */
-function theme_audiofield_icon($file) {
-  $ext = strtolower(array_pop(explode('.', $file['filename'])));;
-
-  $image = theme('image', _file_get_resource_path($ext, 'audiofield', 'png', 'audio'));
-
-  return <<<OUTPUT
-<div class="audiofield-icon icon-$ext">
-  $image
-</div>
-OUTPUT;
-}
-
-/*function theme_audiofield_view_file($file, $item, $field) {
-  return theme('audiofield', $file);
-}*/
-
-/**
- * Themed output for audiofield on a node view page. Called from formatter hook.
- */
-function theme_audiofield($file, $item, $field) {
-  $file = (array)$file;
-  if (is_file($file['filepath'])) {
-    if ($file['fid'] == 'upload') {
-      $path = file_create_filename($file['filename'], file_create_path());
-    } else {
-      $path = $file['filepath'];
-    }
-    $name = $file['filename'];
-    $desc = $file['description'];
-
-    $item['sample_rate'] = format_samplerate($item['sample_rate']);
-    $item['bitrate'] = format_bitrate($item['bitrate']);
-    $item['filesize'] = format_filesize($item['filesize']);
-    $url = l($name, file_create_url($path));
-
-    $info = sprintf("<div> %s %s min %s %s (%s) </div>", $item['sample_rate'], $item['bitrate'], $url, $item['playtime'], $item['filesize']);
-
-    return $info;
-  }
-}
-
-/**
- * Menu callback for JavaScript-based uploads.
- */
-function audiofield_js() {
-  // Parse fieldname from submit button.
-  $matches = array();
-  foreach(array_keys($_POST) as $key) {
-    if (preg_match('/cck_audiofield_(.*)_op/', $key, $matches)) {
-      $fieldname = $matches[1];
-      break;
-    }
-  }
-
-  $node = (object)$_POST;
-  $field = content_fields($fieldname, $node->type); // load field data
-
-  // Load fids stored by content.module.
-  $node_field = array();
-  $values = content_field('load', $node, $field, $node_field, FALSE, FALSE);
-  $node_field = $values[$fieldname];
-
-  // Load additional field data.
-  audiofield_field('load', $node, $field, $node_field, FALSE, FALSE);
-
-  // Handle uploads and validation.
-  _audiofield_widget_prepare_form_values($node, $field, $node_field);
-  _audiofield_widget_validate($node, $field, $node_field);
-
-  // Get our new form baby, yeah tiger, get em!
-  $form = _audiofield_widget_form($node, $field, $node_field);
-
-  foreach (module_implements('form_alter') as $module) {
-    $function = $module .'_form_alter';
-    $function('audiofield_js', $form);
-  }
-  $form = form_builder('audiofield_js', $form);
-
-  $output = theme('status_messages') . drupal_render($form);
-
-  // Send the updated file attachments form.
-  print drupal_to_js(array('status' => TRUE, 'data' => $output));
-  exit();
-}
-    
-function audiofield_menu($may_cache) {
-  $items = array();
-
-  if (!$may_cache) {
-    $items[] = array(
-      'path' => 'audiofield/js',
-      'callback' => 'audiofield_js',
-      //'access' => user_access(),
-      'access' => TRUE,
-      'type' => MENU_CALLBACK
-    );
-  }
-  return $items;
-}
Index: mediafield.info
===================================================================
RCS file: mediafield.info
diff -N mediafield.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mediafield.info	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,7 @@
+; $Id: videofield.info,v 1.4 2008/06/26 08:55:12 acm Exp $
+name = Media field
+description = Defines audio and video widgets for CCK file fields.
+core = 6.x
+dependencies[] = filefield
+dependencies[] = getid3
+package = CCK
Index: mediafield.install
===================================================================
RCS file: mediafield.install
diff -N mediafield.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mediafield.install	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,98 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Installation functions.
+ */
+
+/**
+ * Implementation of hook_schema().
+ */
+function mediafield_schema() {
+  return array(
+    'mediafield_id3' => array(
+      'description' => t('ID3 data for media files.'),
+      'fields' => array(
+        'fid' => array(
+          'description' => t('The file identifier.'),
+          'type' => 'int',
+          'unsigned' => TRUE,
+          'not null' => TRUE,
+          'default' => 0,
+        ),
+        'fileformat' => array(
+          'description' => t('The video data format for video files.'),
+          'type' => 'varchar',
+          'length' => 10,
+        ),
+        'videox' => array(
+          'description' => t('The horizontal resolution for video files.'),
+          'type' => 'int',
+          'size' => 'small',
+          'length' => 4,
+          'not null' => TRUE,
+          'default' => 0,
+        ),
+        'videoy' => array(
+          'description' => t('The vertical resolution for video files.'),
+          'type' => 'int',
+          'size' => 'small',
+          'length' => 4,
+          'not null' => TRUE,
+          'default' => 0,
+        ),
+        'bits_per_sample' => array(
+          'description' => t('The total bits per sample for video files.'),
+          'type' => 'int',
+          'length' => 10,
+        ),
+        'videocodec' => array(
+          'description' => t('The video codec for video files.'),
+          'type' => 'varchar',
+          'length' => 255,
+        ),
+        'audiocodec' => array(
+          'description' => t('The audio codec for video files.'),
+          'type' => 'varchar',
+          'length' => 255,
+        ),
+        'sample_rate' => array(
+          'description' => t('The audio sample rate.'),
+          'type' => 'int',
+          'length' => 10,
+        ),
+        'bitrate' => array(
+          'description' => t('The bit rate for audio files.'),
+          'type' => 'float',
+          'unsigned' => TRUE,
+        ),
+        'channel_mode' => array(
+          'description' => t('The audio channel mode.'),
+          'type' => 'varchar',
+          'length' => 10,
+        ),
+        'playtime' => array(
+          'description' => t('The file play duration.'),
+          'type' => 'varchar',
+          'length' => 10,
+        ),
+      ),
+      'primary key' => array('fid'),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_install().
+ */
+function mediafield_install() {
+  drupal_install_schema('mediafield');
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function mediafield_uninstall() {
+  drupal_load('module', 'content');
+}
Index: mediafield.module
===================================================================
RCS file: mediafield.module
diff -N mediafield.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mediafield.module	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,274 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Core functions.
+ */
+
+/**
+ * Implementation of hook_elements().
+ */
+function mediafield_elements() {
+  $filefield_elements = filefield_elements();
+  $elements['mediafield_audio'] = $filefield_elements['filefield_widget'];
+  $elements['mediafield_video'] = $filefield_elements['filefield_widget'];
+  $elements['mediafield_audio']['#element_validate'][] = 'mediafield_audio_validate';
+  $elements['mediafield_video']['#element_validate'][] = 'mediafield_video_validate';
+  return $elements;
+}
+
+/**
+ * Implementation of hook_widget_info().
+ */
+function mediafield_widget_info() {
+  return array(
+    'mediafield_audio' => array(
+      'label' => t('Audio'),
+      'field types' => array('filefield'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+      'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM),
+      'description' => t('An edit widget for audio files.'),
+    ),
+    'mediafield_video' => array(
+      'label' => t('Video'),
+      'field types' => array('filefield'),
+      'multiple values' => CONTENT_HANDLE_CORE,
+      'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM),
+      'description' => t('An edit widget for video files.'),
+    ),
+  );
+}
+
+/**
+ * Implementation of hook_widget_settings().
+ */
+function mediafield_widget_settings($op, $widget) {
+  switch ($op) {
+    case 'form':
+      $form = module_invoke('filefield', 'widget_settings', 'form', $widget);
+      $form['file_extensions']['#default_value'] = is_string($widget['file_extensions']) ? $widget['file_extensions'] : NULL;
+      $form['file_extensions']['#description'] = t('Extensions a user can upload to this field. Enter separate extensions in lower case, separating them with a space, and do not include the leading dot. Only !type file extensions are supported with this widget.', array('!type' => $widget['type'] == 'mediafield_audio' ? t('audio') : t('video')));
+      return $form;
+    case 'validate':
+      $extensions = array_filter(explode(' ', $widget['file_extensions']));
+      $web_extensions = _mediafield_file_extensions($widget['type']);
+      if (count($invalid = array_diff($extensions, $web_extensions))) {
+        form_set_error('file_extensions', t('Invalid file extensions: @error. Only video files are supported through the video widget. If you need to upload other types of files, change the widget to use a standard file upload.', array('@error' => implode(', ', $invalid))));
+      }
+      break;
+    case 'save':
+      return module_invoke('filefield', 'widget_settings', 'save', $widget);
+    }
+}
+
+/**
+ * Implementation of hook_default_value().
+ */
+function mediafield_default_value(&$form, &$form_state, $field, $delta) {
+  $items = array();
+  $max = 1;
+  if ($field['multiple']) {
+    $field_name = $field['field_name'];
+    $max = isset($form_state['item_count'][$field_name]) ? $form_state['item_count'][$field_name] : 1;
+  }
+  for ($delta = 0; $delta < $max; $delta++) {
+    $items[$delta] = array();
+  }
+  return $items;
+}
+
+/**
+ * Implementation of hook_widget().
+ */
+function mediafield_widget(&$form, &$form_state, $field, $items, $delta = 0) {
+  $element = filefield_widget($form, $form_state, $field, $items, $delta);
+  $element['#upload_validators'] = array_merge($element['#upload_validators'], mediafield_widget_upload_validators($field));
+  return $element;
+}
+
+function mediafield_widget_upload_validators($field) {
+  $web_extensions = _mediafield_file_extensions($field['widget']['type']);
+  $extensions = array_filter(explode(' ', $field['widget']['file_extensions']));
+  if (empty($extensions)) {
+    $extensions = $web_extensions;
+  }
+  $validators['filefield_validate_extensions'][] = implode(' ', array_intersect($extensions, $web_extensions));
+  return $validators;
+}
+
+/**
+ * Return an array of known video file extensions.
+ */
+function _mediafield_file_extensions($type) {
+  switch ($type) {
+    case 'mediafield_audio':
+      $ogg = array('ogg', 'oga', 'spx');
+      $mpeg = array('mp1', 'mp2', 'mp3', 'm1a', 'm2a', 'mpa');
+      $wm = array('wma');
+      $aac = array('m4a', 'm4b', 'm4p', 'm4v', 'm4r', '3gp', 'mp4', 'aac');
+      $rm = array('rm', 'ra');
+      $mid = array('mid', 'midi');
+      $aif = array('aiff', 'aif', 'aifc');
+      $au = array('au', 'snd');
+      $wav = array('wav');
+      $flac = array('flac');
+      $flash = array('f4a', 'f4b');
+      $matroska = array('mka');
+      return array_merge($ogg, $mpeg, $wm, $aac, $rm, $mid, $aif, $au, $wav, $flac, $flash, $matroska);
+    case 'mediafield_video':
+      $_3gp = array('3gp', '3g2');
+      $asf = array('asf');
+      $avi = array('avi');
+      $avchd = array('bdf');
+      $bink = array('bik');
+      $mpeg1 = array('mpg', 'mpeg', 'm1v', 'mpv', 'fp');
+      $flash = array('flv', 'f4v', 'f4p');
+      $mpeg2 = array('m2v', 'vob');
+      $matroska = array('mkv');
+      $quicktime = array('mov', 'qt');
+      $mpeg4 = array('mp4');
+      $mxf = array('mxf');
+      $nsv = array('nsv');
+      $ogg = array('ogg', 'ogv');
+      $rm = array('rm');
+      $smk2 = array('smk');
+      $wmv = array('wmv');
+      $divx = array('divx');
+      $videocd = array('vcd');
+      return array_merge($_3gp, $asf, $avi, $avchd, $bink, $mpeg1, $flash, $mpeg2, $matroska, $quicktime, $mpeg4, $mxf, $nsv, $ogg, $rm, $smk2, $wmv, $divx, $videocd);
+  }
+}
+
+/**
+ * Implementation of hook_field_formatter_info().
+ */
+function mediafield_field_formatter_info() {
+  $formatters = array(
+    'audio' => array(
+      'label' => t('Audio'),
+      'field types' => array('filefield'),
+    ),
+    'video' => array(
+      'label' => t('Video'),
+      'field types' => array('filefield'),
+    ),
+  );
+  return $formatters;
+}
+
+/**
+ * Implementation of hook_file_insert().
+ */
+function mediafield_file_insert(&$file) {
+  $info = getid3_analyze($file->filepath);
+  if (isset($info['video'])) {
+    $file->mediafield['fileformat'] = $info['video']['dataformat'];
+    if (isset($info['video']['resolution_x'])) {
+      $file->mediafield['videox'] = $info['video']['resolution_x'];
+      $file->mediafield['videoy'] = $info['video']['resolution_y'];
+    }
+    elseif (isset($info['video']['streams'])) {
+      foreach ($info['video']['streams'] as $stream) {
+        $file->mediafield['videox'] = max($file->mediafield['videox'], $stream['resolution_x']);
+        $file->mediafield['videoy'] = max($file->mediafield['videoy'], $stream['resolution_y']);
+      }
+    }
+    if (isset($info['video']['bits_per_sample'])) {
+      $file->mediafield['bits_per_sample'] = $info['video']['bits_per_sample'];
+    }
+    if (isset($info['video']['codec'])) {
+      $file->mediafield['videocodec'] = $info['video']['codec'];
+    }
+    elseif (isset($info['video']['streams'][0]['codec'])) {
+      $file->mediafield['videocodec'] = $info['video']['streams'][0]['codec'];
+    }
+    if (isset($info['audio']['codec'])) {
+      $file->mediafield['audiocodec'] = $info['audio']['codec'];
+    }
+    elseif (isset($info['audio']['streams'][0]['codec'])) {
+      $file->mediafield['audiocodec'] = $info['audio']['streams'][0]['codec'];
+    }
+  }
+  if (isset($info['audio']['sample_rate'])) {
+    $file->mediafield['sample_rate'] = $info['audio']['sample_rate'];
+  }
+  elseif (isset($info['audio']['streams'][0]['sample_rate'])) {
+    $file->mediafield['sample_rate'] = $info['audio']['streams'][0]['sample_rate'];
+  }
+  if (!isset($info['video'])) {
+    $file->mediafield['bitrate'] = $info['bitrate'];
+  }
+  if (isset($info['audio']['channelmode'])) {
+    $file->mediafield['channel_mode'] = $info['audio']['channelmode'];
+  }
+  elseif (isset($info['audio']['streams'][0]['channelmode'])) {
+    $file->mediafield['channel_mode'] = $info['audio']['streams'][0]['channelmode'];
+    if ($file->mediafield['channel_mode'] != 'mono') {
+      break;
+    }
+  }
+  $file->mediafield['playtime'] = $info['playtime_string'];
+  $record = array_merge(array('fid' => $file->fid), $file->mediafield);
+  drupal_write_record('mediafield_id3', $record);
+}
+
+/**
+ * Implementation of hook_file_load().
+ */
+function mediafield_file_load(&$file) {
+  $mediafield = db_fetch_array(db_query("SELECT * FROM {mediafield_id3} WHERE fid = %d", $file->fid));
+  unset($mediafield['fid']);
+  $file->mediafield = array_filter($mediafield);
+}
+
+/**
+ * Implementation of hook_file_update().
+ */
+function mediafield_file_update(&$file) {
+  if (!empty($file->fid)) {
+    mediafield_file_delete($file);
+    mediafield_file_insert($file);
+  }
+}
+
+/**
+ * Implementation of hook_file_delete().
+ */
+function mediafield_file_delete($file) {
+  db_query("DELETE FROM {mediafield_id3} WHERE fid = %d", $file->fid);
+}
+
+/**
+ * Implementation of hook_theme().
+ */
+function mediafield_theme() {
+  return array(
+    'mediafield_audio' => array(
+      'arguments' => array('element' => NULL),
+      'file' => 'theme/mediafield.theme.inc',
+    ),
+    'mediafield_video' => array(
+      'arguments' => array('element' => NULL),
+      'file' => 'theme/mediafield.theme.inc',
+    ),
+    'mediafield_formatter_audio' => array(
+      'arguments' => array('element' => array()),
+      'template' => 'theme/mediafield_formatter_audio',
+      'file' => 'theme/mediafield.theme.inc',
+    ),
+    'mediafield_formatter_video' => array(
+      'arguments' => array('element' => array()),
+      'template' => 'theme/mediafield_formatter_video',
+      'file' => 'theme/mediafield.theme.inc',
+    ),
+    'mediafield_samplerate' => array(
+      'arguments' => array('samplerate' => 0),
+      'file' => 'theme/mediafield.theme.inc',
+    ),
+    'mediafield_bitrate' => array(
+      'arguments' => array('bitrate' => 0),
+      'file' => 'theme/mediafield.theme.inc',
+    ),
+  );
+}
Index: multimediafile.inc
===================================================================
RCS file: multimediafile.inc
diff -N multimediafile.inc
--- multimediafile.inc	26 Jun 2008 09:38:36 -0000	1.8
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,219 +0,0 @@
-<?php
-
-/**
- * Temp function to allow use of getId3 module while we wait for a patch
- */
-function mediafield_getid3_analyze($path){
-  getid3_load();
-  return (GETID3_VERSION != 'GETID3_VERSION'?getid3_analyze($path):array());
-}
-
-
-/**
- * Wrapper function for _file_check_directory that accepts a form element
- * to validate - if user specified one. Won't allow form submit unless the
- * directory exists & is writable
- *
- * @param $form_element
- *   The form element containing the name of the directory to check.
- */
-function _file_form_check_directory($form_element) {
-  if(!empty($form_element['#value'])) {
-    _file_check_directory($form_element['#value'], $form_element);
-  }
-  return $form_element;
-}
-
-/**
- * Create the directory relative to the 'files' dir recursively for every
- * directory in the path.
- *
- * @param $directory
- *   The directory path under files to check, such as 'media/path/here'
- * @param $form_element
- *   A form element to throw an error on if the directory is not writable
- */
-function _file_check_directory($directory, $form_element = array()) {
-  foreach (explode('/', $directory) as $dir) {
-    $dirs[] = $dir;
-    file_check_directory(file_create_path(implode($dirs,'/')), FILE_CREATE_DIRECTORY, $form_element['#parents'][0]);
-  }
-  return TRUE;
-}
-
-/**
- * Protects server from uploading files like file.php.mp3. Should be moved into core.
- */
-function _file_munge_filename($filename, $extensions, $alerts = 1) {
-  $original = $filename;
-  $whitelist = array_unique(explode(' ', trim($extensions)));
-
-  $filename_parts = explode('.', $filename);
-
-  $new_filename = array_shift($filename_parts); // Remove file basename.
-  $final_extension = array_pop($filename_parts); // Remove final extension.
-
-  foreach($filename_parts as $filename_part) {
-    $new_filename .= ".$filename_part";
-    if (!in_array($filename_part, $whitelist) && preg_match("/^[a-zA-Z]{2,5}\d?$/", $filename_part)) {
-      $new_filename .= '_';
-    }
-  }
-  $filename = "$new_filename.$final_extension";
-
-  if ($alerts && $original != $filename) {
-    $message = t('Your filename has been renamed to conform to site policy.');
-    drupal_set_message($message, 'warning');
-  }
-
-  return $filename;
-}
-
-/**
- * Insert a file into the database.
- *
- * @param $node
- *    node object file will be associated with.
- * @param $file
- *    file to be inserted, passed by reference since fid should be attached.
- *
- */
-function _field_file_insert($node, &$file, $field) {
-  $fieldname = $field['field_name'];
-  $safe_filename = _file_munge_filename($file['filename'], trim($field['widget']['file_extensions']));
-  $filepath = file_create_path($field['widget']['upload_path']) . '/' . $safe_filename;
-
-  if (_file_check_directory($field['widget']['upload_path']) && $file = file_save_upload((object)$file,  $filepath)) {
-    $file = (array)$file;
-    $file['fid'] = db_next_id('{files}_fid');
-    db_query(
-      "INSERT into {files} (fid, nid, filename, filepath, filemime, filesize) VALUES (%d, %d, '%s', '%s', '%s', %d)",
-      $file['fid'], $node->nid, $file['filename'], $file['filepath'], $file['filemime'], $file['filesize']
-    );
-    return (array)$file;
-  }
-  else {
-    form_set_error(NULL, t('File upload was unsuccessful!'));
-    return FALSE;
-  }
-}
-
-/**
- * Update the video file record if necessary.
- */
-function _field_file_update($node, &$file, $field) {
-  $file = (array)$file;
-  if ($file['flags']['delete'] == TRUE) {
-     _field_file_delete($file, $field['field_name'], $field['type']);
-     return array();
-  }
-  if ($file['fid'] == 'upload') {
-    return _field_file_insert($node, $file, $field);
-  }
-  else {
-  }
-  return $file;
-}
-
-/**
- * Delete a file from the files table and disk.
- */
-function _field_file_delete($file, $fieldname, $type) {
-  if (is_numeric($file['fid'])) {
-    db_query('DELETE FROM {files} WHERE fid = %d', $file['fid']);
-  }
-  else {
-    unset($_SESSION[$type][$fieldname][$file['sessionid']]);
-  }
-  return file_delete($file['filepath']);
-}
-
-function _field_clear_session($type) {
-  if (is_array($_SESSION[$type]) && count($_SESSION[$type])) {
-    foreach (array_keys($_SESSION[$type]) as $fieldname) {
-      _field_clear_field_session($fieldname, $type);
-    }
-    unset($_SESSION[$type]);
-  }
-}
-
-function _field_clear_field_session($fieldname, $type) {
-  if (count($_SESSION[$type][$fieldname])) {
-    foreach ($_SESSION[$type][$fieldname] as $files) {
-      if (is_file($file['filepath'])) {
-        file_delete($file['filepath']);
-      }
-    }
-    unset($_SESSION[$type][$fieldname]);
-  }
-}
-
-/**
- * Load file information from files table.
- */
-function _field_file_load($fid = NULL) {
-  if (isset($fid)) {
-    if (is_numeric($fid)) {
-      $result = db_query('SELECT * FROM {files} WHERE fid = %d', $fid);
-      $file = db_fetch_array($result);
-      return ($file) ? $file : array();
-    }
-  }
-  return array();
-}
-
-/**
- * Formats audio sample rate.
- */
-function format_samplerate($samplerate) {
-  return sprintf("%.1f kHz", $samplerate/1000);
-}
-
-/**
- * Formats audio bit rate.
- */
-function format_bitrate($bitrate) {
-  return sprintf("%d Kbps", $bitrate/1000);
-}
-
-/**
- * Formats file size.
- */
-function format_filesize($size) {
-  $size = $size/1024;
-  $result = '';
-  if ($size > 0) {
-    $result = sprintf("%.02f MB", $size/1024);
-  } else {
-    $result = sprintf("%.02f Kb", $size);
-  }
-  return $result;
-}
-
-/**
- * Searchs is there a specified resource in the current theme directory.
- * If not, get the path of the parent module.
- *
- * @param string $filename
- *   File name to search for.
- * @param string $module
- *   A name of the module which is a parent module of this file.
- * @param string $ext
- *   File extension.
- * @param string $default
- *   Default file to use if selected file is not found
- * @return string
- *   A path of the file.
- */
-function _file_get_resource_path($filename, $module, $ext = 'png', $default = false) {
-  $resource = path_to_theme() .'/mediaicons/'. "$filename.$ext";
-  if (!file_exists($resource)) {
-    $resource = drupal_get_path('module', $module) .'/mediaicons/'. "$filename.$ext";
-  }
-  
-  if ($default !== false AND !file_exists($resource)) {
-    $resource = _file_get_resource_path($default, $module, $ext);
-  }
-  return $resource;
-//  return check_url(base_path(). $resource);
-}
Index: videofield.css
===================================================================
RCS file: videofield.css
diff -N videofield.css
--- videofield.css	10 Feb 2007 15:20:15 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,9 +0,0 @@
-.videofield-icon {
-  float: left;
-}
-
-
-
-
-
-
Index: videofield.info
===================================================================
RCS file: videofield.info
diff -N videofield.info
--- videofield.info	26 Jun 2008 08:55:12 -0000	1.4
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,5 +0,0 @@
-; $Id: videofield.info,v 1.4 2008/06/26 08:55:12 acm Exp $
-name = Video Field
-description = Defines video field type for CCK content.
-dependencies = content getid3
-package = CCK
Index: videofield.module
===================================================================
RCS file: videofield.module
diff -N videofield.module
--- videofield.module	26 Jun 2008 09:38:36 -0000	1.11
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,561 +0,0 @@
-<?php
-
-/**
- * Implementation of hook_field_info().
- */
-function videofield_field_info() {
-  return array(
-    'file_video' => array('label' => 'Video file'),
-  );
-}
-
-/**
- * Implementation of hook_field_settings().
- */
-function videofield_field_settings($op, $field) {
-  switch ($op) {
-    case 'form':
-      $form = array();
-      return $form;
-
-    case 'validate':
-      break;
-
-    case 'save':
-      return array('fileformat', 'videox', 'videoy', 'bits_per_sample', 'videocodec', 'audiocodec', 'sample_rate', 'bitrate', 'channel_mode', 'playtime');
-
-    case 'database columns':
-      $columns = array(
-        'fid' => array('type' => 'int', 'not null' => TRUE, 'default' => '0'),
-        'fileformat' => array('type' => 'varchar', length => 10, 'not null' => FALSE),
-        'videox' => array('type' => 'smallint', length => 4, 'not null' => TRUE, 'default' => '0'),
-        'videoy' => array('type' => 'smallint', length => 4, 'not null' => TRUE, 'default' => '0'),
-        'bits_per_sample' => array('type' => 'int', length => 10, 'not null' => FALSE),
-        'videocodec' => array('type' => 'varchar', length => 255, 'not null' => FALSE),
-        'audiocodec' => array('type' => 'varchar', length => 255, 'not null' => FALSE),
-        'sample_rate' => array('type' => 'int', length => 10, 'not null' => FALSE),
-        'channel_mode' => array('type' => 'varchar', length => 10, 'not null' => FALSE),
-        'playtime' => array('type' => 'varchar', length => 10, 'not null' => FALSE),
-      );
-      return $columns;
-  }
-}
-
-/**
- * Implementation of hook_field().
- */
-function videofield_field($op, $node, $field, &$node_field, $a1, $a2) {
-  require_once(drupal_get_path('module', 'videofield') .'/multimediafile.inc');
-  $fieldname = $field['field_name'];
-  switch ($op) {
-    case 'load':
-      $output = array();
-      if (count($node_field)) {
-        $values = array();
-        foreach ($node_field as $delta => $file) {
-          if (!empty($file)) {
-            $values[$delta]  = array_merge($node_field[$delta], _field_file_load($file['fid']));
-            $node_field[$delta] = $values[$delta];
-          }
-          $output = array($fieldname => $values);
-        }
-      }
-      break;
-
-    case 'view':
-      $files = array();
-      foreach ($node_field as $delta => $item) {
-        $node_field[$delta]['view'] = content_format($field, $item, 'default');
-      }
-      $output = theme('field', $node, $field, $node_field, $a1, $a2);
-      break;
-
-    case 'insert':
-      foreach ($node_field as  $delta => $item) {
-        $node_field[$delta] = _field_file_insert($node, $item, $field);
-      }
-      break;
-
-    case 'update':
-      foreach ($node_field as $delta => $item) {
-        $node_field[$delta] = _field_file_update($node, $item, $field);
-      }
-      break;
-
-    case 'delete':
-      foreach ($node_field as $delta => $item) {
-        _field_file_delete($item, $field['field_name'], $field['type']);
-      }
-      break;
-  }
-  return $output;
-}
-
-/**
- * Implementation of hook_widget_info().
- */
-function videofield_widget_info() {
-  return array(
-    'video' => array(
-      'label' => 'video file',
-      'field types' => array('file_video'),
-    ),
-  );
-}
-
-/**
- * Implementation of hook_widget_settings().
- */
-function videofield_widget_settings($op, $widget) {
-  require_once(drupal_get_path('module', 'videofield') .'/multimediafile.inc');
-  switch ($op) {
-    case 'form':
-      $form = array();
-      $form['upload_path'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Path to save uploaded file to'),
-        '#default_value' => $widget['upload_path'] ? $widget['upload_path'] : '',
-        '#size' => 64,
-        '#description' => t('A directory where all files uploaded for this field instance will be saved. Example %ex.', array('%ex' => 'media/funny')),
-        '#after_build' => array('_file_form_check_directory')
-      );
-      $form['file_extensions'] = array(
-        '#type' => 'textfield',
-        '#title' => t('Permitted uploaded file extensions'),
-        '#default_value' => $widget['file_extensions'] ? $widget['file_extensions'] : 'avi mpg ogg wmv',
-        '#size' => 64,
-        '#description' => t('Extensions a user can upload to this field. Enter separate extensions, in lower case, separating them with a space and do not include the leading dot.')
-      );
-      return $form;
-    case 'validate':
-      break;
-    case 'save':
-      return array('file_extensions', 'upload_path');
-  }
-}
-
-function _videofield_widget_prepare_form_values(&$node, $field, &$node_field) {
-  $fieldname = $field['field_name'];
-  $type = $field['type'];
-	if (!count($_POST)) {
-		_field_clear_session($type);
-	}
-
-	if ($file = file_check_upload($fieldname .'_upload')) {
-		$file = (array)$file;
-    
-		$ext = strtolower(array_pop(explode('.', $file['filename'])));
-		$allowed_extensions = array_unique(explode(' ', trim($field['widget']['file_extensions'])));
-		if (!in_array($ext, $allowed_extensions)) {
-			form_set_error($field['field_name'] .'_upload', t('Files with the extension %ext are not allowed. Please upload a file with an extension from the following list: %allowed_extensions.', array('%ext' => $ext, '%allowed_extensions' => $field['widget']['file_extensions'])));
-			return FALSE;
-		}
-
-		$file['upload_path'] = trim($field['widget']['upload_path']);
-
-		$file['fid'] = 'upload';
-		if (!$field['multiple']) {
-			if (is_array($node_field)) {
-				foreach ($node_field as $delta => $session_file) {
-					$node_field[$delta]['flags']['delete'] = TRUE;
-				}
-			}
-			_field_clear_field_session($fieldname, $field['type']);
-		}
-
-		// Add the file to the session
-		$file['sessionid'] = count($node_field) + count($_SESSION[$type][$fieldname]);
-		$_SESSION[$type][$fieldname][$file['sessionid']] = $file;
-	}
-
-	if (is_array($_SESSION[$type][$fieldname]) && count($_SESSION[$type][$fieldname])) {
-		foreach ($_SESSION[$type][$fieldname] as $delta => $file) {
-			$node_field[] = $file;
-		}
-	}
-}
-
-function _videofield_widget_validate(&$node, $field, &$node_field) {
-	if ($field['required']) {
-		if (!count($node_field)) {
-			form_set_error($fieldname, $field['widget']['label'] .' is required.');
-		}
-	}
-}
-
-/**
- * Implementation of hook_widget().
- */
-function videofield_widget($op, &$node, $field, &$node_field) {
-  require_once(drupal_get_path('module', 'videofield') .'/multimediafile.inc');
-  $fieldname = $field['field_name'];
-  $type = $field['type'];
-  switch ($op) {
-    case 'prepare form values':
-      _videofield_widget_prepare_form_values($node, $field, $node_field);
-      break;
-
-    case 'form':
-      $form = _videofield_widget_form($node, $field, $node_field);
-      return $form;
-
-    case 'validate':
-      _videofield_widget_validate($node, $field, $node_field);
-      return;
-
-    case 'process form values':
-        break;
-  }
-}
-
-function _videofield_widget_form($node, $field, &$node_field) {
-  drupal_add_js('misc/progress.js');
-  drupal_add_js('misc/upload.js');
-
-  $fieldname = $field['field_name'];
-  drupal_add_css(drupal_get_path('module', 'videofield') .'/videofield.css');
-
-  $form = array();
-  $form[$fieldname] = array(
-    '#type' => 'fieldset',
-    '#title' => t($field['widget']['label']),
-    '#weight' => $field['widget']['weight'],
-    '#collapsible' => TRUE,
-    '#collapsed' => FALSE,
-    '#tree' => TRUE,
-    '#theme' => 'videofield_current',
-    '#prefix' => '<div id="'. form_clean_id($fieldname .'-attach-wrapper') .'">',
-    '#suffix' => '</div>',
-  );
-
-  $form[$fieldname]['new'] = array(
-    '#tree' => FALSE,
-    '#prefix' => '<div id="'. form_clean_id($fieldname .'-attach-hide') .'">',
-    '#suffix' => '</div>',
-    '#weight' => 100,
-  );
-
-  $form[$fieldname]['new'][$fieldname .'_upload'] = array(
-    '#type'  => 'file',
-    '#description' => ($field['widget']['description'] ? $field['widget']['description']. '<br/>' : ''). t('Allowed extensions: %ext.', array('%ext' => $field['widget']['file_extensions'])),
-    '#weight' => 9,
-    '#tree' => FALSE,
-  );
-
-  $form[$fieldname]['new']['upload'] = array(
-    '#type' => 'button',
-    '#value' => t('Upload'),
-    '#name' => 'cck_videofield_'. $fieldname .'_op',
-    '#id' => form_clean_id($fieldname .'-attach-button'),
-    '#tree' => FALSE,
-    '#weight' => 10,
-  );
-
-  if (is_array($node_field) && count($node_field)) {
-    foreach ($node_field as $delta => $file) {
-      if ($file['filepath'] && !$file['flags']['delete']) {
-        $form[$fieldname][$delta]['flags']['delete'] = array(
-          '#type' => 'checkbox',
-          '#default_value' => 0,
-        );
-
-        if ($file['filepath']) {
-          $form[$fieldname][$delta]['icon'] = array(
-            '#type' => 'markup',
-            '#value' => theme('videofield_icon', $file),
-          );
-
-          if (strpos($file['fid'], 'upload') === false) {
-            $filepath =  $file['filepath'];
-          } else {
-            $filepath =  file_create_filename($file['filename'], file_create_path());
-          }
-
-          $path = $filepath;
-          if (strpos($file['fid'], 'upload') !== false) {
-            $path =  $file['filepath'];
-          }
-
-          $info = video_getid3_info($path);
-
-          $description = file_create_url($filepath);
-          $description = "<small>". check_plain($description) ."</small>";
-          $form[$fieldname][$delta]['name'] = array('#type' => 'markup', '#value' => (strlen($file['description'])) ? $file['description'] : $file['filename'], '#maxlength' => 256, '#description' => $description );
-          $form[$fieldname][$delta]['size'] = array('#type' => 'markup', '#value' => format_filesize($file['filesize']));
-
-          $form[$fieldname][$delta]['mfileformat'] = array('#type' => 'markup', '#value' => $info['fileformat']);
-          $form[$fieldname][$delta]['mvideosize'] = array('#type' => 'markup', '#value' => $info['videox'] .'x'. $info['videoy']);
-          $form[$fieldname][$delta]['mbps'] = array('#type' => 'markup', '#value' => $info['bps']);
-          $form[$fieldname][$delta]['mvideocodec'] = array('#type' => 'markup', '#value' => $info['videocodec']);
-          $form[$fieldname][$delta]['maudiocodec'] = array('#type' => 'markup', '#value' => $info['audiocodec']);
-
-          $form[$fieldname][$delta]['msample_rate'] = array('#type' => 'markup', '#value' => format_samplerate($info['sample_rate']));
-          $form[$fieldname][$delta]['mchannel_mode'] = array('#type' => 'markup', '#value' => $info['channelmode']);
-          $form[$fieldname][$delta]['mplaytime'] = array('#type' => 'markup', '#value' => $info['playtime'] .' min');
-
-          $form[$fieldname][$delta]['filename'] = array('#type' => 'value',  '#value' => $file['filename']);
-          $form[$fieldname][$delta]['filepath'] = array('#type' => 'value',  '#value' => $file['filepath']);
-          $form[$fieldname][$delta]['filemime'] = array('#type' => 'value',  '#value' => $file['filemime']);
-          $form[$fieldname][$delta]['filesize'] = array('#type' => 'value',  '#value' => $file['filesize']);
-          $form[$fieldname][$delta]['fid'] = array('#type' => 'value',  '#value' => $file['fid']);
-
-          $form[$fieldname][$delta]['fileformat'] = array('#type' => 'value', '#value' => $info['fileformat']);
-          $form[$fieldname][$delta]['videox'] = array('#type' => 'value', '#value' => $info['videox']);
-          $form[$fieldname][$delta]['videoy'] = array('#type' => 'value', '#value' => $info['videoy']);
-          $form[$fieldname][$delta]['bits_per_sample'] = array('#type' => 'value', '#value' => $info['bps']);
-          $form[$fieldname][$delta]['videocodec'] = array('#type' => 'value', '#value' => $info['videocodec']);
-          $form[$fieldname][$delta]['audiocodec'] = array('#type' => 'value', '#value' => $info['audiocodec']);
-
-          $form[$fieldname][$delta]['sample_rate'] = array('#type' => 'value', '#value' => $info['sample_rate']);
-          $form[$fieldname][$delta]['channel_mode'] = array('#type' => 'value', '#value' => $info['channelmode']);
-          $form[$fieldname][$delta]['playtime'] = array('#type' => 'value', '#value' => $info['playtime']);
-
-          // Special handling for single value fields
-          if (!$field['multiple']) {
-            $form[$fieldname][$delta]['replace'] = array(
-              '#type' => 'markup',
-              '#value' => t('If a new file is chosen, the current file will be replaced upon submitting the form.'),
-              '#weight' => 8,
-            );
-          }
-        }
-      } elseif ($file['filepath'] && $file['flags']['delete']) {
-        $form[$fieldname][$delta]['flags']['delete'] = array(
-          '#type' => 'hidden', // A value type will not persist here, must be hidden
-          '#value' => $file['flags']['delete'],
-        );
-      }
-    }
-  }
-  // The class triggers the js upload behaviour.
-  $form[$fieldname.'-attach-url'] = array(
-    '#type' => 'hidden',
-    '#value' => url('videofield/js', NULL, NULL, TRUE),
-    '#attributes' => array('class' => 'upload'),
-  );
-
-  // Some useful info for our js callback.
-  $form['vid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->vid,
-    '#tree' => FALSE,
-  );
-  $form['nid'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->nid,
-    '#tree' => FALSE,
-  );
-  $form['type'] = array(
-    '#type' => 'hidden',
-    '#value' => $node->type,
-    '#tree' => FALSE,
-  );
-  return $form;
-}
-
-/**
- * Implementation of hook_field_formatter_info().
- */
-function videofield_field_formatter_info() {
-  $formatters = array(
-    'default' => array(
-      'label' => t('Default'),
-      'field types' => array('file_video'),
-    ),
-  );
-  return $formatters;
-}
-
-/**
- * Implementation of hook_field_formatter().
- */
-function videofield_field_formatter($field, $item, $formatter) {
-  require_once(drupal_get_path('module', 'videofield') .'/multimediafile.inc');
-  if (!isset($item['fid'])) {
-    return '';
-  }
-  $file = _field_file_load($item['fid']);
-  return theme('videofield', $file, $item, $field);
-}
-
-/**
- * Read media information from the specified file.
- */
-function video_getid3_info($path) {
-  $info = &mediafield_getid3_analyze($path);
-
-  $other = @reset($info['video']['streams']);
-  $result['videox']     = @$other['resolution_x'];
-  $result['videoy']     = @$other['resolution_y'];
-  $result['bps']        = @$other['bits_per_sample'];
-  $result['videocodec'] = @$other['codec'];
-
-  $other = @reset($info['audio']['streams']);
-  $result['audiocodec']  = @$other['codec'];
-
-  $result['fileformat'] = @$info['video']['dataformat'];
-  $result['channelmode'] = @$info['audio']['channelmode'];
-  $result['sample_rate'] = @$info['audio']['sample_rate'];
-  $result['playtime']    = @$info['playtime_string'];
-
-  return $result;
-}
-
-/**
- * A themed output for a currently uploaded file (used on a node edit form).
- *
- * @param array $form
- *   A form array.
- */
-function theme_videofield_current(&$form) {
-  $header = array(t('Type'), t('Filename'), t('Video'), t('Audio'),  t('Playtime'), t('Size'), t('Delete'));
-  $output = '';
-
-  foreach (element_children($form) as $key) {
-    if (is_numeric($key)) {
-      if (!($form[$key]['flags']['delete']['#type'] == 'hidden')) {
-        $row = array();
-        $row[] = drupal_render($form[$key]['icon']);
-        $row[] = drupal_render($form[$key]['name']);
-        $row[] = drupal_render($form[$key]['mfileformat']) .','. drupal_render($form[$key]['mvideosize']) .','. drupal_render($form[$key]['mvideocodec']) .','. drupal_render($form[$key]['mbps']);
-        $row[] = drupal_render($form[$key]['msample_rate']) .','. drupal_render($form[$key]['mchannel_mode']) .','. drupal_render($form[$key]['maudiocodec']);
-        $row[] = drupal_render($form[$key]['mplaytime']);
-        $row[] = drupal_render($form[$key]['size']);
-        $row[] = drupal_render($form[$key]['flags']);
-        $rows[] = $row;
-      } else {
-        $output = drupal_render($form[$key]['flags']);
-      }
-    }
-  }
-  if (count($rows)) {
-    $output .= theme('table', $header, $rows);
-  }
-  if (count($rows) == 1) {
-    $output .= drupal_render($form[0]['replace']);
-  }
-
-  $output .= drupal_render($form);
-  return $output;
-}
-
-/**
- * A themed output for an icon representing a file type.
- *
- * @param unknown_type $file
- * @return unknown
- */
-function theme_videofield_icon($file) {
-  $ext = strtolower(array_pop(explode('.', $file['filename'])));;
-  
-  $image = theme('image', _file_get_resource_path($ext, 'videofield', 'png', 'video'));
-
-  return <<<OUTPUT
-<div class="videofield-icon icon-$ext">
-  $image
-</div>
-OUTPUT;
-}
-
-/*function theme_videofield_view_file($file, $item, $field) {
-  return theme('videofield', $file);
-}*/
-
-function theme_videofield($file, $item, $field) {
-  $file = (array)$file;
-  if (is_file($file['filepath'])) {
-    if ($file['fid'] == 'upload') {
-      $path = file_create_filename($file['filename'], file_create_path());
-    } else {
-      $path = $file['filepath'];
-    }
-    $name = $file['filename'];
-    $desc = $file['description'];
-    $url = l($name, file_create_url($path));
-
-    $rows = array();
-    $rows[] = array(
-      array('data' => t('Name')),
-      array('data' => $url),
-    );
-    $video = $item['fileformat'] .','. $item['videox'] .'x'. $item['videoy'] .','. $item['videocodec'] .','. $item['bits_per_sample'];
-    $rows[] = array(
-      array('data' => t('Video')),
-      array('data' => $video),
-    );
-    $audio = format_samplerate($item['sample_rate']) .','. $item['channel_mode'] .','. $item['audiocodec'];
-    $rows[] = array(
-      array('data' => t('Audio')),
-      array('data' => $audio),
-    );
-    $rows[] = array(
-      array('data' => t('Duration')),
-      array('data' => $item['playtime'] .' min'),
-    );
-    $rows[] = array(
-      array('data' => t('Size')),
-      array('data' => format_filesize($item['filesize'])),
-    );
-
-    return theme('table', array(), $rows);
-  }
-}
-
-/**
- * Menu callback for JavaScript-based uploads.
- */
-function videofield_js() {
-  // Parse fieldname from submit button.
-  $matches = array();
-  foreach(array_keys($_POST) as $key) {
-    if (preg_match('/cck_videofield_(.*)_op/', $key, $matches)) {
-      $fieldname = $matches[1];
-      break;
-    }
-  }
-
-  $node = (object)$_POST;
-  $field = content_fields($fieldname, $node->type); // load field data
-
-  // Load fids stored by content.module.
-  $node_field = array();
-  $values = content_field('load', $node, $field, $node_field, FALSE, FALSE);
-  $node_field = $values[$fieldname];
-
-  // Load additional field data.
-  videofield_field('load', $node, $field, $node_field, FALSE, FALSE);
-
-  // Handle uploads and validation.
-  _videofield_widget_prepare_form_values($node, $field, $node_field);
-  _videofield_widget_validate($node, $field, $node_field);
-
-  // Get our new form baby, yeah tiger, get em!
-  $form = _videofield_widget_form($node, $field, $node_field);
-
-  foreach (module_implements('form_alter') as $module) {
-    $function = $module .'_form_alter';
-    $function('videofield_js', $form);
-  }
-  $form = form_builder('videofield_js', $form);
-
-  $output = theme('status_messages') . drupal_render($form);
-
-  // Send the updated file attachments form.
-  print drupal_to_js(array('status' => TRUE, 'data' => $output));
-  exit();
-}
-    
-function videofield_menu($may_cache) {
-  $items = array();
-
-  if (!$may_cache) {
-    $items[] = array(
-      'path' => 'videofield/js',
-      'callback' => 'videofield_js',
-      //'access' => user_access(),
-      'access' => TRUE,
-      'type' => MENU_CALLBACK
-    );
-  }
-  return $items;
-}
Index: docs/mediafield.php
===================================================================
RCS file: docs/mediafield.php
diff -N docs/mediafield.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ docs/mediafield.php	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,21 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Documentation functions.
+ */
+
+/**
+ * @see template_preprocess_mediafield_formatter_audio()
+ * @see mediafield_formatter_audio.tpl.php
+ */
+function theme_mediafield_formatter_audio() {
+}
+
+/**
+ * @see template_preprocess_mediafield_formatter_video()
+ * @see mediafield_formatter_video.tpl.php
+ */
+function theme_mediafield_formatter_video() {
+}
Index: legacy/audiofield.info
===================================================================
RCS file: legacy/audiofield.info
diff -N legacy/audiofield.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ legacy/audiofield.info	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,6 @@
+; $Id: audiofield.info,v 1.4 2008/06/26 08:55:12 acm Exp $
+name = Audio field
+description = Converts audio fields to file fields. Uninstall this module after update.php has finished running.
+core = 6.x
+dependencies[] = mediafield
+package = CCK
Index: legacy/audiofield.install
===================================================================
RCS file: legacy/audiofield.install
diff -N legacy/audiofield.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ legacy/audiofield.install	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,105 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Installation functions.
+ */
+
+/**
+ * Implementation of hook_enable().
+ */
+function audiofield_enable() {
+  audiofield_update_6000();
+}
+
+/**
+ * Implementation of hook_update_N().
+ */
+function audiofield_update_6000() {
+  $ret = array();
+  if (module_exists('mediafield')) {
+    $result = db_query("SELECT * FROM {content_node_field} WHERE type = 'file_audio'");
+    while ($field = db_fetch_array($result)) {
+      $field['global_settings'] = unserialize($field['global_settings']);
+      $field['db_columns'] = unserialize($field['db_columns']);
+      $global_settings = serialize(array(
+        'list_field' => FALSE,
+        'list_default' => TRUE,
+        'description_field' => FALSE,
+      ));
+      $update = db_query("UPDATE {content_node_field} SET type = 'filefield', global_settings = '%s' WHERE field_name = '%s'", $global_settings, $field[field_name]);
+      $ret[] = array('success' => $update !== FALSE, 'query' => "UPDATE {content_node_field} SET type = 'filefield', global_settings = '$global_settings' WHERE field_name = '$field[field_name]'");
+      // If field has its own table, rename columns.
+      if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) {
+        _audiofield_field_convert($ret, $field[field_name], $field);
+      }
+      $field_result = db_query("SELECT * FROM {content_node_field_instance} WHERE field_name = '%s'", $field['field_name']);
+      while ($instance = db_fetch_array($field_result)) {
+        $instance['widget_settings'] = unserialize($instance['widget_settings']);
+        $widget_settings = serialize(array(
+          'file_extensions' => $instance['widget_settings']['file_extensions'],
+          'file_path' => $instance['widget_settings']['upload_path'],
+          'max_filesize_per_file' => NULL,
+          'max_filesize_per_node' => NULL,
+        ));
+        $instance['display_settings'] = unserialize($instance['display_settings']);
+        $instance['display_settings']['teaser']['format'] = 'audio';
+        $instance['display_settings']['full']['format'] = 'audio';
+        $display_settings = serialize($instance['display_settings']);
+        $update = db_query("UPDATE {content_node_field_instance} SET widget_type = 'mediafield_audio', widget_settings = '%s', display_settings = '%s', widget_module = 'mediafield', widget_active = 1 WHERE field_name = '%s' AND type_name = '%s'", $widget_settings, $display_settings, $instance[field_name], $instance[type_name]);
+        $ret[] = array('success' => $result !== FALSE, 'query' => "UPDATE {content_node_field_instance} SET widget_type = 'mediafield_audio', widget_settings = '$widget_settings', display_settings = '$display_settings', widget_module = 'mediafield', widget_active = 1 WHERE field_name = '$instance[field_name]' AND type_name = '$instance[type_name]'");
+        // If field uses type table, rename columns.
+        if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) {
+          _audiofield_field_convert($ret, $instance['type_name'], $field);
+        }
+      }
+    }
+    content_associate_fields('filefield');
+  }
+  else {
+    $ret['#abort'] = array('success' => FALSE, 'query' => t('Media field must be enabled before audio fields can be converted.'));
+  }
+  return $ret;
+}
+
+function _audiofield_field_convert(&$ret, $name, $field) {
+  static $schema;
+  if (!isset($schema)) {
+    $schema = module_invoke('filefield', 'field_settings', 'database_columns', $field);
+  }
+  $table = _content_tablename($name, $field['db_storage']);
+  foreach ($schema as $column => $spec) {
+    if (db_column_exists($table, "$field[field_name]_$column")) {
+      db_change_field($ret, $table, "$field[field_name]_$column", "$field[field_name]_$column", $spec);
+    }
+    else {
+      db_add_field($ret, $table, "$field[field_name]_$column", $spec);
+    }
+  }
+  $content = db_query("SELECT * FROM {{$table}}");
+  while ($file = db_fetch_object($content)) {
+    if (!empty($file->{$field['field_name'] .'_fid'})) {
+      $data = array(
+        'fid' => $file->{$field['field_name'] .'_fid'},
+        'sample_rate' => $file->{$field['field_name'] .'_sample_rate'},
+        'bitrate' => $file->{$field['field_name'] .'_bitrate'},
+        'channel_mode' => $file->{$field['field_name'] .'_channel_mode'},
+        'playtime' => $file->{$field['field_name'] .'_playtime'},
+      );
+      drupal_write_record('mediafield_id3', $data);
+    }
+    $update = db_query("UPDATE {{$table}} SET $field[field_name]_list = 1 WHERE vid = %d", $data, $file->vid);
+    $ret[] = array('success' => $update !== FALSE, 'query' => "UPDATE {{$table}} SET $field[field_name]_list = 1 WHERE vid = $file->vid");
+  }
+  db_drop_field($ret, $table, "$field[field_name]_sample_rate");
+  db_drop_field($ret, $table, "$field[field_name]_bitrate");
+  db_drop_field($ret, $table, "$field[field_name]_channel_mode");
+  db_drop_field($ret, $table, "$field[field_name]_playtime");
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function audiofield_uninstall() {
+}
Index: legacy/audiofield.module
===================================================================
RCS file: legacy/audiofield.module
diff -N legacy/audiofield.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ legacy/audiofield.module	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,7 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Core functions.
+ */
Index: legacy/videofield.info
===================================================================
RCS file: legacy/videofield.info
diff -N legacy/videofield.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ legacy/videofield.info	17 Apr 2009 16:28:13 -0000
@@ -0,0 +1,6 @@
+; $Id: videofield.info,v 1.4 2008/06/26 08:55:12 acm Exp $
+name = Video field
+description = Converts video fields to file fields. Uninstall this module after update.php has finished running.
+core = 6.x
+dependencies[] = mediafield
+package = CCK
Index: legacy/videofield.install
===================================================================
RCS file: legacy/videofield.install
diff -N legacy/videofield.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ legacy/videofield.install	17 Apr 2009 16:28:14 -0000
@@ -0,0 +1,115 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Installation functions.
+ */
+
+/**
+ * Implementation of hook_enable().
+ */
+function videofield_enable() {
+  videofield_update_6000();
+}
+
+/**
+ * Implementation of hook_update_N().
+ */
+function videofield_update_6000() {
+  $ret = array();
+  if (module_exists('mediafield')) {
+    $result = db_query("SELECT * FROM {content_node_field} WHERE type = 'file_video'");
+    while ($field = db_fetch_array($result)) {
+      $field['global_settings'] = unserialize($field['global_settings']);
+      $field['db_columns'] = unserialize($field['db_columns']);
+      $global_settings = serialize(array(
+        'list_field' => FALSE,
+        'list_default' => TRUE,
+        'description_field' => FALSE,
+      ));
+      $update = db_query("UPDATE {content_node_field} SET type = 'filefield', global_settings = '%s' WHERE field_name = '%s'", $global_settings, $field[field_name]);
+      $ret[] = array('success' => $update !== FALSE, 'query' => "UPDATE {content_node_field} SET type = 'filefield', global_settings = '$global_settings' WHERE field_name = '$field[field_name]'");
+      // If field has its own table, rename columns.
+      if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD) {
+        _videofield_field_convert($ret, $field[field_name], $field);
+      }
+      $field_result = db_query("SELECT * FROM {content_node_field_instance} WHERE field_name = '%s'", $field['field_name']);
+      while ($instance = db_fetch_array($field_result)) {
+        $instance['widget_settings'] = unserialize($instance['widget_settings']);
+        $widget_settings = serialize(array(
+          'file_extensions' => $instance['widget_settings']['file_extensions'],
+          'file_path' => $instance['widget_settings']['upload_path'],
+          'max_filesize_per_file' => NULL,
+          'max_filesize_per_node' => NULL,
+        ));
+        $instance['display_settings'] = unserialize($instance['display_settings']);
+        $instance['display_settings']['teaser']['format'] = 'video';
+        $instance['display_settings']['full']['format'] = 'video';
+        $display_settings = serialize($instance['display_settings']);
+        $update = db_query("UPDATE {content_node_field_instance} SET widget_type = 'mediafield_video', widget_settings = '%s', display_settings = '%s', widget_module = 'mediafield', widget_active = 1 WHERE field_name = '%s' AND type_name = '%s'", $widget_settings, $display_settings, $instance[field_name], $instance[type_name]);
+        $ret[] = array('success' => $result !== FALSE, 'query' => "UPDATE {content_node_field_instance} SET widget_type = 'mediafield_video', widget_settings = '$widget_settings', display_settings = '$display_settings', widget_module = 'mediafield', widget_active = 1 WHERE field_name = '$instance[field_name]' AND type_name = '$instance[type_name]'");
+        // If field uses type table, rename columns.
+        if ($field['db_storage'] == CONTENT_DB_STORAGE_PER_CONTENT_TYPE) {
+          _videofield_field_convert($ret, $instance['type_name'], $field);
+        }
+      }
+    }
+    content_associate_fields('filefield');
+  }
+  else {
+    $ret['#abort'] = array('success' => FALSE, 'query' => t('Media field must be enabled before video fields can be converted.'));
+  }
+  return $ret;
+}
+
+function _videofield_field_convert(&$ret, $name, $field) {
+  static $schema;
+  if (!isset($schema)) {
+    $schema = module_invoke('filefield', 'field_settings', 'database_columns', $field);
+  }
+  $table = _content_tablename($name, $field['db_storage']);
+  foreach ($schema as $column => $spec) {
+    if (db_column_exists($table, "$field[field_name]_$column")) {
+      db_change_field($ret, $table, "$field[field_name]_$column", "$field[field_name]_$column", $spec);
+    }
+    else {
+      db_add_field($ret, $table, "$field[field_name]_$column", $spec);
+    }
+  }
+  $result = db_query("SELECT * FROM {{$table}}");
+  while ($file = db_fetch_object($result)) {
+    if (!empty($file->{$field['field_name'] .'_fid'})) {
+      $data = array(
+        'fid' => $file->{$field['field_name'] .'_fid'},
+        'fileformat' => $file->{$field['field_name'] .'_fileformat'},
+        'videox' => $file->{$field['field_name'] .'_videox'},
+        'vidoey' => $file->{$field['field_name'] .'_videoy'},
+        'bits_per_sample' => $file->{$field['field_name'] .'_bits_per_sample'},
+        'videocodec' => $file->{$field['field_name'] .'_videocodec'},
+        'audiocodec' => $file->{$field['field_name'] .'_audiocodec'},
+        'sample_rate' => $file->{$field['field_name'] .'_sample_rate'},
+        'channel_mode' => $file->{$field['field_name'] .'_channel_mode'},
+        'playtime' => $file->{$field['field_name'] .'_playtime'},
+      );
+      drupal_write_record('mediafield_id3', $data);
+    }
+    $update = db_query("UPDATE {{$table}} SET $field[field_name]_list = 1 WHERE vid = %d", $file->vid);
+    $ret[] = array('success' => $update !== FALSE, 'query' => "UPDATE {{$table}} SET $field[field_name]_list = 1 WHERE vid = $file->vid");
+  }
+  db_drop_field($ret, $table, "$field[field_name]_fileformat");
+  db_drop_field($ret, $table, "$field[field_name]_videox");
+  db_drop_field($ret, $table, "$field[field_name]_videoy");
+  db_drop_field($ret, $table, "$field[field_name]_bits_per_sample");
+  db_drop_field($ret, $table, "$field[field_name]_videocodec");
+  db_drop_field($ret, $table, "$field[field_name]_audiocodec");
+  db_drop_field($ret, $table, "$field[field_name]_sample_rate");
+  db_drop_field($ret, $table, "$field[field_name]_channel_mode");
+  db_drop_field($ret, $table, "$field[field_name]_playtime");
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function videofield_uninstall() {
+}
Index: legacy/videofield.module
===================================================================
RCS file: legacy/videofield.module
diff -N legacy/videofield.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ legacy/videofield.module	17 Apr 2009 16:28:14 -0000
@@ -0,0 +1,7 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Core functions.
+ */
Index: theme/mediafield.theme.inc
===================================================================
RCS file: theme/mediafield.theme.inc
diff -N theme/mediafield.theme.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ theme/mediafield.theme.inc	17 Apr 2009 16:28:14 -0000
@@ -0,0 +1,74 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Theme functions
+ */
+
+/**
+ * Theme for the audio widget.
+ */
+function theme_mediafield_audio(&$element) {
+  return theme('form_element', $element, $element['#children']);
+}
+
+/**
+ * Theme for the video widget.
+ */
+function theme_mediafield_video(&$element) {
+  return theme('form_element', $element, $element['#children']);
+}
+
+/**
+ * Themed output for audiofield on a node view page.
+ *
+ * @see mediafield_formatter_audio.tpl.php
+ * @see theme_mediafield_formatter_audio()
+ */
+function template_preprocess_mediafield_formatter_audio(&$variables) {
+  $item = $variables['element']['#item'];
+  $variables['item'] = $item;
+  $variables['url'] = l($item['filename'], file_create_url($item['filepath']));
+  $variables['filesize'] = format_size($item['filesize']);
+  $variables['sample_rate'] = theme('mediafield_samplerate', $item['mediafield']['sample_rate']);
+  $variables['bitrate'] = theme('mediafield_bitrate', $item['mediafield']['bitrate']);
+  $variables['channel_mode'] = $item['mediafield']['channel_mode'];
+  $variables['playtime'] = $item['mediafield']['playtime'];
+}
+
+/**
+ * Themed output for audiofield on a node view page.
+ *
+ * @see mediafield_formatter_video.tpl.php
+ * @see theme_mediafield_formatter_video()
+ */
+function template_preprocess_mediafield_formatter_video(&$variables) {
+  $item = $variables['element']['#item'];
+  $variables['item'] = $item;
+  $variables['url'] = l($item['filename'], file_create_url($item['filepath']));
+  $variables['filesize'] = format_size($item['filesize']);
+  $variables['fileformat'] = $item['mediafield']['fileformat'];
+  $variables['videox'] = $item['mediafield']['videox'];
+  $variables['videoy'] = $item['mediafield']['videoy'];
+  $variables['bits_per_sample'] = $item['mediafield']['bits_per_sample'];
+  $variables['videocodec'] = $item['mediafield']['videocodec'];
+  $variables['audiocodec'] = $item['mediafield']['audiocodec'];
+  $variables['sample_rate'] = theme('mediafield_samplerate', $item['mediafield']['sample_rate']);
+  $variables['channel_mode'] = $item['mediafield']['channel_mode'];
+  $variables['playtime'] = $item['mediafield']['playtime'];
+}
+
+/**
+ * Format audio sample rate.
+ */
+function theme_mediafield_samplerate($samplerate) {
+  return sprintf("%.1f kHz", $samplerate/1000);
+}
+
+/**
+ * Format audio bit rate.
+ */
+function theme_mediafield_bitrate($bitrate) {
+  return sprintf("%d Kbps", $bitrate/1000);
+}
Index: theme/mediafield_formatter_audio.tpl.php
===================================================================
RCS file: theme/mediafield_formatter_audio.tpl.php
diff -N theme/mediafield_formatter_audio.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ theme/mediafield_formatter_audio.tpl.php	17 Apr 2009 16:28:14 -0000
@@ -0,0 +1,21 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Themed output for audio field on a node view page.
+ *
+ * Available variables:
+ * - $item: Complete array of file properties.
+ * - $url: Link to the file.
+ * - $filesize: Formatted file size.
+ * - $sample_rate: Formatted sample rate.
+ * - $bitrate: Formatted bit rate.
+ * - $channel_mode: Whether channel is stereo or mono.
+ * - $playtime: Play time string.
+ *
+ * @see template_preprocess_mediafield_formatter_audio()
+ * @see theme_mediafield_formatter_audio()
+ */
+?>
+<div><?php print $sample_rate; ?>, <?php print $bitrate; ?> <?php print $url; ?> <?php print $playtime; ?> (<?php print $filesize; ?>)</div>
Index: theme/mediafield_formatter_video.tpl.php
===================================================================
RCS file: theme/mediafield_formatter_video.tpl.php
diff -N theme/mediafield_formatter_video.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ theme/mediafield_formatter_video.tpl.php	17 Apr 2009 16:28:14 -0000
@@ -0,0 +1,49 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Themed output for video field on a node view page.
+ *
+ * Available variables:
+ * - $item: Complete array of file properties.
+ * - $url: Link to the file.
+ * - $filesize: Formatted file size.
+ * - $fileformat: File format.
+ * - $videox: Horizontal video resolution.
+ * - $videoy: Vertical video resolution.
+ * - $bits_per_sample: Video bits per sample.
+ * - $videocodec: Video encoding.
+ * - $audiocodec: Audio encoding.
+ * - $sample_rate: Formatted sample rate.
+ * - $channel_mode: Whether channel is stereo or mono.
+ * - $playtime: Play time string.
+ *
+ * @see template_preprocess_mediafield_formatter_video()
+ * @see theme_mediafield_formatter_video()
+ */
+?>
+<table>
+  <tbody>
+    <tr class="odd">
+      <td><?php print t('Name'); ?></td>
+      <td><?php print $url; ?></td>
+    </tr>
+    <tr class="even">
+      <td><?php print t('Video'); ?></td>
+      <td><?php print $fileformat; ?>, <?php print $videox; ?>&times;<?php print $videoy; ?>, <?php print $videocodec; ?>, <?php print $bits_per_sample; ?></td>
+    </tr>
+    <tr class="odd">
+      <td><?php print t('Audio'); ?></td>
+      <td><?php print $sample_rate; ?>, <?php print $channel_mode; ?>, <?php print $audiocodec; ?></td>
+    </tr>
+    <tr class="even">
+      <td><?php print t('Duration'); ?></td>
+      <td><?php print $playtime; ?></td>
+    </tr>
+    <tr class="odd">
+      <td><?php print t('Size'); ?></td>
+      <td><?php print $filesize; ?></td>
+    </tr>
+  </tbody>
+</table>
\ No newline at end of file
Index: translations/mediafield.pot
===================================================================
RCS file: translations/mediafield.pot
diff -N translations/mediafield.pot
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ translations/mediafield.pot	17 Apr 2009 16:28:14 -0000
@@ -0,0 +1,95 @@
+# $Id$
+#
+# LANGUAGE translation of Drupal (general)
+# Copyright YEAR NAME <EMAIL@ADDRESS>
+# Generated from files:
+#  mediafield.module: n/a
+#  theme/mediafield_formatter_video.tpl.php: n/a
+#  videofield.info,v 1.4 2008/06/26 08:55:12 acm
+#  audiofield.info,v 1.4 2008/06/26 08:55:12 acm
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PROJECT VERSION\n"
+"POT-Creation-Date: 2009-04-08 13:45-0400\n"
+"PO-Revision-Date: YYYY-mm-DD HH:MM+ZZZZ\n"
+"Last-Translator: NAME <EMAIL@ADDRESS>\n"
+"Language-Team: LANGUAGE <EMAIL@ADDRESS>\n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=utf-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"Plural-Forms: nplurals=INTEGER; plural=EXPRESSION;\n"
+
+#: mediafield.module:27;150 theme/mediafield_formatter_video.tpl.php:20
+msgid "Audio"
+msgstr ""
+
+#: mediafield.module:31
+msgid "An edit widget for audio files."
+msgstr ""
+
+#: mediafield.module:34;154 theme/mediafield_formatter_video.tpl.php:16
+msgid "Video"
+msgstr ""
+
+#: mediafield.module:38
+msgid "An edit widget for video files."
+msgstr ""
+
+#: mediafield.module:51
+msgid "Extensions a user can upload to this field. Enter separate extensions in lower case, separating them with a space, and do not include the leading dot. Only !type file extensions are supported with this widget."
+msgstr ""
+
+#: mediafield.module:51
+msgid "audio"
+msgstr ""
+
+#: mediafield.module:51
+msgid "video"
+msgstr ""
+
+#: mediafield.module:57
+msgid "Invalid file extensions: @error. Only video files are supported through the video widget. If you need to upload other types of files, change the widget to use a standard file upload."
+msgstr ""
+
+#: mediafield.info:0
+msgid "Media field"
+msgstr ""
+
+#: mediafield.info:0
+msgid "Defines audio and video widgets for CCK file fields."
+msgstr ""
+
+#: mediafield.info:0 legacy/audiofield.info:0 legacy/videofield.info:0
+msgid "CCK"
+msgstr ""
+
+#: legacy/audiofield.info:0
+msgid "Audio field"
+msgstr ""
+
+#: legacy/audiofield.info:0
+msgid "Converts audio fields to file fields. Uninstall this module after update.php has finished running."
+msgstr ""
+
+#: legacy/videofield.info:0
+msgid "Video field"
+msgstr ""
+
+#: legacy/videofield.info:0
+msgid "Converts video fields to file fields. Uninstall this module after update.php has finished running."
+msgstr ""
+
+#: theme/mediafield_formatter_video.tpl.php:12
+msgid "Name"
+msgstr ""
+
+#: theme/mediafield_formatter_video.tpl.php:24
+msgid "Duration"
+msgstr ""
+
+#: theme/mediafield_formatter_video.tpl.php:28
+msgid "Size"
+msgstr ""
+
