You are here

function session_limit_tokens in Session Limit 7.2

Implements hook_tokens().

File

./session_limit.tokens.inc, line 46
Provide tokens for session limit.

Code

function session_limit_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();

  // The session limit variable does not need the user context.
  if ($type == 'session_limit') {
    foreach ($tokens as $name => $original) {
      if ($name == 'default') {
        $replacements[$original] = variable_get('session_limit_max', 1);
      }
    }
  }
  if ($type == 'session_limit' && !empty($data['user'])) {
    $account = user_load($data['user']->uid);
    foreach ($tokens as $name => $original) {
      switch ($name) {
        case 'max':
          $replacements[$original] = session_limit_user_max_sessions($account);
          break;
        case 'role':
          $replacements[$original] = session_limit_user_max_sessions_byrole($account);
          break;
        case 'user':
          $replacements[$original] = empty($account->session_limit) ? 0 : check_plain($account->session_limit);
          break;
      }
    }
  }
  return $replacements;
}