query('CREATE TABLE IF NOT EXISTS `' . $bbdb->prefix . 'bbmodsuite_reports` ( `ID` int(10) NOT NULL auto_increment, `report_reason` int(10) NOT NULL default \'0\', `report_from` int(10) NOT NULL, `reported_post` int(10) NOT NULL, `report_content` text NOT NULL, `report_type` varchar(250) NOT NULL default \'new\', `resolved_by` int(10) NOT NULL default \'0\', `resolve_type` int(10) NOT NULL default \'0\', `resolve_content` text NOT NULL default \'\', `reported_at` datetime NOT NULL, `resolved_at` datetime, PRIMARY KEY (`ID`) )'); } function bbmodsuite_report_uninstall() { global $bbdb; $bbdb->query('DROP TABLE `' . $bbdb->prefix . 'bbmodsuite_reports`'); bb_delete_option('bbmodsuite_report_types'); bb_delete_option('bbmodsuite_report_resolve_types'); } if (!defined('BB_PATH') && isset($_GET['report'])) { if (file_exists('../bb-load.php')) require_once '../bb-load.php'; elseif (file_exists('../../bb-load.php')) require_once '../../bb-load.php'; if (strtoupper($_SERVER['REQUEST_METHOD']) === 'GET') { if (!bb_verify_nonce($_GET['_nonce'], 'bbmodsuite-report-' . $_GET['report'])) bb_die(__('Invalid report', 'bbpress-moderation-suite')); global $forums, $bb_post; $bb_post = bb_get_post($_GET['report']); if ($bb_post->post_status) bb_die(__('Invalid report', 'bbpress-moderation-suite')); function bbmodsuite_report_form_uri($a, $b) { if ($b === 'bb-post.php') return str_replace('\\', '/', substr(BB_PLUGIN_URL, 0, -1) . str_replace(realpath(BB_PLUGIN_DIR), '', dirname(__FILE__)) . '/' . basename(__FILE__) . '?report=' . $_GET['report']); return $a; } add_filter('bb_get_uri', 'bbmodsuite_report_form_uri', 10, 2); $forums = false; function bbmodsuite_report_form($a, $b) { if ($b === 'post-form.php') { return dirname(__FILE__) . '/report-form.php'; } return $a; } add_filter('bb_template', 'bbmodsuite_report_form', 10, 2); bb_load_template('front-page.php'); } else { if (!($_POST['report_reason'] === '0' || array_key_exists($_POST['report_reason'], bbmodsuite_report_reasons()))) bb_die(__('Invalid report', 'bbpress-moderation-suite')); $report_reason = $_POST['report_reason']; $report_content = htmlspecialchars($_POST['report_content']); $reported_post = $_GET['report']; $report_from = bb_get_current_user_info('ID'); $reported_at = bb_current_time('mysql'); global $bbdb; $bbdb->insert($bbdb->prefix . 'bbmodsuite_reports', compact('report_reason', 'report_content', 'reported_post', 'report_from', 'reported_at')); bb_die(__('

Your report was submitted. The moderation staff will review the post in question.

', 'bbpress-moderation-suite')); } } function bbmodsuite_report_admin_css() { ?> get_var($bbdb->prepare('SELECT `ID` FROM `' . $bbdb->prefix . 'bbmodsuite_reports` WHERE `report_type`=\'new\' AND `ID`=%d', $_GET['report'])); if (!$report_id) { ?>

update($bbdb->prefix . 'bbmodsuite_reports', array('report_type' => 'resolved', 'resolve_content' => htmlspecialchars(trim($_POST['resolve_content'])), 'resolved_at' => bb_current_time('mysql'), 'resolved_by' => bb_get_current_user_info('ID'), 'resolve_type' => (int) $_POST['resolve_type']), array('ID' => $report_id))) { ?>

get_results('SELECT ID, report_reason, report_from, reported_post, report_content, resolved_by, resolve_type, resolve_content FROM `' . $bbdb->prefix . 'bbmodsuite_reports` WHERE `report_type`=\'resolved\''); $reasons = bbmodsuite_report_reasons() + array(__('Other', 'bbpress-moderation-suite')); $resolve_types = bbmodsuite_report_resolve_types() + array(__('Other', 'bbpress-moderation-suite')); ?>

'resolve_reports', 'report' => $report->ID, 'plugin' => 'bbpress_moderation_suite_report' ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ), 'bbmodsuite-report-resolve_' . $report->ID); ?> >
report_from); ?> report_reason]; ?> report_content)); ?> resolved_by); ?> resolve_type]; ?> resolve_content)); ?>

