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('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; } /** * Implements hook_menu(). */ function recaptcha_menu() { $items = array(); $items['admin/config/people/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; } /** * Implements hook_perm(). */ function recaptcha_permission() { return array( 'administer recaptcha' => array( 'title' => t('reCaptcha Administration'), 'description' => t('Administer reCaptcha settings'), ), ); } /** * Implements 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; $recaptcha_ajax_api = variable_get('recaptcha_ajax_api', FALSE); if ($recaptcha_ajax_api) { // By default CAPTCHA turns off page caching on // any page where a CAPTCHA challenge appears. // If recaptcha is using AJAX API, set caching // back to it's old state as stored in DB. global $conf; $cache = variable_get('cache', FALSE); $conf['cache'] = $cache; } // Construct the Javascript, but only display it once. static $_recaptcha_jsadded = FALSE; if ($_recaptcha_jsadded == FALSE && $recaptcha_ajax_api == 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'] = drupal_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_json_encode($recaptcha_options) . ';', array('type' => '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', ); // Expose the form, either straight HTML, or using the AJAX API. if ($recaptcha_ajax_api == FALSE) { $captcha['form']['captcha_form'] = array( '#type' => 'item', '#markup' => ($recaptcha_form_value ? '