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; } // function recaptcha_help /** * Implementation of hook_menu(). */ function recaptcha_menu($may_cache) { $items = array(); if ($may_cache) { $items[] = array( 'path' => 'admin/user/captcha/recaptcha', 'title' => t('reCAPTCHA'), 'description' => t('Administer the reCAPTCHA web service.'), 'callback' => 'drupal_get_form', 'callback arguments' => array('recaptcha_admin_settings'), 'access' => user_access('administer recaptcha'), 'type' => MENU_LOCAL_TASK, ); } return $items; } // function recaptcha_menu /** * Valid permissions for this module * @return array An array of valid permissions for the onthisdate module */ function recaptcha_perm() { return array('administer recaptcha'); } // function recaptcha_perm() /** * Implementation of admin settings(). */ function recaptcha_admin_settings() { require_once('recaptcha.inc'); @(include_once('recaptcha/recaptchalib.php')) or _recaptcha_library_not_found(); $form = array(); $form['recaptcha_public_key'] = array( '#type' => 'textfield', '#title' => t('Public Key'), '#default_value' => variable_get('recaptcha_public_key', ''), '#maxlength' => 40, '#description' => t('The public key given to you when you registered at reCAPTCHA.net.', array('@url' => url(recaptcha_get_signup_url($_SERVER['SERVER_NAME'], variable_get('site_name', ''))))), ); $form['recaptcha_private_key'] = array( '#type' => 'textfield', '#title' => t('Private Key'), '#default_value' => variable_get('recaptcha_private_key', ''), '#maxlength' => 40, '#description' => t('The private key given to you when you registered at reCAPTCHA.net.', array('@url' => url(recaptcha_get_signup_url($_SERVER['SERVER_NAME'], variable_get('site_name', ''))))), ); $form['recaptcha_secure_connection'] = array( '#type' => 'checkbox', '#title' => t('Secure Connection'), '#default_value' => variable_get('recaptcha_secure_connection', FALSE), '#description' => t('Connect to the reCAPTCHA server using a secure connection.'), ); $form['recaptcha_theme_settings'] = array( '#type' => 'fieldset', '#title' => t('Theme Settings'), '#collapsible' => TRUE, '#collapsed' => TRUE, ); $form['recaptcha_theme_settings']['recaptcha_theme'] = array( '#type' => 'select', '#title' => t('Theme'), '#description' => t('Defines which theme to use for reCAPTCHA.'), '#options' => array( 'red' => t('Red'), 'white' => t('White'), 'blackglass' => t('Black Glass'), ), '#default_value' => variable_get('recaptcha_theme', 'red'), '#required' => TRUE, ); $form['recaptcha_theme_settings']['recaptcha_tabindex'] = array( '#type' => 'textfield', '#title' => t('Tab Index'), '#description' => t('Sets a tabindex for the reCAPTCHA text box. If other elements in the form use a tabindex, this should be set so that navigation is easier for the user.', array('@tabindex' => 'http://www.w3.org/TR/html4/interact/forms.html#adef-tabindex')), '#default_value' => variable_get('recaptcha_tabindex', ''), '#size' => 4, ); return system_settings_form($form); } // function recaptcha_admin_settings /** * The validation on the reCAPTCHA administration settings */ function recaptcha_admin_settings_validate($form_id, $form_values) { $tabindex = $form_values['recaptcha_tabindex']; if (!empty($tabindex) && !is_numeric($tabindex)) { form_set_error('recaptcha_tabindex', t('The Tab Index must be an integer.')); } } /** * 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); $result = array(); if ($captcha_type == 'reCAPTCHA') { require_once('recaptcha.inc'); global $_recaptcha_jsadded; @(include_once('recaptcha/recaptchalib.php')) or _recaptcha_library_not_found(); // 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); // close connection // 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', ''); // Create the form drupal_add_css(drupal_get_path('module', 'recaptcha') .'/recaptcha.css'); if (!isset($_recaptcha_jsadded)) { // only display the javascript once. $_recaptcha_jsadded = TRUE; $js = "var RecaptchaOptions = {theme : '$recaptcha_theme'"; if (!empty($recaptcha_tabindex)) { $js .= ', tabindex : '. $recaptcha_tabindex; } drupal_add_js($js .'};', 'inline'); } $result['preprocess'] = TRUE; // tell captcha to preprocess the form $result['solution'] = TRUE; // require TRUE to be returned $result['form']['captcha_challenge'] = array( '#type' => 'item', '#description' => recaptcha_get_html($recaptcha_public_key, NULL, $recaptcha_secure_connection), '#required' => TRUE, ); } return $result; case 'preprocess': require_once('recaptcha.inc'); @(include_once('recaptcha/recaptchalib.php')) or _recaptcha_library_not_found(); $resp = recaptcha_check_answer( variable_get('recaptcha_private_key', ''), $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']); if ($resp->is_valid) { return TRUE; } else { form_set_error('captcha_response', t('The reCAPTCHA code you entered was incorrect.')); return FALSE; } break; } } // function recaptcha_captcha