page_header.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Prints the page header (duh)
  6. *
  7. * @copyright &copy; 1999-2006 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. * @return void
  25. */
  26. function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = TRUE, $frames = FALSE ) {
  27. global $squirrelmail_language, $sTplDir, $oErrorHandler;
  28. if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
  29. global $base_uri;
  30. }
  31. global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default, $text_direction,
  32. $default_fontset, $chosen_fontset, $default_fontsize, $chosen_fontsize, $chosen_theme;
  33. /* add no cache headers here */
  34. header('Pragma: no-cache'); // http 1.0 (rfc1945)
  35. header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
  36. if ($frames) {
  37. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN"'."\n"
  38. .' "http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd">';
  39. } else {
  40. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
  41. .' "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">';
  42. }
  43. echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
  44. "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
  45. $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
  46. $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
  47. $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
  48. /*
  49. * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
  50. * It is not compatible with html 4.01 Transitional
  51. */
  52. echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
  53. .'?themeid='.$used_theme
  54. .'&amp;templateid='.basename($sTplDir)
  55. .(!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
  56. .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')
  57. .(!empty($text_direction) ? '&amp;dir='.$text_direction : '')."\">\n";
  58. // load custom style sheet (deprecated)
  59. if ( ! empty($theme_css) ) {
  60. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">\n";
  61. }
  62. if ($squirrelmail_language == 'ja_JP') {
  63. /*
  64. * force correct detection of charset, when browser does not follow
  65. * http content-type and tries to detect charset from page content.
  66. * Shooting of browser's creator can't be implemented in php.
  67. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  68. * recommendations and switch to unicode.
  69. */
  70. echo "<!-- \xfd\xfe -->\n";
  71. echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
  72. }
  73. if ($do_hook) {
  74. do_hook('generic_header');
  75. }
  76. echo "<title>$title</title>\n$xtra\n";
  77. /* work around IE6's scrollbar bug */
  78. echo <<<ECHO
  79. <style type="text/css">
  80. <!--
  81. /* avoid stupid IE6 bug with frames and scrollbars */
  82. body {
  83. voice-family: "\"}\"";
  84. voice-family: inherit;
  85. width: expression(document.documentElement.clientWidth - 30);
  86. }
  87. -->
  88. </style>
  89. ECHO;
  90. echo "\n</head>\n\n";
  91. /* this is used to check elsewhere whether we should call this function */
  92. $pageheader_sent = TRUE;
  93. if (isset($oErrorHandler)) {
  94. $oErrorHandler->HeaderSent();
  95. }
  96. }
  97. /**
  98. * Given a path to a SquirrelMail file, return a HTML link to it
  99. *
  100. * @param string path the SquirrelMail file to link to
  101. * @param string text the link text
  102. * @param string target the target frame for this link
  103. */
  104. function makeInternalLink($path, $text, $target='') {
  105. global $base_uri;
  106. // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  107. if ($target != '') {
  108. $target = " target=\"$target\"";
  109. }
  110. // This is an inefficient hook and is only used by
  111. // one plugin that still needs to patch this code,
  112. // plus if we are templat-izing SM, visual hooks
  113. // are not needed. However, I am leaving the code
  114. // here just in case we find a good (non-visual?)
  115. // use for the internal_link hook.
  116. //
  117. //$hooktext = do_hook_function('internal_link',$text);
  118. //if ($hooktext != '')
  119. // $text = $hooktext;
  120. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  121. }
  122. /**
  123. * Same as makeInternalLink, but echoes it too
  124. */
  125. function displayInternalLink($path, $text, $target='') {
  126. echo makeInternalLink($path, $text, $target);
  127. }
  128. /**
  129. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  130. * including the default menu bar. Uses displayHtmlHeader and takes
  131. * JavaScript and locale settings into account.
  132. *
  133. * @param array color the array of theme colors
  134. * @param string mailbox the current mailbox name to display
  135. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  136. * @param string sBodyTagJs js events to be inserted in the body tag
  137. * @return void
  138. */
  139. function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  140. global $reply_focus, $hide_sm_attributions, $frame_top,
  141. $provider_name, $provider_uri, $startMessage,
  142. $javascript_on, $action, $oTemplate;
  143. if (empty($sBodyTagJs)) {
  144. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  145. if ($reply_focus == 'select')
  146. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  147. else if ($reply_focus == 'focus')
  148. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  149. else if ($reply_focus != 'none')
  150. $sBodyTagJs = 'onload="checkForm();"';
  151. }
  152. else
  153. $sBodyTagJs = 'onload="checkForm();"';
  154. }
  155. $urlMailbox = urlencode($mailbox);
  156. $startMessage = (int)$startMessage;
  157. $sTplDir = $oTemplate->template_dir;
  158. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  159. if (!isset($frame_top)) {
  160. $frame_top = '_top';
  161. }
  162. if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  163. $js_includes = $oTemplate->getJavascriptIncludes();
  164. $sJsBlock = '';
  165. foreach ($js_includes as $js_file) {
  166. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  167. }
  168. if ($sHeaderJs) {
  169. $sJsBlock .= "\n<script type=\"text/javascript\">" .
  170. "\n<!--\n" .
  171. $sHeaderJs . "\n\n// -->\n</script>\n";
  172. }
  173. displayHtmlHeader ('SquirrelMail', $sJsBlock);
  174. } else {
  175. /* do not use JavaScript */
  176. displayHtmlHeader ('SquirrelMail');
  177. $sBodyTagJs = '';
  178. }
  179. /*
  180. * this explains the imap_mailbox.php dependency. We should instead store
  181. * the selected mailbox in the session and fallback to the session var.
  182. */
  183. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  184. readShortMailboxName($mailbox, $delimiter)));
  185. if ( $shortBoxName == 'INBOX' ) {
  186. $shortBoxName = _("INBOX");
  187. }
  188. $sm_attributes = '';
  189. if (!$hide_sm_attributions) {
  190. $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
  191. if (empty($provider_uri)) {
  192. $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
  193. } else {
  194. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  195. $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
  196. }
  197. $sm_attributes .= " </td>\n";
  198. }
  199. $oTemplate->assign('body_tag_js', $sBodyTagJs);
  200. $oTemplate->assign('shortBoxName', $shortBoxName);
  201. $oTemplate->assign('sm_attribute_str', $sm_attributes);
  202. $oTemplate->assign('frame_top', $frame_top);
  203. $oTemplate->assign('urlMailbox', $urlMailbox);
  204. $oTemplate->assign('startMessage', $startMessage);
  205. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  206. $oTemplate->display('page_header.tpl');
  207. }
  208. /**
  209. * Blatantly copied/truncated/modified from displayPageHeader.
  210. * Outputs a page header specifically for the compose_in_new popup window
  211. *
  212. * @param array color the array of theme colors
  213. * @param string mailbox the current mailbox name to display
  214. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  215. * @param string sBodyTagJs js events to be inserted in the body tag
  216. * @return void
  217. */
  218. function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  219. global $reply_focus, $javascript_on, $action, $oTemplate;
  220. if (empty($sBodyTagJs)) {
  221. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  222. if ($reply_focus == 'select')
  223. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  224. else if ($reply_focus == 'focus')
  225. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  226. else if ($reply_focus != 'none')
  227. $sBodyTagJs = 'onload="checkForm();"';
  228. }
  229. else
  230. $sBodyTagJs = 'onload="checkForm();"';
  231. }
  232. /*
  233. * Locate the first displayable form element (only when JavaScript on)
  234. */
  235. if($javascript_on) {
  236. if ($sHeaderJs) {
  237. $sJsBlock = "\n<script type=\"text/javascript\">" .
  238. "\n<!--\n" .
  239. $sHeaderJs . "\n\n// -->\n</script>\n";
  240. } else {
  241. $sJsBlock = '';
  242. }
  243. $sJsBlock .= "\n";
  244. $js_includes = $oTemplate->getJavascriptIncludes();
  245. foreach ($js_includes as $js_file) {
  246. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  247. }
  248. displayHtmlHeader (_("Compose"), $sJsBlock);
  249. } else {
  250. /* javascript off */
  251. displayHtmlHeader(_("Compose"));
  252. $onload = '';
  253. }
  254. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  255. }