git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14108...
[squirrelmail.git] / functions / page_header.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * page_header.php
5 *
35586184 6 * Prints the page header (duh)
7 *
ae5dddc0 8 * @copyright 1999-2011 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 10 * @version $Id$
d6c32258 11 * @package squirrelmail
35586184 12 */
13
d6c32258 14/** Include required files from SM */
202bcbcc 15include_once(SM_PATH . 'functions/imap_mailbox.php');
b68edc75 16
d6c32258 17/**
8b096f0a 18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
20 *
81132de8 21 * Since 1.5.1 function sends http headers. Function should be called
22 * before any output is started.
8b096f0a 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
62b9c984 26 * @param bool frames generate html frameset doctype (since 1.5.1)
03478654 27 * @param bool $browser_cache_ok When TRUE, it's OK to leave out the
28 * no-cache browser headers (OPTIONAL;
29 * default = FALSE, send no-cache headers)
8b096f0a 30 * @return void
d6c32258 31 */
03478654 32function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE, $browser_cache_ok=FALSE ) {
b8292491 33 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
692155b7 34
0365891c 35 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
0b97a708 36 global $base_uri;
37 }
ab034e59 38 global $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
acd7fdf2 39 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize,
40 $chosen_theme, $chosen_theme_path, $user_themes, $user_theme_default;
81132de8 41
03478654 42 // add no cache headers here
43 //
44 if (!$browser_cache_ok) {
b8292491 45//FIXME: should change all header() calls in SM core to use $oTemplate->header()!!
03478654 46 $oTemplate->header('Pragma: no-cache'); // http 1.0 (rfc1945)
47 $oTemplate->header('Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0'); // http 1.1 (rfc2616)
48 $oTemplate->header('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
49//TODO: is this needed? $oTemplate->header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
50 }
82d6de25 51 /* prevent information leakage about read emails by forbidding Firefox
52 * to do preemptive DNS requests for any links in the message body. */
53 $oTemplate->header('X-DNS-Prefetch-Control: off');
2c21ef20 54
1f2f93e6 55 // don't show version as a security measure
56 //$oTemplate->header('X-Powered-By: SquirrelMail/' . SM_VERSION, FALSE);
57 $oTemplate->header('X-Powered-By: SquirrelMail', FALSE);
58
b8292491 59 $oTemplate->assign('frames', $frames);
60 $oTemplate->assign('lang', $squirrelmail_language);
61
62 $header_tags = '';
63
b116fd78 64 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n";
2c21ef20 65
d88941c7 66 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
67 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
8757c848 68 $used_theme = !isset($chosen_theme) && $user_theme_default != 'none' && is_dir($chosen_theme) && is_readable($chosen_theme)? $user_themes[$user_theme_default]['PATH'].'/default.css' : $chosen_theme_path;
acd7fdf2 69
d6a6f46b 70 /**
71 * Stylesheets are loaded in the following order:
72 * 1) All stylesheets provided by the template. Normally, these are
e2048f8e 73 * stylsheets in templates/<template>/css/. This is accomplished by calling
d6a6f46b 74 * $oTemplate->fetch_standard_stylesheet_links().
75 * 2) An optional user-defined stylesheet. This is set in the Display
76 * Preferences.
77 * 3) src/style.php which sets some basic font prefs.
78 * 4) If we are dealing with an RTL language, we load rtl.css from the
79 * template set.
e2048f8e 80 */
81
d6a6f46b 82 // 1. Stylesheets from the template.
b8292491 83 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
d6a6f46b 84
b8292491 85 $aUserStyles = array();
e2048f8e 86
d6a6f46b 87 // 2. Option user-defined stylesheet from preferences.
cd81f956 88 if (!empty($used_theme) && $used_theme != 'none') {
83fc5c5e 89 /**
2d2acf5e 90 * All styles (except "none" - ugh) just point to a directory,
91 * so we need to include all .css files in that directory.
83fc5c5e 92 */
2d2acf5e 93//FIXME: rid ourselves of "none" strings! I didn't do it here because I think the problem is that the theme itself should never be "none" (? well, what else would it be? if "none" theme is actually OK, then is there a constant to use below in stead of a hard-coded string?)
94 $styles = $used_theme == 'none' ? array()
95 : list_files($used_theme, '.css');
8757c848 96 foreach ($styles as $sheet) {
97 $aUserStyles[] = $used_theme .'/'.$sheet;
f9376f0b 98 }
deb25c8f 99 }
d6a6f46b 100
101 // 3. src/style.php
102 $aUserStyles[] = $base_uri .'src/style.php?'
b8292491 103 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
d6a6f46b 104 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
f9376f0b 105
106 // 3.1. Load the stylesheets we have already
b8292491 107 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
6182ab4d 108
d6a6f46b 109 // 4. Optional rtl.css stylesheet
6182ab4d 110 if ($text_direction == 'rtl') {
111 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
112 }
62f7daa5 113
2ad37738 114 // 5. Printer friendly stylesheet
115 $header_tags .= create_css_link($base_uri . 'css/print.css', 'printerfriendly', false, 'print');
116
e842b215 117 if ($squirrelmail_language == 'ja_JP') {
683b7853 118 /*
cbd8c251 119 * force correct detection of charset, when browser does not follow
120 * http content-type and tries to detect charset from page content.
121 * Shooting of browser's creator can't be implemented in php.
122 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
123 * recommendations and switch to unicode.
124 */
b8292491 125 $header_tags .= "<!-- \xfd\xfe -->\n";
0d56053e 126 $header_tags .= '<meta http-equiv="Content-type" content="' . $oTemplate->get_content_type() . '; charset=euc-jp" />' . "\n";
e842b215 127 }
237470b4 128 if ($do_hook) {
ed1c151d 129 // NOTE! plugins here MUST assign output to template
130 // and NOT echo anything directly!! A common
131 // approach is if a plugin decides it needs to
132 // put something at page-top after the standard
133 // SM page header, to dynamically add itself to
134 // the page_header_bottom and/or compose_header_bottom
135 // hooks for the current page request. See
136 // the Sent Confirmation v1.7 or Restrict Senders v1.2
137 // plugins for examples of this approach.
ed1c151d 138 ob_start();
c0071a26 139 $temp = array(&$header_tags);
140 do_hook('generic_header', $temp);
ed1c151d 141 $output = ob_get_contents();
142 ob_end_clean();
143 // plugin authors can debug their errors with one of the following:
144 //sm_print_r($output);
145 //echo $output;
146 if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR);
237470b4 147 }
62f7daa5 148
b8292491 149 $header_tags .= $xtra;
150 $oTemplate->assign('page_title', $title);
5ca4b1ee 151
152 /* work around IE6's scrollbar bug */
b8292491 153 $header_tags .= <<<EOS
292a9c32 154<!--[if IE 6]>
5ca4b1ee 155<style type="text/css">
5fe8257d 156/* avoid stupid IE6 bug with frames and scrollbars */
157body {
5fe8257d 158 width: expression(document.documentElement.clientWidth - 30);
159}
5ca4b1ee 160</style>
292a9c32 161<![endif]-->
5ca4b1ee 162
b8292491 163EOS;
5ca4b1ee 164
4bf6fc19 165 $oTemplate->assign('header_tags', $header_tags);
b8292491 166 $oTemplate->display('protocol_header.tpl');
b6c283c4 167
168 /* this is used to check elsewhere whether we should call this function */
169 $pageheader_sent = TRUE;
81de00c0 170 if (isset($oErrorHandler)) {
e6c4caae 171 $oErrorHandler->HeaderSent();
81de00c0 172 }
b8292491 173
a07cd1a4 174}
175
8b096f0a 176/**
177 * Given a path to a SquirrelMail file, return a HTML link to it
178 *
e740a582 179 * @param string $path The SquirrelMail file to link to
180 * (should start with something like "src/..." or
181 * "functions/..." or "plugins/..." etc.)
182 * @param string $text The link text
183 * @param string $target The target frame for this link
184 * @param string $accesskey The access key to be used, if any
8b096f0a 185 */
c12535f6 186function makeInternalLink($path, $text, $target='', $accesskey='NONE') {
f7b996c3 187 global $base_uri, $oTemplate;
202bcbcc 188// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
4910106a 189
e50f5ac2 190 // This is an inefficient hook and is only used by
4910106a 191 // one plugin that still needs to patch this code,
e50f5ac2 192 // plus if we are templat-izing SM, visual hooks
193 // are not needed. However, I am leaving the code
194 // here just in case we find a good (non-visual?)
4910106a 195 // use for the internal_link hook.
196 //
d849b570 197 //do_hook('internal_link', $text);
4910106a 198
e740a582 199 return create_hyperlink($base_uri . $path, $text, $target,
200 '', '', '', '',
c12535f6 201 ($accesskey == 'NONE'
202 ? array()
203 : array('accesskey' => $accesskey)));
d62c4938 204}
205
8b096f0a 206/**
8b096f0a 207 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
208 * including the default menu bar. Uses displayHtmlHeader and takes
209 * JavaScript and locale settings into account.
210 *
211 * @param array color the array of theme colors
212 * @param string mailbox the current mailbox name to display
91c27aee 213 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
ca14ebb7 214 * @param string sOnload JavaScript code to be added inside the body's onload handler
215 * as of 1.5.2, this replaces $sBodyTagJs argument
8b096f0a 216 * @return void
217 */
ca14ebb7 218function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sOnload = '') {
10bf80c0 219
220 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 221 $provider_name, $provider_uri, $startMessage,
d8ca5ea3 222 $action, $oTemplate, $org_title, $base_uri,
223 $data_dir, $username;
10bf80c0 224
ca14ebb7 225 if (empty($sOnload)) {
10bf80c0 226 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
ca14ebb7 227 if ($reply_focus == 'select')
228 $sOnload = 'checkForm(\'select\');';
229 else if ($reply_focus == 'focus')
230 $sOnload = 'checkForm(\'focus\');';
231 else if ($reply_focus != 'none')
232 $sOnload = 'checkForm();';
10bf80c0 233 }
234 else
ca14ebb7 235 $sOnload = 'checkForm();';
10bf80c0 236 }
237
5fe8257d 238 $startMessage = (int)$startMessage;
239
0365891c 240 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 241
d03f3582 242 if (!isset($frame_top)) {
243 $frame_top = '_top';
244 }
715225af 245
ca14ebb7 246//FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary?? (that is, I think checkForJavascript() might already look for new_js_autodetect_results...(?))
83aff890 247 if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
b8292491 248 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 249 $sJsBlock = '';
250 foreach ($js_includes as $js_file) {
251 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
252 }
91c27aee 253 if ($sHeaderJs) {
2c92ea9d 254 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 255 "\n<!--\n" .
a3d59ec3 256 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 257 }
e9e5a322 258 displayHtmlHeader ($org_title, $sJsBlock);
5fe8257d 259 } else {
d62c4938 260 /* do not use JavaScript */
e9e5a322 261 displayHtmlHeader ($org_title);
ca14ebb7 262 $sOnload = '';
715225af 263 }
d8ca5ea3 264 if ($mailbox) {
265 /*
266 * this explains the imap_mailbox.php dependency. We should instead store
267 * the selected mailbox in the session and fallback to the session var.
268 */
269 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
270 readShortMailboxName($mailbox, $delimiter)));
271 if (getPref($data_dir, $username, 'translate_special_folders')) {
0038893a 272 global $sent_folder, $trash_folder, $draft_folder;
273 if ($mailbox == $sent_folder)
274 $shortBoxName = _("Sent");
275 else if ($mailbox == $trash_folder)
276 $shortBoxName = _("Trash");
277 else if ($mailbox == $sent_folder)
278 $shortBoxName = _("Drafts");
d8ca5ea3 279 }
280 $urlMailbox = urlencode($mailbox);
281 } else {
282 $shortBoxName = '';
283 $urlMailbox = '';
7da23762 284 }
0493ed11 285
5810acfa 286 $provider_link = '';
287 if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
288 $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
99ea51d3 289 }
5fe8257d 290
ca14ebb7 291 $oTemplate->assign('onload', $sOnload);
5fe8257d 292 $oTemplate->assign('shortBoxName', $shortBoxName);
4bf6fc19 293 $oTemplate->assign('provider_link', $provider_link);
5fe8257d 294 $oTemplate->assign('frame_top', $frame_top);
295 $oTemplate->assign('urlMailbox', $urlMailbox);
296 $oTemplate->assign('startMessage', $startMessage);
297 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
fbffe024 298
299 // access keys
300 //
301 global $accesskey_menubar_compose, $accesskey_menubar_addresses,
302 $accesskey_menubar_folders, $accesskey_menubar_options,
303 $accesskey_menubar_search, $accesskey_menubar_help,
304 $accesskey_menubar_signout;
305 $oTemplate->assign('accesskey_menubar_compose', $accesskey_menubar_compose);
306 $oTemplate->assign('accesskey_menubar_addresses', $accesskey_menubar_addresses);
307 $oTemplate->assign('accesskey_menubar_folders', $accesskey_menubar_folders);
308 $oTemplate->assign('accesskey_menubar_options', $accesskey_menubar_options);
309 $oTemplate->assign('accesskey_menubar_search', $accesskey_menubar_search);
310 $oTemplate->assign('accesskey_menubar_help', $accesskey_menubar_help);
311 $oTemplate->assign('accesskey_menubar_signout', $accesskey_menubar_signout);
312
5fe8257d 313 $oTemplate->display('page_header.tpl');
c5634692 314
315 global $null;
316 do_hook('page_header_bottom', $null);
a07cd1a4 317}
2ba13803 318
8b096f0a 319/**
320 * Blatantly copied/truncated/modified from displayPageHeader.
321 * Outputs a page header specifically for the compose_in_new popup window
322 *
323 * @param array color the array of theme colors
324 * @param string mailbox the current mailbox name to display
91c27aee 325 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
5bcce050 326 * @param string sOnload JavaScript code to be added inside the body's onload handler
327 * as of 1.5.2, this replaces $sBodyTagJs argument
8b096f0a 328 * @return void
329 */
5bcce050 330function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
10bf80c0 331
83aff890 332 global $reply_focus, $action, $oTemplate;
10bf80c0 333
5bcce050 334 if (empty($sOnload)) {
10bf80c0 335 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5bcce050 336 if ($reply_focus == 'select')
337 $sOnload = 'checkForm(\'select\');';
338 else if ($reply_focus == 'focus')
339 $sOnload = 'checkForm(\'focus\');';
340 else if ($reply_focus != 'none')
341 $sOnload = 'checkForm();';
10bf80c0 342 }
343 else
ca14ebb7 344 $sOnload = 'checkForm();';
10bf80c0 345 }
346
347
9c3e6cd4 348 /*
d62c4938 349 * Locate the first displayable form element (only when JavaScript on)
350 */
83aff890 351 if(checkForJavascript()) {
91c27aee 352 if ($sHeaderJs) {
2c92ea9d 353 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 354 "\n<!--\n" .
a3d59ec3 355 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 356 } else {
5fe8257d 357 $sJsBlock = '';
d62c4938 358 }
6373ad12 359 $sJsBlock .= "\n";
360
b8292491 361 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 362 foreach ($js_includes as $js_file) {
363 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
364 }
365
91c27aee 366 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 367 } else {
368 /* javascript off */
369 displayHtmlHeader(_("Compose"));
ca14ebb7 370 $sOnload = '';
9c3e6cd4 371 }
5bcce050 372
373// FIXME: change the colorization attributes below to a CSS class!
374 $class = '';
375 $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
376 'link' => $color[7], 'vlink' => $color[7],
377 'alink' => $color[7]);
ed1c151d 378
379 // this is template-safe (see create_body() function)
5bcce050 380 echo create_body($sOnload, $class, $aAttribs);
381
6f4b6b68 382 global $null;
383 do_hook('compose_header_bottom', $null);
9c3e6cd4 384}