You are here

function _simplenews_statistics_image_tag in Simplenews Statistics 6.3

Same name and namespace in other branches
  1. 7.2 simplenews_statistics.module \_simplenews_statistics_image_tag()
  2. 7 simplenews_statistics.module \_simplenews_statistics_image_tag()

Add hidden image for view statistics.

1 call to _simplenews_statistics_image_tag()
simplenews_statistics_mail_alter in ./simplenews_statistics.module
Implements hook_mail_alter().

File

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

Code

function _simplenews_statistics_image_tag(&$body, $nid, $mail) {
  if (is_array($body)) {
    foreach ($body as $key => $element) {
      _simplenews_statistics_image_tag($body[$key], $nid, $mail);

      // Only add 1 image tag.
      return;
    }
  }
  else {
    require_once drupal_get_path('module', 'simplenews_statistics') . '/includes/rc4.inc';

    // Add hidden image.
    $pars = 'nid=' . check_plain($nid) . '&mail=' . check_plain($mail);
    $pars = _simplenews_statistics_rc4Encrypt(simplenews_private_key(), $pars);
    $pars_hash = md5($pars);
    $simplenews_statistics_internal_url = url('simplenews/statistics/view', 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);
    $body .= '<img src="' . $shortened_url . '" width="1" height="1">';
  }
}