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