You are here

function _esi__get_roles_hash in ESI: Edge Side Includes 6.2

Get the hash for a set of roles.

Parameters

array $rids: An array of role-ids

2 calls to _esi__get_roles_hash()
esi_user in ./esi.module
Implementation of hook_user(). For maximum cache-efficiency, the proxy must be able to identify the roles held by a user. A cookie is used which provides a consistent hash for all users who share the same roles. For security, the hash uses a random…
theme_esi_tag in ./esi.theme.inc
Create the ESI-tag for a particular block.

File

./esi.inc, line 47
Helper functions for the ESI module.

Code

function _esi__get_roles_hash($rids = NULL) {
  static $roles = array();

  // Get all roles.
  if (empty($rids)) {
    global $user;
    $rids = !empty($user->roles) ? array_keys($user->roles) : 0;
  }

  // Get roles saved from admin/settings/esi.
  $include_roles = array_filter(variable_get('esi_include_roles', array()));
  if (!empty($include_roles)) {
    $included_rids = array_intersect($rids, $include_roles);
  }
  else {
    $included_rids = $rids;
  }

  // Create a hash of the roles.
  $hash = implode(':', $included_rids);
  if (!isset($roles[$hash])) {
    $seed = _esi__get_seed_key();
    $roles[$hash] = md5($seed . md5($hash));

    // Invloke hook_esi_roles_hash().
    drupal_alter('esi_roles_hash', $roles[$hash], $included_rids, $rids, $seed);
  }
  return $roles[$hash];
}