Index: mappers/nodereference.inc
===================================================================
RCS file: mappers/nodereference.inc
diff -N mappers/nodereference.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mappers/nodereference.inc	25 Feb 2010 18:11:40 -0000
@@ -0,0 +1,69 @@
+<?php
+// $Id: nodereference.inc,v 0.1 2012/02/25 16:38:10 katsikas Exp $
+
+/**
+ * @file
+ * On behalf implementation of Feeds mapping API for nodereference.module (CCK).
+ */
+
+/**
+ * Implementation of hook_feeds_node_processor_targets_alter().
+ *
+ * @see FeedsNodeProcessor::getMappingTargets().
+ */
+function nodereference_feeds_node_processor_targets_alter(&$targets, $content_type) {
+  $info = content_types($content_type);
+  $fields = array();
+  if (isset($info['fields']) && count($info['fields'])) {
+    foreach ($info['fields'] as $field_name => $field) {
+      if (in_array($field['type'], array('nodereference'))) {
+        $fields[$field_name] = isset($field['widget']['label']) ? $field['widget']['label'] : $field_name;
+      }
+    }
+  }
+  foreach ($fields as $k => $name) {
+    $targets[$k] = array(
+      'name' => $name,
+      'callback' => 'nodereference_feeds_set_target',
+      'description' => t('The CCK Node Reference !name of the node.', array('!name' => $name)),
+    );
+  }
+}
+/**
+ * Callback for mapping. Here is where the actual mapping happens.
+ *
+ * When the callback is invoked, $target contains the name of the field the
+ * user has decided to map to and $value contains the value of the feed item
+ * element the user has picked as a source.
+ */
+function nodereference_feeds_set_target($node, $target, $value) {
+	$field = isset($node->$target) ? $node->$target : array();
+	
+	  // Handle multiple value fields.
+	  if (is_array($value)) {
+	    $i = 0;
+	    foreach ($value as $v) {
+	      if (!is_array($v) && !is_object($v)) {
+	      	$nids = nodereference_get_nid_by_title($value);
+	        $field[$i]['nid'] = $nids[0];
+	      }
+	      $i++;
+	    }
+	  }
+	  else {
+	    $nids = nodereference_get_nid_by_title($value);
+	    $field[0]['nid'] = $nids[0];
+	  }
+	
+	  $node->$target = $field;
+	
+}
+
+function nodereference_get_nid_by_title($value) {
+  $result = db_query(db_rewrite_sql("SELECT n.nid, n.title AS node_title FROM {node} n WHERE n.title = '%s'", 't'),$value);
+  $references = array();
+  while ($node = db_fetch_object($result)) {
+    $references[] = $node->nid;
+  }
+  return $references;
+}
\ No newline at end of file
