diff --git a/ajax/authcache.php b/ajax/authcache.php index 428921a..e3d4d7f 100644 --- a/ajax/authcache.php +++ b/ajax/authcache.php @@ -118,6 +118,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 */ diff --git a/authcache.admin.inc b/authcache.admin.inc index d15555b..9762266 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 text/javascript, text/plain, application/xml, application/atom+xml by entering paths to those pages here.'), '#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("
Authcache Debug
"); + 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("
Authcache Debug
"); - 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 7e205d7..cb81ffc 100644 --- a/authcache.helpers.inc +++ b/authcache.helpers.inc @@ -248,17 +248,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_uid' => $user->uid, // 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_uid']); - 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 @@ -278,50 +275,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 , otherwise just append - if (strripos($buffer, '') !== FALSE) { - $buffer = str_replace('', $js . '', $buffer); - } - else { - $buffer .= $js; - } - - print $js; //since by this point the drupal page has already been sent to the browser - // Also see authcache_authcache_info() for user debug settings - drupal_add_js($js, array('type' => 'inline', 'scope' => 'header')); - } - // Don't cache empty/dead pages if (!$buffer) { return; @@ -329,25 +286,6 @@ function _authcache_shutdown_save_page() { $path = drupal_get_normal_path($_GET['q']); // normalize path - // Only place JSON info for HTML pages - if (!$is_cached_nonhtml && $user->uid) { - $authcache_footer['info'] = $_authcache_info; - $authcache_footer['ajax'] = $authcache_ajax; - $authcache_json = - "\n\n" . - "\n"; - - // Insert JSON before , otherwise just append - if (strripos($buffer, '') !== FALSE) { - $buffer = str_replace('', $authcache_json . '', $buffer); - } - else { - $buffer .= $authcache_json; - } - } - //header("Content-Length: " . strlen($output)); //D7 seems to have sent headers earlier, so doesn't seem possible to set headers at this point flush(); @@ -356,6 +294,8 @@ function _authcache_shutdown_save_page() { return; } + unset($_authcache_info['no_cache_reason']); + $cache = (object) array( 'cid' => $key, 'data' => array( @@ -363,6 +303,7 @@ function _authcache_shutdown_save_page() { 'body' => $buffer, 'title' => drupal_get_title(), 'headers' => array(), + 'authcache_info' => $_authcache_info, ), 'expire' => CACHE_TEMPORARY, 'created' => REQUEST_TIME, diff --git a/authcache.inc b/authcache.inc index 4182e6e..9bba853 100644 --- a/authcache.inc +++ b/authcache.inc @@ -51,6 +51,7 @@ function authcache_retrieve_cache_page(){ if (isset($_COOKIE['nocache_temp'])) { setcookie('nocache', '', REQUEST_TIME - 36000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); setcookie('nocache_temp', '', REQUEST_TIME - 36000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + setcookie('nocache_reason', '', REQUEST_TIME - 36000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); return FALSE; } @@ -85,6 +86,12 @@ function authcache_retrieve_cache_page(){ if (isset($_COOKIE['authcache_debug'])) { setcookie('cache_render', timer_read('page')); } + + // clear no-cache reason cookie if set + if (isset($_COOKIE['nocache_reason'])) { + setcookie('nocache_reason', '', REQUEST_TIME - 36000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + } + drupal_serve_page_from_cache($cache); return TRUE; diff --git a/authcache.js b/authcache.js index 6cdf8f7..b19c91b 100644 --- a/authcache.js +++ b/authcache.js @@ -3,8 +3,6 @@ var Authcache = { 'isEnabled' : true, // Make sure page is really cached 'isDebug' : false, // Debug mode 'json' : { }, // Holds all responses from ajaxRequest - 'ajax' : { }, // Will be extended with authcacheFooter data - 'info' : { }, // Will be extended with authcacheFooter data 'ajax_count' : 0, // Ajax request count 'timeStart' : new Date().getTime() // JS Benchmark }; @@ -19,12 +17,11 @@ Authcache.init = function() { // Should Ajax request be sent? Ignore if only 'q' key exists authcacheLength = 0; - for (i in Authcache.ajax) { + for (i in Drupal.settings.Authcache.ajax) { authcacheLength++; } - // Will also need to send request if Authcache was disabled in mid-render of HTML ("q" key won't exist since there is no authcacheFooter) - if (authcacheLength > 1 || (!Authcache.isEnabled && authcacheLength > 0)) { - Authcache.ajaxRequest(Authcache.ajax); + if (authcacheLength > 1) { + Authcache.ajaxRequest(Drupal.settings.Authcache.ajax); } else if(Authcache.isDebug) { jQuery("#authcachedebug").append("Ajax request not sent.
"); @@ -36,6 +33,8 @@ Authcache.init = function() { * Look over HTML DOM */ Authcache.init.preprocess = function() { + var ajax = Drupal.settings.Authcache.ajax; + var info = Drupal.settings.Authcache.info; // Display logged-in username jQuery(".authcache-user").html(jQuery.cookie("drupal_user")); @@ -50,8 +49,8 @@ Authcache.init.preprocess = function() { // Find forms that need tokens jQuery("form input[name='form_token_id']").each(function() { - if (Authcache.ajax["form_token_id[]"] == null) Authcache.ajax["form_token_id[]"] = new Array(); - Authcache.ajax["form_token_id[]"].push(this.form.form_token_id.value); + if (ajax["form_token_id[]"] == null) ajax["form_token_id[]"] = new Array(); + ajax["form_token_id[]"].push(this.form.form_token_id.value); // Bind submit button events to pass button name/value if needed on late submit. $form = jQuery(this.form); @@ -77,9 +76,9 @@ Authcache.init.preprocess = function() { if (Authcache.isEnabled) { // Dynamically theme local task tab items for logged-in users (nodes, etc) - if (jQuery.cookie("drupal_user") && Authcache.info.cache_uid != jQuery.cookie("drupal_uid") && jQuery("#authcache-tabs").length) { + if (jQuery.cookie("drupal_user") && info.cache_uid != jQuery.cookie("drupal_uid") && jQuery("#authcache-tabs").length) { ajaxJson = { - 'q' : Authcache.ajax.q, + 'q' : ajax.q, 'menu_local_tasks' : 1, 'max_age' : 86400 }; @@ -87,13 +86,13 @@ Authcache.init.preprocess = function() { } // Forums "new" markers - if (Authcache.info.cache_uid && Authcache.ajax.q.substring(0,5) == "forum") { + if (info.cache_uid && ajax.q.substring(0,5) == "forum") { // Check for new topics jQuery(".authcache-topic-new").each(function(i, elSpan) { - if (Authcache.ajax["forum_topic_new[]"] == null) Authcache.ajax["forum_topic_new[]"] = new Array(); + if (ajax["forum_topic_new[]"] == null) ajax["forum_topic_new[]"] = new Array(); id = elSpan.getAttribute("data-forum-id"); - Authcache.ajax["forum_topic_new[]"].push(id); + ajax["forum_topic_new[]"].push(id); }); // Get number of new comments or if topic node is unread @@ -101,12 +100,12 @@ Authcache.init.preprocess = function() { timestamp = elSpan.getAttribute("data-timestamp"); nid = elSpan.getAttribute("data-nid"); - Authcache.ajax["forum_topic_info["+nid+"]"] = new Array(timestamp); + ajax["forum_topic_info["+nid+"]"] = new Array(timestamp); }); } // Show "edit" comment links for user - if (Authcache.info.comment_usertime != null) { + if (info.comment_usertime != null) { jQuery(".authcache-comment-edit[data-comment-uid=" + jQuery.cookie("drupal_uid") + "]").each(function(i, elSpan) { cid = elSpan.getAttribute("data-comment-id"); @@ -114,7 +113,7 @@ Authcache.init.preprocess = function() { .find(".first") .removeClass("first") .parent() - .prepend('
  • ' + Authcache.info.t.edit + '
  • '); + .prepend('
  • ' + info.t.edit + '
  • '); }); } } @@ -133,7 +132,7 @@ Authcache.init.preprocess = function() { Authcache.ajaxRequest(ajax); } else { - Authcache.ajax["blocks[" + id + "]"] = cid; + ajax["blocks[" + id + "]"] = cid; } }); @@ -217,21 +216,6 @@ Authcache.getValue = function(needle, str) { return (matches == null) ? false : matches[1]; } - -// Check if page is really cached -jQuery(function() { - - // Page not cached for whatever reason (such as a late status message) - if (typeof authcacheFooter == "undefined") { - Authcache.isEnabled = false; - } - // Add "ajax" and "info" keys - else { - Authcache = jQuery.extend(true, Authcache, authcacheFooter); - } -}); - - // // Ajax callback functions // @@ -271,17 +255,19 @@ function _authcache_contact(vars) { * @see comment.module, node.module */ function _authcache_node_history(historyTimestamp) { - if (Authcache.info.comment_usertime != null) { + var info = Drupal.settings.Authcache.info; + + if (info.comment_usertime != null) { jQuery(".authcache-comment-new").each(function(i, elSpan) { timestamp = elSpan.getAttribute("data-timestamp"); if ( timestamp >= historyTimestamp || // Also give buffer for user who accesses first cached page request - (timestamp >= Authcache.info.comment_usertime && Authcache.info.cache_time >= historyTimestamp - 2 && Authcache.info.cache_uid == jQuery.cookie("drupal_uid")) + (timestamp >= info.comment_usertime && info.cache_time >= historyTimestamp - 2 && info.cache_uid == jQuery.cookie("drupal_uid")) ) { - jQuery(elSpan).hide().html(Authcache.info.t["new"]).fadeIn(); + jQuery(elSpan).hide().html(info.t["new"]).fadeIn(); } }) } @@ -342,15 +328,13 @@ function _authcache_menu_local_tasks(vars) { jQuery("#authcache-tabs").html(vars); } - // Prepare Authcache jQuery(function() { // Is debug mode enabled? if (typeof Authcache.debug != "undefined") { - if (!Authcache.info.debug_users || jQuery.inArray(jQuery.cookie('drupal_user'), Authcache.info.debug_users) != -1) { - Authcache.isDebug = true; - Authcache.debug(false); - jQuery.cookie('authcache_debug', 1); // Make sure cookie is set for benchmarks - } + Authcache.isDebug = true; + Authcache.debug(false); + jQuery.cookie('authcache_debug', 1); // Make sure cookie is set for benchmarks } + Authcache.init(); }) diff --git a/authcache.module b/authcache.module index 4028dcc..40ccded 100644 --- a/authcache.module +++ b/authcache.module @@ -125,27 +125,12 @@ function authcache_menu() { 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_info = array( + 'cache_time' => REQUEST_TIME, + ); $_authcache_is_cacheable = _authcache_is_cacheable(); if ($_authcache_is_cacheable) { @@ -154,27 +139,12 @@ function authcache_init() { // 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) { variable_set('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')); - } - ob_start(); } @@ -184,11 +154,74 @@ function authcache_init() { 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'); + setcookie('nocache_reason', "", REQUEST_TIME - 84000, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); } } /** + * Implements hook_page_build(). + * + * Attach authcache JavaScript if page is going to be cached. + */ +function authcache_page_build(&$page) { + global $user, $_authcache_is_cacheable, $_authcache_info; + + // 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'); + // Also see authcache_authcache_info() for user debug settings + } + + drupal_add_css(drupal_get_path('module', 'authcache') . '/authcache.css'); + + if ($_authcache_is_cacheable) { + // Force Ajax to use POST method instead of GET + if (variable_get('authcache_post', FALSE)) { + drupal_add_js(array('Authcache' => array('post' => 1)), 'setting'); + } + + // 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')); + } + } + + // Authcache info JSON + $_authcache_info = array_merge($_authcache_info, array( + 'cache_time' => REQUEST_TIME, + )); + + // Hide sensitive info from anonymous users + if (!variable_get('authcache_debug_all', FALSE) && _authcache_debug_access()) { + $_authcache_info['cache_uid'] = $user->uid; + } + + // Invoke hook_authcache_info() operation to allow modules to modify info array + _authcache_invoke_hook('authcache_info', $_authcache_info); + + // JSON to send via Ajax + // The "q" key is need during Ajax phase + $authcache_ajax = array( + 'q' => $_GET['q'], + ); + + // Invoke hook_authcache() operation to allow modules to modify ajax array + _authcache_invoke_hook('authcache_ajax', $authcache_ajax); + + // Add js setting + drupal_add_js(array('Authcache' => array( + 'ajax' => $authcache_ajax, + 'info' => $_authcache_info, + )), 'setting'); +} + + +/** * Implements hook_user(). */ @@ -231,6 +264,9 @@ function authcache_user_logout($account) { if (isset($_COOKIE['nocache_temp'])) { setcookie('nocache_temp', "", REQUEST_TIME - 86400, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); } + if (isset($_COOKIE['nocache_reason'])) { + setcookie('nocache_reason', "", REQUEST_TIME - 86400, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); + } if (isset($_COOKIE['authcache_debug'])) { setcookie('authcache_debug', "", REQUEST_TIME - 86400, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1'); } @@ -684,7 +720,7 @@ function theme_authcache_comment_view($comment, $node, $links = array(), $visibl * Modifies footer JSON for Ajax call. */ function authcache_authcache_ajax() { - global $user; + global $user, $base_root; $authcache_ajax = array(); @@ -711,6 +747,10 @@ function authcache_authcache_ajax() { } } + if (_authcache_debug_access()) { + $authcache_ajax['debuginfo'] = _authcache_key($user) . $base_root . request_uri(); + } + return $authcache_ajax; } @@ -739,10 +779,5 @@ function authcache_authcache_info() { } } - // Debug mode by user only - if (!variable_get('authcache_debug_all', FALSE) && _authcache_debug_access()) { - $authcache_info['debug_users'] = $debug_users; - } - return $authcache_info; }