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