Commit 026af5df authored by Dries's avatar Dries

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

- Patch #310212 by justinrandell, catch, et all: killed  in _user hook, as well as two small kittens.
parent eabf7ab4
......@@ -335,38 +335,35 @@ function block_box_save($edit, $delta) {
}
/**
* 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;
}
/**
......
......@@ -42,10 +42,10 @@ function blog_access($op, $node, $account) {
}
/**
* 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'),
......
......@@ -600,13 +600,11 @@ function comment_nodeapi(&$node, $op, $arg = 0) {
}
/**
* 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);
}
/**
......
......@@ -130,12 +130,10 @@ function contact_load($cid) {
}
/**
* 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 @@ function contact_user($type, &$edit, &$user, $category = NULL) {
);
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);
}
/**
......
......@@ -101,12 +101,10 @@ function dblog_cron() {
}
/**
* 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() {
......
......@@ -206,42 +206,56 @@ function locale_locale($op = 'groups') {
}
/**
* 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);
}
}
// If the user is being created, we set the user language to the page language.
$user_preferred_language = $user ? user_preferred_language($user) : $language;
function locale_language_selector_form($user) {
global $language;
$languages = language_list('enabled');
$languages = $languages[1];
$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;
// 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;
}
/**
......
......@@ -1379,13 +1379,11 @@ function node_ranking() {
}
/**
* 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);
}
/**
......
......@@ -26,7 +26,7 @@ function openid_menu() {
);
$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 @@ function openid_help($path, $arg) {
}
/**
* 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.'));
......
......@@ -82,7 +82,7 @@ function openid_user_add_validate($form, &$form_state) {
/**
* 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.'));
......
......@@ -823,10 +823,9 @@ function poll_cancel($form, &$form_state) {
}
/**
* 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);
}
......@@ -194,29 +194,66 @@ function profile_block($op = 'list', $delta = '', $edit = array()) {
}
/**
* 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) {
......
......@@ -174,12 +174,10 @@ function statistics_menu() {
}
/**
* 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);
}
/**
......
......@@ -711,12 +711,10 @@ function system_preprocess_page(&$variables) {
}
/**
* 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)) {
......
......@@ -347,9 +347,53 @@ function _trigger_normalize_user_context($type, $account) {
}
/**
* 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.
......
......@@ -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 @@ function user_elements() {
}
/**
* 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),
);
}
if ($type == 'form' && $category == 'account') {
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();
}
$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 @@ function user_delete($edit, $uid) {
$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 @@ function _user_categories($account) {
$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_register_validate($form, &$form_state) {
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 @@ function _user_forms(&$edit, $account, $category, $hook = 'form') {
return empty($groups) ? FALSE : $groups;
}
......@@ -135,7 +135,7 @@ function user_logout() {
// 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();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment