summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--boost.admin.inc81
-rw-r--r--boost.module288
-rw-r--r--stats/boost_stats.php142
3 files changed, 359 insertions, 152 deletions
diff --git a/boost.admin.inc b/boost.admin.inc
index 6050113..b03e46c 100644
--- a/boost.admin.inc
+++ b/boost.admin.inc
@@ -30,7 +30,7 @@ function boost_admin_settings($form = array()) {
else {
$description_core .= '<p>'. t('<strong class="ok">Currently, all enabled modules are compatible with the aggressive caching policy.</strong> Please note, if you use aggressive caching and enable new modules, you will need to check this page again to ensure compatibility.') .'</p>';
}
- $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 64800, 86400, 2*86400, 3*86400, 4*86400, 5*86400, 6*86400, 604800, 2*604800, 3*604800, 4*604800, 8*604800, 16*604800), 'format_interval');
+ $period = drupal_map_assoc(array(0, 60, 180, 300, 600, 900, 1800, 2700, 3600, 10800, 21600, 32400, 43200, 64800, 86400, 2*86400, 3*86400, 4*86400, 5*86400, 6*86400, 604800, 2*604800, 3*604800, 4*604800, 8*604800, 16*604800, 52*604800), 'format_interval');
$period[0] = '<' . t('none') . '>';
// Take over the relevant existing settings
@@ -57,12 +57,12 @@ function boost_admin_settings($form = array()) {
);
$form['boost']['boost_clear'] = array(
'#type' => 'submit',
- '#value' => t('Clear ALL Boost cached data: !count pages', array('!count' => boost_count_db(TRUE))),
+ '#value' => t('Clear ALL Boost cached data: !count pages', array('!count' => boost_count_db(1))),
'#submit' => array('boost_clear_cache_submit'),
);
$form['boost']['boost_clear_expired'] = array(
'#type' => 'submit',
- '#value' => t('Clear Boost expired data: !count pages', array('!count' => boost_count_db(FALSE))),
+ '#value' => t('Clear Boost expired data: !count pages', array('!count' => boost_count_db(0))),
'#submit' => array('boost_clear_expired_cache_submit'),
);
@@ -202,12 +202,12 @@ function boost_admin_settings($form = array()) {
'#type' => 'radios',
'#title' => t('Ignore cache flushing'),
'#default_value' => BOOST_IGNORE_FLUSH,
- '#options' => array(0 => t('Disabled'), 1 => t('Only Ignore Complete Fushes'), 2 => t('Ignore All Delete Commands (Not Recommended)')),
- '#description' => t('Enable to put your site into a static state. Recommend turning on CSS & JS caching.'),
+ '#options' => array(0 => t('Disabled'), 1 => t('Only Ignore Complete Flushes'), 2 => t('Ignore Fluses & Expiration'), 3 => t('Ignore All Delete Commands (Not Recommended)')),
+ '#description' => t('Enable to put your site into a static state. Recommend turning on CSS & JS caching if enabled.'),
);
$form['boost']['advanced']['boost_reset'] = array(
'#type' => 'submit',
- '#value' => t('Reset boost database'),
+ '#value' => t('Reset boost database: !records records', array('!records' => boost_count_db(2))),
'#submit' => array('boost_reset_database_submit'),
);
@@ -239,6 +239,7 @@ function boost_admin_settings($form = array()) {
'#title' => t('Generated Rules'),
'#default_value' => $htaccess,
'#rows' => count(explode("\n", $htaccess))+1,
+ '#wysiwyg' => FALSE,
'#description' => t("Copy this into your .htaccess file below <pre><tt> # RewriteBase / </tt></pre> and above <pre><tt> # Rewrite URLs of the form 'x' to the form 'index.php?q=x'</tt></pre>"),
);
@@ -295,39 +296,50 @@ function boost_admin_settings_submit($form, &$form_state) {
if (empty($boost_enabled) && !empty($boost_previously)) { // the cache was previously enabled
variable_set('boost_ignore_flush', 0);
if (boost_cache_clear_all()) {
- drupal_set_message(t('Static page cache cleared.'));
+ drupal_set_message(t('Boost: Static page cache cleared.'));
}
}
- else if ((variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE) && BOOST_IGNORE_FLUSH == 0) {
- boost_cache_clear_all();
+ else if ($boost_ignore_flush == 0 && (variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE)) {
+ if (boost_cache_clear_all()) {
+ drupal_set_message(t('Boost: Static page cache cleared.'), 'warning');
+ }
}
}
function boost_admin_clear_cache_submit($form, &$form_state) {
- boost_cache_clear_all();
drupal_flush_all_caches();
- drupal_set_message(t('Static page cache and all other caches cleared.'));
+ if (boost_cache_clear_all()) {
+ drupal_set_message(t('Static page cache (boost) and all other caches cleared.'));
+ }
+ else {
+ drupal_set_message(t('Boost: Static page cache NOT cleared. To clear Boosts cache set "Ignore cache flushing:" to \'Disabled\' in the advanced settings.'), 'warning');
+ drupal_set_message(t('All other caches cleared.'));
+ }
}
function boost_admin_site_offline_submit($form, &$form_state) {
if (!empty($form_state['values']['site_offline'])) {
if (BOOST_CLEAR_CACHE_OFFLINE) {
if (boost_cache_clear_all()) {
- drupal_set_message(t('Static page cache cleared.'));
+ drupal_set_message(t('Boost: Static page cache cleared.'), 'warning');
}
}
}
}
function boost_admin_modules_submit($form, &$form_state) {
- if (variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE && BOOST_IGNORE_FLUSH == 0) {
- boost_cache_clear_all();
+ if ((variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE)) {
+ if (boost_cache_clear_all()) {
+ drupal_set_message(t('Boost: Static page cache cleared.'), 'warning');
+ }
}
}
function boost_admin_themes_submit($form, &$form_state) {
- if (variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE && BOOST_IGNORE_FLUSH == 0) {
- boost_cache_clear_all();
+ if ((variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE)) {
+ if (boost_cache_clear_all()) {
+ drupal_set_message(t('Boost: Static page cache cleared.'), 'warning');
+ }
}
}
@@ -420,13 +432,16 @@ return $string;
/**
* Counts the number of pages in the static cache.
*/
-function boost_count_db($all = FALSE) {
- if ($all) {
+function boost_count_db($all = 0) {
+ if ($all == 0) {
return db_result(db_query("SELECT COUNT(*) FROM {boost_cache} WHERE expire <> 0"));
}
- else {
+ elseif ($all == 1) {
return db_result(db_query('SELECT COUNT(*) FROM {boost_cache} WHERE expire BETWEEN 1 AND %d', BOOST_TIME));
}
+ elseif ($all == 2) {
+ return db_result(db_query("SELECT COUNT(*) FROM {boost_cache}"));
+ }
}
/**
@@ -440,8 +455,12 @@ function boost_count_core_db($all = FALSE) {
* Flushes boost page cache
*/
function boost_clear_cache_submit () {
- boost_cache_clear_all();
- drupal_set_message(t('Boost page cache cleared.'));
+ if (boost_cache_clear_all()) {
+ drupal_set_message(t('Boost: Static page cache cleared.'));
+ }
+ else {
+ drupal_set_message(t('Boost: Set "Ignore cache flushing:" to \'Disabled\' in the advanced settings & try again.'), 'warning');
+ }
}
@@ -449,8 +468,12 @@ function boost_clear_cache_submit () {
* Flushes all expired pages from database
*/
function boost_clear_expired_cache_submit () {
- boost_cache_db_expire();
- drupal_set_message(t('Expired stale files from static page cache.'));
+ if (boost_cache_db_expire()) {
+ drupal_set_message(t('Boost: Expired stale files from static page cache.'));
+ }
+ else {
+ drupal_set_message(t('Boost: Set "Ignore cache flushing:" to \'Disabled\' OR \'Only Ignore Complete Flushes\' in the advanced settings & try again.'), 'warning');
+ }
}
/**
@@ -465,7 +488,11 @@ function boost_clear_core_page_cache_submit () {
* Resets boost database & cache
*/
function boost_reset_database_submit () {
- db_query("DELETE FROM {boost_cache}");
- boost_cache_clear_all();
- drupal_set_message(t('Boost page cache & database cleared.'));
-} \ No newline at end of file
+ if (boost_cache_clear_all()) {
+ db_query("DELETE FROM {boost_cache}");
+ drupal_set_message(t('Boost: Static page cache & database cleared.'));
+ }
+ else {
+ drupal_set_message(t('Boost: Set "Ignore cache flushing:" to \'Disabled\' in the advanced settings & try again.'), 'warning');
+ }
+}
diff --git a/boost.module b/boost.module
index a12c53c..db7c4d9 100644
--- a/boost.module
+++ b/boost.module
@@ -53,6 +53,14 @@ define('BOOST_BANNER', variable_get('boost_banner', "<!-- Page cac
define('BOOST_USER_ID', @$GLOBALS['user']->uid);
//////////////////////////////////////////////////////////////////////////////
+// Global variables
+
+//$GLOBALS['_boost_path'] = '';
+//$GLOBALS['_boost_query'] = '';
+//$GLOBALS['_boost_message_count'] = '';
+//$GLOBALS['_boost_cache_this'] = '';
+
+//////////////////////////////////////////////////////////////////////////////
// Core API hooks
/**
@@ -96,6 +104,7 @@ function boost_init() {
|| isset($_GET['nocache'])
|| !boost_is_cacheable($GLOBALS['_boost_path'])
) {
+ $GLOBALS['_boost_cache_this'] = FALSE;
return;
}
@@ -109,68 +118,12 @@ function boost_init() {
if (BOOST_ENABLED != CACHE_AGGRESSIVE) {
$GLOBALS['conf']['cache'] = CACHE_DISABLED;
}
+ $GLOBALS['_boost_cache_this'] = TRUE;
ob_start('_boost_ob_handler');
}
}
/**
- * Implementation of hook_footer().
- *
- * Place boost stat counter image into pages footer.
- *
- * NOTE HTML code could be added to the $buffer directly, right before </body>,
- * inside _boost_ob_handler() function. Would prevent 2x counts on first view.
- */
-function boost_footer() {
- Global $base_path, $user;
- $filename = 'boost_stats.php';
-
- if ( strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE
- || variable_get('site_offline', 0)
- || $_SERVER['REQUEST_METHOD'] != 'GET'
- || $_SERVER['SERVER_SOFTWARE'] === 'PHP CLI'
- || !BOOST_ENABLED
- || isset($_GET['nocache'])
- || !boost_is_cacheable($GLOBALS['_boost_path'])
- || !empty($user->uid)
- || !file_exists($filename)
- ) {
- return;
- }
-
- if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0)) {
- $nid = arg(1);
- }
- if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
- $title = drupal_urlencode(strip_tags(drupal_get_title()));
- $q = $_GET['q'];
- }
- $img_start = '<div style="display:inline;"><img src="' . $base_path . $filename;
- $img_end = '" alt="" /></div>';
- $ns_start = $img_start;
- $ns_end = $img_end;
- $ns = '';
- $js_start = '<script type="text/javascript">';
- $js_end = '</script>';
- $js = '';
-
- if (isset($nid) & !isset($title)) {
- return $ns_start . '?nid=' . $nid . $ns_end;
- }
- elseif (isset($nid) & isset($title)) {
- $ns = '<noscript>' . $ns_start . '?nid=' . $nid . '&amp;q=' . $q . '&amp;title=' . $title . $ns_end . '</noscript>';
- $js = $js_start . 'boost_nid="nid=' . $nid . '"; boost_q="q=' . $q . '"; boost_title="title=' . $title . '"; boost_referrer="referer=" + document.referrer;';
- $js .= " document.write('" . $img_start . "?' + boost_nid + '&amp;' + boost_q + '&amp;' + boost_title + '&amp;' + boost_referrer + '" . $img_end . "');" . $js_end;
- }
- elseif (!isset($nid) & isset($title)) {
- $ns = '<noscript>' . $ns_start . '?q=' . $q . '&amp;title=' . $title . $ns_end . '</noscript>';
- $js = $js_start . 'boost_q="q=' . $q . '"; boost_title="title=' . $title . '"; boost_referrer="referer=" + document.referrer;';
- $js .= " document.write('" . $img_start . "?' + boost_q + '&amp;' + boost_title + '&amp;' + boost_referrer + '" . $img_end . "');" . $js_end;
- }
- return $js . $ns;
-}
-
-/**
* Implementation of hook_exit(). Performs cleanup tasks.
*
* For POST requests by anonymous visitors, this adds a dummy query string
@@ -246,6 +199,13 @@ function boost_form_alter(&$form, $form_state, $form_id) {
case 'system_themes_form':
module_load_include('inc', 'boost', 'boost.admin');
$form['#submit'][] = 'boost_admin_themes_submit';
+
+ // Added below due to this bug: http://drupal.org/node/276615
+ if (variable_get('preprocess_css', FALSE)==TRUE) {
+ if (boost_cache_clear_all()) {
+ drupal_set_message(t('Boost: Static page cache cleared. See <a href="http://drupal.org/node/276615">http://drupal.org/node/276615</a> for reason why (core bug).'), 'warning');
+ }
+ }
break;
}
}
@@ -254,18 +214,27 @@ function boost_form_alter(&$form, $form_state, $form_id) {
* Implementation of hook_cron(). Performs periodic actions.
*/
function boost_cron() {
- if (!BOOST_ENABLED) return;
+ if (!BOOST_ENABLED) {
+ return;
+ }
+ // Expire old content
if (variable_get('boost_expire_cron', TRUE) && boost_cache_db_expire()) {
watchdog('boost', 'Expired stale files from static page cache.', array(), WATCHDOG_NOTICE);
}
+
+ // Update Stats
+ if (module_exists('statistics') && variable_get('boost_block_show_stats', FALSE)) {
+ $block = module_invoke('statistics', 'block', 'view', 0);
+ variable_set('boost_statistics_html', $block['content']);
+ }
}
/*
* Implementation of hook_flush_caches(). Deletes all static files.
*/
function boost_flush_caches() {
- if (variable_get('cron_semaphore', FALSE)==FALSE && (variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE) && BOOST_IGNORE_FLUSH == 0) {
+ if (variable_get('cron_semaphore', FALSE)==FALSE && (variable_get('preprocess_css', FALSE)==TRUE || variable_get('preprocess_js', FALSE)==TRUE)) {
boost_cache_clear_all();
}
return;
@@ -367,12 +336,31 @@ function boost_block($op = 'list', $delta = 0, $edit = array()) {
case 'list':
return array(
'status' => array(
- 'info' => t('Boost page cache status'),
+ 'info' => t('Boost: Pages cache status'),
+ 'region' => 'right',
+ 'weight' => 10,
+ 'cache' => BLOCK_NO_CACHE,
+ ),
+ 'stats' => array(
+ 'info' => t('Boost: AJAX core statistics'),
'region' => 'right',
'weight' => 10,
'cache' => BLOCK_NO_CACHE,
),
);
+ case 'configure':
+ if ($delta == 'stats') {
+ $form['items'] = array(
+ '#type' => 'checkbox',
+ '#title' => t('Display Statistics'),
+ '#default_value' => variable_get('boost_block_show_stats', FALSE),
+ );
+ return $form;
+ }
+ case 'save':
+ if ($delta == 'stats') {
+ variable_set('boost_block_show_stats', $edit['items']);
+ }
case 'view':
$block = array();
switch ($delta) {
@@ -400,7 +388,7 @@ function boost_block($op = 'list', $delta = 0, $edit = array()) {
if (BOOST_HALT_ON_ERRORS && ($error || $drupal_msg != 0)) {
$output = t('There are <strong>php errors</strong> or <strong>drupal messages</strong> on this page, preventing boost from caching.');
if ($error) {
- $output .= t(' ERROR: <pre>%error</pre> !link <br /> !performance', array('%error' => print_r($error, TRUE), '!link' => l(t('Lookup Error Type'), 'http://php.net/errorfunc.constants'), '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')));
+ $output .= t(' ERROR: <pre>%error</pre> !link <br /> !performance', array('%error' => boost_print_r($error, TRUE), '!link' => l(t('Lookup Error Type'), 'http://php.net/errorfunc.constants'), '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')));
}
if ($drupal_msg != 0) {
$output .= t(' MESSAGES: %msg <br /> !performance', array('%msg' => $drupal_msg, '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')));
@@ -411,6 +399,37 @@ function boost_block($op = 'list', $delta = 0, $edit = array()) {
$block['content'] = theme('boost_cache_status', isset($ttl) ? $ttl : -1, $output);
}
break;
+ case 'stats':
+ $filename = 'boost_stats.php';
+ $block = module_invoke('statistics', 'block', 'view', 0);
+ variable_set('boost_statistics_html', $block['content']);
+
+ if (!( strpos($_SERVER['SCRIPT_FILENAME'], 'index.php') === FALSE
+ || variable_get('site_offline', 0)
+ || $_SERVER['REQUEST_METHOD'] != 'GET'
+ || $_SERVER['SERVER_SOFTWARE'] === 'PHP CLI'
+ || !BOOST_ENABLED
+ || isset($_GET['nocache'])
+ || !boost_is_cacheable($GLOBALS['_boost_path'])
+ || !empty($user->uid)
+ || !file_exists($filename)
+ || !module_exists('statistics')
+ )) {
+ if (variable_get('boost_block_show_stats', FALSE)) {
+ $block = array();
+ $block['subject'] = 'Popular content';
+ $block['content'] = '<div id="boost-stats"></div>' . boost_stats_generate($filename);
+ }
+ else {
+ $block = array();
+ $block['content'] = '<div id="boost-stats" style="display:none;"></div>' . boost_stats_generate($filename);
+ }
+ }
+ elseif (!variable_get('boost_block_show_stats', FALSE)) {
+ $block = array();
+ }
+
+
}
return $block;
}
@@ -429,12 +448,60 @@ function boost_block_form() {
return ($form);
}
-
function boost_block_form_submit(&$form_state, $form) {
boost_cache_expire_derivative($form['values']['path'], TRUE);
}
/**
+ * Generate js/html for boost stat counter.
+ *
+ * NOTE HTML code could be added to the $buffer directly. Would prevent 2x
+ * counts on first view. Would be hard to do though.
+ *
+ * @param $filename
+ * Name of boost's statistics php file.
+ */
+function boost_stats_generate($filename) {
+ Global $base_path;
+
+ // is node & node count enabled.
+ if (arg(0) == 'node' && is_numeric(arg(1)) && arg(2) == '' && variable_get('statistics_count_content_views', 0)) {
+ $nid = 'nid=' . arg(1);;
+ }
+ else {
+ $nid = 'nid=NULL';
+ }
+
+ // access log enabled.
+ if ((variable_get('statistics_enable_access_log', 0)) && (module_invoke('throttle', 'status') == 0)) {
+ $title = 'title=' . drupal_urlencode(strip_tags(drupal_get_title()));
+ $q = 'q=' . $_GET['q'];
+ }
+ else {
+ $title = 'title=NULL';
+ $q = 'q=NULL';
+ }
+
+ $page_js = array(
+ 'boost' => array(
+ 'nid' => $nid,
+ 'q' => $q,
+ 'title' => $title,
+ ),
+ );
+ $site_js = '$("#boost-stats").load(Drupal.settings.basePath + "boost_stats.php?js=2" + "&" + Drupal.settings.boost.nid + "&" + Drupal.settings.boost.q + "&" + Drupal.settings.boost.title + "&referer=" + document.referrer);';
+
+ // page specific variables
+ drupal_add_js($page_js, 'setting', 'header');
+ // site-wide code
+ drupal_add_js($site_js, 'inline', 'footer');
+ // no script code
+ $page_ns = '<noscript><div style="display:inline;"><img src="' . $base_path . $filename . '?js=0' . '&amp;'. $nid . '&amp;'. $title . '&amp;'. $q . '" alt="" /></div></noscript>';
+
+ return $page_ns;
+}
+
+/**
* Implementation of hook_theme().
*/
function boost_theme() {
@@ -467,13 +534,13 @@ function _boost_ob_handler($buffer) {
if (function_exists('error_get_last')) {
if (BOOST_HALT_ON_ERRORS && $error = error_get_last()) {
switch ($error['type']) {
- //case E_NOTICE: //Ignore run-time notices
- //case E_USER_NOTICE: //Ignore user-generated notice message
+ case E_NOTICE: //Ignore run-time notices
+ case E_USER_NOTICE: //Ignore user-generated notice message
//case E_DEPRECATED: //Ignore run-time notices
//case E_USER_DEPRECATED: //Ignore user-generated notice message
- // break;
+ break;
default: //Do not cache page on all other errors
- watchdog('boost', 'There are <strong>php errors</strong> on this page, preventing boost from caching. ERROR: <pre>%error</pre> !link <br /> !performance', array('%error' => print_r($error, TRUE), '!link' => l(t('Lookup Error Type'), 'http://php.net/errorfunc.constants'), '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')), WATCHDOG_WARNING);
+ watchdog('boost', 'There are <strong>php errors</strong> on this page, preventing boost from caching. ERROR: <pre>%error</pre> !link <br /> !performance', array('%error' => boost_print_r($error, TRUE), '!link' => l(t('Lookup Error Type'), 'http://php.net/errorfunc.constants'), '!performance' => l(t('Turn Off Error Checking'), 'admin/settings/performance')), WATCHDOG_WARNING);
return $buffer;
}
}
@@ -489,7 +556,7 @@ function _boost_ob_handler($buffer) {
// exceedingly conservative here and only cache 'text/html' pages that
// were output with a 200 OK status. Anything more is simply asking for
// loads of trouble.
- if (_boost_get_http_status() == 200 && strlen($buffer) > 0) {
+ if ($GLOBALS['_boost_cache_this'] && _boost_get_http_status() == 200 && strlen($buffer) > 0) {
switch (_boost_get_content_type()) {
case 'text/html':
boost_cache_set($GLOBALS['_boost_path'], $buffer);
@@ -615,9 +682,13 @@ function boost_is_cached($path) {
* Deletes all files currently in the cache.
*/
function boost_cache_clear_all() {
- boost_cache_clear_all_db();
- boost_cache_delete(TRUE);
- watchdog('boost', 'Flushed ALL files from static page cache.', array(), WATCHDOG_NOTICE);
+ if (BOOST_IGNORE_FLUSH == 0) {
+ boost_cache_clear_all_db();
+ boost_cache_delete(TRUE);
+ watchdog('boost', 'Flushed ALL files from static page cache.', array(), WATCHDOG_NOTICE);
+ return TRUE;
+ }
+ return FALSE;
}
/**
@@ -738,7 +809,7 @@ function boost_cache_expire($path, $wildcard = FALSE) {
* Name of cached file; primary key in database
*/
function boost_cache_kill($filename) {
- if (BOOST_IGNORE_FLUSH !=2 && strstr($filename, BOOST_FILE_PATH)) {
+ if (BOOST_IGNORE_FLUSH < 3 && strstr($filename, BOOST_FILE_PATH)) {
db_query("UPDATE {boost_cache} SET expire = 0 WHERE filename = '%s'", $filename);
if (file_exists($filename)) {
@unlink($filename);
@@ -752,16 +823,21 @@ function boost_cache_kill($filename) {
/**
* Flushes all expired pages from database
+ *
+ * TODO del empty dirs if enabled
*/
function boost_cache_db_expire() {
- $result = db_query('SELECT filename FROM {boost_cache} WHERE expire BETWEEN 1 AND %d', BOOST_TIME);
- while ($boost = db_fetch_array($result)) {
- boost_cache_kill($boost['filename']);
- }
- if (BOOST_FLUSH_DIR) {
- //TO-DO: del empty dirs.
+ if (BOOST_IGNORE_FLUSH < 2) {
+ $result = db_query('SELECT filename FROM {boost_cache} WHERE expire BETWEEN 1 AND %d', BOOST_TIME);
+ while ($boost = db_fetch_array($result)) {
+ boost_cache_kill($boost['filename']);
+ }
+ if (BOOST_FLUSH_DIR) {
+ // TO-DO: del empty dirs.
+ }
+ return TRUE;
}
- return TRUE;
+ return FALSE;
}
/**
@@ -1038,6 +1114,7 @@ function boost_db_is_expired($filename) {
/**
* Sets a special cookie preventing authenticated users getting served pages
* from the static page cache.
+ *
* @param $user
* User Object
* @param $expires
@@ -1052,6 +1129,7 @@ function boost_set_cookie($user, $expires = NULL) {
else {
setcookie(BOOST_COOKIE, FALSE, $expires, ini_get('session.cookie_path'), ini_get('session.cookie_domain'), ini_get('session.cookie_secure') == '1');
}
+ $GLOBALS['_boost_cache_this'] = FALSE;
}
/**
@@ -1114,6 +1192,60 @@ function boost_cache_css_js_files($buffer) {
}
}
+/**
+ * An alternative to print_r that unlike the original does not use output buffering with
+ * the return parameter set to true. Thus, Fatal errors that would be the result of print_r
+ * in return-mode within ob handlers can be avoided.
+ * http://www.php.net/manual/en/function.print-r.php#75872
+ *
+ * Comes with an extra parameter to be able to generate html code. If you need a
+ * human readable DHTML-based print_r alternative, see http://krumo.sourceforge.net/
+ *
+ * Support for printing of objects as well as the $return parameter functionality
+ * added by Fredrik Wollsén (fredrik dot motin at gmail), to make it work as a drop-in
+ * replacement for print_r (Except for that this function does not output
+ * paranthesises around element groups... ;) )
+ *
+ * Based on return_array() By Matthew Ruivo (mruivo at gmail)
+ * (http://www.php.net/manual/en/function.print-r.php#73436)
+ */
+function boost_print_r($var, $return = false, $html = false, $level = 0) {
+ $spaces = "";
+ $space = $html ? "&nbsp;" : " ";
+ $newline = $html ? "<br />" : "\n";
+ for ($i = 1; $i <= 6; $i++) {
+ $spaces .= $space;
+ }
+ $tabs = $spaces;
+ for ($i = 1; $i <= $level; $i++) {
+ $tabs .= $spaces;
+ }
+ if (is_array($var)) {
+ $title = "Array";
+ }
+ elseif (is_object($var)) {
+ $title = get_class($var)." Object";
+ }
+ $output = $title . $newline . $newline;
+
+ // Recursive boost_print_r
+ foreach($var as $key => $value) {
+ if (is_array($value) || is_object($value)) {
+ $level++;
+ $value = boost_print_r($value, true, $html, $level);
+ $level--;
+ }
+ $output .= $tabs . "[" . $key . "] => " . $value . $newline;
+ }
+
+ if ($return) {
+ return $output;
+ }
+ else {
+ echo $output;
+ }
+}
+
//////////////////////////////////////////////////////////////////////////////
// Boost API internals
/**
diff --git a/stats/boost_stats.php b/stats/boost_stats.php
index 1e0bf03..659da86 100644
--- a/stats/boost_stats.php
+++ b/stats/boost_stats.php
@@ -1,26 +1,10 @@
<?php
// $Id$
-// Script should take under 1mb of memory to work.
-// Prime php for background operations
-ob_end_clean();
-header("Connection: close");
-ignore_user_abort();
-
-// Output of 1 pixel transparent gif
-ob_start();
-header("Content-type: image/gif");
-header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
-header("Cache-Control: no-cache");
-header("Cache-Control: must-revalidate");
-header("Content-Length: 43");
-header("Connection: close");
-printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
-ob_end_flush();
-flush();
-
-// Image returned and connection closed.
-// Do background processing. Time taken below should not effect page load times.
+if (isset($_GET['js']) && $_GET['js']==0) {
+ // stats not called via JS, send image out & close connection.
+ boost_stats_async_image();
+}
// Exit script if nothing was passed to it.
if ( !isset($_GET['nid'])
@@ -31,38 +15,63 @@ if ( !isset($_GET['nid'])
exit;
}
-// Set variables passed via GET.
-$nid = isset($_GET['nid']) ? $_GET['nid'] : NULL;
-$title = isset($_GET['title']) ? urldecode($_GET['title']) : NULL;
-$q = isset($_GET['q']) ? $_GET['q'] : NULL;
-$referer = isset($_GET['referer']) ? $_GET['referer'] : NULL;
-
-// Connect to DB.
-include_once './includes/bootstrap.inc';
-drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
-
-// Get stat settings.
-$count_views = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_count_content_views', 0, 1));
-$count_views = unserialize($count_views['value']);
-$access_log = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_enable_access_log', 0, 1));
-$access_log = unserialize($access_log['value']);
+// connect to db & set variables.
+boost_stats_init();
// Set node counter.
-if ($count_views) {
- // We are counting content views.
- if (isset($nid) && is_numeric($nid)) {
- // A node has been viewed, so update the node's counters.
- db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $nid);
- // If we affected 0 rows, this is the first time viewing the node.
- if (!db_affected_rows()) {
- // We must create a new row to store counters for the new node.
- db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $nid, time());
- }
- }
+if ($count_views && isset($nid) && is_numeric($nid)) {
+ boost_stats_update_node_counter();
}
// Set access log.
if ($access_log && isset($title) && isset($q)) {
+ boost_stats_add_access_log();
+}
+
+// Send stats block html.
+if ($stats) {
+ boost_stats_output_stats_block();
+}
+
+// end of script, exit.
+exit;
+
+Function boost_stats_async_image() {
+ // Script should take under 1mb of memory to work.
+ // Prime php for background operations
+ ob_end_clean();
+ header("Connection: close");
+ ignore_user_abort();
+
+ // Output of 1 pixel transparent gif
+ ob_start();
+ header("Content-type: image/gif");
+ header("Expires: Wed, 11 Nov 1998 11:11:11 GMT");
+ header("Cache-Control: no-cache");
+ header("Cache-Control: must-revalidate");
+ header("Content-Length: 43");
+ header("Connection: close");
+ printf("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",71,73,70,56,57,97,1,0,1,0,128,255,0,192,192,192,0,0,0,33,249,4,1,0,0,0,0,44,0,0,0,0,1,0,1,0,0,2,2,68,1,0,59);
+ ob_end_flush();
+ flush();
+
+ // Image returned and connection closed.
+ // Do background processing. Time taken below should not effect page load times.
+}
+
+Function boost_stats_init() {
+ Global $nid, $title, $q, $referer, $session_id, $uid, $stats, $count_views, $access_log, $stats_block;
+
+ // Connect to DB.
+ include_once './includes/bootstrap.inc';
+ drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
+
+ // Set variables passed via GET.
+ $nid = isset($_GET['nid']) ? $_GET['nid'] : NULL;
+ $title = isset($_GET['title']) ? urldecode($_GET['title']) : NULL;
+ $q = isset($_GET['q']) ? $_GET['q'] : NULL;
+ $referer = isset($_GET['referer']) ? $_GET['referer'] : NULL;
+ $stats = (isset($_GET['js']) && $_GET['js'] == 2) ? TRUE : NULL;
$session_id = session_id();
if (empty($session_id)) {
$session_id = $_COOKIE[session_name()];
@@ -72,6 +81,45 @@ if ($access_log && isset($title) && isset($q)) {
}
}
$uid = 0;
+
+ // Node Counter
+ if (isset($nid)) {
+ $count_views = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_count_content_views', 0, 1));
+ $count_views = unserialize($count_views['value']);
+ }
+
+ // Access Log
+ if (isset($title) && isset($q)) {
+ $access_log = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'statistics_enable_access_log', 0, 1));
+ $access_log = unserialize($access_log['value']);
+ }
+
+ // stats block
+ if (isset($stats)) {
+ $stats_block = db_fetch_array(db_query_range("SELECT value FROM {variable} WHERE name = '%s'", 'boost_statistics_html', 0, 1));
+ $stats_block = unserialize($stats_block['value']);
+ }
+}
+
+Function boost_stats_update_node_counter() {
+ Global $nid;
+
+ // A node has been viewed, so update the node's counters.
+ db_query('UPDATE {node_counter} SET daycount = daycount + 1, totalcount = totalcount + 1, timestamp = %d WHERE nid = %d', time(), $nid);
+ // If we affected 0 rows, this is the first time viewing the node.
+ if (!db_affected_rows()) {
+ // We must create a new row to store counters for the new node.
+ db_query('INSERT INTO {node_counter} (nid, daycount, totalcount, timestamp) VALUES (%d, 1, 1, %d)', $nid, time());
+ }
+}
+
+Function boost_stats_add_access_log() {
+ Global $title, $q, $referer, $session_id, $uid;
+
db_query("INSERT INTO {accesslog} (title, path, url, hostname, uid, sid, timer, timestamp) values('%s', '%s', '%s', '%s', %d, '%s', %d, %d)", $title, $q, $referer, ip_address(), $uid, $session_id, timer_read('page'), time());
}
-exit; \ No newline at end of file
+
+Function boost_stats_output_stats_block() {
+ Global $stats_block;
+ echo $stats_block;
+}