| 1 |
<?php |
<?php |
| 2 |
// $Id: filefield_widget.inc,v 1.53 2009/02/27 18:20:56 quicksketch Exp $ |
// $Id: filefield_widget.inc,v 1.54 2009/02/28 22:50:18 quicksketch Exp $ |
| 3 |
/** |
/** |
| 4 |
* @file |
* @file |
| 5 |
* FileField: Defines a CCK file field type. |
* FileField: Defines a CCK file field type. |
| 183 |
$item = $element['#value']; |
$item = $element['#value']; |
| 184 |
$field_name = $element['#field_name']; |
$field_name = $element['#field_name']; |
| 185 |
$delta = $element['#delta']; |
$delta = $element['#delta']; |
| 186 |
|
$element['#theme'] = 'filefield_widget_item'; |
| 187 |
|
|
| 188 |
$field = content_fields($element['#field_name'], $element['#type_name']); |
$field = content_fields($element['#field_name'], $element['#type_name']); |
| 189 |
|
|
| 190 |
// check remove buttons... |
// Title is not necessary for each individual field. |
| 191 |
|
if ($field['multiple'] > 0) { |
| 192 |
|
unset($element['#title']); |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
// Check if a remove button was clicked. |
| 196 |
$remove_name = $element['#field_name'] .'_'. $element['#delta'] .'_remove_btn'; |
$remove_name = $element['#field_name'] .'_'. $element['#delta'] .'_remove_btn'; |
| 197 |
if (isset($form_state['clicked_button']) && $form_state['clicked_button']['#name'] == $remove_name) { |
if (isset($form_state['clicked_button']) && $form_state['clicked_button']['#name'] == $remove_name) { |
| 198 |
$item = array('fid' => 0, 'list' => $field['list_default'], 'data' => array('description' => '')); |
$item = array('fid' => 0, 'list' => $field['list_default'], 'data' => array('description' => '')); |
| 214 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 215 |
'#title' => t('Description'), |
'#title' => t('Description'), |
| 216 |
'#value' => isset($item['data']['description']) ? $item['data']['description'] : '', |
'#value' => isset($item['data']['description']) ? $item['data']['description'] : '', |
| 217 |
|
'#access' => !empty($item['fid']), |
| 218 |
); |
); |
| 219 |
} |
} |
| 220 |
|
|
| 230 |
'#title' => t('List'), |
'#title' => t('List'), |
| 231 |
'#value' => isset($item['list']) ? $item['list'] : $field['list_default'], |
'#value' => isset($item['list']) ? $item['list'] : $field['list_default'], |
| 232 |
'#attributes' => array('class' => 'filefield-list'), |
'#attributes' => array('class' => 'filefield-list'), |
| 233 |
|
'#access' => !empty($item['fid']), |
| 234 |
); |
); |
| 235 |
} |
} |
| 236 |
|
|
|
|
|
|
|
|
| 237 |
foreach ($element['#upload_validators'] as $callback => $arguments) { |
foreach ($element['#upload_validators'] as $callback => $arguments) { |
| 238 |
$help_func = $callback .'_help'; |
$help_func = $callback .'_help'; |
| 239 |
if (function_exists($help_func)) { |
if (function_exists($help_func)) { |
| 243 |
$element['upload'] = array( |
$element['upload'] = array( |
| 244 |
'#name' => 'files['. $element['#field_name'] .'_'. $element['#delta'] .']', |
'#name' => 'files['. $element['#field_name'] .'_'. $element['#delta'] .']', |
| 245 |
'#type' => 'file', |
'#type' => 'file', |
|
'#title' => t('New Upload'), |
|
| 246 |
'#description' => implode('<br />', $desc), |
'#description' => implode('<br />', $desc), |
| 247 |
|
'#size' => 22, |
| 248 |
'#attributes' => array( |
'#attributes' => array( |
| 249 |
'accept' => implode(',', array_filter(explode(' ', $field['widget']['file_extensions']))), |
'accept' => implode(',', array_filter(explode(' ', $field['widget']['file_extensions']))), |
| 250 |
) |
), |
| 251 |
|
'#access' => empty($item['fid']), |
| 252 |
); |
); |
| 253 |
|
|
|
|
|
|
if ($item['fid'] != 0) { |
|
|
$element['upload']['#title'] = t('Replace'); |
|
|
} |
|
|
|
|
|
if (isset($element['#attributes']['class']) && strlen($element['#attributes']['class'])) { |
|
|
$element['#attributes']['class'] .= 'filefield-element clear-block'; |
|
|
} |
|
|
else { |
|
|
$element['#attributes']['class'] = 'filefield-element clear-block'; |
|
|
} |
|
|
|
|
| 254 |
$element['#attributes']['id'] = $element['#id'] .'-ahah-wrapper'; |
$element['#attributes']['id'] = $element['#id'] .'-ahah-wrapper'; |
|
$element['#attributes']['class'] = $element['#attributes']['class']; |
|
| 255 |
$element['#prefix'] = '<div '. drupal_attributes($element['#attributes']) .'>'; |
$element['#prefix'] = '<div '. drupal_attributes($element['#attributes']) .'>'; |
| 256 |
$element['#suffix'] = '</div>'; |
$element['#suffix'] = '</div>'; |
| 257 |
$element['upload_btn'] = array( |
$element['upload_btn'] = array( |
| 269 |
'#delta' => $element['#delta'], |
'#delta' => $element['#delta'], |
| 270 |
'#type_name' => $element['#type_name'], |
'#type_name' => $element['#type_name'], |
| 271 |
'#upload_validators' => $element['#upload_validators'], |
'#upload_validators' => $element['#upload_validators'], |
| 272 |
|
'#access' => empty($item['fid']), |
| 273 |
); |
); |
|
if ($item['fid'] != 0) { |
|
|
$element['remove_btn'] = array( |
|
|
'#name' => $element['#field_name'] .'_'. $element['#delta'] .'_remove_btn', |
|
|
'#type' => 'submit', |
|
|
'#value' => t('Remove'), |
|
|
'#process' => array('filefield_widget_process_remove_btn', 'form_expand_ahah'), |
|
|
'#submit' => array('node_form_submit_build_node'), |
|
|
'#ahah' => array( // with JavaScript |
|
|
'path' => 'filefield/ahah/'. $element['#type_name'] .'/'. $element['#field_name'] .'/'. $element['#delta'], |
|
|
'wrapper' => $element['#id'] .'-ahah-wrapper', |
|
|
'method' => 'replace', |
|
|
'effect' => 'fade', |
|
|
), |
|
|
'#field_name' => $element['#field_name'], |
|
|
'#delta' => $element['#delta'], |
|
|
); |
|
|
} |
|
| 274 |
|
|
| 275 |
|
$element['remove_btn'] = array( |
| 276 |
|
'#name' => $element['#field_name'] .'_'. $element['#delta'] .'_remove_btn', |
| 277 |
|
'#type' => 'submit', |
| 278 |
|
'#value' => t('Remove'), |
| 279 |
|
'#process' => array('filefield_widget_process_remove_btn', 'form_expand_ahah'), |
| 280 |
|
'#submit' => array('node_form_submit_build_node'), |
| 281 |
|
'#ahah' => array( // with JavaScript |
| 282 |
|
'path' => 'filefield/ahah/'. $element['#type_name'] .'/'. $element['#field_name'] .'/'. $element['#delta'], |
| 283 |
|
'wrapper' => $element['#id'] .'-ahah-wrapper', |
| 284 |
|
'method' => 'replace', |
| 285 |
|
'effect' => 'fade', |
| 286 |
|
), |
| 287 |
|
'#field_name' => $element['#field_name'], |
| 288 |
|
'#delta' => $element['#delta'], |
| 289 |
|
'#access' => !empty($item['fid']), |
| 290 |
|
); |
| 291 |
|
|
| 292 |
return $element; |
return $element; |
| 293 |
} |
} |
| 308 |
} |
} |
| 309 |
|
|
| 310 |
function theme_filefield_widget_preview($item) { |
function theme_filefield_widget_preview($item) { |
| 311 |
return '<div class="filefield-preview clear-block">'. |
return '<div class="filename">'. theme('filefield_file', $item) .'</div>'. |
| 312 |
'<div class="filename">'. theme('filefield_file', $item) .'</div>'. |
'<div class="filesize">'. format_size($item['filesize']) .'</div>'. |
| 313 |
'<div class="filesize">'. format_size($item['filesize']) .'</div>'. |
'<div class="filemime">'. $item['filemime'] .'</div>'; |
|
'<div class="filemime">'. $item['filemime'] .'</div>'. |
|
|
'</div>'; |
|
| 314 |
} |
} |
| 315 |
|
|
| 316 |
function theme_filefield_widget_item($element) { |
function theme_filefield_widget_item($element) { |
| 317 |
return '<div class="filefield-row clear-block">'. |
// Put the upload button directly after the upload field. |
| 318 |
'<div class="filefield-filename clear-block">'. drupal_render($element['preview']) . '</div>'. |
$element['upload']['#field_suffix'] = drupal_render($element['upload_btn']); |
| 319 |
'<div class="fllefield-edit clear-block">'. |
$element['upload']['#theme'] = 'filefield_widget_file'; |
| 320 |
'<div class="filefield-list">'. drupal_render($element['list']) . '</div>' . |
|
| 321 |
'<div class="filefield-description">'. drupal_render($element['description']) . '</div>' . |
$output = ''; |
| 322 |
'<div class="filefield-stuff">'. drupal_render($element) .'</div>'. |
$output .= '<div class="filefield-element clear-block">'; |
| 323 |
'</div>'. |
|
| 324 |
'</div>'; |
if ($element['fid']['#value'] != 0) { |
| 325 |
|
$output .= '<div class="filefield-preview">'; |
| 326 |
|
$output .= drupal_render($element['preview']); |
| 327 |
|
$output .= '</div>'; |
| 328 |
|
} |
| 329 |
|
|
| 330 |
|
$output .= '<div class="filefield-edit">'; |
| 331 |
|
$output .= drupal_render($element); |
| 332 |
|
$output .= '</div>'; |
| 333 |
|
$output .= '</div>'; |
| 334 |
|
|
| 335 |
|
return $output; |
| 336 |
|
} |
| 337 |
|
|
| 338 |
|
/** |
| 339 |
|
* Render the #field_suffix for file elements. |
| 340 |
|
*/ |
| 341 |
|
function theme_filefield_widget_file($element) { |
| 342 |
|
$output = ''; |
| 343 |
|
|
| 344 |
|
$output .= '<div class="filefield-upload clear-block">'; |
| 345 |
|
|
| 346 |
|
if (isset($element['#field_prefix'])) { |
| 347 |
|
$output .= $element['#field_prefix']; |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
_form_set_class($element, array('form-file')); |
| 351 |
|
$output .= '<input type="file" name="'. $element['#name'] .'"'. ($element['#attributes'] ? ' '. drupal_attributes($element['#attributes']) : '') .' id="'. $element['#id'] .'" size="'. $element['#size'] ."\" />\n"; |
| 352 |
|
|
| 353 |
|
if (isset($element['#field_suffix'])) { |
| 354 |
|
$output .= $element['#field_suffix']; |
| 355 |
|
} |
| 356 |
|
|
| 357 |
|
$output .= '</div>'; |
| 358 |
|
|
| 359 |
|
return theme('form_element', $element, $output); |
| 360 |
} |
} |
| 361 |
|
|
| 362 |
/** |
/** |