diff --git a/ajax/authcache.php b/ajax/authcache.php
index 546bddf..2a83cf6 100644
--- a/ajax/authcache.php
+++ b/ajax/authcache.php
@@ -120,6 +120,25 @@ function _authcache_form_token_id($vars) {
/**
+ * Return debug information for the given page request.
+ */
+function _authcache_debuginfo($key) {
+ include_once dirname(__FILE__) . '../authcache.helpers.module';
+ $info = array();
+
+ if (_authcache_debug_access()) {
+ $cache = cache_get($key, 'cache_page');
+
+ if ($cache) {
+ $info = $cache->data['authcache_info'];
+ }
+ }
+
+ return $info;
+}
+
+
+/**
* Node history
* @see node.module
*/
@@ -151,6 +170,8 @@ function _authcache_node_history($nid) {
* @see statistics.module
*/
function _authcache_statistics($vars) {
+ // TODO: Disable statistics_exit hook in AJAX phase, otherwise each hit will
+ // be counted at least two times.
include_once './modules/statistics/statistics.module';
statistics_exit();
}
@@ -196,7 +217,10 @@ function _authcache_forum_topic_info($vars) {
include_once './modules/forum/forum.module';
include_once './modules/comment/comment.module';
- foreach ($vars as $nid => $timestamp) {
+ foreach ($vars as $rec) {
+ $nid = $rec['nid'];
+ $timestamp = $rec['timestamp'];
+
$history = _forum_user_last_visit($nid);
$new_topics = (int)comment_num_new($nid, $history);
if ($new_topics) {
@@ -228,20 +252,24 @@ function _authcache_contact($vars) {
function _authcache_poll($vars) {
// FULL bootstrap required in case custom theming is used
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
- $node = node_load($vars['nid']);
- $build = node_view($node);
- if (isset($build['poll_view_voting'])) {
- $output = render($build['poll_view_voting']);
- }
- elseif (isset($build['poll_view_results'])) {
- $output = render($build['poll_view_results']);
+ $nodes = node_load_multiple($vars);
+ $build = node_view_multiple($nodes);
+
+ $result = array();
+
+ foreach (element_children($build['nodes']) as $nid) {
+ if (isset($build['nodes'][$nid]['poll_view_voting'])) {
+ $output = render($build['nodes'][$nid]['poll_view_voting']);
+ }
+ elseif (isset($build['nodes'][$nid]['poll_view_results'])) {
+ $output = render($build['nodes'][$nid]['poll_view_results']);
+ }
+
+ $result[$nid] = $output;
}
- return array(
- 'nid' => $vars['nid'],
- 'html' => $output,
- );
+ return $result;
}
/**
@@ -268,7 +296,10 @@ function _authcache_blocks($blocks) {
global $user, $theme_key;
$return = array();
- foreach ($blocks as $block_id => $block_cid) {
+ foreach ($blocks as $block) {
+ $block_id = $block['id'];
+ $block_cid = $block['cid'];
+
// If block cache is per user, then specify current user id.
$block_cid = preg_replace('/:u.[0-9]+/', ":u.$user->uid", $block_cid);
diff --git a/authcache.admin.inc b/authcache.admin.inc
index d15555b..d4f02a5 100644
--- a/authcache.admin.inc
+++ b/authcache.admin.inc
@@ -318,7 +318,7 @@ function authcache_admin_pagecaching($form, $form_state, $ajax_form = array()) {
'#collapsible' => TRUE,
'#collapsed' => (variable_get('authcache_nonhtml', AUTHCACHE_NONHTML_DEFAULT) == AUTHCACHE_NONHTML_DEFAULT),
'#title' => t('Non-HTML Cached Pages'),
- '#description' => t('JavaScript is appended at the end of pages to support Ajax callbacks and page manipulation ("var authcacheFooter"). If you are experiencing issues for some content, you may disable this by entering pages below that you wish to cache but do not want JavaScript appended to.'),
+ '#description' => t('You may enable caching of non-HTML content other than %content_types by entering paths to those pages here.', array('%content_types' => implode(', ', _authcache_get_nonhtml_content_types()))),
'#prefix' => '
',
);
$form['nonhtmlfs']['nonhtml'] = array(
diff --git a/authcache.debug.js b/authcache.debug.js
index 555a2a0..07a51cf 100644
--- a/authcache.debug.js
+++ b/authcache.debug.js
@@ -7,70 +7,18 @@
* Display debug info, depending on phase
*/
Authcache.debug = function(ajaxData) {
+ var debugInfo;
if (!ajaxData) {
+ jQuery("body").prepend("");
+ jQuery("#authcachehide").click(function() {jQuery("#authcachedebug").toggle(); return false; })
- legend = (jQuery.cookie('drupal_user')) ? " (logged in: "+jQuery.cookie('drupal_user')+')' : '';
-
- //if (Authcache.isEnabled) {
- //simg: changed to authcache.info to help make more debug info available more often
- if (Authcache.info) {
- // Get seconds page was last cached, using Unix Epoch (GMT/UTC timestamp)
- utc = (new Date()).toUTCString(); // Client's time
- utcTimestamp = Date.parse(utc) / 1000; // Convert to seconds
-
- Authcache.info["(page_age)"] = Math.round(utcTimestamp - Authcache.info.cache_time) + " seconds";
- jQuery("#authcache-info").html("This page was cached " + Authcache.info["(page_age)"] + " ago.");
- if (utcTimestamp - Authcache.info.cache_time < -10) {
- jQuery("#authcache-info").append("Your computer's
time may be off.
");
- }
-
- var cache_render_time = jQuery.cookie("cache_render");
- jQuery.cookie("cache_render",null);
- var alert_color = '#F7F7F7';
- if (!jQuery.cookie('authcache_debug')) {
- Authcache.info.cache_render = 'This is your first site visit and the debug cookie has just been set.';
- }
- else if(cache_render_time && !isNaN(cache_render_time)) { // numeric?
- Authcache.info.cache_render = cache_render_time + " ms"
- Authcache.info.cache_render += " (" + Math.round((Authcache.info.page_render - cache_render_time) / cache_render_time * 100).toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2') + "% increase)"
- if (cache_render_time < 30) alert_color = 'green';
- else if (cache_render_time < 100) alert_color = 'orange';
- else if (cache_render_time > 100) alert_color = 'red';
- }
- else if(!cache_render_time) {
- Authcache.info.cache_render = 'cache miss';
- var alert_color = 'red';
- }
- else {
- Authcache.info.cache_render = "n/a (try a different browser?)";
- var alert_color = 'red';
- }
- //if (jQuery.cookie('authcache_compression')) {
- //Authcache.info.compression = jQuery.cookie('authcache_compression');
- //}
-
- //Authcache.info.page_render += " ms"; //simg: why was this here?
-
- debugInfo = Authcache.debugFieldset("Authcache.info"+legend, Authcache.info);
-
- if (Authcache.isEnabled) {
- debugInfo += 'Disable caching for this browser session';
- } else {
- if (jQuery.cookie("nocache")) {
- debugInfo += 'Enable caching for this browser session';
- }
- }
- }
- else {
- if (JSON.stringify(Authcache.info) == "{}") Authcache.info = "Authcache.info JSON is empty. @see _authcache_shutdown_save_page()";
- //Authcache.info = "Authcache.info JSON is empty. @see _authcache_shutdown_save_page()";
- debugInfo = Authcache.debugFieldset("Authcache prevented caching", {"NO_CACHE" : "Page not cached.", "INFO" : Authcache.info });
+ Authcache.debugCacheRenderTime = jQuery.cookie("cache_render");
+ jQuery.cookie("cache_render",null);
+
+ if (Drupal.settings.Authcache.info) {
+ Authcache.debugUpdate(Drupal.settings.Authcache.info);
}
-
-
- jQuery("body").prepend("");
- jQuery("#authcachehide").click(function() {jQuery("#authcachedebug").toggle(); return false; })
Authcache.debugTimer();
}
@@ -84,11 +32,75 @@ Authcache.debug = function(ajaxData) {
Authcache.debugFieldset("Response:", ajaxData.received) +
"";
+ if (typeof ajaxData.received.debuginfo != "undefined") {
+ Authcache.debugUpdate(ajaxData.received.debuginfo);
+ }
+
jQuery("#authcachedebug").append(debugInfo);
Authcache.debugTimer();
}
}
+Authcache.debugUpdate = function(info) {
+ var debugInfo;
+
+ // Get seconds page was last cached, using Unix Epoch (GMT/UTC timestamp)
+ utc = (new Date()).toUTCString(); // Client's time
+ utcTimestamp = Date.parse(utc) / 1000; // Convert to seconds
+
+ if (info.cache_time) {
+ info["(page_age)"] = Math.round(utcTimestamp - info.cache_time) + " seconds";
+ jQuery("#authcache-info").html("This page was cached " + info["(page_age)"] + " ago.");
+ if (utcTimestamp - info.cache_time < -10) {
+ jQuery("#authcache-info").append("Your computer's
time may be off.
");
+ }
+ }
+
+ var alert_color = '#F7F7F7';
+ if (!jQuery.cookie('authcache_debug')) {
+ info.cache_render = 'This is your first site visit and the debug cookie has just been set.';
+ }
+ else if(Authcache.debugCacheRenderTime && !isNaN(Authcache.debugCacheRenderTime)) { // numeric?
+ info.cache_render = Authcache.debugCacheRenderTime + " ms"
+ info.cache_render += " (" + Math.round((info.page_render - Authcache.debugCacheRenderTime) / Authcache.debugCacheRenderTime * 100).toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2') + "% increase)"
+ if (Authcache.debugCacheRenderTime < 30) alert_color = 'green';
+ else if (Authcache.debugCacheRenderTime < 100) alert_color = 'orange';
+ else if (Authcache.debugCacheRenderTime > 100) alert_color = 'red';
+ }
+ else if(!Authcache.debugCacheRenderTime) {
+ if (jQuery.cookie('nocache_reason')) {
+ info.cache_render = jQuery.cookie('nocache_reason').replace(/\+/g, " ");
+ }
+ else {
+ info.cache_render = "Cache miss";
+ }
+ var alert_color = 'red';
+ }
+ else {
+ info.cache_render = "n/a (try a different browser?)";
+ var alert_color = 'red';
+ }
+ //if (jQuery.cookie('authcache_compression')) {
+ //info.compression = jQuery.cookie('authcache_compression');
+ //}
+
+ //info.page_render += " ms"; //simg: why was this here?
+
+ legend = (jQuery.cookie('drupal_user')) ? " (logged in: "+jQuery.cookie('drupal_user')+')' : '';
+ debugInfo = Authcache.debugFieldset("info"+legend, info);
+
+ if (Authcache.isEnabled) {
+ debugInfo += 'Disable caching for this browser session';
+ } else {
+ if (jQuery.cookie("nocache")) {
+ debugInfo += 'Enable caching for this browser session';
+ }
+ }
+
+ jQuery("#authcache_status_indicator").css({"background": alert_color});
+ jQuery("#authcachedebuginfo").first().html(debugInfo);
+}
+
/**
* Disable caching by setting cookie
*/
diff --git a/authcache.helpers.inc b/authcache.helpers.inc
index c864f79..a0fdde6 100644
--- a/authcache.helpers.inc
+++ b/authcache.helpers.inc
@@ -246,16 +246,14 @@ function _authcache_shutdown_save_page() {
'page_render' => timer_read('page'), // Benchmark
'page_queries' => '-1', // Database benchmark, if enabled
'cache_render' => '-1', // Filled by cookie via JS on cache request
- 'cache_token' => drupal_get_token('authcache'), // Required by JS for HTML updates
'cache_class' => get_class(_cache_get_object('cache_page')),
- 'cache_time' => REQUEST_TIME, // Required by JS for HTML updates,
'is_cacheable' => $_authcache_is_cacheable,
'cache_key' => $key,
+ 'debug_users' => variable_get('authcache_debug_users', array()),
));
- // Hide sensitive info from anonymous users
- if (variable_get('authcache_debug_all', FALSE) || !_authcache_debug_access()) {
- unset($_authcache_info['cache_inc']);
+ if (!$_authcache_is_cacheable && _authcache_debug_access()) {
+ setcookie('nocache_reason', $_authcache_info['no_cache_reason'], 0, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1');
}
// Database benchmarks
@@ -275,50 +273,10 @@ function _authcache_shutdown_save_page() {
unset($_authcache_info['page_queries']);
}
- // JSON to send via Ajax
- // The "q" key is need during Ajax phase
- $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();
- if (substr($buffer, 0, 5) == 'uid && ($debug_users = variable_get('authcache_debug_users', array()))))
- && !$is_cached_nonhtml
- ) {
- $js = '';
-
-
-
- // Insert JSON before