function esi__get_cookie_data in ESI: Edge Side Includes 7.3
Get all the relevant cookie data for an account.
2 calls to esi__get_cookie_data()
- esi_user_logout in ./
esi.module - Implements hook_user_logout().
- esi__set_user_contexts in ./
esi.module - Set the cookies to track current ESI contexts.
File
- ./
esi.module, line 398 - Adds support for ESI (Edge-Side-Include) integration, allowing components\ to be delivered by ESI, with support for per-component cache times.
Code
function esi__get_cookie_data($account) {
$cookie_data = array();
// Allow other modules to generate context for this user.
$contexts = esi__get_user_contexts($account);
// Use the same path/domain/secure/httponly params as the main site config.
$params = session_get_cookie_params();
$expire = $params['lifetime'] ? REQUEST_TIME + $params['lifetime'] : 0;
$cookie_name_prefix = variable_get('esi_cookie_name_prefix', ESI_DEFAULT_COOKIE_NAME_PREFIX);
// If support for the AJAX fallback with contextualized URLs is needed, then
// the ESI cookies must be accessible to JavaScript.
$ajax_with_contextualize_urls = variable_get('esi_ajax_fallback', ESI_DEFAULT_AJAX_FALLBACK) && variable_get('esi_ajax_fallback_contextualize_url', ESI_DEFAULT_AJAX_FALLBACK_CONTEXTUALIZE_URL);
if ($ajax_with_contextualize_urls) {
$params['httponly'] = FALSE;
}
foreach ($contexts as $key => $context) {
// Each context has the session key appended to it, to ensure site-
// specifity.
$cookie_data[] = array(
'name' => $cookie_name_prefix . $key,
'value' => $context,
'expire' => $expire,
'path' => $params['path'],
'domain' => $params['domain'],
'secure' => $params['secure'],
'httponly' => $params['httponly'],
);
}
// Allow other modules to alter the contexts.
// This is where the context gets encrypted against the rotating seed.
drupal_alter('esi_context_cookies', $cookie_data);
// Add a *consistent* cookie, so that hook_boot() can determine if a cache-
// refresh is necessary.
$cookie_data[] = array(
'name' => 'ESI_',
'value' => time(),
'expire' => $expire,
'path' => $params['path'],
'domain' => $params['domain'],
'secure' => $params['secure'],
'httponly' => $params['httponly'],
);
// The ESI cookie names are predictable. They can be made less predictable,
// by using the same session-naming convention as core - adding a hash of the
// domain name as a suffix.
// See drupal_settings_initialize() where the session name is initialized.
$harden_esi_cookies = variable_get('esi_harden_cookie_key', ESI_DEFAULT_CONTEXT_COOKIES_HARDENING);
if ($harden_esi_cookies) {
$session_name = '_' . session_name();
foreach ($cookie_data as &$cookie) {
$cookie['name'] .= $session_name;
}
}
return $cookie_data;
}