diff options
author | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-09-10 09:28:28 +0000 |
---|---|---|
committer | Gábor Hojtsy <gabor@hojtsy.hu> | 2007-09-10 09:28:28 +0000 |
commit | f0cb501c23dc720ad5bf7c21546cd8bcdc3841d0 (patch) | |
tree | 2e3c690374267ab1884a096b700326c65d5dc1dd /modules/system | |
parent | c4b02c121301af3cea351ec6f267aa3b1099bdd5 (diff) | |
download | brdo-f0cb501c23dc720ad5bf7c21546cd8bcdc3841d0.tar.gz brdo-f0cb501c23dc720ad5bf7c21546cd8bcdc3841d0.tar.bz2 |
#174169 by chx: correct usage of drupal_mail() with actions
Diffstat (limited to 'modules/system')
-rw-r--r-- | modules/system/system.module | 82 |
1 files changed, 49 insertions, 33 deletions
diff --git a/modules/system/system.module b/modules/system/system.module index 6b65c0b44..a469c6cae 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -1444,7 +1444,6 @@ function system_send_email_action_submit($form, $form_state) { */ function system_send_email_action($object, $context) { global $user; - $variables['%site_name'] = variable_get('site_name', 'Drupal'); switch ($context['hook']) { case 'nodeapi': @@ -1471,25 +1470,11 @@ function system_send_email_action($object, $context) { return; } break; - case 'taxonomy': - $account = $user; - $vocabulary = taxonomy_vocabulary_load($object->vid); - $variables = array_merge($variables, array( - '%term_name' => $object->name, - '%term_description' => $object->description, - '%term_id' => $object->tid, - '%vocabulary_name' => $vocabulary->name, - '%vocabulary_description' => $vocabulary->description, - '%vocabulary_id' => $vocabulary->vid, - ) - ); - break; default: // We are being called directly. $node = $object; } - $from = variable_get('site_mail', ini_get('sendmail_from')); $recipient = $context['recipient']; if (isset($node)) { @@ -1501,27 +1486,17 @@ function system_send_email_action($object, $context) { } } - $variables['%username'] = $account->name; + if (!isset($account)) { + $account = $user; - // Node-based variable translation is only available if we have a node. - if (isset($node) && is_object($node)) { - $variables = array_merge($variables, array( - '%uid' => $node->uid, - '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)), - '%node_type' => node_get_types('name', $node), - '%title' => $node->title, - '%teaser' => $node->teaser, - '%body' => $node->body - ) - ); + } + $language = user_preferred_language($account); + $params = array('account' => $account, 'object' => $object, 'context' => $context); + if (isset($node)) { + $params['node'] = $node; } - $subject = strtr($context['subject'], $variables); - $subject = str_replace(array("\r", "\n"), '', $subject); - $message = strtr($context['message'], $variables); - $body = drupal_html_to_text($message); - - if (drupal_mail('action_send_email', $recipient, $subject, $body, $from )) { + if (drupal_mail('system', 'action_send_email', $recipient, $language, $params)) { watchdog('action', 'Sent email to %recipient', array('%recipient' => $recipient)); } else { @@ -1529,6 +1504,47 @@ function system_send_email_action($object, $context) { } } +/** + * Implementation of hook_mail(). + */ +function system_mail($key, &$message, $params) { + $account = $params['account']; + $context = $params['context']; + $variables = array( + '%site_name' => variable_get('site_name', 'Drupal'), + '%username' => $account->name, + ); + if ($context['hook'] == 'taxonomy') { + $object = $params['object']; + $vocabulary = taxonomy_vocabulary_load($object->vid); + $variables += array( + '%term_name' => $object->name, + '%term_description' => $object->description, + '%term_id' => $object->tid, + '%vocabulary_name' => $vocabulary->name, + '%vocabulary_description' => $vocabulary->description, + '%vocabulary_id' => $vocabulary->vid, + ); + } + + // Node-based variable translation is only available if we have a node. + if (isset($params['node'])) { + $node = $params['node']; + $variables += array( + '%uid' => $node->uid, + '%node_url' => url('node/'. $node->nid, array('absolute' => TRUE)), + '%node_type' => node_get_types('name', $node), + '%title' => $node->title, + '%teaser' => $node->teaser, + '%body' => $node->body, + ); + } + $subject = strtr($context['subject'], $variables); + $body = strtr($context['message'], $variables); + $message['subject'] .= str_replace(array("\r", "\n"), '', $subject); + $message['body'][] = drupal_html_to_text($body); +} + function system_message_action_form($context) { $form['message'] = array( '#type' => 'textarea', |