| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: user.api.php,v 1.1 2008/11/25 02:37:33 webchick Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 23 |
* (probably along with 'insert') if you want to reuse some information from |
* (probably along with 'insert') if you want to reuse some information from |
| 24 |
* the user object. |
* the user object. |
| 25 |
* - "categories": A set of user information categories is requested. |
* - "categories": A set of user information categories is requested. |
|
* - "delete": The user account is being deleted. The module should remove its |
|
|
* custom additions to the user object from the database. |
|
| 26 |
* - "form": The user account edit form is about to be displayed. The module |
* - "form": The user account edit form is about to be displayed. The module |
| 27 |
* should present the form elements it wishes to inject into the form. |
* should present the form elements it wishes to inject into the form. |
| 28 |
* - "insert": The user account is being added. The module should save its |
* - "insert": The user account is being added. The module should save its |
| 86 |
} |
} |
| 87 |
|
|
| 88 |
/** |
/** |
| 89 |
|
* Act on user account cancellations. |
| 90 |
|
* |
| 91 |
|
* The user account is being canceled. Depending on the account cancellation |
| 92 |
|
* method, the module should either do nothing, unpublish content, anonymize |
| 93 |
|
* content, or delete content and data belonging to the canceled user account. |
| 94 |
|
* |
| 95 |
|
* Expensive operations should be added to the global batch with batch_set(). |
| 96 |
|
* |
| 97 |
|
* @param &$edit |
| 98 |
|
* The array of form values submitted by the user. |
| 99 |
|
* @param &$account |
| 100 |
|
* The user object on which the operation is being performed. |
| 101 |
|
* @param $method |
| 102 |
|
* The account cancellation method. |
| 103 |
|
* |
| 104 |
|
* @see user_cancel_methods() |
| 105 |
|
* @see hook_user_cancel_methods_alter() |
| 106 |
|
* @see user_cancel() |
| 107 |
|
*/ |
| 108 |
|
function hook_user_cancel(&$edit, &$account, $method) { |
| 109 |
|
switch ($method) { |
| 110 |
|
case 'user_cancel_block_unpublish': |
| 111 |
|
// Unpublish nodes (current revisions). |
| 112 |
|
module_load_include('inc', 'node', 'node.admin'); |
| 113 |
|
$nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol(); |
| 114 |
|
node_mass_update($nodes, array('status' => 0)); |
| 115 |
|
break; |
| 116 |
|
|
| 117 |
|
case 'user_cancel_reassign': |
| 118 |
|
// Anonymize nodes (current revisions). |
| 119 |
|
module_load_include('inc', 'node', 'node.admin'); |
| 120 |
|
$nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol(); |
| 121 |
|
node_mass_update($nodes, array('uid' => 0)); |
| 122 |
|
// Anonymize old revisions. |
| 123 |
|
db_update('node_revision')->fields(array('uid' => 0))->condition('uid', $account->uid)->execute(); |
| 124 |
|
// Clean history. |
| 125 |
|
db_delete('history')->condition('uid', $account->uid)->execute(); |
| 126 |
|
break; |
| 127 |
|
|
| 128 |
|
case 'user_cancel_delete': |
| 129 |
|
// Delete nodes (current revisions). |
| 130 |
|
$nodes = db_select('node', 'n')->fields('n', array('nid'))->condition('uid', $account->uid)->execute()->fetchCol(); |
| 131 |
|
foreach ($nodes as $nid) { |
| 132 |
|
node_delete($nid); |
| 133 |
|
} |
| 134 |
|
// Delete old revisions. |
| 135 |
|
db_delete('node_revision')->condition('uid', $account->uid)->execute(); |
| 136 |
|
// Clean history. |
| 137 |
|
db_delete('history')->condition('uid', $account->uid)->execute(); |
| 138 |
|
break; |
| 139 |
|
} |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
/** |
| 143 |
|
* Modify account cancellation methods. |
| 144 |
|
* |
| 145 |
|
* By implementing this hook, modules are able to add, customize, or remove |
| 146 |
|
* account cancellation methods. All defined methods are turned into radio |
| 147 |
|
* button form elements by user_cancel_methods() after this hook is invoked. |
| 148 |
|
* The following properties can be defined for each method: |
| 149 |
|
* - title: The radio button's title. |
| 150 |
|
* - description: (optional) A description to display on the confirmation form |
| 151 |
|
* if the user is not allowed to select the account cancellation method. The |
| 152 |
|
* description is NOT used for the radio button, but instead should provide |
| 153 |
|
* additional explanation to the user seeking to cancel their account. |
| 154 |
|
* - access: (optional) A boolean value indicating whether the user can access |
| 155 |
|
* a method. If #access is defined, the method cannot be configured as default |
| 156 |
|
* method. |
| 157 |
|
* |
| 158 |
|
* @param &$methods |
| 159 |
|
* An array containing user account cancellation methods, keyed by method id. |
| 160 |
|
* |
| 161 |
|
* @see user_cancel_methods() |
| 162 |
|
* @see user_cancel_confirm_form() |
| 163 |
|
*/ |
| 164 |
|
function hook_user_cancel_methods_alter(&$methods) { |
| 165 |
|
// Limit access to disable account and unpublish content method. |
| 166 |
|
$methods['user_cancel_block_unpublish']['access'] = user_access('administer site configuration'); |
| 167 |
|
|
| 168 |
|
// Remove the content re-assigning method. |
| 169 |
|
unset($methods['user_cancel_reassign']); |
| 170 |
|
|
| 171 |
|
// Add a custom zero-out method. |
| 172 |
|
$methods['mymodule_zero_out'] = array( |
| 173 |
|
'title' => t('Delete the account and remove all content.'), |
| 174 |
|
'description' => t('All your content will be replaced by empty strings.'), |
| 175 |
|
// access should be used for administrative methods only. |
| 176 |
|
'access' => user_access('access zero-out account cancellation method'), |
| 177 |
|
); |
| 178 |
|
} |
| 179 |
|
|
| 180 |
|
/** |
| 181 |
* Add mass user operations. |
* Add mass user operations. |
| 182 |
* |
* |
| 183 |
* This hook enables modules to inject custom operations into the mass operations |
* This hook enables modules to inject custom operations into the mass operations |
| 204 |
'label' => t('Block the selected users'), |
'label' => t('Block the selected users'), |
| 205 |
'callback' => 'user_user_operations_block', |
'callback' => 'user_user_operations_block', |
| 206 |
), |
), |
| 207 |
'delete' => array( |
'cancel' => array( |
| 208 |
'label' => t('Delete the selected users'), |
'label' => t('Cancel the selected user accounts'), |
| 209 |
), |
), |
| 210 |
); |
); |
| 211 |
return $operations; |
return $operations; |