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' ?
'u_'.$user_themes[$user_theme_default]['PATH'] : $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 // 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)
74 // 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?
75 // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
76 // Steve, can you please document what u_ means? Will it work with the
77 // new template inheritance system and auto-detection of alternate sheets?
79 * Stylesheets beginning with a "u_" == user provided stylesheets, e.g. those
80 * in SM_PATH/css/. Template provided stylesheets (TEMPLATE_DIR/css/alternatives/)
81 * should begin with 't_'. This was the initial path I took to get it working
82 * since I wasn't sure what mods to the Template class would be used to handle
83 * template-provided alt stylesheets.
85 * TODO: Re-evaluate this naming convetion.
87 if (!empty($used_theme) && substr($used_theme, 0, 2) == 'u_') {
88 $aUserStyles[] = substr($used_theme, 2) .'default.css';
92 $aUserStyles[] = $base_uri .'src/style.php?'
93 . (!empty($used_fontset) ?
'&fontset='.$used_fontset : '')
94 . (!empty($used_fontsize) ?
'&fontsize='.$used_fontsize : '');
95 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
97 // 4. Optional rtl.css stylesheet
98 if ($text_direction == 'rtl') {
99 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
102 if ($squirrelmail_language == 'ja_JP') {
104 * force correct detection of charset, when browser does not follow
105 * http content-type and tries to detect charset from page content.
106 * Shooting of browser's creator can't be implemented in php.
107 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
108 * recommendations and switch to unicode.
110 $header_tags .= "<!-- \xfd\xfe -->\n";
111 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
114 // NOTE! plugins here must assign output to template
115 // and NOT echo anything directly!!
116 do_hook('generic_header');
119 $header_tags .= $xtra;
120 $oTemplate->assign('page_title', $title);
122 /* work around IE6's scrollbar bug */
123 $header_tags .= <<<EOS
125 <style type="text/css">
126 /* avoid stupid IE6 bug with frames and scrollbars */
128 width: expression(document.documentElement.clientWidth - 30);
135 $oTemplate->assign('header_tags', $header_tags);
136 $oTemplate->display('protocol_header.tpl');
138 /* this is used to check elsewhere whether we should call this function */
139 $pageheader_sent = TRUE;
140 if (isset($oErrorHandler)) {
141 $oErrorHandler->HeaderSent();
147 * Given a path to a SquirrelMail file, return a HTML link to it
149 * @param string path the SquirrelMail file to link to
150 * @param string text the link text
151 * @param string target the target frame for this link
153 function makeInternalLink($path, $text, $target='') {
155 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
157 $target = " target=\"$target\"";
160 // This is an inefficient hook and is only used by
161 // one plugin that still needs to patch this code,
162 // plus if we are templat-izing SM, visual hooks
163 // are not needed. However, I am leaving the code
164 // here just in case we find a good (non-visual?)
165 // use for the internal_link hook.
167 //$hooktext = do_hook_function('internal_link',$text);
168 //if ($hooktext != '')
169 // $text = $hooktext;
171 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
175 * Same as makeInternalLink, but echoes it too
177 function displayInternalLink($path, $text, $target='') {
178 // FIXME: should let the template echo all these kinds of things
179 echo makeInternalLink($path, $text, $target);
183 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
184 * including the default menu bar. Uses displayHtmlHeader and takes
185 * JavaScript and locale settings into account.
187 * @param array color the array of theme colors
188 * @param string mailbox the current mailbox name to display
189 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
190 * @param string sBodyTagJs js events to be inserted in the body tag
194 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
196 global $reply_focus, $hide_sm_attributions, $frame_top,
197 $provider_name, $provider_uri, $startMessage,
198 $javascript_on, $action, $oTemplate;
200 if (empty($sBodyTagJs)) {
201 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
202 if ($reply_focus == 'select')
203 $sBodyTagJs = 'onload="checkForm(\'select\');"';
204 else if ($reply_focus == 'focus')
205 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
206 else if ($reply_focus != 'none')
207 $sBodyTagJs = 'onload="checkForm();"';
210 $sBodyTagJs = 'onload="checkForm();"';
213 $urlMailbox = urlencode($mailbox);
214 $startMessage = (int)$startMessage;
216 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
218 if (!isset($frame_top)) {
222 if( $javascript_on ||
strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
223 $js_includes = $oTemplate->get_javascript_includes(TRUE);
225 foreach ($js_includes as $js_file) {
226 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
229 $sJsBlock .= "\n<script type=\"text/javascript\">" .
231 $sHeaderJs . "\n\n// -->\n</script>\n";
233 displayHtmlHeader ('SquirrelMail', $sJsBlock);
235 /* do not use JavaScript */
236 displayHtmlHeader ('SquirrelMail');
240 * this explains the imap_mailbox.php dependency. We should instead store
241 * the selected mailbox in the session and fallback to the session var.
243 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
244 readShortMailboxName($mailbox, $delimiter)));
245 if ( $shortBoxName == 'INBOX' ) {
246 $shortBoxName = _("INBOX");
250 if (!$hide_sm_attributions) {
251 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
252 if (empty($provider_uri)) {
253 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
255 if (empty($provider_name)) $provider_name= 'SquirrelMail';
256 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
258 $sm_attributes .= " </td>\n";
261 $oTemplate->assign('body_tag_js', $sBodyTagJs);
262 $oTemplate->assign('shortBoxName', $shortBoxName);
263 $oTemplate->assign('sm_attribute_str', $sm_attributes);
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');
272 * Blatantly copied/truncated/modified from displayPageHeader.
273 * Outputs a page header specifically for the compose_in_new popup window
275 * @param array color the array of theme colors
276 * @param string mailbox the current mailbox name to display
277 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
278 * @param string sBodyTagJs js events to be inserted in the body tag
281 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
283 global $reply_focus, $javascript_on, $action, $oTemplate;
285 if (empty($sBodyTagJs)) {
286 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
287 if ($reply_focus == 'select')
288 $sBodyTagJs = 'onload="checkForm(\'select\');"';
289 else if ($reply_focus == 'focus')
290 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
291 else if ($reply_focus != 'none')
292 $sBodyTagJs = 'onload="checkForm();"';
295 $sBodyTagJs = 'onload="checkForm();"';
300 * Locate the first displayable form element (only when JavaScript on)
304 $sJsBlock = "\n<script type=\"text/javascript\">" .
306 $sHeaderJs . "\n\n// -->\n</script>\n";
312 $js_includes = $oTemplate->get_javascript_includes(TRUE);
313 foreach ($js_includes as $js_file) {
314 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
317 displayHtmlHeader (_("Compose"), $sJsBlock);
320 displayHtmlHeader(_("Compose"));
323 // FIXME: should let the template echo all these kinds of things
324 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";