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