You are here

function _spamspan_callback_mailto in SpamSpan filter 7

Same name and namespace in other branches
  1. 6 spamspan.module \_spamspan_callback_mailto()

The callback functions for preg_replace_callback

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

Parameters

$matches: An array containing parts of an email address or mailto: URL.

Return value

The span with which to replace the email address

1 string reference to '_spamspan_callback_mailto'
_spamspan_filter_process in ./spamspan.module
Spamspan filter process callback

File

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

Code

function _spamspan_callback_mailto($matches) {

  // take the mailto: URL in $matches[3] and split the query string
  // into its component parts, putting them in $headers as
  // [0]=>"header=contents" etc.  We cannot use parse_str because
  // the query string might contain dots.
  // Single quote can be encoded as &#039; which breaks parse_url
  // Replace it back to a single quote which is perfectly valid
  $matches[3] = str_replace("&#039;", '\'', $matches[3]);
  $query = parse_url($matches[3], PHP_URL_QUERY);
  $query = str_replace('&amp;', '&', $query);
  $headers = preg_split('/[&;]/', $query);

  // if no matches, $headers[0] will be set to '' so $headers must be reset
  if ($headers[0] == '') {
    $headers = array();
  }

  // take all <a> attributes except the href and put them into custom $vars
  $vars = $attributes = array();

  //before href
  if (!empty($matches[1])) {
    $matches[1] = trim($matches[1]);
    $attributes[] = $matches[1];
  }

  //after href
  if (!empty($matches[6])) {
    $matches[6] = trim($matches[6]);
    $attributes[] = $matches[6];
  }
  if (count($attributes)) {
    $vars['extra_attributes'] = implode(' ', $attributes);
  }
  return spamspan_admin()
    ->output($matches[4], $matches[5], $matches[7], $headers, $vars);
}