? boost-503628.patch
Index: boost.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.install,v
retrieving revision 1.2.2.1.2.3.2.20
diff -u -p -r1.2.2.1.2.3.2.20 boost.install
--- boost.install	6 Jul 2009 18:24:26 -0000	1.2.2.1.2.3.2.20
+++ boost.install	27 Jul 2009 23:41:59 -0000
@@ -96,14 +96,6 @@ function boost_requirements($phase) {
           'value'       => $t('Can not write to filesystem'),
         );
       }
-      elseif ((variable_get('statistics_count_content_views', 0) || variable_get('statistics_enable_access_log', 0)) && !file_exists('boost_stats.php')) {
-        $requirements['boost'] = array(
-          'title'       => $t('Boost'),
-          'description' => $t('Copy the boost_stats.php file to your webroot. It should be located in the modules/boost/stats directory.'),
-          'severity'    => REQUIREMENT_WARNING,
-          'value'       => $t('boost_stats.php missing from root dir'),
-        );
-      }
       else {
         $requirements['boost'] = array(
           'title'       => $t('Boost'),
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.78
diff -u -p -r1.3.2.2.2.5.2.78 boost.module
--- boost.module	22 Jul 2009 03:09:53 -0000	1.3.2.2.2.5.2.78
+++ boost.module	27 Jul 2009 23:41:59 -0000
@@ -187,6 +187,11 @@ function boost_menu() {
     'type' => MENU_LOCAL_TASK,
     'file' => 'boost.admin.inc',
   );
+  $items['boost/ajax'] = array(
+    'page callback' => 'boost_stats_ajax_callback',
+    'type' => MENU_CALLBACK,
+    'file' => 'stats/boost_stats.ajax.inc',
+  );
   return $items;
 }
 
@@ -387,8 +392,9 @@ function boost_block($op = 'list', $delt
       if ($delta == 'stats') {
         $form['boost_block_show_stats'] = array(
         '#type' => 'checkbox',
-        '#title' => t('Display Statistics'),
+        '#title' => t('Display Statistics.'),
         '#default_value' => variable_get('boost_block_show_stats', FALSE),
+        '#description' => t('If false, uses Javascript to hide the block via "parent().parent().hide()".'),
         );
         $form['boost_block_cache_stats_block'] = array(
         '#type' => 'checkbox',
@@ -457,14 +463,13 @@ function boost_block($op = 'list', $delt
               || !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);
-            }
-            elseif (!variable_get('boost_block_show_stats', FALSE)) {
-              $block = array();
-            }
+            $block = array();
+            $block['subject'] = 'Popular content';
+            $block['content'] = '<div id="boost-stats"></div>' . boost_stats_generate($filename);
+          }
+          elseif (!variable_get('boost_block_show_stats', FALSE)) {
+            $block['content'] .= '<div id="boost-stats"></div>';
+            drupal_add_js('$("#boost-stats").parent().parent().hide();', 'inline', 'footer');
           }
           break;
       }
@@ -569,7 +574,12 @@ function boost_stats_generate($filename)
   $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);
+    if (contents == 'NULL') {
+      $(id).parent().parent().hide();
+    }
+    else {
+      $(id).html(contents);
+    }
   });
 });
 ETO;
