beafbdb6a707adc7702a32777795cc20dd49c998
[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 $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 /**
78 * Stylesheets beginning with a "u_" == user provided stylesheets, e.g. those
79 * in SM_PATH/css/. Template provided stylesheets (TEMPLATE_DIR/css/alternatives/)
80 * should begin with 't_'. This was the initial path I took to get it working
81 * since I wasn't sure what mods to the Template class would be used to handle
82 * template-provided alt stylesheets.
83 *
84 * TODO: Re-evaluate this naming convetion.
85 */
86 if (!empty($chosen_theme) && substr($chosen_theme, 0, 2) == 'u_') {
87 $aUserStyles[] = substr($chosen_theme, 2) .'default.css';
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 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
95
96 // 4. Optional rtl.css stylesheet
97 if ($text_direction == 'rtl') {
98 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
99 }
100
101 if ($squirrelmail_language == 'ja_JP') {
102 /*
103 * force correct detection of charset, when browser does not follow
104 * http content-type and tries to detect charset from page content.
105 * Shooting of browser's creator can't be implemented in php.
106 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
107 * recommendations and switch to unicode.
108 */
109 $header_tags .= "<!-- \xfd\xfe -->\n";
110 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
111 }
112 if ($do_hook) {
113 // NOTE! plugins here must assign output to template
114 // and NOT echo anything directly!!
115 do_hook('generic_header');
116 }
117
118 $header_tags .= $xtra;
119 $oTemplate->assign('page_title', $title);
120
121 /* work around IE6's scrollbar bug */
122 $header_tags .= <<<EOS
123 <!--[if IE 6]>
124 <style type="text/css">
125 /* avoid stupid IE6 bug with frames and scrollbars */
126 body {
127 width: expression(document.documentElement.clientWidth - 30);
128 }
129 </style>
130 <![endif]-->
131
132 EOS;
133
134 $oTemplate->assign('header_tags', $header_tags);
135 $oTemplate->display('protocol_header.tpl');
136
137 /* this is used to check elsewhere whether we should call this function */
138 $pageheader_sent = TRUE;
139 if (isset($oErrorHandler)) {
140 $oErrorHandler->HeaderSent();
141 }
142
143 }
144
145 /**
146 * Given a path to a SquirrelMail file, return a HTML link to it
147 *
148 * @param string path the SquirrelMail file to link to
149 * @param string text the link text
150 * @param string target the target frame for this link
151 */
152 function makeInternalLink($path, $text, $target='') {
153 global $base_uri;
154 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
155 if ($target != '') {
156 $target = " target=\"$target\"";
157 }
158
159 // This is an inefficient hook and is only used by
160 // one plugin that still needs to patch this code,
161 // plus if we are templat-izing SM, visual hooks
162 // are not needed. However, I am leaving the code
163 // here just in case we find a good (non-visual?)
164 // use for the internal_link hook.
165 //
166 //$hooktext = do_hook_function('internal_link',$text);
167 //if ($hooktext != '')
168 // $text = $hooktext;
169
170 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
171 }
172
173 /**
174 * Same as makeInternalLink, but echoes it too
175 */
176 function displayInternalLink($path, $text, $target='') {
177 // FIXME: should let the template echo all these kinds of things
178 echo makeInternalLink($path, $text, $target);
179 }
180
181 /**
182 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
183 * including the default menu bar. Uses displayHtmlHeader and takes
184 * JavaScript and locale settings into account.
185 *
186 * @param array color the array of theme colors
187 * @param string mailbox the current mailbox name to display
188 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
189 * @param string sBodyTagJs js events to be inserted in the body tag
190 * @return void
191 */
192
193 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
194
195 global $reply_focus, $hide_sm_attributions, $frame_top,
196 $provider_name, $provider_uri, $startMessage,
197 $javascript_on, $action, $oTemplate;
198
199 if (empty($sBodyTagJs)) {
200 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
201 if ($reply_focus == 'select')
202 $sBodyTagJs = 'onload="checkForm(\'select\');"';
203 else if ($reply_focus == 'focus')
204 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
205 else if ($reply_focus != 'none')
206 $sBodyTagJs = 'onload="checkForm();"';
207 }
208 else
209 $sBodyTagJs = 'onload="checkForm();"';
210 }
211
212 $urlMailbox = urlencode($mailbox);
213 $startMessage = (int)$startMessage;
214
215 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
216
217 if (!isset($frame_top)) {
218 $frame_top = '_top';
219 }
220
221 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
222 $js_includes = $oTemplate->get_javascript_includes(TRUE);
223 $sJsBlock = '';
224 foreach ($js_includes as $js_file) {
225 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
226 }
227 if ($sHeaderJs) {
228 $sJsBlock .= "\n<script type=\"text/javascript\">" .
229 "\n<!--\n" .
230 $sHeaderJs . "\n\n// -->\n</script>\n";
231 }
232 displayHtmlHeader ('SquirrelMail', $sJsBlock);
233 } else {
234 /* do not use JavaScript */
235 displayHtmlHeader ('SquirrelMail');
236 $sBodyTagJs = '';
237 }
238 /*
239 * this explains the imap_mailbox.php dependency. We should instead store
240 * the selected mailbox in the session and fallback to the session var.
241 */
242 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
243 readShortMailboxName($mailbox, $delimiter)));
244 if ( $shortBoxName == 'INBOX' ) {
245 $shortBoxName = _("INBOX");
246 }
247
248 $sm_attributes = '';
249 if (!$hide_sm_attributions) {
250 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
251 if (empty($provider_uri)) {
252 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
253 } else {
254 if (empty($provider_name)) $provider_name= 'SquirrelMail';
255 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
256 }
257 $sm_attributes .= " </td>\n";
258 }
259
260 $oTemplate->assign('body_tag_js', $sBodyTagJs);
261 $oTemplate->assign('shortBoxName', $shortBoxName);
262 $oTemplate->assign('sm_attribute_str', $sm_attributes);
263 $oTemplate->assign('frame_top', $frame_top);
264 $oTemplate->assign('urlMailbox', $urlMailbox);
265 $oTemplate->assign('startMessage', $startMessage);
266 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
267 $oTemplate->display('page_header.tpl');
268 }
269
270 /**
271 * Blatantly copied/truncated/modified from displayPageHeader.
272 * Outputs a page header specifically for the compose_in_new popup window
273 *
274 * @param array color the array of theme colors
275 * @param string mailbox the current mailbox name to display
276 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
277 * @param string sBodyTagJs js events to be inserted in the body tag
278 * @return void
279 */
280 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
281
282 global $reply_focus, $javascript_on, $action, $oTemplate;
283
284 if (empty($sBodyTagJs)) {
285 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
286 if ($reply_focus == 'select')
287 $sBodyTagJs = 'onload="checkForm(\'select\');"';
288 else if ($reply_focus == 'focus')
289 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
290 else if ($reply_focus != 'none')
291 $sBodyTagJs = 'onload="checkForm();"';
292 }
293 else
294 $sBodyTagJs = 'onload="checkForm();"';
295 }
296
297
298 /*
299 * Locate the first displayable form element (only when JavaScript on)
300 */
301 if($javascript_on) {
302 if ($sHeaderJs) {
303 $sJsBlock = "\n<script type=\"text/javascript\">" .
304 "\n<!--\n" .
305 $sHeaderJs . "\n\n// -->\n</script>\n";
306 } else {
307 $sJsBlock = '';
308 }
309 $sJsBlock .= "\n";
310
311 $js_includes = $oTemplate->get_javascript_includes(TRUE);
312 foreach ($js_includes as $js_file) {
313 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
314 }
315
316 displayHtmlHeader (_("Compose"), $sJsBlock);
317 } else {
318 /* javascript off */
319 displayHtmlHeader(_("Compose"));
320 $onload = '';
321 }
322 // FIXME: should let the template echo all these kinds of things
323 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
324 }