Add support for user-provided alternate stylesheets
[squirrelmail.git] / functions / page_header.php
1 <?php
2
3 /**
4 * page_header.php
5 *
6 * Prints the page header (duh)
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** Include required files from SM */
15 include_once(SM_PATH . 'functions/imap_mailbox.php');
16
17 /**
18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
20 *
21 * Since 1.5.1 function sends http headers. Function should be called
22 * before any output is started.
23 * @param string title the page title, default SquirrelMail.
24 * @param string xtra extra HTML to insert into the header
25 * @param bool do_hook whether to execute hooks, default true
26 * @param bool frames generate html frameset doctype (since 1.5.1)
27 * @return void
28 */
29 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
30 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
31
32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
33 global $base_uri;
34 }
35 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
37
38 /* add no cache headers here */
39 //FIXME: should change all header() calls in SM core to use $oTemplate->header()!!
40 $oTemplate->header('Pragma: no-cache'); // http 1.0 (rfc1945)
41 $oTemplate->header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
42
43 $oTemplate->assign('frames', $frames);
44 $oTemplate->assign('lang', $squirrelmail_language);
45
46 $header_tags = '';
47
48 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
49
50 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
51 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
52 $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
53
54 /**
55 * Stylesheets are loaded in the following order:
56 * 1) All stylesheets provided by the template. Normally, these are
57 * stylsheets in $sTplDir/css/. This is accomplished by calling
58 * $oTemplate->fetch_standard_stylesheet_links().
59 * 2) An optional user-defined stylesheet. This is set in the Display
60 * Preferences.
61 * 3) src/style.php which sets some basic font prefs.
62 * 4) If we are dealing with an RTL language, we load rtl.css from the
63 * template set.
64 **/
65
66 // 1. Stylesheets from the template.
67 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
68
69 $aUserStyles = array();
70 // 2. Option user-defined stylesheet from preferences.
71 // FIXME: the following user pref ("sUserStyle"; rename as necessary) will have to be populated by the display prefs screen from a widget similar to the color themes widget (which it replaces) where its values should be full relative paths (from SM_PATH) to the selected css "themes" (either in template css/alternates dir or SM_PATH/css/alternates dir)
72 // FIXME: uhhh, getPref() is not available yet here. (at least on login page) Ugh. Nor has load_prefs been included yet -- how do we fix this?
73 // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
74 if (!empty($chosen_theme) && substr($chosen_theme, 0, 2) == 'u_') {
75 $aUserStyles[] = substr($chosen_theme, 2) .'default.css';
76 }
77
78 // 3. src/style.php
79 $aUserStyles[] = $base_uri .'src/style.php?'
80 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
81 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
82 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
83
84 // 4. Optional rtl.css stylesheet
85 if ($text_direction == 'rtl') {
86 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
87 }
88
89 if ($squirrelmail_language == 'ja_JP') {
90 /*
91 * force correct detection of charset, when browser does not follow
92 * http content-type and tries to detect charset from page content.
93 * Shooting of browser's creator can't be implemented in php.
94 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
95 * recommendations and switch to unicode.
96 */
97 $header_tags .= "<!-- \xfd\xfe -->\n";
98 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
99 }
100 if ($do_hook) {
101 // NOTE! plugins here must assign output to template
102 // and NOT echo anything directly!!
103 do_hook('generic_header');
104 }
105
106 $header_tags .= $xtra;
107 $oTemplate->assign('page_title', $title);
108
109 /* work around IE6's scrollbar bug */
110 $header_tags .= <<<EOS
111 <!--[if IE 6]>
112 <style type="text/css">
113 /* avoid stupid IE6 bug with frames and scrollbars */
114 body {
115 width: expression(document.documentElement.clientWidth - 30);
116 }
117 </style>
118 <![endif]-->
119
120 EOS;
121
122 $oTemplate->assign('header_tags', $header_tags);
123 $oTemplate->display('protocol_header.tpl');
124
125 /* this is used to check elsewhere whether we should call this function */
126 $pageheader_sent = TRUE;
127 if (isset($oErrorHandler)) {
128 $oErrorHandler->HeaderSent();
129 }
130
131 }
132
133 /**
134 * Given a path to a SquirrelMail file, return a HTML link to it
135 *
136 * @param string path the SquirrelMail file to link to
137 * @param string text the link text
138 * @param string target the target frame for this link
139 */
140 function makeInternalLink($path, $text, $target='') {
141 global $base_uri;
142 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
143 if ($target != '') {
144 $target = " target=\"$target\"";
145 }
146
147 // This is an inefficient hook and is only used by
148 // one plugin that still needs to patch this code,
149 // plus if we are templat-izing SM, visual hooks
150 // are not needed. However, I am leaving the code
151 // here just in case we find a good (non-visual?)
152 // use for the internal_link hook.
153 //
154 //$hooktext = do_hook_function('internal_link',$text);
155 //if ($hooktext != '')
156 // $text = $hooktext;
157
158 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
159 }
160
161 /**
162 * Same as makeInternalLink, but echoes it too
163 */
164 function displayInternalLink($path, $text, $target='') {
165 // FIXME: should let the template echo all these kinds of things
166 echo makeInternalLink($path, $text, $target);
167 }
168
169 /**
170 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
171 * including the default menu bar. Uses displayHtmlHeader and takes
172 * JavaScript and locale settings into account.
173 *
174 * @param array color the array of theme colors
175 * @param string mailbox the current mailbox name to display
176 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
177 * @param string sBodyTagJs js events to be inserted in the body tag
178 * @return void
179 */
180
181 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
182
183 global $reply_focus, $hide_sm_attributions, $frame_top,
184 $provider_name, $provider_uri, $startMessage,
185 $javascript_on, $action, $oTemplate;
186
187 if (empty($sBodyTagJs)) {
188 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
189 if ($reply_focus == 'select')
190 $sBodyTagJs = 'onload="checkForm(\'select\');"';
191 else if ($reply_focus == 'focus')
192 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
193 else if ($reply_focus != 'none')
194 $sBodyTagJs = 'onload="checkForm();"';
195 }
196 else
197 $sBodyTagJs = 'onload="checkForm();"';
198 }
199
200 $urlMailbox = urlencode($mailbox);
201 $startMessage = (int)$startMessage;
202
203 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
204
205 if (!isset($frame_top)) {
206 $frame_top = '_top';
207 }
208
209 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
210 $js_includes = $oTemplate->get_javascript_includes(TRUE);
211 $sJsBlock = '';
212 foreach ($js_includes as $js_file) {
213 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
214 }
215 if ($sHeaderJs) {
216 $sJsBlock .= "\n<script type=\"text/javascript\">" .
217 "\n<!--\n" .
218 $sHeaderJs . "\n\n// -->\n</script>\n";
219 }
220 displayHtmlHeader ('SquirrelMail', $sJsBlock);
221 } else {
222 /* do not use JavaScript */
223 displayHtmlHeader ('SquirrelMail');
224 $sBodyTagJs = '';
225 }
226 /*
227 * this explains the imap_mailbox.php dependency. We should instead store
228 * the selected mailbox in the session and fallback to the session var.
229 */
230 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
231 readShortMailboxName($mailbox, $delimiter)));
232 if ( $shortBoxName == 'INBOX' ) {
233 $shortBoxName = _("INBOX");
234 }
235
236 $sm_attributes = '';
237 if (!$hide_sm_attributions) {
238 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
239 if (empty($provider_uri)) {
240 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
241 } else {
242 if (empty($provider_name)) $provider_name= 'SquirrelMail';
243 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
244 }
245 $sm_attributes .= " </td>\n";
246 }
247
248 $oTemplate->assign('body_tag_js', $sBodyTagJs);
249 $oTemplate->assign('shortBoxName', $shortBoxName);
250 $oTemplate->assign('sm_attribute_str', $sm_attributes);
251 $oTemplate->assign('frame_top', $frame_top);
252 $oTemplate->assign('urlMailbox', $urlMailbox);
253 $oTemplate->assign('startMessage', $startMessage);
254 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
255 $oTemplate->display('page_header.tpl');
256 }
257
258 /**
259 * Blatantly copied/truncated/modified from displayPageHeader.
260 * Outputs a page header specifically for the compose_in_new popup window
261 *
262 * @param array color the array of theme colors
263 * @param string mailbox the current mailbox name to display
264 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
265 * @param string sBodyTagJs js events to be inserted in the body tag
266 * @return void
267 */
268 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
269
270 global $reply_focus, $javascript_on, $action, $oTemplate;
271
272 if (empty($sBodyTagJs)) {
273 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
274 if ($reply_focus == 'select')
275 $sBodyTagJs = 'onload="checkForm(\'select\');"';
276 else if ($reply_focus == 'focus')
277 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
278 else if ($reply_focus != 'none')
279 $sBodyTagJs = 'onload="checkForm();"';
280 }
281 else
282 $sBodyTagJs = 'onload="checkForm();"';
283 }
284
285
286 /*
287 * Locate the first displayable form element (only when JavaScript on)
288 */
289 if($javascript_on) {
290 if ($sHeaderJs) {
291 $sJsBlock = "\n<script type=\"text/javascript\">" .
292 "\n<!--\n" .
293 $sHeaderJs . "\n\n// -->\n</script>\n";
294 } else {
295 $sJsBlock = '';
296 }
297 $sJsBlock .= "\n";
298
299 $js_includes = $oTemplate->get_javascript_includes(TRUE);
300 foreach ($js_includes as $js_file) {
301 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
302 }
303
304 displayHtmlHeader (_("Compose"), $sJsBlock);
305 } else {
306 /* javascript off */
307 displayHtmlHeader(_("Compose"));
308 $onload = '';
309 }
310 // FIXME: should let the template echo all these kinds of things
311 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
312 }