Index: mappers/og.inc
===================================================================
RCS file: mappers/og.inc
diff -N mappers/og.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mappers/og.inc	19 Jul 2010 00:01:00 -0000
@@ -0,0 +1,88 @@
+<?php
+
+/**
+ * @file
+ * On behalf implementation of Feeds mapping API for organic groups.
+ */
+
+/**
+ * Implementation of hook_feeds_node_processor_targets_alter().
+ *
+ * @see FeedsNodeProcessor::getMappingTargets().
+ */
+function og_feeds_node_processor_targets_alter(&$targets, $content_type) {
+  $fields = array();
+  if (!og_is_omitted_type($content_type)) {
+    $fields['spaces_og_audience'] = 'Spaces OG Group';
+    $fields['og_groups'] = 'OG Group';
+  }
+  foreach ($fields as $k => $name) {
+    $targets[$k] = array(
+      'name' => $name,
+      'callback' => "og_feeds_set_target",
+      'description' => t('The !name of the node.', array('!name' => $name)),
+    );
+  }
+}
+
+/**
+ * Implementation of hook_feeds_set_target().
+ *
+ * @param $node
+ *   The target node.
+ * @param $target
+ *   The name of field on the target node to map to.
+ * @param $value
+ *   The value to be mapped.
+ *
+ */
+function og_feeds_set_target($node, $target, $value) {
+  $field = isset($node->$target) ? $node->$target : array();
+
+  if (!is_array($value)) {
+    $value = array($value);
+  }
+
+  foreach ($value as $v) {
+    if (!is_array($v) && !is_object($v)) {
+      // Return list of possible exact matches for the title
+      $nids = _og_feeds_potential_references($v, 'equals', 1);
+      
+      // Use the first element of the returned array
+      switch($target) {
+        case 'og_groups':
+          $field[] = array(key($nids) => key($nids));
+          break;
+        case 'spaces_og_audience':
+          $field = key($nids);
+          break;
+      }
+    }
+  }
+
+  $node->$target = $field;
+}
+
+function _og_feeds_potential_references($value, $test = 'equals', $limit = NULL) {
+  switch($test) {
+    case 'equals':
+      $where_clause = " WHERE n.title = '%s'";
+      break;
+    default:
+      $where_clause = NULL;
+      break;
+  }    
+  $args[] = $value;
+
+  $sql = db_rewrite_sql("SELECT n.nid, n.title AS node_title, n.type AS node_type FROM {node} n $where_clause");
+  $result = $limit ? db_query_range($sql, $args, 0, $limit) : db_query($sql, $args);
+  $references = array();
+  while ($node = db_fetch_object($result)) {
+    $references[$node->nid] = array(
+      'title' => $node->node_title,
+      'rendered' => check_plain($node->node_title),
+    );
+  }
+
+  return $references;
+}
\ No newline at end of file
