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 | } |
f549a706 |
35 | global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction, |
d88941c7 |
36 | $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme; |
81132de8 |
37 | |
38 | /* add no cache headers here */ |
b8292491 |
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) |
2c21ef20 |
42 | |
b8292491 |
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"; |
2c21ef20 |
49 | |
d88941c7 |
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'); |
5fe8257d |
53 | |
d6a6f46b |
54 | /** |
55 | * Stylesheets are loaded in the following order: |
56 | * 1) All stylesheets provided by the template. Normally, these are |
e2048f8e |
57 | * stylsheets in templates/<template>/css/. This is accomplished by calling |
d6a6f46b |
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. |
e2048f8e |
64 | */ |
65 | |
d6a6f46b |
66 | // 1. Stylesheets from the template. |
b8292491 |
67 | $header_tags .= $oTemplate->fetch_standard_stylesheet_links(); |
d6a6f46b |
68 | |
b8292491 |
69 | $aUserStyles = array(); |
e2048f8e |
70 | |
d6a6f46b |
71 | // 2. Option user-defined stylesheet from preferences. |
b8292491 |
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', ''); |
e2048f8e |
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? |
78228623 |
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 | */ |
deb25c8f |
86 | if (!empty($chosen_theme) && substr($chosen_theme, 0, 2) == 'u_') { |
87 | $aUserStyles[] = substr($chosen_theme, 2) .'default.css'; |
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 : ''); |
b8292491 |
94 | $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles); |
6182ab4d |
95 | |
d6a6f46b |
96 | // 4. Optional rtl.css stylesheet |
6182ab4d |
97 | if ($text_direction == 'rtl') { |
98 | $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link(); |
99 | } |
62f7daa5 |
100 | |
e842b215 |
101 | if ($squirrelmail_language == 'ja_JP') { |
683b7853 |
102 | /* |
cbd8c251 |
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 | */ |
b8292491 |
109 | $header_tags .= "<!-- \xfd\xfe -->\n"; |
110 | $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n"; |
e842b215 |
111 | } |
237470b4 |
112 | if ($do_hook) { |
b8292491 |
113 | // NOTE! plugins here must assign output to template |
114 | // and NOT echo anything directly!! |
d68323ff |
115 | do_hook('generic_header'); |
237470b4 |
116 | } |
62f7daa5 |
117 | |
b8292491 |
118 | $header_tags .= $xtra; |
119 | $oTemplate->assign('page_title', $title); |
5ca4b1ee |
120 | |
121 | /* work around IE6's scrollbar bug */ |
b8292491 |
122 | $header_tags .= <<<EOS |
292a9c32 |
123 | <!--[if IE 6]> |
5ca4b1ee |
124 | <style type="text/css"> |
5fe8257d |
125 | /* avoid stupid IE6 bug with frames and scrollbars */ |
126 | body { |
5fe8257d |
127 | width: expression(document.documentElement.clientWidth - 30); |
128 | } |
5ca4b1ee |
129 | </style> |
292a9c32 |
130 | <![endif]--> |
5ca4b1ee |
131 | |
b8292491 |
132 | EOS; |
5ca4b1ee |
133 | |
b8292491 |
134 | $oTemplate->assign('header_tags', $header_tags); |
135 | $oTemplate->display('protocol_header.tpl'); |
b6c283c4 |
136 | |
137 | /* this is used to check elsewhere whether we should call this function */ |
138 | $pageheader_sent = TRUE; |
81de00c0 |
139 | if (isset($oErrorHandler)) { |
e6c4caae |
140 | $oErrorHandler->HeaderSent(); |
81de00c0 |
141 | } |
b8292491 |
142 | |
a07cd1a4 |
143 | } |
144 | |
8b096f0a |
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 | */ |
d62c4938 |
152 | function makeInternalLink($path, $text, $target='') { |
202bcbcc |
153 | global $base_uri; |
154 | // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
dcc1cc82 |
155 | if ($target != '') { |
156 | $target = " target=\"$target\""; |
157 | } |
4910106a |
158 | |
e50f5ac2 |
159 | // This is an inefficient hook and is only used by |
4910106a |
160 | // one plugin that still needs to patch this code, |
e50f5ac2 |
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?) |
4910106a |
164 | // use for the internal_link hook. |
165 | // |
166 | //$hooktext = do_hook_function('internal_link',$text); |
167 | //if ($hooktext != '') |
168 | // $text = $hooktext; |
169 | |
d62c4938 |
170 | return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>'; |
171 | } |
172 | |
8b096f0a |
173 | /** |
174 | * Same as makeInternalLink, but echoes it too |
175 | */ |
d62c4938 |
176 | function displayInternalLink($path, $text, $target='') { |
b8292491 |
177 | // FIXME: should let the template echo all these kinds of things |
b26d81e5 |
178 | echo makeInternalLink($path, $text, $target); |
a07cd1a4 |
179 | } |
180 | |
8b096f0a |
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 |
91c27aee |
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 |
8b096f0a |
190 | * @return void |
191 | */ |
715225af |
192 | |
10bf80c0 |
193 | function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') { |
194 | |
195 | global $reply_focus, $hide_sm_attributions, $frame_top, |
5fe8257d |
196 | $provider_name, $provider_uri, $startMessage, |
197 | $javascript_on, $action, $oTemplate; |
10bf80c0 |
198 | |
199 | if (empty($sBodyTagJs)) { |
200 | if (strpos($action, 'reply') !== FALSE && $reply_focus) { |
5fe8257d |
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();"'; |
10bf80c0 |
207 | } |
208 | else |
5fe8257d |
209 | $sBodyTagJs = 'onload="checkForm();"'; |
10bf80c0 |
210 | } |
211 | |
5fe8257d |
212 | $urlMailbox = urlencode($mailbox); |
213 | $startMessage = (int)$startMessage; |
214 | |
0365891c |
215 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION ); |
91c27aee |
216 | |
d03f3582 |
217 | if (!isset($frame_top)) { |
218 | $frame_top = '_top'; |
219 | } |
715225af |
220 | |
c18f58c5 |
221 | if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) { |
b8292491 |
222 | $js_includes = $oTemplate->get_javascript_includes(TRUE); |
6373ad12 |
223 | $sJsBlock = ''; |
224 | foreach ($js_includes as $js_file) { |
225 | $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n"; |
226 | } |
91c27aee |
227 | if ($sHeaderJs) { |
2c92ea9d |
228 | $sJsBlock .= "\n<script type=\"text/javascript\">" . |
91c27aee |
229 | "\n<!--\n" . |
a3d59ec3 |
230 | $sHeaderJs . "\n\n// -->\n</script>\n"; |
d62c4938 |
231 | } |
91c27aee |
232 | displayHtmlHeader ('SquirrelMail', $sJsBlock); |
5fe8257d |
233 | } else { |
d62c4938 |
234 | /* do not use JavaScript */ |
235 | displayHtmlHeader ('SquirrelMail'); |
91c27aee |
236 | $sBodyTagJs = ''; |
715225af |
237 | } |
202bcbcc |
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 | */ |
72520f77 |
242 | $shortBoxName = htmlspecialchars(imap_utf7_decode_local( |
91e0dccc |
243 | readShortMailboxName($mailbox, $delimiter))); |
3b7d68e6 |
244 | if ( $shortBoxName == 'INBOX' ) { |
7da23762 |
245 | $shortBoxName = _("INBOX"); |
246 | } |
0493ed11 |
247 | |
5fe8257d |
248 | $sm_attributes = ''; |
249 | if (!$hide_sm_attributions) { |
250 | $sm_attributes .= '<td class="sqm_providerInfo">' ."\n"; |
8b5c49cd |
251 | if (empty($provider_uri)) { |
5fe8257d |
252 | $sm_attributes .= ' <a href="about.php">SquirrelMail</a>'; |
8b5c49cd |
253 | } else { |
254 | if (empty($provider_name)) $provider_name= 'SquirrelMail'; |
5fe8257d |
255 | $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n"; |
8b5c49cd |
256 | } |
5fe8257d |
257 | $sm_attributes .= " </td>\n"; |
99ea51d3 |
258 | } |
5fe8257d |
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'); |
a07cd1a4 |
268 | } |
2ba13803 |
269 | |
8b096f0a |
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 |
91c27aee |
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 |
8b096f0a |
278 | * @return void |
279 | */ |
10bf80c0 |
280 | function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') { |
281 | |
6373ad12 |
282 | global $reply_focus, $javascript_on, $action, $oTemplate; |
10bf80c0 |
283 | |
284 | if (empty($sBodyTagJs)) { |
285 | if (strpos($action, 'reply') !== FALSE && $reply_focus) { |
5fe8257d |
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();"'; |
10bf80c0 |
292 | } |
293 | else |
5fe8257d |
294 | $sBodyTagJs = 'onload="checkForm();"'; |
10bf80c0 |
295 | } |
296 | |
297 | |
9c3e6cd4 |
298 | /* |
d62c4938 |
299 | * Locate the first displayable form element (only when JavaScript on) |
300 | */ |
301 | if($javascript_on) { |
91c27aee |
302 | if ($sHeaderJs) { |
2c92ea9d |
303 | $sJsBlock = "\n<script type=\"text/javascript\">" . |
91c27aee |
304 | "\n<!--\n" . |
a3d59ec3 |
305 | $sHeaderJs . "\n\n// -->\n</script>\n"; |
91c27aee |
306 | } else { |
5fe8257d |
307 | $sJsBlock = ''; |
d62c4938 |
308 | } |
6373ad12 |
309 | $sJsBlock .= "\n"; |
310 | |
b8292491 |
311 | $js_includes = $oTemplate->get_javascript_includes(TRUE); |
6373ad12 |
312 | foreach ($js_includes as $js_file) { |
313 | $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n"; |
314 | } |
315 | |
91c27aee |
316 | displayHtmlHeader (_("Compose"), $sJsBlock); |
d62c4938 |
317 | } else { |
318 | /* javascript off */ |
319 | displayHtmlHeader(_("Compose")); |
320 | $onload = ''; |
9c3e6cd4 |
321 | } |
b8292491 |
322 | // FIXME: should let the template echo all these kinds of things |
91c27aee |
323 | echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n"; |
9c3e6cd4 |
324 | } |