59177427 |
1 | <?php |
7350889b |
2 | |
35586184 |
3 | /** |
4 | * page_header.php |
5 | * |
35586184 |
6 | * Prints the page header (duh) |
7 | * |
47ccfad4 |
8 | * @copyright © 1999-2006 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 | |
b8292491 |
44 | $oTemplate->assign('frames', $frames); |
45 | $oTemplate->assign('lang', $squirrelmail_language); |
46 | |
47 | $header_tags = ''; |
48 | |
49 | $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n"; |
2c21ef20 |
50 | |
d88941c7 |
51 | $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset); |
52 | $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize); |
8757c848 |
53 | $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 |
54 | |
d6a6f46b |
55 | /** |
56 | * Stylesheets are loaded in the following order: |
57 | * 1) All stylesheets provided by the template. Normally, these are |
e2048f8e |
58 | * stylsheets in templates/<template>/css/. This is accomplished by calling |
d6a6f46b |
59 | * $oTemplate->fetch_standard_stylesheet_links(). |
60 | * 2) An optional user-defined stylesheet. This is set in the Display |
61 | * Preferences. |
62 | * 3) src/style.php which sets some basic font prefs. |
63 | * 4) If we are dealing with an RTL language, we load rtl.css from the |
64 | * template set. |
e2048f8e |
65 | */ |
66 | |
d6a6f46b |
67 | // 1. Stylesheets from the template. |
b8292491 |
68 | $header_tags .= $oTemplate->fetch_standard_stylesheet_links(); |
d6a6f46b |
69 | |
b8292491 |
70 | $aUserStyles = array(); |
e2048f8e |
71 | |
d6a6f46b |
72 | // 2. Option user-defined stylesheet from preferences. |
f9376f0b |
73 | if (!empty($used_theme)) { |
83fc5c5e |
74 | /** |
8757c848 |
75 | * All styles just point to a directory, so we need to include all .css |
76 | * files in that directory. |
83fc5c5e |
77 | */ |
8757c848 |
78 | $styles = list_files($used_theme, '.css'); |
79 | foreach ($styles as $sheet) { |
80 | $aUserStyles[] = $used_theme .'/'.$sheet; |
f9376f0b |
81 | } |
deb25c8f |
82 | } |
d6a6f46b |
83 | |
84 | // 3. src/style.php |
85 | $aUserStyles[] = $base_uri .'src/style.php?' |
b8292491 |
86 | . (!empty($used_fontset) ? '&fontset='.$used_fontset : '') |
d6a6f46b |
87 | . (!empty($used_fontsize) ? '&fontsize='.$used_fontsize : ''); |
f9376f0b |
88 | |
89 | // 3.1. Load the stylesheets we have already |
b8292491 |
90 | $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles); |
6182ab4d |
91 | |
d6a6f46b |
92 | // 4. Optional rtl.css stylesheet |
6182ab4d |
93 | if ($text_direction == 'rtl') { |
94 | $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link(); |
95 | } |
62f7daa5 |
96 | |
e842b215 |
97 | if ($squirrelmail_language == 'ja_JP') { |
683b7853 |
98 | /* |
cbd8c251 |
99 | * force correct detection of charset, when browser does not follow |
100 | * http content-type and tries to detect charset from page content. |
101 | * Shooting of browser's creator can't be implemented in php. |
102 | * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/ |
103 | * recommendations and switch to unicode. |
104 | */ |
b8292491 |
105 | $header_tags .= "<!-- \xfd\xfe -->\n"; |
106 | $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n"; |
e842b215 |
107 | } |
237470b4 |
108 | if ($do_hook) { |
b8292491 |
109 | // NOTE! plugins here must assign output to template |
110 | // and NOT echo anything directly!! |
d849b570 |
111 | global $null; |
112 | do_hook('generic_header', $null); |
237470b4 |
113 | } |
62f7daa5 |
114 | |
b8292491 |
115 | $header_tags .= $xtra; |
116 | $oTemplate->assign('page_title', $title); |
5ca4b1ee |
117 | |
118 | /* work around IE6's scrollbar bug */ |
b8292491 |
119 | $header_tags .= <<<EOS |
292a9c32 |
120 | <!--[if IE 6]> |
5ca4b1ee |
121 | <style type="text/css"> |
5fe8257d |
122 | /* avoid stupid IE6 bug with frames and scrollbars */ |
123 | body { |
5fe8257d |
124 | width: expression(document.documentElement.clientWidth - 30); |
125 | } |
5ca4b1ee |
126 | </style> |
292a9c32 |
127 | <![endif]--> |
5ca4b1ee |
128 | |
b8292491 |
129 | EOS; |
5ca4b1ee |
130 | |
b8292491 |
131 | $oTemplate->assign('header_tags', $header_tags); |
132 | $oTemplate->display('protocol_header.tpl'); |
b6c283c4 |
133 | |
134 | /* this is used to check elsewhere whether we should call this function */ |
135 | $pageheader_sent = TRUE; |
81de00c0 |
136 | if (isset($oErrorHandler)) { |
e6c4caae |
137 | $oErrorHandler->HeaderSent(); |
81de00c0 |
138 | } |
b8292491 |
139 | |
a07cd1a4 |
140 | } |
141 | |
8b096f0a |
142 | /** |
143 | * Given a path to a SquirrelMail file, return a HTML link to it |
144 | * |
145 | * @param string path the SquirrelMail file to link to |
146 | * @param string text the link text |
147 | * @param string target the target frame for this link |
148 | */ |
d62c4938 |
149 | function makeInternalLink($path, $text, $target='') { |
f7b996c3 |
150 | global $base_uri, $oTemplate; |
202bcbcc |
151 | // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
4910106a |
152 | |
e50f5ac2 |
153 | // This is an inefficient hook and is only used by |
4910106a |
154 | // one plugin that still needs to patch this code, |
e50f5ac2 |
155 | // plus if we are templat-izing SM, visual hooks |
156 | // are not needed. However, I am leaving the code |
157 | // here just in case we find a good (non-visual?) |
4910106a |
158 | // use for the internal_link hook. |
159 | // |
d849b570 |
160 | //do_hook('internal_link', $text); |
4910106a |
161 | |
f7b996c3 |
162 | $oTemplate->assign('uri', $base_uri . $path); |
163 | $oTemplate->assign('text', $text); |
164 | $oTemplate->assign('target', $target); |
1c4fa572 |
165 | |
166 | // blank the onclick because the template object might |
167 | // already contain an onclick value due to having been |
168 | // used to show a compose link (when comp_in_new is turned on) |
169 | // |
170 | $oTemplate->assign('onclick', ''); |
171 | |
f7b996c3 |
172 | return $oTemplate->fetch('hyperlink.tpl'); |
d62c4938 |
173 | } |
174 | |
8b096f0a |
175 | /** |
176 | * Same as makeInternalLink, but echoes it too |
177 | */ |
d62c4938 |
178 | function displayInternalLink($path, $text, $target='') { |
b8292491 |
179 | // FIXME: should let the template echo all these kinds of things |
b26d81e5 |
180 | echo makeInternalLink($path, $text, $target); |
a07cd1a4 |
181 | } |
182 | |
8b096f0a |
183 | /** |
184 | * Outputs a complete SquirrelMail page header, starting with <!doctype> and |
185 | * including the default menu bar. Uses displayHtmlHeader and takes |
186 | * JavaScript and locale settings into account. |
187 | * |
188 | * @param array color the array of theme colors |
189 | * @param string mailbox the current mailbox name to display |
91c27aee |
190 | * @param string sHeaderJs javascipt code to be inserted in a script block in the header |
191 | * @param string sBodyTagJs js events to be inserted in the body tag |
8b096f0a |
192 | * @return void |
193 | */ |
715225af |
194 | |
10bf80c0 |
195 | function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') { |
196 | |
197 | global $reply_focus, $hide_sm_attributions, $frame_top, |
5fe8257d |
198 | $provider_name, $provider_uri, $startMessage, |
199 | $javascript_on, $action, $oTemplate; |
10bf80c0 |
200 | |
201 | if (empty($sBodyTagJs)) { |
202 | if (strpos($action, 'reply') !== FALSE && $reply_focus) { |
5fe8257d |
203 | if ($reply_focus == 'select') |
204 | $sBodyTagJs = 'onload="checkForm(\'select\');"'; |
205 | else if ($reply_focus == 'focus') |
206 | $sBodyTagJs = 'onload="checkForm(\'focus\');"'; |
207 | else if ($reply_focus != 'none') |
208 | $sBodyTagJs = 'onload="checkForm();"'; |
10bf80c0 |
209 | } |
210 | else |
5fe8257d |
211 | $sBodyTagJs = 'onload="checkForm();"'; |
10bf80c0 |
212 | } |
213 | |
5fe8257d |
214 | $urlMailbox = urlencode($mailbox); |
215 | $startMessage = (int)$startMessage; |
216 | |
0365891c |
217 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION ); |
91c27aee |
218 | |
d03f3582 |
219 | if (!isset($frame_top)) { |
220 | $frame_top = '_top'; |
221 | } |
715225af |
222 | |
c18f58c5 |
223 | if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) { |
b8292491 |
224 | $js_includes = $oTemplate->get_javascript_includes(TRUE); |
6373ad12 |
225 | $sJsBlock = ''; |
226 | foreach ($js_includes as $js_file) { |
227 | $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n"; |
228 | } |
91c27aee |
229 | if ($sHeaderJs) { |
2c92ea9d |
230 | $sJsBlock .= "\n<script type=\"text/javascript\">" . |
91c27aee |
231 | "\n<!--\n" . |
a3d59ec3 |
232 | $sHeaderJs . "\n\n// -->\n</script>\n"; |
d62c4938 |
233 | } |
91c27aee |
234 | displayHtmlHeader ('SquirrelMail', $sJsBlock); |
5fe8257d |
235 | } else { |
d62c4938 |
236 | /* do not use JavaScript */ |
237 | displayHtmlHeader ('SquirrelMail'); |
91c27aee |
238 | $sBodyTagJs = ''; |
715225af |
239 | } |
202bcbcc |
240 | /* |
241 | * this explains the imap_mailbox.php dependency. We should instead store |
242 | * the selected mailbox in the session and fallback to the session var. |
243 | */ |
72520f77 |
244 | $shortBoxName = htmlspecialchars(imap_utf7_decode_local( |
91e0dccc |
245 | readShortMailboxName($mailbox, $delimiter))); |
3b7d68e6 |
246 | if ( $shortBoxName == 'INBOX' ) { |
7da23762 |
247 | $shortBoxName = _("INBOX"); |
248 | } |
0493ed11 |
249 | |
5fe8257d |
250 | $sm_attributes = ''; |
251 | if (!$hide_sm_attributions) { |
252 | $sm_attributes .= '<td class="sqm_providerInfo">' ."\n"; |
8b5c49cd |
253 | if (empty($provider_uri)) { |
5fe8257d |
254 | $sm_attributes .= ' <a href="about.php">SquirrelMail</a>'; |
8b5c49cd |
255 | } else { |
256 | if (empty($provider_name)) $provider_name= 'SquirrelMail'; |
5fe8257d |
257 | $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n"; |
8b5c49cd |
258 | } |
5fe8257d |
259 | $sm_attributes .= " </td>\n"; |
99ea51d3 |
260 | } |
5fe8257d |
261 | |
262 | $oTemplate->assign('body_tag_js', $sBodyTagJs); |
263 | $oTemplate->assign('shortBoxName', $shortBoxName); |
264 | $oTemplate->assign('sm_attribute_str', $sm_attributes); |
265 | $oTemplate->assign('frame_top', $frame_top); |
266 | $oTemplate->assign('urlMailbox', $urlMailbox); |
267 | $oTemplate->assign('startMessage', $startMessage); |
268 | $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions); |
269 | $oTemplate->display('page_header.tpl'); |
a07cd1a4 |
270 | } |
2ba13803 |
271 | |
8b096f0a |
272 | /** |
273 | * Blatantly copied/truncated/modified from displayPageHeader. |
274 | * Outputs a page header specifically for the compose_in_new popup window |
275 | * |
276 | * @param array color the array of theme colors |
277 | * @param string mailbox the current mailbox name to display |
91c27aee |
278 | * @param string sHeaderJs javascipt code to be inserted in a script block in the header |
279 | * @param string sBodyTagJs js events to be inserted in the body tag |
8b096f0a |
280 | * @return void |
281 | */ |
10bf80c0 |
282 | function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') { |
283 | |
6373ad12 |
284 | global $reply_focus, $javascript_on, $action, $oTemplate; |
10bf80c0 |
285 | |
286 | if (empty($sBodyTagJs)) { |
287 | if (strpos($action, 'reply') !== FALSE && $reply_focus) { |
5fe8257d |
288 | if ($reply_focus == 'select') |
289 | $sBodyTagJs = 'onload="checkForm(\'select\');"'; |
290 | else if ($reply_focus == 'focus') |
291 | $sBodyTagJs = 'onload="checkForm(\'focus\');"'; |
292 | else if ($reply_focus != 'none') |
293 | $sBodyTagJs = 'onload="checkForm();"'; |
10bf80c0 |
294 | } |
295 | else |
5fe8257d |
296 | $sBodyTagJs = 'onload="checkForm();"'; |
10bf80c0 |
297 | } |
298 | |
299 | |
9c3e6cd4 |
300 | /* |
d62c4938 |
301 | * Locate the first displayable form element (only when JavaScript on) |
302 | */ |
303 | if($javascript_on) { |
91c27aee |
304 | if ($sHeaderJs) { |
2c92ea9d |
305 | $sJsBlock = "\n<script type=\"text/javascript\">" . |
91c27aee |
306 | "\n<!--\n" . |
a3d59ec3 |
307 | $sHeaderJs . "\n\n// -->\n</script>\n"; |
91c27aee |
308 | } else { |
5fe8257d |
309 | $sJsBlock = ''; |
d62c4938 |
310 | } |
6373ad12 |
311 | $sJsBlock .= "\n"; |
312 | |
b8292491 |
313 | $js_includes = $oTemplate->get_javascript_includes(TRUE); |
6373ad12 |
314 | foreach ($js_includes as $js_file) { |
315 | $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n"; |
316 | } |
317 | |
91c27aee |
318 | displayHtmlHeader (_("Compose"), $sJsBlock); |
d62c4938 |
319 | } else { |
320 | /* javascript off */ |
321 | displayHtmlHeader(_("Compose")); |
322 | $onload = ''; |
9c3e6cd4 |
323 | } |
b8292491 |
324 | // FIXME: should let the template echo all these kinds of things |
91c27aee |
325 | echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n"; |
9c3e6cd4 |
326 | } |