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.14
diff -u -p -r1.1.2.14 openid_cp_field.module
--- openid_cp_field.module	29 Jun 2009 13:02:14 -0000	1.1.2.14
+++ openid_cp_field.module	30 Jun 2009 09:25:25 -0000
@@ -56,6 +56,22 @@ function openid_cp_field_menu() {
 }
 
 /**
+ * Implementation of hook_nodeapi().
+ */
+function openid_cp_field_nodeapi(&$node, $op, $teaser, $page) {
+  switch ($op) {
+    case 'update':
+      if (module_exists('openid_provider_ax')) {
+        $profile_types = array_keys(content_profile_get_types('names'));
+        if (in_array($node->type, $profile_types)) {
+          module_invoke('openid_provider', 'update', $node->uid);
+        }
+      }
+      break;
+  }
+}
+
+/**
  * Form of the mapping, map CCK fields to ax schema attributes
  */
 function openid_cp_field_map($form_state, $type) {
@@ -277,7 +293,7 @@ function openid_cp_field_openid_provider
 /**
  * Implementation of hook_openid_provider_ax()
  */
-function openid_cp_field_openid_provider_ax($op, $attributes) {
+function openid_cp_field_openid_provider_ax($op, $attributes, $uid = FALSE) {
   if ($op == 'load') {
     $response = array();
     $short_names = array();
@@ -290,7 +306,7 @@ function openid_cp_field_openid_provider
     foreach ($short_names as $key) {
       // Get the full URL
       $full_url = $attributes['openid.ax.type.'. $key];
-      $value = _openid_cp_field_get_value($full_url);
+      $value = _openid_cp_field_get_value($full_url, $uid);
       if (!empty($value)) {
         $response['openid.ax.value.'. $key] = $value;
       }
@@ -384,33 +400,48 @@ function openid_cp_field_get_mapping(&$m
 }
 
 /**
+ * Assigns a profile node to the user
+ * 
+ * @param $uid
+ *   User id
+ * @return
+ *   Node object of the profile
+ */
+function openid_cp_field_assign_profile($uid) {
+  static $user_type = array();
+  if (isset($user_type[$uid])) {
+    return $user_type[$uid];
+  }
+  $types = array_keys(content_profile_get_types('names'));
+  foreach ($types as $type) {
+    $profile = content_profile_load($type, $uid);
+    if ($profile !== FALSE) {
+      $user_type[$uid] = $profile;
+      break;
+    }
+  }
+  $user_type[$uid] = isset($user_type[$uid]) ? $user_type[$uid] : FALSE;
+  return $user_type[$uid];
+}
+
+/**
  * Utility function to retrieve the value for the field if all permissions checks pass
  *
  * @param $field
  *      Field we are looking for i.e. ((http://axschema.org/contact/email) or (openid.sreg.email)
  *      Depends on whether AX or Sreg is being used
  */
-function _openid_cp_field_get_value($field) {
+function _openid_cp_field_get_value($field, $uid = FALSE) {
   global $user;
-  static $user_type = array();
   static $mapping = array();
   
-  $appendix = strstr($field, '.sreg.') && !strstr($field, 'axschema.org') ? '_sreg' : '';
-
-  if (!isset($user_type[$user->uid]))  {
-    $types = array_keys(content_profile_get_types('names'));
-    foreach ($types as $type) {
-      $profile = content_profile_load($type, $user->uid);
-      if ($profile !== FALSE) {
-        $user_type[$user->uid] = $profile;
-        break;
-      }
-    }
-  }
-  else {
-    $profile = $user_type[$user->uid];
-    $type = $profile->type;
+  if ($uid == FALSE) {
+    $uid = $user->uid;
   }
+  
+  $appendix = strstr($field, '.sreg.') && !strstr($field, 'axschema.org') ? '_sreg' : '';
+  $profile = openid_cp_field_assign_profile($uid);
+  $type = $profile->type;
 
   $type .= $appendix;
   if (count($mapping) == 0) {
