Index: nodeprofile.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodeprofile/nodeprofile.module,v
retrieving revision 1.7.2.2
diff -u -p -r1.7.2.2 nodeprofile.module
--- nodeprofile.module	25 Feb 2007 14:49:15 -0000	1.7.2.2
+++ nodeprofile.module	30 Mar 2007 17:13:12 -0000
@@ -13,20 +13,42 @@
 function nodeprofile_menu($may_cache) {
   $items = array();
 
-  if ($may_cache && module_exists('usernode')) {
-    // prevent the deletion of the usernode-ct - nodeprofile-ct relation
+  if ($may_cache) {
     $items[] = array(
-      'path' => 'admin/content/nodefamily/'. USERNODE_CONTENT_TYPE,
-      'title' => t('delete relation'),
-      'callback' => 'nodeprofile_keep_relation',
-      'access' => user_access('administer nodes'),
-      'type' => MENU_CALLBACK,
+      'path' => 'admin/user/nodeprofile',
+      'title' => t('Node profile settings'),
+      'description' => t('Configure the display and management of node profiles.'),
+      'callback' => 'drupal_get_form',
+      'callback arguments' => array('nodeprofile_admin_settings'),
+      'access' => user_access('administer users'),
     );
+    if (module_exists('usernode')) {
+      // prevent the deletion of the usernode-ct - nodeprofile-ct relation
+      $items[] = array(
+        'path' => 'admin/content/nodefamily/'. USERNODE_CONTENT_TYPE,
+        'title' => t('delete relation'),
+        'callback' => 'nodeprofile_keep_relation',
+        'access' => user_access('administer nodes'),
+        'type' => MENU_CALLBACK,
+      );
+    }
   }
   return $items;
 }
 
 /**
+ * Menu callback; node profile settings.
+ */
+function nodeprofile_admin_settings() {
+  $form['nodeprofiles_on_user_page'] = array(
+    '#type' => 'checkbox',
+    '#title' => t("Manage node profiles on user's account page."),
+    '#default_value' => !module_exists('usernode'),
+  );
+  return system_settings_form($form);
+}
+
+/**
  * Menu callback.
  * Hooks into admin/content/nodefamily/usernode which is normally handled by
  * the nodefamily module, but gets special handling here for relations that
@@ -157,6 +179,68 @@ function nodeprofile_node_settings_submi
  */
 function nodeprofile_user($op, &$edit, &$account, $category = NULL) {
   switch ($op) {
+    case 'categories':
+      if (variable_get('nodeprofiles_on_user_page', !module_exists('usernode'))) {
+        $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 (variable_get('nodeprofiles_on_user_page', !module_exists('usernode'))) {
+        $types = nodeprofile_get_types('types');
+        foreach ($types as $type) {
+          if ($category == $type->type) {
+            $nid = db_result(db_query("
+              SELECT nid
+              FROM {node}
+              WHERE type = '%s'
+              AND uid = %d
+            ", $category, $account->uid));
+            if (empty($nid)) {
+              $node = array('uid' => $account->uid, 'name' => $account->name, 'type' => $category);
+            }
+            else {
+              $node = node_load($nid);
+            }
+            $form = node_form($node);
+            _nodeprofile_alter_node_form($node, $form);
+            $form['log']['#access'] = 0;
+            $form['author']['#access'] = 0;
+            $form['options']['#access'] = 0;
+            $form['comment_settings']['#access'] = 0;
+            $form['menu']['#access'] = 0;
+            unset($form['preview']);
+            unset($form['submit']);
+            unset($form['delete']);
+            $fields[$category] = $form;
+            return $fields;
+          }
+        }
+      }
+      break;
+
+    case 'update':
+      if (variable_get('nodeprofiles_on_user_page', !module_exists('usernode'))) {
+        $types = nodeprofile_get_types('types');
+        foreach ($types as $type) {
+          if ($category == $type->type) {
+            $node = node_submit($edit);
+            unset($edit);
+            node_save($node);
+            break;
+          }
+        }
+      }
+      break;
+
     case 'delete':
       if (!module_exists('usernode')) {
         break;
@@ -197,12 +281,53 @@ function nodeprofile_user($op, &$edit, &
       }
       break;
 
+    case 'view':
+      if (variable_get('nodeprofiles_on_user_page', !module_exists('usernode'))) {
+        $types = nodeprofile_get_types('types');
+        $cond = array();
+        $arguments = array();
+        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;
+
     default:
       break;
   }
 }
 
 /**
+ * Modules cannot tell that this is a node form unless we tell them.
+ */
+function _nodeprofile_alter_node_form($node, &$form) {
+  foreach (module_implements('form_alter') as $module) {
+    $function = $module .'_form_alter';
+    $function($node->type . '_node_form', $form);
+  }
+}
+
+/**
  * The original node_delete() function uses node_load() to get the $node object.
  * Unfortunately, when a hook_user('delete') is called, node_load() doesn't
  * work anymore because the user has already been deleted, and node_load()
