You are here

function boost_cache_css_js_files in Boost 6

Cache css and or js files.

Parse the html file so we get all css/js files. drupal_get_js/css isn't 100%.

Parameters

$buffer: String containing documents html.

1 call to boost_cache_css_js_files()
_boost_ob_handler in ./boost.module
PHP output buffering callback for static page caching.

File

./boost.module, line 4688
Provides static file caching for Drupal text output. Pages, Feeds, ect...

Code

function boost_cache_css_js_files($buffer) {
  if (BOOST_CACHE_CSS) {

    // Extract external css files from html document
    $css_files = explode('<link ', $buffer);
    array_shift($css_files);
    foreach ($css_files as $key => $value) {

      // Extract css filename
      list($temp) = explode('" />', $value);
      $temp = explode('href="', $temp);
      $temp = explode('//', array_pop($temp));
      $temp = explode(base_path(), array_pop($temp));
      array_shift($temp);
      list($temp) = explode('?', implode('/', $temp));
      list($css_files[$key]) = explode('"', $temp);
    }
    _boost_copy_css_files($css_files);
  }
  if (BOOST_CACHE_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
      list($temp) = explode('">', $value);
      $temp = explode('src="', $temp);
      $temp = explode('//', array_pop($temp));
      $temp = explode(base_path(), array_pop($temp));
      array_shift($temp);
      list($temp) = explode('?', implode('/', $temp));
      list($temp) = explode('"', $temp);
      list($js_files[$key]) = explode('type=', $temp);
    }
    _boost_copy_js_files(array_filter($js_files));
  }
  if (BOOST_CACHE_CSS || BOOST_CACHE_JS) {
    foreach (_boost_copy_file_get_domains(BOOST_PERM_FILE_PATH) as $dir) {
      _boost_write_file_chmod($dir . '/' . BOOST_ROOT_FILE, $dir);
    }
    foreach (_boost_copy_file_get_domains(BOOST_PERM_GZIP_FILE_PATH) as $dir) {
      _boost_write_file_chmod($dir . '/' . BOOST_ROOT_FILE, $dir);
    }
  }
}