You are here

function _spamspan_output in SpamSpan filter 6

A helper function for the callbacks

Replace an email addresses which has been found with the appropriate <span> tags

Parameters

$name: The user name

$domain: The email domain

$contents: The contents of any <a> tag

$headers: The email headers extracted from a mailto: URL

Return value

The span with which to replace the email address

2 calls to _spamspan_output()
_spamspan_callback_email in ./spamspan.module
_spamspan_callback_mailto in ./spamspan.module
The callback functions for preg_replace_callback

File

./spamspan.module, line 183
This module implements the spamspan technique (http://www.spamspan.com ) for hiding email addresses from spambots.

Code

function _spamspan_output($name, $domain, $contents, $headers) {

  // Replace .'s in the address with [dot]
  $user_name = str_replace(".", " [dot] ", $name);
  $domain = str_replace(".", " [dot] ", $domain);
  if (variable_get('spamspan_use_graphic', 0)) {
    $image = base_path() . drupal_get_path("module", "spamspan") . "/image.gif";
    $at = '<img alt="at" width="10" src="' . $image . '" />';
  }
  else {
    $at = variable_get('spamspan_at', ' [at] ');
  }
  $output = '<span class="spamspan"><span class="' . variable_get('spamspan_userclass', 'u') . "\">{$user_name}</span>" . $at . "<span class=\"" . variable_get('spamspan_domainclass', 'd') . "\">{$domain}</span>";

  // if there are headers, include them as eg (subject: xxx, cc: zzz)
  if (isset($headers) and $headers) {
    foreach ($headers as $value) {

      //replace the = in the headers arrays by ": " to look nicer
      $temp_headers[] = str_replace("=", ": ", $value);
    }
    $output .= "<span class=\"h\"> (" . check_plain(implode(', ', $temp_headers)) . ") </span>";
  }

  // 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($contents) and $contents and !preg_match("!^" . SPAMSPAN_EMAIL . "\$!ix", $contents)) {
    $output .= "<span class=\"" . variable_get('spamspan_anchorclass', 't') . "\"> (" . $contents . ")</span>";
  }
  $output .= "</span>";

  // remove anything except certain inline elements, just in case.  NB nested
  // <a> elements are illegal.  <img> needs to be here to allow for graphic
  // @
  $output = filter_xss($output, $allowed_tags = array(
    'em',
    'strong',
    'cite',
    'b',
    'i',
    'code',
    'span',
    'img',
  ));
  return $output;
}