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