You are here

function ad_notify_send_mail in Advertisement 5

Same name and namespace in other branches
  1. 5.2 notify/ad_notify.module \ad_notify_send_mail()
  2. 6 notify/ad_notify.module \ad_notify_send_mail()

Send email notifications using PHP mail() function.

1 call to ad_notify_send_mail()
ad_notify_cron in notify/ad_notify.module
Drupal _cron() hook. For performance reasons, all notifications are actually sent via this cron hook.

File

notify/ad_notify.module, line 145
Receive email notifications regarding ads.

Code

function ad_notify_send_mail($notification, $count = 0) {
  $uid = db_result(db_query('SELECT uid FROM {ad_owners} WHERE oid = %d', $notification->oid));
  $node = node_load(array(
    'nid' => $notification->aid,
  ));
  $owner = user_load(array(
    'uid' => $uid,
  ));
  $statistics = ad_statistics($notification->aid);
  $notifications = module_invoke_all('adnotifyapi', 'register');
  $variables = array(
    t('%owner_name') => $owner->name,
    t('%owner_mail') => $owner->mail,
    t('%owner_uid') => $owner->uid,
    t('%sitename') => variable_get('site_name', 'drupal'),
    t('%status') => $node->adstatus,
    t('%type') => $node->adtype,
    t('%event') => $notification->event,
    t('%frequency') => t(strtolower($notifications[$notification->event]), array(
      '@when' => format_interval($notification->delay),
    )),
    t('%redirect') => url($node->redirect, NULL, NULL, TRUE),
    t('%aid') => $notification->aid,
    t('%title') => $node->title,
    t('%url') => url("node/{$node->nid}", NULL, NULL, TRUE),
    t('%siteurl') => url('', NULL, NULL, TRUE),
    t('%comments') => $node->comment_count,
    t('%count') => $count,
    t('%created_small') => format_date($node->created, 'small'),
    t('%created_medium') => format_date($node->created, 'medium'),
    t('%created_large') => format_date($node->created, 'large'),
    t('%activated_small') => $node->activated ? format_date($node->activated, 'small') : t('never'),
    t('%activated_medium') => $node->activated ? format_date($node->activated, 'medium') : t('never'),
    t('%activated_large') => $node->activated ? format_date($node->activated, 'large') : t('never'),
    t('%expired_small') => $node->expired ? format_date($node->expired, 'small') : t('never'),
    t('%expired_medium') => $node->expired ? format_date($node->expired, 'medium') : t('never'),
    t('%expired_large') => $node->expired ? format_date($node->expired, 'large') : t('never'),
    t('%autoactivate_small') => $node->autoactivate ? format_date($node->autoactivate, 'small') : t('never'),
    t('%autoactivate_medium') => $node->autoactivate ? format_date($node->autoactivate, 'medium') : t('never'),
    t('%autoactivate_large') => $node->autoactivate ? format_date($node->autoactivate, 'large') : t('never'),
    t('%autoexpire_small') => $node->autoexpire ? format_date($node->autoexpire, 'small') : t('never'),
    t('%autoexpire_medium') => $node->autoexpire ? format_date($node->autoexpire, 'medium') : t('never'),
    t('%autoexpire_large') => $node->autoexpire ? format_date($node->autoexpire, 'large') : t('never'),
    t('%maxviews') => $node->maxviews,
    t('%maxclicks') => $node->maxclicks,
    t('%global_views') => $statistics['global']['views'],
    t('%global_clicks') => $statistics['global']['clicks'],
    t('%last_year_views') => $statistics['last_year']['views'],
    t('%last_year_clicks') => $statistics['last_year']['clicks'],
    t('%this_year_views') => $statistics['this_year']['views'],
    t('%this_year_clicks') => $statistics['this_year']['clicks'],
    t('%last_month_views') => $statistics['last_month']['views'],
    t('%last_month_clicks') => $statistics['last_month']['clicks'],
    t('%this_month_views') => $statistics['this_month']['views'],
    t('%this_month_clicks') => $statistics['this_month']['clicks'],
    t('%this_week_views') => $statistics['this_week']['views'],
    t('%this_week_clicks') => $statistics['this_week']['clicks'],
    t('%yesterday_views') => $statistics['yesterday']['views'],
    t('%yesterday_clicks') => $statistics['yesterday']['clicks'],
    t('%today_views') => $statistics['today']['views'],
    t('%today_clicks') => $statistics['today']['clicks'],
    t('%last_hour_views') => $statistics['last_hour']['views'],
    t('%last_hour_clicks') => $statistics['last_hour']['clicks'],
    t('%this_hour_views') => $statistics['this_hour']['views'],
    t('%this_hour_clicks') => $statistics['this_hour']['clicks'],
  );

  // TODO: Add hook to allow other modules to define variables.
  // TODO: Should the from_address be configurable?
  drupal_mail('ad_notify_mail', $notification->address, strtr($notification->subject, $variables), wordwrap(strtr($notification->body, $variables), 72), variable_get('site_mail', ini_get('sendmail_from')));
}