You are here

function user_token_values in Token 5

Same name and namespace in other branches
  1. 6 token_user.inc \user_token_values()

Implementation of hook_token_values().

File

./token_user.inc, line 40
Implementations of token module hooks for the core user module.

Code

function user_token_values($type, $object = NULL, $options = array()) {
  $values = array();
  switch ($type) {
    case 'user':
      if (isset($object)) {
        $account = $object;
      }
      else {
        global $user;
        $account = user_load(array(
          'uid' => $user->uid,
        ));
      }

      // Adjust for the anonymous user name.
      if (!$account->uid && !$account->name) {
        $account->name = variable_get('anonymous', 'Anonymous');
      }
      $values['user'] = check_plain($account->name);
      $values['user-raw'] = $account->name;
      $values['uid'] = $account->uid;
      $values['mail'] = $account->uid ? $account->mail : '';
      if ($account->uid) {
        $values += token_get_date_token_values($account->created, 'user-created-');
        $values += token_get_date_token_values($account->access, 'user-last-login-');
        $values['reg-date'] = $values['user-created-small'];
        $values['reg-since'] = $values['user-created-since'];
        $values['log-date'] = $values['user-last-login-small'];
        $values['log-since'] = $values['user-last-login-since'];
        $values['date-in-tz'] = $account->uid ? format_date(time(), 'small', '', $account->timezone) : '';
      }
      $values['account-url'] = $account->uid ? url("user/{$account->uid}", NULL, NULL, TRUE) : '';
      $values['account-edit-url'] = $account->uid ? url("user/{$account->uid}/edit", NULL, NULL, TRUE) : '';
      $values['account-edit'] = $values['account-edit-url'];
      break;
  }
  return $values;
}