diff options
Diffstat (limited to 'types/uploadfield')
-rw-r--r-- | types/uploadfield/uploadfield.info | 9 | ||||
-rw-r--r-- | types/uploadfield/uploadfield.install | 25 | ||||
-rw-r--r-- | types/uploadfield/uploadfield.module | 146 | ||||
-rw-r--r-- | types/uploadfield/uploadfield.theme.inc | 18 | ||||
-rw-r--r-- | types/uploadfield/uploadfield_widget.inc | 129 |
5 files changed, 327 insertions, 0 deletions
diff --git a/types/uploadfield/uploadfield.info b/types/uploadfield/uploadfield.info new file mode 100644 index 0000000..9468461 --- /dev/null +++ b/types/uploadfield/uploadfield.info @@ -0,0 +1,9 @@ +; $Id$ +name = Video Upload +description = Handle video upload for video module using filefield and CCK. +core = 6.x +version = 6.x-4.x-dev +dependencies[] = content +dependencies[] = filefield +dependencies[] = video +package = "Video"
\ No newline at end of file diff --git a/types/uploadfield/uploadfield.install b/types/uploadfield/uploadfield.install new file mode 100644 index 0000000..a2e1b65 --- /dev/null +++ b/types/uploadfield/uploadfield.install @@ -0,0 +1,25 @@ +<?php +// $Id$ + +/** + * Implementation of hook_install(). + */ +function uploadfield_install() { + drupal_load('module', 'content'); + content_notify('install', 'uploadfield'); +} + +function uploadfield_uninstall() { + drupal_load('module', 'content'); + content_notify('uninstall', 'uploadfield'); +} + +function uploadfield_enable() { + drupal_load('module', 'content'); + content_notify('enable', 'uploadfield'); +} + +function uploadfield_disable() { + drupal_load('module', 'content'); + content_notify('disable', 'uploadfield'); +}
\ No newline at end of file diff --git a/types/uploadfield/uploadfield.module b/types/uploadfield/uploadfield.module new file mode 100644 index 0000000..9664e1e --- /dev/null +++ b/types/uploadfield/uploadfield.module @@ -0,0 +1,146 @@ +<?php +// $Id$ + +/** + * @file + * uploadfield core hooks and menu callbacks. + */ + +module_load_include('inc', 'uploadfield', 'uploadfield_widget'); + +/** + * Implementation of hook_perm(). + */ +function uploadfield_perm() { + return array('use default thumbnail', 'bypass conversion video'); +} + +/** + * Implementation of hook_theme(). + */ +function uploadfield_theme() { + $theme = array(); + $theme['uploadfield_widget'] = array( + 'arguments' => array('element' => NULL), + 'file' => 'uploadfield.theme.inc', + ); + $theme['uploadfield_widget_item'] = array( + 'arguments' => array('element' => NULL), + 'file' => 'uploadfield.theme.inc', + ); + return $theme; +} + +/** + * Implementation of CCK's hook_widget_info(). + */ +function uploadfield_widget_info() { + return array( + 'uploadfield_widget' => 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, including video thumbnails and transcoding to flash.'), + ), + ); +} + + +/** + * Implementation of hook_elements(). + */ +function uploadfield_elements() { + $elements = array(); + // An uploadfield is really just a FileField with extra processing. + $filefield_elements = module_invoke('filefield', 'elements'); + $elements['uploadfield_widget'] = $filefield_elements['filefield_widget']; + $elements['uploadfield_widget']['#process'][] = 'uploadfield_widget_process'; + $elements['uploadfield_widget']['#element_validate'][] = 'uploadfield_widget_validate'; + // uploadfield needs a separate value callback to save its alt and title texts. + $elements['uploadfield_widget']['#value_callback'] = 'uploadfield_widget_value'; + return $elements; +} + +/** + * Implementation of hook_file_download. + */ +function uploadfield_file_download($filepath) { + // Return headers for default images. + if (strpos($filepath, 'video_thumbs') !== FALSE) { + $full_path = file_create_path($filepath); + if ($info = getimagesize($full_path)) { + return array( + 'Content-Type: ' . $info['mime'], + 'Content-Length: ' . filesize($full_path) + ); + } + } +} + +/** + * Implementation of CCK's hook_widget_settings(). + */ +function uploadfield_widget_settings($op, $widget) { + switch ($op) { + case 'form': + return uploadfield_widget_settings_form($widget); + case 'validate': + return uploadfield_widget_settings_validate($widget); + case 'save': + return uploadfield_widget_settings_save($widget); + } +} + +/** + * Implementation of hook_widget(). + */ +function uploadfield_widget(&$form, &$form_state, $field, $items, $delta = NULL) { + $item = array('fid' => 0, 'list' => $field['list_default'], 'data' => array('description' => '', 'video_thumb' => '')); + if (isset($items[$delta])) { + $item = array_merge($item, $items[$delta]); + } + return filefield_widget($form, $form_state, $field, $items, $delta); +} + +/** + * Implementation of CCK's hook_default_value(). + */ +function uploadfield_default_value(&$form, &$form_state, $field, $delta) { + return filefield_default_value($form, $form_state, $field, $delta); +} + +/** + * Implementation of hook_form_[form_id]_alter(). + * + * Modify the add new field form to make "Video" the default formatter. + */ +function uploadfield_form_content_field_overview_form_alter(&$form, &$form_state) { + $form['#submit'][] = 'uploadfield_form_content_field_overview_submit'; +} + +/** + * Submit handler to set a new field's formatter to "video_plain". + */ +function uploadfield_form_content_field_overview_submit(&$form, &$form_state) { + if (isset($form_state['fields_added']['_add_new_field']) && isset($form['#type_name'])) { + $new_field = $form_state['fields_added']['_add_new_field']; + $node_type = $form['#type_name']; + $field = content_fields($new_field, $node_type); + if ($field['widget']['module'] == 'uploadfield') { + foreach ($field['display_settings'] as $display_type => $display_settings) { + if ($field['display_settings'][$display_type]['format'] == 'default') { + $field['display_settings'][$display_type]['format'] = 'video_plain'; + } + } + content_field_instance_update($field); + } + } +} + +/** + * filefield source support + */ +function uploadfield_filefield_sources_widgets() { + return array('uploadfield_widget'); +}
\ No newline at end of file diff --git a/types/uploadfield/uploadfield.theme.inc b/types/uploadfield/uploadfield.theme.inc new file mode 100644 index 0000000..5a81efd --- /dev/null +++ b/types/uploadfield/uploadfield.theme.inc @@ -0,0 +1,18 @@ +<?php +//$Id$ +/** + * + * @file + * Theme functions for the videoftp module. + */ + +/** + * FormAPI theme function. Theme the output of an video upload field. + */ +function theme_uploadfield_widget($element) { + return theme('form_element', $element, $element['#children']); +} + +function theme_uploadfield_widget_item($element) { + return theme('filefield_widget_item', $element); +}
\ No newline at end of file diff --git a/types/uploadfield/uploadfield_widget.inc b/types/uploadfield/uploadfield_widget.inc new file mode 100644 index 0000000..68e447d --- /dev/null +++ b/types/uploadfield/uploadfield_widget.inc @@ -0,0 +1,129 @@ +<?php +// $Id$ + +/** + * @file + * uploadfield widget hooks and callbacks. + */ + +/** + * Implementation of CCK's hook_widget_settings($op = 'form'). + */ +function uploadfield_widget_settings_form($widget) { + $form = module_invoke('filefield', 'widget_settings', 'form', $widget); + + if ($form['file_extensions']['#default_value'] == 'txt') { + $form['file_extensions']['#default_value'] = 'mp4 mpeg avi mpg wmv flv mov'; + } + //fix our path settings + $form['path_settings']['file_path']['#default_value'] = ltrim(ltrim($form['path_settings']['file_path']['#default_value'], "videos"), "/"); //wierd i had to break this into two ltrims... + $form['path_settings']['file_path']['#description'] = t('Optional subdirectory within the "<em>files/videos/</em>" directory where files will be stored. Do not include preceding or trailing slashes.'); + array_unshift($form['path_settings']['file_path']['#element_validate'], 'video_widget_settings_file_path_validate'); + + //default settings + $default = video_default_widget_settings($widget); + $form = $form + $default; + return $form; +} + +/** + * Implementation of CCK's hook_widget_settings($op = 'validate'). + */ +function uploadfield_widget_settings_validate($widget) { + // Check that only web images are specified in the callback. + if(!video_web_extensions($widget['file_extensions'])) { + form_set_error('file_extensions', t('Only web-standard videos are supported through the videoftp widget. If needing to upload other types of files, change the widget to use a standard file upload.')); + } +} + +/** + * Implementation of CCK's hook_widget_settings($op = 'save'). + */ +function uploadfield_widget_settings_save($widget) { + $filefield_settings = module_invoke('filefield', 'widget_settings', 'save', $widget); + return array_merge($filefield_settings, array('default_video_thumb', 'default_dimensions', 'default_player_dimensions', 'autoconversion', 'autothumbnail')); +} + +/** + * Element #value_callback function. + */ +function uploadfield_widget_value($element, $edit = FALSE) { + //copied from filefield_widget_value with one change to reset our data array + if (!$edit) { + $file = field_file_load($element['#default_value']['fid']); + $item = $element['#default_value']; + } + else { + $item = array_merge($element['#default_value'], $edit); + $field = content_fields($element['#field_name'], $element['#type_name']); + + // Uploads take priority over value of fid text field. + if ($fid = filefield_save_upload($element)) { + $item['fid'] = $fid; + $item['data'] = array(); //reset our data array for thumbnails and values. + } + // Check for #filefield_value_callback values. + // Because FAPI does not allow multiple #value_callback values like it does + // for #element_validate and #process, this fills the missing functionality + // to allow FileField to be extended purely through FAPI. + elseif (isset($element['#filefield_value_callback'])) { + foreach ($element['#filefield_value_callback'] as $callback) { + $callback($element, $item); + } + } + + // Load file if the FID has changed so that it can be saved by CCK. + $file = field_file_load($item['fid']); + + // If the file entry doesn't exist, don't save anything. + if (empty($file)) { + $item = array(); + } + + // Checkboxes loose their value when empty. + // If the list field is present make sure its unchecked value is saved. + if (!empty($field['list_field']) && empty($edit['list'])) { + $item['list'] = 0; + } + } + // Merge file and item data so it is available to all widgets. + $item = array_merge($item, $file); + + return $item; +} + +/** + * Element #process callback function. + */ +function uploadfield_widget_process($element, $edit, &$form_state, $form) { + $item = $element['#value']; + $field_name = $element['#field_name']; + $delta = $element['#delta']; + $field = content_fields($element['#field_name'], $element['#type_name']); + $element['#theme'] = 'uploadfield_widget_item'; + + if (isset($element['preview']) && $element['#value']['fid'] != 0) { + $element['preview']['#value'] = theme('video_widget_preview', $element['#value']); + } + + // Title is not necessary for each individual field. + if ($field['multiple'] > 0) { + unset($element['#title']); + } + + // Create our thumbnails + if($field['widget']['autothumbnail']) { + video_thumb_process($element); + } + + // Add our extra fields if in preview mode + if(!empty($item['fid'])) { + video_widget_element_settings($element); + } + + // Lets use the clicked_button #submit[0] value here instead and see how that works out for now... + if($form_state['submitted'] == 1) { + video_widget_process($element, $form_state); + } + return $element; +}
\ No newline at end of file |