a08c5e5fff0660fbd864d59878473bd21b5b3bcd
[squirrelmail.git] / functions / page_header.php
1 <?php
2
3 /**
4 * page_header.php
5 *
6 * Prints the page header (duh)
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** Include required files from SM */
15 include_once(SM_PATH . 'functions/imap_mailbox.php');
16
17 /**
18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
20 *
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)
27 * @return void
28 */
29 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
30 global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
31
32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
33 global $base_uri;
34 }
35 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
37
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)
42
43 $oTemplate->assign('frames', $frames);
44 $oTemplate->assign('lang', $squirrelmail_language);
45
46 $header_tags = '';
47
48 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
49
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');
53
54 /**
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
60 * Preferences.
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
63 * template set.
64 */
65
66 // 1. Stylesheets from the template.
67 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
68
69 $aUserStyles = array();
70
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?
77 if (!empty($chosen_theme) && substr($chosen_theme, 0, 2) == 'u_') {
78 $aUserStyles[] = substr($chosen_theme, 2) .'default.css';
79 }
80
81 // 3. src/style.php
82 $aUserStyles[] = $base_uri .'src/style.php?'
83 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
84 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
85 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
86
87 // 4. Optional rtl.css stylesheet
88 if ($text_direction == 'rtl') {
89 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
90 }
91
92 if ($squirrelmail_language == 'ja_JP') {
93 /*
94 * force correct detection of charset, when browser does not follow
95 * http content-type and tries to detect charset from page content.
96 * Shooting of browser's creator can't be implemented in php.
97 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
98 * recommendations and switch to unicode.
99 */
100 $header_tags .= "<!-- \xfd\xfe -->\n";
101 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
102 }
103 if ($do_hook) {
104 // NOTE! plugins here must assign output to template
105 // and NOT echo anything directly!!
106 do_hook('generic_header');
107 }
108
109 $header_tags .= $xtra;
110 $oTemplate->assign('page_title', $title);
111
112 /* work around IE6's scrollbar bug */
113 $header_tags .= <<<EOS
114 <!--[if IE 6]>
115 <style type="text/css">
116 /* avoid stupid IE6 bug with frames and scrollbars */
117 body {
118 width: expression(document.documentElement.clientWidth - 30);
119 }
120 </style>
121 <![endif]-->
122
123 EOS;
124
125 $oTemplate->assign('header_tags', $header_tags);
126 $oTemplate->display('protocol_header.tpl');
127
128 /* this is used to check elsewhere whether we should call this function */
129 $pageheader_sent = TRUE;
130 if (isset($oErrorHandler)) {
131 $oErrorHandler->HeaderSent();
132 }
133
134 }
135
136 /**
137 * Given a path to a SquirrelMail file, return a HTML link to it
138 *
139 * @param string path the SquirrelMail file to link to
140 * @param string text the link text
141 * @param string target the target frame for this link
142 */
143 function makeInternalLink($path, $text, $target='') {
144 global $base_uri;
145 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
146 if ($target != '') {
147 $target = " target=\"$target\"";
148 }
149
150 // This is an inefficient hook and is only used by
151 // one plugin that still needs to patch this code,
152 // plus if we are templat-izing SM, visual hooks
153 // are not needed. However, I am leaving the code
154 // here just in case we find a good (non-visual?)
155 // use for the internal_link hook.
156 //
157 //$hooktext = do_hook_function('internal_link',$text);
158 //if ($hooktext != '')
159 // $text = $hooktext;
160
161 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
162 }
163
164 /**
165 * Same as makeInternalLink, but echoes it too
166 */
167 function displayInternalLink($path, $text, $target='') {
168 // FIXME: should let the template echo all these kinds of things
169 echo makeInternalLink($path, $text, $target);
170 }
171
172 /**
173 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
174 * including the default menu bar. Uses displayHtmlHeader and takes
175 * JavaScript and locale settings into account.
176 *
177 * @param array color the array of theme colors
178 * @param string mailbox the current mailbox name to display
179 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
180 * @param string sBodyTagJs js events to be inserted in the body tag
181 * @return void
182 */
183
184 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
185
186 global $reply_focus, $hide_sm_attributions, $frame_top,
187 $provider_name, $provider_uri, $startMessage,
188 $javascript_on, $action, $oTemplate;
189
190 if (empty($sBodyTagJs)) {
191 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
192 if ($reply_focus == 'select')
193 $sBodyTagJs = 'onload="checkForm(\'select\');"';
194 else if ($reply_focus == 'focus')
195 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
196 else if ($reply_focus != 'none')
197 $sBodyTagJs = 'onload="checkForm();"';
198 }
199 else
200 $sBodyTagJs = 'onload="checkForm();"';
201 }
202
203 $urlMailbox = urlencode($mailbox);
204 $startMessage = (int)$startMessage;
205
206 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
207
208 if (!isset($frame_top)) {
209 $frame_top = '_top';
210 }
211
212 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
213 $js_includes = $oTemplate->get_javascript_includes(TRUE);
214 $sJsBlock = '';
215 foreach ($js_includes as $js_file) {
216 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
217 }
218 if ($sHeaderJs) {
219 $sJsBlock .= "\n<script type=\"text/javascript\">" .
220 "\n<!--\n" .
221 $sHeaderJs . "\n\n// -->\n</script>\n";
222 }
223 displayHtmlHeader ('SquirrelMail', $sJsBlock);
224 } else {
225 /* do not use JavaScript */
226 displayHtmlHeader ('SquirrelMail');
227 $sBodyTagJs = '';
228 }
229 /*
230 * this explains the imap_mailbox.php dependency. We should instead store
231 * the selected mailbox in the session and fallback to the session var.
232 */
233 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
234 readShortMailboxName($mailbox, $delimiter)));
235 if ( $shortBoxName == 'INBOX' ) {
236 $shortBoxName = _("INBOX");
237 }
238
239 $sm_attributes = '';
240 if (!$hide_sm_attributions) {
241 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
242 if (empty($provider_uri)) {
243 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
244 } else {
245 if (empty($provider_name)) $provider_name= 'SquirrelMail';
246 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
247 }
248 $sm_attributes .= " </td>\n";
249 }
250
251 $oTemplate->assign('body_tag_js', $sBodyTagJs);
252 $oTemplate->assign('shortBoxName', $shortBoxName);
253 $oTemplate->assign('sm_attribute_str', $sm_attributes);
254 $oTemplate->assign('frame_top', $frame_top);
255 $oTemplate->assign('urlMailbox', $urlMailbox);
256 $oTemplate->assign('startMessage', $startMessage);
257 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
258 $oTemplate->display('page_header.tpl');
259 }
260
261 /**
262 * Blatantly copied/truncated/modified from displayPageHeader.
263 * Outputs a page header specifically for the compose_in_new popup window
264 *
265 * @param array color the array of theme colors
266 * @param string mailbox the current mailbox name to display
267 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
268 * @param string sBodyTagJs js events to be inserted in the body tag
269 * @return void
270 */
271 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
272
273 global $reply_focus, $javascript_on, $action, $oTemplate;
274
275 if (empty($sBodyTagJs)) {
276 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
277 if ($reply_focus == 'select')
278 $sBodyTagJs = 'onload="checkForm(\'select\');"';
279 else if ($reply_focus == 'focus')
280 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
281 else if ($reply_focus != 'none')
282 $sBodyTagJs = 'onload="checkForm();"';
283 }
284 else
285 $sBodyTagJs = 'onload="checkForm();"';
286 }
287
288
289 /*
290 * Locate the first displayable form element (only when JavaScript on)
291 */
292 if($javascript_on) {
293 if ($sHeaderJs) {
294 $sJsBlock = "\n<script type=\"text/javascript\">" .
295 "\n<!--\n" .
296 $sHeaderJs . "\n\n// -->\n</script>\n";
297 } else {
298 $sJsBlock = '';
299 }
300 $sJsBlock .= "\n";
301
302 $js_includes = $oTemplate->get_javascript_includes(TRUE);
303 foreach ($js_includes as $js_file) {
304 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
305 }
306
307 displayHtmlHeader (_("Compose"), $sJsBlock);
308 } else {
309 /* javascript off */
310 displayHtmlHeader(_("Compose"));
311 $onload = '';
312 }
313 // FIXME: should let the template echo all these kinds of things
314 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
315 }