function authcache_init in Authenticated User Page Caching (Authcache) 7
Same name and namespace in other branches
- 6 authcache.module \authcache_init()
- 7.2 authcache.module \authcache_init()
Implements hook_init().
File
- ./
authcache.module, line 113 - Authenticated User Page Caching (and anonymous users, too!)
Code
function authcache_init() {
global $user, $_authcache_is_cacheable, $_authcache_info;
// Pressflow compatibility (since Pressflow doesn't set this cookie)
if (($sysblock = system_block_info()) && $sysblock['powered-by'] == t('Powered by Pressflow')) {
drupal_add_js("document.cookie = 'has_js=1; path=/';", array(
'scope' => 'header',
));
}
// Authcache core JS and cookie library
drupal_add_library('system', 'jquery.cookie');
drupal_add_js(drupal_get_path('module', 'authcache') . '/authcache.js');
// Add JS for debug mode?
if (_authcache_debug_access()) {
drupal_add_js(drupal_get_path('module', 'authcache') . '/authcache.debug.js', array(
'type' => 'file',
'scope' => 'header',
));
// Also see authcache_authcache_info() for user debug settings
}
drupal_add_css(drupal_get_path('module', 'authcache') . '/authcache.css', array(
'type' => 'file',
'scope' => 'header',
));
//moved to hook_exit (as per boost module) as an experiment
//register_shutdown_function('_authcache_shutdown_save_page');
$_authcache_info = array();
$_authcache_is_cacheable = _authcache_is_cacheable();
if ($_authcache_is_cacheable) {
global $conf;
// Don't allow format_date() to use the user's local timezone
$conf['configurable_timezones'] = FALSE;
// Initialize Authcache after all other JS is loaded
drupal_add_js('jQuery(function() { Authcache.init(); });', array(
'type' => 'inline',
'scope' => 'header',
));
// Force Ajax to use POST method instead of GET
if (variable_get('authcache_post', FALSE)) {
drupal_add_js(array(
'Authcache' => array(
'post' => 1,
),
), array(
'type' => 'setting',
'scope' => 'header',
));
}
// Forcibly disable Drupal's built-in SQL caching
// (No need to cache page twice for anonymous users)
if (!$user->uid && variable_get('cache', CACHE_DISABLED) != CACHE_DISABLED) {
$conf['cache'] = CACHE_DISABLED;
}
// Status messages prevent pages from being cached.
if (variable_get('authcache_debug_page', FALSE)) {
drupal_set_message(t('Caching disabled by') . ' ' . l('Authcache Config.', 'admin/config/development/performance/authcache/config'));
}
}
// Remove debug cookies
if (isset($_COOKIE['authcache_debug']) && !_authcache_debug_access()) {
setcookie('authcache_debug', "", REQUEST_TIME - 84000);
// Delete JS cookie
setcookie('authcache_debug', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1');
setcookie('nocache', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1');
setcookie('nocache_temp', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1');
}
}