function authcache_authcache_request_exclude in Authenticated User Page Caching (Authcache) 7.2
Implements hook_authcache_request_exclude().
Related topics
File
- ./
authcache.module, line 919 - Authenticated User Page Caching (and anonymous users, too!)
Code
function authcache_authcache_request_exclude() {
// The following four basic exclusion rules are mirrored in
// authcacheinc_retrieve_cache_page() in authcache_builtin.cache.inc
// BEGIN: basic exclusion rules.
if (!($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'HEAD')) {
return t('Only GET and HEAD requests allowed. Method for this request is: @method.', array(
'@method' => $_SERVER['REQUEST_METHOD'],
));
}
if (variable_get('cache') || variable_get('page_cache_without_database')) {
return t('Drupal core page caching for anonymous users active.');
}
$frontscripts = variable_get('authcache_frontcontroller_whitelist', array(
DRUPAL_ROOT . '/index.php',
));
$frontscripts = array_map('realpath', $frontscripts);
if (!in_array(realpath($_SERVER['SCRIPT_FILENAME']), $frontscripts)) {
return t('Not invoked using an allowed front controller.');
}
// END: basic exclusion rules.
//
if (!authcache_backend()) {
return t('No active cache backend.');
}
if (variable_get('authcache_noajax', FALSE) && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') {
return t('Ajax request');
}
$alias = drupal_get_path_alias($_GET['q']);
// Now check page caching settings, defined by the site admin.
$pagecaching = variable_get('authcache_pagecaching', _authcache_default_pagecaching());
foreach ($pagecaching as $i => $page_rules) {
$rule_num = $i + 1;
// Do caching page roles apply to current user?
if (authcache_role_restrict_access($page_rules['roles'])) {
switch ($page_rules['option']) {
case '0':
// Cache every page except the listed pages.
case '1':
// Cache only the listed pages.
$page_listed = drupal_match_path($alias, $page_rules['pages']);
if (!!($page_rules['option'] xor $page_listed)) {
return t('Caching disabled by path list of page ruleset #@number', array(
'@number' => $rule_num,
));
}
break;
case '2':
// Cache pages for which the following PHP code returns TRUE.
$result = 0;
if (module_exists('php')) {
$result = php_eval($page_rules['pages']);
}
if (empty($result)) {
return t('Caching disabled by PHP rule of page ruleset #@number', array(
'@number' => $rule_num,
));
}
break;
default:
break;
}
if (!empty($page_rules['noadmin']) && path_is_admin(current_path())) {
return t('Not caching admin pages (by page ruleset #@number)', array(
'@number' => $rule_num,
));
}
}
}
}