You are here

function answers_notify_new_answer in Answers 6.2

Same name and namespace in other branches
  1. 7 includes/answers.notify.inc \answers_notify_new_answer()
  2. 7.2 includes/answers.notify.inc \answers_notify_new_answer()
  3. 7.3 includes/answers.notify.inc \answers_notify_new_answer()

If configured to, notify question author of an answer.

Parameters

$nid: Numeric node NID of question.

1 call to answers_notify_new_answer()
_answers_notify_nodeapi in includes/answers.notify.inc
Pseudo implementation of hook_nodeapi().

File

includes/answers.notify.inc, line 94
Notification functionality for 'Answers' to inform users of answers.

Code

function answers_notify_new_answer($nid) {
  global $user;
  $question = node_load($nid);
  $notify_p = $question->field_notify_p[0]['value'];
  if ($notify_p) {
    $question_user = user_load($question->uid);
    $params = array(
      '!question_user_name' => $question_user->name,
      '!answer_user_name' => $user->uid == 0 ? 'anonymous' : $user->name,
      '!question_title' => $question->title,
      '!question_url' => url('node/' . $nid, array(
        'absolute' => TRUE,
        'target' => '_blank',
      )),
      '!site' => variable_get('site_name', 'drupal'),
    );
    $language = user_preferred_language($question_user);
    $subject_template = variable_get('answers_answer_notification_subject', ANSWERS_DEFAULT_NEW_ANSWER_NOTICE_SUBJECT);
    $subject = t($subject_template, $params, $language->language);
    $body_template = variable_get('answers_answer_notification_body', ANSWERS_DEFAULT_NEW_ANSWER_NOTICE_BODY);
    $body = t($body_template, $params, $language->language);
    if (!module_exists('mimemail')) {
      $headers['MIME-Version'] = '1.0';
    }
    $headers['Content-Type'] = "text/html";
    $headers['From'] = variable_get('site_mail', ini_get('sendmail_from'));
    $message = array(
      'headers' => $headers,
      'to' => $question_user->mail,
      'from' => variable_get('site_mail', ini_get('sendmail_from')),
      'subject' => $subject,
      'body' => $body,
    );
    drupal_mail_send($message);
  }
}