Add / before default.css in user themes in case it is not in the path for some reason.
[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' ? 'u_'.$user_themes[$user_theme_default]['PATH'] : $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 // 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)
74 // 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?
75 // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
76 // Steve, can you please document what u_ means? Will it work with the
77 // new template inheritance system and auto-detection of alternate sheets?
78 /**
79 * Stylesheets beginning with a "u_" == user provided stylesheets, e.g. those
80 * in SM_PATH/css/. Template provided stylesheets (TEMPLATE_DIR/css/alternatives/)
81 * should begin with 't_'. This was the initial path I took to get it working
82 * since I wasn't sure what mods to the Template class would be used to handle
83 * template-provided alt stylesheets.
84 *
85 * TODO: Re-evaluate this naming convetion.
86 */
87 # var_dump($used_theme);
88 if (!empty($used_theme)) {
89 if (substr($used_theme, 0, 2) == 'u_') {
90 $aUserStyles[] = substr($used_theme, 2) .'/default.css';
91 } elseif (substr($used_theme, 0, 2) == 't_') {
92 $aUserStyles[] = SM_PATH . $oTemplate->get_template_file_directory().'css/alternates/'.substr($used_theme, 2);
93 # $aUserStyles[] = substr($used_theme, 2);
94 }
95 }
96
97 // 3. src/style.php
98 $aUserStyles[] = $base_uri .'src/style.php?'
99 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
100 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
101
102 // 3.1. Load the stylesheets we have already
103 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
104
105 // 4. Optional rtl.css stylesheet
106 if ($text_direction == 'rtl') {
107 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
108 }
109
110 if ($squirrelmail_language == 'ja_JP') {
111 /*
112 * force correct detection of charset, when browser does not follow
113 * http content-type and tries to detect charset from page content.
114 * Shooting of browser's creator can't be implemented in php.
115 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
116 * recommendations and switch to unicode.
117 */
118 $header_tags .= "<!-- \xfd\xfe -->\n";
119 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
120 }
121 if ($do_hook) {
122 // NOTE! plugins here must assign output to template
123 // and NOT echo anything directly!!
124 do_hook('generic_header');
125 }
126
127 $header_tags .= $xtra;
128 $oTemplate->assign('page_title', $title);
129
130 /* work around IE6's scrollbar bug */
131 $header_tags .= <<<EOS
132 <!--[if IE 6]>
133 <style type="text/css">
134 /* avoid stupid IE6 bug with frames and scrollbars */
135 body {
136 width: expression(document.documentElement.clientWidth - 30);
137 }
138 </style>
139 <![endif]-->
140
141 EOS;
142
143 $oTemplate->assign('header_tags', $header_tags);
144 $oTemplate->display('protocol_header.tpl');
145
146 /* this is used to check elsewhere whether we should call this function */
147 $pageheader_sent = TRUE;
148 if (isset($oErrorHandler)) {
149 $oErrorHandler->HeaderSent();
150 }
151
152 }
153
154 /**
155 * Given a path to a SquirrelMail file, return a HTML link to it
156 *
157 * @param string path the SquirrelMail file to link to
158 * @param string text the link text
159 * @param string target the target frame for this link
160 */
161 function makeInternalLink($path, $text, $target='') {
162 global $base_uri;
163 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
164 if ($target != '') {
165 $target = " target=\"$target\"";
166 }
167
168 // This is an inefficient hook and is only used by
169 // one plugin that still needs to patch this code,
170 // plus if we are templat-izing SM, visual hooks
171 // are not needed. However, I am leaving the code
172 // here just in case we find a good (non-visual?)
173 // use for the internal_link hook.
174 //
175 //$hooktext = do_hook_function('internal_link',$text);
176 //if ($hooktext != '')
177 // $text = $hooktext;
178
179 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
180 }
181
182 /**
183 * Same as makeInternalLink, but echoes it too
184 */
185 function displayInternalLink($path, $text, $target='') {
186 // FIXME: should let the template echo all these kinds of things
187 echo makeInternalLink($path, $text, $target);
188 }
189
190 /**
191 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
192 * including the default menu bar. Uses displayHtmlHeader and takes
193 * JavaScript and locale settings into account.
194 *
195 * @param array color the array of theme colors
196 * @param string mailbox the current mailbox name to display
197 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
198 * @param string sBodyTagJs js events to be inserted in the body tag
199 * @return void
200 */
201
202 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
203
204 global $reply_focus, $hide_sm_attributions, $frame_top,
205 $provider_name, $provider_uri, $startMessage,
206 $javascript_on, $action, $oTemplate;
207
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 if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
231 $js_includes = $oTemplate->get_javascript_includes(TRUE);
232 $sJsBlock = '';
233 foreach ($js_includes as $js_file) {
234 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
235 }
236 if ($sHeaderJs) {
237 $sJsBlock .= "\n<script type=\"text/javascript\">" .
238 "\n<!--\n" .
239 $sHeaderJs . "\n\n// -->\n</script>\n";
240 }
241 displayHtmlHeader ('SquirrelMail', $sJsBlock);
242 } else {
243 /* do not use JavaScript */
244 displayHtmlHeader ('SquirrelMail');
245 $sBodyTagJs = '';
246 }
247 /*
248 * this explains the imap_mailbox.php dependency. We should instead store
249 * the selected mailbox in the session and fallback to the session var.
250 */
251 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
252 readShortMailboxName($mailbox, $delimiter)));
253 if ( $shortBoxName == 'INBOX' ) {
254 $shortBoxName = _("INBOX");
255 }
256
257 $sm_attributes = '';
258 if (!$hide_sm_attributions) {
259 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
260 if (empty($provider_uri)) {
261 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
262 } else {
263 if (empty($provider_name)) $provider_name= 'SquirrelMail';
264 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
265 }
266 $sm_attributes .= " </td>\n";
267 }
268
269 $oTemplate->assign('body_tag_js', $sBodyTagJs);
270 $oTemplate->assign('shortBoxName', $shortBoxName);
271 $oTemplate->assign('sm_attribute_str', $sm_attributes);
272 $oTemplate->assign('frame_top', $frame_top);
273 $oTemplate->assign('urlMailbox', $urlMailbox);
274 $oTemplate->assign('startMessage', $startMessage);
275 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
276 $oTemplate->display('page_header.tpl');
277 }
278
279 /**
280 * Blatantly copied/truncated/modified from displayPageHeader.
281 * Outputs a page header specifically for the compose_in_new popup window
282 *
283 * @param array color the array of theme colors
284 * @param string mailbox the current mailbox name to display
285 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
286 * @param string sBodyTagJs js events to be inserted in the body tag
287 * @return void
288 */
289 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
290
291 global $reply_focus, $javascript_on, $action, $oTemplate;
292
293 if (empty($sBodyTagJs)) {
294 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
295 if ($reply_focus == 'select')
296 $sBodyTagJs = 'onload="checkForm(\'select\');"';
297 else if ($reply_focus == 'focus')
298 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
299 else if ($reply_focus != 'none')
300 $sBodyTagJs = 'onload="checkForm();"';
301 }
302 else
303 $sBodyTagJs = 'onload="checkForm();"';
304 }
305
306
307 /*
308 * Locate the first displayable form element (only when JavaScript on)
309 */
310 if($javascript_on) {
311 if ($sHeaderJs) {
312 $sJsBlock = "\n<script type=\"text/javascript\">" .
313 "\n<!--\n" .
314 $sHeaderJs . "\n\n// -->\n</script>\n";
315 } else {
316 $sJsBlock = '';
317 }
318 $sJsBlock .= "\n";
319
320 $js_includes = $oTemplate->get_javascript_includes(TRUE);
321 foreach ($js_includes as $js_file) {
322 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
323 }
324
325 displayHtmlHeader (_("Compose"), $sJsBlock);
326 } else {
327 /* javascript off */
328 displayHtmlHeader(_("Compose"));
329 $onload = '';
330 }
331 // FIXME: should let the template echo all these kinds of things
332 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
333 }