You are here

function subscriptions_mail_digest_add_item in Subscriptions 2.0.x

Same name and namespace in other branches
  1. 7 subscriptions_mail.cron.inc \subscriptions_mail_digest_add_item()

Formats an item and adds it to the digest data.

Parameters

array $digest_data:

string $mailmod:

string $mailkey:

array $data:

object $user:

Return value

array The updated $digest_data array.

2 calls to subscriptions_mail_digest_add_item()
_subscriptions_mail_cron in subscriptions_mail/subscriptions_mail.cron.inc
Implementation of hook_cron().
_subscriptions_mail_preview_form in subscriptions_mail/subscriptions_mail.mail_edit.inc
Returns the template preview subform.

File

subscriptions_mail/subscriptions_mail.cron.inc, line 215
Subscriptions module mail gateway (cron functions).

Code

function subscriptions_mail_digest_add_item($digest_data, $mailmod, $mailkey, $data, $user) {
  $params = array(
    'data' => $data,
    'account' => $user,
    'object' => NULL,
    'context' => array(
      'mail_edit' => 'DIGEST',
    ),
  );

  // This code is adapted from drupal_mail() and simulates mailing the item.
  // We probably need to provide all the data in order to not surprise any
  // third-party module that implements hook_mail() or hook_mail_alter().
  $message = array(
    'id' => $mailmod . '_' . $mailkey,
    'module' => $mailmod,
    'key' => $mailkey,
    'to' => '',
    'from' => '',
    //isset($from) ? $from : $default_from,
    'language' => user_preferred_language($user),
    'params' => $params,
    'subject' => '',
    'body' => array(),
  );
  $headers = array(
    'MIME-Version' => '1.0',
    'Content-Type' => 'text/plain; charset=UTF-8; format=flowed; delsp=yes',
    'Content-Transfer-Encoding' => '8Bit',
    'X-Mailer' => 'Drupal',
  );
  $headers['From'] = $headers['Sender'] = $headers['Return-Path'] = variable_get('site_mail', ini_get('sendmail_from'));
  $message['headers'] = $headers;
  if (function_exists($function = $mailmod . '_mail')) {
    $function($mailkey, $message, $params);
  }

  // Invoke hook_mail_alter() to allow all modules to alter the resulting e-mail.
  drupal_alter('mail', $message);

  // Save the formatted body and return the modified $data.
  $data['subs']['formatted_item'] = $message['body'][0];
  $item_data = $data;
  $digest_data['subs']['items'][] = $item_data;
  $digest_data['subs'] += array(
    'name' => $item_data['subs']['name'],
    'mail' => $item_data['subs']['mail'],
    'uid' => $item_data['subs']['uid'],
  );
  return $digest_data;
}