MDL-15942 - separate data escaped for database entry from unescaped data
[moodle-linuxchix.git] / lib / cssconstants.php
blob6fbb0253eb0096b8b9b59e4b929446c2748d1884
1 <?php // $Id$
3 /******************************************************************************
5 Plug in constants/variables - See MDL-6798 for details
7 Information from Urs Hunkler:
10 More flexible themes with CSS constants: An option for Moodle retro themes and easy colour palette variants.
12 I adopted Shaun Inman's "CSS Server-side Constants" to Moodle: http://www.shauninman.com/post/heap/2005/08/09/css_constants
14 With setting "cssconstants" to true in "config.php" you activate the CSS constants. If "cssconstants" is missing or set to "false" the
15 replacement function is not used.
17 $THEME->cssconstants = true;
18 /// By setting this to true, you will be able to use CSS constants
21 The constant definitions are written into a separate CSS file named like "constants.css" and loaded first in config.php. You can use constants for any CSS properties. The constant definition looks like:
23 @server constants {
24 fontColor: #3a2830;
25 aLink: #116699;
26 aVisited: #AA2200;
27 aHover: #779911;
28 pageBackground: #FFFFFF;
29 backgroundColor: #EEEEEE;
30 backgroundSideblockHeader: #a8a4e9;
31 fontcolorSideblockHeader: #222222;
32 color1: #98818b;
33 color2: #bd807b;
34 color3: #f9d1d7;
35 color4: #e8d4d8;
40 The lines in the CSS files using CSS constants look like:
42 body {
43 font-size: 100%;
44 background-color: pageBackground;
45 color: fontColor;
46 font-family: 'Bitstream Vera Serif', georgia, times, serif;
47 margin: 0;
48 padding: 0;
50 div#page {
51 margin: 0 10px;
52 padding-top: 5px;
53 border-top-width: 10px;
54 border-top-style: solid;
55 border-top-color: color3;
57 div.clearer {
58 clear: both;
60 a:link {
61 color: aLink;
64 ******************************************************************************/
66 function replace_cssconstants($css) {
67 if (preg_match_all("/@server\s+(?:variables|constants)\s*\{\s*([^\}]+)\s*\}\s*/i",$css,$matches)) {
68 $variables = array();
69 foreach ($matches[0] as $key=>$server) {
70 $css = str_replace($server,'',$css);
71 preg_match_all("/([^:\}\s]+)\s*:\s*([^;\}]+);/",$matches[1][$key],$vars);
72 foreach ($vars[1] as $var=>$value) {
73 $variables[$value] = $vars[2][$var];
76 $css = str_replace(array_keys($variables),array_values($variables),$css);
78 return ($css);
81 // vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140: