Index: content.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/content.module,v
retrieving revision 1.56.2.17
diff -u -r1.56.2.17 content.module
--- content.module	21 Aug 2006 03:06:45 -0000	1.56.2.17
+++ content.module	25 Aug 2006 04:42:08 -0000
@@ -15,6 +15,9 @@
 if (module_exist('pathauto')) {
   include_once(drupal_get_path('module', 'content') .'/content_pathauto.inc');
 }
+if (module_exist('importexportapi')) {
+  include_once(drupal_get_path('module', 'content') .'/content_importexportapi.inc');
+}
 
 /**
  * Implementation of hook_help().
Index: content_importexportapi.inc
===================================================================
RCS file: content_importexportapi.inc
diff -N content_importexportapi.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ content_importexportapi.inc	25 Aug 2006 04:42:08 -0000
@@ -0,0 +1,315 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implements data definitions on behalf of content.module.
+ */
+
+/**
+ * Implementation of hook_def().
+ */
+function content_def() {
+  $defs = array();
+
+  $def = array(
+    '#type' => 'entity',
+    '#title' => t('Content field'),
+    '#db_default_table' => 'node_field',
+    '#xml_plural' => 'content-fields',
+    '#csv_plural' => 'content-fields'
+  );
+
+  $def['field_name'] = array(
+    '#title' => t('Field name'),
+    '#key_component' => TRUE
+  );
+  $def['field_type'] = array(
+    '#title' => t('Field type'),
+    '#db_field_unaliased' => 'type'
+  );
+  $def['global_settings'] = array(
+    '#title' => t('Global settings')
+  );
+  $def['required'] = array(
+    '#type' => 'int',
+    '#title' => t('Required')
+  );
+  $def['multiple'] = array(
+    '#type' => 'int',
+    '#title' => t('Multiple values')
+  );
+  $def['db_storage'] = array(
+    '#type' => 'int',
+    '#title' => t('Uses database storage')
+  );
+
+  $defs['content_field'] = $def;
+
+  $def = array(
+    '#type' => 'entity',
+    '#title' => t('Content type'),
+    '#db_default_table' => 'node_type_content',
+    '#xml_plural' => 'content-types',
+    '#csv_plural' => 'content-types'
+  );
+
+  $def['type_name'] = array(
+    '#title' => t('Type name'),
+    '#key_component' => TRUE
+  );
+  $def['type_label'] = array(
+    '#title' => t('Label'),
+    '#db_field_unaliased' => 'label',
+    '#alt_key_for' => 'type_name'
+  );
+  $def['description'] = array(
+    '#title' => t('Description')
+  );
+  $def['help_text'] = array(
+    '#title' => t('Help text'),
+    '#db_field_unaliased' => 'help'
+  );
+  $def['title_label'] = array(
+    '#title' => t('Title label')
+  );
+
+  $def['fields'] = array(
+    '#type' => 'array',
+    '#title' => t('Fields'),
+    '#db_default_table' => 'node_field_instance',
+    '#xml_plural' => 'fields',
+    '#csv_plural' => 'content-field-instances',
+    '#xml_mapping' => 'field'
+  );
+  $def['fields']['field_name'] = array(
+    '#title' => t('Field name'),
+    '#key_component' => TRUE,
+    '#reference_entity' => 'content_field'
+  );
+  $def['fields']['type_name'] = array(
+    '#title' => t('Type name'),
+    '#key_component' => TRUE,
+    '#reference_entity' => 'content_type'
+  );
+  $def['fields']['weight'] = array(
+    '#type' => 'int',
+    '#title' => t('Weight')
+  );
+  $def['fields']['label'] = array(
+    '#title' => t('Label')
+  );
+  $def['fields']['widget_type'] = array(
+    '#title' => t('Widget type')
+  );
+  $def['fields']['widget_settings'] = array(
+    '#title' => t('Widget settings')
+  );
+  $def['fields']['description'] = array(
+    '#title' => t('Description')
+  );
+
+  $defs['content_type'] = $def;
+
+  $content_types = content_types();
+  $content_fields = content_fields();
+
+  foreach ($content_types as $content_type_name => $content_type_info) {
+    $def = importexportapi_node_get_def();
+    $table_info = array();
+
+    $content_type_name_system = str_replace('-', '_', $content_type_name);
+    $content_type_name_mapping = str_replace('_', '-', $content_type_name);
+
+    $def['#title'] = $content_type_info['label'];
+    $def['#title'][0] = strtoupper($def['#title'][0]);
+
+    $def['#xml_plural'] = $def['#csv_plural'] = $content_type_name_mapping .'-collection';
+    $def['revisions']['#csv_plural'] = $content_type_name_mapping .'-revisions';
+
+    $def['type']['#db_filter'] = array(
+      'values' => array($content_type_name)
+    );
+
+    foreach ($content_type_info['fields'] as $field_name => $field_info) {
+      $table_info += _content_importexportapi_generate_fields($def, $field_info);
+    }
+
+    foreach ($table_info as $table => $table_info) {
+      _content_importexportapi_add_parent_references($def, $table, $table_info, $content_type_name_system);
+    }
+
+    $defs[$content_type_name_system] = $def;
+  }
+
+  return $defs;
+}
+
+/**
+ * Implementation of hook_db_def_tables().
+ */
+function content_db_def_tables() {
+  $tables = array();
+
+  $tables['node_type_content'] = 'nt';
+  $tables['node_field'] = 'nf';
+  $tables['node_field_instance'] = 'nfi';
+
+  $content_fields = content_fields();
+
+  foreach ($content_fields as $field_info) {
+    $database_info = content_database_info($field_info);
+    $db_table = $database_info['table'];
+
+    if (!isset($tables[$db_table])) {
+      $tables[$db_table] = $db_table;
+    }
+  }
+
+  return $tables;
+}
+
+function _content_importexportapi_generate_fields(&$def, $field_info) {
+  $database_info = content_database_info($field_info);
+
+  // Boolean flags.
+  $multiple_columns = (count($database_info['columns']) > 1);
+  $storage_per_field = ($field_info['db_storage'] == CONTENT_DB_STORAGE_PER_FIELD);
+  $multiple_values = ($field_info['multiple']);
+
+  $base_title = !empty($field_info['widget']['label']) ? $field_info['widget']['label'] : $field_info['field_name'];
+  $field_name = NULL;
+  $ret_field_name = NULL;
+
+  foreach ($database_info['columns'] as $column) {
+    $sub_field_array = explode('_', $column['column']);
+    $sub_field = end($sub_field_array);
+
+    $name = substr($column['column'], 6);
+    $field_title = $title = $base_title;
+    $field_type = $type = _content_importexportapi_map_cck_db_type($column['type']);
+    $field_already_set = TRUE;
+
+    if ($multiple_columns && !$multiple_values) {
+      $field_title .= ' ('. $sub_field .')';
+    }
+
+    if ($multiple_values) {
+      $field_name = substr($name, 0, ((strlen($name) - strlen($sub_field)) - 1));
+      $field_type = 'array';
+      $field_title .= ' (collection)';
+      $title .= ' ('. $sub_field .')';
+    }
+    else {
+      $field_name = $name;
+      $ret_field_name = substr($name, 0, ((strlen($name) - strlen($sub_field)) - 1));
+    }
+
+    if (!isset($def['revisions'][$field_name])) {
+      $def['revisions'][$field_name] = array(
+        '#type' => $field_type,
+        '#title' => $field_title
+      );
+
+      $field_already_set = FALSE;
+    }
+
+    if ($multiple_values) {
+      if (!$field_already_set) {
+        $field_name_mapping = str_replace('_', '-', $field_name);
+        $def['revisions'][$field_name]['#db_default_table'] = $database_info['table'];
+        $def['revisions'][$field_name]['#xml_plural'] = $def['revisions'][$field_name]['#csv_plural'] = $field_name_mapping .'-collection';
+        $def['revisions'][$field_name]['#xml_mapping'] = $field_name_mapping;
+      }
+
+      $def['revisions'][$field_name][$name] = array(
+        '#type' => $type,
+        '#title' => $title,
+        '#db_field_unaliased' => $column['column']
+      );
+
+      _content_importexportapi_invoke_def_references($def['revisions'][$field_name][$name], $field_info);
+    }
+    else {
+      $def['revisions'][$field_name]['#db_field_unaliased'] = $column['column'];
+      $def['revisions'][$field_name]['#db_table'] = $database_info['table'];
+
+      _content_importexportapi_invoke_def_references($def['revisions'][$field_name], $field_info);
+    }
+  }
+
+  $table_info = array(
+    'field_name' => (isset($ret_field_name) ? $ret_field_name : $field_name),
+    'multiple_values' => $multiple_values,
+    'storage_per_field' => $storage_per_field,
+    'db_table' => $database_info['table']
+  );
+
+  return array($database_info['table'] => $table_info);
+}
+
+function _content_importexportapi_map_cck_db_type($type) {
+  $new_type = $type;
+
+  switch ($type) {
+    case 'varchar':
+    case 'longtext':
+      $new_type = 'string';
+      break;
+    default:
+      break;
+  }
+
+  return $new_type;
+}
+
+function _content_importexportapi_add_parent_references(&$def, $table, $table_info, $content_type_name_system) {
+  $field_name = $table_info['field_name'];
+
+  if ($table_info['multiple_values']) {
+    $def['revisions'][$field_name]['vid'] = array(
+      '#type' => 'int',
+      '#title' => t('Revision ID'),
+      '#reference_entity' => $content_type_name_system,
+      '#reference_field' => array('revisions', 'vid'),
+      '#key_component' => TRUE
+    );
+    $def['revisions'][$field_name]['nid'] = array(
+      '#type' => 'int',
+      '#title' => t('Node ID'),
+      '#reference_entity' => $content_type_name_system
+    );
+    $def['revisions'][$field_name]['delta'] = array(
+      '#type' => 'int',
+      '#title' => t('Delta'),
+      '#key_component' => TRUE
+    );
+  }
+  else {
+    $def['revisions'][$field_name .'_vid'] = array(
+      '#type' => 'int',
+      '#title' => t('Revision ID'),
+      '#reference_entity' => $content_type_name_system,
+      '#reference_field' => array('revisions', 'vid'),
+      '#db_table' => $table_info['db_table'],
+      '#db_field_unaliased' => 'vid',
+      '#key_component' => TRUE,
+      '#csv_hidden' => TRUE
+    );
+    $def['revisions'][$field_name .'_nid'] = array(
+      '#type' => 'int',
+      '#title' => t('Node ID'),
+      '#reference_entity' => $content_type_name_system,
+      '#db_table' => $table_info['db_table'],
+      '#db_field_unaliased' => 'nid',
+      '#csv_hidden' => TRUE
+    );
+  }
+}
+
+function _content_importexportapi_invoke_def_references(&$field_def, $field_info) {
+  foreach (module_implements('content_def_references') as $module) {
+    $function = $module .'_content_def_references';
+    $function($field_def, $field_info);
+  }
+}
Index: nodereference.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/nodereference.module,v
retrieving revision 1.25.2.11
diff -u -r1.25.2.11 nodereference.module
--- nodereference.module	21 Aug 2006 03:06:45 -0000	1.25.2.11
+++ nodereference.module	25 Aug 2006 04:42:09 -0000
@@ -6,6 +6,10 @@
  * Defines a field type for referencing one node from another.
  */
 
