Fix session autostart code - session_name() return value does not indicate session...
[squirrelmail.git] / src / style.php
CommitLineData
d3c2ff0a 1<?php
3e6ee6ca 2
d3c2ff0a 3/**
4 * Style sheet script
5c4ff7bf 5 *
3e6ee6ca 6 * Script processes GET arguments and generates CSS output from stylesheet.tpl,
7 * which is defined in each template set.
8 *
d3c2ff0a 9 * Used GET arguments:
10 * <ul>
11 * <li>themeid - string, sets theme file from themes/*.php
3e6ee6ca 12 * <li>templateid - string, sets template set ID
d3c2ff0a 13 * <li>fontset - string, sets selected set of fonts from $fontsets array.
14 * <li>fontsize - integer, sets selected font size
fd7f21b6 15 * <li>dir - string, sets text direction variables. Possible values 'rtl' or 'ltr'
d3c2ff0a 16 * </ul>
4b5049de 17 * @copyright &copy; 2005-2007 The SquirrelMail Project Team
d3c2ff0a 18 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
19 * @version $Id$
20 * @package squirrelmail
21 */
22
ebd2391c 23/** This is the style page */
24define('PAGE_NAME', 'style');
25
202bcbcc 26/**
202bcbcc 27 * Include the SquirrelMail initialization file.
28 */
29require('../include/init.php');
d3c2ff0a 30
2cc2227d 31/* safety check for older config.php */
32if (!isset($fontsets) || !is_array($fontsets)) {
33 $fontsets=array();
34}
d3c2ff0a 35
f46db954 36
37/**
10c46cec 38 * The following code should no longer be neccesary, but it will remain for the
f46db954 39 * time being, just in case.
10c46cec 40 *
f46db954 41 * TODO: Remove if no longer needed.
42 **/
d3c2ff0a 43/* set default colors in case color theme is not full */
44$color = array();
45$color[0] = '#dcdcdc'; // (light gray) TitleBar
46$color[1] = '#800000'; // (red)
47$color[2] = '#cc0000'; // (light red) Warning/Error Messages
48$color[3] = '#a0b8c8'; // (green-blue) Left Bar Background
49$color[4] = '#ffffff'; // (white) Normal Background
50$color[5] = '#ffffcc'; // (light yellow) Table Headers
51$color[6] = '#000000'; // (black) Text on left bar
52$color[7] = '#0000cc'; // (blue) Links
53$color[8] = '#000000'; // (black) Normal text
54$color[9] = '#ababab'; // (mid-gray) Darker version of #0
55$color[10] = '#666666'; // (dark gray) Darker version of #9
56$color[11] = '#770000'; // (dark red) Special Folders color
57$color[12] = '#ededed'; // (light gray) Alternate color for message list
58$color[13] = '#800000'; // (dark red) Color for quoted text -- > 1 quote
59$color[14] = '#ff0000'; // (red) Color for quoted text -- >> 2 or more
60$color[15] = '#002266'; // (dark blue) Unselectable folders
61$color[16] = '#ff9933'; // (orange) Highlight color
62
d3c2ff0a 63/**
64 * set color constants in order to use simple names instead of color array
5c4ff7bf 65 * 0 - SQM_TEXT_DISABLED, SQM_TITLE_BACKGROUND, SQM_BUTTON_BACKGROUND_DISABLED,
d3c2ff0a 66 * SQM_ROW_BACKGROUND_1
67 * 1 -
68 * 2 - SQM_ERROR_TEXT
69 * 3 - SQM_BACKGROUND_LEFT
70 * 4 - SQM_BACKGROUND
71 * 5 - SQM_ROW_BACKGROUND_HIGHLIGHT, SQM_COLUMN_HEADER_BACKGROUND
72 * 6 - SQM_TEXT_STANDARD_LEFT
73 * 7 - SQM_TITLE_TEXT, SQM_BLOCK_TITLE_TEXT
5c4ff7bf 74 * 8 - SQM_TEXT_STANDARD, SQM_BUTTON_TEXT, SQM_BLOCK_TEXT, SQM_ROW_TEXT_1,
75 * SQM_ROW_TEXT_2, SQM_ROW_TEXT_HIGHLIGHT, SQM_ROW_TEXT_SELECTED,
d3c2ff0a 76 * SQM_COLUMN_HEADER_TEXT
77 * 9 - SQM_BUTTON_BACKGROUND
78 * 10 - SQM_BLOCK_TITLE
79 * 11 - SQM_TEXT_SPECIAL
80 * 12 - SQM_BUTTON_BACKGROUND_TEXT, SQM_BLOCK_BACKGROUND, SQM_ROW_BACKGROUND_2
81 * 13 - SQM_MESSAGE_QUOTE_1
82 * 14 - SQM_MESSAGE_QUOTE_2
83 * 15 - SQM_TEXT_HIGHLIGHT
84 * 16 - SQM_ROW_BACKGROUND_SELECTED
85 */
86define('SQM_BACKGROUND',$color[4]);
87define('SQM_BACKGROUND_LEFT',$color[3]);
88
89define('SQM_TEXT_STANDARD',$color[8]);
90define('SQM_TEXT_STANDARD_LEFT',$color[6]);
91define('SQM_TEXT_HIGHLIGHT',$color[15]);
92define('SQM_TEXT_DISABLED',$color[0]);
93define('SQM_TEXT_SPECIAL',$color[11]);
94
95define('SQM_LINK',$color[7]);
96define('SQM_LINK_LEFT',$color[6]);
97
98define('SQM_TITLE_BACKGROUND',$color[0]);
99define('SQM_TITLE_TEXT',$color[7]);
100
101define('SQM_BUTTON_BACKGROUND',$color[9]);
102define('SQM_BUTTON_TEXT',$color[8]);
103define('SQM_BUTTON_BACKGROUND_DISABLED',$color[0]);
104define('SQM_BUTTON_BACKGROUND_TEXT',$color[12]);
105
106define('SQM_BLOCK_BACKGROUND',$color[12]);
107define('SQM_BLOCK_TEXT',$color[8]);
108define('SQM_BLOCK_TITLE',$color[10]);
109define('SQM_BLOCK_TITLE_TEXT',$color[7]);
110
111define('SQM_ROW_BACKGROUND_1',$color[0]);
112define('SQM_ROW_BACKGROUND_2',$color[12]);
113define('SQM_ROW_TEXT_1',$color[8]);
114define('SQM_ROW_TEXT_2',$color[8]);
115define('SQM_ROW_BACKGROUND_HIGHLIGHT',$color[5]);
116define('SQM_ROW_TEXT_HIGHLIGHT',$color[8]);
117define('SQM_ROW_BACKGROUND_SELECTED',$color[16]);
118define('SQM_ROW_TEXT_SELECTED',$color[8]);
119
120define('SQM_COLUMN_HEADER_BACKGROUND',$color[5]);
121define('SQM_COLUMN_HEADER_TEXT',$color[8]);
122
123define('SQM_MESSAGE_QUOTE_1',$color[13]);
124define('SQM_MESSAGE_QUOTE_2',$color[14]);
125
126define('SQM_ERROR_TEXT',$color[2]);
127
5c4ff7bf 128define('SQM_ALIGN_LEFT', $align['left']);
129define('SQM_ALIGN_RIGHT', $align['right']);
130
f46db954 131// END TODO
132
d3c2ff0a 133if (sqgetGlobalVar('fontset',$fontset,SQ_GET) &&
134 isset($fontsets[$fontset])) {
6309ffc2 135 $fontfamily=$fontsets[$fontset];
d3c2ff0a 136} else {
137 $fontfamily='';
138}
d3c2ff0a 139
140if (! sqgetGlobalVar('fontsize',$fontsize,SQ_GET)) {
141 $fontsize = 0;
142} else {
143 $fontsize = (int) $fontsize;
144}
d3c2ff0a 145
10c46cec 146$oTemplate->header('Content-Type: text/css');
86921eda 147/**
148 * GOTCHA #1: When sending the headers for caching, we must send Expires,
149 * Last-Modified, Pragma, and Cache-Control headers. If we don't PHP
3e6ee6ca 150 * will makeup values that will break the cacheing.
86921eda 151 *
152 * GOTCHA #2: If the current template does not contain a template named
153 * stylesheet.tpl, this cacheing will break because filemtime() won't
154 * work. This is a problem e.g. with the default_advanced template
155 * that inherits CSS properties from the default template but
156 * doesn't contain stylesheet.tpl itself.
3e6ee6ca 157IDEA: 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!)
94b68ceb 158 * Possibly naive suggestion - template can define its own default
159 * template name
86921eda 160 *
3e6ee6ca 161 * GOTCHA #3: If the user changes user prefs for things like font size then
162 * the mtime should be updated to the time of that change, and not
163 * that of the stylesheet.tpl file. IDEA: can this be a value kept
164 * in user prefs (always compare to actual file mtime before sending
165 * to the browser)
166 *
f46db954 167 * Comment re gotcha #3: If we only define basic font prefs here, we really
168 * only need to refresh the cache if one of the font prefs changes.
169 * Possibly some type of "force nocache flag could be set if a font pref is
170 * changed?
10c46cec 171 *
172 * Response: Perhaps, if that can be implemented great, but I think the
173 * user prefs solution would definitely work: catch the font setting change
174 * in a custom save() routine from user prefs and away we go.
175 *
86921eda 176 * TODO: Fix this. :)
10c46cec 177 */
f46db954 178
3e6ee6ca 179if ( $lastmod = @filemtime(SM_PATH . $oTemplate->get_template_file_directory()
180 . 'css/stylesheet.tpl') ) {
00a68572 181 $gmlastmod = gmdate('D, d M Y H:i:s', $lastmod) . ' GMT';
86921eda 182 $expires = gmdate('D, d M Y H:i:s', strtotime('+1 week')) . ' GMT';
00a68572 183 header('Last-Modified: ' . $gmlastmod);
86921eda 184 header('Expires: '. $expires);
185 header('Pragma: ');
186 header('Cache-Control: public, must-revalidate');
00a68572 187}
10c46cec 188// Steve, why did you remove this? Is it irrelevant now? If so, let's
189// remove the rest of the references to it here (note that it is being
190// used above in the filetime() statement) and elsewhere
191// $oTemplate->display('css/stylesheet.tpl');
f46db954 192
193/**
10c46cec 194 * Additional styles are now handled by adding stylesheets to
195 * templates/<template>/css/, so here, we simply define some
196 * basic styles based on user prefs.
f46db954 197 */
198?>
199/* older css template */
200body, td, th, dd, dt, h1, h2, h3, h4, h5, h6, p, ol, ul, li {
201<?php
202if($fontfamily) echo ' font-family: '.$fontfamily.";\n";
203?>
204}
205body, small {
206<?php
207if($fontsize) echo ' font-size: '.($fontsize-2)."pt;\n";
208?>
209}
210td, th {
211<?php
212if($fontsize) echo ' font-size: '.$fontsize."pt;\n";
213?>
214}
215textarea, pre {
216font-family: monospace;
217<?php
218if($fontsize) echo ' font-size: '.($fontsize-1)."pt;\n";
219?>
220}
d3c2ff0a 221