Index: openid_cp_field.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/openid_cp_field/openid_cp_field.module,v
retrieving revision 1.1.2.7
diff -u -p -r1.1.2.7 openid_cp_field.module
--- openid_cp_field.module	21 Apr 2009 14:28:35 -0000	1.1.2.7
+++ openid_cp_field.module	22 Apr 2009 06:27:31 -0000
@@ -122,7 +122,7 @@ function openid_cp_field_map($form_state
     $rows[] = array('node' => $node_label, 'openid' => 'SReg: '. $sreg_fields[$openid], 'link' => l(t('Delete'), "openid_cp_field/delete/{$type['type']}/". base64_encode($openid) .'/sreg'));
   }
   if (count($rows) > 0) {
-    $current_map = theme('table', array('node' => t('Node field'), 'openid' => t('OpenID'), 'link' => t('Operation')), $rows);
+    $current_map = theme('table', array('node' => t('Node field'), 'openid' => t('OpenID field'), 'link' => t('Operation')), $rows);
   }
   if ($source == OPENID_CP_FIELD_NORMAL) {
     $source_msg = t('defined via the user interface.');
@@ -135,9 +135,8 @@ function openid_cp_field_map($form_state
   }
   $form['current_map'] = array(
     '#type' => 'fieldset',
-    '#title' => t('The currently defined relationships'),
-    '#collapsible' => TRUE,
-    '#collapsed' => count($rows) > 0 ? FALSE : TRUE,
+    '#title' => t('Mappings'),
+    '#collapsible' => FALSE,
     '#description' => t('The source of the current mapping is: !source', array('!source' => $source_msg)),
   );
   $form['current_map']['map'] = array(
@@ -151,10 +150,10 @@ function openid_cp_field_map($form_state
   }
   $form['map'] = array(
     '#type' => 'fieldset',
-    '#title' => t('Define a relationship between OpenID attributes and CCK fields'),
+    '#title' => t('Map node fields to OpenID attributes'),
   );
   if (count($options_node) == 0 || (count($openid_attrs) == 0 && count($openid_sreg_fields) == 0)) {
-    $form['map']['info'] = array('#value' => t('No more fields to map, please delete a relationship if you want to modify the current mapping.'));
+    $form['map']['info'] = array('#value' => t('No more fields to map. Please delete a relationship to modify current mapping.'));
   }
   else {
     drupal_add_css(drupal_get_path('module', 'openid_cp_field') ."/openid_cp_field.css", "module");
@@ -172,6 +171,7 @@ function openid_cp_field_map($form_state
       '#type' => 'submit',
       '#value' => t('Add'),
     );
+    $form['map']['#description'] = t('AX prefixed attributes follows the attribute exchange specification from axschema.org and they are compatible with the sites using the same set of attributes. SReg prefixed attributes are more widely supported but there are only a very limited number of attributes.');
   }
   $form['type'] = array(
       '#type' => 'value',
@@ -274,12 +274,71 @@ function openid_cp_field_openid_provider
 }
 
 /**
+ * Implementation of hook_openid_client_ax()
+ */
+function openid_cp_field_openid_client_ax($op, $response = NULL, $account = NULL) {
+  if ($op == 'get') {
+    $mapping = array();
+    openid_cp_field_get_mapping($mapping);
+    return array_keys($mapping);
+  }
+  if ($op == 'save') {
+    $mapping = array();
+    openid_cp_field_get_mapping($mapping);
+    if (empty($mapping)) {
+      return;
+    }
+    $types = content_profile_get_types('names');
+    foreach ($types as $type => $value) {
+      break;
+    }
+    // If there is a saved profile actually, do nothing
+    if (db_result(db_query("SELECT COUNT(*) FROM {node} WHERE uid = %d AND type = '%s'", $account->uid, $type)) > 0) {
+      return;
+    }
+    $profile = new StdClass();
+    $profile->uid = $account->uid;
+    $profile->type = $type;
+    $matched_attribute = 0;
+    foreach ($mapping as $openid => $node) {
+      $short_name = array_pop(explode('/', $openid));
+      if (isset($response['openid.ax.value.'. $short_name])) {
+        $field_value = $response['openid.ax.value.'. $short_name];
+        if (!empty($field_value)) {
+          $matched_attribute++;
+          $profile->$node = array();
+          // Check if it's a CCK field or not
+          if (strstr($node, 'field_') && module_exists('content_profile')) {
+            $profile->{$node}[0]['value'] = $field_value;
+          }
+          else {
+            $profile->{$node} = $field_value;
+          }
+        }
+      }
+    }
+    if (!isset($profile->title)) {
+      $profile->title = $account->name;
+    }
+    // Only creates the profile when it has some data from the provider part
+    if ($matched_attribute > 0) {
+      $profile = node_submit($profile);
+      // Since we utilize autonodetitle for the titles have added this to update the node title
+      // If the module auto_nodetitle exists in the system.
+      if (module_exists('auto_nodetitle')) {
+        auto_nodetitle_set_title($profile);
+      }
+      node_save($profile);
+    }
+  }
+}
+
+/**
  * Implementation of hook_openid_provider_ax()
  */
 function openid_cp_field_openid_provider_ax($op, $attributes) {
   if ($op == 'load') {
     $response = array();
-    $fields = array();
     $short_names = array();
     if (isset($attributes['openid.ax.if_available'])) {
       $short_names += explode(',', $attributes['openid.ax.if_available']);
