diff --git a/imagefield.module b/imagefield.module index 6fd0aa2..f061f10 100644 --- a/imagefield.module +++ b/imagefield.module @@ -31,7 +31,7 @@ function imagefield_theme() { // Use to generate a preview (admin view) of an imagefield item for use in // field item forms and filefield widgets. Invoked by filefield_widget_process. 'imagefield_widget_preview' => array( - 'arguments' => array('item' => NULL), + 'arguments' => array('item' => NULL, 'preview_preset' => NULL), ), // Theme function for the field item elements. allows you to place children // within the context of the parent. @@ -40,7 +40,7 @@ function imagefield_theme() { ), // Generates and img tag to the admin thumbnail of an ImageField upload. 'imagefield_admin_thumbnail' => array( - 'arguments' => array('item' => NULL), + 'arguments' => array('item' => NULL, 'preview_preset' => NULL), ), // ImageField formatter theme functions. 'imagefield_formatter_image_plain' => array( @@ -357,19 +357,31 @@ function theme_imagefield_item($item) { return theme('imagefield_image', $item, $item['alt'], $item['title']); } -function theme_imagefield_widget_preview($item = NULL) { - return '
' . theme('imagefield_admin_thumbnail', $item) . '
'; +function theme_imagefield_widget_preview($item = NULL, $preview_preset = ''){ + return '
' . theme('imagefield_admin_thumbnail', $item, $preview_preset) . '
'; } function theme_imagefield_widget_item($element) { return theme('filefield_widget_item', $element); } -function theme_imagefield_admin_thumbnail($item = NULL) { +function theme_imagefield_admin_thumbnail($item = NULL, $preview_preset = ''){ if (is_null($item) || empty($item['filepath'])) { return ''; } - $thumb_path = imagefield_file_admin_thumb_path($item); + + if (!empty($preview_preset)){ + return theme('imagecache', $preview_preset, $item['filepath']); + } + else{ + $thumb_path = imagefield_file_admin_thumb_path($item); + + //Encode the parts of the the path. + $parts = explode('/', $thumb_path); + foreach ($parts as $n => $part){ + $parts[$n] = rawurlencode($part); + } + $thumb_path = implode('/', $parts); // Encode the path so that unusual characters are printed correctly. $thumb_path = field_file_urlencode_path($thumb_path); @@ -381,7 +393,10 @@ function theme_imagefield_admin_thumbnail($item = NULL) { $query_string = $query_character . $item['timestamp']; } + return '' . t('Image preview') . ''; + + } } /** * @} End defgroup "Theme Callbacks". diff --git a/imagefield_widget.inc b/imagefield_widget.inc index 710ab97..5bcfeed 100644 --- a/imagefield_widget.inc +++ b/imagefield_widget.inc @@ -17,7 +17,7 @@ function imagefield_widget_settings_form($widget) { $form['max_resolution'] = array( '#type' => 'textfield', - '#title' => t('Maximum resolution for Images'), + '#title' => t('Maximum dimensions for images'), '#default_value' => !empty($widget['max_resolution']) ? $widget['max_resolution'] : 0, '#size' => 15, '#maxlength' => 10, @@ -26,7 +26,7 @@ function imagefield_widget_settings_form($widget) { ); $form['min_resolution'] = array( '#type' => 'textfield', - '#title' => t('Minimum resolution for Images'), + '#title' => t('Minimum dimensions for images'), '#default_value' => !empty($widget['min_resolution']) ? $widget['min_resolution'] : 0, '#size' => 15, '#maxlength' => 10, @@ -126,6 +126,38 @@ function imagefield_widget_settings_form($widget) { '#value' => $widget['default_image'], ); + //preview options (imagecache for preview thumbnails) + $form['preview'] = array( + '#type' => 'fieldset', + '#title' => t('Preview Thumbnail Settings'), + '#collapsible' => true, + '#collapsed' => true, + '#weight' => 8, + ); + $form['preview']['preview_preset'] = array( + '#default_value' => !empty($widget['preview_preset']) ? $widget['preview_preset'] : '', + ); + if (module_exists('imagecache')){ + $imagecache_presets = imagecache_presets(); + $preview_presets_list[''] = t(''); + foreach ($imagecache_presets as $key => $preset){ + $preview_presets_list[$preset['presetname']] = $preset['presetname']; + } + $imagecache_preset = array( + '#type' => 'select', + '#title' => t('ImageCache Preset'), + '#description' => t('This ImageCache preset will be used to create the thumbnail.'), + '#options' => $preview_presets_list, //@str_replace: returns correct node type + ); + $form['preview']['preview_preset'] = array_merge($form['preview']['preview_preset'], $imagecache_preset); + } else{ + $form['preview']['ImageCache_disabled'] = array( + '#value' => '

'.t('Enable imagecache to control the way preview thumbnails should be shown for this field.').'

', + ); + $form['preview']['preview_preset']['#type'] = 'value'; + + } + return $form; } @@ -197,7 +229,7 @@ function imagefield_widget_settings_validate($widget) { */ function imagefield_widget_settings_save($widget) { $filefield_settings = module_invoke('filefield', 'widget_settings', 'save', $widget); - return array_merge($filefield_settings, array('max_resolution', 'min_resolution', 'alt', 'custom_alt', 'title', 'custom_title', 'title_type', 'default_image', 'use_default_image')); + return array_merge($filefield_settings, array('max_resolution', 'min_resolution', 'alt', 'custom_alt', 'title', 'custom_title', 'title_type', 'default_image', 'use_default_image', 'preview_preset')); } /** @@ -226,7 +258,8 @@ function imagefield_widget_process($element, $edit, &$form_state, $form) { $element['#theme'] = 'imagefield_widget_item'; if (isset($element['preview']) && $element['#value']['fid'] != 0) { - $element['preview']['#value'] = theme('imagefield_widget_preview', $element['#value']); + $preview_preset = module_exists('imagecache') ? $field['widget']['preview_preset'] : ''; + $element['preview']['#value'] = theme('imagefield_widget_preview', $element['#value'], $preview_preset); } // Check if using the default alt text and replace tokens.