function support_mail_tokens in Support Ticketing System 6
Same name and namespace in other branches
- 7 support.module \support_mail_tokens()
Return an array of token to value mappings for support e-mail messages.
1 call to support_mail_tokens()
- support_mail in ./
support.module - Implementation of hook_mail().
File
- ./
support.module, line 1183 - support.module
Code
function support_mail_tokens($account, $language, $nid, $comment, $suppress, $html = FALSE) {
global $base_url, $user;
static $reset = TRUE;
// force reload node from database to get updated state/priority information,
// but no need to reset it multiple times when sending multiple notifications
$node = node_load($nid, NULL, $reset);
$assigned = user_load(array(
'uid' => $node->assigned,
));
$reset = FALSE;
if (isset($comment['cid'])) {
$cid = $comment['cid'];
$update_account = user_load($comment['uid']);
}
else {
$cid = 0;
$update_account = user_load($node->uid);
}
$client = support_client_load($node->client);
$ticket_unsubscribe_key = md5($account->uid . $node->nid);
$all_unsubscribe_key = md5($account->uid);
$previous_comment = db_result(db_query_range('SELECT cid FROM {comments} WHERE nid = %d ORDER BY cid DESC', $nid, 1, 1));
if ($previous_comment) {
$previous = db_fetch_object(db_query('SELECT * FROM {support_ticket_comment} WHERE cid = %d', $previous_comment));
}
if ($html) {
$body = check_markup($node->body, variable_get('mimemail_format', FILTER_FORMAT_DEFAULT), FALSE) . _support_mail_list_attachments($node, $comment);
$update = check_markup(isset($comment['comment']) ? $comment['comment'] : '', variable_get('mimemail_format', FILTER_FORMAT_DEFAULT), FALSE) . _support_mail_list_attachments($node, $comment);
}
else {
$body = drupal_html_to_text(check_markup($node->body) . _support_mail_list_attachments($node, $comment));
$update = drupal_html_to_text(check_markup(isset($comment['comment']) ? $comment['comment'] : '') . _support_mail_list_attachments($node, $comment));
}
$tokens = array(
'!username' => $account->name,
'!client_name' => $client->name,
'!client_path' => $client->path,
'!key' => '[' . variable_get('support_key', 'tkt') . ":{$nid}]",
'!ticket_id' => $nid,
'!ticket_update_id' => isset($comment['cid']) ? $comment['cid'] : 0,
'!update_username' => isset($update_account->name) ? $update_account->name : '',
'!update_realname' => theme('username', $user),
'!site' => variable_get('site_name', 'Drupal'),
'!uri' => $base_url,
'!uri_brief' => preg_replace('!^https?://!', '', $base_url),
'!uri_login' => url('user/register', array(
'absolute' => TRUE,
'alias' => !variable_get('support_use_aliased_urls', TRUE),
)),
'!mailto' => $account->mail,
'!date' => format_date(time(), 'medium', '', NULL, $language->language),
'!ticket_subject' => check_plain($node->title),
'!ticket_body' => $suppress ? t('The text of this ticket was manually suppressed. You must view the ticket online to see it.') . "\n" : $body,
'!ticket_url' => url("node/{$nid}", array(
'absolute' => TRUE,
'language' => $language,
'fragment' => "comment-{$cid}",
'alias' => !variable_get('support_use_aliased_urls', TRUE),
)),
'!update_url' => url("node/{$nid}", array(
'absolute' => TRUE,
'language' => $language,
'fragment' => "comment-form",
'alias' => !variable_get('support_use_aliased_urls', TRUE),
)),
'!update' => $suppress ? t('The text of this ticket update was manually suppressed. You must view the ticket online to see the update.') . "\n" : $update,
'!state' => (isset($previous->state) && $previous->state != $node->state ? _support_state($previous->state) . ' -> ' : '') . _support_state($node->state),
'!priority' => (isset($previous->priority) && $previous->priority != $node->priority ? _support_priorities($previous->priority) . ' -> ' : '') . _support_priorities($node->priority),
'!assigned_username' => !empty($assigned) ? $assigned->name : '',
'!assigned_realname' => !empty($assigned) ? theme('username', $assigned) : '',
'!unsubscribe_ticket' => url("support/{$nid}/unsubscribe/{$account->uid}/{$ticket_unsubscribe_key}", array(
'absolute' => TRUE,
'language' => $language,
'alias' => !variable_get('support_use_aliased_urls', TRUE),
)),
'!unsubscribe_all' => url("support/all/unsubscribe/{$account->uid}/{$all_unsubscribe_key}", array(
'absolute' => TRUE,
'language' => $language,
'alias' => !variable_get('support_use_aliased_urls', TRUE),
)),
);
if (!empty($account->password)) {
$tokens['!password'] = $account->password;
}
drupal_alter('support_mail_tokens', $tokens);
return $tokens;
}