diff --git a/esi.admin.inc b/esi.admin.inc index d560582..3316fef 100644 --- a/esi.admin.inc +++ b/esi.admin.inc @@ -131,6 +131,19 @@ function esi_admin_settings_form() { '#description' => t('Disabled - Do not use ESI.
Not Cached - Use ESI, but never cache the content.
Global - Content is same on every page.
Page - Content changes based on the URL.
User Role - Content changes based on the user role.
User Role/Page - Content changes based on the user role as well as the URL.
User ID - Content changes based on the UID; otherwise it is the same as global.
User ID/Page - Content changes based on the UID and based on the URL.'), ); + // Roles config + $form['roles'] = array( + '#type' => 'fieldset', + '#title' => t('Role settings'), + ); + $form['roles']['esi_include_roles'] = array( + '#title' => t('Roles included in User Role scope'), + '#type' => 'checkboxes', + '#options' => user_roles(FALSE), + '#default_value' => variable_get('esi_include_roles', array()), + '#description' => t('Choose the roles that will be included in the roles hash. Only select roles that may affect caching. If you select no roles, all roles will be candidates.'), + ); + // Cache Flusing $form['cache_page'] = array( '#type' => 'fieldset', diff --git a/esi.inc b/esi.inc index 6c94504..48bef52 100644 --- a/esi.inc +++ b/esi.inc @@ -51,11 +51,19 @@ function _esi__get_roles_hash($rids = NULL) { global $user; $rids = !empty($user->roles) ? array_keys($user->roles) : 0; } + $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; + } - $hash = implode(':', $rids); + $hash = implode(':', $included_rids); if (!isset($roles[$hash])) { $seed = _esi__get_seed_key(); $roles[$hash] = md5($seed . md5($hash)); + drupal_alter('esi_roles_hash', $roles[$hash], $included_rids, $rids, $seed); } return $roles[$hash]; } @@ -77,6 +85,7 @@ function esi_get_user_hash($uid = NULL) { if (!isset($users[$uid])) { $seed = _esi__get_seed_key(); $users[$uid] = md5($seed . md5($uid)); + drupal_alter('esi_user_hash', $users[$uid], $uid, $seed); } return $users[$uid]; }