| [ Index ] |
PHP Cross Reference of Drupal 6 (yi-drupal) |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @file 5 * video ftp core hooks and menu callbacks. 6 */ 7 8 module_load_include('inc', 'videoftp', 'videoftp_widget'); 9 10 /* 11 * Implementation of hook_menu(). 12 */ 13 function videoftp_menu() { 14 $items = array(); 15 $items['videoftp/ahah/%/%/%'] = array( 16 'page callback' => 'videoftp_js', 17 'page arguments' => array(2, 3, 4), 18 //'access callback' => 'videoftp_edit_access', 19 'access arguments' => array('access content'), 20 'type' => MENU_CALLBACK, 21 ); 22 $items['videoftp/progress'] = array( 23 'page callback' => 'videoftp_progress', 24 'access arguments' => array('access content'), 25 'type' => MENU_CALLBACK, 26 ); 27 return $items; 28 } 29 30 /** 31 * Implementation of hook_theme(). 32 */ 33 function videoftp_theme() { 34 $theme = array(); 35 $theme['videoftp_widget'] = array( 36 'arguments' => array('element' => NULL), 37 'file' => 'videoftp.theme.inc', 38 ); 39 $theme['videoftp_widget_item'] = array( 40 'arguments' => array('element' => NULL), 41 'file' => 'videoftp.theme.inc', 42 ); 43 $theme['videoftp_widget_file'] = array( 44 'arguments' => array('element' => NULL), 45 'file' => 'videoftp.theme.inc', 46 ); 47 return $theme; 48 } 49 50 /** 51 * Implementation of CCK's hook_widget_info(). 52 */ 53 function videoftp_widget_info() { 54 return array( 55 'videoftp_widget' => array( 56 'label' => t('Video FTP'), 57 'field types' => array('filefield'), 58 'multiple values' => CONTENT_HANDLE_CORE, 59 'callbacks' => array('default value' => CONTENT_CALLBACK_CUSTOM), 60 'description' => t('Widget allows you to select video files uploaded through FTP to be attached to the node.'), 61 ), 62 ); 63 } 64 65 /** 66 * Implementation of hook_elements(). 67 */ 68 function videoftp_elements() { 69 $elements = array(); 70 $filefield_elements = module_invoke('filefield', 'elements'); 71 $elements['videoftp_widget'] = $filefield_elements['filefield_widget']; 72 $elements['videoftp_widget']['#columns'][] = 'filepath'; 73 $elements['videoftp_widget']['#process'] = array('videoftp_widget_process'); 74 $elements['videoftp_widget']['#value_callback'] = 'videoftp_widget_value'; 75 76 // Support for the imagefield_extended module 77 if (module_exists('imagefield_extended')) { 78 $elements['uploadfield_widget']['#process'][] = 'imagefield_extended_widget_process'; 79 } 80 81 return $elements; 82 83 $elements = array( 84 'videoftp_widget' => array( 85 '#input' => TRUE,// 86 '#columns' => array('fid', 'list', 'data', 'filepath'),// 87 '#process' => array('videoftp_widget_process'),// 88 '#value_callback' => 'videoftp_widget_value', 89 ), 90 ); 91 92 // Support for the imagefield_extended module 93 if (module_exists('imagefield_extended')) { 94 $elements['videoftp_widget']['#process'][] = 'imagefield_extended_widget_process'; 95 } 96 97 return $elements; 98 } 99 100 /** 101 * Implementation of CCK's hook_widget_settings(). 102 */ 103 function videoftp_widget_settings($op, $widget) { 104 //load up our include file for the widget 105 module_load_include('inc', 'videoftp', 'videoftp_widget'); 106 switch ($op) { 107 case 'form': 108 return videoftp_widget_settings_form($widget); 109 case 'validate': 110 return videoftp_widget_settings_validate($widget); 111 case 'save': 112 return videoftp_widget_settings_save($widget); 113 } 114 } 115 116 /** 117 * Implementation of hook_widget(). 118 */ 119 function videoftp_widget(&$form, &$form_state, $field, $items, $delta = NULL) { 120 if (empty($form['#validate']) || !in_array('filefield_node_form_validate', $form['#validate'])) { 121 $form['#validate'][] = 'filefield_node_form_validate'; 122 } 123 124 $item = array('fid' => 0, 'list' => $field['list_default']); 125 $data = array('description' => '', 'video_thumb' => '', 'bypass_autoconversion' => variable_get('video_bypass_conversion', FALSE)); 126 127 if (isset($items[$delta])) { 128 if (isset($items[$delta]['data'])) { 129 $data = array_merge($data, $items[$delta]['data']); 130 } 131 $item = array_merge($item, $items[$delta]); 132 } 133 134 $item['data'] = $data; 135 136 return array( 137 '#title' => $field['widget']['label'], 138 '#type' => $field['widget']['type'], 139 '#default_value' => $item, 140 ); 141 } 142 143 /** 144 * Menu callback; Shared AHAH callback for ftp file attachment and deletions. 145 * 146 * This rebuilds the form element for a particular field item. As long as the 147 * form processing is properly encapsulated in the widget element the form 148 * should rebuild correctly using FAPI without the need for additional callbacks 149 * or processing. 150 */ 151 function videoftp_js($type_name, $field_name, $delta) { 152 module_load_include('inc', 'videoftp', 'videoftp_widget'); 153 $field = content_fields($field_name, $type_name); 154 155 if (empty($field) || empty($_POST['form_build_id'])) { 156 // Invalid request. 157 drupal_set_message(t('An unrecoverable error occurred.'), 'error'); 158 print drupal_to_js(array('data' => theme('status_messages'))); 159 exit; 160 } 161 162 // Build the new form. 163 $form_state = array('submitted' => FALSE); 164 $form_build_id = $_POST['form_build_id']; 165 $form = form_get_cache($form_build_id, $form_state); 166 167 if (!$form) { 168 // Invalid form_build_id. 169 drupal_set_message(t('An unrecoverable error occurred. This form was missing from the server cache. Try reloading the page and submitting again.'), 'error'); 170 print drupal_to_js(array('data' => theme('status_messages'))); 171 exit; 172 } 173 174 // Build the form. This calls the file field's #value_callback function and 175 // saves the uploaded file. Since this form is already marked as cached 176 // (the #cache property is TRUE), the cache is updated automatically and we 177 // don't need to call form_set_cache(). 178 $args = $form['#parameters']; 179 $form_id = array_shift($args); 180 $form['#post'] = $_POST; 181 $form = form_builder($form_id, $form, $form_state); 182 183 // Update the cached form with the new element at the right place in the form. 184 if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type_name, $field_name))) { 185 if (isset($form['#multigroups']) && isset($form['#multigroups'][$group_name][$field_name])) { 186 $form_element = $form[$group_name][$delta][$field_name]; 187 } 188 else { 189 $form_element = $form[$group_name][$field_name][$delta]; 190 } 191 } 192 else { 193 $form_element = $form[$field_name][$delta]; 194 } 195 196 if (isset($form_element['_weight'])) { 197 unset($form_element['_weight']); 198 } 199 $output = drupal_render($form_element); 200 // AHAH is not being nice to us and doesn't know the "other" button (that is, 201 // either "Attach" or "Delete") yet. Which in turn causes it not to attach 202 // AHAH behaviours after replacing the element. So we need to tell it first. 203 204 // Loop through the JS settings and find the settings needed for our buttons. 205 $javascript = drupal_add_js(NULL, NULL); 206 $videoftp_ahah_settings = array(); 207 if (isset($javascript['setting'])) { 208 foreach ($javascript['setting'] as $settings) { 209 if (isset($settings['ahah'])) { 210 foreach ($settings['ahah'] as $id => $ahah_settings) { 211 if (strpos($id, 'videoftp-attach') || strpos($id, 'videoftp-remove')) { 212 $videoftp_ahah_settings[$id] = $ahah_settings; 213 } 214 } 215 } 216 } 217 } 218 219 // Add the AHAH settings needed for our new buttons. 220 if (!empty($videoftp_ahah_settings)) { 221 $output .= '<script type="text/javascript">jQuery.extend(Drupal.settings.ahah, '. drupal_to_js($videoftp_ahah_settings) .');</script>'; 222 } 223 224 $output = theme('status_messages') . $output; 225 226 // For some reason, file uploads don't like drupal_json() with its manual 227 // setting of the text/javascript HTTP header. So use this one instead. 228 $GLOBALS['devel_shutdown'] = FALSE; 229 print drupal_to_js(array('status' => TRUE, 'data' => $output)); 230 exit; 231 }
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 |