View source
<?php
module_load_include('inc', 'videoftp', 'videoftp_widget');
function videoftp_menu() {
$items = array();
$items['videoftp/ahah/%/%/%'] = array(
'page callback' => 'videoftp_js',
'page arguments' => array(
2,
3,
4,
),
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
$items['videoftp/progress'] = array(
'page callback' => 'videoftp_progress',
'access arguments' => array(
'access content',
),
'type' => MENU_CALLBACK,
);
return $items;
}
function videoftp_theme() {
$theme = array();
$theme['videoftp_widget'] = array(
'arguments' => array(
'element' => NULL,
),
'file' => 'videoftp.theme.inc',
);
$theme['videoftp_widget_item'] = array(
'arguments' => array(
'element' => NULL,
),
'file' => 'videoftp.theme.inc',
);
$theme['videoftp_widget_file'] = array(
'arguments' => array(
'element' => NULL,
),
'file' => 'videoftp.theme.inc',
);
return $theme;
}
function videoftp_widget_info() {
return array(
'videoftp_widget' => array(
'label' => t('Video FTP'),
'field types' => array(
'filefield',
),
'multiple values' => CONTENT_HANDLE_CORE,
'callbacks' => array(
'default value' => CONTENT_CALLBACK_CUSTOM,
),
'description' => t('Widget allows you to select video files uploaded through FTP to be attached to the node.'),
),
);
}
function videoftp_elements() {
$elements = array();
$filefield_elements = module_invoke('filefield', 'elements');
$elements['videoftp_widget'] = $filefield_elements['filefield_widget'];
$elements['videoftp_widget']['#columns'][] = 'filepath';
$elements['videoftp_widget']['#process'] = array(
'videoftp_widget_process',
);
$elements['videoftp_widget']['#value_callback'] = 'videoftp_widget_value';
if (module_exists('imagefield_extended')) {
$elements['uploadfield_widget']['#process'][] = 'imagefield_extended_widget_process';
}
return $elements;
$elements = array(
'videoftp_widget' => array(
'#input' => TRUE,
'#columns' => array(
'fid',
'list',
'data',
'filepath',
),
'#process' => array(
'videoftp_widget_process',
),
'#value_callback' => 'videoftp_widget_value',
),
);
if (module_exists('imagefield_extended')) {
$elements['videoftp_widget']['#process'][] = 'imagefield_extended_widget_process';
}
return $elements;
}
function videoftp_widget_settings($op, $widget) {
module_load_include('inc', 'videoftp', 'videoftp_widget');
switch ($op) {
case 'form':
return videoftp_widget_settings_form($widget);
case 'validate':
return videoftp_widget_settings_validate($widget);
case 'save':
return videoftp_widget_settings_save($widget);
}
}
function videoftp_widget(&$form, &$form_state, $field, $items, $delta = NULL) {
if (empty($form['#validate']) || !in_array('filefield_node_form_validate', $form['#validate'])) {
$form['#validate'][] = 'filefield_node_form_validate';
}
$item = array(
'fid' => 0,
'list' => $field['list_default'],
);
$data = array(
'description' => '',
'video_thumb' => '',
'bypass_autoconversion' => variable_get('video_bypass_conversion', FALSE),
);
if (isset($items[$delta])) {
if (isset($items[$delta]['data'])) {
$data = array_merge($data, $items[$delta]['data']);
}
$item = array_merge($item, $items[$delta]);
}
$item['data'] = $data;
return array(
'#title' => $field['widget']['label'],
'#type' => $field['widget']['type'],
'#default_value' => $item,
);
}
function videoftp_js($type_name, $field_name, $delta) {
module_load_include('inc', 'videoftp', 'videoftp_widget');
$field = content_fields($field_name, $type_name);
if (empty($field) || empty($_POST['form_build_id'])) {
drupal_set_message(t('An unrecoverable error occurred.'), 'error');
print drupal_to_js(array(
'data' => theme('status_messages'),
));
exit;
}
$form_state = array(
'submitted' => FALSE,
);
$form_build_id = $_POST['form_build_id'];
$form = form_get_cache($form_build_id, $form_state);
if (!$form) {
drupal_set_message(t('An unrecoverable error occurred. This form was missing from the server cache. Try reloading the page and submitting again.'), 'error');
print drupal_to_js(array(
'data' => theme('status_messages'),
));
exit;
}
$args = $form['#parameters'];
$form_id = array_shift($args);
$form['#post'] = $_POST;
$form = form_builder($form_id, $form, $form_state);
if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type_name, $field_name))) {
if (isset($form['#multigroups']) && isset($form['#multigroups'][$group_name][$field_name])) {
$form_element = $form[$group_name][$delta][$field_name];
}
else {
$form_element = $form[$group_name][$field_name][$delta];
}
}
else {
$form_element = $form[$field_name][$delta];
}
if (isset($form_element['_weight'])) {
unset($form_element['_weight']);
}
$output = drupal_render($form_element);
$javascript = drupal_add_js(NULL, NULL);
$videoftp_ahah_settings = array();
if (isset($javascript['setting'])) {
foreach ($javascript['setting'] as $settings) {
if (isset($settings['ahah'])) {
foreach ($settings['ahah'] as $id => $ahah_settings) {
if (strpos($id, 'videoftp-attach') || strpos($id, 'videoftp-remove')) {
$videoftp_ahah_settings[$id] = $ahah_settings;
}
}
}
}
}
if (!empty($videoftp_ahah_settings)) {
$output .= '<script type="text/javascript">jQuery.extend(Drupal.settings.ahah, ' . drupal_to_js($videoftp_ahah_settings) . ');</script>';
}
$output = theme('status_messages') . $output;
$GLOBALS['devel_shutdown'] = FALSE;
print drupal_to_js(array(
'status' => TRUE,
'data' => $output,
));
exit;
}