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