get_results('SELECT ID, report_reason, report_from, reported_post, report_content FROM `' . $bbdb->prefix . 'bbmodsuite_reports` WHERE `report_type`=\'new\''); $reasons = bbmodsuite_report_reasons() + array(__('Other', 'bbpress-moderation-suite')); ?>

'resolve_reports', 'report' => $report->ID, 'plugin' => 'bbpress_moderation_suite_report' ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ), 'bbmodsuite-report-resolve_' . $report->ID); ?> >
report_from); ?> report_reason]; ?> report_content)); ?>
Resolve
get_results($bbdb->prepare('SELECT `reported_post` FROM `' . $bbdb->prefix . 'bbmodsuite_reports` WHERE `report_type`=%s', 'new')); $reported_post_ids = array(); foreach ($new_reports as $new_report) { foreach ($posts as $post) { if ($new_report->reported_post === $post->post_id) $reported_post_ids[] = $new_report->reported_post; } } return '#post-' . implode(', #post-', $reported_post_ids) . ' { background: #900; color: #fff; }'; } function bbmodsuite_report_css() { echo ''; } add_action('bb_head', 'bbmodsuite_report_css'); function bbmodsuite_report_reasons() { $reasons = explode("\n", ".\n" . bb_get_option('bbmodsuite_report_types')); $reasons = array_filter($reasons); unset($reasons[0]); return $reasons; } function bbmodsuite_report_resolve_types() { $reasons = explode("\n", ".\n" . bb_get_option('bbmodsuite_report_resolve_types')); $reasons = array_filter($reasons); unset($reasons[0]); return $reasons; } function bbmodsuite_report_header() { if (!bb_current_user_can('moderate')) return; $link = bb_get_uri( 'bb-admin/admin-base.php', array( 'page' => 'new_reports', 'plugin' => 'bbpress_moderation_suite_report' ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ); $number = number_format(bbmodsuite_report_count('new')); if ($number == 0) return; if ($number == 1) echo '

' . __('There is a new report waiting for you!', 'bbpress-moderation-suite') . '

'; else echo '

' . sprintf(__('There are %s new reports waiting for you!', 'bbpress-moderation-suite'), $number) . '

'; } add_action('bb_logged-in.php', 'bbmodsuite_report_header'); add_action('bb_login-form.php', 'bbmodsuite_report_header'); function bbmodsuite_report_count($type = 'all') { global $bbdb; if ($type === 'all') return $bbdb->get_var('SELECT COUNT(*) FROM `' . $bbdb->prefix . 'bbmodsuite_reports`'); return $bbdb->get_var($bbdb->prepare('SELECT COUNT(*) FROM `' . $bbdb->prefix . 'bbmodsuite_reports` WHERE `report_type`=%s', $type)); } function bbmodsuite_report_link($parts) { $post_id = get_post_id(); if (bb_current_user_can('participate') && !bb_current_user_can('delete_post', $post_id)) { $post_author_id = get_post_author_id($post_id); $post_author = new WP_User($post_author_id); if ($post_author_id != bb_get_current_user_info('ID') && !$post_author->has_cap('moderate')) { $title = __('Report this post to a moderator.', 'bbpress-moderation-suite'); $bbreport_confirm = __('Are you sure you want to report this post?', 'bbpress-moderation-suite'); $bbreport_href = str_replace('\\', '/', substr(BB_PLUGIN_URL, 0, -1) . str_replace(realpath(BB_PLUGIN_DIR), '', dirname(__FILE__)) . '/' . basename(__FILE__)); $parts[] = ''.__("Report", 'bbpress-moderation-suite').''; } } return $parts; } add_filter('bb_post_admin', 'bbmodsuite_report_link'); ?>