comment_threshold_settings

Versions
4.6
comment_threshold_settings($fid = 0)

Menu callback; displays settings for thresholds at which comments are displayed.

Code

modules/comment.module, line 1190

<?php
function comment_threshold_settings($fid = 0) {
  $op   = $_POST['op'];
  $edit = $_POST['edit'];

  if ($op == t('Save threshold')) {
    db_query("UPDATE {moderation_filters} SET filter = '%s', minimum = %d WHERE fid = %d", $edit['filter'], $edit['minimum'], $fid);
    $fid = 0; // zero it out so we return to the overview.
    drupal_set_message(t('The threshold has been saved.'));
  }
  else if ($op == t('Delete threshold')) {
    db_query('DELETE FROM {moderation_filters} WHERE fid = %d', $fid);
    $fid = 0; // zero it out so we return to the overview.
    drupal_set_message(t('The threshold has been deleted.'));
  }
  else if ($op == t('Add new threshold')) {
    db_query("INSERT INTO {moderation_filters} (filter, minimum) VALUES ('%s', %d)", $edit['filter'], $edit['minimum']);
    $fid = 0; // zero it out so we return to the overview.
    drupal_set_message(t('The threshold has been added.'));
  }

  $output .= '<h3>'. t('Comment threshold overview') .'</h3>';

  // load up and show any thresholds previously defined.
  $header = array(t('Name'), t('Minimum score'), t('Operations'));
  $result = db_query('SELECT fid, filter, minimum FROM {moderation_filters} ORDER BY minimum');
  while ($filter = db_fetch_object($result)) {
    $rows[] = array($filter->filter, array('data' => $filter->minimum), array('data' => l(t('edit'), "admin/comment/configure/thresholds/$filter->fid")));
  }
  if (!$rows) {
    $rows[] = array(array('data' => t('No thresholds have been defined.'), 'colspan' => '3'));
  }
  $output .= theme('table', $header, $rows);

  if ($fid) { // if we're not saving, deleting, or adding, we must be editing, so prefill the form fields.
    $filter = db_fetch_object(db_query('SELECT filter, fid, minimum FROM {moderation_filters} WHERE fid = %d', $fid));
  }

  $output .= '<br /><h3>'. (isset($fid) ? t('Edit threshold') : t('Add new threshold')) .'</h3>';
  $form .= form_textfield(t('Threshold name'), 'filter', $filter->filter, 32, 64, t('The name of this threshold. Example: "good comments", "+1 comments", "everything".'));
  $form .= form_textfield(t('Minimum score'), 'minimum', $filter->minimum, 32, 64, t('Show all comments whose score is larger or equal to the provided minimal score. Range: -127 +128'));
  if ($fid) {
    $form .= form_submit(t('Save threshold'));
    $form .= form_submit(t('Delete threshold'));
  }
  else {
    $form .= form_submit(t('Add new threshold'));
  }

  print theme('page', $output . form($form));
}
?>
Login or register to post comments
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.