Centralized init
[squirrelmail.git] / functions / page_header.php
1 <?php
2
3 /**
4 * page_header.php
5 *
6 * Prints the page header (duh)
7 *
8 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
9 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
10 * @version $Id$
11 * @package squirrelmail
12 */
13
14 /** Include required files from SM */
15 include_once(SM_PATH . 'functions/imap_mailbox.php');
16
17 /**
18 * Output a SquirrelMail page header, from <!doctype> to </head>
19 * Always set up the language before calling these functions.
20 *
21 * Since 1.5.1 function sends http headers. Function should be called
22 * before any output is started.
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
26 * @param bool frames generate html frameset doctype (since 1.5.1)
27 * @return void
28 */
29 function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
30 global $squirrelmail_language, $sTplDir, $oErroHandler;
31
32 if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
33 global $base_uri;
34 }
35 global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
36 $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
37
38 /* add no cache headers here */
39 header('Pragma: no-cache'); // http 1.0 (rfc1945)
40 header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
41
42 if ($frames) {
43 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"'."\n"
44 .' "http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd">';
45 } else {
46 echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
47 .' "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">';
48 }
49 echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
50 "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
51
52 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
53 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
54 $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
55
56 /*
57 * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
58 * It is not compatible with html 4.01 Transitional
59 */
60 echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
61 .'?themeid='.$used_theme
62 .'&amp;templateid='.basename($sTplDir)
63 .(!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
64 .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
65 .(!empty($text_direction) ? '&amp;dir='.$text_direction : '')."\">\n";
66
67
68 // load custom style sheet (deprecated)
69 if ( ! empty($theme_css) ) {
70 echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
71 }
72
73 if ($squirrelmail_language == 'ja_JP') {
74 /*
75 * force correct detection of charset, when browser does not follow
76 * http content-type and tries to detect charset from page content.
77 * Shooting of browser's creator can't be implemented in php.
78 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
79 * recommendations and switch to unicode.
80 */
81 echo "<!-- \xfd\xfe -->\n";
82 echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
83 }
84 if ($do_hook) {
85 do_hook('generic_header');
86 }
87
88 echo "<title>$title</title>\n$xtra\n";
89
90 /* work around IE6's scrollbar bug */
91 echo <<<ECHO
92 <style type="text/css">
93 <!--
94 /* avoid stupid IE6 bug with frames and scrollbars */
95 body {
96 voice-family: "\"}\"";
97 voice-family: inherit;
98 width: expression(document.documentElement.clientWidth - 30);
99 }
100 -->
101 </style>
102
103 ECHO;
104
105 echo "\n</head>\n\n";
106
107 /* this is used to check elsewhere whether we should call this function */
108 $pageheader_sent = TRUE;
109 if (isset($oErrorHandler)) {
110 $oErrorHander->HeaderSent();
111 }
112 }
113
114 /**
115 * Given a path to a SquirrelMail file, return a HTML link to it
116 *
117 * @param string path the SquirrelMail file to link to
118 * @param string text the link text
119 * @param string target the target frame for this link
120 */
121 function makeInternalLink($path, $text, $target='') {
122 global $base_uri;
123 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
124 if ($target != '') {
125 $target = " target=\"$target\"";
126 }
127
128 // This is an inefficient hook and is only used by
129 // one plugin that still needs to patch this code,
130 // plus if we are templat-izing SM, visual hooks
131 // are not needed. However, I am leaving the code
132 // here just in case we find a good (non-visual?)
133 // use for the internal_link hook.
134 //
135 //$hooktext = do_hook_function('internal_link',$text);
136 //if ($hooktext != '')
137 // $text = $hooktext;
138
139 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
140 }
141
142 /**
143 * Same as makeInternalLink, but echoes it too
144 */
145 function displayInternalLink($path, $text, $target='') {
146 echo makeInternalLink($path, $text, $target);
147 }
148
149 /**
150 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
151 * including the default menu bar. Uses displayHtmlHeader and takes
152 * JavaScript and locale settings into account.
153 *
154 * @param array color the array of theme colors
155 * @param string mailbox the current mailbox name to display
156 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
157 * @param string sBodyTagJs js events to be inserted in the body tag
158 * @return void
159 */
160
161 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
162
163 global $reply_focus, $hide_sm_attributions, $frame_top,
164 $provider_name, $provider_uri, $startMessage,
165 $javascript_on, $action, $oTemplate;
166
167 if (empty($sBodyTagJs)) {
168 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
169 if ($reply_focus == 'select')
170 $sBodyTagJs = 'onload="checkForm(\'select\');"';
171 else if ($reply_focus == 'focus')
172 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
173 else if ($reply_focus != 'none')
174 $sBodyTagJs = 'onload="checkForm();"';
175 }
176 else
177 $sBodyTagJs = 'onload="checkForm();"';
178 }
179
180 $urlMailbox = urlencode($mailbox);
181 $startMessage = (int)$startMessage;
182
183 $sTplDir = $oTemplate->template_dir;
184
185 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
186
187 if (!isset($frame_top)) {
188 $frame_top = '_top';
189 }
190
191 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
192 $js_includes = $oTemplate->getJavascriptIncludes();
193 $sJsBlock = '';
194 foreach ($js_includes as $js_file) {
195 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
196 }
197 if ($sHeaderJs) {
198 $sJsBlock .= "\n<script type=\"text/javascript\">" .
199 "\n<!--\n" .
200 $sHeaderJs . "\n\n// -->\n</script>\n";
201 }
202 displayHtmlHeader ('SquirrelMail', $sJsBlock);
203 } else {
204 /* do not use JavaScript */
205 displayHtmlHeader ('SquirrelMail');
206 $sBodyTagJs = '';
207 }
208 /*
209 * this explains the imap_mailbox.php dependency. We should instead store
210 * the selected mailbox in the session and fallback to the session var.
211 */
212 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
213 readShortMailboxName($mailbox, $delimiter)));
214 if ( $shortBoxName == 'INBOX' ) {
215 $shortBoxName = _("INBOX");
216 }
217
218 $sm_attributes = '';
219 if (!$hide_sm_attributions) {
220 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
221 if (empty($provider_uri)) {
222 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
223 } else {
224 if (empty($provider_name)) $provider_name= 'SquirrelMail';
225 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
226 }
227 $sm_attributes .= " </td>\n";
228 }
229
230 $oTemplate->assign('body_tag_js', $sBodyTagJs);
231 $oTemplate->assign('shortBoxName', $shortBoxName);
232 $oTemplate->assign('sm_attribute_str', $sm_attributes);
233 $oTemplate->assign('frame_top', $frame_top);
234 $oTemplate->assign('urlMailbox', $urlMailbox);
235 $oTemplate->assign('startMessage', $startMessage);
236 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
237 $oTemplate->display('page_header.tpl');
238 }
239
240 /**
241 * Blatantly copied/truncated/modified from displayPageHeader.
242 * Outputs a page header specifically for the compose_in_new popup window
243 *
244 * @param array color the array of theme colors
245 * @param string mailbox the current mailbox name to display
246 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
247 * @param string sBodyTagJs js events to be inserted in the body tag
248 * @return void
249 */
250 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
251
252 global $reply_focus, $javascript_on, $action, $oTemplate;
253
254 if (empty($sBodyTagJs)) {
255 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
256 if ($reply_focus == 'select')
257 $sBodyTagJs = 'onload="checkForm(\'select\');"';
258 else if ($reply_focus == 'focus')
259 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
260 else if ($reply_focus != 'none')
261 $sBodyTagJs = 'onload="checkForm();"';
262 }
263 else
264 $sBodyTagJs = 'onload="checkForm();"';
265 }
266
267
268 /*
269 * Locate the first displayable form element (only when JavaScript on)
270 */
271 if($javascript_on) {
272 if ($sHeaderJs) {
273 $sJsBlock = "\n<script type=\"text/javascript\">" .
274 "\n<!--\n" .
275 $sHeaderJs . "\n\n// -->\n</script>\n";
276 } else {
277 $sJsBlock = '';
278 }
279 $sJsBlock .= "\n";
280
281 $js_includes = $oTemplate->getJavascriptIncludes();
282 foreach ($js_includes as $js_file) {
283 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
284 }
285
286 displayHtmlHeader (_("Compose"), $sJsBlock);
287 } else {
288 /* javascript off */
289 displayHtmlHeader(_("Compose"));
290 $onload = '';
291 }
292 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
293 }