[HACK]Moderation of Comments
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic   printer-friendly view    b2evolution Forum Index -> Plugins & Extensions
View previous topic :: View next topic  
Author Message
EdB
/bb|[^b]{2}/

Joined: 05 Jan 2004
Posts: 7123
Reputation: 140.9 add or subtract from this member's reputationadd or subtract from this member's reputation
votes: 90

PostPosted: Tue Sep 06, 2005 14:50    Post subject: [HACK]Moderation of Comments Reply with quote

Over in the User Administration forum we have a hack that requires a user be logged in if they want to comment. I should lock that thread so no one adds to it since it's a hack and therefore belongs here. Anyway the guts of it from me and clang2 goes like this:
edb wrote:
Every skin has a skinname, and every skins/skinname/ folder has a bunch of files in it. The skins/ folder tends to have the same file names. Open skins/_feedback.php and look down around line 140 for this
Code:
   if( $disp_comment_form )
   {   // We want to display the comments form:
      if( $Item->can_comment() )
      { // User can leave a comment
and change it to this
Code:
   if( $disp_comment_form && is_logged_in() )
   {   // We want to display the comments form to a registered member:
      if( $Item->can_comment() )
      { // User can leave a comment


Save the file and upload it. Live long and prosper.

clang2 wrote:
I added an extra code block just above the code that Ed mentions. The point of the code is just to display a message that you have to be logged in before leaving a comment:
Code:

   if( $disp_comment_form && !is_logged_in() )
   {
      echo "You must be logged in to add a comment.<br />";
   }


Just a little cleaner.


There is another way to moderate comments that doesn't require registration and logging in: Just change the default status of comments from 'published' to 'draft', then hack it up so that the author of a post can decide to publish any given comment. This method depends on the post author being notified of comments (profile setting), or regularly checking to see if a new comment exists. Whatever! Using phpmyadmin you do
Code:
ALTER TABLE `evo_comments` CHANGE `comment_status` `comment_status` ENUM( 'published', 'deprecated', 'protected', 'private', 'draft' ) NOT NULL DEFAULT 'draft'
to accomplish that.

You will now have to make sure only published comments are displayed. Do that in either skins/_feedback.php or skins/skinname/_feedback.php by finding this:
Code:
while( $Comment = $CommentList->get_next() ) { // Begin looping through comments, trackbacks, pingbacks

$Comment->anchor() ?>
and changing it to this:
Code:
while( $Comment = $CommentList->get_next() ) { // Begin looping through comments, trackbacks, pingbacks

if( $Comment->status != 'published' ) {
   continue;
   }

$Comment->anchor() ?>

By the way this will do a weird thing that will help authors if they're looking. It will provide the complete number of comments where it says "11 comments" but will only display those the author has approved. Anyway, on with the hack.

You probably want to tell people comments are moderated, so do that in either skins/_feedback.php or skins/skinname/_feedback.php by finding this:
Code:
$comment_author_url = isset($_COOKIE[$cookie_url]) ? trim($_COOKIE[$cookie_url]) : '';
?>

<form action="<?php echo $htsrv_url ?>/comment_post.php" method="post" class="bComment">
and changing it to this:
Code:
$comment_author_url = isset($_COOKIE[$cookie_url]) ? trim($_COOKIE[$cookie_url]) : '';
?>

<div class="bSmallPrint">
<p>Comments are moderated by the post author.  Your comment will be published after the author approves it.</p>
</div>

<form action="<?php echo $htsrv_url ?>/comment_post.php" method="post" class="bComment">


Next thing is the author needs to be able to change a comment from draft to published. This will require editing 3 files. First in admin/_edit_showposts.php find:
Code:
                     // Display delete button if current user has the rights:
                     $Comment->delete_link( ' ', ' ', '#', '#', 'DeleteButton');

                  ?>
                  </div>
and make it be this:
Code:
                     // Display delete button if current user has the rights:
                     $Comment->delete_link( ' ', ' ', '#', '#', 'DeleteButton');

                      // Display publish button if current user has the rights:
                     if( $Comment->status == 'draft' ) {
                        $Comment->publish_link( ' ', ' ', '#', '#', 'PublishButton');
                        }
                  ?>
                  </div>

Next edit admin/edit_actions.php and find this:
Code:
      // Delete from Db:
      $edited_Comment->dbdelete();

      header ("Location: b2browse.php?blog=$blog&p=$comment_post_ID&c=1#comments");
      exit();


   default:
      // This can happen if we were displaying an action result, then the user logs out
and change it to this:
Code:
      // Delete from Db:
      $edited_Comment->dbdelete();

      header ("Location: b2browse.php?blog=$blog&p=$comment_post_ID&c=1#comments");
      exit();


   case 'publishcomment':
      /*
       * --------------------------------------------------------------------
       * Publish a draft comment:
       */
      param( 'comment_ID', 'integer', true );
      // echo $comment_ID;
      $edited_Comment = Comment_get_by_ID( $comment_ID );
    $comment_post_ID = $edited_Comment->Item->ID;
      $blog = $edited_Comment->Item->get( 'blog_ID' );

      // Check permission:
      $current_User->check_perm( 'blog_comments', '', true, $blog );

      // change comment from draft to published
      $sql = "UPDATE $tablecomments SET comment_status = 'published' WHERE comment_ID = $comment_ID";
      $DB->query( $sql );

      header ("Location: b2browse.php?blog=$blog&p=$comment_post_ID&c=1#comments");
      exit();


   default:
      // This can happen if we were displaying an action result, then the user logs out


Finally, edit b2evocore/_class_comment.php and add a new function between "function delete_link" and "function permalink":
Code:
   /**
    * Provide link to publish a comment if it is a draft (moderated)
    * This is a hack function to go with moderation of comments!!!
    *
    * {@internal Comment::publish_link(-)}}
    *
    * @param string to display before link
    * @param string to display after link
    * @param string link text
    * @param string link title
    * @param string class name
    */
   function publish_link( $before = ' ', $after = ' ', $text = '#', $title = '#', $class = '' )
   {
      global $current_User, $admin_url;
      
      if( ! is_logged_in() ) return false;
   
      if( ! $current_User->check_perm( 'blog_comments', '', false, $this->Item->get( 'blog_ID' ) ) )
      {   // If User has no permission to edit comments:
         return false;
      }
   
      if( $text == '#' ) $text = T_('Publish');
      if( $title == '#' ) $title = T_('Publish this comment');
      
      echo $before;
      echo '<a href="'.$admin_url.'/edit_actions.php?action=publishcomment&amp;comment_ID='.$this->ID;
      echo '" title="'.$title.'"';
      if( !empty( $class ) ) echo ' class="'.$class.'"';

      echo '>'.$text.'</a>';
      echo $after;
   
      return true;
   }




I suppose an astute hacker could make it so that unregistered commenters get moderated and registered members don't, or maybe registered members of a certain level or in a certain group don't, but that's too much for my tiny unmoderated brain. I've also learned the hard way that sooner or later someone out there will find a hole in my hack that needs plugging. Good thing hacking hacks on open source software is totally cool to do eh?

Note to self: now that you've been deemed a 'guru' you should change your sig file.


Last edited by EdB on Thu Oct 06, 2005 16:25; edited 3 times in total
Back to top
View user's profile Send private message
EdB
/bb|[^b]{2}/

Joined: 05 Jan 2004
Posts: 7123
Reputation: 140.9 add or subtract from this member's reputationadd or subtract from this member's reputation
votes: 90

PostPosted: Tue Sep 06, 2005 19:02    Post subject: Reply with quote

Okay, so maybe that's not enough. With the above hack when you go to your edit tab and select a post to edit the comments that are not published will have a 'Publish' button along with the standard 'Edit' and 'Delete' buttons. Problem is if you hit the link in your email message saying you got a new comment you won't have the 'Publish' option because you're in edit_comment mode. On that page you will see that the status is 'draft' but won't have any easy way to do anything about it. That's bad, but this additional hackage gives you a radio button to publish the comment.

Open admin/_edit_form.php and find this:
Code:
if ($action == "editcomment")
{
?>
   <fieldset>
      <legend><?php echo T_('Comment info') ?></legend>
      <p><strong><?php echo T_('Author') ?>:</strong> <?php echo $edited_Comment->author() ?></p>
      <p><strong><?php echo T_('Type') ?>:</strong> <?php echo $commentdata["comment_type"]; ?></p>
      <p><strong><?php echo T_('Status') ?>:</strong> <?php echo $commentdata["comment_status"]; ?></p>
      <p><strong><?php echo T_('IP address') ?>:</strong> <?php echo $commentdata["comment_author_IP"]; ?></p>

<?php
}
/* elseif ($action == "edit")
{
//       <p><strong>Pings:</strong> <?php echo in_array( 'pingsdone', $postdata["Flags"] ) ? 'Done':'Not done yet';
}*/
and change it to this:
Code:
if ($action == "editcomment")
{
?>
   <fieldset>
      <legend><?php echo T_('Comment info') ?></legend>
      <p><strong><?php echo T_('Author') ?>:</strong> <?php echo $edited_Comment->author() ?></p>
      <p><strong><?php echo T_('Type') ?>:</strong> <?php echo $commentdata["comment_type"]; ?></p>
      <p><strong><?php echo T_('Status') ?>:</strong> <?php echo $commentdata["comment_status"]; ?></p>
      <p><strong><?php echo T_('IP address') ?>:</strong> <?php echo $commentdata["comment_author_IP"]; ?></p>

<?php
} ?>

   <fieldset>
      <legend><?php echo T_('Status') ?></legend>

      <?php
      if( $current_User->check_perm( 'blog_post_statuses', 'published', false, $blog ) )
      {
      ?>
      <label title="<?php echo T_('Publish this Comment') ?>"><input type="radio" name="comment_status" value="published" class="checkbox" />
      <?php echo T_('Publish this Comment') ?></label><br />
      <?php
      }
      ?>
   </fieldset>

<?php
/* elseif ($action == "edit")
{
//       <p><strong>Pings:</strong> <?php echo in_array( 'pingsdone', $postdata["Flags"] ) ? 'Done':'Not done yet';
}*/


Now you've got a button, so edit admin/edit_actions.php again to make it work. Find this bit:
Code:
      if( $edit_date && $current_User->check_perm( 'edit_timestamp' ))
      {   // We use user date
         $edited_Comment->set( 'date', date('Y-m-d H:i:s', mktime( $hh, $mn, $ss, $mm, $jj, $aa ) ) );
      }

      $edited_Comment->dbupdate();   // Commit update to the DB

       $comment_post_ID = $edited_Comment->Item->ID;
      header ("Location: b2browse.php?blog=$blog&p=$comment_post_ID&c=1#comments"); //?a=ec");
      exit();
and change it to this:
Code:
      if( $edit_date && $current_User->check_perm( 'edit_timestamp' ))
      {   // We use user date
         $edited_Comment->set( 'date', date('Y-m-d H:i:s', mktime( $hh, $mn, $ss, $mm, $jj, $aa ) ) );
      }

      $edited_Comment->dbupdate();   // Commit update to the DB

      if( $comment_status == 'published' )
      {   // change comment from draft to published
         $sql = "UPDATE $tablecomments SET comment_status = 'published' WHERE comment_ID = $comment_ID";
         $DB->query( $sql );
      }

       $comment_post_ID = $edited_Comment->Item->ID;
      header ("Location: b2browse.php?blog=$blog&p=$comment_post_ID&c=1#comments"); //?a=ec");
      exit();

Now you have moderated comments that the post author can delete or publish two different ways.


Last edited by EdB on Thu Oct 06, 2005 16:27; edited 1 time in total
Back to top
View user's profile Send private message
Nate
Docs team
Docs team

Joined: 28 Jul 2004
Posts: 385
Reputation: 49.8Reputation: 49.8Reputation: 49.8Reputation: 49.8Reputation: 49.8 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Thu Oct 06, 2005 15:51    Post subject: Reply with quote

Thank you so much for this moderation hack. I'm overseeing my school's website blog (http://www.loganelementary.com) and it's very nice to be able to screen comments before they reach the students.

This was quite an involved hack, though. I'm very impressed that you were able to pull this off. Thanks again!
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
johnnyeng
New Poster
New Poster

Joined: 13 Jul 2004
Posts: 26
Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Fri Oct 28, 2005 16:54    Post subject: nice hackage Reply with quote

Hello there EdB,

I too am very thankful for this hack. It is wonderful.
I've implemeneted the code you supplied and been over it several times.
Everything seems to work pretty well except for the fact that when I change from 'Draft' status to 'Published' in the back office the comment_content field in my database is being stripped.

Do you have any ideas as to why this would be happening?

Thanks much. Smile

johnnyeng
Back to top
View user's profile Send private message
EdB
/bb|[^b]{2}/

Joined: 05 Jan 2004
Posts: 7123
Reputation: 140.9 add or subtract from this member's reputationadd or subtract from this member's reputation
votes: 90

PostPosted: Fri Oct 28, 2005 18:48    Post subject: Reply with quote

No clue! This, like most of the hacks I do, is something I don't actually use. Most of the time I do a pretty good job of testing my stuff, but I can only test on one server with one configuration. Not that I'm saying it's a server issue!

Give me a bit of a clue here. You mean the comment content is actually disappearing from the database? Like, you still have a comment but it is completely empty? What happens when you visit your blog after approving a comment? Do you see that a comment exists but that there is no comment content? IIRC b2evolution won't allow an empty comment, but that doesn't mean my hack isn't eating content.

I am still in the process of replacing my computer after the last one blew up. I don't have a local copy of my webs and I haven't figured out how to make filezilla work again, but as soon as I can I'll re-do this hack and make sure to test it with a specific eye towards seeing if the comment content gets wiped out.
Back to top
View user's profile Send private message
johnnyeng
New Poster
New Poster

Joined: 13 Jul 2004
Posts: 26
Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Mon Oct 31, 2005 10:48    Post subject: Reply with quote

Thanks for the reply EdB. Smile

Yes, the content is actually disappearing from the database.
When the comment is first submitted, the database is populated correctly. The comment_content is there, while in draft format.
The weirdness happens when I try to edit the comment.
When I am here:
Code:
'../b2browse.php?blog=8&p=44&c=1#comments'

and hit the edit button,
the content seems to disappear, or at least does not show up in the Comment Text box here:
Code:
'../b2edit.php?action=editcomment&comment=18'

Somehow it's getting stripped. When I look at the database it's just gone. The comment_content field is totally empty.

Also, the comment does exist when I visit the blog after approval, it just does not have any content. Something like this:

Comments:
Comment from: johnnyeng [Visitor]
Posted on: October 17, 2005 @ 17:52 CST

Again thanks for your help with this EdB, I really appreciate it.

johnnyeng
Back to top
View user's profile Send private message
Nate
Docs team
Docs team

Joined: 28 Jul 2004
Posts: 385
Reputation: 49.8Reputation: 49.8Reputation: 49.8Reputation: 49.8Reputation: 49.8 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Mon Dec 19, 2005 10:59    Post subject: Reply with quote

After upgrading to 1.6 I'd like to reapply this comment moderation hack. Do you know if it will still work as shown here?
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
johnnyeng
New Poster
New Poster

Joined: 13 Jul 2004
Posts: 26
Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7Reputation: 73.7 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Mon Dec 19, 2005 11:46    Post subject: Reply with quote

Hi Nate, I can't be sure if it will work with the new version.
The blog I have it running on is 0.9.1 "Dawn"

Sorry I couldn't be of more help.

johnnyeng
Back to top
View user's profile Send private message
balupton
1.8 & 1.9 expert

Joined: 22 Jun 2005
Posts: 2087
Reputation: 138 add or subtract from this member's reputationadd or subtract from this member's reputation
votes: 24

PostPosted: Mon Dec 19, 2005 11:59    Post subject: Reply with quote

How bout some code that requires the user to be a member of the blog that the post is in to allow the user to comment?
Would be great!

Oh and i love the sayings that you throw into your code:
//Live long and prosper
//If you remove this, the sky will fall down on your head - Kubrick2evo

Keep it up Wink

_________________
Products & Services:
ShareHouseHQ - Shared expenses made easy., Web 2.0 Architect, jQuery Lightbox.
- The best user reports problems, don't be sorry, be proud! Smile
Back to top
View user's profile Send private message Visit poster's website
nucsa
New Poster
New Poster

Joined: 01 Jan 2006
Posts: 10
Reputation: 4.3Reputation: 4.3Reputation: 4.3Reputation: 4.3 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Sun Jan 01, 2006 19:47    Post subject: Reply with quote

I would also like to know if there is any way for this hack to work in the new version.
I had it working on the old ver. but don't how on the new.

I just want people to have to register before they leave a comment.

Thanks
Back to top
View user's profile Send private message
nucsa
New Poster
New Poster

Joined: 01 Jan 2006
Posts: 10
Reputation: 4.3Reputation: 4.3Reputation: 4.3Reputation: 4.3 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Mon Jan 02, 2006 0:01    Post subject: Reply with quote

Ok the codes in the first post do work with the new version 1.6
Back to top
View user's profile Send private message
EdB
/bb|[^b]{2}/

Joined: 05 Jan 2004
Posts: 7123
Reputation: 140.9 add or subtract from this member's reputationadd or subtract from this member's reputation
votes: 90

PostPosted: Mon Jan 02, 2006 9:05    Post subject: Reply with quote

Cool! Thanks for testing and sharing what you learned.
Back to top
View user's profile Send private message
kskhater
Hooked :)
Hooked :)

Joined: 15 Nov 2005
Posts: 235
Reputation: 50.5Reputation: 50.5Reputation: 50.5Reputation: 50.5Reputation: 50.5 add or subtract from this member's reputationadd or subtract from this member's reputation
votes: 3

PostPosted: Tue Jan 03, 2006 2:43    Post subject: Publish checkbox does not have any effect! Reply with quote

In the code below from admin/_edit_form.php does not change the status if one saves the comment. One must use the Publish button, why?

PHP:
if ($action == "editcomment")
{
?>
   <fieldset>
      <legend><?php echo T_('Comment info'?></legend>
      <p><strong><?php echo T_('Author'?>:</strong> <?php echo $edited_Comment->author() ?></p>
      <p><strong><?php echo T_('Type'?>:</strong> <?php echo $commentdata["comment_type"]; ?></p>
      <p><strong><?php echo T_('Status'?>:</strong> <?php echo $commentdata["comment_status"]; ?></p>
      <p><strong><?php echo T_('IP address'?>:</strong> <?php echo $commentdata["comment_author_IP"]; ?></p>

<?php
?>

   <fieldset>
      <legend><?php echo T_('Status'?></legend>

      <?php
      
if( $current_User->check_perm'blog_post_statuses''published'false$blog ) )
      {
      
?>
      <label title="<?php echo T_('Publish this Comment'?>"><input type="radio" name="comment_status" value="published" class="checkbox" />
      <?php echo T_('Publish this Comment'?></label><br />
      <?php
      
}
      
?>
   </fieldset>

<?php
/* elseif ($action == "edit")
{
//       <p><strong>Pings:</strong> <?php echo in_array( 'pingsdone', $postdata["Flags"] ) ? 'Done':'Not done yet';
}*/ 

_________________
Search and you shall find.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
paisley
New Poster
New Poster

Joined: 24 Jan 2006
Posts: 4
Reputation: 3.4Reputation: 3.4Reputation: 3.4 add or subtract from this member's reputationadd or subtract from this member's reputation

PostPosted: Tue Jan 24, 2006 14:20    Post subject: comments Reply with quote

EdB -- what file contains this?

There is another way to moderate comments that doesn't require registration and logging in: Just change the default status of comments from 'published' to 'draft', then hack it up so that the author of a post can decide to publish any given comment. This method depends on the post author being notified of comments (profile setting), or regularly checking to see if a new comment exists. Whatever! Using phpmyadmin you do
Quote:
Code:
ALTER TABLE `evo_comments` CHANGE `comment_status` `comment_status` ENUM( 'published', 'deprecated', 'protected', 'private', 'draft' ) NOT NULL DEFAULT 'draft'
to accomplish that.




also i got the error after following the instructions above.
Fatal error: Call to a member function on a non-object in /home/httpd/vhosts/blogcommscope.com/httpdocs/b2evolution/admin/_edit_showposts.php on line 168

ver. 0.9.0.11
Back to top
View user's profile Send private message
EdB
/bb|[^b]{2}/

Joined: 05 Jan 2004
Posts: 7123
Reputation: 140.9 add or subtract from this member's reputationadd or subtract from this member's reputation
votes: 90

PostPosted: Tue Jan 24, 2006 18:29    Post subject: Reply with quote

That bit doesn't get put in any file - you use something like phpmyadmin to alter your mysql database.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    b2evolution Forum Index -> Plugins & Extensions All times are GMT - 5 Hours
Goto page 1, 2, 3  Next
Page 1 of 3


 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
b2evolution Support Forum RSS Feed Forums powered by php Bulletin Board