6 * Prints the page header (duh)
8 * @copyright © 1999-2007 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 // don't show version as a security measure
45 //$oTemplate->header('X-Powered-By: SquirrelMail/' . SM_VERSION, FALSE);
46 $oTemplate->header('X-Powered-By: SquirrelMail', FALSE);
48 $oTemplate->assign('frames', $frames);
49 $oTemplate->assign('lang', $squirrelmail_language);
53 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n";
55 $used_fontset = (!empty($chosen_fontset) ?
$chosen_fontset : $default_fontset);
56 $used_fontsize = (!empty($chosen_fontsize) ?
$chosen_fontsize : $default_fontsize);
57 $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;
60 * Stylesheets are loaded in the following order:
61 * 1) All stylesheets provided by the template. Normally, these are
62 * stylsheets in templates/<template>/css/. This is accomplished by calling
63 * $oTemplate->fetch_standard_stylesheet_links().
64 * 2) An optional user-defined stylesheet. This is set in the Display
66 * 3) src/style.php which sets some basic font prefs.
67 * 4) If we are dealing with an RTL language, we load rtl.css from the
71 // 1. Stylesheets from the template.
72 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
74 $aUserStyles = array();
76 // 2. Option user-defined stylesheet from preferences.
77 if (!empty($used_theme) && $used_theme != 'none') {
79 * All styles (except "none" - ugh) just point to a directory,
80 * so we need to include all .css files in that directory.
82 //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?)
83 $styles = $used_theme == 'none' ?
array()
84 : list_files($used_theme, '.css');
85 foreach ($styles as $sheet) {
86 $aUserStyles[] = $used_theme .'/'.$sheet;
91 $aUserStyles[] = $base_uri .'src/style.php?'
92 . (!empty($used_fontset) ?
'&fontset='.$used_fontset : '')
93 . (!empty($used_fontsize) ?
'&fontsize='.$used_fontsize : '');
95 // 3.1. Load the stylesheets we have already
96 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
98 // 4. Optional rtl.css stylesheet
99 if ($text_direction == 'rtl') {
100 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
103 // 5. Printer friendly stylesheet
104 $header_tags .= create_css_link($base_uri . 'css/print.css', 'printerfriendly', false, 'print');
106 if ($squirrelmail_language == 'ja_JP') {
108 * force correct detection of charset, when browser does not follow
109 * http content-type and tries to detect charset from page content.
110 * Shooting of browser's creator can't be implemented in php.
111 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
112 * recommendations and switch to unicode.
114 $header_tags .= "<!-- \xfd\xfe -->\n";
115 $header_tags .= '<meta http-equiv="Content-type" content="' . $oTemplate->get_content_type() . '; charset=euc-jp" />' . "\n";
118 // NOTE! plugins here MUST assign output to template
119 // and NOT echo anything directly!! A common
120 // approach is if a plugin decides it needs to
121 // put something at page-top after the standard
122 // SM page header, to dynamically add itself to
123 // the page_header_bottom and/or compose_header_bottom
124 // hooks for the current page request. See
125 // the Sent Confirmation v1.7 or Restrict Senders v1.2
126 // plugins for examples of this approach.
128 $temp = array(&$header_tags);
129 do_hook('generic_header', $temp);
130 $output = ob_get_contents();
132 // plugin authors can debug their errors with one of the following:
133 //sm_print_r($output);
135 if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR
);
138 $header_tags .= $xtra;
139 $oTemplate->assign('page_title', $title);
141 /* work around IE6's scrollbar bug */
142 $header_tags .= <<<EOS
144 <style type="text/css">
145 /* avoid stupid IE6 bug with frames and scrollbars */
147 width: expression(document.documentElement.clientWidth - 30);
154 $oTemplate->assign('header_tags', $header_tags);
155 $oTemplate->display('protocol_header.tpl');
157 /* this is used to check elsewhere whether we should call this function */
158 $pageheader_sent = TRUE;
159 if (isset($oErrorHandler)) {
160 $oErrorHandler->HeaderSent();
166 * Given a path to a SquirrelMail file, return a HTML link to it
168 * @param string path the SquirrelMail file to link to
169 * (should start with something like "src/..." or
170 * "functions/..." or "plugins/..." etc.)
171 * @param string text the link text
172 * @param string target the target frame for this link
174 function makeInternalLink($path, $text, $target='') {
175 global $base_uri, $oTemplate;
176 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
178 // This is an inefficient hook and is only used by
179 // one plugin that still needs to patch this code,
180 // plus if we are templat-izing SM, visual hooks
181 // are not needed. However, I am leaving the code
182 // here just in case we find a good (non-visual?)
183 // use for the internal_link hook.
185 //do_hook('internal_link', $text);
187 return create_hyperlink($base_uri . $path, $text, $target);
191 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
192 * including the default menu bar. Uses displayHtmlHeader and takes
193 * JavaScript and locale settings into account.
195 * @param array color the array of theme colors
196 * @param string mailbox the current mailbox name to display
197 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
198 * @param string sOnload JavaScript code to be added inside the body's onload handler
199 * as of 1.5.2, this replaces $sBodyTagJs argument
202 function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sOnload = '') {
204 global $reply_focus, $hide_sm_attributions, $frame_top,
205 $provider_name, $provider_uri, $startMessage,
206 $action, $oTemplate, $org_title, $base_uri,
207 $data_dir, $username;
209 if (empty($sOnload)) {
210 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
211 if ($reply_focus == 'select')
212 $sOnload = 'checkForm(\'select\');';
213 else if ($reply_focus == 'focus')
214 $sOnload = 'checkForm(\'focus\');';
215 else if ($reply_focus != 'none')
216 $sOnload = 'checkForm();';
219 $sOnload = 'checkForm();';
222 $startMessage = (int)$startMessage;
224 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
226 if (!isset($frame_top)) {
230 //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...(?))
231 if( checkForJavascript() ||
strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
232 $js_includes = $oTemplate->get_javascript_includes(TRUE);
234 foreach ($js_includes as $js_file) {
235 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
238 $sJsBlock .= "\n<script type=\"text/javascript\">" .
240 $sHeaderJs . "\n\n// -->\n</script>\n";
242 displayHtmlHeader ($org_title, $sJsBlock);
244 /* do not use JavaScript */
245 displayHtmlHeader ($org_title);
250 * this explains the imap_mailbox.php dependency. We should instead store
251 * the selected mailbox in the session and fallback to the session var.
253 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
254 readShortMailboxName($mailbox, $delimiter)));
255 if (getPref($data_dir, $username, 'translate_special_folders')) {
256 $shortBoxName = _($shortBoxName);
258 $urlMailbox = urlencode($mailbox);
265 if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
266 $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
269 $oTemplate->assign('onload', $sOnload);
270 $oTemplate->assign('shortBoxName', $shortBoxName);
271 $oTemplate->assign('provider_link', $provider_link);
272 $oTemplate->assign('frame_top', $frame_top);
273 $oTemplate->assign('urlMailbox', $urlMailbox);
274 $oTemplate->assign('startMessage', $startMessage);
275 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
276 $oTemplate->display('page_header.tpl');
279 do_hook('page_header_bottom', $null);
283 * Blatantly copied/truncated/modified from displayPageHeader.
284 * Outputs a page header specifically for the compose_in_new popup window
286 * @param array color the array of theme colors
287 * @param string mailbox the current mailbox name to display
288 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
289 * @param string sOnload JavaScript code to be added inside the body's onload handler
290 * as of 1.5.2, this replaces $sBodyTagJs argument
293 function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
295 global $reply_focus, $action, $oTemplate;
297 if (empty($sOnload)) {
298 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
299 if ($reply_focus == 'select')
300 $sOnload = 'checkForm(\'select\');';
301 else if ($reply_focus == 'focus')
302 $sOnload = 'checkForm(\'focus\');';
303 else if ($reply_focus != 'none')
304 $sOnload = 'checkForm();';
307 $sOnload = 'checkForm();';
312 * Locate the first displayable form element (only when JavaScript on)
314 if(checkForJavascript()) {
316 $sJsBlock = "\n<script type=\"text/javascript\">" .
318 $sHeaderJs . "\n\n// -->\n</script>\n";
324 $js_includes = $oTemplate->get_javascript_includes(TRUE);
325 foreach ($js_includes as $js_file) {
326 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
329 displayHtmlHeader (_("Compose"), $sJsBlock);
332 displayHtmlHeader(_("Compose"));
336 // FIXME: change the colorization attributes below to a CSS class!
338 $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
339 'link' => $color[7], 'vlink' => $color[7],
340 'alink' => $color[7]);
342 // this is template-safe (see create_body() function)
343 echo create_body($sOnload, $class, $aAttribs);
346 do_hook('compose_header_bottom', $null);