'moderate' ) ); global $bbmodsuite_cache; $bbmodsuite_cache['banplus'] = array( 'bans' => array(), 'options' => array( 'min_level' => 'moderate' ) ); } function bbmodsuite_banplus_uninstall() { global $bbmodsuite_cache; foreach ( $bbmodsuite_cache['banplus']['bans'] as $user_id => $ban ) { do_action( 'bbmodsuite_banplus_unban', $user_id, $ban ); } bb_delete_option( 'bbmodsuite_banplus_current_bans' ); bb_delete_option( 'bbmodsuite_banplus_options' ); } /** * bbmodsuite_banplus_set_ban() - Set a ban on a user * * @param int|string $user_id The ID or username of the user to ban. * @param string $type 'temp' for temporary. Other plugins can add more. * @param int $length How long the ban should be in seconds. Defaults to 1 day. * @param string $notes The reason for the ban. * @return bool true on success, false on error * @global $bbmodsuite_cache Cache of options and bans */ function bbmodsuite_banplus_set_ban( $user_id, $type = 'temp', $length = 86400, $notes = '' ) { global $bbmodsuite_cache; $the_options = $bbmodsuite_cache['banplus']['options']; if ( !bb_current_user_can( $the_options['min_level'] ) ) return false; $user_id = bb_get_user_id( $user_id ); if ( !$user_id ) return false; if ( $user_id === bb_get_current_user_info( 'ID' ) ) return false; if ( class_exists( 'BP_User' ) ) $user = new BP_User( $user_id ); else $user = new WP_User( $user_id ); if ( ( $user->has_cap( 'moderate' ) && !bb_current_user_can( 'administrate' ) ) || ( $user->has_cap( 'administrate' ) && !bb_current_user_can( 'use_keys' ) ) ) return false; $current_bans = $bbmodsuite_cache['banplus']['bans']; if ( $type === 'unban' ) { if ( !isset( $current_bans[$user_id] ) ) return true; do_action( 'bbmodsuite_banplus_unban', $user_id, $current_bans[$user_id] ); unset( $current_bans[$user_id] ); $bbmodsuite_cache['bans'] = $current_bans; bb_update_option( 'bbmodsuite_banplus_current_bans', $current_bans ); return true; } $length = (int)$length; if ($length <= 0) return false; $until = time() + $length; if ( !in_array( $type, bbmodsuite_banplus_get_ban_types() ) ) return false; if ( $current_bans[$user_id]['type'] === $type && $current_bans[$user_id]['length'] === $length ) return true; if ( isset( $current_bans[$user_id] ) ) return false; $notes = bb_autop( htmlspecialchars( trim( $notes ) ) ); $current_bans[$user_id] = array( 'type' => $type, 'length' => $length, 'on' => time(), 'until' => $until, 'banned_by' => bb_get_current_user_info( 'ID' ), 'notes' => $notes, ); do_action( 'bbmodsuite_banplus_ban', $user_id, $current_bans[$user_id] ); $bbmodsuite_cache['bans'] = $current_bans; bb_update_option( 'bbmodsuite_banplus_current_bans', $current_bans ); return true; } function bbmodsuite_banplus_init() { $current_bans = (array)bb_get_option( 'bbmodsuite_banplus_current_bans' ); $changed = false; foreach ( $current_bans as $user_id => $ban ) { if ( $ban['until'] < time() ) { do_action( 'bbmodsuite_banplus_unban', $user_id, $current_bans[$user_id] ); unset( $current_bans[$user_id] ); $changed = true; } } if ( $changed ) bb_update_option( 'bbmodsuite_banplus_current_bans', $current_bans ); global $bbmodsuite_cache; if ( empty( $bbmodsuite_cache['banplus'] ) ) $bbmodsuite_cache['banplus'] = array( 'bans' => $current_bans, 'options' => bb_get_option( 'bbmodsuite_banplus_options' ) ); } bbmodsuite_banplus_init(); function bbmodsuite_banplus_maybe_block_user() { global $bbmodsuite_cache; $current_bans = $bbmodsuite_cache['banplus']['bans']; if ( !empty( $current_bans[bb_get_current_user_info( 'ID' )] ) ) { switch ( $current_bans[bb_get_current_user_info( 'ID' )]['type'] ) { case 'temp': if ( bb_get_template( 'ban-plus.php', false ) ) { bb_load_template( 'ban-plus.php', array( 'ban' => $current_bans[bb_get_current_user_info( 'ID' )] ), $current_bans[bb_get_current_user_info( 'ID' )] ); exit; } bb_die( sprintf( __( 'You are banned from this forum until %s from now. The person who banned you said the reason was: %s', 'bbpress-moderation-suite' ), bb_since( time() * 2 - $current_bans[bb_get_current_user_info( 'ID' )]['until'], true ), $current_bans[bb_get_current_user_info( 'ID' )]['notes'] ) ); break; } } } if ( bb_get_location() != 'login-page' ) // Let them log out bbmodsuite_banplus_maybe_block_user(); function bbmodsuite_banplus_get_ban_types() { global $bbmodsuite_active_plugins; $types = array( 'temp' ); return apply_filters( 'bbmodsuite_banplus_ban_types', $types ); } function bbmodsuite_banplus_admin_add_jquery() { wp_enqueue_script( 'jquery' ); } if ( $_GET['page'] == 'new_ban' ) add_action( 'bbpress_moderation_suite_ban_plus_pre_head', 'bbmodsuite_banplus_admin_add_jquery' ); function bbmodsuite_banplus_admin_newbanajax() { header( 'Content-Type: text/plain' ); if ( !bb_verify_nonce( $_POST['_wpnonce'], 'bbmodsuite-banplus-new-ajax' ) ) exit; $name = stripslashes( $_POST['text'] ); $name = str_replace( array( '%', '?' ), array( '\\%', '\\?' ), substr( $_POST['text'], 0, $_POST['pos'] ) ) . '%' . str_replace( array( '%', '?' ), array( '\\%', '\\?' ), substr( $_POST['text'], $_POST['pos'] ) ); global $bbdb; $results = $bbdb->get_col( $bbdb->prepare( 'SELECT `user_nicename` FROM `' . $bbdb->users . '` WHERE ( `user_nicename` LIKE %s OR `user_login` LIKE %s OR `ID` = %d ) AND `ID` != %d ORDER BY LENGTH(`user_nicename`) ASC LIMIT 15', $name, $name, $_POST['text'], bb_get_current_user_info( 'ID' ) ) ); exit( '["' . implode( '","', array_map( 'addslashes', $results ) ) . '"]' ); } if ( $_GET['page'] == 'new_ban_ajax' ) add_action( 'bbpress_moderation_suite_ban_plus_pre_head', 'bbmodsuite_banplus_admin_newbanajax' ); function bbpress_moderation_suite_ban_plus() { ?>

href=" 'bbpress_moderation_suite_ban_plus', 'page' => 'current_bans' ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ); ?>"> () | href=" 'bbpress_moderation_suite_ban_plus', 'page' => 'new_ban' ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ), 'bbmodsuite-banplus-new' ); ?>"> | href=" 'bbpress_moderation_suite_ban_plus', 'page' => 'admin' ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ); ?>">

'nicename' ) ) ) if ( !$user = bb_get_user( $_POST['user_id'], array( 'by' => 'username' ) ) ) { ?>

ID; $username = get_user_display_name( $user_id ); $time = (int)$_POST['time']; $multiplier = (int)$_POST['time_multiplier']; $length = $time * $multiplier; $notes = $_POST['notes']; if ( bbmodsuite_banplus_set_ban( $user_id, 'temp', $length, $notes ) ) { ?>

$ban ) { $unban_link = attribute_escape( bb_nonce_url( bb_get_uri( 'bb-admin/admin-base.php', array( 'page' => 'unban_user', 'user' => $user_id, 'plugin' => 'bbpress_moderation_suite_ban_plus', ), BB_URI_CONTEXT_A_HREF + BB_URI_CONTEXT_BB_ADMIN ), 'bbmodsuite-banplus-unban_' . $user_id ) ); ?> >