drupal_load_stylesheet_content
- Versions
- 7
drupal_load_stylesheet_content($contents, $optimize = FALSE)
Process the contents of a stylesheet for aggregation.
Parameters
$contents The contents of the stylesheet.
$optimize (optional) Boolean whether CSS contents should be minified. Defaults to FALSE.
Return value
Contents of the stylesheet including the imported stylesheets.
Code
includes/common.inc, line 3475
<?php
function drupal_load_stylesheet_content($contents, $optimize = FALSE) {
// Remove multiple charset declarations for standards compliance (and fixing Safari problems).
$contents = preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents);
if ($optimize) {
// Perform some safe CSS optimizations.
$contents = preg_replace('{
(?<=\\\\\*/)([^/\*]+/\*)([^\*/]+\*/) # Add a backslash also at the end ie-mac hack comment, so the next pass will not touch it.
# The added backshlash does not affect the effectiveness of the hack.
}x', '\1\\\\\2', $contents);
$contents = preg_replace('<
\s*([@{}:;,]|\)\s|\s\()\s* | # Remove whitespace around separators, but keep space around parentheses.
/\*[^*\\\\]*\*+([^/*][^*]*\*+)*/ | # Remove comments that are not CSS hacks.
>x', '\1', $contents);
}
// Replaces @import commands with the actual stylesheet content.
// This happens recursively but omits external files.
$contents = preg_replace_callback('/@import\s*(?:url\()?[\'"]?(?![a-z]+:)([^\'"\()]+)[\'"]?\)?;/', '_drupal_load_stylesheet', $contents);
return $contents;
}
?>Login or register to post comments 