diff -urp /home/lntw/temp/authcache/ajax/authcache.php authcache/ajax/authcache.php --- /home/lntw/temp/authcache/ajax/authcache.php 2009-09-13 18:04:54.000000000 -0400 +++ authcache/ajax/authcache.php 2009-10-11 07:24:07.000000000 -0400 @@ -4,7 +4,7 @@ /** * @file authcache.php * - * Authcache Ajax phase, included by ../authcache.inc during + * Authcache Ajax phase, included by ../authcache.inc during * Drupal's index.php EARLY_PAGE_CACHE bootstrap. Executed within * _drupal_bootstrap() function. * @@ -16,8 +16,10 @@ * For custom functions, use "authcache_custom.php" *************************************************************/ +global $is_ajax_authcache; + // Attempt to prevent "cross-site request forgery" by requiring a custom header -if(!isset($_SERVER['HTTP_AUTHCACHE'])) { +if(!isset($_SERVER['HTTP_AUTHCACHE'])) { header($err = 'HTTP/1.1 400 Bad Request (No Authcache Header)'); die($err); } @@ -139,11 +141,11 @@ function _authcache_statistics($vars) { function _authcache_forum_topic_new($vars) { global $user; $new = array(); - + drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH); include_once './modules/node/node.module'; // Need NODE_NEW_LIMIT definition include_once './modules/forum/forum.module'; - + foreach($vars as $tid) { $new_topics = (int)_forum_topics_unread($tid, $user->uid); if($new_topics) { @@ -201,7 +203,7 @@ function _authcache_poll($vars) { $node = node_load($vars['nid']); $node = poll_view($node, TRUE, FALSE, $vars['block']); $output = $node->content['body']['#value']; - + return array( 'nid' => $vars['nid'], 'block' => $vars['block'], diff -urp /home/lntw/temp/authcache/authcache.helpers.inc authcache/authcache.helpers.inc --- /home/lntw/temp/authcache/authcache.helpers.inc 2009-09-12 12:41:00.000000000 -0400 +++ authcache/authcache.helpers.inc 2009-10-11 07:24:07.000000000 -0400 @@ -3,9 +3,9 @@ /** * @file - * Helper functions for the Authcache module (no Drupal hooks here). + * Helper functions for the Authcache module (no Drupal hooks here). */ - + /** * Should the current page be cached? @@ -28,12 +28,12 @@ function _authcache_is_cacheable() { ) { return FALSE; } - + // Check if caching is enabled for user's role if(!_authcache_is_account_cacheable($user)) { return FALSE; } - + $is_cached = FALSE; $alias = drupal_get_path_alias($_GET['q']); @@ -45,7 +45,7 @@ function _authcache_is_cacheable() { // Do caching page roles apply to current user? $keys = array_keys($user->roles); - + // Match up authenticated roles correctly in case "authenticated user" is unchecked if(in_array(DRUPAL_AUTHENTICATED_RID, $keys) && !in_array(DRUPAL_AUTHENTICATED_RID, $page_rules['roles'])) { unset($keys[array_search(DRUPAL_AUTHENTICATED_RID, $keys)]); @@ -68,7 +68,7 @@ function _authcache_is_cacheable() { } } } - + return $is_cached; } @@ -97,7 +97,7 @@ function _authcache_is_account_cacheable return FALSE; } } - + return TRUE; } @@ -110,12 +110,17 @@ function _authcache_is_account_cacheable * are not deconstructed and the function is executed later. */ function _authcache_shutdown_save_page() { - global $user, $base_root, $is_page_authcache; - + global $user, $base_root, $is_page_authcache, $is_ajax_authcache; + + // We don't want this code to run for ajax requests + if ($is_ajax_authcache) { + return; + } + // Check if non-html page that should be cached - + //$is_html = !($path == 'rss.xml' || preg_match('!/feed$!', $path)); - + $alias = drupal_get_path_alias($_GET['q']); $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\($|\|)/'), array('|', '.*', '\1'. preg_quote(variable_get('site_frontpage', 'node'), '/') .'\2'), preg_quote(variable_get('authcache_nonhtml', AUTHCACHE_NONHTML_DEFAULT), '/')) .')$/'; $is_cached_nonhtml = (preg_match($regexp, $alias)); @@ -130,7 +135,7 @@ function _authcache_shutdown_save_page() if (empty($_SERVER['REQUEST_METHOD'])) { return; } - + // Make sure "Location" redirect isn't used foreach(headers_list() as $header) { if(strpos($header, "Location:") !== FALSE) { @@ -141,7 +146,7 @@ function _authcache_shutdown_save_page() // Final check, in case variable was modified if(!$is_page_authcache) { global $authcache_debug_info; - + if(!$authcache_debug_info) { $authcache_debug_info = '$is_page_authcache = false'; } @@ -184,7 +189,7 @@ function _authcache_shutdown_save_page() 'cache_time' => time(), // Required by JS for HTML updates //'cache_key' => $key, ); - + // Database benchmarks if(variable_get('dev_query',0)) { global $queries; @@ -195,7 +200,7 @@ function _authcache_shutdown_save_page() } $time_query = round($time_query * 1000, 2); // Convert seconds to milliseconds $percent_query = round(($time_query / $authcache_info['page_render']) * 100); - + $authcache_info['page_queries'] = count($queries) . " queries @ {$time_query} ms ({$percent_query}%)"; } else { @@ -207,24 +212,24 @@ function _authcache_shutdown_save_page() $authcache_ajax = array( 'q' => $_GET['q'], ); - + // Invoke hook_authcache_info() operation to allow modules to modify info array _authcache_invoke_hook('authcache_info', $authcache_info); // Invoke hook_authcache() operation to allow modules to modify ajax array _authcache_invoke_hook('authcache_ajax', $authcache_ajax); - + // Get buffered HTML $buffer = ob_get_contents(); ob_end_clean(); - + // Don't cache empty/dead pages - if(!$buffer) { + if(!$buffer) { return; } - + $path = drupal_get_normal_path($_GET['q']); // normalize path - + if(substr($buffer, 0, 5) == '