# This patch file was generated by NetBeans IDE
# This patch can be applied using context Tools: Apply Diff Patch action on respective folder.
# It uses platform neutral UTF-8 encoding.
# Above lines and this line are ignored by the patching process.
Index: contributions/modules/node_gallery/node_gallery.admin.inc
--- contributions/modules/node_gallery/node_gallery.admin.inc Base (1.11.2.22)
+++ contributions/modules/node_gallery/node_gallery.admin.inc Locally Modified (Based On 1.11.2.22)
@@ -20,9 +20,11 @@
   $ng_rels = node_gallery_get_all_relationships();
   
   if (!empty($ng_rels)) {
-    $headers = array(t('Relationship name'), t('Gallery type'), t('Image type'), t('Operations'));
+    $headers = array(t('Relationship name'), t('Gallery type'), t('Image type'), t('Image Field'), t('Operations'));
     foreach ($ng_rels as $gallery_type => $config) {
-      $rows[] = array($config['settings']['name'], $gallery_type, $config['image_type'], 
+      $image_type = content_types($config['image_type']);
+      $field_link = 'admin/content/node-type/'.$type['url_str'].'/fields/'.$config['imagefield_name'];
+      $rows[] = array($config['settings']['name'], $gallery_type, $config['image_type'], l($config['imagefield_name'], $field_link),
       theme('links', node_gallery_relationship_operations($gallery_type)));
     }
     return theme('table', $headers, $rows, array('class' => 'node-gallery-config-list'));
@@ -188,7 +190,33 @@
     if (empty($imagecaches)) {
       form_set_error('Node gallery config', t('There are no imagecache presets. <a href="@imagecache">You must create at least one preset</a>.', array('@imagecache' => url('admin/build/imagecache/add'))));
     }
+    module_load_include('inc', 'content', 'includes/content.crud');
+    $imagefield_instances = content_field_instance_read(array('type_name' => $relationship['image_type']));
+    $options_imagefields = array();
+    if (!empty($imagefield_instances)) {
+      foreach ($imagefield_instances as $imagefield_instance) {
+        $options_imagefields[$imagefield_instance['field_name']] = $imagefield_instance['field_name'];
+      }
+    }
+    if (!array_key_exists('field_node_gallery_image', $options_imagefields)) {
+      $options_imagefields['field_node_gallery_image'] = t('Create new imagefield');
+    }
     
+    $form['node_gallery_relationship_settings'] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Relationship settings'),
+      '#description' => t('This area defines the settings used to define the relationship between the content types.'),
+      '#collapsible' => TRUE,
+      '#collapsed' => FALSE,
+    );
+    
+    $form['node_gallery_relationship_settings']['imagefield'] = array(
+      '#type' => 'select',
+      '#title' => t('Imagefield for Galleries'),
+      '#description' => t('Select the imagefield that will be used for the gallery images.'),
+      '#options' => $options_imagefields,
+      //'#default_value' => (isset($relationship['imagefield_name']) && !empty($relationship['imagefield_name'])) ? $relationship['imagefield_name'] : '',
+    );
     $viewdisplays = node_gallery_build_views_select();
   
     $form['node_gallery_gallery_view'] = array(
@@ -321,8 +349,36 @@
   $r = new stdClass;
   $r->gallery_type = $form_state['storage']['gallery_type'];
   $r->image_type = $form_state['storage']['image_type'];
-  // @todo: Build a list of all imagefields on the image content type, and allow the user to choose one or create our default field_node_gallery_image imagefield content type.
-  $r->imagefield_name = 'field_node_gallery_image';
+
+  $r->imagefield_name = $form_state['values']['imagefield'];
+  if ($r->imagefield_name == 'field_node_gallery_image') {
+    // if the field is named 'field_node_gallery_image' check if it exists
+    // or if we need to create it. We could hack around that check with a pre- or
+    // suffix, but I rate this way cleaner (though more costly).
+    module_load_include('inc', 'content', 'includes/content.crud');
+    $param = array(
+      'type_name' => $r->image_type,
+      'field_name' => 'field_node_gallery_image',
+    );
+    $field_instance = content_field_instance_read($param);
+    if (empty($field_instance)) {
+      // create the default imagefield read out of the default type
+      $path = drupal_get_path('module', 'node_gallery') . "/cck_types";
+      $cck_file = $path . '/node_gallery_image.cck';
+      if (module_exists('image_fupload_imagefield') && variable_get('node_gallery_image_fupload_integration', FALSE)) {
+        $cck_file = $path . '/node_gallery_image_fupload.cck';
+      }
+      $param = array('type_name' => $r->image_type);
+      {
+        $content = array();
+        eval(file_get_contents($cck_file));
+        $param = array_merge($param, array_pop($content['fields']));
+        unset($content);
+      }
+      content_field_instance_create($param);
+      drupal_set_message(t('Node Gallery imagefield created.'));
+    }
+  }
   $existing = node_gallery_get_relationship($r->gallery_type);
   $settings = isset($existing['settings']) ? $existing['settings'] : array();
   $valid_settings=array('view_gallery_full_image_display', 'view_gallery_teaser_view_image_display', 'display_navigator', 'node_images_page_fragment', 'teaser_display_type', 'gallery_display_type');
Index: contributions/modules/node_gallery/node_gallery.inc
--- contributions/modules/node_gallery/node_gallery.inc Base (1.2.2.42)
+++ contributions/modules/node_gallery/node_gallery.inc Locally Modified (Based On 1.2.2.42)
@@ -613,8 +613,8 @@
   db_query("UPDATE {node_gallery_galleries} SET cover_image = NULL WHERE cover_image = %d", $node->nid);
   // We don't delete the file from the filesystem anymore, because imagefield handles this for us
   // Clean our imagecache - note, this API call leaves empty dirs
-  // @todo: eliminate hardcoded reference to field_node_gallery_image below
-  imagecache_image_flush($node->field_node_gallery_image[0]['filepath']);
\ No newline at end of file
+  $relationship = node_gallery_get_relationship(NULL, $node->type);
+  imagecache_image_flush($node->{$relationship['imagefield_name']}[0]['filepath']);
   // Clean up empty dirs, if they exist
   node_gallery_clean_empty_dirs(dirname($node->field_node_gallery_image[0]['filepath']));
 }
Index: contributions/modules/node_gallery/node_gallery.install
--- contributions/modules/node_gallery/node_gallery.install No Base Revision
+++ contributions/modules/node_gallery/node_gallery.install Locally New
@@ -0,0 +1,565 @@
+<?php
+// $Id: node_gallery.install,v 1.19.2.35 2010/05/10 15:01:50 justintime Exp $
+
+/**
+ * @file
+ * Node gallery install file. 
+ *
+ */
+
+define(NODE_GALLERY_DEFAULT_GALLERY_TYPE, 'node_gallery_gallery');
+define(NODE_GALLERY_DEFAULT_IMAGE_TYPE, 'node_gallery_image');
+
+/**
+ * Implements hook_schema()
+ *
+ * @return unknown
+ */
+function node_gallery_schema() {
+  $schema = array();
+  
+  $schema['node_gallery_relationships'] = array(
+    'fields' => array(
+      'rid' => array(
+        'type' => 'serial',
+        'not null' => TRUE,
+        'description' => t('Node Gallery Relationship ID'),
+      ),
+      'gallery_type' => array(
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'description' => t('Node Gallery Gallery Content Type.'),
+      ),
+      'image_type' => array(
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'description' => t('Node Gallery Image Content Type.'),
+      ),
+      'imagefield_name' => array(
+        'type' => 'varchar',
+        'not null' => TRUE,
+        'length' => 255,
+        'description' => t('The name of the imagefield that contains the image on an image node.'),
+      ),
+      'settings' => array(
+        'type' => 'text',
+        'not null' => FALSE,
+        'serialize' => TRUE,
+      ),
+    ),
+    'primary key' => array('rid'),
+  );
+  $schema['node_gallery_images'] = array(
+    'fields' => array(
+      'nid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Image node id.'),
+      ),
+      'gid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Gallery node id.'),
+      ),
+      'weight' => array(
+        'type' => 'int',
+        'size' => 'small',
+        'not null' => TRUE,
+        'default' => 0,
+      ),
+    ),
+    'primary key' => array('nid'),
+    'indexes' => array(
+      // For quick finding of the contents of a gallery
+      'gallery' => array('gid'),
+    )
+  );
+  $schema['node_gallery_galleries'] = array(
+    'fields' => array(
+      'gid' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+        'default' => 0,
+        'description' => t('Gallery node id.'),
+      ),
+      'cover_image' => array(
+        'type' => 'int',
+        'unsigned' => TRUE,
+        'not null' => FALSE,
+        'default' => NULL,
+        'description' => t('Node Id of the Cover Image')
+      ),
+    ),
+    'primary key' => array('gid'),
+    'unique keys' => array(
+      // To quickly answer, is this image the cover image?
+      'cover_image' => array('cover_image'),
+    ),
+  );
+   
+  return $schema;
+}
+
+function node_gallery_required_modules() {
+  return array('content', 'views', 'filefield', 'imageapi', 'imagecache', 'imagefield');
+}
+
+function node_gallery_type_exists($type) {
+  // During install profiles, node and user modules aren't yet loaded.
+  // Ensure they're loaded before calling node_get_types().
+  include_once './'. drupal_get_path('module', 'node') .'/node.module';
+  include_once './'. drupal_get_path('module', 'user') .'/user.module';
+  $types = node_get_types();
+  $types = array_change_key_case($types, CASE_LOWER);
+  return array_key_exists($type, $types);
+}
+
+function node_gallery_install_cck_type($type = '<create>', $filename = '') {
+  // Since we only need content copy once at install time, we cheat a bit here and include it
+  // to take care of the case where CCK is installed and enabled, but content_copy isn't enabled
+  require_once './' . drupal_get_path('module', 'content') . '/modules/content_copy/content_copy.module';
+     
+
+  // Get the files content
+  if (file_exists($filename)) {
+    $macro = implode('', file($filename));
+  }
+  else {
+    drupal_set_message(t('Unable to read cck file !file for import. Exiting.', array('!file' => $filename)), 'error');
+    return;
+  }
+  if ($type != '<create>') {
+    // add the imagefield for the image type.
+    if ($type == NODE_GALLERY_DEFAULT_IMAGE_TYPE) {
+        $content = array();
+        eval($macro);
+        $param = array('type_name' => $type);
+        $param = array_merge($param, array_pop($content['fields']));
+        module_load_include('inc', 'content', 'includes/content.crud');
+        content_field_instance_create($param);
+    }
+  } else {
+    // Build form state
+    $form_state = array(
+    'values' => array(
+      'type_name' => $type,
+      'macro' => $macro,
+      ),
+    );
+
+    // form provided by content_copy.module
+    drupal_execute('content_copy_import_form', $form_state);
+    content_clear_type_cache();
+  }
+}
+
+function _migrate_files_to_imagefields() {
+  $total = db_result(db_query('SELECT COUNT(nid) FROM {node_galleries}'));
+  
+  // first, select nid, fid from node_galleries
+  $result = db_query('SELECT nid, fid FROM {node_galleries}');
+  
+  // upgrade the node
+  while ($r = db_fetch_array($result)) {
+    $image = node_load($r['nid']);
+    $file = db_fetch_array(db_query('SELECT fid, uid, filename, filepath, filemime, filesize, status, timestamp FROM {files} WHERE fid = %d', $r['fid']));
+    $image->field_node_gallery_image[0] = $file;
+    $image->field_node_gallery_image[0]['data'] = array('alt' => $node->title, 'title' => $node->title);
+    $image->field_node_gallery_image[0]['origname'] = $file['filename'];
+    $image->field_node_gallery_image[0]['list'] = 1;
+    node_save($image);
+    db_query('DELETE FROM {node_galleries} WHERE nid = %d', $image->nid);
+  }
+  drupal_set_message(t('Upgraded !number total images to imagefields.', array('!number' => $total)));
+}
+
+function node_gallery_setup_content_type($type) {
+   // add CCK types
+  $path = drupal_get_path('module', 'node_gallery') . "/cck_types";
+  $cck_file = $path . "/" . $type . ".cck";
+  $action = node_gallery_type_exists($type) ? $type : '<create>';
+  node_gallery_install_cck_type($action, $cck_file);
+  drupal_set_message(t('Node type "' . $type . '" created/modified.'));
+}
+
+function node_gallery_setup_content_types() {
+  foreach (array(NODE_GALLERY_DEFAULT_GALLERY_TYPE, NODE_GALLERY_DEFAULT_IMAGE_TYPE) as $type) {
+    node_gallery_setup_content_type($type);
+  }
+}
+
+/**
+ * Implements hook_install()
+ *
+ */
+function node_gallery_install() {
+  // If the user manages to install this module without the prerequisite modules enabled, this will enable them.
+  module_enable(node_gallery_required_modules());
+  node_gallery_setup_content_types();  
+  $ret = drupal_install_schema('node_gallery');
+  node_gallery_install_imagecache_presets();
+  node_gallery_set_imagecache_permissions();
+  node_gallery_install_default_settings();
+}
+
+/**
+ * Implements hook_uninstall()
+ *
+ */
+function node_gallery_uninstall() {
+  global $conf;
+  include_once './'. drupal_get_path('module', 'node') .'/node.module';
+  include_once './'. drupal_get_path('module', 'user') .'/user.module';
+  $types = node_get_types();
+  foreach (array(NODE_GALLERY_DEFAULT_GALLERY_TYPE, NODE_GALLERY_DEFAULT_IMAGE_TYPE) as $content_type) {
+    if (in_array($content_type, array_keys($types))) {
+      drupal_set_message(t('The !content_type content type is still present.  You may !delete_link.', array('!content_type' => $content_type, '!delete_link' => l(t('delete it'), 'admin/content/node-type/'. str_replace('_', '-', $content_type) .'/delete', array('attributes' => array('target' => '_blank'))))));
+    }
+  }
+  // Remove our imagecache presets
+  foreach (array('node-gallery-cover', 'node-gallery-display', 'node-gallery-thumbnail') as $preset_name) {
+    $preset = imagecache_preset_by_name($preset_name);
+    if ($preset['presetid']) {
+      drupal_set_message(t('The !preset_name imagecache preset is still present.  You may !delete_link.', array('!preset_name' => $preset_name, '!delete_link' => l(t('delete it'), 'admin/build/imagecache/'. $preset['presetid'] .'/delete', array('attributes' => array('target' => '_blank'))))));
+    }
+  }
+  $ret = drupal_uninstall_schema('node_gallery');
+  foreach ($conf as $key => $value) {
+    if (strpos($key, 'node_gallery') === 0) {
+      variable_del($key);
+    }
+  }
+  cache_clear_all();
+}
+
+function node_gallery_relationship_default_settings() {
+  // @todo Finalize the default settings for relationships
+  $settings = array(
+    'foo' => 'bar',
+  );
+  return $settings;
+}
+
+function node_gallery_install_default_settings() {
+  /* Set the defaults for a node_gallery relationship */
+  // @todo Remove this before release
+  /*
+  $default = array(
+   'gallery_type' => 'node_gallery_gallery',
+   'image_type' => 'node_gallery_image',
+   'name' => 'Node Gallery Default', 
+   'display_fields' => array('title' => 'title', 'body_field' => 'body_field', ), 
+   'content_display' => 'image', 
+   'view_original' => '0', 
+   'view_original_text' => 'Download the Original Image', 
+   'lightbox2' => 'node-gallery-display', 
+   'image_size' => array('cover' => 'node-gallery-cover', 'thumbnail' => 'node-gallery-thumbnail', 'preview' => 'node-gallery-display'), 
+   'teaser' => array('gallery_display_type' => 'thumbnails', 'thumbnails_num' => '6', 'lightbox2_gallery' => 'node-gallery-display', 'image' => 'node-gallery-thumbnail'), 
+   'gallery' => array('gallery_display_type' => 'thumbnails', 'lightbox2_gallery_preset' => 'node-gallery-display'));
+  
+  variable_set('node_gallery_' . NODE_GALLERY_DEFAULT_GALLERY_TYPE, $default);
+  */
+  $rel = new stdClass;
+  $rel->gallery_type = $var['gallery_type'];
+  $rel->image_type = $var['image_type'];
+  $rel->settings = node_gallery_relationship_default_settings();
+  drupal_write_record('node_gallery_relationships', $rel);
+}
+
+function node_gallery_install_imagecache_presets() {
+  // First, build an array of all the preset names so we do not make duplicates
+  // Set the argument to TRUE to reset the cache
+  $presets = imagecache_presets(TRUE);
+  $preset_names = array();
+  
+  // If there are any presets
+  if ($presets != '') {
+    foreach ($presets as $preset) {
+      $preset_names[] = $preset['presetname'];
+    }
+  }
+  
+  // Prepare to install ImageCache presets
+  $imagecache_presets = array();
+  $imagecache_actions = array();
+  
+  // We are checking to make sure the preset name does not exist before creating
+  if (!in_array('node-gallery-thumbnail', $preset_names)) {
+    $imagecache_presets[] = array(
+      'presetname' => 'node-gallery-thumbnail',
+    );
+    $imagecache_actions['node-gallery-thumbnail'][] = array(
+      'action' => 'imagecache_scale_and_crop',
+      'data' => array(
+        'width' => 100,
+        'height' => 100,
+      ),
+      'weight' => 0,
+    );
+  }
+  
+  if (!in_array('node-gallery-cover', $preset_names)) {
+    $imagecache_presets[] = array(
+      'presetname' => 'node-gallery-cover',
+    );
+    $imagecache_actions['node-gallery-cover'][] = array(
+      'action' => 'imagecache_scale_and_crop',
+      'data' => array(
+        'width' => 150,
+        'height' => 150,
+      ),
+      'weight' => 0,
+    );
+  }
+  
+  if (!in_array('node-gallery-display', $preset_names)) {
+    $imagecache_presets[] = array(
+      'presetname' => 'node-gallery-display',
+    );
+    $imagecache_actions['node-gallery-display'][] = array(
+      'action' => 'imagecache_scale',
+      'data' => array(
+        'height' => 1500,
+      ),
+      'weight' => 0,
+    );
+    $imagecache_actions['node-gallery-display'][] = array(
+      'action' => 'imagecache_scale',
+      'data' => array(
+        'width' => 600,
+      ),
+      'weight' => 1,
+    );
+  }
+  
+  // Need to install preset, id will be returned by function,
+  // Then install action add presetid to action prior to install:
+  foreach ($imagecache_presets as $preset) {
+    $preset = imagecache_preset_save($preset);
+    foreach ($imagecache_actions[$preset['presetname']] as $action) {
+      $action['presetid'] = $preset['presetid'];
+      imagecache_action_save($action);
+    }
+    drupal_set_message(t('ImageCache preset %id: %name and corresponding actions saved.', array('%id' => $preset['presetid'], '%name' => $preset['presetname'])));
+  }
+}
+
+function node_gallery_set_imagecache_permissions() {
+  $query = db_query("SELECT rid, perm FROM {permission} ORDER BY rid");
+  while ($role = db_fetch_object($query)) {
+    $role->perm .= ', view imagecache node-gallery-cover, view imagecache node-gallery-thumbnail, view imagecache node-gallery-display';
+    update_sql("UPDATE {permission} SET perm = '$role->perm' WHERE rid = $role->rid");
+  }
+}
+
+function _migrate_variables_to_relationship_table() {
+  global $conf;
+  $node_types = array_keys(node_get_types());
+  foreach ($conf as $key => $value) {
+    if (strpos($key, 'node_gallery_') === 0) {
+      $t = substr($key, 13);
+      if (in_array($t, $node_types)) {
+        // migrate monolithic node_gallery_<content_type> variables
+        $var = variable_get($key, array());
+        if (! isset($var['gallery_type'])) {
+          continue;
+        }
+        $rel = new stdClass;
+        $rel->gallery_type = $var['gallery_type'];
+        $rel->image_type = $var['image_type'];
+        $rel->imagefield_name = 'field_node_gallery_image';
+        // @todo Replicate settings to views using $view->save()
+        // @todo Can we/should we migrate image limits to filefield
+        if (isset($var['gallery_directory']) || isset($var['default_cover']) || isset($var['upload_limits'])) {
+          // @todo Either display a link to the settings page, or migrate.
+        }
+        $rel->settings = array_merge(node_gallery_relationship_default_settings(), $var);
+        drupal_write_record('node_gallery_relationships', $rel);
+        variable_del($key);
+      }
+    }
+  }
+  // Move this variable to one with a proper namespace
+  if (variable_get('node_images_page_fragment', FALSE)) {
+    drupal_set_message(t('You have selected \'Use Named Anchors on Image "Previous" and "Next" links\' in your configuration.  This setting is now set on a per-relationship basis.  Please <a href="@relationship_page">configure your relationships</a> to re-apply your previous setting.', array('@relationship_page' => url('admin/settings/node_gallery'))), 'warning');
+    variable_del('node_images_page_fragment');
+  }
+  foreach (array('node_gallery_page_number', 'node_images_page_number', ) as $v) {
+    $value = variable_get($v, 20);
+    switch ($v) {
+      case 'node_gallery_page_number':
+        if ($value != 20) {
+          drupal_set_message(t('You have selected to display @value galleries per page.  The default is 20 - you may change the value by <a href="@view_link">editing the view</a>.', array('@value' => $value, '@view_link' => url('admin/build/views/edit/node_gallery_gallery_summaries'))), 'warning');
+        }
+        break;
+      case 'node_images_page_number':
+        if ($value != 0) {
+          drupal_set_message(t('You have selected to display @value images per page.  The default is 0 (unlimited) - you may change the value by <a href="@view_link">editing the view</a>.', array('@value' => $value, '@view_link' => url('admin/build/views/edit/node_gallery_gallery_image_views'))), 'warning');
+        }
+        break;
+    }
+    variable_del($v);
+  }
+}
+
+/**
+ * Implements hook_update_N()
+ * Directly installing the default imagecache presets
+ */
+function node_gallery_update_6100() {
+  $ret = array();
+  node_gallery_install_imagecache_presets();
+  node_gallery_set_imagecache_permissions();
+  return $ret;
+}
+
+/**
+ * Implements hook_update_N()
+ * Updating the database for the changing options for "view original"
+ */
+function node_gallery_update_6101() {
+  $ret = array();
+  $result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
+  $t = drupal_unpack(db_fetch_object($result));
+  while ($t = drupal_unpack(db_fetch_object($result))) {
+    if (!empty($t)) {
+      $relationship = new gallery_config($t);
+      if (!$relationship->lightbox2) {
+        $relationship->lightbox2 = 'node-gallery-display';
+      }
+      if (!$relationship->view_original_text) {
+        $relationship->view_original_text = '';
+      }
+      if ($relationship->view_original == '1') {
+        $relationship->view_original = 'default';
+      }
+      unset($relationship->data);
+      
+      $relationship->save();
+    }
+  }
+  return $ret;
+}
+
+/**
+ * Implements hook_update_N()
+ * Updating the database for the changing options for "view teaser"
+ */
+function node_gallery_update_6102() {
+  $ret = array();
+  $result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
+  $t = drupal_unpack(db_fetch_object($result));
+  while ($t = drupal_unpack(db_fetch_object($result))) {
+    if (!empty($t)) {
+      $relationship = new gallery_config($t);
+      if ($relationship->teaser['gallery_display_type'] == '0') {
+        $relationship->teaser['gallery_display_type'] = 'cover';
+      }
+      elseif ($relationship->teaser['gallery_display_type'] == '1') {
+        $relationship->teaser['gallery_display_type'] = 'thumbnails';
+      }
+      $relationship->gallery = array(
+        'gallery_display' => 'thumbnails',
+        'lightbox2_gallery_preset' => 'node-gallery-display',
+      );
+      unset($relationship->data);
+      $relationship->save();
+    }
+  }
+  return $ret;
+}
+
+/**
+ * Implements hook_update_N()
+ * Updating the database so we can custom select the number of uploads
+ */
+function node_gallery_update_6103() {
+  $ret = array();
+  $result = db_query("SELECT * FROM {ng_gallery_config} WHERE 1");
+  $t = drupal_unpack(db_fetch_object($result));
+  while ($t = drupal_unpack(db_fetch_object($result))) {
+    if (!empty($t)) {
+      $relationship = new gallery_config($t);
+      $relationship->upload_settings = array(
+        'number_uploads' => '5',
+      );
+      unset($relationship->data);
+      $relationship->save();
+    }
+  }
+  return $ret;
+}
+
+function node_gallery_update_6201() {
+  $ret = array();
+  
+  db_drop_primary_key($ret, 'node_galleries');
+  db_add_primary_key($ret, 'node_galleries', array('nid'));
+  return $ret;
+}
+
+/**
+ * Implements hook_update_N()
+ * Alerting the users that we have potentially broken their views
+ */
+function node_gallery_update_6202() {
+  $ret = array();
+  drupal_set_message(t('Node Gallery had to change some of our views code to <a href="http://drupal.org/node/547982">fix a bug relating to the "Gallery Operations" field</a>.  If you used this field, you may be required to rebuild any views using that field.  %broken.', array('%broken' => l(t('Read this information on how to fix any broken views'), 'http://drupal.org/node/547982', array('fragment' => 'comment-2199342')))), 'warning');
+  return $ret;
+}
+
+function node_gallery_update_6203() {
+  $ret = array();
+  drupal_set_message(t('Node Gallery Access has been removed from core, and migrated to it\'s own module - you may download the new version from !url.', array('url' => l('http://drupal.org/project/node_gallery_access', 'http://drupal.org/project/node_gallery_access'))));
+  $contribdir = drupal_get_path('module', 'node_gallery') . '/contrib/node_gallery_access';
+  // Does the contrib node_gallery_access exist?
+  if (is_dir($contribdir)) {
+    // Is it enabled?
+    if (module_exists('node_gallery_access')) {
+      module_disable(array('node_gallery_access'));
+      drupal_set_message(t('Node Gallery Access (contrib version) has been disabled, but your data is still there.  Simply download the new version after removing the old one, and everything will upgrade automatically.'));
+    }
+    // We could go to the trouble to try a recursive delete, but most modules/* files aren't writable by Apache anyways.
+    $ret['#abort'] = array('success' => FALSE, 'query' => 'Old contrib version of Node Gallery Access was found at ' . $contribdir . '.  Please remove that directory and all of it\'s subfolders then rerun ' . l('update.php', 'update.php'));
+  }
+  return $ret;
+}
+
+function node_gallery_update_6300() {
+  // @todo fill $ret with the right values
+  $ret = array();
+  // Create new tables
+  $schema = node_gallery_schema();
+  foreach (array('node_gallery_galleries', 'node_gallery_images', 'node_gallery_relationships') as $table) {
+    if (!db_table_exists($table)) {
+      db_create_table($ret, $table, $schema[$table]);
+    }
+  }
+  // Update gallery and image content types with new imagefield
+  node_gallery_setup_content_types();
+  cache_clear_all();
+  if (db_table_exists('node_galleries')) {
+    update_sql('DELETE FROM {node_gallery_galleries}');
+    update_sql('DELETE FROM {node_gallery_images}');
+    // Migrate galleries from old table to new
+    update_sql('INSERT INTO {node_gallery_galleries} (SELECT DISTINCT gid, NULL FROM {node_galleries})');
+    // Migrate cover images
+    update_sql('UPDATE {node_gallery_galleries} new JOIN {node_galleries} old ON new.gid = old.gid SET cover_image = nid WHERE is_cover > 0');
+    // Migrate images from old table to new
+    update_sql('INSERT INTO {node_gallery_images} (SELECT nid,gid,weight FROM {node_galleries})');
+    _migrate_files_to_imagefields();
+    db_drop_table($ret, 'node_galleries');
+  }
+  
+  _migrate_variables_to_relationship_table();
+  cache_clear_all();
+  return $ret;
+} 
+
Index: contributions/modules/node_gallery/node_gallery.module
--- contributions/modules/node_gallery/node_gallery.module Base (1.18.2.75)
+++ contributions/modules/node_gallery/node_gallery.module Locally Modified (Based On 1.18.2.75)
@@ -310,11 +310,13 @@
           
           // If the user has image_fupload enabled, they have to allow multiple imagefields per node.
           // We really don't want that, so we zap the buttons on this form and set the right theme.
-          // @todo: eliminate hardcoded reference to field_node_gallery_image below
-          $form['field_node_gallery_image']['#theme'] = 'content_single_value';
-          unset($form['field_node_gallery_image']['0']['_weight']);
-          unset($form['field_node_gallery_image']['field_node_gallery_image_add_more']);
-          unset($form['field_node_gallery_image']['1']);
\ No newline at end of file
+          $relationship = node_gallery_get_relationship(NULL, $form['type']['#value']);
+          $field_name = $relationship['imagefield_name'];
+          
+          $form[$field_name]['#theme'] = 'content_single_value';
+          unset($form[$field_name]['0']['_weight']);
+          unset($form[$field_name][$field_name.'_add_more']);
+          unset($form[$field_name]['1']);
           if ($form['fupload']) {
             unset($form['body_field']);
             // @todo Need to display cover radios and tabledrag for weight on fupload form.
