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 13 Apr 2009 15:18:25 -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 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 @@ - 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' => '
', - '#suffix' => '
', - '#theme' => 'audiofield_current', - ); - - $form[$fieldname]['new'] = array( - '#tree' => FALSE, - '#prefix' => '
', - '#suffix' => '
', - '#weight' => 100, - ); - - $form[$fieldname]['new'][$fieldname .'_upload'] = array( - '#type' => 'file', - '#description' => ($field['widget']['description'] ? $field['widget']['description']. '
' : ''). 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 = "". check_plain($description) .""; - $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 << - $image - -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("
%s %s min %s %s (%s)
", $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 13 Apr 2009 15:18:25 -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 13 Apr 2009 15:18:25 -0000 @@ -0,0 +1,116 @@ + 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'); + drupal_load('module', 'content'); + content_notify('install', 'mediafield'); +} + +/** + * Implementation of hook_enable(). + */ +function mediafield_enable() { + content_notify('enable', 'mediafield'); +} + +/** + * Implementation of hook_disable(). + */ +function mediafield_disable() { + content_notify('disable', 'mediafield'); +} + +/** + * Implementation of hook_uninstall(). + */ +function mediafield_uninstall() { + drupal_load('module', 'content'); + content_notify('uninstall', 'mediafield'); + drupal_uninstall_schema('mediafield'); +} Index: mediafield.module =================================================================== RCS file: mediafield.module diff -N mediafield.module --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ mediafield.module 13 Apr 2009 15:18:25 -0000 @@ -0,0 +1,274 @@ + 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 @@ -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 @@ - 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' => '
', - '#suffix' => '
', - ); - - $form[$fieldname]['new'] = array( - '#tree' => FALSE, - '#prefix' => '
', - '#suffix' => '
', - '#weight' => 100, - ); - - $form[$fieldname]['new'][$fieldname .'_upload'] = array( - '#type' => 'file', - '#description' => ($field['widget']['description'] ? $field['widget']['description']. '
' : ''). 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 = "". check_plain($description) .""; - $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 << - $image - -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 13 Apr 2009 15:18:25 -0000 @@ -0,0 +1,21 @@ + 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' 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' 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_notify('enable', 'mediafield'); + } + 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 13 Apr 2009 15:18:25 -0000 @@ -0,0 +1,7 @@ + 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' 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' 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_notify('enable', 'mediafield'); + } + 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 13 Apr 2009 15:18:25 -0000 @@ -0,0 +1,7 @@ + +
, ()
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 13 Apr 2009 15:18:25 -0000 @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
, ×, ,
, ,
\ 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 13 Apr 2009 15:18:25 -0000 @@ -0,0 +1,95 @@ +# $Id$ +# +# LANGUAGE translation of Drupal (general) +# Copyright YEAR NAME +# 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 \n" +"Language-Team: LANGUAGE \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 "" +