This will be a great feature for Drupal- I just need a little help with the php. When it's all worked out I come right back and post all the code :)

What I want to do is enable automatic comment moderation with the vote up/down module. Comments below a certain threshold will be hidden, but openable via javascript.

So I was thinking of putting the code in comment.tpl.php, but maybe it's better in comment.module? i don't know.

Something like this, but I don't know how to write the php:

<?php
if (($vote_result->value) < -2) {$toggle='none';}
else {$toggle='block';}

<a href="javascript:dm('toggle-<?php print $comment->cid; ?>');">Show/Hide Comment</a>
<div id="toggle-<?php print $comment->cid; ?>" style="display: <?php print $toggle; ?>">

I tried this out and it didn't work, but oh so close... all comments are hidden, I've tried several different variables for $votes_result->value all to no avail- if someone could just tell me how to pull that vote value it'll be all set

thanks in advance (- ;

Comments

justin3’s picture

maybe I was too wordy above... it all works except I cannot find the "vote result" value for the comment. It must be there somewhere as it's printed in each comment, even ajax updated with a new vote.

for this bit of code
if (($vote->points) < -2) then comment is hidden, else show

but $vote->points is not correct.

i've tried everything i can think of to pull the comment vote up/down score but I still haven't found it. can somebody throw me a bone, pretty please... i've got nasty trolls whose comments _really_ need to be hidden by default (-;

ola90@drupal.ru’s picture

I think you're looking for $vote_up_down_points->value.
Also, could you explain a bit more how your code above works? I could not make it work on my site - everything goes blank.

mukhsim’s picture

I already have something like this working. But voting has been broken with introduction of jquery. Comment viewing with collapsible comment body works so far.
Site: http://uz.dreamhosters.com/drupal5
Login: user1
Password: user1

I will post all code with instructions later.
As I said earlier, to get the whole thing working I need voting functionality implemented correctly.

See also: http://drupal.org/node/83640

Delf.

justin3’s picture

but i couldn't actually find where to vote on each comment- oh, that must be the jquery prob, but those js stars sure are nice

did you use the $comment->score variable for the score, or a karma variable?

do you happen to know anything about the vote up/down or votingapi modules- i've got my system all setup with vote up/down, but i can't find out how to pull the voting results variable... it's driving me nuts.

mukhsim’s picture

Unfortunately, I am not very familiar with vote up/down.
comment.module has function comment_render, I modified that function ,
I added variable $visible:
if ($comment->score >= $threshold_min) {$visible = 1;} else {$visible = 0;}

So function comment_render passes variable $visible when calls theme("comment_view"...

Down the road, function theme_comment_view($comment, $links = array(), $visible = 1) pases $visible too: $output .= theme('comment', $comment, $links, $visible);

Now, in phptemplate.engine, there is some modification:

  function phptemplate_comment($comment, $links = 0, $visible = 0) {
  return _phptemplate_callback('comment', array(
    'visible'   => $visible,
	'author'    => theme('username', $comment),

And comment.tpl.php looks like this:

 <!-- div class="comment<?php if ($comment->status == COMMENT_NOT_PUBLISHED) print ' comment-unpublished'; ?>"  -->
<div class="my_comment">
  
  <?php if ($visible) { print '<div class="comment-header">';}
        else {print '<div class="comment-header-folded">';} 

		print '<div   style="float: left; display: inline;"> <a href="javascript:toggle(\'' . 'commentdiv'  . $comment->cid . '\')">' . $comment->subject . '</a>' . ' (' . t('Score') . ': ' . $comment->score . ')' . '</div>';
        print '<div style="margin: 0 5px 0 0;  text-align: right;">' . $submitted . '</div>';
		
		print '</div>';
		?>
  
  <?php if ($visible) { print '<div class="comment-main" id="commentdiv' . $comment->cid . '">' ;}
        else { print '<div class="comment-main-folded" id="commentdiv' . $comment->cid . '"  style="display: none;" >' ;}
  ?>
  
  <div class="comment-left">
  
  <?php	
    if ($comment->name !== ""){
    print '<div class="author-name">' . theme('username', $comment) . '</div>';
    print  '<div class="picture">' . $picture . ' </div>
		      <!-- div class="author-posts">' . t('Joined:') . ' ' . $joined . ' <br/> ' . t('Posts:') . ' ' . $posts . '</div-->';
    }
    else 
      print '<div class="author-name">' . t('Anonymous') . '</div>';		
  ?>
  
  </div>
  
  <div class="comment-right">
    <div class="content">
        <?php print $content; ?>
    </div>		
  </div>
  
  
    <div class="comment-links"> <?php print $links ?></div>

</div>
</div>  
 

Don't forget to add toggle.js into modules/comment/ folder

Fully working version (last modified October 10, 2006) can be downloaded from:
http://uz.dreamhosters.com/drupal5.zip
http://uz.dreamhosters.com/drupal5_sql.zip
Don't forget to modify settings.php.

Delf.

morphir’s picture

what about having +1 and -1 rating. Just like digg.com. Where the comments gets collapsed when voting results reaches a negative value. And expanded as long they are positive. And when it reaches -20 or -30 it gets automatically deleted(require actions module?). That should provide some kick ass community driven comment moderation, right? :)

This will then generate points, which again can be user points(if you have user point module enabled)

And last, what about using the jQuery library?

morphir.com

SubWolf’s picture

Heh, digg doesn't have a strictly negative system, they either don't get enough diggs, or enough people tag them for burying. I get the jist though, just an anal comment.

As we're about to build some digg clone stuff for a client (partly utilizing packages already in use) I'll let ya know of any contributions we can make back in the process.

---
Santa Cruz Tech | "... Just Below My Skin, I'm Screamin'..."

morphir’s picture

A solution like this opens up for the community to moderate the comments. Of course if the comment should be deleted on -10 votes, -30 votes or -200 votes depends how many who participate in the community(site members). This value should be optionally set for each site.

The key thing here, is to bind a action to the article or the comment, if it reaches a specific amount of comment, push to frontpage or another "special" view.

let comment points affect overall user points..

morphir.com

patchak’s picture

Well vote up down module already does this with voting actions on 4.7... Once voting actions is ported to 5, you,ll have an eaasy way to make that site's comments moderated by the users...

Now if we could change the display of the comments when they are under a certain number of points... it would be perfect!

ola90@drupal.ru’s picture

I've finally managed to do this. I changed comment.tpl.php so that it wraps comments with rating below a certain threshold into a div which has display property set to none. Then I put a Javascript widget above the comments that allows users to decide if they want to see only "good" comments or all comments, switching the "bad" comments' display property.

morphir’s picture

you have any proof of concept?

Either as in real code or a live example?

morphir.com

ola90@drupal.ru’s picture

It finally works.
I added this to comment.tpl.php

<?php $vote_result = votingapi_get_voting_result('comment', $comment->cid, 'points', variable_get('vote_up_down_tag', 'vote'), 'sum');
      $vp = (int) $vote_result->value;
      if ($vp < 0) : ?>
      <div class="bad_comment">
      <?php endif; ?>
...all other code...
<?php if ($vp < 0) : ?>
</div>
<?php endif; ?>

So every comment with rating below 0 gets wrapped in a "bad_comment" div. (My website, which currently exists only at localhost, employs vote_up_down module allowing users to vote +1/-1 on comments. Different voting modes will require tweaking) I chose the threshold rating of 0 only as an example and for making testing easier.

I added this to template.php, in the "Comments" header (you may choose a different place and form):

<form id="show_or_not_comm">
<select name="show_or_not" onChange=\'setStyleByClass("DIV", "bad_comment", "display", this.value);\'>
<option selected value="none">'. t('Show only Good comments'). '
<option value="inline">'. t('Show all comments').'
</select>
</form>

This dropdown form allows the user to choose if he wants to see only good comments or all comments and changes "bad_comment" divs' display property accordingly. By default it is set to "none" in style.css

And finally I imported this script via page.tpl.php (borrowed it here http://developer.apple.com/internet/webcontent/examples/styley_source.html):

function setStyleByClass(t,c,p,v){
	var ie = (document.all) ? true : false;
	var elements;
	if(t == '*') {
		// '*' not supported by IE/Win 5.5 and below
		elements = (ie) ? document.all : document.getElementsByTagName('*');
	} else {
		elements = document.getElementsByTagName(t);
	}
	for(var i = 0; i < elements.length; i++){
		var node = elements.item(i);
		for(var j = 0; j < node.attributes.length; j++) {
			if(node.attributes.item(j).nodeName == 'class') {
				if(node.attributes.item(j).nodeValue == c) {
					eval('node.style.' + p + " = '" +v + "'");
				}
			}
		}
	}
}

It sets the property (p) of all elements of type (t) and class (c) to given value (v).

zigma’s picture

This is interesting. I think we can use this technique to hide/show individual comments as well.

zigma’s picture

This is interesting. I think we can use this technique to hide/show individual comments as well.

ola90@drupal.ru’s picture

You can, for example, replace comments that you want to hide with Javascript buttons ("Here be bad comment. Click if you really want to see it"). Then you need a different function - SetStyleByID, if I'm not mistaken.

stafford’s picture

Hi,

I have problems with the simple comment moderation function. Voting comments works fine (with the arrows). But the voting actions don't work. The comments are still published. Modules: vote up/down, actions, vote actions.

Settings:

value type: Points

tag: "emtpy"

function: sum

comparsion: is less than

value: 0

We have a lot of comments with negatives, but they are still published.

Did I make a mistake?