source: sipes/modules_contrib/token/token_user.inc @ dba7f09

stableversion-3.0
Last change on this file since dba7f09 was d5990f8, checked in by José Gregorio Puentes <jpuentes@…>, 8 años ago

se actualizo el modulo

  • Propiedad mode establecida a 100755
File size: 2.9 KB
Línea 
1<?php
2
3/**
4 * @file
5 * Implementations of token module hooks for the core user module.
6 *
7 * The token module requires specific hooks to be added to modules
8 * so that those modules can return data about their objects to the
9 * token API.  Until and unless token becomes a part of core, the
10 * implementations of the token hooks for core modules are provided
11 * in the token module itself.
12 *
13 * @ingroup token
14 */
15
16/**
17 * Implementation of hook_token_list().
18 */
19function user_token_list($type = 'all') {
20  $tokens = array();
21
22  if ($type == 'user' || $type == 'all') {
23    $tokens['user']['user']     = t("The login name of the user account.");
24    $tokens['user']['user-raw'] = t("The login name of the user account.");
25    $tokens['user']['uid']      = t("The unique ID of the user account.");
26    $tokens['user']['mail']     = t("The email address of the user account.");
27
28    $tokens['user'] += token_get_date_token_info(t("User's registration"), 'user-created-');
29    $tokens['user'] += token_get_date_token_info(t("User's last login"), 'user-last-login-');
30    $tokens['user']['date-in-tz'] = t("The current date in the user's timezone.");
31
32    $tokens['user']['account-url']      = t("The URL of the account profile page.");
33    $tokens['user']['account-edit-url'] = t("The URL of the account edit page.");
34  }
35
36  return $tokens;
37}
38
39/**
40 * Implementation of hook_token_values().
41 */
42function user_token_values($type, $object = NULL, $options = array()) {
43  $values = array();
44
45  if ($type == 'user') {
46    // @todo Why do we all the current user object to be loaded?
47    $account = !empty($object) ? $object : user_load(array('uid' => $GLOBALS['user']->uid));
48
49    // Adjust for the anonymous user name.
50    if (!$account->uid && empty($account->name)) {
51      $account_name = variable_get('anonymous', 'Anonymous');
52    }
53    else {
54      $account_name = $account->name;
55    }
56
57    $values['user']     = check_plain($account_name);
58    $values['user-raw'] = $account_name;
59    $values['uid']      = $account->uid;
60    $values['mail']     = $account->uid ? $account->mail : '';
61
62    if ($account->uid) {
63      $values += token_get_date_token_values($account->created, 'user-created-');
64      $values += token_get_date_token_values($account->access, 'user-last-login-');
65      $values['reg-date'] = $values['user-created-small'];
66      $values['reg-since'] = $values['user-created-since'];
67      $values['log-date'] = $values['user-last-login-small'];
68      $values['log-since'] = $values['user-last-login-since'];
69      $values['date-in-tz'] = $account->uid ? format_date(time(), 'small', '', $account->timezone) : '';
70    }
71
72    $values['account-url']      = $account->uid ? url("user/$account->uid", array('absolute' => TRUE)) : '';
73    $values['account-edit-url'] = $account->uid ? url("user/$account->uid/edit", array('absolute' => TRUE)) : '';
74    $values['account-edit']     = $values['account-edit-url'];
75  }
76
77  return $values;
78}
Nota: Vea TracBrowser para ayuda de uso del navegador del repositorio.