function advagg_build_css_bundle in Advanced CSS/JS Aggregation 7
Same name and namespace in other branches
- 6 advagg.module \advagg_build_css_bundle()
Given a list of files, grab their contents and glue it into one big string.
Parameters
$files: array of filenames.
Return value
string containing all the files.
2 calls to advagg_build_css_bundle()
- advagg_css_js_file_builder in ./
advagg.module - Aggregate CSS/JS files, putting them in the files directory.
- _advagg_drupal_load_stylesheet in ./
advagg.module - Loads stylesheets recursively and returns contents with corrected paths.
File
- ./
advagg.module, line 2371 - Advanced CSS/JS aggregation module
Code
function advagg_build_css_bundle($files) {
$data = '';
// Build aggregate CSS file.
foreach ($files as $file) {
$contents = drupal_load_stylesheet($file, TRUE);
// Return the path to where this CSS file originated from.
$base = base_path() . dirname($file) . '/';
_drupal_build_css_path(NULL, $base);
// Prefix all paths within this CSS file, ignoring external and absolute paths.
$data .= preg_replace_callback('/url\\([\'"]?(?![a-z]+:|\\/+)([^\'")]+)[\'"]?\\)/i', '_drupal_build_css_path', $contents);
}
// Per the W3C specification at http://www.w3.org/TR/REC-CSS2/cascade.html#at-import,
// @import rules must proceed any other style, so we move those to the top.
$regexp = '/@import[^;]+;/i';
preg_match_all($regexp, $data, $matches);
$data = preg_replace($regexp, '', $data);
$data = implode('', $matches[0]) . $data;
return $data;
}