Commit 144624 by dries

- Patch #310212 by justinrandell, catch, et all: killed in _user hook, as well as two small kittens.

--- modules/block/block.module	2008/09/27 19:47:42	1.310
+++ modules/block/block.module	2008/10/06 11:30:10	1.311
@@ -335,38 +335,35 @@
 }
 /**
- * Implementation of hook_user().
- *
- * Allow users to decide which custom blocks to display when they visit
- * the site.
+ * Implementation of hook_user_form().
  */
-function block_user($type, $edit, &$account, $category = NULL) {
-  switch ($type) {
-    case 'form':
-      if ($category == 'account') {
-        $rids = array_keys($account->roles);
-        $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL) ORDER BY b.weight, b.module", $rids);
-        $form['block'] = array('#type' => 'fieldset', '#title' => t('Block configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE);
-        while ($block = db_fetch_object($result)) {
-          $data = module_invoke($block->module, 'block', 'list');
-          if ($data[$block->delta]['info']) {
-            $return = TRUE;
-            $form['block'][$block->module][$block->delta] = array('#type' => 'checkbox', '#title' => check_plain($data[$block->delta]['info']), '#default_value' => isset($account->block[$block->module][$block->delta]) ? $account->block[$block->module][$block->delta] : ($block->custom == 1));
-          }
-        }
-
-        if (!empty($return)) {
-          return $form;
-        }
+function block_user_form(&$edit, &$account, $category = NULL) {
+  if ($category == 'account') {
+    $rids = array_keys($account->roles);
+    $result = db_query("SELECT DISTINCT b.* FROM {blocks} b LEFT JOIN {blocks_roles} r ON b.module = r.module AND b.delta = r.delta WHERE b.status = 1 AND b.custom != 0 AND (r.rid IN (" . db_placeholders($rids) . ") OR r.rid IS NULL) ORDER BY b.weight, b.module", $rids);
+    $form['block'] = array('#type' => 'fieldset', '#title' => t('Block configuration'), '#weight' => 3, '#collapsible' => TRUE, '#tree' => TRUE);
+    while ($block = db_fetch_object($result)) {
+      $data = module_invoke($block->module, 'block', 'list');
+      if ($data[$block->delta]['info']) {
+        $return = TRUE;
+        $form['block'][$block->module][$block->delta] = array('#type' => 'checkbox', '#title' => check_plain($data[$block->delta]['info']), '#default_value' => isset($account->block[$block->module][$block->delta]) ? $account->block[$block->module][$block->delta] : ($block->custom == 1));
       }
+    }
-      break;
-    case 'validate':
-      if (empty($edit['block'])) {
-        $edit['block'] = array();
-      }
-      return $edit;
+    if (!empty($return)) {
+      return $form;
+    }
+  }
+}
+
+/**
+ * Implementation of hook_user_validate().
+ */
+function block_user_validate(&$edit, &$account, $category = NULL) {
+  if (empty($edit['block'])) {
+    $edit['block'] = array();
   }
+  return $edit;
 }
 /**
--- modules/blog/blog.module	2008/07/22 20:00:55	1.309
+++ modules/blog/blog.module	2008/10/06 11:30:11	1.310
@@ -42,10 +42,10 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_view().
  */
-function blog_user($type, &$edit, &$user) {
-  if ($type == 'view' && user_access('create blog content', $user)) {
+function blog_user_view(&$edit, &$user, $category) {
+  if (user_access('create blog content', $user)) {
     $user->content['summary']['blog'] =  array(
       '#type' => 'user_profile_item',
       '#title' => t('Blog'),
--- modules/comment/comment.module	2008/09/27 20:37:00	1.652
+++ modules/comment/comment.module	2008/10/06 11:30:11	1.653
@@ -600,13 +600,11 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_delete().
  */
-function comment_user($type, $edit, &$user, $category = NULL) {
-  if ($type == 'delete') {
-    db_query('UPDATE {comments} SET uid = 0 WHERE uid = %d', $user->uid);
-    db_query('UPDATE {node_comment_statistics} SET last_comment_uid = 0 WHERE last_comment_uid = %d', $user->uid);
-  }
+function comment_user_delete(&$edit, &$user, $category = NULL) {
+  db_query('UPDATE {comments} SET uid = 0 WHERE uid = %d', $user->uid);
+  db_query('UPDATE {node_comment_statistics} SET last_comment_uid = 0 WHERE last_comment_uid = %d', $user->uid);
 }
 /**
--- modules/contact/contact.module	2008/09/17 20:37:32	1.109
+++ modules/contact/contact.module	2008/10/06 11:30:11	1.110
@@ -130,12 +130,10 @@
 }
 /**
- * Implementation of hook_user().
- *
- * Allows the user the option of enabling/disabling his personal contact form.
+ * Implementation of hook_user_form().
  */
-function contact_user($type, &$edit, &$user, $category = NULL) {
-  if ($type == 'form' && $category == 'account') {
+function contact_user_form(&$edit, &$user, $category = NULL) {
+  if ($category == 'account') {
     $form['contact'] = array('#type' => 'fieldset',
       '#title' => t('Contact settings'),
       '#weight' => 5,
@@ -148,12 +146,20 @@
     );
     return $form;
   }
-  elseif ($type == 'validate') {
-    return array('contact' => isset($edit['contact']) ? $edit['contact'] : FALSE);
-  }
-  elseif ($type == 'insert') {
-    $edit['contact'] = variable_get('contact_default_status', 1);
-  }
+}
+
+/**
+ * Implementation of hook_user_insert().
+ */
+function contact_user_insert(&$edit, &$user, $category = NULL) {
+  $edit['contact'] = variable_get('contact_default_status', 1);
+}
+
+/**
+ * Implementation of hook_user_validate().
+ */
+function contact_user_validate(&$edit, &$user, $category = NULL) {
+  return array('contact' => isset($edit['contact']) ? $edit['contact'] : FALSE);
 }
 /**
--- modules/dblog/dblog.module	2008/08/21 19:36:37	1.27
+++ modules/dblog/dblog.module	2008/10/06 11:30:11	1.28
@@ -101,12 +101,10 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_delete().
  */
-function dblog_user($op, &$edit, &$user) {
-  if ($op == 'delete') {
-    db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
-  }
+function dblog_user_delete(&$edit, &$user) {
+  db_query('UPDATE {watchdog} SET uid = 0 WHERE uid = %d', $user->uid);
 }
 function _dblog_get_message_types() {
--- modules/locale/locale.module	2008/10/02 13:11:34	1.225
+++ modules/locale/locale.module	2008/10/06 11:30:11	1.226
@@ -206,42 +206,56 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_register().
  */
-function locale_user($type, $edit, &$user, $category = NULL) {
-  global $language;
+function locale_user_register(&$edit, &$user, $category = NULL) {
+  // If we have more then one language and either creating a user on the
+  // admin interface or edit the user, show the language selector.
+  if (variable_get('language_count', 1) > 1 && user_access('administer users')) {
+    return locale_language_selector_form($user);
+  }
+}
+/**
+ * Implementation of hook_user_form().
+ */
+function locale_user_form(&$edit, &$user, $category = NULL) {
   // If we have more then one language and either creating a user on the
   // admin interface or edit the user, show the language selector.
-  if (variable_get('language_count', 1) > 1 && ($type == 'register' && user_access('administer users') || $type == 'form' && $category == 'account' )) {
-    $languages = language_list('enabled');
-    $languages = $languages[1];
+  if (variable_get('language_count', 1) > 1 && $category == 'account') {
+    return locale_language_selector_form($user);
+  }
+}
+
+function locale_language_selector_form($user) {
+  global $language;
+  $languages = language_list('enabled');
+  $languages = $languages[1];
-    // If the user is being created, we set the user language to the page language.
-    $user_preferred_language = $user ? user_preferred_language($user) : $language;
+  // If the user is being created, we set the user language to the page language.
+  $user_preferred_language = $user ? user_preferred_language($user) : $language;
-    $names = array();
-    foreach ($languages as $langcode => $item) {
-      $name = t($item->name);
-      $names[$langcode] = $name . ($item->native != $name ? ' (' . $item->native . ')' : '');
-    }
-    $form['locale'] = array(
-      '#type' => 'fieldset',
-      '#title' => t('Language settings'),
-      '#weight' => 1,
-    );
-
-    // Get language negotiation settings.
-    $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
-    $form['locale']['language'] = array(
-      '#type' => (count($names) <= 5 ? 'radios' : 'select'),
-      '#title' => t('Language'),
-      '#default_value' => $user_preferred_language->language,
-      '#options' => $names,
-      '#description' => ($mode == LANGUAGE_NEGOTIATION_PATH) ? t("This account's default language for e-mails, and preferred language for site presentation.") : t("This account's default language for e-mails."),
-    );
-    return $form;
-  }
+  $names = array();
+  foreach ($languages as $langcode => $item) {
+    $name = t($item->name);
+    $names[$langcode] = $name . ($item->native != $name ? ' (' . $item->native . ')' : '');
+  }
+  $form['locale'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Language settings'),
+    '#weight' => 1,
+  );
+
+  // Get language negotiation settings.
+  $mode = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE);
+  $form['locale']['language'] = array(
+    '#type' => (count($names) <= 5 ? 'radios' : 'select'),
+    '#title' => t('Language'),
+    '#default_value' => $user_preferred_language->language,
+    '#options' => $names,
+    '#description' => ($mode == LANGUAGE_NEGOTIATION_PATH) ? t("This account's default language for e-mails, and preferred language for site presentation.") : t("This account's default language for e-mails."),
+  );
+  return $form;
 }
 /**
--- modules/node/node.module	2008/09/27 19:47:43	1.978
+++ modules/node/node.module	2008/10/06 11:30:11	1.979
@@ -1379,13 +1379,11 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_delete().
  */
-function node_user($op, &$edit, &$user) {
-  if ($op == 'delete') {
-    db_query('UPDATE {node} SET uid = 0 WHERE uid = %d', $user->uid);
-    db_query('UPDATE {node_revisions} SET uid = 0 WHERE uid = %d', $user->uid);
-  }
+function node_user_delete(&$edit, &$user) {
+  db_query('UPDATE {node} SET uid = 0 WHERE uid = %d', $user->uid);
+  db_query('UPDATE {node_revisions} SET uid = 0 WHERE uid = %d', $user->uid);
 }
 /**
--- modules/openid/openid.module	2008/09/17 07:11:57	1.29
+++ modules/openid/openid.module	2008/10/06 11:30:11	1.30
@@ -26,7 +26,7 @@
   );
   $items['user/%user/openid/delete'] = array(
     'title' => 'Delete OpenID',
-    'page callback' => 'openid_user_delete',
+    'page callback' => 'openid_delete_user',
     'page arguments' => array(1),
     'access callback' => 'user_edit_access',
     'access arguments' => array(1),
@@ -58,10 +58,10 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_insert().
  */
-function openid_user($op, &$edit, &$account, $category = NULL) {
-  if ($op == 'insert' && isset($_SESSION['openid']['values'])) {
+function openid_user_insert(&$edit, &$account, $category = NULL) {
+  if (isset($_SESSION['openid']['values'])) {
     // The user has registered after trying to login via OpenID.
     if (variable_get('user_email_verification', TRUE)) {
       drupal_set_message(t('Once you have verified your email address, you may log in via OpenID.'));
--- modules/openid/openid.pages.inc	2008/04/14 17:48:38	1.6
+++ modules/openid/openid.pages.inc	2008/10/06 11:30:11	1.7
@@ -82,7 +82,7 @@
 /**
  * Menu callback; Delete the specified OpenID identity from the system.
  */
-function openid_user_delete($account, $aid = 0) {
+function openid_delete_user($account, $aid = 0) {
   db_query("DELETE FROM {authmap} WHERE uid=%d AND aid=%d AND module='openid'", $account->uid, $aid);
   if (db_affected_rows()) {
     drupal_set_message(t('OpenID deleted.'));
--- modules/poll/poll.module	2008/09/17 07:11:57	1.272
+++ modules/poll/poll.module	2008/10/06 11:30:11	1.273
@@ -823,10 +823,9 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_delete().
  */
-function poll_user($op, &$edit, &$user) {
-  if ($op == 'delete') {
-    db_query('UPDATE {poll_votes} SET uid = 0 WHERE uid = %d', $user->uid);
-  }
+function poll_user_delete(&$edit, &$user) {
+  db_query('UPDATE {poll_votes} SET uid = 0 WHERE uid = %d', $user->uid);
 }
+
--- modules/profile/profile.module	2008/09/05 09:25:52	1.244
+++ modules/profile/profile.module	2008/10/06 11:30:12	1.245
@@ -194,29 +194,66 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_load().
  */
-function profile_user($type, &$edit, &$user, $category = NULL) {
-  switch ($type) {
-    case 'load':
-      return profile_load_profile($user);
-    case 'register':
-      return profile_form_profile($edit, $user, $category, TRUE);
-    case 'update':
-    return profile_save_profile($edit, $user, $category);
-    case 'insert':
-      return profile_save_profile($edit, $user, $category, TRUE);
-    case 'view':
-      return profile_view_profile($user);
-    case 'form':
-      return profile_form_profile($edit, $user, $category);
-    case 'validate':
-      return profile_validate_profile($edit, $category);
-    case 'categories':
-      return profile_categories();
-    case 'delete':
-      db_query('DELETE FROM {profile_values} WHERE uid = %d', $user->uid);
-  }
+function profile_user_load(&$edit, &$user, $category = NULL) {
+  return profile_load_profile($user);
+}
+
+/**
+ * Implementation of hook_user_register().
+ */
+function profile_user_register(&$edit, &$user, $category = NULL) {
+  return profile_form_profile($edit, $user, $category, TRUE);
+}
+
+/**
+ * Implementation of hook_user_update().
+ */
+function profile_user_update(&$edit, &$user, $category = NULL) {
+  return profile_save_profile($edit, $user, $category);
+}
+
+/**
+ * Implementation of hook_user_insert().
+ */
+function profile_user_insert(&$edit, &$user, $category = NULL) {
+  return profile_save_profile($edit, $user, $category, TRUE);
+}
+
+/**
+ * Implementation of hook_user_view().
+ */
+function profile_user_view(&$edit, &$user, $category = NULL) {
+  return profile_view_profile($user);
+}
+
+/**
+ * Implementation of hook_user_form().
+ */
+function profile_user_form(&$edit, &$user, $category = NULL) {
+  return profile_form_profile($edit, $user, $category);
+}
+
+/**
+ * Implementation of hook_user_validate().
+ */
+function profile_user_validate(&$edit, &$user, $category = NULL) {
+  return profile_validate_profile($edit, $category);
+}
+
+/**
+ * Implementation of hook_user_categories().
+ */
+function profile_user_categories(&$edit, &$user, $category = NULL) {
+  return profile_categories();
+}
+
+/**
+ * Implementation of hook_user_delete().
+ */
+function profile_user_delete(&$edit, &$user, $category = NULL) {
+  db_query('DELETE FROM {profile_values} WHERE uid = %d', $user->uid);
 }
 function profile_load_profile(&$user) {
--- modules/statistics/statistics.module	2008/09/17 07:11:58	1.283
+++ modules/statistics/statistics.module	2008/10/06 11:30:12	1.284
@@ -174,12 +174,10 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_delete().
  */
-function statistics_user($op, &$edit, &$user) {
-  if ($op == 'delete') {
-    db_query('UPDATE {accesslog} SET uid = 0 WHERE uid = %d', $user->uid);
-  }
+function statistics_user_delete(&$edit, &$user, $category) {
+  db_query('UPDATE {accesslog} SET uid = 0 WHERE uid = %d', $user->uid);
 }
 /**
--- modules/system/system.module	2008/09/27 19:47:43	1.624
+++ modules/system/system.module	2008/10/06 11:30:12	1.625
@@ -711,12 +711,10 @@
 }
 /**
- * Implementation of hook_user().
- *
- * Allows users to individually set their theme and time zone.
+ * Implementation of hook_user_form().
  */
-function system_user($type, $edit, &$user, $category = NULL) {
-  if ($type == 'form' && $category == 'account') {
+function system_user_form(&$edit, &$user, $category = NULL) {
+  if ($category == 'account') {
     $form['theme_select'] = system_theme_select_form(t('Selecting a different theme will change the look and feel of the site.'), isset($edit['theme']) ? $edit['theme'] : NULL, 2);
     if (variable_get('configurable_timezones', 1)) {
--- modules/trigger/trigger.module	2008/08/21 19:36:38	1.18
+++ modules/trigger/trigger.module	2008/10/06 11:30:12	1.19
@@ -347,9 +347,53 @@
 }
 /**
- * Implementation of hook_user().
+ * trigger_user_login 
  */
-function trigger_user($op, &$edit, &$account, $category = NULL) {
+function trigger_user_login(&$edit, &$account, $category) {
+  _trigger_user('login', $edit, $account, $category); 
+}
+
+/**
+ * Implementation of hook_user_logout().
+ */
+function trigger_user_logout(&$edit, &$account, $category) {
+  _trigger_user('logout', $edit, $account, $category); 
+}
+
+/**
+ * Implementation of hook_user_insert().
+ */
+function trigger_user_insert(&$edit, &$account, $category) {
+  _trigger_user('insert', $edit, $account, $category); 
+}
+
+/**
+ * Implementation of hook_user_update().
+ */
+function trigger_user_update(&$edit, &$account, $category) {
+  _trigger_user('update', $edit, $account, $category); 
+}
+
+/**
+ * Implementation of hook_user_delete().
+ */
+function trigger_user_delete(&$edit, &$account, $category) {
+  _trigger_user('delete', $edit, $account, $category); 
+}
+
+/**
+ * Implementation of hook_user_view().
+ */
+function trigger_user_view(&$edit, &$account, $category) {
+  _trigger_user('view', $edit, $account, $category); 
+}
+
+/**
+ * Simple wrapper function to make user hooks work with new entry points.
+ *
+ * @TODO: Take advantage of the new API and reorganise/remove this function. 
+ */
+function _trigger_user($op, &$edit, &$account, $category = NULL) {
   // Keep objects for reuse so that changes actions make to objects can persist.
   static $objects;
   // We support a subset of operations.
--- modules/user/user.module	2008/09/21 15:08:39	1.924
+++ modules/user/user.module	2008/10/06 11:30:12	1.925
@@ -24,9 +24,9 @@
  */
 function user_module_invoke($type, &$array, &$user, $category = NULL) {
   foreach (module_list() as $module) {
-    $function = $module . '_user';
+    $function = $module . '_user_' . $type;
     if (function_exists($function)) {
-      $function($type, $array, $user, $category);
+      $function($array, $user, $category);
     }
   }
 }
@@ -633,45 +633,62 @@
 }
 /**
- * Implementation of hook_user().
+ * Implementation of hook_user_view().
  */
-function user_user($type, &$edit, &$account, $category = NULL) {
-  if ($type == 'view') {
-    $account->content['user_picture'] = array(
-      '#value' => theme('user_picture', $account),
-      '#weight' => -10,
-    );
-    if (!isset($account->content['summary'])) {
-      $account->content['summary'] = array();
-    }
-    $account->content['summary'] += array(
-      '#type' => 'user_profile_category',
-      '#attributes' => array('class' => 'user-member'),
-      '#weight' => 5,
-      '#title' => t('History'),
-    );
-    $account->content['summary']['member_for'] =  array(
-      '#type' => 'user_profile_item',
-      '#title' => t('Member for'),
-      '#markup' => format_interval(REQUEST_TIME - $account->created),
-    );
+function user_user_view(&$edit, &$account, $category = NULL) {
+  $account->content['user_picture'] = array(
+    '#value' => theme('user_picture', $account),
+    '#weight' => -10,
+  );
+  if (!isset($account->content['summary'])) {
+    $account->content['summary'] = array();
   }
-  if ($type == 'form' && $category == 'account') {
+  $account->content['summary'] += array(
+    '#type' => 'user_profile_category',
+    '#attributes' => array('class' => 'user-member'),
+    '#weight' => 5,
+    '#title' => t('History'),
+  );
+  $account->content['summary']['member_for'] =  array(
+    '#type' => 'user_profile_item',
+    '#title' => t('Member for'),
+    '#markup' => format_interval(REQUEST_TIME - $account->created),
+  );
+}
+
+/**
+ * Implementation of hook_user_form.
+ */
+function user_user_form(&$edit, &$account, $category = NULL) {
+  if ($category == 'account') {
     $form_state = array();
     return user_edit_form($form_state, arg(1), $edit);
   }
+}
-  if ($type == 'validate' && $category == 'account') {
+/**
+ * Implementation of hook_user_validate.
+ */
+function user_user_validate(&$edit, &$account, $category = NULL) {
+  if ($category == 'account') {
     return _user_edit_validate(arg(1), $edit);
   }
+}
-  if ($type == 'submit' && $category == 'account') {
+/**
+ * Implementation of hook_user_submit.
+ */
+function user_user_submit(&$edit, &$account, $category = NULL) {
+  if ($category == 'account') {
     return _user_edit_submit(arg(1), $edit);
   }
+}
-  if ($type == 'categories') {
+/**
+ * Implementation of hook_user_categories.
+ */
+function user_user_categories(&$edit, &$account, $category = NULL) {
     return array(array('name' => 'account', 'title' => t('Account settings'), 'weight' => 1));
-  }
 }
 function user_login_block() {
@@ -1560,7 +1577,7 @@
   $account = user_load(array('uid' => $uid));
   drupal_session_destroy_uid($uid);
   _user_mail_notify('status_deleted', $account);
-  module_invoke_all('user', 'delete', $edit, $account);
+  module_invoke_all('user_delete', $edit, $account);
   db_query('DELETE FROM {users} WHERE uid = %d', $uid);
   db_query('DELETE FROM {users_roles} WHERE uid = %d', $uid);
   db_query('DELETE FROM {authmap} WHERE uid = %d', $uid);
@@ -1888,7 +1905,7 @@
   $categories = array();
   foreach (module_list() as $module) {
-    if ($data = module_invoke($module, 'user', 'categories', NULL, $account, '')) {
+    if ($data = module_invoke($module, 'user_categories', NULL, $account, '')) {
       $categories = array_merge($data, $categories);
     }
   }
@@ -2410,7 +2427,7 @@
 function _user_forms(&$edit, $account, $category, $hook = 'form') {
   $groups = array();
   foreach (module_list() as $module) {
-    if ($data = module_invoke($module, 'user', $hook, $edit, $account, $category)) {
+    if ($data = module_invoke($module, 'user_' . $hook, $edit, $account, $category)) {
       $groups = array_merge_recursive($data, $groups);
     }
   }
@@ -2418,3 +2435,4 @@
   return empty($groups) ? FALSE : $groups;
 }
+
--- modules/user/user.pages.inc	2008/09/17 07:11:59	1.17
+++ modules/user/user.pages.inc	2008/10/06 11:30:12	1.18
@@ -135,7 +135,7 @@
   // Destroy the current session:
   session_destroy();
-  module_invoke_all('user', 'logout', NULL, $user);
+  module_invoke_all('user_logout', NULL, $user);
   // Load the anonymous user
   $user = drupal_anonymous_user();
No votes yet