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