Mostly moved from base template dir
[squirrelmail.git] / src / style.php
CommitLineData
d3c2ff0a 1<?php
2/**
3 * Style sheet script
5c4ff7bf 4 *
d3c2ff0a 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
94b68ceb 9 * <li>templatedir - string, sets template directory from templates/
d3c2ff0a 10 * <li>fontset - string, sets selected set of fonts from $fontsets array.
11 * <li>fontsize - integer, sets selected font size
fd7f21b6 12 * <li>dir - string, sets text direction variables. Possible values 'rtl' or 'ltr'
d3c2ff0a 13 * </ul>
47ccfad4 14 * @copyright &copy; 2005-2006 The SquirrelMail Project Team
d3c2ff0a 15 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
16 * @version $Id$
17 * @package squirrelmail
18 */
19
202bcbcc 20/**
21 * Set the location in order to skip unneeded validation and other includes
22 * in the SquirrelMail initialisation file.
23 */
24$sInitLocation = 'style';
d3c2ff0a 25
202bcbcc 26/**
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
d3c2ff0a 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 */
57if (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
5c4ff7bf 64/**
f549a706 65 * Get text direction
5c4ff7bf 66 */
f549a706 67if (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');
5c4ff7bf 72}
73
d3c2ff0a 74/**/
75$oTemplate->assign('color', $color);
76
77/**
78 * set color constants in order to use simple names instead of color array
5c4ff7bf 79 * 0 - SQM_TEXT_DISABLED, SQM_TITLE_BACKGROUND, SQM_BUTTON_BACKGROUND_DISABLED,
d3c2ff0a 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
5c4ff7bf 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,
d3c2ff0a 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 */
100define('SQM_BACKGROUND',$color[4]);
101define('SQM_BACKGROUND_LEFT',$color[3]);
102
103define('SQM_TEXT_STANDARD',$color[8]);
104define('SQM_TEXT_STANDARD_LEFT',$color[6]);
105define('SQM_TEXT_HIGHLIGHT',$color[15]);
106define('SQM_TEXT_DISABLED',$color[0]);
107define('SQM_TEXT_SPECIAL',$color[11]);
108
109define('SQM_LINK',$color[7]);
110define('SQM_LINK_LEFT',$color[6]);
111
112define('SQM_TITLE_BACKGROUND',$color[0]);
113define('SQM_TITLE_TEXT',$color[7]);
114
115define('SQM_BUTTON_BACKGROUND',$color[9]);
116define('SQM_BUTTON_TEXT',$color[8]);
117define('SQM_BUTTON_BACKGROUND_DISABLED',$color[0]);
118define('SQM_BUTTON_BACKGROUND_TEXT',$color[12]);
119
120define('SQM_BLOCK_BACKGROUND',$color[12]);
121define('SQM_BLOCK_TEXT',$color[8]);
122define('SQM_BLOCK_TITLE',$color[10]);
123define('SQM_BLOCK_TITLE_TEXT',$color[7]);
124
125define('SQM_ROW_BACKGROUND_1',$color[0]);
126define('SQM_ROW_BACKGROUND_2',$color[12]);
127define('SQM_ROW_TEXT_1',$color[8]);
128define('SQM_ROW_TEXT_2',$color[8]);
129define('SQM_ROW_BACKGROUND_HIGHLIGHT',$color[5]);
130define('SQM_ROW_TEXT_HIGHLIGHT',$color[8]);
131define('SQM_ROW_BACKGROUND_SELECTED',$color[16]);
132define('SQM_ROW_TEXT_SELECTED',$color[8]);
133
134define('SQM_COLUMN_HEADER_BACKGROUND',$color[5]);
135define('SQM_COLUMN_HEADER_TEXT',$color[8]);
136
137define('SQM_MESSAGE_QUOTE_1',$color[13]);
138define('SQM_MESSAGE_QUOTE_2',$color[14]);
139
140define('SQM_ERROR_TEXT',$color[2]);
141
5c4ff7bf 142define('SQM_ALIGN_LEFT', $align['left']);
143define('SQM_ALIGN_RIGHT', $align['right']);
144
d3c2ff0a 145if (sqgetGlobalVar('fontset',$fontset,SQ_GET) &&
146 isset($fontsets[$fontset])) {
6309ffc2 147 $fontfamily=$fontsets[$fontset];
d3c2ff0a 148} else {
149 $fontfamily='';
150}
151$oTemplate->assign('fontfamily', $fontfamily);
152
153if (! sqgetGlobalVar('fontsize',$fontsize,SQ_GET)) {
154 $fontsize = 0;
155} else {
156 $fontsize = (int) $fontsize;
157}
158$oTemplate->assign('fontsize', $fontsize);
159
86921eda 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.
94b68ceb 170 * Possibly naive suggestion - template can define its own default
171 * template name
86921eda 172 *
173 * TODO: Fix this. :)
174 **/
d3c2ff0a 175header('Content-Type: text/css');
86921eda 176if ( $lastmod = @filemtime(getcwd() .'/'. $oTemplate->template_dir . 'stylesheet.tpl') ) {
00a68572 177 $gmlastmod = gmdate('D, d M Y H:i:s', $lastmod) . ' GMT';
86921eda 178 $expires = gmdate('D, d M Y H:i:s', strtotime('+1 week')) . ' GMT';
00a68572 179 header('Last-Modified: ' . $gmlastmod);
86921eda 180 header('Expires: '. $expires);
181 header('Pragma: ');
182 header('Cache-Control: public, must-revalidate');
00a68572 183}
d3c2ff0a 184$oTemplate->display('stylesheet.tpl');
185
3cecf1cd 186/**
187 * Include any additional stylesheets provided by the template
188 */
189$template_css = $oTemplate->getAdditionalStyleSheets();
190foreach ($template_css as $stylesheet) {
191 $oTemplate->display($stylesheet);
192}