View source
<?php
module_load_include('inc', 'uploadfield', 'uploadfield_widget');
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;
}
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.'),
),
);
}
function uploadfield_elements() {
$filefield_elements = module_invoke('filefield', 'elements');
$elements = array();
$elements['uploadfield_widget'] = $filefield_elements['filefield_widget'];
$elements['uploadfield_widget']['#process'][] = 'uploadfield_widget_process';
$elements['uploadfield_widget']['#value_callback'] = 'uploadfield_widget_value';
return $elements;
}
function uploadfield_file_download($filepath) {
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),
);
}
}
}
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);
}
}
function uploadfield_widget(&$form, &$form_state, $field, $items, $delta = NULL) {
$uploadfield = array(
'data' => array(
'video_thumb' => '',
'bypass_autoconversion' => variable_get('video_bypass_conversion', FALSE),
),
);
$filefield = filefield_widget($form, $form_state, $field, $items, $delta);
$element = $filefield;
$element['#default_value'] = array_merge($uploadfield, $filefield['#default_value']);
$element['#default_value']['data'] = array_merge($uploadfield['data'], $filefield['#default_value']['data']);
return $element;
}
function uploadfield_default_value(&$form, &$form_state, $field, $delta) {
return filefield_default_value($form, $form_state, $field, $delta);
}
function uploadfield_form_content_field_overview_form_alter(&$form, &$form_state) {
$form['#submit'][] = 'uploadfield_form_content_field_overview_submit';
}
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);
}
}
}
function uploadfield_filefield_sources_widgets() {
return array(
'uploadfield_widget',
);
}