You are here

function comment_ip_confirm_blocked_ips in Comment IP 7

Altered comment overview page with IP column and block IP select option.

1 string reference to 'comment_ip_confirm_blocked_ips'
comment_ip_redirect in ./comment_ip.module
Redirect the menu callback to specific forms based on posted data.

File

./comment_ip.module, line 85
Main hooks and functions for comment_ip module.

Code

function comment_ip_confirm_blocked_ips($form, &$form_state) {
  $edit = $form_state['input'];
  $form['comments'] = array(
    '#prefix' => '<ul>',
    '#suffix' => '</ul>',
    '#tree' => TRUE,
  );

  // array_filter() returns only elements with actual values.
  $comment_counter = 0;
  foreach (array_filter($edit['comments']) as $cid => $value) {
    $comment = comment_load($cid);
    if (is_object($comment) && is_numeric($comment->cid)) {
      $result = db_query('SELECT subject, hostname FROM {comment} WHERE cid = :cid', array(
        ':cid' => $cid,
      ))
        ->fetchAllKeyed();
      $subject = key($result);
      $ip = $result[$subject];
      $warning = $ip == ip_address() ? ' <strong>(This IP address is yours, so we won\'t block it.)</strong>' : '';
      $form['comments'][$cid] = array(
        '#type' => 'hidden',
        '#value' => $cid,
        '#prefix' => '<li>',
        '#suffix' => check_plain($subject) . ' - ' . check_plain($ip) . $warning . '</li>',
      );
      $comment_counter++;
    }
  }
  $form['operation'] = array(
    '#type' => 'hidden',
    '#value' => 'block',
  );
  if (!$comment_counter) {
    drupal_set_message(t('There do not appear to be any comments to delete, or your selected comment was deleted by another administrator.'));
    drupal_goto('admin/content/comment');
  }
  else {
    return confirm_form($form, t("Are you sure you want to delete these comments and all their children, and block the following IPs"), 'admin/content/comment', t('This action cannot be undone.'), t('Delete comments'), t('Cancel'));
  }
}