Index: stats/boost_stats.ajax.inc
===================================================================
RCS file: stats/boost_stats.ajax.inc
diff -N stats/boost_stats.ajax.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ stats/boost_stats.ajax.inc	27 Jul 2009 23:41:59 -0000
@@ -0,0 +1,146 @@
+<?php
+
+/**
+ * AJAX Menu Callback.
+ */
+function boost_stats_ajax_callback() {
+  if (!isset($_GET['js'])) {
+    // stats not called via JS, send image out & close connection.
+    boost_stats_async_image();
+  }
+
+  // Exit if nothing was passed to this.
+  if (   !isset($_GET['nid'])
+      && !isset($_GET['title'])
+      && !isset($_GET['q'])
+      && !isset($_GET['referer'])
+      ) {
+    exit;
+  }
+
+  // Set variables passed via GET.
+  $nid = (isset($_GET['nid']) && is_numeric($_GET['nid'])) ? $_GET['nid'] : NULL;
+  $title = (isset($_GET['title']) && $_GET['title'] != 'NULL') ? urldecode($_GET['title']) : NULL;
+  $q = (isset($_GET['q']) && $_GET['q'] != 'NULL') ? $_GET['q'] : NULL;
+  $referer = isset($_GET['referer']) ? $_GET['referer'] : NULL;
+
+  // This only goes in the access log; only used for stats, not creds.
+  $session_id = session_id();
+  if (empty($session_id)) {
+    if (empty($_COOKIE[session_name()])) {
+      if (empty($_SERVER['HTTP_USER_AGENT'])) {
+        $session_id = md5(ip_address());
+      }
+      else {
+        $session_id = md5($_SERVER['HTTP_USER_AGENT'] . ip_address());
+      }
+    }
+    else {
+      $session_id = $_COOKIE[session_name()];
+    }
+  }
+  $uid = 0;
+
+  // Set node counter.
+  if (variable_get('statistics_count_content_views', FALSE)) {
+    boost_stats_update_node_counter($nid);
+  }
+
+  // Set access log.
+  if (variable_get('statistics_enable_access_log', FALSE)) {
+    boost_stats_add_access_log($title, $q, $referer, $session_id, $uid);
+  }
+
+  // Return Data
+  if (isset($_GET['js'])) {
+    if ($_GET['js'] == 1) {
+      $json = array();
+      // Get stats block html.
+      $json = array_merge($json, boost_stats_output_stats_block());
+
+      // Send JSON Back
+      if (!empty($json)) {
+        echo json_encode($json);
+      }
+    }
+    // Send HTML back
+    elseif ($_GET['js'] == 2) {
+      echo array_pop(boost_stats_output_stats_block());
+    }
+  }
+}
+
+/**
+ * Update database node count.
+ *
+ * @param $nid
+ *  Node ID of page.
+ */
+function boost_stats_update_node_counter($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());
+  }
+}
+
+/**
+ * Add entry to access log
+ *
+ * @param $title
+ *  Title of page.
+ * @param $q
+ *  URL directory structure
+ * @param $referrer
+ *  Javascript referrer
+ * @param $session_id
+ *  Session ID
+ * @param $uid
+ *  User ID; should be 0.
+ */
+function boost_stats_add_access_log($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());
+}
+
+/**
+ * Return array with stats block html.
+ */
+function boost_stats_output_stats_block() {
+  if (variable_get('boost_block_show_stats', FALSE)) {
+      $block = module_invoke('statistics', 'block', 'view', 0);
+      $block = $block['content'];
+  }
+  else {
+    $block = 'NULL';
+  }
+
+  return array('#boost-stats' => $block);
+}
+
+/**
+ * Returns a 1px image and allows for php to run in the background.
+ */
+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 after this should not effect page loading.
+}
\ No newline at end of file
Index: stats/boost_stats.php
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/stats/Attic/boost_stats.php,v
retrieving revision 1.1.2.6
diff -u -p -r1.1.2.6 boost_stats.php
--- stats/boost_stats.php	22 Jul 2009 03:08:25 -0000	1.1.2.6
+++ stats/boost_stats.php	27 Jul 2009 23:41:59 -0000
@@ -28,16 +28,23 @@ if (boost_stats_variable_get('statistics
   boost_stats_add_access_log();
 }
 
-$json = array();
-// Get stats block html.
-if (boost_stats_variable_get('boost_block_show_stats')) {
-  $json = array_merge($json, boost_stats_output_stats_block());
+if (isset($_GET['js'])) {
+  if ($_GET['js'] == 1) {
+    $json = array();
+    // Get stats block html.
+    $json = array_merge($json, boost_stats_output_stats_block());
+
+    // Send JSON Back
+    if (!empty($json)) {
+      echo json_encode($json);
+    }
+  }
+  // Send HTML back
+  elseif ($_GET['js'] == 2) {
+    echo array_pop(boost_stats_output_stats_block());
+  }
 }
 
-// Send JSON Back
-if (!empty($json)) {
-  echo json_encode($json);
-}
 // end of script, exit.
 exit;
 
@@ -74,9 +81,9 @@ function boost_stats_init() {
   drupal_bootstrap(DRUPAL_BOOTSTRAP_DATABASE);
 
   // Set variables passed via GET.
-  $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;
+  $nid = (isset($_GET['nid']) && is_numeric($_GET['nid'])) ? $_GET['nid'] : NULL;
+  $title = (isset($_GET['title']) && $_GET['title'] != 'NULL') ? urldecode($_GET['title']) : NULL;
+  $q = (isset($_GET['q']) && $_GET['q'] != 'NULL') ? $_GET['q'] : NULL;
   $referer = isset($_GET['referer']) ? $_GET['referer'] : NULL;
   $session_id = session_id();
   if (empty($session_id)) {
@@ -121,14 +128,18 @@ function boost_stats_add_access_log() {
 }
 
 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'];
+  if (boost_stats_variable_get('boost_block_show_stats')) {
+    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');
+    }
   }
   else {
-    $block = boost_stats_variable_get('boost_statistics_html');
+    $block = 'NULL';
   }
 
   return array('#boost-stats' => $block);
