Index: imagefield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/imagefield/imagefield.module,v
retrieving revision 1.30.2.6.2.63
diff -u -p -r1.30.2.6.2.63 imagefield.module
--- imagefield.module	11 May 2008 23:28:46 -0000	1.30.2.6.2.63
+++ imagefield.module	13 May 2008 14:57:44 -0000
@@ -24,9 +24,6 @@ function imagefield_menu($maycache) {
     );
   }
   elseif ($_SESSION['imagefield']) {
-    // do this variable_get once....
-    $download_method = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC);
-
     // Iterate over each field stored in session imagefield looking
     // for files in a preview state to add menu items for. This
     // allows us to preview new uploads before a node is submitted.
@@ -38,23 +35,10 @@ function imagefield_menu($maycache) {
         // If the file is not a preview do not display it.
         if (empty($file['preview']))  continue;
 
-        // filepath to pass into _imagefield_preview
-        $filepath = $file['preview'];
-
-        // build url path for private files menu item.
-        if ($download_method == FILE_DOWNLOADS_PRIVATE) {
-          // strip out the file_directory_path. It shouldn't be a part
-          // of the URL with private downloads.
-          if (strpos($file['preview'], file_directory_path()) !== false) {
-            $file['preview'] = trim(substr($file['preview'], strlen(file_directory_path())), '\\/');
-          }
-          $file['preview'] = 'system/files/'. $file['preview'];
-        }
-
         $items[] = array(
           'path' => $file['preview'],
           'callback' => '_imagefield_preview',
-          'callback arguments' => array($filepath),
+          'callback arguments' => array($file['preview']),
           'access' => true,
           'type' => MENU_CALLBACK,
         );
@@ -611,7 +595,15 @@ function _imagefield_widget_prepare_form
         $widget_image_path = $field['widget']['image_path'];
       }
       imagefield_check_directory($widget_image_path);
+
+      // Create the filepath for the image preview
       $filepath = file_create_filename($file['filename'], file_create_path($widget_image_path));
+      if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) ==  FILE_DOWNLOADS_PRIVATE) {
+        if (strpos($filepath, file_directory_path()) !== FALSE) {
+          $filepath = trim(substr($filepath, strlen(file_directory_path())), '\\/');
+        }
+        $filepath = 'system/files/' . $filepath;
+      }
 
       $file['fid'] = 'upload';
       $file['preview'] = $filepath;
@@ -1030,10 +1022,9 @@ function theme_imagefield_image($file, $
   }
   if (!$getsize || (list($width, $height, $type, $image_attributes) = @getimagesize($file['filepath']))) {
     $attributes = drupal_attributes($attributes);
-    $path = ($file['fid'] == 'upload') ? $file['preview'] : $file['filepath'];
+    $url = ($file['fid'] == 'upload') ? url($file['preview']) : file_create_url($file['filepath']);
     $alt = empty($alt) ? $file['alt'] : $alt;
     $title = empty($title) ? $file['title'] : $title;
-    $url = file_create_url($path);
     return '<img src="'. check_url($url) .'" alt="'.
         check_plain($alt) .'" title="'. check_plain($title) .'" '. $image_attributes . $attributes .' />';
   }
