Index: boost.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/boost/boost.module,v
retrieving revision 1.3.2.2.2.5.2.133
diff -u -p -r1.3.2.2.2.5.2.133 boost.module
--- boost.module	5 Sep 2009 09:26:34 -0000	1.3.2.2.2.5.2.133
+++ boost.module	6 Sep 2009 07:59:33 -0000
@@ -1751,23 +1751,22 @@ function boost_path_redirect_load($where
 function boost_cache_css_js_files($buffer) {
   if (BOOST_CACHE_CSS) {
     // Extract external css files from html document
-    $css = explode('<link type="text/css" rel="stylesheet" ', $buffer);
-    array_shift($css);
-    foreach ($css as $key => $value) {
-      // Only grab the first string, containing the css filename.
-      $css[$key] = array_shift(explode(' />', $value));
+    $css_files = explode('<link ', $buffer);
+    array_shift($css_files);
+    foreach ($css_files as $key => $value) {
+      // Extract css filename
+      $css_files[$key] = array_shift(explode('"', array_shift(explode('?', array_pop(explode(base_path(), array_pop(explode('//', array_pop(explode('href="', array_shift(explode('" />', $value))))))))))));
     }
-    $css = implode('',$css);
-
-    _boost_copy_css_files($css);
+    _boost_copy_css_files($css_files);
   }
   if (BOOST_CACHE_JS) {
-    $js = explode('<script type="text/javascript" ', $buffer);
-    array_shift($js);
-    $temp = explode('</script>', array_pop($js));
-    $js[] = array_shift($temp);
-    $js = implode('',$js);
-    _boost_copy_js_files($js);
+    $js_files = explode('<script ', $buffer);
+    array_shift($js_files);
+    foreach ($js_files as $key => $value) {
+      // Extract javascript src filename; kill scripts with no src tag
+      $js_files[$key] = array_shift(explode('type=', array_shift(explode('"', array_shift(explode('?', array_pop(explode(base_path(), array_pop(explode('//', array_pop(explode('src="', array_shift(explode('">', $value))))))))))))));
+    }
+    _boost_copy_js_files(array_filter($js_files));
   }
 }

@@ -1856,25 +1855,19 @@ function boost_glue_url($parsed) {
 /**
  * Extract css filenames from html and copy them & their children.
  *
- * @param $css
- *   String containing all html css.
+ * @param $css_files
+ *   array containing all css filenames.
  */
-function _boost_copy_css_files($css) {
-  //extract css file name
-  $css_files=explode('href="', $css);
-  array_shift($css_files);
-  for ($i = 0; $i < count($css_files); $i++) {
-    $temp = array_pop(explode('//', $css_files[$i]));
-    $temp = explode(base_path(), array_shift(explode('.css', $temp)));
-    array_shift($temp);
-    $css_files[$i] = implode(base_path(), $temp);
-  }
-
+function _boost_copy_css_files($css_files) {
   //copy files
   foreach ($css_files as $css_file) {
+    // Strip extenstion from filename
+    $css_file = dirname($css_file) . '/' . array_shift(explode('.', basename($css_file)));
+    watchdog('boost', $css_file);
+
     if (file_exists($css_file . '.css')) {
       $src = $css_file . '.css';
-      $dest = BOOST_PERM_FILE_PATH . '/' . $css_file . '.css' . BOOST_PERM_CHAR . BOOST_CSS_EXTENSION;
+      $dest = BOOST_PERM_FILE_PATH . '/' . $src . BOOST_PERM_CHAR . BOOST_CSS_EXTENSION;
       _boost_copy_file($src, $dest);
     }
     if (file_exists($css_file . '.css.gz')) {
@@ -1884,7 +1877,7 @@ function _boost_copy_css_files($css) {
     }
     elseif (BOOST_GZIP && file_exists($css_file . '.css')) {
       $src = $css_file . '.css';
-      $dest = BOOST_PERM_GZIP_FILE_PATH . '/' . $css_file . '.css' . BOOST_PERM_CHAR . BOOST_CSS_EXTENSION . BOOST_GZIP_EXTENSION;
+      $dest = BOOST_PERM_GZIP_FILE_PATH . '/' . $src . BOOST_PERM_CHAR . BOOST_CSS_EXTENSION . BOOST_GZIP_EXTENSION;
       _boost_gz_copy_file($src, $dest);
     }
   }
@@ -1893,28 +1886,19 @@ function _boost_copy_css_files($css) {
 /**
  * Extract javascript filenames from html and copy them & their children.
  *
- * @param $js
- *   String containing all html javascript.
+ * @param $js_files
+ *   Array containing all javascript filenames.
  */
-function _boost_copy_js_files($js) {
-  //extract js file name
-  $js_files=explode('src="', $js);
-  array_shift($js_files);
-  for ($i = 0; $i < count($js_files); $i++) {
-    $temp = array_shift(explode('"', $js_files[$i]));
-    $temp = array_pop(explode('//', $temp));
-    $temp = explode('.', $temp);
-    array_pop($temp);
-    $temp = explode(base_path(), implode('.', $temp));
-    array_shift($temp);
-    $js_files[$i] = implode(base_path(), $temp);
-  }
-
+function _boost_copy_js_files($js_files) {
   //copy files
   foreach ($js_files as $js_file) {
+    // Strip extenstion from filename
+    $js_file = dirname($js_file) . '/' . array_shift(explode('.', basename($js_file)));
+    watchdog('boost', $js_file);
+
     if (file_exists($js_file . '.js')) {
       $src = $js_file . '.js';
-      $dest = BOOST_PERM_FILE_PATH . '/' . $js_file . '.js' . BOOST_PERM_CHAR . BOOST_JS_EXTENSION;
+      $dest = BOOST_PERM_FILE_PATH . '/' . $src . BOOST_PERM_CHAR . BOOST_JS_EXTENSION;
       _boost_copy_file($src, $dest);
     }
     if (file_exists($js_file . '.js.gz')) {
@@ -1924,12 +1908,12 @@ function _boost_copy_js_files($js) {
     }
     elseif (BOOST_GZIP && file_exists($js_file . '.js')) {
       $src = $js_file . '.js';
-      $dest = BOOST_PERM_GZIP_FILE_PATH . '/' . $js_file . '.js' . BOOST_PERM_CHAR . BOOST_JS_EXTENSION . BOOST_GZIP_EXTENSION;
+      $dest = BOOST_PERM_GZIP_FILE_PATH . '/' . $src . BOOST_PERM_CHAR . BOOST_JS_EXTENSION . BOOST_GZIP_EXTENSION;
       _boost_gz_copy_file($src, $dest);
     }
     if (file_exists($js_file . '.jsmin.js')) {
       $src = $js_file . '.jsmin.js';
-      $dest = BOOST_PERM_FILE_PATH . '/' . $js_file . '.jsmin.js' . BOOST_PERM_CHAR . BOOST_JS_EXTENSION;
+      $dest = BOOST_PERM_FILE_PATH . '/' . $src . BOOST_PERM_CHAR . BOOST_JS_EXTENSION;
       _boost_copy_file($src, $dest);
     }
     if (file_exists($js_file . '.jsmin.js.gz')) {
@@ -1939,7 +1923,7 @@ function _boost_copy_js_files($js) {
     }
     elseif (BOOST_GZIP && file_exists($js_file . '.jsmin.js')) {
       $src = $js_file . '.jsmin.js';
-      $dest = BOOST_PERM_GZIP_FILE_PATH . '/' . $js_file . '.jsmin.js' . BOOST_PERM_CHAR . BOOST_JS_EXTENSION . BOOST_GZIP_EXTENSION;
+      $dest = BOOST_PERM_GZIP_FILE_PATH . '/' . $src . BOOST_PERM_CHAR . BOOST_JS_EXTENSION . BOOST_GZIP_EXTENSION;
       _boost_gz_copy_file($src, $dest);
     }
   }
