Make Comments Require Admin Approval in Clip-Bucket v2

Hello,

A couple of weeks ago a customer was asking me how to make comments require approval prior to being displayed on the site. I told him there was no native function to do so, but that I was going to do the modifications for him. I finished it, he implemented it and we were all happy. I thought that it’d be nice if I shared the code with all the community, so here you go! This was tested under v2.6 only. It might work for the whole v2 branch, though.

**Remember to back up all the files to be edited, in case something goes wrong or you simply want to revert changes.

1. Open ./includes/classes/my_queries.class.php

2. Find:

if($type_id!='*')

before that line, add:

if($type=='v') { $cond .= " AND approved='approved'"; }

3. Find:

('type,comment,type_id,userid,date_added,parent_id,anonym_name,anonym_email','comment_ip','type_owner_id'),

replace it with:

('type,comment,type_id,userid,date_added,parent_id,anonym_name,anonym_email','comment_ip','type_owner_id','approved'),

4. Find:

($type,$comment,$obj_id,userid(),NOW(),$reply_to,$name,$email,$_SERVER['REMOTE_ADDR'],$obj_owner));

replace it with:

($type,$comment,$obj_id,userid(),NOW(),$reply_to,$name,$email,$_SERVER['REMOTE_ADDR'],$obj_owner,'pending'));

5. Find:

function DeleteComment($id,$videoid){return $this->delete_comment($videoid);}

and after that, paste:

/**
     * Function used to approve comment
     */
    function approve_comment($cid)
    {
        global $db;
        $comment = $this->get_comment($cid);    
        $uid = user_id();
        if($comment)
        {

            if(!$comment)
                e(lang('no_comment_exists'));
            else
            {

                $db->update(tbl('comments'),array('approved'),array('approved')," comment_id='$cid'");
                e("Successfully approved comment");            
            }

        }
        e(lang('no_comment_exists'));
        return false;
    }

6. Save & Upload.

1. Open ./js/functions.js
2. Find the function:

function add_comment_js(form_id,type)

and replace it completely with:

function add_comment_js(form_id,type)
    {
        $("#add_comment_result").css("display","block");
        $("#add_comment_result").html(loading);
        $("#add_comment_button").attr("disabled","disabled");

        //var captcha_enabled =  $("#"+form_id+" input:#cb_captcha_enabled").val();

        //First we will get all values of form_id and then serialize them
        //so we can forward details to ajax.php

        var formObjectData = $('#'+form_id).serialize()+'&mode=add_comment';

        $.post(page,formObjectData,
        function(data)
        {
            if(!data)
                alert("No data");
            else
            {
                $("#add_comment_result").css("display","block");
                $("#add_comment").html('<div style="display:block" class="add_comment_result" id="add_comment_result"></div>');
                if(data.err!='')
                {
                    $("#add_comment_result").html(data.err);
                }
                if(data.msg!='') {
                    $("#add_comment_result").html("-Comment has been added and it is pending approval.");

                }
            }
        },'json');
    }

3. Find the function:

function get_the_comment(id,div)

and comment all of its content, making it look like this:

function get_the_comment(id,div)
    {

        /*$(div).html(loading);
        $.post(page,
        {    
            mode : 'get_comment',
            cid : id
        },
        function(data)
        {
            if(!data)
                alert("No data");
            else
            {        
                $(div).css("display","none");
                $(div).html(data).fadeIn("slow");
            }
        },'text');*/
    }

4. Save & Upload.

1. Open ./admin_area/styles/cbv2/layout/comments.html
2. Find:

<a href="{videoLink vdetails=$comment}#{if $comment.spam_votes > 0}spam_{/if}comment_{$comment.comment_id}" target="_blank">{lang code='view'} {lang code='comment'}</a> |

and after that, add the following:

{if $comment.approved !='approved'}
<a href="#" id="approve_comment_{$comment.comment_id}" onclick="admin_approve_comment({$comment.comment_id}); return false;"  style="display:inline" >Set Approved</a> | {/if}

3. Save and Upload.

1. Open ./js/admin_functions.js
2. Find:

function admin_remove_spam(cid)

before that, paste:

function admin_approve_comment(cid)
    {

        $.post(page,
        {    
            mode : 'approve_comment',
            cid : cid
        },
        function(data)
        {
            if(!data)
                alert("No data");
            else
            {
                if(data.msg)
                {
                    $("#comment_"+cid).css({'backgroundColor' : '#ffd7d7'});
                    $("#approve_comment_"+cid).fadeOut(350);

                }
                if(data.err)
                {
                    alert(data.err)
                }
            }
        },'json');
    }

3. Save and Upload.

1. Open ./actions/admin.php
2. Find

case 'spam_comment':

and before that, paste:

case 'approve_comment':
    {
        $cid = mysql_clean($_POST['cid']);

        $rating = $myquery->approve_comment($cid);
        if(msg())
        {
            $msg = msg_list();
            $msg = $msg[0];
        }
        if(error())
        {
            $err = error_list();
            $err = $err[0];
        }

        $ajax['msg'] = $msg;
        $ajax['err'] = $err;

        echo json_encode($ajax);
    }
    break;

3. Save and Upload.

1. Now go to your phpMyadmin.
2. Select your database.
3. Run the following query:

ALTER TABLE `cb_comments`  ADD `approved` ENUM('approved','pending') NOT NULL DEFAULT 'approved' AFTER `type_owner_id`

There you go! Please go to your website, write a comment and then go to your admin_area to check if the option to approve it now available. As this is a pretty long guide, if you get stuck at any point or are not sure how to proceed, please do not hesitate to contact me and I’ll get back to you ASAP. Any questions or comments are welcome!

Best Regards,

Richi

Looking for quality Clip-Bucket hosting? Try out Arvixe and you won’t be disappointed.
Tags: , , , , , , , , , , , | Posted under ClipBucket | RSS 2.0

Author Spotlight

Richi González

Richi González

I started programming when I was 12. I'm a Developer and have been working with the Clip-Bucket script since it came out. I'm the Liaison between Arvixe and Clip-Bucket, so anything you need regarding Clip-Bucket or any particular computer-related subject you need, let me know so I can assist you.

Leave a Reply

Your email address will not be published. Required fields are marked *


4 − = 2

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>