6 * Prints the page header (duh)
8 * @copyright © 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
11 * @package squirrelmail
14 /** Include required files from SM */
15 include_once(SM_PATH
. 'functions/imap_mailbox.php');
18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
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)
29 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
30 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
) ) {
35 global $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize,
37 $chosen_theme, $chosen_theme_path, $user_themes, $user_theme_default;
39 /* add no cache headers here */
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)
44 $oTemplate->assign('frames', $frames);
45 $oTemplate->assign('lang', $squirrelmail_language);
49 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
51 $used_fontset = (!empty($chosen_fontset) ?
$chosen_fontset : $default_fontset);
52 $used_fontsize = (!empty($chosen_fontsize) ?
$chosen_fontsize : $default_fontsize);
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;
56 * Stylesheets are loaded in the following order:
57 * 1) All stylesheets provided by the template. Normally, these are
58 * stylsheets in templates/<template>/css/. This is accomplished by calling
59 * $oTemplate->fetch_standard_stylesheet_links().
60 * 2) An optional user-defined stylesheet. This is set in the Display
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
67 // 1. Stylesheets from the template.
68 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
70 $aUserStyles = array();
72 // 2. Option user-defined stylesheet from preferences.
73 if (!empty($used_theme)) {
75 * All styles just point to a directory, so we need to include all .css
76 * files in that directory.
78 $styles = list_files($used_theme, '.css');
79 foreach ($styles as $sheet) {
80 $aUserStyles[] = $used_theme .'/'.$sheet;
85 $aUserStyles[] = $base_uri .'src/style.php?'
86 . (!empty($used_fontset) ?
'&fontset='.$used_fontset : '')
87 . (!empty($used_fontsize) ?
'&fontsize='.$used_fontsize : '');
89 // 3.1. Load the stylesheets we have already
90 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
92 // 4. Optional rtl.css stylesheet
93 if ($text_direction == 'rtl') {
94 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
97 if ($squirrelmail_language == 'ja_JP') {
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.
105 $header_tags .= "<!-- \xfd\xfe -->\n";
106 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
109 // NOTE! plugins here must assign output to template
110 // and NOT echo anything directly!!
111 do_hook('generic_header');
114 $header_tags .= $xtra;
115 $oTemplate->assign('page_title', $title);
117 /* work around IE6's scrollbar bug */
118 $header_tags .= <<<EOS
120 <style type="text/css">
121 /* avoid stupid IE6 bug with frames and scrollbars */
123 width: expression(document.documentElement.clientWidth - 30);
130 $oTemplate->assign('header_tags', $header_tags);
131 $oTemplate->display('protocol_header.tpl');
133 /* this is used to check elsewhere whether we should call this function */
134 $pageheader_sent = TRUE;
135 if (isset($oErrorHandler)) {
136 $oErrorHandler->HeaderSent();
142 * Given a path to a SquirrelMail file, return a HTML link to it
144 * @param string path the SquirrelMail file to link to
145 * @param string text the link text
146 * @param string target the target frame for this link
148 function makeInternalLink($path, $text, $target='') {
150 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
152 $target = " target=\"$target\"";
155 // This is an inefficient hook and is only used by
156 // one plugin that still needs to patch this code,
157 // plus if we are templat-izing SM, visual hooks
158 // are not needed. However, I am leaving the code
159 // here just in case we find a good (non-visual?)
160 // use for the internal_link hook.
162 //$hooktext = do_hook_function('internal_link',$text);
163 //if ($hooktext != '')
164 // $text = $hooktext;
166 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
170 * Same as makeInternalLink, but echoes it too
172 function displayInternalLink($path, $text, $target='') {
173 // FIXME: should let the template echo all these kinds of things
174 echo makeInternalLink($path, $text, $target);
178 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
179 * including the default menu bar. Uses displayHtmlHeader and takes
180 * JavaScript and locale settings into account.
182 * @param array color the array of theme colors
183 * @param string mailbox the current mailbox name to display
184 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
185 * @param string sBodyTagJs js events to be inserted in the body tag
189 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
191 global $reply_focus, $hide_sm_attributions, $frame_top,
192 $provider_name, $provider_uri, $startMessage,
193 $javascript_on, $action, $oTemplate;
195 if (empty($sBodyTagJs)) {
196 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
197 if ($reply_focus == 'select')
198 $sBodyTagJs = 'onload="checkForm(\'select\');"';
199 else if ($reply_focus == 'focus')
200 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
201 else if ($reply_focus != 'none')
202 $sBodyTagJs = 'onload="checkForm();"';
205 $sBodyTagJs = 'onload="checkForm();"';
208 $urlMailbox = urlencode($mailbox);
209 $startMessage = (int)$startMessage;
211 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
213 if (!isset($frame_top)) {
217 if( $javascript_on ||
strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
218 $js_includes = $oTemplate->get_javascript_includes(TRUE);
220 foreach ($js_includes as $js_file) {
221 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
224 $sJsBlock .= "\n<script type=\"text/javascript\">" .
226 $sHeaderJs . "\n\n// -->\n</script>\n";
228 displayHtmlHeader ('SquirrelMail', $sJsBlock);
230 /* do not use JavaScript */
231 displayHtmlHeader ('SquirrelMail');
235 * this explains the imap_mailbox.php dependency. We should instead store
236 * the selected mailbox in the session and fallback to the session var.
238 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
239 readShortMailboxName($mailbox, $delimiter)));
240 if ( $shortBoxName == 'INBOX' ) {
241 $shortBoxName = _("INBOX");
245 if (!$hide_sm_attributions) {
246 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
247 if (empty($provider_uri)) {
248 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
250 if (empty($provider_name)) $provider_name= 'SquirrelMail';
251 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
253 $sm_attributes .= " </td>\n";
256 $oTemplate->assign('body_tag_js', $sBodyTagJs);
257 $oTemplate->assign('shortBoxName', $shortBoxName);
258 $oTemplate->assign('sm_attribute_str', $sm_attributes);
259 $oTemplate->assign('frame_top', $frame_top);
260 $oTemplate->assign('urlMailbox', $urlMailbox);
261 $oTemplate->assign('startMessage', $startMessage);
262 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
263 $oTemplate->display('page_header.tpl');
267 * Blatantly copied/truncated/modified from displayPageHeader.
268 * Outputs a page header specifically for the compose_in_new popup window
270 * @param array color the array of theme colors
271 * @param string mailbox the current mailbox name to display
272 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
273 * @param string sBodyTagJs js events to be inserted in the body tag
276 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
278 global $reply_focus, $javascript_on, $action, $oTemplate;
280 if (empty($sBodyTagJs)) {
281 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
282 if ($reply_focus == 'select')
283 $sBodyTagJs = 'onload="checkForm(\'select\');"';
284 else if ($reply_focus == 'focus')
285 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
286 else if ($reply_focus != 'none')
287 $sBodyTagJs = 'onload="checkForm();"';
290 $sBodyTagJs = 'onload="checkForm();"';
295 * Locate the first displayable form element (only when JavaScript on)
299 $sJsBlock = "\n<script type=\"text/javascript\">" .
301 $sHeaderJs . "\n\n// -->\n</script>\n";
307 $js_includes = $oTemplate->get_javascript_includes(TRUE);
308 foreach ($js_includes as $js_file) {
309 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
312 displayHtmlHeader (_("Compose"), $sJsBlock);
315 displayHtmlHeader(_("Compose"));
318 // FIXME: should let the template echo all these kinds of things
319 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";