/** * Check to make sure that a user is not making too many posts in a short amount of time. */ function bb_check_post_flood() { global $bbdb; $user_id = (int) $user_id; $throttle_time = bb_get_option('throttle_time'); if (bb_current_user_can('manage_options') || empty($throttle_time)) { return; } if (bb_is_user_logged_in()) { $bb_current_user = bb_get_current_user(); if (isset($bb_current_user->data->last_posted) && time() < $bb_current_user->data->last_posted + $throttle_time && !bb_current_user_can('throttle')) { if (defined('DOING_AJAX') && DOING_AJAX) { die(__('Slow down; you move too fast.')); } else { bb_die(__('Slow down; you move too fast.')); } } } else { if (($last_posted = bb_get_transient($_SERVER['REMOTE_ADDR'] . '_last_posted')) && time() < $last_posted + $throttle_time) { if (defined('DOING_AJAX') && DOING_AJAX) { die(__('Slow down; you move too fast.')); } else { bb_die(__('Slow down; you move too fast.')); } } } }
function get($transient) { return bb_get_transient(BP_Transients::prefix() . $transient); }
function nospamuser_check($type, $data) { $settings = bb_get_option('nospamuser-settings'); if (!$settings) { bb_update_option('nospamuser-settings', $settings = array('days' => 30, 'min_occur' => 5, 'max_occur' => 10, 'api_key' => '', 'recaptcha_mode' => 'aggressive', 'recapthca_pub' => '', 'recaptcha_priv' => '', 'stats_public' => 0)); } if (!is_array($result = bb_get_transient('nospamuser-' . $type . '-' . md5($data)))) { $wp_http = new WP_Http(); $response = $wp_http->get('http://www.stopforumspam.com/api?' . urlencode($type) . '=' . urlencode($data), array('user-agent' => apply_filters('http_headers_useragent', backpress_get_option('wp_http_version')) . NOSPAMUSER_AGENT)); $response = $response['body']; if (strpos($response, '<response success="true">') === false) { return; } if (strpos($response, '<appears>no</appears>') !== false) { $result = array(0, 0); } else { preg_match('/<lastseen>([^<>]+)<\\/lastseen>/', $response, $matches); $result = array((int) substr($response, strpos($response, '<frequency>') + 11), strtotime($matches[1])); } bb_set_transient('nospamuser-' . $type . '-' . md5($data), $result, 604800); } if ($result == array(0, 0)) { // Even if the settings are set incorrectly, non-spammers shouldn't be blocked. return; } if ($result[0] >= $settings['min_occur'] && $result[1] >= time() - $settings['days'] * 86400 || $result[0] >= $settings['max_occur'] && $settings['recaptcha_mode'] == 'aggressive') { if ($result[0] >= $settings['max_occur'] && $settings['recaptcha_mode'] == 'adaptive') { nospamuser_block($type, $data, true); } elseif ($settings['recaptcha_mode'] == 'aggressive' || !$settings['recaptcha_pub'] || !$settings['recaptcha_priv']) { nospamuser_block($type, $data, true); } else { nospamuser_block($type, $data, false); } } }