summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Carper2009-09-06 08:02:42 (GMT)
committer Mike Carper2009-09-06 08:02:42 (GMT)
commit0cf73a611239d3a30c4c2806b4ead3332e73bd7a (patch)
tree9e1ae142034f7205fa17ac6a78eb7da695bb3be5
parentd46bc4f70a6085aba9bd8b01e8c99ca417924481 (diff)
#566808: Cleanup css/js code; smaller & more accurate.
-rw-r--r--boost.module82
1 files changed, 32 insertions, 50 deletions
diff --git a/boost.module b/boost.module
index b11c14f..d77104c 100644
--- a/boost.module
+++ b/boost.module
@@ -1751,23 +1751,22 @@ function boost_path_redirect_load($where = array(), $args = array(), $sort = arr
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,18 @@ 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)));
+
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 +1876,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 +1885,18 @@ function _boost_copy_css_files($css) {
/**
* Extract javascript filenames from html and copy them & their children.
*
- * @param $js
- * String containing all html javascript.
- */
-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);
- }
-
+ * @param $js_files
+ * Array containing all javascript filenames.
+ */
+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)));
+
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 +1906,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 +1921,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);
}
}