Index: includes/images.previewlist.imagefield.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image_fupload/includes/images.previewlist.imagefield.inc,v
retrieving revision 1.10
diff -u -r1.10 images.previewlist.imagefield.inc
--- includes/images.previewlist.imagefield.inc	1 Feb 2010 21:37:26 -0000	1.10
+++ includes/images.previewlist.imagefield.inc	27 Jan 2011 01:31:08 -0000
@@ -32,40 +32,14 @@
   // prepare token
   $token_installed = module_exists("token");
 
-  // prepare taxonomy
-  $form_taxonomy = array();
-  if (module_exists("taxonomy") && count($fields_preview_list['taxonomy'])) {
-    $form_taxonomy = array('type' => array('#value' => $node_type), '#node' => (object) array('type' => $node_type));
-    taxonomy_form_alter($form_taxonomy, array(), $node_type .'_node_form');
-
-    // delete all elements without the ones we need
-    foreach ($form_taxonomy['taxonomy'] as $key => $value) {
-      // taxonomy normal
-      if (!in_array($key, $fields_preview_list['taxonomy']) && is_numeric($key)) {
-        unset($form_taxonomy['taxonomy'][$key]);
-      }
-    }
-    if (is_array($form_taxonomy['taxonomy']['tags'])) {    
-      foreach ($form_taxonomy['taxonomy']['tags'] as $key => $value) {
-        // taxonomy tags
-        if (!in_array($key, $fields_preview_list['taxonomy'])) {
-         unset($form_taxonomy['taxonomy']['tags'][$key]);
-        }
-      }
-    }
-  }
-
   // get our preview images
   $result = db_query("SELECT p.nid, p.fid, f.filename, f.filepath FROM {fupload_previewlist} AS p JOIN {files} AS f ON p.fid = f.fid WHERE p.fieldname = '%s' AND p.uid = %d ORDER BY p.fid ASC", $field_name, $user->uid);
   while ($image = db_fetch_object($result)) {
     $count += 1;
     $image_items[$image->fid] = $image->nid;
 
-    // get title and body fields contents if available and storage mode is single
-    if ($field_image['widget']['fupload_mode'] == "single") {
-      $node = db_query("SELECT title, body FROM {node_revisions} WHERE nid = %d", $image->nid);
-      $node = db_fetch_object($node);
-    }
+    // Load the node to get all default-saved values.
+    $node = node_load($image->nid);
 
     $form[$image->fid] = array(
       '#type' => 'fieldset',
@@ -168,13 +142,34 @@
       $form[$image->fid]['format_'. $image->fid]['#weight'] = $fields['extra']['body_field']['weight'] + 0.1;
     }
 
-    // taxonomy field
-    if (count($form_taxonomy)) {
+    // Taxonomy fields.
+    if (module_exists("taxonomy") && count($fields_preview_list['taxonomy'])) {
+      $form_taxonomy = array(
+        'type' => array('#value' => $node_type),
+        '#node' => $node,
+      );
+      taxonomy_form_alter($form_taxonomy, array(), $node_type .'_node_form');
+      image_fupload_remove_taxonomy($form_taxonomy, $fields_preview_list['taxonomy']);
+
       $form_taxonomy['taxonomy']['#weight'] = $fields['extra']['taxonomy']['weight'];
       $form[$image->fid]['taxonomy_'. $image->fid] = $form_taxonomy['taxonomy'];
     }
 
-    // ckk fields here ... in a future version
+    // CCK fields.
+    if (count($fields_preview_list['cck'])) {
+      $form_cck = array(
+        'type' => array('#value' => $node_type),
+        '#node' => $node,
+      );
+      $form_state = array();
+      content_form_alter($form_cck, $form_state, $node_type .'_node_form');
+      image_fupload_remove_cck($form_cck, $fields_preview_list['cck'], $image->fid, array($field_name, '#node', 'type', '#content_extra_fields', '#pre_render'));
+
+      $form['#field_info'] = $form_cck['#field_info'];
+      $form['#cck_list'] = $fields_preview_list['cck'];
+      unset($form_cck['#field_info']);
+      $form[$image->fid]['cck_'. $image->fid] = $form_cck;
+    }
 
   }
 
@@ -326,9 +321,12 @@
       }
       $node->$form_state['values']['field_name'] = $image_field;
 
-      // cck fields (contributed module)
-      // ... will follow in future version
-
+      // cck fields
+      if (isset($form['#cck_list']) && count($form['#cck_list'])) {
+        foreach ($form['#cck_list'] as $cck_field) {
+          $node->$cck_field = $form_state['values'][$cck_field . '_' . $fid];
+        }
+      }
       // save changes to node
       node_save($node);
     }
@@ -348,3 +346,80 @@
   drupal_set_message(t('All images have been saved and published.'));
   drupal_redirect_form($form);
 }
