Allow makeInternalLink() and makeComposeLink() to accomodate access keys
[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-2007 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='') {
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 (empty($accesskey) ? array() : array('accesskey' => $accesskey)));
191 }
192
193 /**
194 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
195 * including the default menu bar. Uses displayHtmlHeader and takes
196 * JavaScript and locale settings into account.
197 *
198 * @param array color the array of theme colors
199 * @param string mailbox the current mailbox name to display
200 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
201 * @param string sOnload JavaScript code to be added inside the body's onload handler
202 * as of 1.5.2, this replaces $sBodyTagJs argument
203 * @return void
204 */
205 function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sOnload = '') {
206
207 global $reply_focus, $hide_sm_attributions, $frame_top,
208 $provider_name, $provider_uri, $startMessage,
209 $action, $oTemplate, $org_title, $base_uri,
210 $data_dir, $username;
211
212 if (empty($sOnload)) {
213 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
214 if ($reply_focus == 'select')
215 $sOnload = 'checkForm(\'select\');';
216 else if ($reply_focus == 'focus')
217 $sOnload = 'checkForm(\'focus\');';
218 else if ($reply_focus != 'none')
219 $sOnload = 'checkForm();';
220 }
221 else
222 $sOnload = 'checkForm();';
223 }
224
225 $startMessage = (int)$startMessage;
226
227 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
228
229 if (!isset($frame_top)) {
230 $frame_top = '_top';
231 }
232
233 //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...(?))
234 if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
235 $js_includes = $oTemplate->get_javascript_includes(TRUE);
236 $sJsBlock = '';
237 foreach ($js_includes as $js_file) {
238 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
239 }
240 if ($sHeaderJs) {
241 $sJsBlock .= "\n<script type=\"text/javascript\">" .
242 "\n<!--\n" .
243 $sHeaderJs . "\n\n// -->\n</script>\n";
244 }
245 displayHtmlHeader ($org_title, $sJsBlock);
246 } else {
247 /* do not use JavaScript */
248 displayHtmlHeader ($org_title);
249 $sOnload = '';
250 }
251 if ($mailbox) {
252 /*
253 * this explains the imap_mailbox.php dependency. We should instead store
254 * the selected mailbox in the session and fallback to the session var.
255 */
256 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
257 readShortMailboxName($mailbox, $delimiter)));
258 if (getPref($data_dir, $username, 'translate_special_folders')) {
259 $shortBoxName = _($shortBoxName);
260 }
261 $urlMailbox = urlencode($mailbox);
262 } else {
263 $shortBoxName = '';
264 $urlMailbox = '';
265 }
266
267 $provider_link = '';
268 if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
269 $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
270 }
271
272 $oTemplate->assign('onload', $sOnload);
273 $oTemplate->assign('shortBoxName', $shortBoxName);
274 $oTemplate->assign('provider_link', $provider_link);
275 $oTemplate->assign('frame_top', $frame_top);
276 $oTemplate->assign('urlMailbox', $urlMailbox);
277 $oTemplate->assign('startMessage', $startMessage);
278 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
279 $oTemplate->display('page_header.tpl');
280
281 global $null;
282 do_hook('page_header_bottom', $null);
283 }
284
285 /**
286 * Blatantly copied/truncated/modified from displayPageHeader.
287 * Outputs a page header specifically for the compose_in_new popup window
288 *
289 * @param array color the array of theme colors
290 * @param string mailbox the current mailbox name to display
291 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
292 * @param string sOnload JavaScript code to be added inside the body's onload handler
293 * as of 1.5.2, this replaces $sBodyTagJs argument
294 * @return void
295 */
296 function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
297
298 global $reply_focus, $action, $oTemplate;
299
300 if (empty($sOnload)) {
301 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
302 if ($reply_focus == 'select')
303 $sOnload = 'checkForm(\'select\');';
304 else if ($reply_focus == 'focus')
305 $sOnload = 'checkForm(\'focus\');';
306 else if ($reply_focus != 'none')
307 $sOnload = 'checkForm();';
308 }
309 else
310 $sOnload = 'checkForm();';
311 }
312
313
314 /*
315 * Locate the first displayable form element (only when JavaScript on)
316 */
317 if(checkForJavascript()) {
318 if ($sHeaderJs) {
319 $sJsBlock = "\n<script type=\"text/javascript\">" .
320 "\n<!--\n" .
321 $sHeaderJs . "\n\n// -->\n</script>\n";
322 } else {
323 $sJsBlock = '';
324 }
325 $sJsBlock .= "\n";
326
327 $js_includes = $oTemplate->get_javascript_includes(TRUE);
328 foreach ($js_includes as $js_file) {
329 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
330 }
331
332 displayHtmlHeader (_("Compose"), $sJsBlock);
333 } else {
334 /* javascript off */
335 displayHtmlHeader(_("Compose"));
336 $sOnload = '';
337 }
338
339 // FIXME: change the colorization attributes below to a CSS class!
340 $class = '';
341 $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
342 'link' => $color[7], 'vlink' => $color[7],
343 'alink' => $color[7]);
344
345 // this is template-safe (see create_body() function)
346 echo create_body($sOnload, $class, $aAttribs);
347
348 global $null;
349 do_hook('compose_header_bottom', $null);
350 }