reCAPTCHA web service to improve the CAPTCHA system and protect email addresses.', array('@url' => url('http://www.recaptcha.net'))); break; case 'admin/help#recaptcha': $output .= '

'. t('Uses the reCAPTCHA web service to improve the CAPTCHA module and protect email addresses. For more information on what reCAPTCHA is, visit the official website.', array('@url' => url('http://www.recaptcha.net'))) . '

'. t('Configuration') . '

'. t('The settings associated with reCAPTCHA can be found in the reCAPTCHA tab, in the CAPTCHA settings. You must set your public and private reCAPTCHA keys in order to use the module. Once the public and private keys are set, visit the CAPTCHA settings, where you can choose where reCAPTCHA should be displayed.', array('@recaptchatab' => url('admin/user/captcha/recaptcha'), '@captchasettings' => url('admin/user/captcha'))) . '

'; break; } return $output; } /** * Implementation of hook_menu(). */ function recaptcha_menu() { $items = array(); $items['admin/user/captcha/recaptcha'] = array( 'title' => 'reCAPTCHA', 'description' => 'Administer the reCAPTCHA web service.', 'page callback' => 'drupal_get_form', 'page arguments' => array('recaptcha_admin_settings'), 'access arguments' => array('administer recaptcha'), 'type' => MENU_LOCAL_TASK, 'file' => 'recaptcha.admin.inc', ); return $items; } /** * Implementation of hook_perm(). */ function recaptcha_perm() { return array('administer recaptcha'); } /** * Implementation of hook_captcha(). */ function recaptcha_captcha() { $args = func_get_args(); $op = array_shift($args); switch ($op) { case 'list': return array('reCAPTCHA'); case 'generate': $captcha_type = array_shift($args); $captcha = array(); if ($captcha_type == 'reCAPTCHA') { // Load the recaptcha library. _recaptcha_load_library(); // Check if reCAPTCHA is available and show Math if not. $connect = @fsockopen(RECAPTCHA_VERIFY_SERVER, 80); if (!$connect) { return captcha_captcha('generate', 'Math', $args); } fclose($connect); // Retrieve configuration variables from database. $recaptcha_secure_connection = variable_get('recaptcha_secure_connection', FALSE); $recaptcha_theme = variable_get('recaptcha_theme', 'red'); $recaptcha_tabindex = variable_get('recaptcha_tabindex', NULL); $recaptcha_public_key = variable_get('recaptcha_public_key', ''); $recaptcha_form_value = NULL; // Construct the Javascript, but only display it once. static $_recaptcha_jsadded = FALSE; if ($_recaptcha_jsadded == FALSE) { $_recaptcha_jsadded = TRUE; $recaptcha_options = array( 'theme' => $recaptcha_theme, ); // Localization support. global $language; if (isset($language->language)) { // reCAPTCHA uses two-character language codes, so 'pt-br' must be // passed as 'pt' (cf. http://wiki.recaptcha.net/index.php/I18n). $recaptcha_options['lang'] = substr($language->language, 0, 2); } // Add support to display the custom theme. if ($recaptcha_theme == 'custom') { $recaptcha_options['custom_theme_widget'] = 'recaptcha_custom_theme_widget'; $recaptcha_form_value = theme('recaptcha_custom_widget'); } // Set the default tab index. if (!empty($recaptcha_tabindex)) { $recaptcha_options['tabindex'] = $recaptcha_tabindex; } drupal_add_js('var RecaptchaOptions = '. drupal_to_js($recaptcha_options) .';', 'inline'); } // Create the form. Captcha requires TRUE to be returned in solution. $captcha['solution'] = TRUE; $captcha['captcha_validate'] = 'recaptcha_captcha_validation'; $html = recaptcha_get_html($recaptcha_public_key, NULL, $recaptcha_secure_connection); $captcha['form']['captcha_response'] = array( '#type' => 'hidden', '#value' => 'reCAPTCHA', ); $captcha['form']['captcha_form'] = array( '#type' => 'item', '#value' => ($recaptcha_form_value ? '
'. $recaptcha_form_value .'
' : '') . $html, ); } return $captcha; } } /** * CAPTCHA Callback; Validates the reCAPTCHA code. */ function recaptcha_captcha_validation($solution = NULL, $response = NULL) { if ($response == 'reCAPTCHA' && isset($_POST['recaptcha_challenge_field']) && isset($_POST['recaptcha_response_field'])) { $resp = recaptcha_check_answer( variable_get('recaptcha_private_key', ''), $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] ); return $resp->is_valid; } return FALSE; } /** * Implementation of hook_theme(). */ function recaptcha_theme() { return array( 'recaptcha_custom_widget' => array( 'arguments' => array(), ), ); } /** * Theme function: creates the custom themed recaptcha widget. * * @ingroup themeable */ function theme_recaptcha_custom_widget() { $recaptcha_only_if_incorrect_sol = t('Incorrect please try again'); $recaptcha_only_if_image_enter = t('Enter the words above:'); $recaptcha_only_if_audio_enter = t('Enter the numbers you hear:'); $recaptcha_get_another_captcha = t('Get another CAPTCHA'); $recaptcha_only_if_image = t('Get an audio CAPTCHA'); $recaptcha_only_if_audio = t('Get an image CAPTCHA'); $help = t('Help'); return <<
$recaptcha_only_if_incorrect_sol
$recaptcha_only_if_image_enter $recaptcha_only_if_audio_enter
$recaptcha_get_another_captcha
$recaptcha_only_if_image
$recaptcha_only_if_audio
$help
EOT; } /** * Load the recaptcha library. */ function _recaptcha_load_library() { module_load_include('php', 'recaptcha', 'recaptcha/recaptchalib'); }