+
+/**
+ * Unsets unneeded CCK field form elements.
+ *
+ * Recursive function that goes into fieldsets properly, and removes/keeps the
+ * desired elements. Kept elements are modified so their field name is unique.
+ *
+ * @param $form
+ *   Form to remove elements from.
+ * @param $keep
+ *   CCK field elements to keep from the form.
+ * @param $fid
+ *   File ID to prefix element names with.
+ * @param $remove
+ *   Additional non-elements to remove.
+ */
+function image_fupload_remove_cck(&$form, $keep, $fid, $remove = array()) {
+  $newstuff = array();
+  foreach ($form as $key => $element) {
+    if (in_array($key, $remove)) {
+      unset($form[$key]);
+      continue;
+    }
+
+    // Make sure what we're looking at is a form element array.
+    if (!is_array($element) || !isset($element['#field_name'])) {
+      continue;
+    }
+
+    // If it's a fieldset, recurse.
+    if ($element['#type'] == 'fieldset') {
+      image_fupload_remove_cck($element, $keep, $fid);
+      continue;
+    }
+
+    // If we get here it's a normal element, so see if we should keep it or
+    // not.
+    if (!in_array($key, $keep)) {
+      unset($form[$key]);
+      continue;
+    }
+
+    // If we get here, it's a keeper. Change the name.
+    $newkey = $key . '_' . $fid;
+    $newstuff[$newkey] = $element;
+    unset($form[$key]);
+  }
+
+  $form += $newstuff;
+}
+
+/**
+ * Unsets unneeded taxonomy field form elements.
+ *
+ * @param $form
+ *   Form to remove elements from.
+ * @param $keep
+ *   Elements to keep from the form.
+ */
+function image_fupload_remove_taxonomy(&$form, $keep) {
+  // Regular vocabularies.
+  foreach ($form['taxonomy'] as $key => $value) {
+    // taxonomy normal
+    if (!in_array($key, $keep) && is_numeric($key)) {
+      unset($form['taxonomy'][$key]);
+    }
+  }
+
+  // Tag vocabularies.
+  if (is_array($form['taxonomy']['tags'])) {
+    foreach ($form['taxonomy']['tags'] as $key => $value) {
+      if (!in_array($key, $keep)) {
+        unset($form['taxonomy']['tags'][$key]);
+      }
+    }
+  }
+}
Index: image_fupload_imagefield/image_fupload_imagefield.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/image_fupload/image_fupload_imagefield/image_fupload_imagefield.module,v
retrieving revision 1.38
diff -u -r1.38 image_fupload_imagefield.module
--- image_fupload_imagefield/image_fupload_imagefield.module	1 Feb 2010 21:00:22 -0000	1.38
+++ image_fupload_imagefield/image_fupload_imagefield.module	27 Jan 2011 01:31:08 -0000
@@ -120,7 +120,7 @@
 
           if (user_access('edit captions')) { // user allowed to use preview list?
             // delete fields which will be shown later in preview list; cache this
-            form_fields_destroy($form, $field['widget']['fupload_previewlist_field_settings']);
+            form_fields_remove_some($form, $field['widget']['fupload_previewlist_field_settings']);
             form_set_cache($form['form_build_id'], $form, $form_state); // save changed data in cache, include removed fields for image preview list --> no validation
             unset($form['buttons']['preview']);
           }
@@ -526,7 +526,6 @@
  * Removing a given list of fields (ckk, node, imagefield, taxonomy) of form
  * Validation for these fields will also be deactivated
  */
-
 function form_fields_destroy(&$form, $fields_to_remove = array()) {
   // collect information about fields being used by image preview list, if needed
   $fields = array();
@@ -579,6 +578,38 @@
 }
 
 /**
+ * Removes some fields, removes validation from others.
+ *
+ * Lets some fields be editable to set defaults, and leaves others to the
+ * preview screen.
+ */
+function form_fields_remove_some(&$form, $fields_to_remove = array()) {
+  // collect information about fields being used by image preview list, if needed
+  $fields = array();
+
+  if (count($fields_to_remove)) {
+    foreach ($fields_to_remove as $key) {
+      $elements = explode("_", $key, 2);
+      if (!isset($fields[$elements[0]]) && $fields_to_remove[$key] != FALSE)
+        $fields[$elements[0]] = array();
+      if ($fields_to_remove[$key] != FALSE)
+        array_push($fields[$elements[0]], $elements[1]);
+    }
+  }
+
+  // Remove node title and body, if they can be edited on the
+  // preview form.
+  if (isset($fields['node'])) {
+    if (in_array("title", $fields['node'])) {
+      unset($form['title']);
+    }
+    if (in_array("description", $fields['node'])) {
+      unset($form['body_field']);
+    }
+  }
+}
+
+/**
  * Theming related things
  */
 
