Fix login error for users with no theme
[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-2007 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' && is_dir($chosen_theme) && is_readable($chosen_theme)? $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) && $used_theme != 'none') {
74 /**
75 * All styles (except "none" - ugh) just point to a directory,
76 * so we need to include all .css files in that directory.
77 */
78 //FIXME: rid ourselves of "none" strings! I didn't do it here because I think the problem is that the theme itself should never be "none" (? well, what else would it be? if "none" theme is actually OK, then is there a constant to use below in stead of a hard-coded string?)
79 $styles = $used_theme == 'none' ? array()
80 : list_files($used_theme, '.css');
81 foreach ($styles as $sheet) {
82 $aUserStyles[] = $used_theme .'/'.$sheet;
83 }
84 }
85
86 // 3. src/style.php
87 $aUserStyles[] = $base_uri .'src/style.php?'
88 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
89 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
90
91 // 3.1. Load the stylesheets we have already
92 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
93
94 // 4. Optional rtl.css stylesheet
95 if ($text_direction == 'rtl') {
96 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
97 }
98
99 if ($squirrelmail_language == 'ja_JP') {
100 /*
101 * force correct detection of charset, when browser does not follow
102 * http content-type and tries to detect charset from page content.
103 * Shooting of browser's creator can't be implemented in php.
104 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
105 * recommendations and switch to unicode.
106 */
107 $header_tags .= "<!-- \xfd\xfe -->\n";
108 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n";
109 }
110 if ($do_hook) {
111 // NOTE! plugins here MUST assign output to template
112 // and NOT echo anything directly!! A common
113 // approach is if a plugin decides it needs to
114 // put something at page-top after the standard
115 // SM page header, to dynamically add itself to
116 // the page_header_bottom and/or compose_header_bottom
117 // hooks for the current page request. See
118 // the Sent Confirmation v1.7 or Restrict Senders v1.2
119 // plugins for examples of this approach.
120 global $null;
121 ob_start();
122 do_hook('generic_header', $null);
123 $output = ob_get_contents();
124 ob_end_clean();
125 // plugin authors can debug their errors with one of the following:
126 //sm_print_r($output);
127 //echo $output;
128 if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR);
129 }
130
131 $header_tags .= $xtra;
132 $oTemplate->assign('page_title', $title);
133
134 /* work around IE6's scrollbar bug */
135 $header_tags .= <<<EOS
136 <!--[if IE 6]>
137 <style type="text/css">
138 /* avoid stupid IE6 bug with frames and scrollbars */
139 body {
140 width: expression(document.documentElement.clientWidth - 30);
141 }
142 </style>
143 <![endif]-->
144
145 EOS;
146
147 $oTemplate->assign('header_tags', $header_tags);
148 $oTemplate->display('protocol_header.tpl');
149
150 /* this is used to check elsewhere whether we should call this function */
151 $pageheader_sent = TRUE;
152 if (isset($oErrorHandler)) {
153 $oErrorHandler->HeaderSent();
154 }
155
156 }
157
158 /**
159 * Given a path to a SquirrelMail file, return a HTML link to it
160 *
161 * @param string path the SquirrelMail file to link to
162 * @param string text the link text
163 * @param string target the target frame for this link
164 */
165 function makeInternalLink($path, $text, $target='') {
166 global $base_uri, $oTemplate;
167 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
168
169 // This is an inefficient hook and is only used by
170 // one plugin that still needs to patch this code,
171 // plus if we are templat-izing SM, visual hooks
172 // are not needed. However, I am leaving the code
173 // here just in case we find a good (non-visual?)
174 // use for the internal_link hook.
175 //
176 //do_hook('internal_link', $text);
177
178 return create_hyperlink($base_uri . $path, $text, $target);
179 }
180
181 /**
182 * Same as makeInternalLink, but echoes it too
183 */
184 function displayInternalLink($path, $text, $target='') {
185 // FIXME: should let the template echo all these kinds of things
186 echo makeInternalLink($path, $text, $target);
187 }
188
189 /**
190 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
191 * including the default menu bar. Uses displayHtmlHeader and takes
192 * JavaScript and locale settings into account.
193 *
194 * @param array color the array of theme colors
195 * @param string mailbox the current mailbox name to display
196 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
197 * @param string sBodyTagJs js events to be inserted in the body tag
198 * @return void
199 */
200
201 function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sBodyTagJs = '') {
202
203 global $reply_focus, $hide_sm_attributions, $frame_top,
204 $provider_name, $provider_uri, $startMessage,
205 $action, $oTemplate, $org_title, $base_uri;
206
207 //FIXME: $sBodyTag should be turned into $sOnload and should only contain the contents of the onload attribute (not the attribute name nor any quotes).... only question is if anyone was using $sBodyTag for anything but onload event handlers? (see function compose_Header() below for how to fix it once we confirm it can be changed)
208 if (empty($sBodyTagJs)) {
209 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
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();"';
216 }
217 else
218 $sBodyTagJs = 'onload="checkForm();"';
219 }
220
221 $urlMailbox = urlencode($mailbox);
222 $startMessage = (int)$startMessage;
223
224 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
225
226 if (!isset($frame_top)) {
227 $frame_top = '_top';
228 }
229
230 //FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary??
231 if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
232 $js_includes = $oTemplate->get_javascript_includes(TRUE);
233 $sJsBlock = '';
234 foreach ($js_includes as $js_file) {
235 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
236 }
237 if ($sHeaderJs) {
238 $sJsBlock .= "\n<script type=\"text/javascript\">" .
239 "\n<!--\n" .
240 $sHeaderJs . "\n\n// -->\n</script>\n";
241 }
242 displayHtmlHeader ($org_title, $sJsBlock);
243 } else {
244 /* do not use JavaScript */
245 displayHtmlHeader ($org_title);
246 $sBodyTagJs = '';
247 }
248 /*
249 * this explains the imap_mailbox.php dependency. We should instead store
250 * the selected mailbox in the session and fallback to the session var.
251 */
252 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
253 readShortMailboxName($mailbox, $delimiter)));
254 if ( $shortBoxName == 'INBOX' ) {
255 $shortBoxName = _("INBOX");
256 }
257
258 $provider_link = '';
259 if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
260 $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
261 }
262
263 $oTemplate->assign('body_tag_js', $sBodyTagJs);
264 $oTemplate->assign('shortBoxName', $shortBoxName);
265 $oTemplate->assign('provider_link', $provider_link);
266 $oTemplate->assign('frame_top', $frame_top);
267 $oTemplate->assign('urlMailbox', $urlMailbox);
268 $oTemplate->assign('startMessage', $startMessage);
269 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
270 $oTemplate->display('page_header.tpl');
271
272 global $null;
273 do_hook('page_header_bottom', $null);
274 }
275
276 /**
277 * Blatantly copied/truncated/modified from displayPageHeader.
278 * Outputs a page header specifically for the compose_in_new popup window
279 *
280 * @param array color the array of theme colors
281 * @param string mailbox the current mailbox name to display
282 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
283 * @param string sOnload JavaScript code to be added inside the body's onload handler
284 * as of 1.5.2, this replaces $sBodyTagJs argument
285 * @return void
286 */
287 function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
288
289 global $reply_focus, $action, $oTemplate;
290
291 if (empty($sOnload)) {
292 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
293 if ($reply_focus == 'select')
294 $sOnload = 'checkForm(\'select\');';
295 else if ($reply_focus == 'focus')
296 $sOnload = 'checkForm(\'focus\');';
297 else if ($reply_focus != 'none')
298 $sOnload = 'checkForm();';
299 }
300 else
301 $sOnload = 'checkForm();';
302 }
303
304
305 /*
306 * Locate the first displayable form element (only when JavaScript on)
307 */
308 if(checkForJavascript()) {
309 if ($sHeaderJs) {
310 $sJsBlock = "\n<script type=\"text/javascript\">" .
311 "\n<!--\n" .
312 $sHeaderJs . "\n\n// -->\n</script>\n";
313 } else {
314 $sJsBlock = '';
315 }
316 $sJsBlock .= "\n";
317
318 $js_includes = $oTemplate->get_javascript_includes(TRUE);
319 foreach ($js_includes as $js_file) {
320 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
321 }
322
323 displayHtmlHeader (_("Compose"), $sJsBlock);
324 } else {
325 /* javascript off */
326 displayHtmlHeader(_("Compose"));
327 $onload = '';
328 }
329
330 // FIXME: change the colorization attributes below to a CSS class!
331 $class = '';
332 $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
333 'link' => $color[7], 'vlink' => $color[7],
334 'alink' => $color[7]);
335
336 // this is template-safe (see create_body() function)
337 echo create_body($sOnload, $class, $aAttribs);
338
339 global $null;
340 do_hook('compose_header_bottom', $null);
341 }