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 # var_dump($used_theme);
88 if (!empty($used_theme)) {
89 if (substr($used_theme, 0, 2) == 'u_') {
90 $aUserStyles[] = substr($used_theme, 2) .'/default.css';
91 } elseif (substr($used_theme, 0, 2) == 't_') {
92 $aUserStyles[] = SM_PATH
. $oTemplate->get_template_file_directory().'css/alternates/'.substr($used_theme, 2);
93 # $aUserStyles[] = substr($used_theme, 2);
98 $aUserStyles[] = $base_uri .'src/style.php?'
99 . (!empty($used_fontset) ?
'&fontset='.$used_fontset : '')
100 . (!empty($used_fontsize) ?
'&fontsize='.$used_fontsize : '');
102 // 3.1. Load the stylesheets we have already
103 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
105 // 4. Optional rtl.css stylesheet
106 if ($text_direction == 'rtl') {
107 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
110 if ($squirrelmail_language == 'ja_JP') {
112 * force correct detection of charset, when browser does not follow
113 * http content-type and tries to detect charset from page content.
114 * Shooting of browser's creator can't be implemented in php.
115 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
116 * recommendations and switch to unicode.
118 $header_tags .= "<!-- \xfd\xfe -->\n";
119 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
122 // NOTE! plugins here must assign output to template
123 // and NOT echo anything directly!!
124 do_hook('generic_header');
127 $header_tags .= $xtra;
128 $oTemplate->assign('page_title', $title);
130 /* work around IE6's scrollbar bug */
131 $header_tags .= <<<EOS
133 <style type="text/css">
134 /* avoid stupid IE6 bug with frames and scrollbars */
136 width: expression(document.documentElement.clientWidth - 30);
143 $oTemplate->assign('header_tags', $header_tags);
144 $oTemplate->display('protocol_header.tpl');
146 /* this is used to check elsewhere whether we should call this function */
147 $pageheader_sent = TRUE;
148 if (isset($oErrorHandler)) {
149 $oErrorHandler->HeaderSent();
155 * Given a path to a SquirrelMail file, return a HTML link to it
157 * @param string path the SquirrelMail file to link to
158 * @param string text the link text
159 * @param string target the target frame for this link
161 function makeInternalLink($path, $text, $target='') {
163 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
165 $target = " target=\"$target\"";
168 // This is an inefficient hook and is only used by
169 // one plugin that still needs to patch this code,
170 // plus if we are templat-izing SM, visual hooks
171 // are not needed. However, I am leaving the code
172 // here just in case we find a good (non-visual?)
173 // use for the internal_link hook.
175 //$hooktext = do_hook_function('internal_link',$text);
176 //if ($hooktext != '')
177 // $text = $hooktext;
179 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
183 * Same as makeInternalLink, but echoes it too
185 function displayInternalLink($path, $text, $target='') {
186 // FIXME: should let the template echo all these kinds of things
187 echo makeInternalLink($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 sBodyTagJs js events to be inserted in the body tag
202 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
204 global $reply_focus, $hide_sm_attributions, $frame_top,
205 $provider_name, $provider_uri, $startMessage,
206 $javascript_on, $action, $oTemplate;
208 if (empty($sBodyTagJs)) {
209 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
210 if ($reply_focus == 'select')
211 $sBodyTagJs = 'onload="checkForm(\'select\');"';
212 else if ($reply_focus == 'focus')
213 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
214 else if ($reply_focus != 'none')
215 $sBodyTagJs = 'onload="checkForm();"';
218 $sBodyTagJs = 'onload="checkForm();"';
221 $urlMailbox = urlencode($mailbox);
222 $startMessage = (int)$startMessage;
224 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
226 if (!isset($frame_top)) {
230 if( $javascript_on ||
strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
231 $js_includes = $oTemplate->get_javascript_includes(TRUE);
233 foreach ($js_includes as $js_file) {
234 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
237 $sJsBlock .= "\n<script type=\"text/javascript\">" .
239 $sHeaderJs . "\n\n// -->\n</script>\n";
241 displayHtmlHeader ('SquirrelMail', $sJsBlock);
243 /* do not use JavaScript */
244 displayHtmlHeader ('SquirrelMail');
248 * this explains the imap_mailbox.php dependency. We should instead store
249 * the selected mailbox in the session and fallback to the session var.
251 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
252 readShortMailboxName($mailbox, $delimiter)));
253 if ( $shortBoxName == 'INBOX' ) {
254 $shortBoxName = _("INBOX");
258 if (!$hide_sm_attributions) {
259 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
260 if (empty($provider_uri)) {
261 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
263 if (empty($provider_name)) $provider_name= 'SquirrelMail';
264 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
266 $sm_attributes .= " </td>\n";
269 $oTemplate->assign('body_tag_js', $sBodyTagJs);
270 $oTemplate->assign('shortBoxName', $shortBoxName);
271 $oTemplate->assign('sm_attribute_str', $sm_attributes);
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');
280 * Blatantly copied/truncated/modified from displayPageHeader.
281 * Outputs a page header specifically for the compose_in_new popup window
283 * @param array color the array of theme colors
284 * @param string mailbox the current mailbox name to display
285 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
286 * @param string sBodyTagJs js events to be inserted in the body tag
289 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
291 global $reply_focus, $javascript_on, $action, $oTemplate;
293 if (empty($sBodyTagJs)) {
294 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
295 if ($reply_focus == 'select')
296 $sBodyTagJs = 'onload="checkForm(\'select\');"';
297 else if ($reply_focus == 'focus')
298 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
299 else if ($reply_focus != 'none')
300 $sBodyTagJs = 'onload="checkForm();"';
303 $sBodyTagJs = 'onload="checkForm();"';
308 * Locate the first displayable form element (only when JavaScript on)
312 $sJsBlock = "\n<script type=\"text/javascript\">" .
314 $sHeaderJs . "\n\n// -->\n</script>\n";
320 $js_includes = $oTemplate->get_javascript_includes(TRUE);
321 foreach ($js_includes as $js_file) {
322 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
325 displayHtmlHeader (_("Compose"), $sJsBlock);
328 displayHtmlHeader(_("Compose"));
331 // FIXME: should let the template echo all these kinds of things
332 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";