From 20c5802e66b87bccb7030217eda7ab31e68ef79c Mon Sep 17 00:00:00 2001 From: Heshan Wanigasooriya Date: Sun, 5 Dec 2010 15:53:26 +0000 Subject: Rename uploadfield submodule to videoupload --- types/uploadfield/uploadfield.info | 10 --- types/uploadfield/uploadfield.install | 27 ------ types/uploadfield/uploadfield.module | 146 ------------------------------- types/uploadfield/uploadfield.theme.inc | 18 ---- types/uploadfield/uploadfield_widget.inc | 129 --------------------------- types/videoupload/videoupload.field.inc | 7 ++ types/videoupload/videoupload.info | 10 +++ types/videoupload/videoupload.install | 27 ++++++ types/videoupload/videoupload.module | 146 +++++++++++++++++++++++++++++++ types/videoupload/videoupload.theme.inc | 18 ++++ types/videoupload/videoupload_widget.inc | 129 +++++++++++++++++++++++++++ 11 files changed, 337 insertions(+), 330 deletions(-) delete mode 100644 types/uploadfield/uploadfield.info delete mode 100644 types/uploadfield/uploadfield.install delete mode 100644 types/uploadfield/uploadfield.module delete mode 100644 types/uploadfield/uploadfield.theme.inc delete mode 100644 types/uploadfield/uploadfield_widget.inc create mode 100644 types/videoupload/videoupload.field.inc create mode 100644 types/videoupload/videoupload.info create mode 100644 types/videoupload/videoupload.install create mode 100644 types/videoupload/videoupload.module create mode 100644 types/videoupload/videoupload.theme.inc create mode 100644 types/videoupload/videoupload_widget.inc diff --git a/types/uploadfield/uploadfield.info b/types/uploadfield/uploadfield.info deleted file mode 100644 index 3c5e92d..0000000 --- a/types/uploadfield/uploadfield.info +++ /dev/null @@ -1,10 +0,0 @@ -; $Id$ - -name = Video Upload -description = Handle video upload for video module using filefield and CCK. -package = Video -core = 7.x -dependencies[] = video -files[] = uploadfield.module -files[] = uploadfield.field.inc -files[] = uploadfield.install \ No newline at end of file diff --git a/types/uploadfield/uploadfield.install b/types/uploadfield/uploadfield.install deleted file mode 100644 index 9f43a6d..0000000 --- a/types/uploadfield/uploadfield.install +++ /dev/null @@ -1,27 +0,0 @@ - array( - 'fid' => array( - 'description' => 'The {file_managed}.fid being referenced in this field.', - 'type' => 'int', - 'not null' => FALSE, - 'unsigned' => TRUE, - ), - ), - 'indexes' => array( - 'fid' => array('fid'), - ), - 'foreign keys' => array( - 'fid' => array( - 'table' => 'file_managed', - 'columns' => array('fid' => 'fid'), - ), - ), - ); -} \ No newline at end of file diff --git a/types/uploadfield/uploadfield.module b/types/uploadfield/uploadfield.module deleted file mode 100644 index 9664e1e..0000000 --- a/types/uploadfield/uploadfield.module +++ /dev/null @@ -1,146 +0,0 @@ - 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 deleted file mode 100644 index 5a81efd..0000000 --- a/types/uploadfield/uploadfield.theme.inc +++ /dev/null @@ -1,18 +0,0 @@ -files/videos/" 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 diff --git a/types/videoupload/videoupload.field.inc b/types/videoupload/videoupload.field.inc new file mode 100644 index 0000000..a79177e --- /dev/null +++ b/types/videoupload/videoupload.field.inc @@ -0,0 +1,7 @@ + diff --git a/types/videoupload/videoupload.info b/types/videoupload/videoupload.info new file mode 100644 index 0000000..3c5e92d --- /dev/null +++ b/types/videoupload/videoupload.info @@ -0,0 +1,10 @@ +; $Id$ + +name = Video Upload +description = Handle video upload for video module using filefield and CCK. +package = Video +core = 7.x +dependencies[] = video +files[] = uploadfield.module +files[] = uploadfield.field.inc +files[] = uploadfield.install \ No newline at end of file diff --git a/types/videoupload/videoupload.install b/types/videoupload/videoupload.install new file mode 100644 index 0000000..9f43a6d --- /dev/null +++ b/types/videoupload/videoupload.install @@ -0,0 +1,27 @@ + array( + 'fid' => array( + 'description' => 'The {file_managed}.fid being referenced in this field.', + 'type' => 'int', + 'not null' => FALSE, + 'unsigned' => TRUE, + ), + ), + 'indexes' => array( + 'fid' => array('fid'), + ), + 'foreign keys' => array( + 'fid' => array( + 'table' => 'file_managed', + 'columns' => array('fid' => 'fid'), + ), + ), + ); +} \ No newline at end of file diff --git a/types/videoupload/videoupload.module b/types/videoupload/videoupload.module new file mode 100644 index 0000000..9664e1e --- /dev/null +++ b/types/videoupload/videoupload.module @@ -0,0 +1,146 @@ + 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/videoupload/videoupload.theme.inc b/types/videoupload/videoupload.theme.inc new file mode 100644 index 0000000..5a81efd --- /dev/null +++ b/types/videoupload/videoupload.theme.inc @@ -0,0 +1,18 @@ +files/videos/" 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 -- cgit v1.2.3