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.

'); } } /** * 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 readable 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($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. You should not normally need to change any of these settings.'), '#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.') ); $form['spamspan_settings']['spamspan_use_graphic'] = array( '#type' => 'checkbox', '#title' => t('Use a graphical replacement for "@"'), '#default_value' => variable_get('spamspan_use_graphic', 0), '#required' => TRUE, '#description' => t('Replace "@" with a graphical representation when javascript is disabled (and ignore the setting "Replacement for @" above).') ); return $form; } break; } } /** * Implementation of hook_init(). */ function spamspan_init() { // 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'); } /** * The callback function for preg_replace_callback * * Replace an email addresses which has been found with the appropriate * tags * * @param $matches * An array containing parts of an email address. User is in $matches[2], * domain in [3] and mailto tag contents in [4] (if any) * @return * The span with which to replace the email address */ function _spamspan_callback($matches) { // Replace .'s in the address with [dot] $user_name = str_replace(".", " [dot] ", $matches[2]); $domain = str_replace(".", " [dot] ", $matches[3]); if (variable_get('spamspan_use_graphic', 1)) { $image = base_path() . drupal_get_path("module", "spamspan") ."/image.gif"; $at = 'at'; } else { $at = variable_get('spamspan_at', ' [at] '); } $output = '$user_name". $at ."$domain"; // if there are tag contents, include them, between round brackets, unless // the contents are an email address. In that case, we can ignore them. This // is also a good idea because otherise the tag contents are themselves // converted into a spamspan, with undesirable consequences - see bug #305464. // NB problems may still be caused by edge cases, eg if the tag contents are // "blah blah email@example.com ..." if (isset ($matches[4]) and $matches[4] and !(preg_match("!^". SPAMSPAN_EMAIL ."$!ix", $matches[4]))) { $output .= " (". $matches[4] .")"; } $output .= ""; return $output; } /** * Scan text and replace email addresses with span tags * * We are aiming to replace emails with code like this: * * user * [at] * example [dot] com * * * This function may be called by other modules and themes. * * @param $string * Text, maybe containing email addresses. * @return * The input text with emails replaced by spans */ function spamspan($string) { // Top and tail the email regexp it so that it is case insensitive and // ignores whitespace. The extra brackets ensure that the pattern captures // the name into the second group and the domain into the third. The first // group is not used: $emailpattern = "!(". SPAMSPAN_EMAIL .")!ix"; // Next set up a regex for mailto: URLs. Again, this captures the name into // the second group and the domain into the third. The tag contents go into // the fourth. This does not presently do anything with URL parameters, // eg the subject in mailto:email@example.com?subject=subject $mailtopattern = "! # 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"; // Now we can convert all mailto URLs $string = preg_replace_callback($mailtopattern, '_spamspan_callback', $string); // and finally, all bare email addresses return preg_replace_callback($emailpattern, '_spamspan_callback', $string); }