Hi,

The comments awaiting moderation are not published yet, so they do not appear to anyone. How can I make the comments awaiting moderation appear to the author only? Currently just some text appears that says "Your comment is awaiting moderation." and that's it. It would be nice if the author could see what he posted.

For example with modr8 module the new nodes that are awaiting moderation CAN be seen by noone with the exception of the author. How can I make it the same for the comments?

Steven

Comments

WorldFallz’s picture

Believe it or not, there's a module for it: http://drupal.org/project/su_comments. ;-)

steven9’s picture

Thank you WorldFallz for your reply. I was ecstatic for a minute hoping this module will solve my problem. But it is not exactly what I need.

With this module when a user posts a new comment, the comment appears to him as part of the node itself, and the funny thing is that, if he clicks on a different node, the initial comment appears in the lower part of the second node as well etc. Nomatter which node he is viewing, the comment is there. Not pretty at all.

I would like the comment to appear like a normal comment, in it's proper node, at it's proper location in the list of other comments and in the "Recent comments" also. But just for the author.

WorldFallz’s picture

Just because a module has a bug, doesn't mean it's not the module you need, lol. But my bad-- I should have mentioned there's a fix for this in the module's issue queue.

steven9’s picture

I added the patch. The comment appears now on the right node, but appended inside the node, and I needed it to be like a normal comment that appears as an independent comment in the right spot in the comment list after the node, in Recent comments (only for the author) etc. Do you have another idea how I can do that?

steven9’s picture

I just noticed that the admin sees all the unpublished comments as I would like it to be.

So there must be something in the comments module where it says something like show all the published comments to those who have the right permissions and if admin is logged in, show all published and unpublished posts.

To this I would need to add something like "to those with the right permissions show all published comments PLUS the unpublished ones that the user is the author of".

WorldFallz’s picture

I believe this is tied to the administer comments permission-- but as you describe, users with that permission see all comments. Because of core permissions and the way comment module works it's not easy to circumvent and why the su_comments module works the way it does.

You might be able to use hook_nodeapi to override comment display, but I'm not sure. The only other thing you can do, and it's not recommended, is hack comment module.

steven9’s picture

I found the function that I would need to modify - comment_render. And I think it is particularly this part here:

// Multiple comment view
$query_count = 'SELECT COUNT(*) FROM {comments} c WHERE c.nid = %d';
$query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';

$query_args = array($nid);
if (!user_access('administer comments')) {
$query .= ' AND c.status = %d';
$query_count .= ' AND c.status = %d';
$query_args[] = COMMENT_PUBLISHED;
}

What this does is get all the comments from the database associated with a certain node. Then if the user logged-in does NOT have administer rights, leave only the published comments. To this I deed to add "but leave the unpublished comments that the user logged in is the author"

How can I write that?

WorldFallz’s picture

Yeah-- I found that too. Try the following:

if (!user_access('administer comments')) {
  $query .= ' AND c.status = %d OR c.uid = %d';
  $query_count .= ' AND c.status = %d';
  $query_args[] = COMMENT_PUBLISHED;
  $query_args[] = $user->uid;
}
steven9’s picture

I played around with it and so far this is the lucky combination :)

if (!user_access('administer comments')) {
$query .= ' AND (c.uid = %d OR c.status = %d)';
$query_count .= ' AND (c.uid = %d OR c.status = %d)';
$query_args[] = $user->uid;
$query_args[] = COMMENT_PUBLISHED;
}

It appears to be working, I will have to check it in some more situations.

WorldFallz, thank you very much for all your help, you are are real blessing on the forum.

WorldFallz’s picture

Excellent-- glad it worked out.

And you're welcome-- happy to help ;-)

WorldFallz’s picture

one other thing-- the 'reply' link appears on the unpublished comment but doesn't work. You can either test for comment status in comment.tpl.php and only print links for published comments (which will prevent the 'edit' link from appearing as well). Or make one additional change to comment module (around line 845) to prevent just the reply link from appearing on unpublished comments:

if ($comment->status == 0) {
  $links['comment_reply'] = array(
    'title' => t('reply'),
    'href' => "comment/reply/$comment->nid/$comment->cid"
   );
}
WorldFallz’s picture

For convenience, here are the changes in the form of a patch:

Index: modules/comment/comment.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v
retrieving revision 1.617.2.14
diff -u -p -r1.617.2.14 comment.module
--- modules/comment/comment.module	1 Mar 2010 09:44:31 -0000	1.617.2.14
+++ modules/comment/comment.module	2 Mar 2010 20:20:15 -0000
@@ -272,7 +272,7 @@ function comment_node_type($op, $info) {
  * Implementation of hook_perm().
  */
 function comment_perm() {
-  return array('access comments', 'post comments', 'administer comments', 'post comments without approval');
+  return array('access comments', 'post comments', 'administer comments', 'post comments without approval', 'view own unpublished comments');
 }
 
 /**
@@ -842,10 +842,12 @@ function comment_links($comment, $return
           'href' => "comment/edit/$comment->cid"
         );
       }
-      $links['comment_reply'] = array(
-        'title' => t('reply'),
-        'href' => "comment/reply/$comment->nid/$comment->cid"
-      );
+      if ($comment->status == COMMENT_PUBLISHED) {
+        $links['comment_reply'] = array(
+          'title' => t('reply'),
+          'href' => "comment/reply/$comment->nid/$comment->cid"
+        );
+      }
     }
     else {
       $node = node_load($comment->nid);
@@ -960,11 +962,17 @@ function comment_render($node, $cid = 0)
       $query = 'SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.signature_format, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.nid = %d';
 
       $query_args = array($nid);
-      if (!user_access('administer comments')) {
+      if (!user_access('administer comments') && !user_access('view own unpublished comments')) {
         $query .= ' AND c.status = %d';
         $query_count .= ' AND c.status = %d';
         $query_args[] = COMMENT_PUBLISHED;
       }
+      elseif (user_access('view own unpublished comments')) {
+        $query .= ' AND (c.status = %d OR c.uid = %d)';
+        $query_count .= ' AND c.status = %d';
+        $query_args[] = COMMENT_PUBLISHED;
+        $query_args[] = $user->uid;     
+      }
 
       if ($order == COMMENT_ORDER_NEWEST_FIRST) {
         if ($mode == COMMENT_MODE_FLAT_COLLAPSED || $mode == COMMENT_MODE_FLAT_EXPANDED) {

I ended up doing this with an added comment permission of "view own unpublished comments".

steven9’s picture

WorldFallz, the patch looks great. But in my trials I tried this part

+ $query .= ' AND c.status = %d OR c.uid = %d';
+ $query_count .= ' AND c.status = %d';

and it gives funny results because the OR goes against ALL the ANDs before, but just the preceding one, thus you need the parentheses. Query_count also needs the OR. I have something more like this:

+ $query .= ' AND (c.status = %d OR c.uid = %d)';
+ $query_count .= ' AND (c.status = %d OR c.uid = %d)';

WorldFallz’s picture

odd-- i didn't notice any flakiness without the parens, but they're easy enough to add(i edited the patch and put them in). As for the node count-- I didn't want it to reflect unpublished nodes so I didn't alter that query, obviously ymmv. I've also got this working on a d7 dev site-- I'm going to post it as a patch, but at this point it wouldn't be viable until d8.

steven9’s picture

Actually you're right. Parentheses are not necessary in this case. They were necessary in my case because my solution was a bit different but I like yours more.

chintan4u’s picture

Thanks....! Folks.
Nice patch....worked exactly.
Keep rocking ... \m/

-
Chintan Umarani
Drupal Developer
www.umarani.com