You are here

function _recaptcha_replace in reCAPTCHA 7

Same name and namespace in other branches
  1. 8 recaptcha_mailhide/recaptcha_mailhide.module \_recaptcha_replace()
  2. 5.2 recaptcha_mailhide.module \_recaptcha_replace()
  3. 6 recaptcha_mailhide/recaptcha_mailhide.module \_recaptcha_replace()

Private reCAPTCHA function to replace an email regex match.

1 string reference to '_recaptcha_replace'
_filter_recaptcha_mailhide in recaptcha_mailhide/recaptcha_mailhide.module
Filter callbacks.

File

recaptcha_mailhide/recaptcha_mailhide.module, line 105
Protects email addresses using the reCAPTCHA web service.

Code

function _recaptcha_replace($match) {
  global $_recaptcha_mailhide_public_key, $_recaptcha_mailhide_private_key, $_recaptcha_mailhide_nokey_warn;

  // If we invoke recaptchalib without setting the keys, it will die(). Instead,
  // fail gracefully.
  if (empty($_recaptcha_mailhide_public_key) || empty($_recaptcha_mailhide_private_key) || !function_exists('mcrypt_encrypt')) {
    if ($_recaptcha_mailhide_nokey_warn != TRUE) {
      if (!function_exists('mcrypt_encrypt')) {
        drupal_set_message(t('Addresses cannot be hidden because Mcrypt is not installed.'), 'error');
      }
      else {
        drupal_set_message(t('Addresses cannot be hidden because the administrator has not set the reCAPTCHA Mailhide keys.'), 'error');
      }
      $_recaptcha_mailhide_nokey_warn = TRUE;
    }
    $email = $match[2];
  }
  else {
    $email = recaptcha_mailhide_html($_recaptcha_mailhide_public_key, $_recaptcha_mailhide_private_key, $match[2]);
  }
  return $match[1] . $email . $match[3];
}