[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/token/ -> token_user.inc (source)

   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   */
  19  function user_token_list($type = 'all') {
  20    if ($type == 'user' || $type == 'all') {
  21      $tokens['user']['user']     = t("The login name of the user account.");
  22      $tokens['user']['user-raw'] = t("The login name of the user account.");
  23      $tokens['user']['uid']      = t("The unique ID of the user account.");
  24      $tokens['user']['mail']     = t("The email address of the user account.");
  25  
  26      $tokens['user'] += token_get_date_token_info(t("User's registration"), 'user-created-');
  27      $tokens['user'] += token_get_date_token_info(t("User's last login"), 'user-last-login-');
  28      $tokens['user']['date-in-tz'] = t("The current date in the user's timezone.");
  29  
  30      $tokens['user']['account-url']      = t("The URL of the account profile page.");
  31      $tokens['user']['account-edit-url'] = t("The URL of the account edit page.");
  32  
  33      return $tokens;
  34    }
  35  }
  36  
  37  /**
  38   * Implementation of hook_token_values().
  39   */
  40  function user_token_values($type, $object = NULL, $options = array()) {
  41    $values = array();
  42    switch ($type) {
  43      case 'user':
  44        if (!empty($object)) {
  45          $account = $object;
  46        }
  47        else {
  48          $account = user_load(array('uid' => $GLOBALS['user']->uid));
  49        }
  50  
  51        // Adjust for the anonymous user name.
  52        if (!$account->uid && !$account->name) {
  53          $account->name = variable_get('anonymous', 'Anonymous');
  54        }
  55  
  56        $values['user']     = check_plain($account->name);
  57        $values['user-raw'] = $account->name;
  58        $values['uid']      = $account->uid;
  59        $values['mail']     = $account->uid ? $account->mail : '';
  60  
  61        if ($account->uid) {
  62          $values += token_get_date_token_values($account->created, 'user-created-');
  63          $values += token_get_date_token_values($account->access, 'user-last-login-');
  64          $values['reg-date'] = $values['user-created-small'];
  65          $values['reg-since'] = $values['user-created-since'];
  66          $values['log-date'] = $values['user-last-login-small'];
  67          $values['log-since'] = $values['user-last-login-since'];
  68          $values['date-in-tz'] = $account->uid ? format_date(time(), 'small', '', $account->timezone) : '';
  69        }
  70  
  71        $values['account-url']      = $account->uid ? url("user/$account->uid", array('absolute' => TRUE)) : '';
  72        $values['account-edit-url'] = $account->uid ? url("user/$account->uid/edit", array('absolute' => TRUE)) : '';
  73        $values['account-edit']     = $values['account-edit-url'];
  74  
  75        break;
  76    }
  77    return $values;
  78  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7