Template themes are now directories, not individual stylesheets.
[squirrelmail.git] / functions / page_header.php
CommitLineData
59177427 1<?php
7350889b 2
35586184 3/**
4 * page_header.php
5 *
35586184 6 * Prints the page header (duh)
7 *
47ccfad4 8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
4b4abf93 9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
31841a9e 10 * @version $Id$
d6c32258 11 * @package squirrelmail
35586184 12 */
13
d6c32258 14/** Include required files from SM */
202bcbcc 15include_once(SM_PATH . 'functions/imap_mailbox.php');
b68edc75 16
d6c32258 17/**
8b096f0a 18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
20 *
81132de8 21 * Since 1.5.1 function sends http headers. Function should be called
22 * before any output is started.
8b096f0a 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
62b9c984 26 * @param bool frames generate html frameset doctype (since 1.5.1)
8b096f0a 27 * @return void
d6c32258 28 */
d88941c7 29function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
b8292491 30 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
692155b7 31
0365891c 32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
0b97a708 33 global $base_uri;
34 }
ab034e59 35 global $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
acd7fdf2 36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize,
37 $chosen_theme, $chosen_theme_path, $user_themes, $user_theme_default;
81132de8 38
39 /* add no cache headers here */
b8292491 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)
2c21ef20 43
b8292491 44 $oTemplate->assign('frames', $frames);
45 $oTemplate->assign('lang', $squirrelmail_language);
46
47 $header_tags = '';
48
49 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
2c21ef20 50
d88941c7 51 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
52 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
8757c848 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;
acd7fdf2 54
d6a6f46b 55 /**
56 * Stylesheets are loaded in the following order:
57 * 1) All stylesheets provided by the template. Normally, these are
e2048f8e 58 * stylsheets in templates/<template>/css/. This is accomplished by calling
d6a6f46b 59 * $oTemplate->fetch_standard_stylesheet_links().
60 * 2) An optional user-defined stylesheet. This is set in the Display
61 * Preferences.
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
64 * template set.
e2048f8e 65 */
66
d6a6f46b 67 // 1. Stylesheets from the template.
b8292491 68 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
d6a6f46b 69
b8292491 70 $aUserStyles = array();
e2048f8e 71
d6a6f46b 72 // 2. Option user-defined stylesheet from preferences.
f9376f0b 73 if (!empty($used_theme)) {
83fc5c5e 74 /**
8757c848 75 * All styles just point to a directory, so we need to include all .css
76 * files in that directory.
83fc5c5e 77 */
8757c848 78 $styles = list_files($used_theme, '.css');
79 foreach ($styles as $sheet) {
80 $aUserStyles[] = $used_theme .'/'.$sheet;
f9376f0b 81 }
deb25c8f 82 }
d6a6f46b 83
84 // 3. src/style.php
85 $aUserStyles[] = $base_uri .'src/style.php?'
b8292491 86 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
d6a6f46b 87 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
f9376f0b 88
89 // 3.1. Load the stylesheets we have already
b8292491 90 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
6182ab4d 91
d6a6f46b 92 // 4. Optional rtl.css stylesheet
6182ab4d 93 if ($text_direction == 'rtl') {
94 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
95 }
62f7daa5 96
e842b215 97 if ($squirrelmail_language == 'ja_JP') {
683b7853 98 /*
cbd8c251 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.
104 */
b8292491 105 $header_tags .= "<!-- \xfd\xfe -->\n";
106 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
e842b215 107 }
237470b4 108 if ($do_hook) {
b8292491 109 // NOTE! plugins here must assign output to template
110 // and NOT echo anything directly!!
d68323ff 111 do_hook('generic_header');
237470b4 112 }
62f7daa5 113
b8292491 114 $header_tags .= $xtra;
115 $oTemplate->assign('page_title', $title);
5ca4b1ee 116
117 /* work around IE6's scrollbar bug */
b8292491 118 $header_tags .= <<<EOS
292a9c32 119<!--[if IE 6]>
5ca4b1ee 120<style type="text/css">
5fe8257d 121/* avoid stupid IE6 bug with frames and scrollbars */
122body {
5fe8257d 123 width: expression(document.documentElement.clientWidth - 30);
124}
5ca4b1ee 125</style>
292a9c32 126<![endif]-->
5ca4b1ee 127
b8292491 128EOS;
5ca4b1ee 129
b8292491 130 $oTemplate->assign('header_tags', $header_tags);
131 $oTemplate->display('protocol_header.tpl');
b6c283c4 132
133 /* this is used to check elsewhere whether we should call this function */
134 $pageheader_sent = TRUE;
81de00c0 135 if (isset($oErrorHandler)) {
e6c4caae 136 $oErrorHandler->HeaderSent();
81de00c0 137 }
b8292491 138
a07cd1a4 139}
140
8b096f0a 141/**
142 * Given a path to a SquirrelMail file, return a HTML link to it
143 *
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
147 */
d62c4938 148function makeInternalLink($path, $text, $target='') {
202bcbcc 149 global $base_uri;
150// sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
dcc1cc82 151 if ($target != '') {
152 $target = " target=\"$target\"";
153 }
4910106a 154
e50f5ac2 155 // This is an inefficient hook and is only used by
4910106a 156 // one plugin that still needs to patch this code,
e50f5ac2 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?)
4910106a 160 // use for the internal_link hook.
161 //
162 //$hooktext = do_hook_function('internal_link',$text);
163 //if ($hooktext != '')
164 // $text = $hooktext;
165
d62c4938 166 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
167}
168
8b096f0a 169/**
170 * Same as makeInternalLink, but echoes it too
171 */
d62c4938 172function displayInternalLink($path, $text, $target='') {
b8292491 173// FIXME: should let the template echo all these kinds of things
b26d81e5 174 echo makeInternalLink($path, $text, $target);
a07cd1a4 175}
176
8b096f0a 177/**
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.
181 *
182 * @param array color the array of theme colors
183 * @param string mailbox the current mailbox name to display
91c27aee 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
8b096f0a 186 * @return void
187 */
715225af 188
10bf80c0 189function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
190
191 global $reply_focus, $hide_sm_attributions, $frame_top,
5fe8257d 192 $provider_name, $provider_uri, $startMessage,
193 $javascript_on, $action, $oTemplate;
10bf80c0 194
195 if (empty($sBodyTagJs)) {
196 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 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();"';
10bf80c0 203 }
204 else
5fe8257d 205 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 206 }
207
5fe8257d 208 $urlMailbox = urlencode($mailbox);
209 $startMessage = (int)$startMessage;
210
0365891c 211 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
91c27aee 212
d03f3582 213 if (!isset($frame_top)) {
214 $frame_top = '_top';
215 }
715225af 216
c18f58c5 217 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
b8292491 218 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 219 $sJsBlock = '';
220 foreach ($js_includes as $js_file) {
221 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
222 }
91c27aee 223 if ($sHeaderJs) {
2c92ea9d 224 $sJsBlock .= "\n<script type=\"text/javascript\">" .
91c27aee 225 "\n<!--\n" .
a3d59ec3 226 $sHeaderJs . "\n\n// -->\n</script>\n";
d62c4938 227 }
91c27aee 228 displayHtmlHeader ('SquirrelMail', $sJsBlock);
5fe8257d 229 } else {
d62c4938 230 /* do not use JavaScript */
231 displayHtmlHeader ('SquirrelMail');
91c27aee 232 $sBodyTagJs = '';
715225af 233 }
202bcbcc 234 /*
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.
237 */
72520f77 238 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
91e0dccc 239 readShortMailboxName($mailbox, $delimiter)));
3b7d68e6 240 if ( $shortBoxName == 'INBOX' ) {
7da23762 241 $shortBoxName = _("INBOX");
242 }
0493ed11 243
5fe8257d 244 $sm_attributes = '';
245 if (!$hide_sm_attributions) {
246 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
8b5c49cd 247 if (empty($provider_uri)) {
5fe8257d 248 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
8b5c49cd 249 } else {
250 if (empty($provider_name)) $provider_name= 'SquirrelMail';
5fe8257d 251 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
8b5c49cd 252 }
5fe8257d 253 $sm_attributes .= " </td>\n";
99ea51d3 254 }
5fe8257d 255
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');
a07cd1a4 264}
2ba13803 265
8b096f0a 266/**
267 * Blatantly copied/truncated/modified from displayPageHeader.
268 * Outputs a page header specifically for the compose_in_new popup window
269 *
270 * @param array color the array of theme colors
271 * @param string mailbox the current mailbox name to display
91c27aee 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
8b096f0a 274 * @return void
275 */
10bf80c0 276function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
277
6373ad12 278 global $reply_focus, $javascript_on, $action, $oTemplate;
10bf80c0 279
280 if (empty($sBodyTagJs)) {
281 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
5fe8257d 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();"';
10bf80c0 288 }
289 else
5fe8257d 290 $sBodyTagJs = 'onload="checkForm();"';
10bf80c0 291 }
292
293
9c3e6cd4 294 /*
d62c4938 295 * Locate the first displayable form element (only when JavaScript on)
296 */
297 if($javascript_on) {
91c27aee 298 if ($sHeaderJs) {
2c92ea9d 299 $sJsBlock = "\n<script type=\"text/javascript\">" .
91c27aee 300 "\n<!--\n" .
a3d59ec3 301 $sHeaderJs . "\n\n// -->\n</script>\n";
91c27aee 302 } else {
5fe8257d 303 $sJsBlock = '';
d62c4938 304 }
6373ad12 305 $sJsBlock .= "\n";
306
b8292491 307 $js_includes = $oTemplate->get_javascript_includes(TRUE);
6373ad12 308 foreach ($js_includes as $js_file) {
309 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
310 }
311
91c27aee 312 displayHtmlHeader (_("Compose"), $sJsBlock);
d62c4938 313 } else {
314 /* javascript off */
315 displayHtmlHeader(_("Compose"));
316 $onload = '';
9c3e6cd4 317 }
b8292491 318// FIXME: should let the template echo all these kinds of things
91c27aee 319 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
9c3e6cd4 320}