_color_rewrite_stylesheet
modules/color/color.module, строка 288
- Версии
- 5
_color_rewrite_stylesheet($theme, &$info, &$paths, $palette)
- 6
_color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style)
Rewrite the stylesheet to match the colors in the palette.
Код
<?php
function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette) {
// Load stylesheet
$style = file_get_contents($paths['source'] .'style.css');
// Prepare color conversion table
$conversion = $palette;
unset($conversion['base']);
foreach ($conversion as $k => $v) {
$conversion[$k] = drupal_strtolower($v);
}
$default = color_get_palette($theme, true);
// Split off the "Don't touch" section of the stylesheet.
list($style, $fixed) = explode("Color Module: Don't touch", $style);
// Look for @import commands and insert the referenced stylesheets.
$cwd = getcwd();
chdir(drupal_get_path('theme', $theme));
$style = preg_replace_callback('/@import\s*["\']([^"\']+)["\'];/', '_color_import_stylesheet', $style);
chdir($cwd);
// Find all colors in the stylesheet and the chunks in between.
$style = preg_split('/(#[0-9a-f]{6}|#[0-9a-f]{3})/i', $style, -1, PREG_SPLIT_DELIM_CAPTURE);
$is_color = false;
$output = '';
$base = 'base';
// Iterate over all parts
foreach ($style as $chunk) {
if ($is_color) {
$chunk = drupal_strtolower($chunk);
// Check if this is one of the colors in the default palette
if ($key = array_search($chunk, $default)) {
$chunk = $conversion[$key];
}
// Not a pre-set color. Extrapolate from the base.
else {
$chunk = _color_shift($palette[$base], $default[$base], $chunk, $info['blend_target']);
}
}
else {
// Determine the most suitable base color for the next color.
// 'a' declarations. Use link.
if (preg_match('@[^a-z0-9_-](a)[^a-z0-9_-][^/{]*{[^{]+$@i', $chunk)) {
$base = 'link';
}
// 'color:' styles. Use text.
else if (preg_match('/(?<!-)color[^{:]*:[^{#]*$/i', $chunk)) {
$base = 'text';
}
// Reset back to base.
else {
$base = 'base';
}
}
$output .= $chunk;
$is_color = !$is_color;
}
// Append fixed colors segment
$output .= $fixed;
// Replace paths to images
foreach ($paths['map'] as $before => $after) {
$output = str_replace($before, $after, $output);
}
// Write new stylesheet
$file = fopen($paths['stylesheet'], 'w+');
fwrite($file, $output);
fclose($file);
$paths['files'][] = $paths['stylesheet'];
// Set standard file permissions for webserver-generated files
@chmod($paths['stylesheet'], 0664);
}
?>
Войдите или зарегистрируйтесь, чтобы получить возможность отправлять комментарии