You are here

function simplenews_statistics_mail_alter in Simplenews Statistics 6.3

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

Implements hook_mail_alter().

Adds a hidden image to the body and counts the amount of emails send.

File

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

Code

function simplenews_statistics_mail_alter(&$message) {
  if (($message['id'] == 'simplenews_node' || $message['id'] == 'simplenews_test') && $message['params']['context']['node']->simplenews['s_format'] == 'html') {
    $nid = $message['params']['context']['node']->nid;
    $mail = $message['params']['context']['account']->mail;

    // Parse body.
    _simplenews_statistics_parse_links($message['body'], $nid, $mail);

    // Add view image.
    _simplenews_statistics_image_tag($message['body'], $nid, $mail);

    // Count the number of sent mails for this newsletter
    if (variable_get('simplenews_statistics', 1)) {
      if (!db_fetch_array(db_query('SELECT * FROM {simplenews_statistics} WHERE nid = %d', $nid))) {
        db_query('INSERT INTO {simplenews_statistics} (nid, send) VALUES (%d, %d)', $nid, 1);
      }
      else {
        db_query('UPDATE {simplenews_statistics} SET send = send+1 WHERE nid = %d', $nid);
      }
    }
  }
}