| 1 |
<?php
|
| 2 |
// $Id: color.stylesheet.inc,v 1.5.2.3 2008/08/20 16:45:41 skiquel Exp $
|
| 3 |
/**
|
| 4 |
* @file
|
| 5 |
* Stylesheet modification functions
|
| 6 |
*/
|
| 7 |
|
| 8 |
/**
|
| 9 |
* Rewrite the stylesheet to match the colors in the palette.
|
| 10 |
*
|
| 11 |
* @param $theme
|
| 12 |
* String of theme name
|
| 13 |
* @param &$info
|
| 14 |
* Reference array of theme info
|
| 15 |
* @param &$paths
|
| 16 |
* Reference array of file paths for CSS/image slices.
|
| 17 |
* @param $palette
|
| 18 |
* Array of hexes
|
| 19 |
* @param $style
|
| 20 |
* String of the stylesheet contents
|
| 21 |
*/
|
| 22 |
function _color_rewrite_stylesheet($theme, &$info, &$paths, $palette, $style) {
|
| 23 |
module_load_include('module', 'color', 'color');
|
| 24 |
module_load_include('inc', 'color', 'color.database');
|
| 25 |
module_load_include('inc', 'color', 'color.misc');
|
| 26 |
|
| 27 |
$info = color_get_theme_info($theme, "sql");
|
| 28 |
|
| 29 |
// Split off the "Don't touch" section of the stylesheet.
|
| 30 |
$split = "Color Module: Don't touch";
|
| 31 |
if (strpos($style, $split) !== FALSE) {
|
| 32 |
list($style, $fixed) = explode($split, $style);
|
| 33 |
}
|
| 34 |
|
| 35 |
foreach (array_keys($info['engine']) as $engine) {
|
| 36 |
module_load_include('inc', 'color', 'engines/' . $engine);
|
| 37 |
if (function_exists('_color_engine_' . $engine) == TRUE) {
|
| 38 |
$style = call_user_func('_color_engine_'.$engine, $style, $info, $palette, $info['engine'][$engine]);
|
| 39 |
}
|
| 40 |
}
|
| 41 |
/*
|
| 42 |
if (array_key_exists('shift', $info['engine']) !== FALSE) {
|
| 43 |
module_load_include('inc', 'color', 'engines/shift');
|
| 44 |
$style = _color_engine_shift($style, $info, $palette, $info['engine']['shift']);
|
| 45 |
}
|
| 46 |
|
| 47 |
if (array_key_exists('tag', $info['engine']) !== FALSE) {
|
| 48 |
module_load_include('inc', 'color', 'engines/tag');
|
| 49 |
$style = _color_engine_tag($style, $info, $palette, $info['engine']['tag']);
|
| 50 |
}
|
| 51 |
*/
|
| 52 |
// Append fixed colors segment.
|
| 53 |
if (isset($fixed)) {
|
| 54 |
$style .= $fixed;
|
| 55 |
}
|
| 56 |
|
| 57 |
// Replace paths to images.
|
| 58 |
foreach ($paths['map'] as $before => $after) {
|
| 59 |
$before = base_path() . $paths['source'] . $before;
|
| 60 |
$before = preg_replace('`(^|/)(?!../)([^/]+)/../`', '$1', $before);
|
| 61 |
$style = str_replace($before, $after, $style);
|
| 62 |
}
|
| 63 |
|
| 64 |
return $style;
|
| 65 |
}
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
/**
|
| 70 |
* Save the rewritten stylesheet to disk.
|
| 71 |
*/
|
| 72 |
function _color_save_stylesheet($file, $style, &$paths) {
|
| 73 |
// Write new stylesheet.
|
| 74 |
file_save_data($style, $file, FILE_EXISTS_REPLACE);
|
| 75 |
$paths['files'][] = $file;
|
| 76 |
|
| 77 |
// Set standard file permissions for webserver-generated files.
|
| 78 |
@chmod($file, 0664);
|
| 79 |
}
|