function simplenews_send_node in Simplenews 6
Same name and namespace in other branches
- 6.2 includes/simplenews.mail.inc \simplenews_send_node()
Send newsletter node to subcribers.
Parameters
integer or object $node Newsletter node to be sent. integer = nid; object = node object:
array $accounts account objects to send the newsletter to.: account = object ( snid = subscription id. 0 if no subscription record exists tids = array(tid) array of newsletter tid's uid = user id. 0 if subscriber is anonymous user. mail = user email address. name = <empty>. Added for compatebility with user account object language = language object. User preferred of default language ) NOTE: either snid, mail or uid is required.
2 calls to simplenews_send_node()
- simplenews_nodeapi in ./
simplenews.module - Implementation of hook_nodeapi().
- simplenews_send_newsletter_action in simplenews_action/
simplenews_action.module - A configurable Drupal action. Send a simplenews newsletter. hook = cron: Send a newsletter to all subscribers. hook = user: Send a newsletter to the user who triggered the action.
File
- ./
simplenews.module, line 1400 - Simplnews node handling, sent email, newsletter block and general hooks
Code
function simplenews_send_node($node, $accounts = array()) {
$mails = array();
if (is_numeric($node)) {
$node = node_load($node);
}
if (is_object($node)) {
$from = _simplenews_set_from($node);
$params['context']['node'] = $node;
$params['from'] = $from;
$node_data['tid'] = $node->simplenews['tid'];
$node_data['nid'] = $node->nid;
$node_data['vid'] = $node->vid;
if (empty($accounts)) {
// No accounts specified. Get email address of all accounts subscribed to this newsletter.
$result = db_query('SELECT s.mail FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.activated = %d AND t.tid = %d', 1, $node_data['tid']);
while ($account = db_fetch_object($result)) {
$mails[] = array(
'mail' => $account->mail,
);
}
}
else {
// Get email address of specified accounts.
foreach ($accounts as $account) {
$account = simplenews_get_subscription($account);
$mails[] = array(
'mail' => $account->mail,
);
}
}
// To send the newsletter, the node id and target email addresses
// are stored in the spool.
// When cron is not used the newsletter is send immediately to the emails
// in the spool. When cron is used newsletters are send to addresses in the
// spool during the next (and following) cron run.
foreach ($mails as $mail) {
$data = array_merge($node_data, $mail);
simplenews_save_spool($data);
}
if (variable_get('simplenews_use_cron', TRUE) == FALSE) {
simplenews_mail_spool($node_data['nid'], $node_data['vid'], 999999);
drupal_set_message(t('Newsletter sent.'));
simplenews_clear_spool();
}
else {
drupal_set_message(t('Newsletter pending.'));
}
}
}