function recaptcha_mailhide_filter in reCAPTCHA 6
Same name and namespace in other branches
- 5.2 recaptcha_mailhide.module \recaptcha_mailhide_filter()
Implements hook_filter().
File
- recaptcha_mailhide/
recaptcha_mailhide.module, line 40 - Protects email addresses using the reCAPTCHA web service.
Code
function recaptcha_mailhide_filter($op, $delta = 0, $format = -1, $text = '') {
switch ($op) {
case 'list':
return array(
0 => t('reCAPTCHA Mailhide'),
);
case 'description':
return recaptcha_mailhide_filter_tips($delta, $format);
case 'settings':
_recaptcha_mailhide_load_library();
$form['filter_recaptcha'] = array(
'#type' => 'fieldset',
'#title' => t('reCAPTCHA Mailhide Keys'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
);
$form['filter_recaptcha']['recaptcha_mailhide_public_key'] = array(
'#type' => 'textfield',
'#title' => t('Public Key'),
'#default_value' => variable_get('recaptcha_mailhide_public_key', ''),
'#maxlength' => 50,
'#description' => t('Your public Mailhide key obtained from <a href="@url">reCAPTCHA</a>.', array(
'@url' => 'https://www.google.com/recaptcha/mailhide/apikey',
)),
);
$form['filter_recaptcha']['recaptcha_mailhide_private_key'] = array(
'#type' => 'textfield',
'#title' => t('Private Key'),
'#default_value' => variable_get('recaptcha_mailhide_private_key', ''),
'#maxlength' => 50,
'#description' => t('Your private Mailhide key obtained from <a href="@url">reCAPTCHA</a>.', array(
'@url' => 'https://www.google.com/recaptcha/mailhide/apikey',
)),
);
return $form;
break;
case 'process':
global $_recaptcha_mailhide_public_key, $_recaptcha_mailhide_private_key, $_recaptcha_mailhide_nokey_warn;
_recaptcha_mailhide_load_library();
$_recaptcha_mailhide_public_key = variable_get('recaptcha_mailhide_public_key', '');
$_recaptcha_mailhide_private_key = variable_get('recaptcha_mailhide_private_key', '');
$text = ' ' . $text . ' ';
$text = preg_replace_callback("!(<p>|<li>|<br\\s*/?>|[ \n\r\t\\(])([A-Za-z0-9._-]+@[A-Za-z0-9._+-]+\\.[A-Za-z]{2,4})([.,?]?)(?=(</p>|</li>|<br\\s*/?>|[ \n\r\t\\)]))!i", '_recaptcha_replace', $text);
$text = drupal_substr($text, 1, -1);
unset($_recaptcha_mailhide_public_key);
unset($_recaptcha_mailhide_private_key);
unset($_recaptcha_mailhide_nokey_warn);
return $text;
default:
return $text;
}
}