diff -urN boost/boost.admin.inc boost_patch/boost.admin.inc --- boost/boost.admin.inc 2009-07-15 03:45:49.000000000 -0400 +++ boost_patch/boost.admin.inc 2009-07-18 08:28:00.000000000 -0400 @@ -66,6 +66,20 @@ '#submit' => array('boost_clear_expired_cache_submit'), ); + // Boost Pre-Caching + if (BOOST_ENABLED == 1) { + $form['boost-pre'] = array( + '#type' => 'fieldset', + '#title' => t('Boost File Pre-Cache'), + '#description' => t('Instead of relying on an anonymous user visit to trigger caching, pre-caching allows us to cache pages before the user arrives.'), + ); + $form['boost-pre']['boost_export_button'] = array( + '#type' => 'submit', + '#submit' => array('boost_export_submit'), + '#value' => t('Click this button to export all pages to HTML now'), + ); + } + // Alter core page cache setttings. $form['core'] = array( '#type' => 'fieldset', @@ -523,3 +537,11 @@ drupal_set_message(t('Boost: Set "Ignore cache flushing:" to \'Disabled\' in the boost advanced settings & try again.', array('!link' => url('admin/settings/performance/boost', array('fragment' => 'edit-boost-ignore-flush-0-wrapper')))), 'warning'); } } + +/** + * Initiates pre-caching of pages, taxonomies + */ +function boost_export_submit($form, &$form_state) { + module_load_include('inc', 'boost', 'boost.pages'); + boost_collect_pages(); +} \ No newline at end of file diff -urN boost/boost.module boost_patch/boost.module --- boost/boost.module 2009-07-15 03:48:30.000000000 -0400 +++ boost_patch/boost.module 2009-07-17 18:00:31.000000000 -0400 @@ -52,6 +52,9 @@ // This is needed since the $user object is already destructed in _boost_ob_handler(): define('BOOST_USER_ID', @$GLOBALS['user']->uid); +// Include boost.pages.inc for batch functions. +require_once('boost.pages.inc'); + ////////////////////////////////////////////////////////////////////////////// // Global variables diff -urN boost/boost.pages.inc boost_patch/boost.pages.inc --- boost/boost.pages.inc 1969-12-31 19:00:00.000000000 -0500 +++ boost_patch/boost.pages.inc 2009-07-18 08:55:02.000000000 -0400 @@ -0,0 +1,95 @@ +nid, '')); + } + + // Get all terms + if (module_exists('taxonomy')) { + $result = db_query("SELECT tid FROM {term_data}"); + while ($row = db_fetch_object($result)) { + $operations[] = array('boost_export_html', array('taxonomy/term/'. $row->tid, '')); + } + } + + // Invoke hook_boost_export() + foreach (module_implements('boost_export') as $module) { + if (($result = module_invoke($module, 'boost_export')) != NULL) { + $operations = array_merge($operations, $result); + } + } + + // TODO more support for modules (views, panels, ... ?) + + // Batch properties. + $batch = array( + 'title' => t('Exporting html'), + 'operations' => $operations, + 'finished' => 'boost_export_done', + ); + batch_set($batch); +} + +/** + * Batch callback function. + * @param $page + * The drupal page we are going to fetch. + * @param $path + * Override path we take from $page, ie for frontpage. + */ +function boost_export_html($page, $path, &$context) { + // Set initial variable. + if (!isset($context['results']['num_html'])) { + $context['results']['num_html'] = 0; + } + + if (boost_is_cacheable($page) == TRUE && boost_is_cached($page) == FALSE) { + // Fetch a page with drupal_http_request, this does an anonymous request. + $url = url($page, array('absolute' => TRUE)); + $data = drupal_http_request($url); + + // Write the file away if code is 200 and we have data. + if ($data->code == 200 && strlen($data->data) > 0) { + $path = (!empty($path)) ? $path : $page; + boost_cache_set($path, $data->data); + $context['results']['num_html']++; + } + } +} + +/** + * Batch finished callback. + */ +function boost_export_done($success, $results, $operations) { + if ($success) { + // Count the number of pages we processed. + $message = $results['num_html'] . ' ' . t('html files created during Boost pre-cache.'); + drupal_set_message($message, 'status'); + watchdog('boost', $message); + } + else { + // An error occurred. + $error_operation = reset($operations); + $message = t('An error occurred while creating the html files for Boost pre-cache.'); + drupal_set_message($message, 'error'); + watchdog('boost', $message, array(), WATCHDOG_ERROR); + } +}