Index: cck_import.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/cck_import/cck_import.module,v
retrieving revision 1.1
diff -u -p -r1.1 cck_import.module
--- cck_import.module	8 Jun 2009 20:36:45 -0000	1.1
+++ cck_import.module	18 Nov 2009 20:26:27 -0000
@@ -1,2 +1,70 @@
 <?php
 // $Id: cck_import.module,v 1.1 2009/06/08 20:36:45 psynaptic Exp $
+
+/**
+ * Allow other modules to import cck node types
+ *
+ * @param   $file_name - The name of the file with CCK export data, either an
+ * absolute path or a path relative to the drupal root.
+ */
+function cck_import_custom_type($file_name) {
+  // make sure we don't time out when importing
+  if (function_exists('set_time_limit')) {
+    @set_time_limit(0);
+  }
+
+  //include required files
+  include_once './'. drupal_get_path('module', 'node') .'/content_types.inc';
+  include_once('./'. drupal_get_path('module', 'content_copy') .'/content_copy.module');
+
+  $export_data = file_get_contents($file_name);
+  @eval($export_data);
+
+  if (db_table_exists('content_type_'. $content['type']['type'])) {
+    drupal_set_message(t('Content type already exists for $type.', array('$type' => $content['type']['name'])));
+  }
+  else {
+    // with some more complicated node types I had to create the node type first
+    // before importing the fields
+    $type = array(
+      'type' => $content['type']['type'],
+      'name' => $content['type']['name'],
+      'module' => 'node',
+      'description' => $content['type']['description'],
+      'has_title' => $content['type']['title_label'] ? 1 : 0,
+      'title_label' => $content['type']['title_label'],
+      'has_body' => $content['type']['body_label'] ? 1 : 0,
+      'body_label' => $content['type']['body_label'],
+      'min_word_count' => $content['type']['min_word_count'],
+      'custom' => $content['type']['custom'],
+      'modified' => $content['type']['modified'],
+      'locked' => $content['type']['locked'],
+      'orig_type' => $content['type']['type'],
+    );
+    $flag = node_type_save((object)$type);
+    if ($flag) {
+      drupal_set_message(t('Node type @type added successfully', array('@type' => $type_name)));
+    }
+    else {
+      drupal_set_message(t('Node type @type could not be added. Please check your error log and try again.', array('@type' => $type_name)));
+      return;
+    }
+  }
+  // convert back to string representation of macro
+  $typestr  = var_export($content['type'], true);
+  $groupsstr = var_export($content['groups'], true);
+  $fieldsstr = var_export($content['fields'], true); 
+
+  $values['type_name'] = $content['type']['type'];
+  $values['macro'] = <<<CONTENT
+  \$content['type'] = $typestr;
+  \$content['groups'] = $groupsstr;
+  \$content['fields'] = $fieldsstr;
+CONTENT;
+
+  $form_state = array(
+    'values' => $values,
+  );
+  // import CCK fields
+  drupal_execute('content_copy_import_form', $form_state);
+}
\ No newline at end of file
