list_files vomits over the non-existence of 'none'. The definition of $used_theme is
[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 *
4b5049de 8 * @copyright &copy; 1999-2007 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)
2c21ef20 43
b8292491 44 $oTemplate->assign('frames', $frames);
45 $oTemplate->assign('lang', $squirrelmail_language);
46
47 $header_tags = '';
48
b116fd78 49 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n";
2c21ef20 50
d88941c7 51 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
52 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
8757c848 53 $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 54
d6a6f46b 55 /**
56 * Stylesheets are loaded in the following order:
57 * 1) All stylesheets provided by the template. Normally, these are
e2048f8e 58 * stylsheets in templates/<template>/css/. This is accomplished by calling
d6a6f46b 59 * $oTemplate->fetch_standard_stylesheet_links().
60 * 2) An optional user-defined stylesheet. This is set in the Display
61 * Preferences.
62 * 3) src/style.php which sets some basic font prefs.
63 * 4) If we are dealing with an RTL language, we load rtl.css from the
64 * template set.
e2048f8e 65 */
66
d6a6f46b 67 // 1. Stylesheets from the template.
b8292491 68 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
d6a6f46b 69
b8292491 70 $aUserStyles = array();
e2048f8e 71
d6a6f46b 72 // 2. Option user-defined stylesheet from preferences.
cd81f956 73 if (!empty($used_theme) && $used_theme != 'none') {
83fc5c5e 74 /**
8757c848 75 * All styles just point to a directory, so we need to include all .css
76 * files in that directory.
83fc5c5e 77 */
8757c848 78 $styles = list_files($used_theme, '.css');
79 foreach ($styles as $sheet) {
80 $aUserStyles[] = $used_theme .'/'.$sheet;
f9376f0b 81 }
deb25c8f 82 }
d6a6f46b 83
84 // 3. src/style.php
85 $aUserStyles[] = $base_uri .'src/style.php?'
b8292491 86 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
d6a6f46b 87 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
f9376f0b 88
89 // 3.1. Load the stylesheets we have already
b8292491 90 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
6182ab4d 91
d6a6f46b 92 // 4. Optional rtl.css stylesheet
6182ab4d 93 if ($text_direction == 'rtl') {
94 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
95 }
62f7daa5 96
e842b215 97 if ($squirrelmail_language == 'ja_JP') {
683b7853 98 /*
cbd8c251 99 * force correct detection of charset, when browser does not follow
100 * http content-type and tries to detect charset from page content.
101 * Shooting of browser's creator can't be implemented in php.
102 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
103 * recommendations and switch to unicode.
104 */
b8292491 105 $header_tags .= "<!-- \xfd\xfe -->\n";
b116fd78 106 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n";
e842b215 107 }
237470b4 108 if ($do_hook) {
ed1c151d 109 // NOTE! plugins here MUST assign output to template
110 // and NOT echo anything directly!! A common
111 // approach is if a plugin decides it needs to
112 // put something at page-top after the standard
113 // SM page header, to dynamically add itself to
114 // the page_header_bottom and/or compose_header_bottom
115 // hooks for the current page request. See
116 // the Sent Confirmation v1.7 or Restrict Senders v1.2
117 // plugins for examples of this approach.
d849b570 118 global $null;
ed1c151d 119 ob_start();
d849b570 120 do_hook('generic_header', $null);
ed1c151d 121 $output = ob_get_contents();
122 ob_end_clean();
123 // plugin authors can debug their errors with one of the following:
124 //sm_print_r($output);
125 //echo $output;
126 if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR);
237470b4 127 }
62f7daa5 128
b8292491 129 $header_tags .= $xtra;
130 $oTemplate->assign('page_title', $title);
5ca4b1ee 131
132 /* work around IE6's scrollbar bug */
b8292491 133 $header_tags .= <<<EOS
292a9c32 134<!--[if IE 6]>
5ca4b1ee 135<style type="text/css">
5fe8257d 136/* avoid stupid IE6 bug with frames and scrollbars */
137body {
5fe8257d 138 width: expression(document.documentElement.clientWidth - 30);
139}
5ca4b1ee 140</style>
292a9c32 141<![endif]-->
5ca4b1ee 142
b8292491 143EOS;
5ca4b1ee 144
b8292491 145 $oTemplate->assign('header_tags', $header_tags);
146 $oTemplate->display('protocol_header.tpl');
b6c283c4 147
148 /* this is used to check elsewhere whether we should call this function */
149 $pageheader_sent = TRUE;
81de00c0 150 if (isset($oErrorHandler)) {
e6c4caae 151 $oErrorHandler->HeaderSent();
81de00c0 152 }
b8292491 153
a07cd1a4 154}
155
8b096f0a 156/**
157 * Given a path to a SquirrelMail file, return a HTML link to it
158 *
159 * @param string path the SquirrelMail file to link to
160 * @param string text the link text
161 * @param string target the target frame for this link
162 */
d62c4938 163function makeInternalLink($path, $text, $target='') {
f7b996c3 164 global $base_uri, $oTemplate;
202bcbcc 165// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
4910106a 166
e50f5ac2 167 // This is an inefficient hook and is only used by
4910106a 168 // one plugin that still needs to patch this code,
e50f5ac2 169 // plus if we are templat-izing SM, visual hooks
170 // are not needed. However, I am leaving the code
171 // here just in case we find a good (non-visual?)
4910106a 172 // use for the internal_link hook.
173 //
d849b570 174 //do_hook('internal_link', $text);
4910106a 175
769a819d 176 return create_hyperlink($base_uri . $path, $text, $target);
d62c4938 177}
178
8b096f0a 179/**
180 * Same as makeInternalLink, but echoes it too
181 */
d62c4938 182function displayInternalLink($path, $text, $target='') {
b8292491 183// FIXME: should let the template echo all these kinds of things
b26d81e5 184 echo makeInternalLink($path, $text, $target);
a07cd1a4 185}
186
8b096f0a 187/**
188 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
189 * including the default menu bar. Uses displayHtmlHeader and takes
190 * JavaScript and locale settings into account.
191 *
192 * @param array color the array of theme colors
193 * @param string mailbox the current mailbox name to display
91c27aee 194 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
195 * @param string sBodyTagJs js events to be inserted in the body tag
8b096f0a 196 * @return void
197 */
715225af 198
876fdb60 199function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sBodyTagJs = '') {
10bf80c0 200
201 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 202 $provider_name, $provider_uri, $startMessage,
5f66bc58 203 $action, $oTemplate, $org_title, $base_uri;
10bf80c0 204
5bcce050 205//FIXME: $sBodyTag should be turned into $sOnload and should only contain the contents of the onload attribute (not the attribute name nor any quotes).... only question is if anyone was using $sBodyTag for anything but onload event handlers? (see function compose_Header() below for how to fix it once we confirm it can be changed)
10bf80c0 206 if (empty($sBodyTagJs)) {
207 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 208 if ($reply_focus == 'select')
209 $sBodyTagJs = 'onload="checkForm(\'select\');"';
210 else if ($reply_focus == 'focus')
211 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
212 else if ($reply_focus != 'none')
213 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 214 }
215 else
5fe8257d 216 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 217 }
218
5fe8257d 219 $urlMailbox = urlencode($mailbox);
220 $startMessage = (int)$startMessage;
221
0365891c 222 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 223
d03f3582 224 if (!isset($frame_top)) {
225 $frame_top = '_top';
226 }
715225af 227
83aff890 228//FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary??
229 if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
b8292491 230 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 231 $sJsBlock = '';
232 foreach ($js_includes as $js_file) {
233 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
234 }
91c27aee 235 if ($sHeaderJs) {
2c92ea9d 236 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 237 "\n<!--\n" .
a3d59ec3 238 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 239 }
e9e5a322 240 displayHtmlHeader ($org_title, $sJsBlock);
5fe8257d 241 } else {
d62c4938 242 /* do not use JavaScript */
e9e5a322 243 displayHtmlHeader ($org_title);
91c27aee 244 $sBodyTagJs = '';
715225af 245 }
202bcbcc 246 /*
247 * this explains the imap_mailbox.php dependency. We should instead store
248 * the selected mailbox in the session and fallback to the session var.
249 */
72520f77 250 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 251 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 252 if ( $shortBoxName == 'INBOX' ) {
7da23762 253 $shortBoxName = _("INBOX");
254 }
0493ed11 255
5810acfa 256 $provider_link = '';
257 if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
258 $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
99ea51d3 259 }
5fe8257d 260
261 $oTemplate->assign('body_tag_js', $sBodyTagJs);
262 $oTemplate->assign('shortBoxName', $shortBoxName);
5810acfa 263 $oTemplate->assign('provider_link', $provider_link);
5fe8257d 264 $oTemplate->assign('frame_top', $frame_top);
265 $oTemplate->assign('urlMailbox', $urlMailbox);
266 $oTemplate->assign('startMessage', $startMessage);
267 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
268 $oTemplate->display('page_header.tpl');
c5634692 269
270 global $null;
271 do_hook('page_header_bottom', $null);
a07cd1a4 272}
2ba13803 273
8b096f0a 274/**
275 * Blatantly copied/truncated/modified from displayPageHeader.
276 * Outputs a page header specifically for the compose_in_new popup window
277 *
278 * @param array color the array of theme colors
279 * @param string mailbox the current mailbox name to display
91c27aee 280 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
5bcce050 281 * @param string sOnload JavaScript code to be added inside the body's onload handler
282 * as of 1.5.2, this replaces $sBodyTagJs argument
8b096f0a 283 * @return void
284 */
5bcce050 285function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
10bf80c0 286
83aff890 287 global $reply_focus, $action, $oTemplate;
10bf80c0 288
5bcce050 289 if (empty($sOnload)) {
10bf80c0 290 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5bcce050 291 if ($reply_focus == 'select')
292 $sOnload = 'checkForm(\'select\');';
293 else if ($reply_focus == 'focus')
294 $sOnload = 'checkForm(\'focus\');';
295 else if ($reply_focus != 'none')
296 $sOnload = 'checkForm();';
10bf80c0 297 }
298 else
5bcce050 299 $sOnload = 'checkForm();';
10bf80c0 300 }
301
302
9c3e6cd4 303 /*
d62c4938 304 * Locate the first displayable form element (only when JavaScript on)
305 */
83aff890 306 if(checkForJavascript()) {
91c27aee 307 if ($sHeaderJs) {
2c92ea9d 308 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 309 "\n<!--\n" .
a3d59ec3 310 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 311 } else {
5fe8257d 312 $sJsBlock = '';
d62c4938 313 }
6373ad12 314 $sJsBlock .= "\n";
315
b8292491 316 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 317 foreach ($js_includes as $js_file) {
318 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
319 }
320
91c27aee 321 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 322 } else {
323 /* javascript off */
324 displayHtmlHeader(_("Compose"));
325 $onload = '';
9c3e6cd4 326 }
5bcce050 327
328// FIXME: change the colorization attributes below to a CSS class!
329 $class = '';
330 $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
331 'link' => $color[7], 'vlink' => $color[7],
332 'alink' => $color[7]);
ed1c151d 333
334 // this is template-safe (see create_body() function)
5bcce050 335 echo create_body($sOnload, $class, $aAttribs);
336
6f4b6b68 337 global $null;
338 do_hook('compose_header_bottom', $null);
9c3e6cd4 339}