Apply correct stylesheets for RTL languages
[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 $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 //FIXME: should change all header() calls in SM core to use $oTemplate->header()!!
40 $oTemplate->header('Pragma: no-cache'); // http 1.0 (rfc1945)
41 $oTemplate->header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
42
43 $oTemplate->assign('frames', $frames);
44 $oTemplate->assign('lang', $squirrelmail_language);
45
46 $header_tags = '';
47
48 $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
49
50 $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
51 $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
52 $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
53
54 $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
55 $aUserStyles = array();
56 //FIXME: remove this!!
57 // load custom style sheet (deprecated)
58 if ( ! empty($theme_css) ) {
59 $aUserStyles[] = $theme_css;
60 }
61 // 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)
62 // 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?
63 // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
64 $aUserStyles[] = $base_uri .'src/style.php'
65 . '?themeid='.$used_theme
66 . '&amp;templateid='.$sTemplateID
67 . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
68 . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
69 . (!empty($text_direction) ? '&amp;dir='.$text_direction : '');
70 $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
71
72 if ($text_direction == 'rtl') {
73 $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
74 }
75
76 if ($squirrelmail_language == 'ja_JP') {
77 /*
78 * force correct detection of charset, when browser does not follow
79 * http content-type and tries to detect charset from page content.
80 * Shooting of browser's creator can't be implemented in php.
81 * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
82 * recommendations and switch to unicode.
83 */
84 $header_tags .= "<!-- \xfd\xfe -->\n";
85 $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
86 }
87 if ($do_hook) {
88 // NOTE! plugins here must assign output to template
89 // and NOT echo anything directly!!
90 do_hook('generic_header');
91 }
92
93 $header_tags .= $xtra;
94 $oTemplate->assign('page_title', $title);
95
96 /* work around IE6's scrollbar bug */
97 $header_tags .= <<<EOS
98 <!--[if IE 6]>
99 <style type="text/css">
100 /* avoid stupid IE6 bug with frames and scrollbars */
101 body {
102 width: expression(document.documentElement.clientWidth - 30);
103 }
104 </style>
105 <![endif]-->
106
107 EOS;
108
109 $oTemplate->assign('header_tags', $header_tags);
110 $oTemplate->display('protocol_header.tpl');
111
112 /* this is used to check elsewhere whether we should call this function */
113 $pageheader_sent = TRUE;
114 if (isset($oErrorHandler)) {
115 $oErrorHandler->HeaderSent();
116 }
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 */
127 function makeInternalLink($path, $text, $target='') {
128 global $base_uri;
129 // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
130 if ($target != '') {
131 $target = " target=\"$target\"";
132 }
133
134 // This is an inefficient hook and is only used by
135 // one plugin that still needs to patch this code,
136 // plus if we are templat-izing SM, visual hooks
137 // are not needed. However, I am leaving the code
138 // here just in case we find a good (non-visual?)
139 // use for the internal_link hook.
140 //
141 //$hooktext = do_hook_function('internal_link',$text);
142 //if ($hooktext != '')
143 // $text = $hooktext;
144
145 return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
146 }
147
148 /**
149 * Same as makeInternalLink, but echoes it too
150 */
151 function displayInternalLink($path, $text, $target='') {
152 // FIXME: should let the template echo all these kinds of things
153 echo makeInternalLink($path, $text, $target);
154 }
155
156 /**
157 * Outputs a complete SquirrelMail page header, starting with <!doctype> and
158 * including the default menu bar. Uses displayHtmlHeader and takes
159 * JavaScript and locale settings into account.
160 *
161 * @param array color the array of theme colors
162 * @param string mailbox the current mailbox name to display
163 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
164 * @param string sBodyTagJs js events to be inserted in the body tag
165 * @return void
166 */
167
168 function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
169
170 global $reply_focus, $hide_sm_attributions, $frame_top,
171 $provider_name, $provider_uri, $startMessage,
172 $javascript_on, $action, $oTemplate;
173
174 if (empty($sBodyTagJs)) {
175 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
176 if ($reply_focus == 'select')
177 $sBodyTagJs = 'onload="checkForm(\'select\');"';
178 else if ($reply_focus == 'focus')
179 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
180 else if ($reply_focus != 'none')
181 $sBodyTagJs = 'onload="checkForm();"';
182 }
183 else
184 $sBodyTagJs = 'onload="checkForm();"';
185 }
186
187 $urlMailbox = urlencode($mailbox);
188 $startMessage = (int)$startMessage;
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 $js_includes = $oTemplate->get_javascript_includes(TRUE);
198 $sJsBlock = '';
199 foreach ($js_includes as $js_file) {
200 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
201 }
202 if ($sHeaderJs) {
203 $sJsBlock .= "\n<script type=\"text/javascript\">" .
204 "\n<!--\n" .
205 $sHeaderJs . "\n\n// -->\n</script>\n";
206 }
207 displayHtmlHeader ('SquirrelMail', $sJsBlock);
208 } else {
209 /* do not use JavaScript */
210 displayHtmlHeader ('SquirrelMail');
211 $sBodyTagJs = '';
212 }
213 /*
214 * this explains the imap_mailbox.php dependency. We should instead store
215 * the selected mailbox in the session and fallback to the session var.
216 */
217 $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
218 readShortMailboxName($mailbox, $delimiter)));
219 if ( $shortBoxName == 'INBOX' ) {
220 $shortBoxName = _("INBOX");
221 }
222
223 $sm_attributes = '';
224 if (!$hide_sm_attributions) {
225 $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
226 if (empty($provider_uri)) {
227 $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
228 } else {
229 if (empty($provider_name)) $provider_name= 'SquirrelMail';
230 $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
231 }
232 $sm_attributes .= " </td>\n";
233 }
234
235 $oTemplate->assign('body_tag_js', $sBodyTagJs);
236 $oTemplate->assign('shortBoxName', $shortBoxName);
237 $oTemplate->assign('sm_attribute_str', $sm_attributes);
238 $oTemplate->assign('frame_top', $frame_top);
239 $oTemplate->assign('urlMailbox', $urlMailbox);
240 $oTemplate->assign('startMessage', $startMessage);
241 $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
242 $oTemplate->display('page_header.tpl');
243 }
244
245 /**
246 * Blatantly copied/truncated/modified from displayPageHeader.
247 * Outputs a page header specifically for the compose_in_new popup window
248 *
249 * @param array color the array of theme colors
250 * @param string mailbox the current mailbox name to display
251 * @param string sHeaderJs javascipt code to be inserted in a script block in the header
252 * @param string sBodyTagJs js events to be inserted in the body tag
253 * @return void
254 */
255 function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
256
257 global $reply_focus, $javascript_on, $action, $oTemplate;
258
259 if (empty($sBodyTagJs)) {
260 if (strpos($action, 'reply') !== FALSE && $reply_focus) {
261 if ($reply_focus == 'select')
262 $sBodyTagJs = 'onload="checkForm(\'select\');"';
263 else if ($reply_focus == 'focus')
264 $sBodyTagJs = 'onload="checkForm(\'focus\');"';
265 else if ($reply_focus != 'none')
266 $sBodyTagJs = 'onload="checkForm();"';
267 }
268 else
269 $sBodyTagJs = 'onload="checkForm();"';
270 }
271
272
273 /*
274 * Locate the first displayable form element (only when JavaScript on)
275 */
276 if($javascript_on) {
277 if ($sHeaderJs) {
278 $sJsBlock = "\n<script type=\"text/javascript\">" .
279 "\n<!--\n" .
280 $sHeaderJs . "\n\n// -->\n</script>\n";
281 } else {
282 $sJsBlock = '';
283 }
284 $sJsBlock .= "\n";
285
286 $js_includes = $oTemplate->get_javascript_includes(TRUE);
287 foreach ($js_includes as $js_file) {
288 $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
289 }
290
291 displayHtmlHeader (_("Compose"), $sJsBlock);
292 } else {
293 /* javascript off */
294 displayHtmlHeader(_("Compose"));
295 $onload = '';
296 }
297 // FIXME: should let the template echo all these kinds of things
298 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
299 }