function spambot_user_spam_admin_form_submit in Spambot 6.3
Same name and namespace in other branches
- 7 spambot.pages.inc \spambot_user_spam_admin_form_submit()
File
- ./
spambot.pages.inc, line 122
Code
function spambot_user_spam_admin_form_submit($form, &$form_state) {
$account = user_load($form_state['values']['uid']);
if ($form_state['values']['op'] == $form_state['values']['check']) {
// This is a more comprehensive check than the automated criteria checks.
// This tests everything.
$messages = array();
$service_down = FALSE;
// Check email and username
$request = array(
'email' => $account->mail,
'username' => $account->name,
);
$data = array();
if (spambot_sfs_request($request, $data)) {
if (!empty($data['email']['appears'])) {
$messages[] = t('This account\'s email address matches @num times: !link', array(
'!link' => l($request['email'], 'http://www.stopforumspam.com/search?q=' . $request['email']),
'@num' => $data['email']['frequency'],
));
}
if (!empty($data['username']['appears'])) {
$messages[] = t('This account\'s username matches @num times: !link', array(
'!link' => l($request['username'], 'http://www.stopforumspam.com/search?q=' . $request['username']),
'@num' => $data['username']['frequency'],
));
}
}
else {
drupal_set_message(t('Error contacting service.'), 'warning');
$service_down = TRUE;
}
// Check IP addresses
if (!$service_down) {
$ips = spambot_account_ip_addresses($account);
foreach ($ips as $ip) {
// Skip the loopback interface
if ($ip == '127.0.0.1') {
continue;
}
elseif (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === FALSE) {
$messages[] = t('Invalid IP address: @ip. Spambot will not rely on it.', array(
'@ip' => $ip,
));
continue;
}
$request = array(
'ip' => $ip,
);
$data = array();
if (spambot_sfs_request($request, $data)) {
if (!empty($data['ip']['appears'])) {
$messages[] = t('An IP address !ip used by this account matches @num times.', array(
'!ip' => l($ip, 'http://www.stopforumspam.com/search?q=' . $ip),
'@num' => $data['ip']['frequency'],
));
}
}
else {
drupal_set_message(t('Error contacting service.'), 'warning');
$service_down = TRUE;
break;
}
}
}
if (count($messages)) {
foreach ($messages as $message) {
drupal_set_message($message);
}
}
else {
drupal_set_message(t('No matches against known spammers found.'));
}
}
else {
if ($form_state['values']['op'] == $form_state['values']['action']) {
if ($account->uid == 1) {
drupal_set_message(t('Sorry, taking action against uid 1 is not allowed.'));
return;
}
// Block account
if (!empty($form_state['values']['block_user'])) {
if ($account->status) {
user_save($account, array(
'status' => 0,
));
drupal_set_message(t('Account blocked.'));
}
else {
drupal_set_message(t('This account is already blocked.'));
}
}
// Prepare some data
$nodes = array();
$result = db_query("SELECT nid FROM {node} WHERE uid = %d ORDER BY nid", $account->uid);
while ($object = db_fetch_object($result)) {
$nodes[$object->nid] = $object->nid;
}
$node_hostnames = array();
$result = db_query("SELECT nid, hostname FROM {node_spambot} WHERE uid = %d ORDER BY nid", $account->uid);
while ($object = db_fetch_object($result)) {
$node_hostnames[$object->nid] = $object->hostname;
}
$comments = array();
if (module_exists('comment')) {
$result = db_query("SELECT cid FROM {comments} WHERE uid = %d ORDER BY cid", $account->uid);
while ($object = db_fetch_object($result)) {
$comments[$object->cid] = $object->cid;
}
}
// Report posts to www.stopforumspam.com
if (!empty($form_state['values']['report']['nids'])) {
foreach (array_filter($form_state['values']['report']['nids']) as $nid => $unused) {
$node = node_load($nid);
if (!empty($node->nid)) {
if (spambot_report_account($account, $node_hostnames[$nid], $node->title . "\n\n" . $node->body)) {
drupal_set_message(t('Node %title has been reported.', array(
'%title' => $node->title,
)));
}
else {
drupal_set_message(t('There was a problem reporting node %title.', array(
'%title' => $node->title,
)));
}
}
}
}
if (module_exists('comment') && !empty($form_state['values']['report']['cids'])) {
foreach (array_filter($form_state['values']['report']['cids']) as $cid => $unused) {
$comment = _comment_load($cid);
if (!empty($comment->cid)) {
if (spambot_report_account($account, $comment->hostname, $comment->subject . "\n\n" . $comment->comment)) {
drupal_set_message(t('Comment %title has been reported.', array(
'%title' => $comment->subject,
)));
}
else {
drupal_set_message(t('There was a problem reporting comment %title.', array(
'%title' => $comment->subject,
)));
}
}
}
}
// Delete nodes and content
if (!empty($form_state['values']['delete_content'])) {
if (count($nodes)) {
foreach ($nodes as $nid) {
node_delete($nid);
}
}
if (count($comments)) {
foreach ($comments as $cid) {
$comment = _comment_load($cid);
module_load_include('inc', 'comment', 'comment.admin');
_comment_delete_thread($comment);
_comment_update_node_statistics($comment->nid);
}
cache_clear_all();
}
drupal_set_message(t('Nodes and comments have been deleted.'));
}
else {
if (!empty($form_state['values']['unpublish_content'])) {
// Unpublish nodes and content
if (count($nodes)) {
module_load_include('inc', 'node', 'node.admin');
node_mass_update($nodes, array(
'status' => 0,
));
}
if (count($comments)) {
db_query("UPDATE {comments} SET status = %d WHERE uid = %d", COMMENT_NOT_PUBLISHED, $account->uid);
cache_clear_all();
}
drupal_set_message(t('Nodes and comments have been unpublished.'));
}
}
// Delete user
if (!empty($form_state['values']['delete_user'])) {
// Redirect to user delete form
$form_state['redirect'] = 'user/' . $account->uid . '/delete';
}
}
}
}