? boost-482000.1.patch
? boost-482000.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.40
diff -u -p -r1.1.2.1.2.3.2.40 boost.admin.inc
--- boost.admin.inc	22 Jul 2009 02:59:40 -0000	1.1.2.1.2.3.2.40
+++ boost.admin.inc	23 Jul 2009 00:46:35 -0000
@@ -138,6 +138,8 @@ function boost_admin_clear_cache_submit(
  *  http://drupal.org/node/337756
  */
 function boost_admin_boost_performace_page() {
+  Global $base_path;
+
   // Cacheability settings
   $options = array(t('Cache every page except the listed pages.'), t('Cache only the listed pages.'));
   $description = t("Enter one page per line as Drupal paths. The '*' character is a wildcard. Example paths are '%blog' for the blog page and %blog-wildcard for every personal blog. %front is the front page.", array('%blog' => 'blog', '%blog-wildcard' => 'blog/*', '%front' => '<front>'));
@@ -301,12 +303,42 @@ function boost_admin_boost_performace_pa
     '#options'       => array('%{SERVER_NAME}' => '%{SERVER_NAME}', '%{HTTP_HOST}' => '%{HTTP_HOST}', $_SERVER['SERVER_NAME'] => $_SERVER['SERVER_NAME'], $_SERVER['HTTP_HOST'] => $_SERVER['HTTP_HOST'], ),
     '#description'   => t('Best to leave these as %{}, only try the last option(s) if boost is still not working.'),
   );
+
+  // Set DOCUMENT_ROOT
+  $drupal_subdir = rtrim($base_path, '/');
+  $document_root = str_replace("\\", '/', getcwd()); // remove windows
+  $document_root = str_replace($drupal_subdir, '', $document_root); // remove subdir
+  $options = array('%{DOCUMENT_ROOT}' => '%{DOCUMENT_ROOT}', $document_root => $document_root); // initial options
+  $rejects = array('SCRIPT_FILENAME', 'DOCUMENT_ROOT'); // values to ignore
+  $output = boost_array_find($document_root, $_SERVER, $rejects); //search for values that match getcwd
+  if (!empty($output)) {
+    foreach ($output as $key=>$value) {
+      $temp = '%{ENV:' . $key . '}';
+      $options[$temp] = $temp; // adding values to options
+      if ($value == $document_root) {
+        $best = $temp; // set best since it's a match
+      }
+    }
+  }
+  if ($_SERVER['DOCUMENT_ROOT'] == $document_root) {
+    $best = '%{DOCUMENT_ROOT}';
+  }
+  else {
+    $best = $document_root;
+  }
+  $description = t("Value of $best is recommened for this server.");
+
+  // If a suitable apache variable couldn't be found do this
+  if ($best == $document_root) {
+    $description .= t(' Please open an boost issue on drupal.org, since apache and php are not configured correctly.');
+  }
+
   $form['htaccess']['boost_document_root'] = array(
     '#type'          => 'radios',
     '#title'         => t('Document Root'),
     '#default_value' => variable_get('boost_document_root', '%{DOCUMENT_ROOT}'),
-    '#options'       => array('%{DOCUMENT_ROOT}' => '%{DOCUMENT_ROOT}', getcwd() => getcwd()),
-    '#description'   => t('Default value %{DOCUMENT_ROOT} is highly recommened.'),
+    '#options'       => $options,
+    '#description'   => $description,
   );
   $form['htaccess']['boost_generated'] = array(
     '#type'          => 'textarea',
@@ -399,8 +431,6 @@ function boost_admin_themes_submit($form
 function boost_admin_generate_htaccess($server_name = '%{SERVER_NAME}', $document_root = '%{DOCUMENT_ROOT}', $cache_dir = 'cache', $gzip_dir = 'gz', $html = '.html', $xml = '.xml') {
   Global $base_path;
   $drupal_subdir = rtrim($base_path, '/');
-  $document_root = str_replace("\\", '/', $document_root);
-  $document_root = str_replace($drupal_subdir, '', $document_root );
   $html = '\\' . $html;
   $xml = '\\' . $xml;
   $css = '\\.css';
@@ -535,3 +565,31 @@ function boost_reset_database_submit () 
     drupal_set_message(t('Boost: Set "Ignore cache flushing:" to \'Disabled\' in the <a href="!link">boost advanced settings</a> & try again.', array('!link' => url('admin/settings/performance/boost', array('fragment' => 'edit-boost-ignore-flush-0-wrapper')))), 'warning');
   }
 }
+
+/**
+ * Returns all key/values in array that match.
+ *
+ * @param $needle
+ *  What your searching for
+ * @param $haystack
+ *  Array of values
+ * @param $a_not
+ *  Optional array of key names to exclude
+ */
+function boost_array_find($needle, $haystack, $a_not = array()) {
+  $out = array();
+  foreach($haystack as $key=>$value) {
+    if (strpos($value, $needle) !== FALSE) {
+      $good = TRUE;
+      foreach($a_not as $not) {
+        if (strpos($key, $not) !== FALSE) {
+          $good = FALSE;
+        }
+      }
+      if ($good) {
+        $out[$key] = $value;
+      }
+    }
+  }
+  return $out;
+}
