Social Web CMS
February 09, 2010, 06:43:58 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: We have reinvented SocialWebCMS as HotaruCMS, which is available to download from http://hotarucms.org.
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Comment Approval Module v.0.1  (Read 2511 times)
Nick
Administrator
Hero Member
*****
Offline Offline

Posts: 668



View Profile WWW
« on: February 10, 2009, 05:15:19 am »

Comment Approval v0.1
Created by: Nick Ramsay
Created on: 2009/02/10

This is just a first version, but give it a try if you're brave. Leave a comment to let me know if it works okay or if I've got some bugs to fix. Sorry for all the edits you have to make, steps 2, 3 and 4 are the main ones. 5, 6 and 7 just stop the comments showing up in the sidebar and Live pages.

Description
Puts comments from a new user into moderation, and notifies the administrator via email and a "pending" section in Admin.

How it works
- The comment form shows the message "Please note that comment moderation is enabled" for users with no previously approved comments.
- When that user submits a comment, it doesn't appear. However, the comment with approve/delete links is sent to 'god' or 'admin' users via email.
- 'god' users can set where they want the email notification to go through the Admin panel.
- The approve/delete links in the email (also shown on pending comments listed in Admin) perform the action in one step - no confirmation step!
- 'admin' users can moderate comments, but are not shown the email notification settings. Only 'god' users see those.

How to change the minimum number of comments needed for auto-approval
Open comment_approval_settings.php and change the number in the first "define" line. By default, 1 comment must be manually approved before being auto-approved.

Instructions
1. Upload the comment_approval folder to your modules folder. Install it from Module Management in Admin.
2. Add the following at the very bottom of /templates/your_template/comment_form.tpl, just before the closing "fieldset":
Code:
{checkActionsTpl location="tpl_comment_form_end"}

3. Open /templates/your_template/comment_show.tpl and add the opening "if" at the very top, and the closing "if" at the very bottom:
Code:
{if $comment_status == "approved"}
Code:
{/if}

