You are here

function invisimail_callback in Invisimail 6

Same name and namespace in other branches
  1. 5 invisimail.module \invisimail_callback()

Callback function used by preg_replace_callback.

Expects the regex pattern defined in invisimail() to be used.

Parameters

array $matches: An array of matched patterns from our regex. Any match will have four keys, numbered 0-3, which correspond to the capturing groups in our regex. For all these examples, assume the following string: <p><a href="mailto:user@domain.com">user@domain.com</a></p>

  • 0: The entire matched string. This will include the email address, as well as that email address' corresponding href mailto iff it exists. In the example, it would be <a href="mailto:user@domain.com">user@domain.com
  • 1: The full string of the <a> tag portion of the match, iff that portion was matched; otherwise an empty string. In the example, it would be <a href="mailto:user@domain.com">
  • 2: The mailto + email address string from the href portion of the match, iff an href was found. In the example, it would be: mailto:user@domain.com
  • 3: The email address itself. In the example, just: user@domain.com

for the next set of array elements, assume the following string: <p><a href="mailto:user@domain.com">click here to eMail</a></p>

  • 1: The entire matched string, but this time where the link text does not match the mailto address. In the example, it would be <a href="mailto:user@domain.com">click here to eMail
  • 2:The mailto + email address string from the href portion of the match, iff an href was found. In the example, it would be: mailto:user@domain.com
  • 3: The link text. In the example, just: click here to eMail

Return value

string The full ASCII-encoded string that will replace the entire match.

1 string reference to 'invisimail_callback'
invisimail in ./invisimail.module

File

./invisimail.module, line 219
This module provides a filter that will search content for email addresses and replace them with their ascii equivalents before display. This is not a complete protection from spam harvesters, but it is some help.

Code

function invisimail_callback($matches) {
  $format = $GLOBALS['invisimail_format'];

  // If $matches[1] is empty, no link portion was matched for this item, so
  // it's a simple replace operation.
  if (empty($matches[1])) {
    return invisimail_ascii_encode($matches[3], $format['js'], $format['link']);
  }

  // If $matches[3] is something other than the eMail address, then we
  // matched on an <a> tag that didn't have the link text the same as the
  // mailto eMail address, so just replace the eMail address
  if ($matches[2] != 'mailto:' . $matches[3]) {
    return str_replace($matches[2], _invisimail_encode_string($matches[2], FALSE), $matches[0]);
  }

  // We DO have an existing link portion. Do our best to preserve it; that means
  // ignoring the js setting, since it makes for heinous string transformations.
  return str_replace(array(
    $matches[2],
    $matches[3],
  ), array(
    _invisimail_encode_string($matches[2], FALSE),
    _invisimail_encode_string($matches[3], FALSE),
  ), $matches[0]);
}