drupal_build_css_cache
includes/common.inc, строка 1631
- Версии
- 5 – 6
drupal_build_css_cache($types, $filename)
Объединяет и оптимизирует файлы CSS, размещая конечный файл в файловой директории.
Параметры
$types
Массив с типами CSS файлов (например screen, print) для объединения и сжатия в один файл.
$filename
Имя объединенного CSS файла.
Возвращаемое значение
Имя CSS файла.
Связанные темы
Код
<?php
function drupal_build_css_cache($types, $filename) {
$data = '';
// Create the css/ within the files folder.
$csspath = file_create_path('css');
file_check_directory($csspath, FILE_CREATE_DIRECTORY);
if (!file_exists($csspath .'/'. $filename)) {
// Build aggregate CSS file.
foreach ($types as $type) {
foreach ($type as $file => $cache) {
if ($cache) {
$contents = file_get_contents($file);
// Remove multiple charset declarations for standards compliance (and fixing Safari problems)
$contents = preg_replace('/^@charset\s+[\'"](\S*)\b[\'"];/i', '', $contents);
// Return the path to where this CSS file originated from, stripping off the name of the file at the end of the path.
$path = base_path() . substr($file, 0, strrpos($file, '/')) .'/';
// Wraps all @import arguments in url().
$contents = preg_replace('/@import\s+(?!url)[\'"]?(\S*)\b[\'"]?/i', '@import url("\1")', $contents);
// Fix all paths within this CSS file, ignoring absolute paths.
$data .= preg_replace('/url\(([\'"]?)(?![a-z]+:)/i', 'url(\1'. $path . '\2', $contents);
}
}
}
// @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;
// Perform some safe CSS optimizations.
$data = 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', $data);
// Create the CSS file.
file_save_data($data, $csspath .'/'. $filename, FILE_EXISTS_REPLACE);
}
return $csspath .'/'. $filename;
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии