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, $chosen_theme;
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)
43 $oTemplate->assign('frames', $frames);
44 $oTemplate->assign('lang', $squirrelmail_language);
48 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
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');
55 * Stylesheets are loaded in the following order:
56 * 1) All stylesheets provided by the template. Normally, these are
57 * stylsheets in templates/<template>/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
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
66 // 1. Stylesheets from the template.
67 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
69 $aUserStyles = array();
71 // 2. Option user-defined stylesheet from preferences.
72 // 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)
73 // 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?
74 // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
75 // Steve, can you please document what u_ means? Will it work with the
76 // new template inheritance system and auto-detection of alternate sheets?
78 * Stylesheets beginning with a "u_" == user provided stylesheets, e.g. those
79 * in SM_PATH/css/. Template provided stylesheets (TEMPLATE_DIR/css/alternatives/)
80 * should begin with 't_'. This was the initial path I took to get it working
81 * since I wasn't sure what mods to the Template class would be used to handle
82 * template-provided alt stylesheets.
84 * TODO: Re-evaluate this naming convetion.
86 if (!empty($chosen_theme) && substr($chosen_theme, 0, 2) == 'u_') {
87 $aUserStyles[] = substr($chosen_theme, 2) .'default.css';
91 $aUserStyles[] = $base_uri .'src/style.php?'
92 . (!empty($used_fontset) ?
'&fontset='.$used_fontset : '')
93 . (!empty($used_fontsize) ?
'&fontsize='.$used_fontsize : '');
94 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
96 // 4. Optional rtl.css stylesheet
97 if ($text_direction == 'rtl') {
98 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
101 if ($squirrelmail_language == 'ja_JP') {
103 * force correct detection of charset, when browser does not follow
104 * http content-type and tries to detect charset from page content.
105 * Shooting of browser's creator can't be implemented in php.
106 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
107 * recommendations and switch to unicode.
109 $header_tags .= "<!-- \xfd\xfe -->\n";
110 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
113 // NOTE! plugins here must assign output to template
114 // and NOT echo anything directly!!
115 do_hook('generic_header');
118 $header_tags .= $xtra;
119 $oTemplate->assign('page_title', $title);
121 /* work around IE6's scrollbar bug */
122 $header_tags .= <<<EOS
124 <style type="text/css">
125 /* avoid stupid IE6 bug with frames and scrollbars */
127 width: expression(document.documentElement.clientWidth - 30);
134 $oTemplate->assign('header_tags', $header_tags);
135 $oTemplate->display('protocol_header.tpl');
137 /* this is used to check elsewhere whether we should call this function */
138 $pageheader_sent = TRUE;
139 if (isset($oErrorHandler)) {
140 $oErrorHandler->HeaderSent();
146 * Given a path to a SquirrelMail file, return a HTML link to it
148 * @param string path the SquirrelMail file to link to
149 * @param string text the link text
150 * @param string target the target frame for this link
152 function makeInternalLink($path, $text, $target='') {
154 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
156 $target = " target=\"$target\"";
159 // This is an inefficient hook and is only used by
160 // one plugin that still needs to patch this code,
161 // plus if we are templat-izing SM, visual hooks
162 // are not needed. However, I am leaving the code
163 // here just in case we find a good (non-visual?)
164 // use for the internal_link hook.
166 //$hooktext = do_hook_function('internal_link',$text);
167 //if ($hooktext != '')
168 // $text = $hooktext;
170 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
174 * Same as makeInternalLink, but echoes it too
176 function displayInternalLink($path, $text, $target='') {
177 // FIXME: should let the template echo all these kinds of things
178 echo makeInternalLink($path, $text, $target);
182 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
183 * including the default menu bar. Uses displayHtmlHeader and takes
184 * JavaScript and locale settings into account.
186 * @param array color the array of theme colors
187 * @param string mailbox the current mailbox name to display
188 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
189 * @param string sBodyTagJs js events to be inserted in the body tag
193 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
195 global $reply_focus, $hide_sm_attributions, $frame_top,
196 $provider_name, $provider_uri, $startMessage,
197 $javascript_on, $action, $oTemplate;
199 if (empty($sBodyTagJs)) {
200 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
201 if ($reply_focus == 'select')
202 $sBodyTagJs = 'onload="checkForm(\'select\');"';
203 else if ($reply_focus == 'focus')
204 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
205 else if ($reply_focus != 'none')
206 $sBodyTagJs = 'onload="checkForm();"';
209 $sBodyTagJs = 'onload="checkForm();"';
212 $urlMailbox = urlencode($mailbox);
213 $startMessage = (int)$startMessage;
215 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
217 if (!isset($frame_top)) {
221 if( $javascript_on ||
strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
222 $js_includes = $oTemplate->get_javascript_includes(TRUE);
224 foreach ($js_includes as $js_file) {
225 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
228 $sJsBlock .= "\n<script type=\"text/javascript\">" .
230 $sHeaderJs . "\n\n// -->\n</script>\n";
232 displayHtmlHeader ('SquirrelMail', $sJsBlock);
234 /* do not use JavaScript */
235 displayHtmlHeader ('SquirrelMail');
239 * this explains the imap_mailbox.php dependency. We should instead store
240 * the selected mailbox in the session and fallback to the session var.
242 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
243 readShortMailboxName($mailbox, $delimiter)));
244 if ( $shortBoxName == 'INBOX' ) {
245 $shortBoxName = _("INBOX");
249 if (!$hide_sm_attributions) {
250 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
251 if (empty($provider_uri)) {
252 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
254 if (empty($provider_name)) $provider_name= 'SquirrelMail';
255 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
257 $sm_attributes .= " </td>\n";
260 $oTemplate->assign('body_tag_js', $sBodyTagJs);
261 $oTemplate->assign('shortBoxName', $shortBoxName);
262 $oTemplate->assign('sm_attribute_str', $sm_attributes);
263 $oTemplate->assign('frame_top', $frame_top);
264 $oTemplate->assign('urlMailbox', $urlMailbox);
265 $oTemplate->assign('startMessage', $startMessage);
266 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
267 $oTemplate->display('page_header.tpl');
271 * Blatantly copied/truncated/modified from displayPageHeader.
272 * Outputs a page header specifically for the compose_in_new popup window
274 * @param array color the array of theme colors
275 * @param string mailbox the current mailbox name to display
276 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
277 * @param string sBodyTagJs js events to be inserted in the body tag
280 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
282 global $reply_focus, $javascript_on, $action, $oTemplate;
284 if (empty($sBodyTagJs)) {
285 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
286 if ($reply_focus == 'select')
287 $sBodyTagJs = 'onload="checkForm(\'select\');"';
288 else if ($reply_focus == 'focus')
289 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
290 else if ($reply_focus != 'none')
291 $sBodyTagJs = 'onload="checkForm();"';
294 $sBodyTagJs = 'onload="checkForm();"';
299 * Locate the first displayable form element (only when JavaScript on)
303 $sJsBlock = "\n<script type=\"text/javascript\">" .
305 $sHeaderJs . "\n\n// -->\n</script>\n";
311 $js_includes = $oTemplate->get_javascript_includes(TRUE);
312 foreach ($js_includes as $js_file) {
313 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
316 displayHtmlHeader (_("Compose"), $sJsBlock);
319 displayHtmlHeader(_("Compose"));
322 // FIXME: should let the template echo all these kinds of things
323 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";