Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: plugin idea: “report this post”


_ck_
Participant

@_ck_

And a report post plugin is born – tested working!

Needs a few features but gets the job done for now:

<?php
/*
Plugin Name: report post
Description: allows members to report a post to admin/moderators
Plugin URI: http://CKon.wordpress.com
Author: _ck_
Author URI: http://CKon.wordpress.com
Version: 0.1
*/

/*
instructions: install, activate and put <? report_post_link(); ?> in your post.php template where you want the link to be seen
optional in stylesheet: a.report_post {color:red;}

todo:
1. don't let them report more than once on a post - or more than too many times per minute/hour
2. auto-delete post if more than x reports from different members
3. auto-post report into a specified moderator's forum #
4. maybe ajax xmlhttp call instead of real form post so there's no page movement
5. it's technically possible to alert a browing mod with a popup directing to the reported post, no email needed
*/

function report_post_link($post_id=0) {
if (bb_current_user_can('participate') ) :
$post_id= get_post_id( $post_id );
if (get_post_author_id($post_id) != bb_get_current_user_info( 'id' )) {
echo '<a class=report_post title="report post to moderator" href="#post-'.$post_id.'" onClick="report_post('.$post_id.');return false;">Report</a>';
}
endif;
}

function report_post_form() {
if (bb_current_user_can('participate')) :
if (isset($_POST['report_post_id']) && isset($_POST['report_post_reason'])) {
echo '<scr'.'ipt type="text/javascript">alert("Thank you for the report. A moderator has been notified.");</scr'.'ipt>';
$post_id=intval($_POST['report_post_id']);
// todo: custom response if invalid id, problem sending email - maybe flush output buffer so member gets alert faster
$to = bb_get_option('admin_email');
$subject = " reported post by member for moderation";
$headers = "From: ".bb_get_option('admin_email');
$message ="report by: ".bb_get_current_user_info( 'name' )." (".bb_get_current_user_info( 'id' ).") email: ".bb_get_current_user_info( 'email' )."rnrn";
$message.="report: ".wordwrap(strip_tags(substr($_POST['report_post_reason'],0,255)),70)."rnrn".get_post_link($post_id)."rn";
$message.="post by: ". get_post_author($post_id)."rn"; // add "member since", total posts, blah blah
$message.="rnrnReport Trace:rn";
$message.="IP: ".$_SERVER['REMOTE_ADDR']."rn";
$message.="Host: ".gethostbyaddr($_SERVER['REMOTE_ADDR'])."rn"; // useful but can add a few seconds
$message.="Agent: ".$_SERVER['HTTP_USER_AGENT']."rn";
$message.="Refer: ". $_REQUEST['refer']."rn";
$message.="URL: http://".$_SERVER['HTTP_HOST'].$GLOBALS["HTTP_SERVER_VARS"]["REQUEST_URI"]."rn";
mail( $to, $subject, $message,$headers);
}
echo '<form method="POST" name="report_post_form" id="report_post_form" style="display:none;visibility:hidden"><input type=hidden name="report_post_id"><input type=hidden name="report_post_reason"></form>';
echo '<scr'.'ipt type="text/javascript">
function report_post(post_id) {
var report_post_reason = prompt("Please enter a short but descriptive reason why a moderator needs to review this post:", "");
if (report_post_reason && report_post_reason.length>9) {
document.report_post_form.report_post_id.value=post_id;
document.report_post_form.action="#post-"+post_id;
document.report_post_form.report_post_reason.value=report_post_reason;
document.report_post_form.submit();
} else {alert("report cancelled, incomplete description"); }
}
</scr'.'ipt>';
endif;
}
add_action('bb_foot', 'report_post_form');

?>

Skip to toolbar