more help', array('%url' => url('admin/help/spamspan'))); } return $output; case 'admin/help#spamspan': return t('
The SpamSpan module obfuscates email addresses to help prevent spambots from collecting them. It will produce clickable links if JavaScript is enabled, and will show the email address as example [at] example [dot] com
if the browser does not support JavaScript.
To configure the module, select "configure" next to the input format you\'d like to use. Enable "Hide Email Addresses" and submit the form. Then select the "configure" tab to choose relevant options.
', array('%url' => url('admin/filters'))); } } /** * Implementation of hook_filter_tips(). * */ function spamspan_filter_tips($delta, $format, $long = FALSE) { switch ($delta) { case 0: return t('Each email address will be obfuscated in a human readble fashion or (if JavaScript is enabled) replaced with a spamproof clickable link.'); break; } } /** * Implementation of hook_filter(). * */ function spamspan_filter($op, $delta = 0, $format = -1, $text = '') { if ($op == 'list') { return array(0 => t('Hide email addresses')); } switch ($delta) { case 0: switch ($op) { case 'description': return t('Attempt to hide email addresses from spam-bots.'); case 'prepare': return $text; case 'process': return spamspan(spamspan_convertmailto($text)); case 'settings': // field set for the spamspan settings $form['spamspan_settings'] = array( '#type' => 'fieldset', '#title' => t('SpamSpan email address encoding filter'), '#description' => t('Warning: these are global settings and not per input format. Changing them here will change them for other input formats too.'), '#collapsible' => true, ); // spamspan user name part class name $form['spamspan_settings']['spamspan_userclass'] = array( '#type' => 'textfield', '#title' => t('User name class'), '#default_value' => variable_get('spamspan_userclass', 'u'), '#required' => TRUE, '#description' => t('The class name of the <span> element enclosing the part of the address before the "@".'), ); // spamspan domain part class name $form['spamspan_settings']['spamspan_domainclass'] = array( '#type' => 'textfield', '#title' => t('Domain part class'), '#default_value' => variable_get('spamspan_domainclass', 'd'), '#required' => TRUE, '#description' => t('The class name of the <span> element enclosing the part of the address after the "@".') ); // spamspan '@' replacement $form['spamspan_settings']['spamspan_at'] = array( '#type' => 'textfield', '#title' => t('Replacement for "@"'), '#default_value' => variable_get('spamspan_at', ' [at] '), '#required' => TRUE, '#description' => t('Replace "@" with this text when javascript is disabled.') ); return $form; } break; } } /** * Implementation of hook_footer(). */ function spamspan_footer($main = 0) { // Add the javascript to each page drupal_add_js(drupal_get_path("module", "spamspan") .'/spamspan.compressed.js'); // pass necessary variables to the javascript drupal_add_js(array( 'spamspan' => array( 'm' => 'spamspan', 'u' => variable_get('spamspan_userclass', 'u'), 'd' => variable_get('spamspan_domainclass', 'd'), 't' => variable_get('spamspan_anchorclass', 't') ) ), 'setting'); } /** * callback function for preg_replace_callback */ function spamspan_callback($matches) { // Replace .'s in the address with [dot] $user_name = str_replace(".", " [dot] ", $matches[1]); $domain = str_replace(".", " [dot] ", $matches[2]); return '$user_name". variable_get('spamspan_at', ' [at] ') ."$domain"; } /** * Central SpamSpan replace function * We are aiming for code like this: * * user * [at] * example [dot] com * */ function spamspan($string) { // The following pattern is not perfect (who is?), but is intended to intercept // things which look like email addresses. It is not intended to determine if // an address is valid. It will not intercept addresses with quoted local parts $pattern = "! ################################################## # Group 1 ([-\.\~\'\w\+^@]+) # Match the name part - dash, dot or characters @ # @ # Group 2 ((?: [-\w]+\. # one or more letters or dashes followed by a dot )+ # The whole thing one or more times [A-Z]{2,6} # with between two and six letters at the end (NB .museum) ) ################################################### !ix"; // Case insensitive, ignore whitespace return preg_replace_callback($pattern, 'spamspan_callback', $string); } function spamspan_convertmailto($string='') { // does not presently work with URL parameters, eg // mailto:email@example.com?subject=subject define("REGEX", "! # end of the first tag .*? # tag contents. NB this will not work properly if there # is a nested , but this is not valid xhtml anyway # closing tag !ix" ); return preg_replace(REGEX, "\\2", $string); }