aboutsummaryrefslogtreecommitdiff
path: root/types/videoupload/videoupload.module
blob: 3f032042b13a96cc16c97591a509c0441fdafbc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
// $Id$

/**
 * @file
 * uploadfield core hooks and menu callbacks.
 */

/**
 * Implementation of hook_perm().
 */
function videoupload_perm() {
  return array('use default thumbnail', 'bypass conversion video');
}

/**
 * Implementation of hook_theme().
 */
function videoupload_theme() {
  $theme = array();
  $theme['uploadfield_widget'] = array(
    'arguments' => array('element' => NULL),
    'file' => 'videoupload.theme.inc',
  );
  $theme['uploadfield_widget_item'] = array(
    'arguments' => array('element' => NULL),
    'file' => 'videoupload.theme.inc',
  );
  return $theme;
}


/**
 * Implementation of hook_elements().
 */
function videoupload_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 videoupload_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 videoupload_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 videoupload_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 videoupload_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 videoupload_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 videoupload_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 videoupload_filefield_sources_widgets() {
  return array('videoupload_widget');
}