You are here

function _invisimail_process_emails_callback in Invisimail 7

Callback function used by preg_replace_callback.

Expects the regex pattern defined in _invisimail_email_matching_regexes() 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_process_emails_callback'
invisimail_encode_string in ./invisimail.module
Encodes all email addresses in a string using the specified encoder.

File

./invisimail.module, line 329
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_process_emails_callback(array $matches) {
  $settings = $GLOBALS['invisimail_settings'];

  // 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 $settings['callback']($matches[3], $settings);

    //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], $settings['callback']($matches[2], $settings, TRUE), $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(
    $settings['callback']($matches[2], $settings, TRUE),
    $settings['callback']($matches[3], $settings, TRUE),
  ), $matches[0]);
}