Projet

Général

Profil

Paste
Télécharger (1,4 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / piwik / piwik.tokens.inc @ a5572547

1 85ad3d82 Assos Assos
<?php
2
3
/**
4
 * @file
5
 * Builds placeholder replacement tokens for user-related data.
6
 */
7
8
/**
9
 * Implements hook_token_info().
10
 */
11
function piwik_token_info() {
12
  $user['piwik-role-names'] = array(
13
    'name' => t('User role names'),
14
    'description' => t('The role names the user account is a member of as comma separated list.'),
15
    'needs-data' => 'user',
16
  );
17
  $user['piwik-role-ids'] = array(
18
    'name' => t('User role ids'),
19
    'description' => t('The role ids the user account is a member of as comma separated list.'),
20
    'needs-data' => 'user',
21
  );
22
23
  return array(
24
    'tokens' => array('user' => $user),
25
  );
26
}
27
28
/**
29
 * Implements hook_tokens().
30
 */
31
function piwik_tokens($type, $tokens, array $data = array(), array $options = array()) {
32
  $sanitize = !empty($options['sanitize']);
33
  $replacements = array();
34
35
  if ($type == 'user' && !empty($data['user']->roles)) {
36
    $account = $data['user'];
37
38
    foreach ($tokens as $name => $original) {
39
      switch ($name) {
40
        // Basic user account information.
41
        case 'piwik-role-names':
42
          $names = implode(',', $account->roles);
43
          $replacements[$original] = $sanitize ? check_plain($names) : $names;
44
          break;
45
46
        case 'piwik-role-ids':
47
          $ids = implode(',', array_keys($account->roles));
48
          $replacements[$original] = $sanitize ? check_plain($ids) : $ids;
49
          break;
50
      }
51
    }
52
  }
53
54
  return $replacements;
55
}