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`) )' ); if ( !$bbmodsuite_cache['report'] = bb_get_option( 'bbmodsuite_report_options' ) ) { bb_update_option( 'bbmodsuite_report_options', array( 'min_level' => 'moderate', 'max_level' => 'moderate', 'types' => '', 'resolve_types' => '', 'obtrusive' => true ) ); $bbmodsuite_cache['report'] = array( 'min_level' => 'moderate', 'max_level' => 'moderate', 'types' => '', 'resolve_types' => '', 'obtrusive' => true ); } if ( !isset( $bbmodsuite_cache['report']['obtrusive'] ) ) { $bbmodsuite_cache['report']['obtrusive'] = true; bb_update_option( 'bbmodsuite_report_options', $bbmodsuite_cache['report'] ); } } function bbmodsuite_report_uninstall() { global $bbdb; $bbdb->query( 'DROP TABLE `' . $bbdb->prefix . 'bbmodsuite_reports`' ); bb_delete_option( 'bbmodsuite_report_options' ); } 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_init() { global $bbmodsuite_cache; if (empty($bbmodsuite_cache['report'])) $bbmodsuite_cache['report'] = bb_get_option('bbmodsuite_report_options'); } add_action('bbmodsuite_init', 'bbmodsuite_report_init'); 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) { ?>' . __('There is a new report waiting for you!', 'bbpress-moderation-suite') . '
'; else echo ''; } add_action('bb_logged-in.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 = class_exists('BP_User') ? new BP_User($post_author_id) : new WP_User($post_author_id); global $bbmodsuite_cache; $options = $bbmodsuite_cache['report']; if ($post_author_id != bb_get_current_user_info('ID') && ($options['max_level'] === 'none' || !$post_author->has_cap($options['max_level']))) { $title = __('Report this post to a moderator.', 'bbpress-moderation-suite'); $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'); ?>