Index: commentapproval.info
===================================================================
RCS file: commentapproval.info
diff -N commentapproval.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ commentapproval.info	8 Aug 2007 17:15:20 -0000
@@ -0,0 +1,5 @@
+; $ID$
+name = Comment approval
+description = Reactive moderation of comments. Comments get published normally but appear in an approval queue. From the queue they can be approved, disapproved or deleted.
+package = Approval
+dependencies = comment
Index: commentapproval.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/commentapproval/commentapproval.module,v
retrieving revision 1.1
diff -u -F^f -r1.1 commentapproval.module
--- commentapproval.module	21 Nov 2006 18:30:35 -0000	1.1
+++ commentapproval.module	8 Aug 2007 17:15:20 -0000
@@ -15,75 +15,85 @@ function commentapproval_help($section) 
   }
 }
 
+function commentapproval_perm() {
+  return array('approve comments');
+}
+
+
 /**
  * Implementation of hook_menu
- * 
+ *
  * This implementation intentionally overrides the menu item provided by the
  * comment.module for approval, thus changing the behavior of that page.
- * 
+ *
  */
 function commentapproval_menu($may_cache) {
   $items = array();
-  
+
   if ($may_cache) {
-    $access = user_access('administer comments');
+    $access = user_access('approve comments');
     $items[] = array(
-      'path' => 'admin/comment/list/approval', 
-      'title' => t('not yet moderated'),
-      'callback' => 'commentapproval_admin_overview', 
+      'path' => 'admin/content/approval',
+      'title' => t('Approval'),
+      'description' => t('Approve, disapprove, and delete content'),
       'access' => $access,
-      'callback arguments' => array(COMMENT_NOT_YET_MODERATED),
-      'type' => MENU_LOCAL_TASK,
+      'callback' => 'commentapproval_admin_overview',
     );
     $items[] = array(
-      'path' => 'admin/comment/list/approve', 
-      'title' => t('approved'),
-      'callback' => 'commentapproval_admin_overview', 
-      'access' => $access,
-      'callback arguments' => array(COMMENT_APPROVED),
+      'path' => 'admin/content/approval/comment',
+      'title' => t('Comments'),
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+    );
+    $items[] = array(
+      'path' => 'admin/content/approval/comment/approval',
+      'title' => t('Not yet moderated'),
+      'type' => MENU_DEFAULT_LOCAL_TASK,
+      'weight' => -1,
+    );
+    $items[] = array(
+      'path' => 'admin/content/approval/comment/approve',
+      'title' => t('Approved'),
       'type' => MENU_LOCAL_TASK,
     );
     $items[] = array(
-      'path' => 'admin/comment/list/disapprove', 
-      'title' => t('disapproved'),
-      'callback' => 'commentapproval_admin_overview', 
-      'access' => $access,
-      'callback arguments' => array(COMMENT_DISAPPROVED),
+      'path' => 'admin/content/approval/comment/disapprove',
+      'title' => t('Disapproved'),
       'type' => MENU_LOCAL_TASK,
-    );   
+    );
   }
   return $items;
 }
 
 /**
  * Implementation of hook_comment.
- * 
+ *
  * This implementation deletes comments from the table comment_approval
  * whenever a comment is deleted.
- * 
  */
 function commentapproval_comment($a1, $op) {
   if ($op == 'delete') {
     db_query("DELETE FROM {comment_approval} where cid = %d", $a1->cid);
-  } 
+  }
 }
 
