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