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