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