+if (module_exist('importexportapi')) {
+  include_once(drupal_get_path('module', 'content') .'/nodereference_importexportapi.inc');
+}
+
 /**
  * Implementation of hook_help().
  */
Index: nodereference_importexportapi.inc
===================================================================
RCS file: nodereference_importexportapi.inc
diff -N nodereference_importexportapi.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ nodereference_importexportapi.inc	25 Aug 2006 04:42:09 -0000
@@ -0,0 +1,22 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implements data definitions on behalf of nodereference.module.
+ */
+
+/**
+ * Implementation of hook_content_def_references().
+ */
+function nodereference_content_def_references(&$field_def, $field_info) {
+  static $reference_delta = 1;
+
+  if ($field_info['type'] == 'nodereference') {
+    $field_def['#reference_entity'] = 'node';
+    $field_def['#reference_field'] = array('nid');
+    $field_def['#reference_delta'] = $reference_delta;
+
+    $reference_delta++;
+  }
+}
Index: userreference.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck/userreference.module,v
retrieving revision 1.22.2.9
diff -u -r1.22.2.9 userreference.module
--- userreference.module	21 Aug 2006 03:06:45 -0000	1.22.2.9
+++ userreference.module	25 Aug 2006 04:42:09 -0000
@@ -6,6 +6,10 @@
  * Defines a field type for referencing a user from a node.
  */
 
+if (module_exist('importexportapi')) {
+  include_once(drupal_get_path('module', 'content') .'/userreference_importexportapi.inc');
+}
+
 /**
  * Implementation of hook_help().
  */
Index: userreference_importexportapi.inc
===================================================================
RCS file: userreference_importexportapi.inc
diff -N userreference_importexportapi.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ userreference_importexportapi.inc	25 Aug 2006 04:42:09 -0000
@@ -0,0 +1,22 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Implements data definitions on behalf of userreference.module.
+ */
+
+/**
+ * Implementation of hook_content_def_references().
+ */
+function userreference_content_def_references(&$field_def, $field_info) {
+  static $reference_delta = 1;
+
+  if ($field_info['type'] == 'userreference') {
+    $field_def['#reference_entity'] = 'user';
+    $field_def['#reference_field'] = array('uid');
+    $field_def['#reference_delta'] = $reference_delta;
+
+    $reference_delta++;
+  }
+}
