function antispam_user in AntiSpam 6
Implementation of hook_user().
File
- ./
antispam.module, line 1398
Code
function antispam_user($op, &$edit, &$account, $category = NULL) {
$moderator_email_for_options = array(
'all' => t('All new (or updated) content'),
'approval' => t('Only content needing approval'),
'never' => t('Never'),
);
switch ($op) {
case 'form':
if ($category == 'account' && variable_get('antispam_email_enabled', 1)) {
$moderator_types = antispam_get_moderator_types($account);
$moderator_types_count = count($moderator_types);
if ($moderator_types_count > 0) {
$form = array();
$form['antispam_moderator'] = array(
'#type' => 'fieldset',
'#title' => t('AntiSpam moderator settings'),
'#weight' => 5,
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#description' => t('You are currently moderator for the following content types: %types.', array(
'%types' => implode(', ', $moderator_types),
)),
);
$form['antispam_moderator']['antispam_moderator_email_for'] = array(
'#type' => 'radios',
'#title' => t('Send me e-mails for'),
'#options' => $moderator_email_for_options,
'#default_value' => isset($moderator_email_for_options[$edit['antispam_moderator_email_for']]) ? $edit['antispam_moderator_email_for'] : 'approval',
);
return $form;
}
}
break;
case 'load':
$moderator_types = antispam_get_moderator_types($account);
$moderator_types_count = count($moderator_types);
if ($moderator_types_count > 0) {
$moderator_data = db_fetch_object(db_query('SELECT * FROM {antispam_moderator} WHERE uid = %d', $account->uid));
$account->antispam_moderator_email_for = isset($moderator_data->email_for) && isset($moderator_email_for_options[$moderator_data->email_for]) ? $moderator_data->email_for : 'approval';
}
break;
case 'insert':
case 'update':
$moderator_types = antispam_get_moderator_types($account);
$moderator_types_count = count($moderator_types);
if ($moderator_types_count > 0 && isset($edit['antispam_moderator_email_for'])) {
if (!isset($moderator_email_for_options[$edit['antispam_moderator_email_for']])) {
$edit['antispam_moderator_email_for'] = 'approval';
}
db_query('UPDATE {antispam_moderator} SET email_for = \'%s\' WHERE uid = %d', $edit['antispam_moderator_email_for'], $account->uid);
if (!db_affected_rows()) {
db_query('INSERT INTO {antispam_moderator} (uid, email_for) VALUES (%d, \'%s\')', $account->uid, $edit['antispam_moderator_email_for']);
}
$edit['antispam_moderator_email_for'] = NULL;
break;
}
// Fall through, to remove possible garbage.
case 'delete':
db_query('DELETE FROM {antispam_moderator} WHERE uid = %d', $account->uid);
break;
}
}