page_header.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Prints the page header (duh)
  6. *
  7. * @copyright 1999-2010 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id$
  10. * @package squirrelmail
  11. */
  12. /** Include required files from SM */
  13. include_once(SM_PATH . 'functions/imap_mailbox.php');
  14. /**
  15. * Output a SquirrelMail page header, from <!doctype> to </head>
  16. * Always set up the language before calling these functions.
  17. *
  18. * Since 1.5.1 function sends http headers. Function should be called
  19. * before any output is started.
  20. * @param string title the page title, default SquirrelMail.
  21. * @param string xtra extra HTML to insert into the header
  22. * @param bool do_hook whether to execute hooks, default true
  23. * @param bool frames generate html frameset doctype (since 1.5.1)
  24. * @param bool $browser_cache_ok When TRUE, it's OK to leave out the
  25. * no-cache browser headers (OPTIONAL;
  26. * default = FALSE, send no-cache headers)
  27. * @return void
  28. */
  29. function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE, $browser_cache_ok=FALSE ) {
  30. global $squirrelmail_language, $sTemplateID, $oErrorHandler, $oTemplate;
  31. if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
  32. global $base_uri;
  33. }
  34. global $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
  35. $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize,
  36. $chosen_theme, $chosen_theme_path, $user_themes, $user_theme_default;
  37. // add no cache headers here
  38. //
  39. if (!$browser_cache_ok) {
  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, must-revalidate, max-age=0'); // http 1.1 (rfc2616)
  43. $oTemplate->header('Expires: Sat, 1 Jan 2000 00:00:00 GMT');
  44. //TODO: is this needed? $oTemplate->header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
  45. }
  46. /* prevent information leakage about read emails by forbidding Firefox
  47. * to do preemptive DNS requests for any links in the message body. */
  48. $oTemplate->header('X-DNS-Prefetch-Control: off');
  49. // don't show version as a security measure
  50. //$oTemplate->header('X-Powered-By: SquirrelMail/' . SM_VERSION, FALSE);
  51. $oTemplate->header('X-Powered-By: SquirrelMail', FALSE);
  52. $oTemplate->assign('frames', $frames);
  53. $oTemplate->assign('lang', $squirrelmail_language);
  54. $header_tags = '';
  55. $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n";
  56. $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
  57. $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
  58. $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;
  59. /**
  60. * Stylesheets are loaded in the following order:
  61. * 1) All stylesheets provided by the template. Normally, these are
  62. * stylsheets in templates/<template>/css/. This is accomplished by calling
  63. * $oTemplate->fetch_standard_stylesheet_links().
  64. * 2) An optional user-defined stylesheet. This is set in the Display
  65. * Preferences.
  66. * 3) src/style.php which sets some basic font prefs.
  67. * 4) If we are dealing with an RTL language, we load rtl.css from the
  68. * template set.
  69. */
  70. // 1. Stylesheets from the template.
  71. $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
  72. $aUserStyles = array();
  73. // 2. Option user-defined stylesheet from preferences.
  74. if (!empty($used_theme) && $used_theme != 'none') {
  75. /**
  76. * All styles (except "none" - ugh) just point to a directory,
  77. * so we need to include all .css files in that directory.
  78. */
  79. //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?)
  80. $styles = $used_theme == 'none' ? array()
  81. : list_files($used_theme, '.css');
  82. foreach ($styles as $sheet) {
  83. $aUserStyles[] = $used_theme .'/'.$sheet;
  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. // 3.1. Load the stylesheets we have already
  91. $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
  92. // 4. Optional rtl.css stylesheet
  93. if ($text_direction == 'rtl') {
  94. $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
  95. }
  96. // 5. Printer friendly stylesheet
  97. $header_tags .= create_css_link($base_uri . 'css/print.css', 'printerfriendly', false, 'print');
  98. if ($squirrelmail_language == 'ja_JP') {
  99. /*
  100. * force correct detection of charset, when browser does not follow
  101. * http content-type and tries to detect charset from page content.
  102. * Shooting of browser's creator can't be implemented in php.
  103. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  104. * recommendations and switch to unicode.
  105. */
  106. $header_tags .= "<!-- \xfd\xfe -->\n";
  107. $header_tags .= '<meta http-equiv="Content-type" content="' . $oTemplate->get_content_type() . '; charset=euc-jp" />' . "\n";
  108. }
  109. if ($do_hook) {
  110. // NOTE! plugins here MUST assign output to template
  111. // and NOT echo anything directly!! A common
  112. // approach is if a plugin decides it needs to
  113. // put something at page-top after the standard
  114. // SM page header, to dynamically add itself to
  115. // the page_header_bottom and/or compose_header_bottom
  116. // hooks for the current page request. See
  117. // the Sent Confirmation v1.7 or Restrict Senders v1.2
  118. // plugins for examples of this approach.
  119. ob_start();
  120. $temp = array(&$header_tags);
  121. do_hook('generic_header', $temp);
  122. $output = ob_get_contents();
  123. ob_end_clean();
  124. // plugin authors can debug their errors with one of the following:
  125. //sm_print_r($output);
  126. //echo $output;
  127. if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR);
  128. }
  129. $header_tags .= $xtra;
  130. $oTemplate->assign('page_title', $title);
  131. /* work around IE6's scrollbar bug */
  132. $header_tags .= <<<EOS
  133. <!--[if IE 6]>
  134. <style type="text/css">
  135. /* avoid stupid IE6 bug with frames and scrollbars */
  136. body {
  137. width: expression(document.documentElement.clientWidth - 30);
  138. }
  139. </style>
  140. <![endif]-->
  141. EOS;
  142. $oTemplate->assign('header_tags', $header_tags);
  143. $oTemplate->display('protocol_header.tpl');
  144. /* this is used to check elsewhere whether we should call this function */
  145. $pageheader_sent = TRUE;
  146. if (isset($oErrorHandler)) {
  147. $oErrorHandler->HeaderSent();
  148. }
  149. }
  150. /**
  151. * Given a path to a SquirrelMail file, return a HTML link to it
  152. *
  153. * @param string $path The SquirrelMail file to link to
  154. * (should start with something like "src/..." or
  155. * "functions/..." or "plugins/..." etc.)
  156. * @param string $text The link text
  157. * @param string $target The target frame for this link
  158. * @param string $accesskey The access key to be used, if any
  159. */
  160. function makeInternalLink($path, $text, $target='', $accesskey='NONE') {
  161. global $base_uri, $oTemplate;
  162. // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  163. // This is an inefficient hook and is only used by
  164. // one plugin that still needs to patch this code,
  165. // plus if we are templat-izing SM, visual hooks
  166. // are not needed. However, I am leaving the code
  167. // here just in case we find a good (non-visual?)
  168. // use for the internal_link hook.
  169. //
  170. //do_hook('internal_link', $text);
  171. return create_hyperlink($base_uri . $path, $text, $target,
  172. '', '', '', '',
  173. ($accesskey == 'NONE'
  174. ? array()
  175. : array('accesskey' => $accesskey)));
  176. }
  177. /**
  178. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  179. * including the default menu bar. Uses displayHtmlHeader and takes
  180. * JavaScript and locale settings into account.
  181. *
  182. * @param array color the array of theme colors
  183. * @param string mailbox the current mailbox name to display
  184. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  185. * @param string sOnload JavaScript code to be added inside the body's onload handler
  186. * as of 1.5.2, this replaces $sBodyTagJs argument
  187. * @return void
  188. */
  189. function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sOnload = '') {
  190. global $reply_focus, $hide_sm_attributions, $frame_top,
  191. $provider_name, $provider_uri, $startMessage,
  192. $action, $oTemplate, $org_title, $base_uri,
  193. $data_dir, $username;
  194. if (empty($sOnload)) {
  195. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  196. if ($reply_focus == 'select')
  197. $sOnload = 'checkForm(\'select\');';
  198. else if ($reply_focus == 'focus')
  199. $sOnload = 'checkForm(\'focus\');';
  200. else if ($reply_focus != 'none')
  201. $sOnload = 'checkForm();';
  202. }
  203. else
  204. $sOnload = 'checkForm();';
  205. }
  206. $startMessage = (int)$startMessage;
  207. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  208. if (!isset($frame_top)) {
  209. $frame_top = '_top';
  210. }
  211. //FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary?? (that is, I think checkForJavascript() might already look for new_js_autodetect_results...(?))
  212. if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  213. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  214. $sJsBlock = '';
  215. foreach ($js_includes as $js_file) {
  216. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  217. }
  218. if ($sHeaderJs) {
  219. $sJsBlock .= "\n<script type=\"text/javascript\">" .
  220. "\n<!--\n" .
  221. $sHeaderJs . "\n\n// -->\n</script>\n";
  222. }
  223. displayHtmlHeader ($org_title, $sJsBlock);
  224. } else {
  225. /* do not use JavaScript */
  226. displayHtmlHeader ($org_title);
  227. $sOnload = '';
  228. }
  229. if ($mailbox) {
  230. /*
  231. * this explains the imap_mailbox.php dependency. We should instead store
  232. * the selected mailbox in the session and fallback to the session var.
  233. */
  234. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  235. readShortMailboxName($mailbox, $delimiter)));
  236. if (getPref($data_dir, $username, 'translate_special_folders')) {
  237. global $sent_folder, $trash_folder, $draft_folder;
  238. if ($mailbox == $sent_folder)
  239. $shortBoxName = _("Sent");
  240. else if ($mailbox == $trash_folder)
  241. $shortBoxName = _("Trash");
  242. else if ($mailbox == $sent_folder)
  243. $shortBoxName = _("Drafts");
  244. }
  245. $urlMailbox = urlencode($mailbox);
  246. } else {
  247. $shortBoxName = '';
  248. $urlMailbox = '';
  249. }
  250. $provider_link = '';
  251. if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
  252. $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
  253. }
  254. $oTemplate->assign('onload', $sOnload);
  255. $oTemplate->assign('shortBoxName', $shortBoxName);
  256. $oTemplate->assign('provider_link', $provider_link);
  257. $oTemplate->assign('frame_top', $frame_top);
  258. $oTemplate->assign('urlMailbox', $urlMailbox);
  259. $oTemplate->assign('startMessage', $startMessage);
  260. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  261. // access keys
  262. //
  263. global $accesskey_menubar_compose, $accesskey_menubar_addresses,
  264. $accesskey_menubar_folders, $accesskey_menubar_options,
  265. $accesskey_menubar_search, $accesskey_menubar_help,
  266. $accesskey_menubar_signout;
  267. $oTemplate->assign('accesskey_menubar_compose', $accesskey_menubar_compose);
  268. $oTemplate->assign('accesskey_menubar_addresses', $accesskey_menubar_addresses);
  269. $oTemplate->assign('accesskey_menubar_folders', $accesskey_menubar_folders);
  270. $oTemplate->assign('accesskey_menubar_options', $accesskey_menubar_options);
  271. $oTemplate->assign('accesskey_menubar_search', $accesskey_menubar_search);
  272. $oTemplate->assign('accesskey_menubar_help', $accesskey_menubar_help);
  273. $oTemplate->assign('accesskey_menubar_signout', $accesskey_menubar_signout);
  274. $oTemplate->display('page_header.tpl');
  275. global $null;
  276. do_hook('page_header_bottom', $null);
  277. }
  278. /**
  279. * Blatantly copied/truncated/modified from displayPageHeader.
  280. * Outputs a page header specifically for the compose_in_new popup window
  281. *
  282. * @param array color the array of theme colors
  283. * @param string mailbox the current mailbox name to display
  284. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  285. * @param string sOnload JavaScript code to be added inside the body's onload handler
  286. * as of 1.5.2, this replaces $sBodyTagJs argument
  287. * @return void
  288. */
  289. function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
  290. global $reply_focus, $action, $oTemplate;
  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. * Locate the first displayable form element (only when JavaScript on)
  305. */
  306. if(checkForJavascript()) {
  307. if ($sHeaderJs) {
  308. $sJsBlock = "\n<script type=\"text/javascript\">" .
  309. "\n<!--\n" .
  310. $sHeaderJs . "\n\n// -->\n</script>\n";
  311. } else {
  312. $sJsBlock = '';
  313. }
  314. $sJsBlock .= "\n";
  315. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  316. foreach ($js_includes as $js_file) {
  317. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  318. }
  319. displayHtmlHeader (_("Compose"), $sJsBlock);
  320. } else {
  321. /* javascript off */
  322. displayHtmlHeader(_("Compose"));
  323. $sOnload = '';
  324. }
  325. // FIXME: change the colorization attributes below to a CSS class!
  326. $class = '';
  327. $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
  328. 'link' => $color[7], 'vlink' => $color[7],
  329. 'alink' => $color[7]);
  330. // this is template-safe (see create_body() function)
  331. echo create_body($sOnload, $class, $aAttribs);
  332. global $null;
  333. do_hook('compose_header_bottom', $null);
  334. }