| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * uploadfield core hooks and menu callbacks. 6 */ 7 8 module_load_include('inc', 'uploadfield', 'uploadfield_widget'); 9 10 /** 11 * Implementation of hook_theme(). 12 */ 13 function uploadfield_theme() { 14 $theme = array(); 15 $theme['uploadfield_widget'] = array( 16 'arguments' => array('element' => NULL), 17 'file' => 'uploadfield.theme.inc', 18 ); 19 $theme['uploadfield_widget_item'] = array( 20 'arguments' => array('element' => NULL), 21 'file' => 'uploadfield.theme.inc', 22 ); 23 return $theme; 24 } 25 26 /** 27 * Implementation of CCK's hook_widget_info(). 28 */ 29 function uploadfield_widget_info() { 30 return array( 31 'uploadfield_widget' => array( 32 'label' => t('Video'), 33 'field types' => array('filefield'), 34 'multiple values' => CONTENT_HANDLE_CORE, 35 'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM), 36 'description' => t('An edit widget for video files, including video thumbnails and transcoding to flash.'), 37 ), 38 ); 39 } 40 41 42 /** 43 * Implementation of hook_elements(). 44 */ 45 function uploadfield_elements() { 46 // An uploadfield is really just a FileField with extra processing. 47 $filefield_elements = module_invoke('filefield', 'elements'); 48 49 $elements = array(); 50 $elements['uploadfield_widget'] = $filefield_elements['filefield_widget']; 51 $elements['uploadfield_widget']['#process'][] = 'uploadfield_widget_process'; 52 // uploadfield needs a separate value callback to save its alt and title texts. 53 $elements['uploadfield_widget']['#value_callback'] = 'uploadfield_widget_value'; 54 55 return $elements; 56 } 57 58 /** 59 * Implementation of hook_file_download. 60 */ 61 function uploadfield_file_download($filepath) { 62 // Return headers for default images. 63 if (strpos($filepath, 'video_thumbs') !== FALSE) { 64 $full_path = file_create_path($filepath); 65 if ($info = getimagesize($full_path)) { 66 return array( 67 'Content-Type: ' . $info['mime'], 68 'Content-Length: ' . filesize($full_path) 69 ); 70 } 71 } 72 } 73 74 /** 75 * Implementation of CCK's hook_widget_settings(). 76 */ 77 function uploadfield_widget_settings($op, $widget) { 78 switch ($op) { 79 case 'form': 80 return uploadfield_widget_settings_form($widget); 81 case 'validate': 82 return uploadfield_widget_settings_validate($widget); 83 case 'save': 84 return uploadfield_widget_settings_save($widget); 85 } 86 } 87 88 /** 89 * Implementation of hook_widget(). 90 */ 91 function uploadfield_widget(&$form, &$form_state, $field, $items, $delta = NULL) { 92 $uploadfield = array( 93 'data' => array( 94 'video_thumb' => '', 95 'bypass_autoconversion' => variable_get('video_bypass_conversion', FALSE), 96 ), 97 ); 98 99 $filefield = filefield_widget($form, $form_state, $field, $items, $delta); 100 101 $element = $filefield; 102 $element['#default_value'] = array_merge($uploadfield, $filefield['#default_value']); 103 $element['#default_value']['data'] = array_merge($uploadfield['data'], $filefield['#default_value']['data']); 104 105 return $element; 106 } 107 108 /** 109 * Implementation of CCK's hook_default_value(). 110 */ 111 function uploadfield_default_value(&$form, &$form_state, $field, $delta) { 112 return filefield_default_value($form, $form_state, $field, $delta); 113 } 114 115 /** 116 * Implementation of hook_form_[form_id]_alter(). 117 * 118 * Modify the add new field form to make "Video" the default formatter. 119 */ 120 function uploadfield_form_content_field_overview_form_alter(&$form, &$form_state) { 121 $form['#submit'][] = 'uploadfield_form_content_field_overview_submit'; 122 } 123 124 /** 125 * Submit handler to set a new field's formatter to "video_plain". 126 */ 127 function uploadfield_form_content_field_overview_submit(&$form, &$form_state) { 128 if (isset($form_state['fields_added']['_add_new_field']) && isset($form['#type_name'])) { 129 $new_field = $form_state['fields_added']['_add_new_field']; 130 $node_type = $form['#type_name']; 131 $field = content_fields($new_field, $node_type); 132 if ($field['widget']['module'] == 'uploadfield') { 133 foreach ($field['display_settings'] as $display_type => $display_settings) { 134 if ($field['display_settings'][$display_type]['format'] == 'default') { 135 $field['display_settings'][$display_type]['format'] = 'video_plain'; 136 } 137 } 138 content_field_instance_update($field); 139 } 140 } 141 } 142 143 /** 144 * filefield source support 145 */ 146 function uploadfield_filefield_sources_widgets() { 147 return array('uploadfield_widget'); 148 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Mon Jul 9 18:01:44 2012 | Cross-referenced by PHPXref 0.7 |