<commit_before><?php
/*
Plugin Name: Recapture
Plugin URI: http://ben.subparcitizens.net/recapture
Description: Recapture displays a reCAPTCHA on the user registration form in an attempt to combat user registration spam.
Version: 0.2beta
Author: <NAME>
Author URI: http://ben.subparcitizens.net/
*/

// We need to include the reCAPTCHA library...
// But not if you have the reCAPTCHA comment plugin installed.
// That causes problems, because the library has already been included
// So we'll just use that one if it exists.
if ( !function_exists( '_recaptcha_qsencode' )) {
	require_once( dirname(__FILE__) . '/recaptchalib.php' );
}

$recaptureOptions = get_option( 'recapture_options' );

// Display the reCAPTCHA on the registration form
function display_recaptcha() {
	global $recaptureOptions;
	$format = <<<END
	<script type='text/javascript'>
		var RecaptchaOptions = { theme: 'clean', tabindex : 30 };
	</script>
END;
	echo $format . recaptcha_get_html( $recaptureOptions[ 'publicKey' ], $error );
}

// Hook the display_recaptcha function into WordPress
add_action( 'register_form', 'display_recaptcha' );

// Check the captcha
function check_recaptcha( $user_login, $user_email, $errors ) {
	global $recaptureOptions;
	$privateKey = $recaptureOptions[ 'privateKey' ];
	
	$response = recaptcha_check_answer( $privateKey,
										$_SERVER[ 'REMOTE_ADDR' ],
										$_POST[ 'recaptcha_challenge_field' ],
										$_POST[ 'recaptcha_response_field' ] );

	if (!$response->is_valid) {
		$recaptureOptions[ 'failedAttempts' ]++;
		update_option( 'recapture_options', $recaptureOptions );
		if ($response->error == 'incorrect-captcha-sol') {
			$errors->add( 'captcha_wrong', 'That reCAPTCHA was incorrect.' );
		}
	}
}

// Hook the check_recaptcha function into WordPress
add_action( 'register_post', 'check_recaptcha', 10, 3 );

function recapture_domain ( ) {
	$uri = parse_url(get_settings('siteurl'));
	return $uri['host'];
}

// Add a link to the configuration options in the WordPress options menu
function add_recapture_config_page( ) {
	add_options_page( 'Recapture Configuration', 'Recapture', 8, __FILE__, 'recapture_config_page' );
}

// Display the configuration options for Recapture<commit_msg>Recapture should be able to work with both WordPress 2.3.x and 2.5 now. Time to make it prettier.<commit_after><?php
/*
Plugin Name: Recapture
Plugin URI: http://ben.subparcitizens.net/recapture
Description: Recapture displays a reCAPTCHA on the user registration form in an attempt to combat user registration spam.
Version: 0.2beta
Author: <NAME>
Author URI: http://ben.subparcitizens.net/
*/

// We need to include the reCAPTCHA library...
// But not if you have the reCAPTCHA comment plugin installed.
// That causes problems, because the library has already been included
// So we'll just use that one if it exists.
global $wp_version;
if ( !function_exists( '_recaptcha_qsencode' )) {
	require_once( dirname(__FILE__) . '/recaptchalib.php' );
}

$recaptureOptions = get_option( 'recapture_options' );

// Display the reCAPTCHA on the registration form
function display_recaptcha() {
	global $recaptureOptions;
	$format = <<<END
	<script type='text/javascript'>
		var RecaptchaOptions = { theme: 'clean', tabindex : 30 };
	</script>
END;
	echo $format . recaptcha_get_html( $recaptureOptions[ 'publicKey' ], $error );
}

// Hook the display_recaptcha function into WordPress
add_action( 'register_form', 'display_recaptcha' );

// Check the captcha
function check_recaptcha( ) {
	global $recaptureOptions, $errors;
	$privateKey = $recaptureOptions[ 'privateKey' ];
	
	$response = recaptcha_check_answer( $privateKey,
										$_SERVER[ 'REMOTE_ADDR' ],
										$_POST[ 'recaptcha_challenge_field' ],
										$_POST[ 'recaptcha_response_field' ] );

	if ( !$response->is_valid ) {
		$recaptureOptions[ 'failedAttempts' ]++;
		update_option( 'recapture_options', $recaptureOptions );
		if ( $response->error == 'incorrect-captcha-sol' ) {
			$errors[ 'captcha_wrong' ] = 'That reCAPTCHA was incorrect.';
		}
	}
}

// Check the captcha
function check_recaptcha_new( $user_login, $user_email, $errors ) {
	global $recaptureOptions;
	$privateKey = $recaptureOptions[ 'privateKey' ];
	
	$response = recaptcha_check_answer( $privateKey,
										$_SERVER[ 'REMOTE_ADDR' ],
										$_POST[ 'recaptcha_challenge_field' ],
										$_POST[ 'recaptcha_response_field' ] );

	if ( !$response->is_valid ) {
		$recaptureOptions[ 'failedAttempts' ]++;
		update_option( 'recapture_options', $recaptureOptions );
		if ( $response->error == 'incorrect-captcha-sol' ) {
			$errors->add( 'captcha_wrong', 'That reCAPTCHA was incorrect.' );			
		}
	}
}

// Hook the check_recaptcha function into WordPress
if ( $wp_version >= '2.5' ) {
	add_action( 'register_post', 'check_recaptcha_new', 10, 3 );
} else {
	add_action( 'register_post', 'check_recaptcha' );
}

function recapture_domain ( ) {
	$uri = parse_url(get_settings('siteurl'));
	return $uri['host'];
}

// Add a link to the configuration options in the WordPress options menu
function add_recapture_config_page( ) {
	add_options_page( 'Recapture Configuration', 'Recapture', 8, __FILE__, 'recapture_config_page' );
}

// Display the configuration options for Recapture
{'fraction_non_alphanumeric': 0.12540561175796908, 'fraction_numerical': 0.0041992746707386905, 'mean_word_length': 4.714285714285714, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1401078', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1692, 'n_words': 455}