You are here

function _simplenews_statistics_replace_url in Simplenews Statistics 6.3

Same name and namespace in other branches
  1. 6 simplenews_statistics.module \_simplenews_statistics_replace_url()
  2. 6.2 simplenews_statistics.module \_simplenews_statistics_replace_url()
  3. 7.2 simplenews_statistics.module \_simplenews_statistics_replace_url()
  4. 7 simplenews_statistics.module \_simplenews_statistics_replace_url()

Alter link to go through statistics.

File

./simplenews_statistics.module, line 188
Main simplenews statistics file.

Code

function _simplenews_statistics_replace_url($match, $nid, $mail) {

  // Do not replace anchor-links
  if (substr($match, 0, 1) == '#') {
    return $match;
  }
  $track_emailaddress = variable_get('simplenews_statistics_track_emailaddress', 1);
  if ($track_emailaddress == 0) {
    if (substr($match, 0, 7) == 'mailto:') {
      return $match;
    }
  }
  require_once drupal_get_path('module', 'simplenews_statistics') . '/includes/rc4.inc';
  $pars = 'nid=' . check_plain($nid) . '&mail=' . check_plain($mail) . '&url=' . check_url($match);
  $pars = _simplenews_statistics_rc4Encrypt(simplenews_private_key(), $pars);
  $pars_hash = md5($pars);
  $simplenews_statistics_internal_url = url('simplenews/statistics/click', array(
    'absolute' => TRUE,
    'query' => array(
      'p' => _simplenews_statistics_encode_parameter($pars),
      'h' => _simplenews_statistics_encode_parameter($pars_hash),
    ),
  ));

  // Use the "full-url"-option to get an absolute URL.
  $shortened_url = shorturl_shorten($simplenews_statistics_internal_url, TRUE);
  return $shortened_url;
}