Index: swfupload_widget.inc =================================================================== --- swfupload_widget.inc (révision 355) +++ swfupload_widget.inc (copie de travail) @@ -41,14 +41,16 @@ function swfupload_widget_validate(&$element, &$fo $element_value = $element['#value']; if (!empty($element_value)) { foreach (array_values($element_value) as $key => $file) { - $form_state['values'][$element['#field_name']][$key] = array( - 'fid' => $file['fid'], - 'list' => $file['list'], - 'data' => array( - 'description' => $file['description'], - 'alt' => $file['alt'], - 'title' => $file['title'], - ), + $form_state['values'][$element['#field_name']][$key] = array_merge( + field_file_load($file['fid']), // Load all fields, such as 'filepath'. + array( + 'list' => $file['list'], + 'data' => array( + 'description' => $file['description'], + 'alt' => $file['alt'], + 'title' => $file['title'], + ), + ) ); unset($form_state['values'][$element['#field_name']][$file['fid']]); } @@ -76,7 +78,7 @@ function swfupload_widget_value($element, $edit = $file += array('description' => $tmp_file['data']['description'], 'alt' => $tmp_file['data']['alt'], 'title' => $tmp_file['data']['title']); // If we're dealing with an image, create a thumbpath if (image_get_info($file['filepath'])) { - $file['thumb'] = file_create_url(swfupload_thumb_path($file)); + $file['thumb'] = file_create_url(drupal_urlencode(swfupload_thumb_path($file))); } $default_value[$file['fid']] = $file; } @@ -104,6 +106,18 @@ function swfupload_widget_process($element, $edit, unset($element['#theme']); } + // Make sure that the thumbnails exist. $element['#value'] is + // structured differently in our widget, so this is not handled by + // imagefield_widget_process(). + if (is_array($element['#value'])) { + foreach (element_children($element['#value']) as $key) { + if (isset($element['#value'][$key]['filepath'])) { + $file = $element['#value'][$key]; + swfupload_thumb_path($file, TRUE); + } + } + } + $element['#default_value'] = '[]'; return $element; } Index: swfupload.module =================================================================== --- swfupload.module (révision 355) +++ swfupload.module (copie de travail) @@ -263,7 +263,7 @@ function swfupload_swfupload(&$file, $op, &$instan if (user_access('upload files with swfupload') && ($file = file_save_upload($instance->name, $file->validators, $file->file_path))) { if (image_get_info($file->filepath)) { - $file->thumb = file_create_url(swfupload_thumb_path($file, TRUE)); + $file->thumb = file_create_url(drupal_urlencode(swfupload_thumb_path($file, TRUE))); } break; } @@ -273,6 +273,19 @@ function swfupload_swfupload(&$file, $op, &$instan } /** + * Implements hook_filefield_paths_process_file(). + * + * Since we have our own widget, the implementation of this hook for + * ImageField (which is provided by FileField Paths) won't do. + */ +function swfupload_filefield_paths_process_file($new, $file, $settings, $node, $update) { + if ($new && isset($file['widget']) && $file['widget'] == 'swfupload' && file_exists($thumbnail_source = swfupload_thumb_path(array('filepath' => $file['filepath']['old'])))) { + // Delete old thumbnail. + file_delete($thumbnail_source); + } +} + +/** * Implementation of hook_jqp(). */ function swfupload_jqp() { @@ -294,7 +307,6 @@ function swfupload_thumb_path($file, $create_thumb $file = (object) $file; $short_path = preg_replace('/^' . preg_quote(file_directory_path(), '/') . '/', '', $file->filepath); $filepath = file_directory_path() . '/imagefield_thumbs' . $short_path; - $filepath = drupal_substr($filepath, 0, (strrpos($filepath, '/') + 1)) . rawurlencode(drupal_substr($filepath, (strrpos($filepath, '/') + 1))); if ($create_thumb) { module_load_include('inc', 'swfupload', 'swfupload.admin');