drupal_load_stylesheet
includes/common.inc, строка 1955
- Версии
- 6
drupal_load_stylesheet($file, $optimize = NULL)
Loads the stylesheet and resolves all @import commands.
Loads a stylesheet and replaces @import commands with the contents of the imported file. Use this instead of file_get_contents when processing stylesheets.
The returned contents are compressed removing white space and comments only when CSS aggregation is enabled. This optimization will not apply for color.module enabled themes with CSS aggregation turned off.
Параметры
$file
Name of the stylesheet to be processed.
$optimize
Defines if CSS contents should be compressed or not.
Возвращаемое значение
Contents of the stylesheet including the imported stylesheets.
Код
<?php
function drupal_load_stylesheet($file, $optimize = NULL) {
static $_optimize;
// Store optimization parameter for preg_replace_callback with nested @import loops.
if (isset($optimize)) {
$_optimize = $optimize;
}
$contents = '';
if (file_exists($file)) {
// Load the local CSS stylesheet.
$contents = file_get_contents($file);
// Change to the current stylesheet's directory.
$cwd = getcwd();
chdir(dirname($file));
// 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);
// 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('<
\s*([@{}:;,]|\)\s|\s\()\s* | # Remove whitespace around separators, but keep space around parentheses.
/\*([^*\\\\]|\*(?!/))+\*/ | # Remove comments that are not CSS hacks.
[\n\r] # Remove line breaks.
>x', '\1', $contents);
}
// Change back directory.
chdir($cwd);
}
return $contents;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии