array('administer mail templates'), 'file' => 'mail_edit.admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('mail_edit_list_form'), 'description' => 'Edit mails being sent out by Drupal.', 'title' => 'Mail templates', ); $items['admin/build/mail-edit/%/%'] = array( 'access arguments' => array('administer mail templates'), 'file' => 'mail_edit.admin.inc', 'page callback' => 'drupal_get_form', 'page arguments' => array('mail_edit_trans', 3, 4), 'description' => 'Edit mails being sent out by Drupal.', 'title' => 'Mail templates', ); return $items; } /** * Implementation of hook_theme(). */ function mail_edit_theme() { return array( 'mail_edit_table' => array( 'arguments' => array('form' => NULL), 'file' => 'mail_edit.admin.inc', ), 'mail_edit_list_filter' => array( 'arguments' => array('form' => NULL), 'file' => 'mail_edit.admin.inc', ), ); } /** * Implementation of hook_mail_alter(). */ function mail_edit_mail_alter(&$mail) { _mail_edit_include(); // Find out if this mail id in our registry. $query = "SELECT * FROM {mail_edit_registry} where id = '%s'"; $result = db_query($query, $mail['id']); $mail_data = db_fetch_object($result); if (!$mail_data) { // If we dont have registry record of mail id in question we shouldnt attempt to alter it. return ; } // Load mail template if we have altered it. $query = "SELECT * FROM {mail_edit} WHERE id = '%s' AND language = '%s'"; $arg[] = $mail['id']; $arg[] = $mail['language']->language; $template = db_fetch_object(db_query($query, $arg)); // Do not try to alter anything if we didn't modify this mail template. if ($template) { // Fetch our token values. $tokens = module_invoke($mail_data->module, 'mail_edit_tokens_value', $mail_data->mailkey, $mail); uksort($tokens, '_mail_edit_sort_long_keys_first'); $result = new stdClass(); $result->tokens = array_keys($tokens); $result->values = array_values($tokens); // Perform replacement of tokens. $mail['subject'] = str_replace($result->tokens, $result->values, $template->subject); unset($mail['body']); $mail['body'][] = str_replace($result->tokens, $result->values, $template->body); } } /* * mail_edit needs the tokens in order of longest keys first * (so [user-raw] comes before [user], for example), * to prevent premature interpolation. */ function _mail_edit_sort_long_keys_first($a, $b) { return (strlen($b) - strlen($a)); }