You are here

function spambot_user_spam_admin_form in Spambot 7

Same name and namespace in other branches
  1. 6.3 spambot.pages.inc \spambot_user_spam_admin_form()

Form builder for spambot_user_spam_admin_form form.

1 string reference to 'spambot_user_spam_admin_form'
spambot_user_spam in ./spambot.pages.inc
Page callback for 'user/%user/spambot' path.

File

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

Code

function spambot_user_spam_admin_form($form, &$form_state, $account) {
  $key = variable_get('spambot_sfs_api_key', FALSE);
  $comments_enabled = module_exists('comment');
  $node_count = db_select('node', 'n')
    ->fields('n', array(
    'nid',
  ))
    ->condition('uid', $account->uid)
    ->countQuery()
    ->execute()
    ->fetchField();
  $status = t('This account has @n nodes.', array(
    '@n' => $node_count,
  ));
  if ($comments_enabled) {
    $comment_count = db_select('comment', 'c')
      ->fields('c', array(
      'cid',
    ))
      ->condition('uid', $account->uid)
      ->countQuery()
      ->execute()
      ->fetchField();
    $status = t('This account has @n nodes and @c comments.', array(
      '@n' => $node_count,
      '@c' => $comment_count,
    ));
  }
  $form['check'] = array(
    '#type' => 'submit',
    '#value' => t('Check if this account matches a known spammer'),
  );
  $form['action'] = array(
    '#type' => 'fieldset',
    '#title' => t('Take action against this account'),
    '#collapsible' => TRUE,
    '#description' => $status,
  );
  $form['action']['content_action'] = array(
    '#type' => 'select',
    '#title' => t('Action to take'),
    '#description' => t('Please select what action to take with nodes and comments.'),
    '#options' => array(
      SPAMBOT_ACTION_NONE => t('None'),
      SPAMBOT_CONTENT_ACTION_UNPUBLISH => t('Unpublish nodes and comments by this account'),
      SPAMBOT_CONTENT_ACTION_DELETE => t('Delete nodes and comments by this account'),
    ),
    '#default_value' => SPAMBOT_CONTENT_ACTION_UNPUBLISH,
  );
  $form['action']['report'] = array(
    '#type' => 'fieldset',
    '#title' => t('Report this account to www.stopforumspam.com'),
    '#tree' => TRUE,
    '#collapsible' => TRUE,
  );

  // Fetch a list of reportable nodes.
  $form['action']['report']['nids'] = array();
  $result = db_select('node_spambot', 'ns')
    ->fields('ns', array(
    'nid',
    'hostname',
  ))
    ->condition('ns.uid', $account->uid)
    ->orderBy('ns.nid', 'DESC')
    ->range(0, 20)
    ->execute();
  $nid_hostnames = array();
  foreach ($result as $record) {
    $nid_hostnames[$record->nid] = $record->hostname;
  }
  foreach ($nid_hostnames as $nid => $hostname) {
    if ($node = node_load($nid)) {
      $title = truncate_utf8(check_plain($node->title), 128, TRUE, TRUE);
      $form['action']['report']['nids'][$nid] = array(
        '#type' => 'checkbox',
        '#title' => l($title, "node/{$nid}", array(
          'attributes' => array(
            'title' => $title,
          ),
        )) . ' ' . t('(node, ip=@ip)', array(
          '@ip' => $hostname,
        )),
        '#disabled' => !$key,
      );
    }
  }

  // Fetch a list of reportable comments.
  if ($comments_enabled) {
    $form['action']['report']['cids'] = array();
    $result = db_select('comment')
      ->fields('comment', array(
      'cid',
    ))
      ->condition('uid', $account->uid)
      ->orderBy('cid', 'DESC')
      ->range(0, 20)
      ->execute();
    $cids = array();
    foreach ($result as $record) {
      $cids[$record->cid] = $record->cid;
    }
    foreach ($cids as $cid) {
      if ($comment = comment_load($cid)) {
        $subject = truncate_utf8(check_plain($comment->subject), 128, TRUE, TRUE);
        $form['action']['report']['cids'][$cid] = array(
          '#type' => 'checkbox',
          '#title' => l($subject, "node/{$comment->nid}", array(
            'fragment' => "comment-{$comment->cid}",
            'attributes' => array(
              'title' => $subject,
            ),
          )) . ' ' . t('(comment, ip=@ip)', array(
            '@ip' => $comment->hostname,
          )),
          '#disabled' => !$key,
        );
      }
    }
  }
  if ($key) {
    $comment_cids = $comments_enabled ? count($form['action']['report']['cids']) : 0;
    $evidence_count = count($form['action']['report']['nids']) + $comment_cids;
    $form['action']['report']['#description'] = $evidence_count ? t('Select one or more posts below to report them to www.stopforumspam.com.') : t('This account cannot be reported because no evidence or IP address is available.');
  }
  else {
    $form['action']['report']['#description'] = t('An API key from <a href="http://www.stopforumspam.com">www.stopforumspam.com</a> must <a href="!admin-url">be configured</a> to report spammers.', array(
      '!admin-url' => url('admin/config/system/spambot'),
    ));
  }
  $form['action']['block_user'] = array(
    '#type' => 'checkbox',
    '#title' => t('Block this account'),
    '#default_value' => TRUE,
  );
  $form['action']['delete_user'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete this account'),
    '#default_value' => FALSE,
  );
  $form['action']['action'] = array(
    '#type' => 'submit',
    '#value' => t('Take action'),
  );
  $form['uid'] = array(
    '#type' => 'value',
    '#value' => $account->uid,
  );
  $form['#validate'][] = 'spambot_user_spam_admin_form_validate';
  $form['#submit'][] = 'spambot_user_spam_admin_form_submit';
  return $form;
}