59177427 |
1 | <?php |
7350889b |
2 | |
35586184 |
3 | /** |
4 | * page_header.php |
5 | * |
35586184 |
6 | * Prints the page header (duh) |
7 | * |
4b5049de |
8 | * @copyright © 1999-2007 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 |
15 | include_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 |
29 | function 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 | |
1f2f93e6 |
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 | |
b8292491 |
48 | $oTemplate->assign('frames', $frames); |
49 | $oTemplate->assign('lang', $squirrelmail_language); |
50 | |
51 | $header_tags = ''; |
52 | |
b116fd78 |
53 | $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n"; |
2c21ef20 |
54 | |
d88941c7 |
55 | $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset); |
56 | $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize); |
8757c848 |
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; |
acd7fdf2 |
58 | |
d6a6f46b |
59 | /** |
60 | * Stylesheets are loaded in the following order: |
61 | * 1) All stylesheets provided by the template. Normally, these are |
e2048f8e |
62 | * stylsheets in templates/<template>/css/. This is accomplished by calling |
d6a6f46b |
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. |
e2048f8e |
69 | */ |
70 | |
d6a6f46b |
71 | // 1. Stylesheets from the template. |
b8292491 |
72 | $header_tags .= $oTemplate->fetch_standard_stylesheet_links(); |
d6a6f46b |
73 | |
b8292491 |
74 | $aUserStyles = array(); |
e2048f8e |
75 | |
d6a6f46b |
76 | // 2. Option user-defined stylesheet from preferences. |
cd81f956 |
77 | if (!empty($used_theme) && $used_theme != 'none') { |
83fc5c5e |
78 | /** |
2d2acf5e |
79 | * All styles (except "none" - ugh) just point to a directory, |
80 | * so we need to include all .css files in that directory. |
83fc5c5e |
81 | */ |
2d2acf5e |
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'); |
8757c848 |
85 | foreach ($styles as $sheet) { |
86 | $aUserStyles[] = $used_theme .'/'.$sheet; |
f9376f0b |
87 | } |
deb25c8f |
88 | } |
d6a6f46b |
89 | |
90 | // 3. src/style.php |
91 | $aUserStyles[] = $base_uri .'src/style.php?' |
b8292491 |
92 | . (!empty($used_fontset) ? '&fontset='.$used_fontset : '') |
d6a6f46b |
93 | . (!empty($used_fontsize) ? '&fontsize='.$used_fontsize : ''); |
f9376f0b |
94 | |
95 | // 3.1. Load the stylesheets we have already |
b8292491 |
96 | $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles); |
6182ab4d |
97 | |
d6a6f46b |
98 | // 4. Optional rtl.css stylesheet |
6182ab4d |
99 | if ($text_direction == 'rtl') { |
100 | $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link(); |
101 | } |
62f7daa5 |
102 | |
2ad37738 |
103 | // 5. Printer friendly stylesheet |
104 | $header_tags .= create_css_link($base_uri . 'css/print.css', 'printerfriendly', false, 'print'); |
105 | |
e842b215 |
106 | if ($squirrelmail_language == 'ja_JP') { |
683b7853 |
107 | /* |
cbd8c251 |
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 | */ |
b8292491 |
114 | $header_tags .= "<!-- \xfd\xfe -->\n"; |
0d56053e |
115 | $header_tags .= '<meta http-equiv="Content-type" content="' . $oTemplate->get_content_type() . '; charset=euc-jp" />' . "\n"; |
e842b215 |
116 | } |
237470b4 |
117 | if ($do_hook) { |
ed1c151d |
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. |
ed1c151d |
127 | ob_start(); |
c0071a26 |
128 | $temp = array(&$header_tags); |
129 | do_hook('generic_header', $temp); |
ed1c151d |
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); |
237470b4 |
136 | } |
62f7daa5 |
137 | |
b8292491 |
138 | $header_tags .= $xtra; |
139 | $oTemplate->assign('page_title', $title); |
5ca4b1ee |
140 | |
141 | /* work around IE6's scrollbar bug */ |
b8292491 |
142 | $header_tags .= <<<EOS |
292a9c32 |
143 | <!--[if IE 6]> |
5ca4b1ee |
144 | <style type="text/css"> |
5fe8257d |
145 | /* avoid stupid IE6 bug with frames and scrollbars */ |
146 | body { |
5fe8257d |
147 | width: expression(document.documentElement.clientWidth - 30); |
148 | } |
5ca4b1ee |
149 | </style> |
292a9c32 |
150 | <![endif]--> |
5ca4b1ee |
151 | |
b8292491 |
152 | EOS; |
5ca4b1ee |
153 | |
4bf6fc19 |
154 | $oTemplate->assign('header_tags', $header_tags); |
b8292491 |
155 | $oTemplate->display('protocol_header.tpl'); |
b6c283c4 |
156 | |
157 | /* this is used to check elsewhere whether we should call this function */ |
158 | $pageheader_sent = TRUE; |
81de00c0 |
159 | if (isset($oErrorHandler)) { |
e6c4caae |
160 | $oErrorHandler->HeaderSent(); |
81de00c0 |
161 | } |
b8292491 |
162 | |
a07cd1a4 |
163 | } |
164 | |
8b096f0a |
165 | /** |
166 | * Given a path to a SquirrelMail file, return a HTML link to it |
167 | * |
e740a582 |
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 |
8b096f0a |
174 | */ |
c12535f6 |
175 | function makeInternalLink($path, $text, $target='', $accesskey='NONE') { |
f7b996c3 |
176 | global $base_uri, $oTemplate; |
202bcbcc |
177 | // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
4910106a |
178 | |
e50f5ac2 |
179 | // This is an inefficient hook and is only used by |
4910106a |
180 | // one plugin that still needs to patch this code, |
e50f5ac2 |
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?) |
4910106a |
184 | // use for the internal_link hook. |
185 | // |
d849b570 |
186 | //do_hook('internal_link', $text); |
4910106a |
187 | |
e740a582 |
188 | return create_hyperlink($base_uri . $path, $text, $target, |
189 | '', '', '', '', |
c12535f6 |
190 | ($accesskey == 'NONE' |
191 | ? array() |
192 | : array('accesskey' => $accesskey))); |
d62c4938 |
193 | } |
194 | |
8b096f0a |
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 |
91c27aee |
202 | * @param string sHeaderJs javascipt code to be inserted in a script block in the header |
ca14ebb7 |
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 |
8b096f0a |
205 | * @return void |
206 | */ |
ca14ebb7 |
207 | function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sOnload = '') { |
10bf80c0 |
208 | |
209 | global $reply_focus, $hide_sm_attributions, $frame_top, |
5fe8257d |
210 | $provider_name, $provider_uri, $startMessage, |
d8ca5ea3 |
211 | $action, $oTemplate, $org_title, $base_uri, |
212 | $data_dir, $username; |
10bf80c0 |
213 | |
ca14ebb7 |
214 | if (empty($sOnload)) { |
10bf80c0 |
215 | if (strpos($action, 'reply') !== FALSE && $reply_focus) { |
ca14ebb7 |
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();'; |
10bf80c0 |
222 | } |
223 | else |
ca14ebb7 |
224 | $sOnload = 'checkForm();'; |
10bf80c0 |
225 | } |
226 | |
5fe8257d |
227 | $startMessage = (int)$startMessage; |
228 | |
0365891c |
229 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION ); |
91c27aee |
230 | |
d03f3582 |
231 | if (!isset($frame_top)) { |
232 | $frame_top = '_top'; |
233 | } |
715225af |
234 | |
ca14ebb7 |
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...(?)) |
83aff890 |
236 | if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) { |
b8292491 |
237 | $js_includes = $oTemplate->get_javascript_includes(TRUE); |
6373ad12 |
238 | $sJsBlock = ''; |
239 | foreach ($js_includes as $js_file) { |
240 | $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n"; |
241 | } |
91c27aee |
242 | if ($sHeaderJs) { |
2c92ea9d |
243 | $sJsBlock .= "\n<script type=\"text/javascript\">" . |
91c27aee |
244 | "\n<!--\n" . |
a3d59ec3 |
245 | $sHeaderJs . "\n\n// -->\n</script>\n"; |
d62c4938 |
246 | } |
e9e5a322 |
247 | displayHtmlHeader ($org_title, $sJsBlock); |
5fe8257d |
248 | } else { |
d62c4938 |
249 | /* do not use JavaScript */ |
e9e5a322 |
250 | displayHtmlHeader ($org_title); |
ca14ebb7 |
251 | $sOnload = ''; |
715225af |
252 | } |
d8ca5ea3 |
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 | $shortBoxName = _($shortBoxName); |
262 | } |
263 | $urlMailbox = urlencode($mailbox); |
264 | } else { |
265 | $shortBoxName = ''; |
266 | $urlMailbox = ''; |
7da23762 |
267 | } |
0493ed11 |
268 | |
5810acfa |
269 | $provider_link = ''; |
270 | if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') { |
271 | $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank'); |
99ea51d3 |
272 | } |
5fe8257d |
273 | |
ca14ebb7 |
274 | $oTemplate->assign('onload', $sOnload); |
5fe8257d |
275 | $oTemplate->assign('shortBoxName', $shortBoxName); |
4bf6fc19 |
276 | $oTemplate->assign('provider_link', $provider_link); |
5fe8257d |
277 | $oTemplate->assign('frame_top', $frame_top); |
278 | $oTemplate->assign('urlMailbox', $urlMailbox); |
279 | $oTemplate->assign('startMessage', $startMessage); |
280 | $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions); |
fbffe024 |
281 | |
282 | // access keys |
283 | // |
284 | global $accesskey_menubar_compose, $accesskey_menubar_addresses, |
285 | $accesskey_menubar_folders, $accesskey_menubar_options, |
286 | $accesskey_menubar_search, $accesskey_menubar_help, |
287 | $accesskey_menubar_signout; |
288 | $oTemplate->assign('accesskey_menubar_compose', $accesskey_menubar_compose); |
289 | $oTemplate->assign('accesskey_menubar_addresses', $accesskey_menubar_addresses); |
290 | $oTemplate->assign('accesskey_menubar_folders', $accesskey_menubar_folders); |
291 | $oTemplate->assign('accesskey_menubar_options', $accesskey_menubar_options); |
292 | $oTemplate->assign('accesskey_menubar_search', $accesskey_menubar_search); |
293 | $oTemplate->assign('accesskey_menubar_help', $accesskey_menubar_help); |
294 | $oTemplate->assign('accesskey_menubar_signout', $accesskey_menubar_signout); |
295 | |
5fe8257d |
296 | $oTemplate->display('page_header.tpl'); |
c5634692 |
297 | |
298 | global $null; |
299 | do_hook('page_header_bottom', $null); |
a07cd1a4 |
300 | } |
2ba13803 |
301 | |
8b096f0a |
302 | /** |
303 | * Blatantly copied/truncated/modified from displayPageHeader. |
304 | * Outputs a page header specifically for the compose_in_new popup window |
305 | * |
306 | * @param array color the array of theme colors |
307 | * @param string mailbox the current mailbox name to display |
91c27aee |
308 | * @param string sHeaderJs javascipt code to be inserted in a script block in the header |
5bcce050 |
309 | * @param string sOnload JavaScript code to be added inside the body's onload handler |
310 | * as of 1.5.2, this replaces $sBodyTagJs argument |
8b096f0a |
311 | * @return void |
312 | */ |
5bcce050 |
313 | function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') { |
10bf80c0 |
314 | |
83aff890 |
315 | global $reply_focus, $action, $oTemplate; |
10bf80c0 |
316 | |
5bcce050 |
317 | if (empty($sOnload)) { |
10bf80c0 |
318 | if (strpos($action, 'reply') !== FALSE && $reply_focus) { |
5bcce050 |
319 | if ($reply_focus == 'select') |
320 | $sOnload = 'checkForm(\'select\');'; |
321 | else if ($reply_focus == 'focus') |
322 | $sOnload = 'checkForm(\'focus\');'; |
323 | else if ($reply_focus != 'none') |
324 | $sOnload = 'checkForm();'; |
10bf80c0 |
325 | } |
326 | else |
ca14ebb7 |
327 | $sOnload = 'checkForm();'; |
10bf80c0 |
328 | } |
329 | |
330 | |
9c3e6cd4 |
331 | /* |
d62c4938 |
332 | * Locate the first displayable form element (only when JavaScript on) |
333 | */ |
83aff890 |
334 | if(checkForJavascript()) { |
91c27aee |
335 | if ($sHeaderJs) { |
2c92ea9d |
336 | $sJsBlock = "\n<script type=\"text/javascript\">" . |
91c27aee |
337 | "\n<!--\n" . |
a3d59ec3 |
338 | $sHeaderJs . "\n\n// -->\n</script>\n"; |
91c27aee |
339 | } else { |
5fe8257d |
340 | $sJsBlock = ''; |
d62c4938 |
341 | } |
6373ad12 |
342 | $sJsBlock .= "\n"; |
343 | |
b8292491 |
344 | $js_includes = $oTemplate->get_javascript_includes(TRUE); |
6373ad12 |
345 | foreach ($js_includes as $js_file) { |
346 | $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n"; |
347 | } |
348 | |
91c27aee |
349 | displayHtmlHeader (_("Compose"), $sJsBlock); |
d62c4938 |
350 | } else { |
351 | /* javascript off */ |
352 | displayHtmlHeader(_("Compose")); |
ca14ebb7 |
353 | $sOnload = ''; |
9c3e6cd4 |
354 | } |
5bcce050 |
355 | |
356 | // FIXME: change the colorization attributes below to a CSS class! |
357 | $class = ''; |
358 | $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4], |
359 | 'link' => $color[7], 'vlink' => $color[7], |
360 | 'alink' => $color[7]); |
ed1c151d |
361 | |
362 | // this is template-safe (see create_body() function) |
5bcce050 |
363 | echo create_body($sOnload, $class, $aAttribs); |
364 | |
6f4b6b68 |
365 | global $null; |
366 | do_hook('compose_header_bottom', $null); |
9c3e6cd4 |
367 | } |