6411c6e1d0254f99cc61bda439bac026421a5b80
[squirrelmail.git] / functions / page_header.php
1 <?php
2
3 /**
4 * page_header.php
5 *
6 * Prints the page header (duh)
7 *
8 * @copyright 1999-2009 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 $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;
38
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)
43
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);
47
48 $oTemplate->assign('frames', $frames);
49 $oTemplate->assign('lang', $squirrelmail_language);
50
51 $header_tags = '';
52
53 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n";
54
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;
58
59 /**
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
65 * Preferences.
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
68 * template set.
69 */
70
71 // 1. Stylesheets from the template.
72 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
73
74 $aUserStyles = array();
75
76 // 2. Option user-defined stylesheet from preferences.
77 if (!empty($used_theme) && $used_theme != 'none') {
78 /**
79 * All styles (except "none" - ugh) just point to a directory,
80 * so we need to include all .css files in that directory.
81 */
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;
87 }
88 }
89
90 // 3. src/style.php
91 $aUserStyles[] = $base_uri .'src/style.php?'
92 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
93 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
94
95 // 3.1. Load the stylesheets we have already
96 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
97
98 // 4. Optional rtl.css stylesheet
99 if ($text_direction == 'rtl') {
100 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
101 }
102
103 // 5. Printer friendly stylesheet
104 $header_tags .= create_css_link($base_uri . 'css/print.css', 'printerfriendly', false, 'print');
105
106 if ($squirrelmail_language == 'ja_JP') {
107 /*
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.
113 */
114 $header_tags .= "<!-- \xfd\xfe -->\n";
115 $header_tags .= '<meta http-equiv="Content-type" content="' . $oTemplate->get_content_type() . '; charset=euc-jp" />' . "\n";
116 }
117 if ($do_hook) {
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.
127 ob_start();
128 $temp = array(&$header_tags);
129 do_hook('generic_header', $temp);
130 $output = ob_get_contents();
131 ob_end_clean();
132 // plugin authors can debug their errors with one of the following:
133 //sm_print_r($output);
134 //echo $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);
136 }
137
138 $header_tags .= $xtra;
139 $oTemplate->assign('page_title', $title);
140
141 /* work around IE6's scrollbar bug */
142 $header_tags .= <<<EOS
143 <!--[if IE 6]>
144 <style type="text/css">
145 /* avoid stupid IE6 bug with frames and scrollbars */
146 body {
147 width: expression(document.documentElement.clientWidth - 30);
148 }
149 </style>
150 <![endif]-->
151
152 EOS;
153
154 $oTemplate->assign('header_tags', $header_tags);
155 $oTemplate->display('protocol_header.tpl');
156
157 /* this is used to check elsewhere whether we should call this function */
158 $pageheader_sent = TRUE;
159 if (isset($oErrorHandler)) {
160 $oErrorHandler->HeaderSent();
161 }
162
163 }
164
165 /**
166 * Given a path to a SquirrelMail file, return a HTML link to it
167 *
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
173 * @param string $accesskey The access key to be used, if any
174 */
175 function makeInternalLink($path, $text, $target='', $accesskey='NONE') {
176 global $base_uri, $oTemplate;
177 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
178
179 // This is an inefficient hook and is only used by
180 // one plugin that still needs to patch this code,
181 // plus if we are templat-izing SM, visual hooks
182 // are not needed. However, I am leaving the code
183 // here just in case we find a good (non-visual?)
184 // use for the internal_link hook.
185 //
186 //do_hook('internal_link', $text);
187
188 return create_hyperlink($base_uri . $path, $text, $target,
189 '', '', '', '',
190 ($accesskey == 'NONE'
191 ? array()
192 : array('accesskey' => $accesskey)));
193 }
194
195 /**
196 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
197 * including the default menu bar. Uses displayHtmlHeader and takes
198 * JavaScript and locale settings into account.
199 *
200 * @param array color the array of theme colors
201 * @param string mailbox the current mailbox name to display
202 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
203 * @param string sOnload JavaScript code to be added inside the body's onload handler
204 * as of 1.5.2, this replaces $sBodyTagJs argument
205 * @return void
206 */
207 function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sOnload = '') {
208
209 global $reply_focus, $hide_sm_attributions, $frame_top,
210 $provider_name, $provider_uri, $startMessage,
211 $action, $oTemplate, $org_title, $base_uri,
212 $data_dir, $username;
213
214 if (empty($sOnload)) {
215 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
216 if ($reply_focus == 'select')
217 $sOnload = 'checkForm(\'select\');';
218 else if ($reply_focus == 'focus')
219 $sOnload = 'checkForm(\'focus\');';
220 else if ($reply_focus != 'none')
221 $sOnload = 'checkForm();';
222 }
223 else
224 $sOnload = 'checkForm();';
225 }
226
227 $startMessage = (int)$startMessage;
228
229 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
230
231 if (!isset($frame_top)) {
232 $frame_top = '_top';
233 }
234
235 //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...(?))
236 if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
237 $js_includes = $oTemplate->get_javascript_includes(TRUE);
238 $sJsBlock = '';
239 foreach ($js_includes as $js_file) {
240 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
241 }
242 if ($sHeaderJs) {
243 $sJsBlock .= "\n<script type=\"text/javascript\">" .
244 "\n<!--\n" .
245 $sHeaderJs . "\n\n// -->\n</script>\n";
246 }
247 displayHtmlHeader ($org_title, $sJsBlock);
248 } else {
249 /* do not use JavaScript */
250 displayHtmlHeader ($org_title);
251 $sOnload = '';
252 }
253 if ($mailbox) {
254 /*
255 * this explains the imap_mailbox.php dependency. We should instead store
256 * the selected mailbox in the session and fallback to the session var.
257 */
258 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
259 readShortMailboxName($mailbox, $delimiter)));
260 if (getPref($data_dir, $username, 'translate_special_folders')) {
261 global $sent_folder, $trash_folder, $draft_folder;
262 if ($mailbox == $sent_folder)
263 $shortBoxName = _("Sent");
264 else if ($mailbox == $trash_folder)
265 $shortBoxName = _("Trash");
266 else if ($mailbox == $sent_folder)
267 $shortBoxName = _("Drafts");
268 }
269 $urlMailbox = urlencode($mailbox);
270 } else {
271 $shortBoxName = '';
272 $urlMailbox = '';
273 }
274
275 $provider_link = '';
276 if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
277 $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
278 }
279
280 $oTemplate->assign('onload', $sOnload);
281 $oTemplate->assign('shortBoxName', $shortBoxName);
282 $oTemplate->assign('provider_link', $provider_link);
283 $oTemplate->assign('frame_top', $frame_top);
284 $oTemplate->assign('urlMailbox', $urlMailbox);
285 $oTemplate->assign('startMessage', $startMessage);
286 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
287
288 // access keys
289 //
290 global $accesskey_menubar_compose, $accesskey_menubar_addresses,
291 $accesskey_menubar_folders, $accesskey_menubar_options,
292 $accesskey_menubar_search, $accesskey_menubar_help,
293 $accesskey_menubar_signout;
294 $oTemplate->assign('accesskey_menubar_compose', $accesskey_menubar_compose);
295 $oTemplate->assign('accesskey_menubar_addresses', $accesskey_menubar_addresses);
296 $oTemplate->assign('accesskey_menubar_folders', $accesskey_menubar_folders);
297 $oTemplate->assign('accesskey_menubar_options', $accesskey_menubar_options);
298 $oTemplate->assign('accesskey_menubar_search', $accesskey_menubar_search);
299 $oTemplate->assign('accesskey_menubar_help', $accesskey_menubar_help);
300 $oTemplate->assign('accesskey_menubar_signout', $accesskey_menubar_signout);
301
302 $oTemplate->display('page_header.tpl');
303
304 global $null;
305 do_hook('page_header_bottom', $null);
306 }
307
308 /**
309 * Blatantly copied/truncated/modified from displayPageHeader.
310 * Outputs a page header specifically for the compose_in_new popup window
311 *
312 * @param array color the array of theme colors
313 * @param string mailbox the current mailbox name to display
314 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
315 * @param string sOnload JavaScript code to be added inside the body's onload handler
316 * as of 1.5.2, this replaces $sBodyTagJs argument
317 * @return void
318 */
319 function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
320
321 global $reply_focus, $action, $oTemplate;
322
323 if (empty($sOnload)) {
324 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
325 if ($reply_focus == 'select')
326 $sOnload = 'checkForm(\'select\');';
327 else if ($reply_focus == 'focus')
328 $sOnload = 'checkForm(\'focus\');';
329 else if ($reply_focus != 'none')
330 $sOnload = 'checkForm();';
331 }
332 else
333 $sOnload = 'checkForm();';
334 }
335
336
337 /*
338 * Locate the first displayable form element (only when JavaScript on)
339 */
340 if(checkForJavascript()) {
341 if ($sHeaderJs) {
342 $sJsBlock = "\n<script type=\"text/javascript\">" .
343 "\n<!--\n" .
344 $sHeaderJs . "\n\n// -->\n</script>\n";
345 } else {
346 $sJsBlock = '';
347 }
348 $sJsBlock .= "\n";
349
350 $js_includes = $oTemplate->get_javascript_includes(TRUE);
351 foreach ($js_includes as $js_file) {
352 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
353 }
354
355 displayHtmlHeader (_("Compose"), $sJsBlock);
356 } else {
357 /* javascript off */
358 displayHtmlHeader(_("Compose"));
359 $sOnload = '';
360 }
361
362 // FIXME: change the colorization attributes below to a CSS class!
363 $class = '';
364 $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
365 'link' => $color[7], 'vlink' => $color[7],
366 'alink' => $color[7]);
367
368 // this is template-safe (see create_body() function)
369 echo create_body($sOnload, $class, $aAttribs);
370
371 global $null;
372 do_hook('compose_header_bottom', $null);
373 }