ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Flag comments for review/inappropriate content

January 12, 2008 4:36am

Subscribe [5]
  • #1 / Jan 12, 2008 4:36am

    Seth Long

    7 posts

    I’d like to provide a feature similar to the reader flagging tool on craigslist that lets readers click a link to “flag” comments which may be inappropriate or somehow violate our terms of service. Has anyone done this in EE? Is there an extension or module already built?

    Thank you.

  • #2 / May 01, 2008 2:59am

    Leevi Graham

    1143 posts

    Hey Seth,

    Based on the forum thread here: http://ellislab.com/forums/viewthread/60902/

    I have put together the following code which closes a comment and emails the site administrator. 😊

    Just create a new template and add this code as discussed in the previously mentioned thread

    <?php
    // declare some globals
    global $DB, $IN, $LANG, $PREFS, $OUT;
    
    // get the comment id
    $comment_id = $IN->fetch_uri_segment('3');
    
    // prepare the basic response
    $data = array(
        'title'     => 'Comment Moderation',
        'redirect'    => '',
        'link'        => array('[removed]history.go(-1)', 'Return to article')
    );
    
    // check the comment exists
    $query = $DB->query("SELECT * FROM exp_comments JOIN exp_weblog_titles USING(entry_id) WHERE comment_id = '".$DB->escape_str($comment_id)."'");
    
    // if the comment does not exist
    if ($query->num_rows != 1)
    {
        // build the error message
        $data['heading'] = 'Comment does not exist';
        $data['content'] = 'The comment you are attempting to mark as inappropriate does not exist.';
        $OUT->show_message($data, 1);
    }
    
    // Mark the comment as inappropriate
    $DB->query($DB->update_string('exp_comments', array('status' => 'c'), array('comment_id' => $comment_id)));
    
    /** ----------------------------
    /**  Send email
    /** ----------------------------*/
    // get the email class
    if ( ! class_exists('EEmail'))
    {
        require PATH_CORE.'core.email'.EXT;
    }
    // create a new email object
    $E = new EEmail;        
    $E->wordwrap = true;
    $E->mailtype = 'html';
    $E->priority = '3';
    
    // set the prefs
    // im sending it to myself
    $E->from($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name'));    
    $E->to($PREFS->ini('webmaster_email'), $PREFS->ini('webmaster_name')); 
    
    // create a subject line
    $E->subject('Comment flagged as inappropriate on the ' . $PREFS->ini('site_name') . ' website');
    
    // build the cp url
    $cp_url = $PREFS->ini('site_url', TRUE) . $PREFS->ini('system_folder', TRUE);
    
    
    // create the message
    $email_msg = "A comment which was made on <em>'" . $query->row['title'] . "'</em> has been marked as inappropriate and closed.
    The comment:
    <div>" . $query->row['comment'] . "</div>
    <strong><a >row['weblog_id'] . "&entry;_id=" . $query->row['entry_id'] . "'>Click here to review comments for this article.</a></strong> - You must be logged in.
    ";
    
    // add the message to the email object
    $E->message($email_msg);
    // send the email
    $E->Send();
    
    // create a nice output message
    $data['heading'] = 'Comment successfully flagged as inappropriate';
    $data['content'] = 'Thankyou for reporting this potentially inappropriate comment. Our editors will review the comment as soon as possible.';
    
    // get outta here
    $OUT->show_message($data, 1);
    
    ?>
  • #3 / Jun 19, 2008 11:43pm

    bhggraphicdesign

    52 posts

    Leevi,

    I am trying to modify your code for a project I’m working on.  Basically our client wants to allow users to flag posts that contain inappropriate content, and after 3 flags, or 5 flags close the post and bring it to an administrator’s attention.  I was able to modify your code to work on a weblog post easily enough by changing instances of comment_id, etc. to entry_id, but I don’t know how to use the $DB global to say, for instance:

    //Check to if/how many times the post has been flagged
    $check2 = $DB->query("SELECT status FROM exp_weblog_titles WHERE entry_id = '".$DB->escape_str($entry_id)."'");
    
    // if the post has not been flagged
    if ($check2->$row['status'] == 'open')
    {
        //change 'open' to 'one' as a mark of first flag
        $DB->query($DB->update_string('exp_weblog_titles', array('status' => 'one'), array('entry_id' => $entry_id)));
    //otherwise check how many times the post has been flagged and add another flag 
    } 
    if elseif ($check->row['s'] == 'one')    
    {
        $DB->query($DB->update_string('exp_weblog_titles', array('status' => 'two'), array('entry_id' => $entry_id)));
    }
    if elseif ($check->row['s'] == 'two')    
    {
        $DB->query($DB->update_string('exp_weblog_titles', array('status' => 'three'), array('entry_id' => $entry_id)));
    }
    if elseif ($check->row['s'] == 'three')    
    {
    // Three strikes and you're out - mark the post as inappropriate
    $DB->query($DB->update_string('exp_weblog_titles', array('status' => 'closed'), array('entry_id' => $entry_id)));

    Now when I attempt to “flag” a post, nothing happens, so I know I’m not writing the $DB query correctly.  Any help you could give, even if you could give me a link to a tutorial for writing $DB queries would be appreciated.

    Thanks,

    James at bhg Graphic Design

  • #4 / Jun 24, 2008 11:40pm

    Leevi Graham

    1143 posts

    Hmmm I’m not sure I would be using statuses for that… maybe a custom field would be more flexible?

    I actually need this functionality again for another project so I’m looking to extend it a bit further.

    The problem with your code is that:

    if elseif ($check->row['s'] == 'one')

    should be

    if elseif ($check2->row['status'] == 'one')
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases