You are here

function spam_content_comment_admin_overview in Spam 6

The 5.x version of comment_admin_overview doesn't provide hooks to easily create a spam overview page. This is nearly an exact copy of that function, with minor changes for loading spam and processing it.

2 string references to 'spam_content_comment_admin_overview'
comment_spamapi_form_alter in content/spam_content_comment.inc
Form alter gets its own function so we can reference &$form without causing errors in PHP4 installations. (If we use spamapi, we have to set a default, which PHP4 doesn't support.)
spam_content_comment_admin in content/spam_content_comment.inc
Menu callback; present an administrative spam comment listing.

File

content/spam_content_comment.inc, line 328
Include file for integration with comments.

Code

function spam_content_comment_admin_overview(&$form_state, $arg) {

  // build an 'Update options' form
  $form['options'] = array(
    '#type' => 'fieldset',
    '#title' => t('Update options'),
    '#prefix' => '<div class="container-inline">',
    '#suffix' => '</div>',
  );
  $options = array(
    'markasnotspam' => t('Mark the selected comments as not spam'),
    'delete' => t('Delete the selected comments'),
  );
  $form['options']['operation'] = array(
    '#type' => 'select',
    '#options' => $options,
    '#default_value' => 'markasnotspam',
  );
  $form['options']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Update'),
  );

  // load the comments that we want to display
  $form['header'] = array(
    '#type' => 'value',
    '#value' => array(
      theme('table_select_header_cell'),
      array(
        'data' => t('Subject'),
        'field' => 'subject',
      ),
      array(
        'data' => t('Author'),
        'field' => 'name',
      ),
      array(
        'data' => t('Posted in'),
        'field' => 'node_title',
      ),
      array(
        'data' => t('Time'),
        'field' => 'timestamp',
        'sort' => 'desc',
      ),
      array(
        'data' => t('Operations'),
      ),
    ),
  );
  $result = pager_query('SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, n.title AS node_title FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid INNER JOIN {node} n ON n.nid = c.nid WHERE c.status = %d' . tablesort_sql($form['header']['#value']), 50, 0, NULL, SPAM_COMMENT);

  // build a table listing the appropriate comments
  $destination = drupal_get_destination();
  while ($comment = db_fetch_object($result)) {
    $comments[$comment->cid] = '';
    $comment->name = $comment->uid ? $comment->registered_name : $comment->name;
    $form['subject'][$comment->cid] = array(
      '#value' => l($comment->subject, 'node/' . $comment->nid, array(
        'attributes' => array(
          'title' => truncate_utf8($comment->comment, 128),
        ),
        'fragment' => 'comment-' . $comment->cid,
      )),
    );
    $form['username'][$comment->cid] = array(
      '#value' => theme('username', $comment),
    );
    $form['node_title'][$comment->cid] = array(
      '#value' => l($comment->node_title, 'node/' . $comment->nid),
    );
    $form['timestamp'][$comment->cid] = array(
      '#value' => format_date($comment->timestamp, 'small'),
    );
    $form['operations'][$comment->cid] = array(
      '#value' => l(t('edit'), 'comment/edit/' . $comment->cid, array(
        'query' => $destination,
      )),
    );
  }
  $form['comments'] = array(
    '#type' => 'checkboxes',
    '#options' => $comments,
  );
  $form['pager'] = array(
    '#value' => theme('pager', NULL, 50, 0),
  );
  return $form;
}