Project

General

Profile

Paste
Download (2.48 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / i18n / i18n_user / i18n_user.module @ 01f36513

1
<?php
2
/**
3
 * @file
4
 * User mail translation module.
5
 */
6

    
7
/**
8
 * Implements hook_mail_alter().
9
 */
10
function i18n_user_mail_alter(&$message) {
11
  if ($message['module'] == 'user') {
12
    $message['language'] = language_default();
13
    if (isset($message['params']['account'])) {
14
      $user_preferred = user_preferred_language($message['params']['account']);
15
      if (isset($user_preferred)) {
16
        $message['language'] = $user_preferred;
17
      }
18
    }
19
    $language = (isset($message['language']) ? $message['language'] : language_default());
20
    $variables = array('user' => $message['params']['account']);
21
    $key = $message['key'];
22

    
23
    $components = array('subject', 'body');
24
    foreach ($components as $component) {
25
      $text = i18n_variable_get('user_mail_' . $key . '_' . $component, $language->language, FALSE);
26
      if ($text) {
27
        $text = token_replace($text, $variables, array('language' => $language, 'callback' => 'i18n_user_user_mail_tokens', 'sanitize' => FALSE));
28

    
29
        switch ($component) {
30
          case 'subject':
31
            $message[$component] = $text;
32
            break;
33

    
34
          case 'body':
35
            $message[$component] = array($text);
36
            break;
37
        }
38
      }
39
    }
40
  }
41
}
42

    
43
/**
44
 * Overrides user_mail_tokens().
45
 *
46
 * @see i18n_user_user_tokens_alter()
47
 * @see user_mail_tokens()
48
 */
49
function i18n_user_user_mail_tokens(&$replacements, $data, $options) {
50
  if (isset($data['user'])) {
51
    $replacements['[user:one-time-login-url]'] = i18n_user_user_pass_reset_url($data['user']);
52
    $replacements['[user:cancel-url]'] = i18n_user_user_cancel_url($data['user']);
53
  }
54
}
55

    
56
/**
57
 * Overrides user_pass_reset_url().
58
 * Generates a unique and localized URL for a user to login and reset their password.
59
 *
60
 * @see user_pass_reset_url().
61
 */
62
function i18n_user_user_pass_reset_url($account) {
63
  $timestamp = REQUEST_TIME;
64
  return url("user/reset/$account->uid/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid), array('absolute' => TRUE, 'language' => i18n_language($account->language)));
65
}
66

    
67
/**
68
 * Overrides user_pass_cancel_url().
69
 * Generates a localized URL to confirm an account cancellation request.
70
 *
71
 * @see i18n_user_user_cancel_url()
72
 */
73
function i18n_user_user_cancel_url($account) {
74
  $timestamp = REQUEST_TIME;
75
  return url("user/$account->uid/cancel/confirm/$timestamp/" . user_pass_rehash($account->pass, $timestamp, $account->login, $account->uid), array('absolute' => TRUE, 'language' => i18n_language($account->language)));
76
}