4. Open /libs/comment.php and find:
Code:
function fill_smarty($smarty){
Add the following anywhere near the top of that function:
Code:
$vars=array('comment_status' => '', 'comment_id' => $this->id);
check_actions('comment_status', $vars);
$smarty->assign('comment_status', $vars['comment_status']);

5. To prevent pending comments showing up in the sidebar, open /sidebar_comments.php and put the following immediately before ORDER BY in the line beginning $res =
Code:
AND comment_status != 'pending'

6. To prevent pending comments showing up on the main Live page, open /live2.php and find:
Code:
function get_comments($time) {
Add the following immediately before "order by" in the line beginning $res =
Code:
AND comment_status != 'pending'

7. To prevent pending comments showing up on the Live Comments page (live_comments.php), find the following:
Code:
$rows=$db->get_var("SELECT count(*) as count $from_where $order_by");
$comments=$db->get_results("$select $from_where $order_by LIMIT $offset,$top_users_size");
Replace those two lines with these:
Code:
$rows=$db->get_var("SELECT count(*) as count $from_where WHERE comment_status != 'pending' $order_by");
$comments=$db->get_results("$select $from_where WHERE comment_status != 'pending' $order_by LIMIT $offset,$top_users_size");

If you are using the live module:
Open /modules/live/live_main.php and find:
Code:
function live_get_comments($time) {
Add the following immediately before "order by" in the line beginning $res =
Code:
AND comment_status != 'pending'

Revision History
Nick 2009/02/10 - v0.1 First version

* comment_approval.zip (24.74 KB - downloaded 87 times.)
« Last Edit: February 15, 2009, 08:49:37 pm by Nick » Logged

Reinventing SWCMS at HotaruCMS.org - testers, designers and developers wanted!
steveoc
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #1 on: February 15, 2009, 03:06:55 pm »

I've followed all the steps up to 7. It isn't clear which file I should edit in this step.

Thanks for the module!

Steve
Logged
steveoc
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #2 on: February 15, 2009, 03:45:49 pm »

Never mind--live_comments.php

It seems to work fine!

This is a big step toward making use of this software in the K12 environment viable!

Thanks,

Steve
Logged
bbrian017
Full Member
***
Offline Offline

Posts: 190



View Profile WWW
« Reply #3 on: September 22, 2009, 07:16:40 am »

in my sidebar_comments.php I only have this,

Code:
{* ----- show the sidebar stories box ----- *}
{php}include(mnmpath.'sidebar_comments.php');{/php}
{* ---------------------------------------- *}

In my live2.php I have way to many $res what one specifically?

Code:
<?php
// The source code packaged with this file is Free Software.
// Portions are Copyright (C) 2005 by Ricardo Galli <gallir at uib dot es>.
// Portions are Copyright (C) 2005 - 2008 by Pligg <www.pligg.com>.
// Portions are Copyright (C) 2008 by the Social Web CMS Team <swcms@socialwebcms.com>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here: http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".

include('config.php');
include(
mnminclude.'link.php');

// number of items to show on the page
$max_items items_to_show;

if(!(
$time=check_integer('time'))) {
$time 0;


header('Content-Type: text/plain; charset=UTF-8');

$last_timestamp 0;

get_votes($time);
get_new_stories($time);
get_new_published($time);
get_comments($time);

if(
$last_timestamp == 0$last_timestamp time();

echo 
"timestamp=$last_timestamp;\n";
if(
count($events) < 1) exit;
ksort($events);
$keys array_reverse(array_keys($events));
$lines min(count($keys), $max_items);

$counter=0;
echo 
"new_items=$lines;\n";
echo 
"new_data = ([";
foreach (
$keys as $key) {
echo "{" $events[$key] . "}, ";
$counter++;
if($counter>=$max_items) {
echo "]);";
exit();
}
}
echo 
"]);";


// get latest votes
function get_votes($time) {
global $db$events$last_timestamp;
$res $db->get_results("select vote_id, unix_timestamp(vote_date) as timestamp, vote_value, vote_ip, vote_user_id, link_id, link_title, link_url, link_status, link_date, link_published_date, link_votes, link_author from " table_votes ", " table_links " where vote_date > from_unixtime($time) and link_id = vote_link_id and vote_user_id != link_author and link_status!='discard' and vote_type = 'links' order by vote_date desc limit 20");
if (!$res) return;
foreach ($res as $event) {
if(substr($event->vote_ip03) != '0.0'){
$id=$event->vote_id;
$uid $event->vote_user_id;
if($uid 0) {
$user $db->get_var("select user_login from " table_users " where user_id = $uid");
} else {
$userpreg_replace('/\.[0-9]+$/'''$event->vote_ip);
}
if ($event->vote_value 0) {
$type 'report';
$who $user;
}
else if ($event->vote_value >= 0) {
$type 'vote';
$who $user;

else { 
$type 'problem';
$who $event->vote_value;
}
$status =  get_status($event->link_status);
$key $event->timestamp ':votes:'.$id;
if(Voting_Method == 2){$votes $event->link_votes/2;}
      else {
$votes $event->link_votes;}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp $last_timestamp$last_timestamp $event->timestamp;
}
}
}

// get latest stories
function get_new_stories($time) {
global $db$events$last_timestamp;
$res $db->get_results("select unix_timestamp(link_date) as timestamp, user_login, link_author, link_id, link_title, link_url, link_status, link_date, link_votes from " table_links ", " table_users " where link_status='queued' and  link_date > from_unixtime($time) and user_id=link_author order by link_date desc limit 20");
if (!$res) return;
foreach ($res as $event) {
$id=$event->link_id;
$uid $event->link_author;
$type 'new';
$who $event->user_login;
$status =  get_status($event->link_status);
$key $event->timestamp ':new:'.$id;
if(Voting_Method == 2){$votes $event->link_votes/2;}
    else {
$votes $event->link_votes;}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp $last_timestamp$last_timestamp $event->timestamp;
}
}

// get latest published stories
function get_new_published($time) {
global $db$events$last_timestamp;
$res $db->get_results("select unix_timestamp(link_published_date) as timestamp, user_login, link_author, link_id, link_title, link_url, link_status, link_date, link_votes from " table_links ", " table_users " where link_status='published' and link_published_date > from_unixtime($time) and user_id=link_author order by link_published_date desc limit 20");
if (!$res) return;
foreach ($res as $event) {
$id=$event->link_id;
$uid $event->link_author;
$type 'published';
$who $event->user_login;
$status =  get_status($event->link_status);
$key $event->timestamp ':published:'.$id;
if(Voting_Method == 2){$votes $event->link_votes/2;}
    else {
$votes $event->link_votes;}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp $last_timestamp$last_timestamp $event->timestamp;
}
}

// get latest comments
function get_comments($time) {
global $db$events$last_timestamp;
$res $db->get_results("select comment_id, unix_timestamp(comment_date) as timestamp, user_login, comment_user_id, link_author, link_id, link_title, link_url, link_status, link_date, link_published_date, link_votes from " table_comments ", " table_links ", " table_users " where comment_date > from_unixtime($time) and link_id = comment_link_id and link_status!='discard' and user_id=comment_user_id order by comment_date desc limit 20");
if (!$res) return;
foreach ($res as $event) {
$id=$event->comment_id;
$uid=$event->comment_user_id;
$type 'comment';
$who $event->user_login;
$status =  get_status($event->link_status);
$key $event->timestamp ':comment:'.$id;
if(Voting_Method == 2){$votes $event->link_votes/2;}
    else {
$votes $event->link_votes;}
$events[$key] = 'ts:"'.$event->timestamp.'", type:"'.$type.'", votes:"'.$votes.'", link:"'.$event->link_id.'", title:"'.addslashes($event->link_title).'", who:"'.addslashes($who).'", status:"'.$status.'", uid:"'.$uid.'"';
//echo "($key)". $events[$key];
if($event->timestamp $last_timestamp$last_timestamp $event->timestamp;
}
}

function 
get_status($status) {
switch ($status) {
case 'published':
$status _('published');
break;
case 'queued':
$status _('queued');
break;
case 'discard':
$status _('discard');
break;
}
return $status;
}

function 
error($mess) {
header('Content-Type: text/plain; charset=UTF-8');
echo "ERROR: $mess";
die;
}
?>


« Last Edit: September 22, 2009, 07:21:39 am by bbrian017 » Logged

Nick
Administrator
Hero Member
*****
Offline Offline

Posts: 668



View Profile WWW
« Reply #4 on: September 22, 2009, 07:38:47 am »

1. Look in sidebar_comments.php in your root directory, not sidebar_comments.tpl in your template.

2. The last note about $res is for people using the Live module, not the default Live page, so you can just ignore that.

EDIT: Sorry, you're talking about step 6? There's only one $res in the get_comments function:

Code:
// get latest comments
function get_comments($time) {
global $db, $events, $last_timestamp;
$res = $db->get_results("select comment_id, unix_timestamp(comment_date) as timestamp, user_login, comment_user_id, link_author, link_id, link_title, link_url, link_status, link_date, link_published_date, link_votes from " . table_comments . ", " . table_links . ", " . table_users . " where comment_date > from_unixtime($time) and link_id = comment_link_id and link_status!='discard' and user_id=comment_user_id order by comment_date desc limit 20");
if (!$res) return;
« Last Edit: September 22, 2009, 07:42:43 am by Nick » Logged

Reinventing SWCMS at HotaruCMS.org - testers, designers and developers wanted!
bbrian017
Full Member
***
Offline Offline

Posts: 190



View Profile WWW
« Reply #5 on: September 22, 2009, 07:55:09 am »

Thanks Nick,

These spamer guys never give  up. I'm running both your spam and submit mods here,

http://www.yoursourceforinfo.com

A little project site of mine! Hey when I deleted the spam comment it was sent right back to the spam admin page.

Can this also happen when we kilspam someone with the submit module?
Logged

Nick
Administrator
Hero Member
*****
Offline Offline

Posts: 668



View Profile WWW
« Reply #6 on: September 22, 2009, 08:09:03 am »

Killspamming through the Submission Approval module works through the default killspam admin pages in SWCMS which redirect to the User Management page by default:

/admin/admin_users.php: Line 415?

Code:
header("Location: ".my_pligg_base."/admin/admin_users.php");

That's what you would need to change. Good luck! Wink
Logged

Reinventing SWCMS at HotaruCMS.org - testers, designers and developers wanted!
bbrian017
Full Member
***
Offline Offline

Posts: 190



View Profile WWW
« Reply #7 on: September 25, 2009, 07:32:30 am »

Nick,

On the story approval it notifies the user their story is on hold.

Does this plugin do the same re the comment?
Logged

Nick
Administrator
Hero Member
*****
Offline Offline

Posts: 668



View Profile WWW
« Reply #8 on: September 25, 2009, 07:44:18 am »

Not quite. It shows a message below the comment form that says "Note: Comment moderation is enabled" or something like that.

Important! Read the latest posts on the thread about comments not appearing in the correct order. They apply to this module.
Logged

Reinventing SWCMS at HotaruCMS.org - testers, designers and developers wanted!
bbrian017
Full Member
***
Offline Offline

Posts: 190



View Profile WWW
« Reply #9 on: September 25, 2009, 07:55:09 am »

Not quite. It shows a message below the comment form that says "Note: Comment moderation is enabled" or something like that.

Important! Read the latest posts on the thread about comments not appearing in the correct order. They apply to this module.

Seems you are right!

http://www.blogengage.com/story.php?title=blogcatalog-does-bloggers-dirty-again#comments

I'm having that affect now after installing this plugin.
Logged

bbrian017
Full Member
***
Offline Offline

Posts: 190



View Profile WWW
« Reply #10 on: September 25, 2009, 09:09:32 am »

Nick I cannot seem to get the sidebar comments to work seeing I have a custom template.

I added the code can you suggest how to edit that file?

Code:
<?php
// The source code packaged with this file is Free Software, Copyright (C) 2005 by
// Ricardo Galli <gallir at uib dot es>.
// It's licensed under the AFFERO GENERAL PUBLIC LICENSE unless stated otherwise.
// You can get copies of the licenses here:
//         http://www.affero.org/oagpl.html
// AFFERO GENERAL PUBLIC LICENSE is also included in the file called "COPYING".
// -------------------------------------------------------------------------------------

include_once('Smarty.class.php');
$main_smarty = new Smarty;

include_once(
'config.php');
include_once(
mnminclude.'html1.php');
include_once(
mnminclude.'link.php');
include_once(
mnminclude.'tags.php');
include_once(
mnminclude.'search.php');
include_once(
mnminclude.'smartyvariables.php');
// -------------------------------------------------------------------------------------
global $the_template$main_smarty$db;

$body '';
$res "select comment_content,comment_date,comment_id,link_id, ".table_links.".link_title_url, ".table_links.".link_category from ".table_comments.",".table_links." WHERE comment_link_id = link_id AND comment_status != 'pending' ORDER BY comment_date DESC limit ".comments_size_sidebar."";
$list_comments $db->get_results($res);
if(
$list_comments)
{
    foreach(
$list_comments as $row){            
        if (
$row->link_title_url == ""){
            
$story_url getmyurl("story"$row->link_id);            
        } else {
            
$story_url getmyurl("storyURL"comments_category_safe_name($row->link_category), urlencode($row->link_title_url), $row->link_id);            
        }

        
$main_smarty->assign('comment_url'$story_url."#c".$row->comment_id);
        
$main_smarty->assign('comment_text'ShortenText(save_text_to_html($row->comment_content)));
        
$main_smarty->assign('comment_date'date("M d, y h:i A",strtotime($row->comment_date)));
        
$body .= $main_smarty->fetch($the_template '/sidebar_comments.tpl');        
    }
}
$main_smarty->assign('live_url'getmyurl("comments"));
$main_smarty->assign('sc_body'$body);
$main_smarty->display($the_template '/sidebar_comments_wrapper.tpl');

// determine the amount of characters to show for each comment    
function ShortenText($text) {
  
$chars comments_length_sidebar;

  
$text $text." ";
  
$text substr($text,0,$chars);
  
$text substr($text,0,strrpos($text,' '));
  
$text $text."...";

  return 
$text;
  }        
function 
comments_category_safe_name($category) {
    
// $the_cats is set in /libs/smartyvariables.php

    
global $dblang$the_cats;

    foreach(
$the_cats as $cat){
        if(
$cat->category_id == $category && $cat->category_lang == $dblang)
        { 
            return 
$cat->category_safe_name
        }
    }
}
?>
Logged

Nick
Administrator
Hero Member
*****
Offline Offline

Posts: 668



View Profile WWW
« Reply #11 on: September 25, 2009, 09:23:30 am »

I can't see a problem with that Brian. Can you check in the database to see if the pending comment does indeed have a pending status?
Logged

Reinventing SWCMS at HotaruCMS.org - testers, designers and developers wanted!
bbrian017
Full Member
***
Offline Offline

Posts: 190



View Profile WWW
« Reply #12 on: September 25, 2009, 09:28:16 am »

While I go look I have another questions.

After I delete the comment the story still shows 1 comment.

See on the front page, http://blogengage.com

Third story says 1 comment

how do we update that after deleting the comment?

EDIT: The comment is in pending.
« Last Edit: September 25, 2009, 09:35:55 am by bbrian017 » Logged

Nick
Administrator
Hero Member
*****
Offline Offline

Posts: 668



View Profile WWW
« Reply #13 on: September 25, 2009, 09:47:14 am »

For the number of comments to exclude pending ones, open /libs/link.php and find:

Code:
function comments() {
global $db;

if(summarize_mysql == 1){
return $this->comments;
}else{
return $db->get_var("SELECT count(*) FROM " . table_comments . " WHERE comment_link_id = $this->id");
        }
}

Change the SQL to read:

Code:
return $db->get_var("SELECT count(*) FROM " . table_comments . " WHERE comment_link_id = $this->id AND comment_status != 'pending'");

You'll have to figure out the sidebar problem yourself. It should just be a simple matter of adding comment_status != 'pending' to the SQL query to filter out those comments - which you did, so I have no idea why it's not working.  Embarrassed
Logged

Reinventing SWCMS at HotaruCMS.org - testers, designers and developers wanted!
bbrian017
Full Member
***
Offline Offline

Posts: 190



View Profile WWW
« Reply #14 on: September 25, 2009, 09:53:34 am »

So if I add the code to exclude pending comment and it's deleted then it will never appear?

I will ask Ramil over at CMS themes to see if he knows.

Hes great help too

How do I delete the 2 comments it's showing now?

Also Nick the 3 and 4 and 5 comments is still showing up after adding this to link.php

Code:
function comments() {
global $db;

if(summarize_mysql == 1){
return $this->comments;
}else{
return $db->get_var("SELECT count(*) FROM " . table_comments . " WHERE comment_link_id = $this->id AND comment_status != 'pending'");
        }
}
« Last Edit: September 25, 2009, 10:10:13 am by bbrian017 » Logged

Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!