-
 /**
  * an array of bindings between operations and callbacks
  */
 function commentapproval_operations() {
-  return array(
+  $operations = array(
     'approve' => array(
-      'text' => t('Approve the selected comments'), 
+      'text' => t('Approve the selected comments'),
       'callback' => 'commentapproval_do_approval'),
     'disapprove' => array(
-      'text' => t('Disapprove the selected comments'), 
+      'text' => t('Disapprove the selected comments'),
       'callback' => 'commentapproval_do_disapprove'),
-    'delete' => array(
-      'text' => t('Delete the selected comments'),
-      'callback' => NULL),
   );
+  if (user_access('administer comments')) {
+  $operations['delete'] = array(
+    'text' => t('Delete the selected comments'),
+    'callback' => NULL);
+  }
+  return $operations;
 }
 
 function commentapproval_do_approval($cid, $approved = COMMENT_APPROVED) {
@@ -104,58 +114,95 @@ function commentapproval_do_disapprove($
 /**
  * Menu callback; present an administrative comment listing.
  */
-function commentapproval_admin_overview($type) {
-  $edit = $_POST['edit'];
+function commentapproval_admin_overview($arg1 = NULL, $type = NULL) {
+    $edit = $_POST;
 
   if ($edit['operation'] == 'delete') {
-    return comment_multiple_delete_confirm();
+    return drupal_get_form('comment_multiple_delete_confirm');
   }
+  return drupal_get_form('commentapproval_admin_overview_form', $arg1, $type);
+}
 
+function commentapproval_admin_overview_form($arg1 = NULL, $type = NULL){
   // build an 'Update options' form
   $form['options'] = array(
     '#type' => 'fieldset', '#title' => t('Update options'),
     '#prefix' => '<div class="container-inline">', '#suffix' => '</div>'
   );
-  $options = array();
-  
+
+
   // bind identifier, text and callbacks.
   $operations = commentapproval_operations();
+  // unset the operation for the current screen since the comment already has that state
+  unset($operations[$type]);
+  $options = array();
   foreach ($operations as $key => $value) {
     $options[$key] = $value['text'];
   }
-  $form['options']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'approve');
-  $form['options']['submit'] = array('#type' => 'submit', '#value' => t('Update'));
+  $form['options']['operation'] = array(
+    '#type' => 'select',
+    '#options' => $options,
+    '#default_value' => 'approve'
+  );
+  $form['options']['submit'] = array(
+    '#type' => 'submit',
+    '#value' => t('Update')
+  );
 
   // load the comments that we want to display
-  $form['header'] = array('#type' => 'value', '#value' => array(
-    NULL,
-    array('data' => t('Subject'), 'field' => 'subject'),
-    array('data' => t('Author'), 'field' => 'name'),
-    array('data' => t('Time'), 'field' => 'timestamp', 'sort' => 'desc'),
-    array('data' => t('Operations')),
-    array('data' => t('Published'), 'field' => 'status'),
-  ));
-  if ($type == COMMENT_NOT_YET_MODERATED) {
+  $form['header'] = array(
+    '#type' => 'value',
+    '#value' => array(
+      NULL ,
+      array(
+        'data' => t('Subject'),
+        'field' => 'subject'
+      ),
+      array(
+        'data' => t('Author'),
+        'field' => 'name'
+      ),
+      array(
+        'data' => t('Time'),
+        'field' => 'timestamp',
+        'sort' => 'desc'
+      ),
+      'operations' => array(
+        'data' => t('Operations')
+      ),
+      array(
+        'data' => t('Published'),
+        'field' => 'status'
+      ),
+    )
+  );
+  if (!user_access('administer comments')) {
+	// unset the column that contains the 'edit' link if the user isn't able to administer comments
+	unset($form['header']['#value']['operations']);
+  }
+
+  if ($type === NULL) {
     $sql = 'SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, app.approved '.
       'FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid '.
       'LEFT JOIN {comment_approval} app ON c.cid = app.cid '.
       'WHERE app.approved IS NULL ';
   }
-  else if ($type == COMMENT_DISAPPROVED) {
+  else if ($type == 'disapprove') {
   	$sql = 'SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, app.approved '.
       'FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid '.
       'LEFT JOIN {comment_approval} app ON c.cid = app.cid '.
       'WHERE app.approved = '. COMMENT_DISAPPROVED;
   }
-  else if ($type == COMMENT_APPROVED) {
+  else if ($type == 'approve') {
   	$sql = 'SELECT c.subject, c.nid, c.cid, c.comment, c.timestamp, c.status, c.name, c.homepage, u.name AS registered_name, u.uid, app.approved '.
       'FROM {comments} c INNER JOIN {users} u ON u.uid = c.uid '.
       'LEFT JOIN {comment_approval} app ON c.cid = app.cid '.
       'WHERE app.approved = '. COMMENT_APPROVED;
   }
   $result = pager_query($sql . tablesort_sql($form['header']['#value']), 50, 0, NULL);
-  
-  // build a table listing the appropriate comments
+
+  // Build a table listing the appropriate comments.
+  // $destination is used in the _edit_ link
   $destination = drupal_get_destination();
   while ($comment = db_fetch_object($result)) {
     $comments[$comment->cid] = '';
@@ -165,13 +212,17 @@ function commentapproval_admin_overview(
     $form['comment'][$comment->cid] = array('#value' => check_markup($comment->comment, $comment->format, FALSE));
     $form['username'][$comment->cid] = array('#value' => theme('username', $comment));
     $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(), $destination));
+    if (user_access('administer comments')) {
+      $form['operations'][$comment->cid] = array('#value' => l(t('edit'), 'comment/edit/'. $comment->cid, array(), $destination));
+    }
   }
+
   $form['comments'] = array('#type' => 'checkboxes', '#options' => $comments);
   $form['pager'] = array('#value' => theme('pager', NULL, 50, 0));
-  return drupal_get_form('commentapproval_admin_overview', $form);
+  $form['#validate']['commentapproval_admin_overview_validate'] = array();
+  $form['#submit']['commentapproval_admin_overview_submit'] = array();
+  return $form;
 }
-
 /**
  * We can't execute any 'Update options' if no comments were selected.
  */
@@ -179,7 +230,6 @@ function commentapproval_admin_overview_
   $edit['comments'] = array_diff($edit['comments'], array(0));
   if (count($edit['comments']) == 0) {
     form_set_error('', t('Please select one or more comments to perform the update on.'));
-    drupal_goto(implode('/', array('admin/comment', arg(2), arg(3))));
   }
 }
 
@@ -188,6 +238,7 @@ function commentapproval_admin_overview_
  * publishing, unpublishing or deleting.
  */
 function commentapproval_admin_overview_submit($form_id, $edit) {
+
   $operations = commentapproval_operations();
   if ($operations[$edit['operation']]['callback']) {
     // extract the appropriate database query operation
@@ -209,29 +260,32 @@ function commentapproval_admin_overview_
     }
     cache_clear_all();
     drupal_set_message(t('The update ('. check_plain($edit['operation']). ') has been performed.'));
-    drupal_goto(implode('/', array('admin/comment', arg(2), arg(3))));
   }
+
 }
 
-function theme_commentapproval_admin_overview($form) {
-  drupal_set_html_head(theme('stylesheet_import', base_path() . drupal_get_path('module', 'commentapproval') .'/commentapproval.css'));
-  $output = form_render($form['options']);
+function theme_commentapproval_admin_overview_form($form) {
+  drupal_add_css(drupal_get_path('module', 'commentapproval') .'/commentapproval.css');
+  $output = drupal_render($form['options']);
   if (isset($form['subject']) && is_array($form['subject'])) {
     foreach (element_children($form['subject']) as $key) {
       $row = array();
-      $row[] = form_render($form['comments'][$key]);
-      $comment = form_render($form['comment'][$key]);
-      if (strlen($comment) > 512) {
-      	$class = ' class="comment-in-table"';
+      $row[] = drupal_render($form['comments'][$key]);
+      $comment = drupal_render($form['comment'][$key]);
+      $lines = count(preg_split('&<br|</p>&i', $comment));
+      if ($lines > 4 ||Ęstrlen($comment) > 512) {
+        $class = ' class="comment-in-table"';
       }
       else {
-      	$class = '';
+        $class = '';
       }
-      $row[] = form_render($form['subject'][$key]) . '<div'. $class. '>'. $comment. '</div>';
-      $row[] = form_render($form['username'][$key]);
-      $row[] = form_render($form['timestamp'][$key]);
-      $row[] = form_render($form['operations'][$key]);
-      $row[] = form_render($form['status'][$key]);
+      $row[] = drupal_render($form['subject'][$key]) . '<div'. $class. '>'. $comment. '</div>';
+      $row[] = drupal_render($form['username'][$key]);
+      $row[] = drupal_render($form['timestamp'][$key]);
+      if (user_access('administer comments')) {
+        $row[] = drupal_render($form['operations'][$key]);
+      }
+      $row[] = drupal_render($form['status'][$key]);
       $rows[] = $row;
     }
   }
@@ -241,10 +295,10 @@ function theme_commentapproval_admin_ove
 
   $output .= theme('table', $form['header']['#value'], $rows);
   if ($form['pager']['#value']) {
-    $output .= form_render($form['pager']);
+    $output .= drupal_render($form['pager']);
   }
 
-  $output .= form_render($form);
+  $output .= drupal_render($form);
 
   return $output;
-}
\ No newline at end of file
+}
