You are here

function _spambot_user_spam_admin_form_submit_action in Spambot 7

Take action under this user account.

1 call to _spambot_user_spam_admin_form_submit_action()
spambot_user_spam_admin_form_submit in ./spambot.pages.inc
Submit handler for spambot_user_spam_admin_form() form.

File

./spambot.pages.inc, line 328
User available pages from Spambot module.

Code

function _spambot_user_spam_admin_form_submit_action(&$form, &$form_state, $account) {
  $comments_enabled = module_exists('comment');
  if ($account->uid == 1) {
    drupal_set_message(t('Sorry, taking action against uid 1 is not allowed.'), 'warning');
    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.
  $node_hostnames = array();
  $result = db_select('node_spambot')
    ->fields('node_spambot', array(
    'nid',
    'hostname',
  ))
    ->condition('uid', $account->uid)
    ->orderBy('nid', 'DESC')
    ->execute();
  foreach ($result as $record) {
    $node_hostnames[$record->nid] = $record->hostname;
  }

  // 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[LANGUAGE_NONE][0]['summary'] . "\n\n" . $node->body[LANGUAGE_NONE][0]['value'])) {
          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 ($comments_enabled && !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_body[LANGUAGE_NONE][0]['value'])) {
          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,
          )));
        }
      }
    }
  }
  $action = $form_state['values']['content_action'];
  spambot_delete_nodes_and_comments($account->uid, $action);

  // Delete user.
  if (!empty($form_state['values']['delete_user'])) {

    // Redirect to user delete form.
    $form_state['redirect'] = "user/{$account->uid}/cancel";
  }
}