function _color_rewrite_stylesheet
Same name in other branches
- 7.x modules/color/color.module \_color_rewrite_stylesheet()
- 9 core/modules/color/color.module \_color_rewrite_stylesheet()
Rewrites the stylesheet to match the colors in the palette.
1 call to _color_rewrite_stylesheet()
- color_scheme_form_submit in core/
modules/ color/ color.module - Form submission handler for color_scheme_form().
File
-
core/
modules/ color/ color.module, line 521
Code
function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) {
// Prepare color conversion table.
$conversion = $palette;
foreach ($conversion as $k => $v) {
$v = mb_strtolower($v);
$conversion[$k] = Color::normalizeHexLength($v);
}
$default = color_get_palette($theme, TRUE);
// Split off the "Don't touch" section of the stylesheet.
$split = "Color Module: Don't touch";
if (strpos($style, $split) !== FALSE) {
list($style, $fixed) = explode($split, $style);
}
// 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 the parts.
foreach ($style as $chunk) {
if ($is_color) {
$chunk = mb_strtolower($chunk);
$chunk = Color::normalizeHexLength($chunk);
// Check if this is one of the colors in the default palette.
if ($key = array_search($chunk, $default)) {
$chunk = $conversion[$key];
}
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';
}
elseif (preg_match('/(?<!-)color[^{:]*:[^{#]*$/i', $chunk)) {
$base = 'text';
}
else {
$base = 'base';
}
}
$output .= $chunk;
$is_color = !$is_color;
}
// Append fixed colors segment.
if (isset($fixed)) {
$output .= $fixed;
}
// Replace paths to images.
foreach ($paths['map'] as $before => $after) {
$before = base_path() . $paths['source'] . $before;
$before = preg_replace('`(^|/)(?!../)([^/]+)/../`', '$1', $before);
$output = str_replace($before, $after, $output);
}
return $output;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.