Index: nodeprofile.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/nodeprofile.module,v
retrieving revision 1.7.2.2
diff -u -r1.7.2.2 nodeprofile.module
--- nodeprofile.module	25 Feb 2007 14:49:15 -0000	1.7.2.2
+++ nodeprofile.module	28 Mar 2007 16:15:03 -0000
@@ -157,18 +157,48 @@
  */
 function nodeprofile_user($op, &$edit, &$account, $category = NULL) {
   switch ($op) {
-    case 'delete':
-      if (!module_exists('usernode')) {
-        break;
+    case 'categories':
+      if (nodeprofile_core_profile_setting()) {
+        $types = nodeprofile_get_types('types');
+        foreach ($types as $type) {
+          $data[] = array(
+            'name' => $type->type,
+            'title' => $type->name,
+            'weight' => 3
+          );
+        }
+        return $data;
+      }
+      break;
+    case 'form':
+      if (nodeprofile_core_profile_setting() && is_nodeprofile($category)) {
+        $type = $category;
+        $node = node_load(array('type' => $type, 'uid' => $account->uid));
+        if (!$node) {
+          $node = array('uid' => $account->uid, 'name' => $account->name, 'type' => $type);
+        }
+        $fields[$category] = node_form($node);
+        unset($fields[$category]['preview']);
+        unset($fields[$category]['submit']);
+        unset($fields[$category]['delete']);
+        return $fields;
       }
+      break;
+    case 'update':
+      if (nodeprofile_core_profile_setting() && is_nodeprofile($category)) {
+        $type = $category;
+        $node = node_submit($edit);
+        unset($edit);
+        node_save($node);
+      }
+      break;
 
+    case 'delete':
       // retrieve profile node types to be deleted
       $typenames = array();
-      foreach (node_get_types('names') as $typename => $visiblename) {
-        if (is_nodeprofile($typename)) {
-          $typenames[] = $typename;
-          $typenames = array_merge($typenames, nodefamily_get_descendant_types($typename));
-        }
+      foreach (nodeprofile_get_types('names') as $typename => $visiblename) {
+        $typenames[] = $typename;
+        $typenames = array_merge($typenames, nodefamily_get_descendant_types($typename));
       }
 
       // Retrieve the matching profile nodes for this user by issueing an SQL
@@ -176,7 +206,6 @@
       // the user to be in the {user} table, which is not the case anymore.
       // That node_load() doesn't work also means that node_delete() doesn't
       // work, which is why we have to use _nodeprofile_node_delete() instead.
-
       $cond = array();
       $arguments = array();
 
@@ -188,16 +217,35 @@
       $arguments[] = $account->uid;
 
       if ($cond) {
-        $result = db_query("SELECT * FROM {node} WHERE (". $cond .") ".
-                           "AND uid = %d", $arguments);
-
+        $result = db_query("SELECT * FROM {node} WHERE (". $cond .") AND uid = %d", $arguments);
         while ($node = db_fetch_object($result)) {
           _nodeprofile_node_delete($node);
         }
       }
       break;
 
-    default:
+    case 'view':
+      if (nodeprofile_core_profile_setting()) {
+        $types = nodeprofile_get_types('types');
+        foreach ($types as $type) {
+          $cond[] = "type = '%s'";
+          $arguments[] = $type->type;
+        }
+        $cond = implode(' OR ', $cond);
+        $arguments[] = $account->uid;
+        if ($cond) {
+          $result = db_query("SELECT nid, type FROM {node} WHERE  (". $cond .") AND uid = %d", $arguments);
+          while ($node = db_fetch_object($result)) {
+            $type = node_get_types('name', $node->type);
+            $fields[$type]['nodeprofile'] = array(
+              'title' => NULL,
+              'value' => node_view(node_load($node->nid)),
+              'class' => $type->type,
+            );
+          }
+        }
+        return $fields;
+      }
       break;
   }
 }
@@ -252,3 +300,11 @@
   drupal_set_message(t('%title has been deleted.', array('%title' => $node->title)));
   watchdog('content', t('@type: deleted %title.', array('@type' => t($node->type), '%title' => $node->title)));
 }
+
+
+/*
+ * Returns the setting for the nodeprofile core profile integration
+ */
+function nodeprofile_core_profile_setting() {
+  return variable_get('nodeprofile_core_profile', !module_exists('usernode'));
+}
\ No newline at end of file
