Index: mappers/feedapi_mapper_nodereference.inc
===================================================================
RCS file: mappers/feedapi_mapper_nodereference.inc
diff -N mappers/feedapi_mapper_nodereference.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mappers/feedapi_mapper_nodereference.inc	31 Jan 2009 15:55:48 -0000
@@ -0,0 +1,47 @@
+<?php
+// $Id$
+
+/**
+ * On behalf implementation of hook_feedapi_mapper for nodereference.module (CCK).
+ *
+ * @param string $op
+ * @param Drupal node $node
+ * @param string $field_name
+ * @param string, number or array of string or number $feed_element
+ * @param string or number as id $sub_field
+ *
+ */
+function nodereference_feedapi_mapper($op, $node, $field_name, $feed_element = array(), $sub_field = '') {
+  // Test for the node field that we would like to map to.
+  if (strpos($field_name, 'field_') === 0) {
+    if ($op == 'describe') {
+      // Describe what we are doing in this mapper. This shows up as help text on the mapping page.
+      if (feedapi_mapper_content_is_cck_type($field_name, array('nodereference'))) {
+        return t('Maps a Node ID to this node reference CCK field.');
+      } 
+    }
+    else if ($op == 'list') {
+      // Here we are being asked to list sub fields we would like to map to.
+      if (feedapi_mapper_content_is_cck_type($field_name, array('nodereference'))) {
+        return TRUE;
+      }
+      return FALSE;
+    }
+    else if ($op == 'map') {
+      // Here is where the actual mapping happens.
+      // When we are called at this point, $field_name contains the name of the field the user has 
+      // decided to map to and $field_element is the feed item element the user has decided to map.
+      // We just need to put the two things together. The data structure here depends a lot on
+      // CCK. We stick the value in $feed_element into $node->$field_name[0]['value'].
+      if (!is_array($feed_element)) {
+        $cckfield = content_fields($field_name);
+        // We are checking for nodes that exactly match the string mapped to $feed_element. We 
+        // could have checked to see if it was numeric first and do something else
+        $nids = _nodereference_potential_references($cckfield, $feed_element, TRUE);
+        $field[0]['nid'] = (!empty($nids)) ? array_shift(array_keys($nids)) : 0;
+        $node->$field_name = $field;
+        return $node;
+      }
+    }
+  }
+}
