? boost-503628.patch
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.72
diff -u -p -r1.3.2.2.2.5.2.72 boost.module
--- boost.module	15 Jul 2009 07:48:30 -0000	1.3.2.2.2.5.2.72
+++ boost.module	21 Jul 2009 22:38:29 -0000
@@ -371,16 +371,22 @@ function boost_block($op = 'list', $delt
       );
     case 'configure':
       if ($delta == 'stats') {
-        $form['items'] = array(
+        $form['boost_block_show_stats'] = array(
         '#type' => 'checkbox',
         '#title' => t('Display Statistics'),
         '#default_value' => variable_get('boost_block_show_stats', FALSE),
         );
+        $form['boost_block_cache_stats_block'] = array(
+        '#type' => 'checkbox',
+        '#title' => t('Cache Statistics Block'),
+        '#default_value' => variable_get('boost_block_cache_stats_block', FALSE),
+        );
       return $form;
       }
     case 'save':
       if ($delta == 'stats') {
-        variable_set('boost_block_show_stats', $edit['items']);
+        variable_set('boost_block_show_stats', $edit['boost_block_show_stats']);
+        variable_set('boost_block_cache_stats_block', $edit['boost_block_cache_stats_block']);
       }
     case 'view':
       $block = array();
@@ -441,16 +447,11 @@ function boost_block($op = 'list', $delt
               $block['subject'] = 'Popular content';
               $block['content'] = '<div id="boost-stats"></div>' . boost_stats_generate($filename);
             }
-            else {
+            elseif (!variable_get('boost_block_show_stats', FALSE)) {
               $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();
-          }
-
-
+          break;
       }
       return $block;
   }
@@ -487,20 +488,20 @@ function boost_stats_generate($filename)
 
   // 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);;
+    $nid = arg(1);;
   }
   else {
-    $nid = 'nid=NULL';
+    $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'];
+    $title = drupal_urlencode(strip_tags(drupal_get_title()));
+    $q = $_GET['q'];
   }
   else {
-    $title = 'title=NULL';
-    $q = 'q=NULL';
+    $title = 'NULL';
+    $q = 'NULL';
   }
 
   $page_js = array(
@@ -510,14 +511,20 @@ function boost_stats_generate($filename)
       '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);';
+  $site_js = <<<ETO
+$.getJSON(Drupal.settings.basePath + "$filename", {nocache: "1", js: "1", nid: Drupal.settings.boost.nid, q: Drupal.settings.boost.q, title: Drupal.settings.boost.title, referer: document.referrer}, function(response) {
+  $.each(response, function(id, contents) {
+    $(id).html(contents);
+  });
+});
+ETO;
 
   // 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>';
+  $page_ns = '<noscript><div style="display:inline;"><img src="' . $base_path . $filename . '?nocache=1' . '&amp;nid='. $nid . '&amp;title='. $title . '&amp;q='. $q . '" alt="" /></div></noscript>';
 
   return $page_ns;
 }
Index: stats/boost_stats.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/stats/Attic/boost_stats.php,v
retrieving revision 1.1.2.4
diff -u -p -r1.1.2.4 boost_stats.php
--- stats/boost_stats.php	10 Jul 2009 00:19:49 -0000	1.1.2.4
+++ stats/boost_stats.php	21 Jul 2009 22:38:29 -0000
@@ -1,7 +1,7 @@
 <?php
 // $Id: boost_stats.php,v 1.1.2.4 2009/07/10 00:19:49 mikeytown2 Exp $
 
-if (isset($_GET['js']) && $_GET['js']==0) {
+if (!isset($_GET['js'])) {
   // stats not called via JS, send image out & close connection.
   boost_stats_async_image();
 }
@@ -19,24 +19,31 @@ if (   !isset($_GET['nid'])
 boost_stats_init();
 
 // Set node counter.
-if ($count_views && isset($nid) && is_numeric($nid)) {
+if (boost_stats_variable_get('statistics_count_content_views')) {
   boost_stats_update_node_counter();
 }
 
 // Set access log.
-if ($access_log && isset($title) && isset($q)) {
+if (boost_stats_variable_get('statistics_enable_access_log')) {
   boost_stats_add_access_log();
 }
 
-// Send stats block html.
-if ($stats) {
-  boost_stats_output_stats_block();
+$json = array();
+// Get stats block html.
+if (boost_stats_variable_get('boost_block_show_stats')) {
+  $json = array_merge($json, boost_stats_output_stats_block());
 }
 
+// Send JSON Back
+if (!empty($json)) {
+  echo json_encode($json);
+}
 // end of script, exit.
 exit;
 
-Function boost_stats_async_image() {
+
+
+function boost_stats_async_image() {
   // Script should take under 1mb of memory to work.
   // Prime php for background operations
   ob_end_clean();
@@ -59,19 +66,18 @@ Function boost_stats_async_image() {
   // 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;
+function boost_stats_init() {
+  Global $nid, $title, $q, $referer, $session_id, $uid, $count_views, $access_log, $variables;
 
   // 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;
+  $nid = (isset($_GET['nid']) && is_numeric($_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()];
@@ -82,26 +88,19 @@ Function boost_stats_init() {
   }
   $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']);
+  // load all boost & statistics variables; 1 transaction instead of mutiple
+  $result = db_query("
+SELECT * FROM {variable}
+WHERE name LIKE 'boost_%'
+OR name LIKE 'statistics_%'
+OR name LIKE 'throttle_%'
+");
+  while ($variable = db_fetch_object($result)) {
+    $variables[$variable->name] = unserialize($variable->value);
   }
 }
 
-Function boost_stats_update_node_counter() {
+function boost_stats_update_node_counter() {
   Global $nid;
 
   // A node has been viewed, so update the node's counters.
@@ -113,13 +112,39 @@ Function boost_stats_update_node_counter
   }
 }
 
-Function boost_stats_add_access_log() {
+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());
 }
 
-Function boost_stats_output_stats_block() {
-  Global $stats_block;
-  echo $stats_block;
+function boost_stats_output_stats_block() {
+
+  if (!boost_stats_variable_get('boost_block_cache_stats_block') && !boost_stats_variable_get('throttle_level')) {
+    boost_stats_full_boot();
+    $block = module_invoke('statistics', 'block', 'view', 0);
+    $block = $block['content'];
+  }
+  else {
+    $block = boost_stats_variable_get('boost_statistics_html');
+  }
+
+  return array('#boost-stats' => $block);
+}
+
+function boost_stats_full_boot() {
+  Global $full_boot;
+  if (!isset($full_boot)) {
+    $full_boot = FALSE;
+  }
+  if (!$full_boot) {
+    include_once './includes/bootstrap.inc';
+    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
+  }
+  $full_boot = TRUE;
 }
+
+function boost_stats_variable_get($name) {
+  Global $variables;
+  return isset($variables[$name]) ? $variables[$name] : FALSE;
+}
\ No newline at end of file
