? boost-586210.patch
Index: boost.admin.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.admin.inc,v
retrieving revision 1.1.2.1.2.3.2.130
diff -u -p -r1.1.2.1.2.3.2.130 boost.admin.inc
--- boost.admin.inc	24 Jan 2010 18:25:46 -0000	1.1.2.1.2.3.2.130
+++ boost.admin.inc	14 Feb 2010 03:04:46 -0000
@@ -568,6 +568,25 @@ function boost_admin_boost_performance_p
     '#default_value' => BOOST_NO_DATABASE,
     '#description'   => t('Go old school and don\'t use the database. Very extreme tweak & support for features in this mode is pretty much non existent.'),
   );
+  $options = array(t('Set the session cookie on every page except the listed pages.'), t('Set the session cookie only on the listed pages.'));
+  $description = t("Enter one page per line as Drupal paths. The '*' character is a wild-card. Example paths are '%blog' for the blog page and %blog-wild-card for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wild-card' => 'blog/*', '%front' => '<front>'));
+  if (user_access('use PHP for block visibility')) {
+    $options[] = t('Set the session cookie for which the following PHP code returns <code>TRUE</code> (PHP-mode, experts only).');
+    $description .= t('If the PHP-mode is chosen, enter PHP code between %php. Note that executing incorrect PHP-code can severely break your Drupal site.', array('%php' => '<?php ?>'));
+  }
+  $form['advanced']['boost_session_option'] = array(
+    '#type'          => 'radios',
+    '#title'         => t('Set session cookie on specific pages'),
+    '#options'       => $options,
+    '#default_value' => BOOST_SESSION_OPTION,
+  );
+  $form['advanced']['boost_session_pages'] = array(
+    '#type'          => 'textarea',
+    '#title'         => t('Pages'),
+    '#default_value' => BOOST_SESSION_PAGES,
+    '#description'   => $description,
+    '#wysiwyg'       => FALSE,
+  );
 
   // Crawler
   $form['crawler'] = array(
Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.304
diff -u -p -r1.3.2.2.2.5.2.304 boost.module
--- boost.module	6 Feb 2010 18:20:58 -0000	1.3.2.2.2.5.2.304
+++ boost.module	14 Feb 2010 03:04:48 -0000
@@ -83,6 +83,8 @@ define('BOOST_IGNORE_SAFE_WARNING',  var
 define('BOOST_IGNORE_SUBDIR_LIMIT',  variable_get('boost_ignore_subdir_limit', TRUE));
 define('BOOST_IGNORE_HTACCESS_WARNING',  variable_get('boost_ignore_htaccess_warning', FALSE));
 define('BOOST_NO_DATABASE',          variable_get('boost_no_database', FALSE));
+define('BOOST_SESSION_OPTION',  variable_get('boost_session_option', 1));
+define('BOOST_SESSION_PAGES',   variable_get('boost_session_pages', ''));
 
 // Crawler Settings
 define('BOOST_CRAWL_ON_CRON',        variable_get('boost_crawl_on_cron', FALSE));
@@ -120,6 +122,7 @@ define('BOOST_MAX_THREAD_TIME',      max
 //$GLOBALS['_boost_router_item'] = '';
 //$GLOBALS['_boost_relationships'] = '';
 //$GLOBALS['_boost_nid'] = '';
+//$GLOBALS['_boost_get_cookie'] = '';
 
 //////////////////////////////////////////////////////////////////////////////
 // Core API hooks
@@ -255,6 +258,7 @@ function boost_init() {
       $GLOBALS['conf']['cache'] = CACHE_DISABLED;
     }
     $GLOBALS['_boost_cache_this'] = TRUE;
+    $GLOBALS['_boost_get_cookie'] = boost_send_session_cookie();
     register_shutdown_function('_boost_ob_handler');
     ob_start();
   }
@@ -351,9 +355,26 @@ function boost_menu() {
     'access arguments' => array('access content'),
     'file path' => drupal_get_path('module', 'boost'),
   );
+  $items['boost-set-session-cookie.php'] = array(
+    'page callback' => 'boost_set_session',
+    'type' => MENU_CALLBACK,
+    'access callback' => 1,
+    'access arguments' => array('access content'),
+    'file path' => drupal_get_path('module', 'boost'),
+  );
   return $items;
 }
 
+function boost_set_session() {
+  $id = session_id();
+  if (empty($id)) {
+    drupal_bootstrap(DRUPAL_BOOTSTRAP_SESSION);
+  }
+  $_SESSION['boost_give_user_session'] = mt_rand();
+  setcookie('boost-session-ready', BOOST_TIME, 0, '/'); // Browser has session cookie now
+  echo "Session Check In<br />\n" . $_SESSION['boost_give_user_session'];
+}
+
 /**
  * Implementation of hook_form_alter(). Performs alterations before a form
  * is rendered.
@@ -1348,6 +1369,9 @@ function _boost_ob_handler() {
   $GLOBALS['_boost_router_item'] = isset($GLOBALS['_boost_router_item']) ? $GLOBALS['_boost_router_item'] : _boost_get_menu_router();
   if (   $GLOBALS['_boost_router_item']['page_callback'] == 'search404_page'
       || $GLOBALS['_boost_router_item']['page_callback'] == 'fivestar_vote'
+      || $GLOBALS['_boost_router_item']['page_callback'] == 'boost_stats_ajax_callback'
+      || $GLOBALS['_boost_router_item']['page_callback'] == 'boost_crawler_run'
+      || $GLOBALS['_boost_router_item']['page_callback'] == 'boost_set_session'
       ) {
     $GLOBALS['_boost_cache_this'] = FALSE;
   }
@@ -1590,6 +1614,31 @@ function boost_is_cacheable($path) {
   return $page_match;
 }
 
+function boost_send_session_cookie($path) {
+  $path = (empty($path)) ? variable_get('site_frontpage', 'node') : $path;
+  // See http://api.drupal.org/api/function/block_list/6
+  // Match the user's set session cookie settings against the path
+  if (BOOST_SESSION_PAGES) {
+    if (BOOST_SESSION_OPTION < 2) {
+      $page_match = drupal_match_path($path, BOOST_SESSION_OPTION);
+      if ($path != $_GET['q']) {
+        $page_match = $page_match || drupal_match_path($_GET['q'], BOOST_SESSION_PAGES);
+      }
+      // When BOOST_CACHEABILITY_OPTION has a value of 0, boost will cache
+      // all pages except those listed in BOOST_CACHEABILITY_PAGES. When set
+      // to 1, boost will cache only on those pages listed in BOOST_CACHEABILITY_PAGES.
+      $page_match =  !(BOOST_SESSION_OPTION xor $page_match);
+    }
+    else {
+      $page_match =  drupal_eval(BOOST_SESSION_PAGES);
+    }
+  }
+  else {
+    $page_match =  TRUE;
+  }
+  return $page_match;
+}
+
 /**
  * This hook is run inorder to determine if a page should be cached.
  *  Runs in boost_init().
@@ -2288,10 +2337,16 @@ function boost_cache_set($path, $data, $
 
   // Create or update the static files as needed
   if (($filename = boost_file_path($path, TRUE, $extension)) && (BOOST_OVERWRITE_FILE || !file_exists($filename) || boost_db_is_expired($filename))) {
+    // Inject iframe/object to set session cookie if desired
+    if ($GLOBALS['_boost_get_cookie'] && $extension == BOOST_FILE_EXTENSION) {
+      $matches = preg_split('/(<body.*?>)/i', $data, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
+      $data = $matches[0] . $matches[1] . boost_html_object_load(url('boost-set-session-cookie.php', array('query' => array('nocache' => '1')))) . $matches[2];
+    }
+
     // Special handling of the front page for aggressive gzip test
     if ($path == '' && BOOST_AGGRESSIVE_GZIP && $extension == BOOST_FILE_EXTENSION) {
       _boost_generate_gzip_test_file();
-      boost_cache_write($filename, _boost_inject_code($data, '<div style="width:0px; height:0px; border:0px; position:absolute; top:-1000px; z-index:10;"><object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" type="text/html" data="/boost-gzip-cookie-test.html" style="width:0px; height:0px; border:0px; position:absolute; top:-1000px; z-index:10;"></object></div>' . "\n"));
+      boost_cache_write($filename, _boost_inject_code($data, boost_html_object_load('/boost-gzip-cookie-test.html') . "\n"));
     }
     else {
       boost_cache_write($filename, $data);
@@ -2307,6 +2362,10 @@ function boost_cache_set($path, $data, $
   }
 }
 
+function boost_html_object_load($dest) {
+  return '<div style="width:1px; height:1px; border:0px; position:absolute; top:-1000px; z-index:10;"><!--[if IE]><object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" data="some.html"></object><object classid="clsid:25336920-03F9-11CF-8FD0-00AA00686F13" type="text/html" data="' . $dest . '" style="width:1px; height:1px; border:0px; position:absolute; top:-1000px; z-index:10;"></object><![endif]--><!--[if !IE]> <--><object data="' . $dest . '" style="width:1px; height:1px; border:0px; position:absolute; top:-1000px; z-index:10;"></object></object></div>';
+}
+
 /**
  * Creates a parent child relationship for pages like views.
  *
