Projet

Général

Profil

Paste
Télécharger (2,16 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / i18n / i18n_user / i18n_user.module @ 76df55b7

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
    $language = $message['language'];
13
    $variables = array('user' => $message['params']['account']);
14
    $key = $message['key'];
15

    
16
    $components = array('subject', 'body');
17
    foreach ($components as $component) {
18
      $text = i18n_variable_get('user_mail_' . $key . '_' . $component, $language->language, FALSE);
19
      if ($text) {
20
        $text = token_replace($text, $variables, array('language' => $language, 'callback' => 'i18n_user_user_mail_tokens', 'sanitize' => FALSE));
21

    
22
        switch ($component) {
23
          case 'subject':
24
            $message[$component] = $text;
25
            break;
26

    
27
          case 'body':
28
            $message[$component] = array($text);
29
            break;
30
        }
31
      }
32
    }
33
  }
34
}
35

    
36
/**
37
 * Overrides user_mail_tokens().
38
 *
39
 * @see i18n_user_user_tokens_alter()
40
 * @see user_mail_tokens()
41
 */
42
function i18n_user_user_mail_tokens(&$replacements, $data, $options) {
43
  if (isset($data['user'])) {
44
    $replacements['[user:one-time-login-url]'] = i18n_user_user_pass_reset_url($data['user']);
45
    $replacements['[user:cancel-url]'] = i18n_user_user_cancel_url($data['user']);
46
  }
47
}
48

    
49
/**
50
 * Overrides user_pass_reset_url().
51
 * Generates a unique and localized URL for a user to login and reset their password.
52
 *
53
 * @see user_pass_reset_url().
54
 */
55
function i18n_user_user_pass_reset_url($account) {
56
  $timestamp = REQUEST_TIME;
57
  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)));
58
}
59

    
60
/**
61
 * Overrides user_pass_cancel_url().
62
 * Generates a localized URL to confirm an account cancellation request.
63
 *
64
 * @see i18n_user_user_cancel_url()
65
 */
66
function i18n_user_user_cancel_url($account) {
67
  $timestamp = REQUEST_TIME;
68
  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)));
69
}