Variable name is misleading, if technically correct. I'd personally eventually like...
[squirrelmail.git] / src / style.php
1 <?php
2 /**
3 * Style sheet script
4 *
5 * Script processes GET arguments and generates CSS output from stylesheet.tpl.
6 * Used GET arguments:
7 * <ul>
8 * <li>themeid - string, sets theme file from themes/*.php
9 * <li>templatedir - string, sets template directory from templates/
10 * <li>fontset - string, sets selected set of fonts from $fontsets array.
11 * <li>fontsize - integer, sets selected font size
12 * <li>dir - string, sets text direction variables. Possible values 'rtl' or 'ltr'
13 * </ul>
14 * @copyright &copy; 2005-2006 The SquirrelMail Project Team
15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
16 * @version $Id$
17 * @package squirrelmail
18 */
19
20 /**
21 * Set the location in order to skip unneeded validation and other includes
22 * in the SquirrelMail initialisation file.
23 */
24 $sInitLocation = 'style';
25
26 /**
27 * Include the SquirrelMail initialization file.
28 */
29 require('../include/init.php');
30
31 /* safety check for older config.php */
32 if (!isset($fontsets) || !is_array($fontsets)) {
33 $fontsets=array();
34 }
35
36 /* set default colors in case color theme is not full */
37 $color = array();
38 $color[0] = '#dcdcdc'; // (light gray) TitleBar
39 $color[1] = '#800000'; // (red)
40 $color[2] = '#cc0000'; // (light red) Warning/Error Messages
41 $color[3] = '#a0b8c8'; // (green-blue) Left Bar Background
42 $color[4] = '#ffffff'; // (white) Normal Background
43 $color[5] = '#ffffcc'; // (light yellow) Table Headers
44 $color[6] = '#000000'; // (black) Text on left bar
45 $color[7] = '#0000cc'; // (blue) Links
46 $color[8] = '#000000'; // (black) Normal text
47 $color[9] = '#ababab'; // (mid-gray) Darker version of #0
48 $color[10] = '#666666'; // (dark gray) Darker version of #9
49 $color[11] = '#770000'; // (dark red) Special Folders color
50 $color[12] = '#ededed'; // (light gray) Alternate color for message list
51 $color[13] = '#800000'; // (dark red) Color for quoted text -- > 1 quote
52 $color[14] = '#ff0000'; // (red) Color for quoted text -- >> 2 or more
53 $color[15] = '#002266'; // (dark blue) Unselectable folders
54 $color[16] = '#ff9933'; // (orange) Highlight color
55
56 /** get theme from GET */
57 if (sqgetGlobalVar('themeid',$themeid,SQ_GET) &&
58 file_exists(SM_PATH . 'themes/'.basename($themeid,'.php').'.php')) {
59 include_once(SM_PATH . 'themes/'.basename($themeid,'.php').'.php');
60 } elseif (file_exists($theme[$theme_default]['PATH'])) {
61 include_once($theme[$theme_default]['PATH']);
62 }
63
64 /**
65 * Get text direction
66 */
67 if (sqgetGlobalVar('dir',$text_direction,SQ_GET) &&
68 $text_direction == 'rtl') {
69 $align = array('left' => 'right', 'right' => 'left');
70 } else {
71 $align = array('left' => 'left', 'right' => 'right');
72 }
73
74 /**/
75 $oTemplate->assign('color', $color);
76
77 /**
78 * set color constants in order to use simple names instead of color array
79 * 0 - SQM_TEXT_DISABLED, SQM_TITLE_BACKGROUND, SQM_BUTTON_BACKGROUND_DISABLED,
80 * SQM_ROW_BACKGROUND_1
81 * 1 -
82 * 2 - SQM_ERROR_TEXT
83 * 3 - SQM_BACKGROUND_LEFT
84 * 4 - SQM_BACKGROUND
85 * 5 - SQM_ROW_BACKGROUND_HIGHLIGHT, SQM_COLUMN_HEADER_BACKGROUND
86 * 6 - SQM_TEXT_STANDARD_LEFT
87 * 7 - SQM_TITLE_TEXT, SQM_BLOCK_TITLE_TEXT
88 * 8 - SQM_TEXT_STANDARD, SQM_BUTTON_TEXT, SQM_BLOCK_TEXT, SQM_ROW_TEXT_1,
89 * SQM_ROW_TEXT_2, SQM_ROW_TEXT_HIGHLIGHT, SQM_ROW_TEXT_SELECTED,
90 * SQM_COLUMN_HEADER_TEXT
91 * 9 - SQM_BUTTON_BACKGROUND
92 * 10 - SQM_BLOCK_TITLE
93 * 11 - SQM_TEXT_SPECIAL
94 * 12 - SQM_BUTTON_BACKGROUND_TEXT, SQM_BLOCK_BACKGROUND, SQM_ROW_BACKGROUND_2
95 * 13 - SQM_MESSAGE_QUOTE_1
96 * 14 - SQM_MESSAGE_QUOTE_2
97 * 15 - SQM_TEXT_HIGHLIGHT
98 * 16 - SQM_ROW_BACKGROUND_SELECTED
99 */
100 define('SQM_BACKGROUND',$color[4]);
101 define('SQM_BACKGROUND_LEFT',$color[3]);
102
103 define('SQM_TEXT_STANDARD',$color[8]);
104 define('SQM_TEXT_STANDARD_LEFT',$color[6]);
105 define('SQM_TEXT_HIGHLIGHT',$color[15]);
106 define('SQM_TEXT_DISABLED',$color[0]);
107 define('SQM_TEXT_SPECIAL',$color[11]);
108
109 define('SQM_LINK',$color[7]);
110 define('SQM_LINK_LEFT',$color[6]);
111
112 define('SQM_TITLE_BACKGROUND',$color[0]);
113 define('SQM_TITLE_TEXT',$color[7]);
114
115 define('SQM_BUTTON_BACKGROUND',$color[9]);
116 define('SQM_BUTTON_TEXT',$color[8]);
117 define('SQM_BUTTON_BACKGROUND_DISABLED',$color[0]);
118 define('SQM_BUTTON_BACKGROUND_TEXT',$color[12]);
119
120 define('SQM_BLOCK_BACKGROUND',$color[12]);
121 define('SQM_BLOCK_TEXT',$color[8]);
122 define('SQM_BLOCK_TITLE',$color[10]);
123 define('SQM_BLOCK_TITLE_TEXT',$color[7]);
124
125 define('SQM_ROW_BACKGROUND_1',$color[0]);
126 define('SQM_ROW_BACKGROUND_2',$color[12]);
127 define('SQM_ROW_TEXT_1',$color[8]);
128 define('SQM_ROW_TEXT_2',$color[8]);
129 define('SQM_ROW_BACKGROUND_HIGHLIGHT',$color[5]);
130 define('SQM_ROW_TEXT_HIGHLIGHT',$color[8]);
131 define('SQM_ROW_BACKGROUND_SELECTED',$color[16]);
132 define('SQM_ROW_TEXT_SELECTED',$color[8]);
133
134 define('SQM_COLUMN_HEADER_BACKGROUND',$color[5]);
135 define('SQM_COLUMN_HEADER_TEXT',$color[8]);
136
137 define('SQM_MESSAGE_QUOTE_1',$color[13]);
138 define('SQM_MESSAGE_QUOTE_2',$color[14]);
139
140 define('SQM_ERROR_TEXT',$color[2]);
141
142 define('SQM_ALIGN_LEFT', $align['left']);
143 define('SQM_ALIGN_RIGHT', $align['right']);
144
145 if (sqgetGlobalVar('fontset',$fontset,SQ_GET) &&
146 isset($fontsets[$fontset])) {
147 $fontfamily=$fontsets[$fontset];
148 } else {
149 $fontfamily='';
150 }
151 $oTemplate->assign('fontfamily', $fontfamily);
152
153 if (! sqgetGlobalVar('fontsize',$fontsize,SQ_GET)) {
154 $fontsize = 0;
155 } else {
156 $fontsize = (int) $fontsize;
157 }
158 $oTemplate->assign('fontsize', $fontsize);
159
160 /**
161 * GOTCHA #1: When sending the headers for caching, we must send Expires,
162 * Last-Modified, Pragma, and Cache-Control headers. If we don't PHP
163 * weill makeup values that will break the cacheing.
164 *
165 * GOTCHA #2: If the current template does not contain a template named
166 * stylesheet.tpl, this cacheing will break because filemtime() won't
167 * work. This is a problem e.g. with the default_advanced template
168 * that inherits CSS properties from the default template but
169 * doesn't contain stylesheet.tpl itself.
170 * Possibly naive suggestion - template can define its own default
171 * template name
172 *
173 * TODO: Fix this. :)
174 **/
175 header('Content-Type: text/css');
176 if ( $lastmod = @filemtime(getcwd() .'/'. $oTemplate->template_dir . 'stylesheet.tpl') ) {
177 $gmlastmod = gmdate('D, d M Y H:i:s', $lastmod) . ' GMT';
178 $expires = gmdate('D, d M Y H:i:s', strtotime('+1 week')) . ' GMT';
179 header('Last-Modified: ' . $gmlastmod);
180 header('Expires: '. $expires);
181 header('Pragma: ');
182 header('Cache-Control: public, must-revalidate');
183 }
184 $oTemplate->display('stylesheet.tpl');
185
186 /**
187 * Include any additional stylesheets provided by the template
188 */
189 $template_css = $oTemplate->getAdditionalStyleSheets();
190 foreach ($template_css as $stylesheet) {
191 $oTemplate->display($stylesheet);
192 }