_color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style)
Rewrites the stylesheet to match the colors in the palette.
File
- core/modules/color/color.module, line 512
- Allows users to change the color scheme of themes.
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | function _color_rewrite_stylesheet( $theme , & $info , & $paths , $palette , $style ) { // Prepare color conversion table. $conversion = $palette ; foreach ( $conversion as $k => $v ) { $conversion [ $k ] = Unicode:: strtolower ( $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 = Unicode:: 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. elseif (preg_match( '/(?<!-)color[^{:]*:[^{#]*$/i' , $chunk )) { $base = 'text' ; } // Reset back to base. 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 ; } |
Please login to continue.