You are here

function spambot_user_spam_admin_form in Spambot 6.3

Same name and namespace in other branches
  1. 7 spambot.pages.inc \spambot_user_spam_admin_form()
1 string reference to 'spambot_user_spam_admin_form'
spambot_menu in ./spambot.module
Implementation of hook_menu()

File

./spambot.pages.inc, line 3

Code

function spambot_user_spam_admin_form($form_state, $account) {
  $key = variable_get('spambot_sfs_api_key', FALSE);
  $node_count = db_result(db_query("SELECT COUNT(nid) FROM {node} WHERE uid = %d", $account->uid));
  if (module_exists('comment')) {
    $comment_count = db_result(db_query("SELECT COUNT(cid) FROM {comments} WHERE uid = %d", $account->uid));
    $status = t('This account has @n nodes and @c comments.', array(
      '@n' => $node_count,
      '@c' => $comment_count,
    ));
  }
  else {
    $status = t('This account has @n nodes.', array(
      '@n' => $node_count,
    ));
  }
  $form = array();
  $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']['unpublish_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unpublish nodes and comments by this account'),
    '#default_value' => TRUE,
  );
  $form['action']['delete_content'] = array(
    '#type' => 'checkbox',
    '#title' => t('Delete nodes and comments by this account'),
    '#default_value' => FALSE,
  );
  $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_query("SELECT nid, hostname FROM {node_spambot} WHERE uid = %d ORDER BY nid DESC LIMIT 20", $account->uid);
  $nid_hostnames = array();
  while ($object = db_fetch_object($result)) {
    $nid_hostnames[$object->nid] = $object->hostname;
  }
  foreach ($nid_hostnames as $nid => $hostname) {
    $node = node_load($nid);
    if (!empty($node->nid)) {
      $form['action']['report']['nids'][$nid] = array(
        '#type' => 'checkbox',
        '#title' => l(mb_strimwidth($node->title, 0, 128, '...'), 'node/' . $nid, array(
          'attributes' => array(
            'title' => $node->teaser,
          ),
        )) . ' ' . t('(node, ip=@ip)', array(
          '@ip' => $hostname,
        )),
        '#disabled' => empty($key),
      );
    }
  }

  // Fetch a list of reportable comments
  if (module_exists('comment')) {
    $form['action']['report']['cids'] = array();
    $result = db_query("SELECT cid FROM {comments} WHERE uid = %d ORDER BY cid DESC LIMIT 20", $account->uid);
    $cids = array();
    while ($object = db_fetch_object($result)) {
      $cids[$object->cid] = $object->cid;
    }
    foreach ($cids as $cid) {
      $comment = _comment_load($cid);
      if (!empty($comment->cid)) {
        $form['action']['report']['cids'][$cid] = array(
          '#type' => 'checkbox',
          '#title' => l(mb_strimwidth($comment->subject, 0, 128, '...'), 'node/' . $comment->nid, array(
            'fragment' => 'comment-' . $comment->cid,
            'attributes' => array(
              'title' => mb_strimwidth($comment->comment, 0, 256, '...'),
            ),
          )) . ' ' . t('(comment, ip=@ip)', array(
            '@ip' => $comment->hostname,
          )),
          '#disabled' => empty($key),
        );
      }
    }
  }
  if ($key) {
    $evidence_count = count($form['action']['report']['nids']) + count($form['action']['report']['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/settings/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,
  );
  return $form;
}