page_header.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. <!--[if IE 6]>
  80. <style type="text/css">
  81. /* avoid stupid IE6 bug with frames and scrollbars */
  82. body {
  83. width: expression(document.documentElement.clientWidth - 30);
  84. }
  85. </style>
  86. <![endif]-->
  87. ECHO;
  88. echo "\n</head>\n\n";
  89. /* this is used to check elsewhere whether we should call this function */
  90. $pageheader_sent = TRUE;
  91. if (isset($oErrorHandler)) {
  92. $oErrorHandler->HeaderSent();
  93. }
  94. }
  95. /**
  96. * Given a path to a SquirrelMail file, return a HTML link to it
  97. *
  98. * @param string path the SquirrelMail file to link to
  99. * @param string text the link text
  100. * @param string target the target frame for this link
  101. */
  102. function makeInternalLink($path, $text, $target='') {
  103. global $base_uri;
  104. // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  105. if ($target != '') {
  106. $target = " target=\"$target\"";
  107. }
  108. // This is an inefficient hook and is only used by
  109. // one plugin that still needs to patch this code,
  110. // plus if we are templat-izing SM, visual hooks
  111. // are not needed. However, I am leaving the code
  112. // here just in case we find a good (non-visual?)
  113. // use for the internal_link hook.
  114. //
  115. //$hooktext = do_hook_function('internal_link',$text);
  116. //if ($hooktext != '')
  117. // $text = $hooktext;
  118. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  119. }
  120. /**
  121. * Same as makeInternalLink, but echoes it too
  122. */
  123. function displayInternalLink($path, $text, $target='') {
  124. echo makeInternalLink($path, $text, $target);
  125. }
  126. /**
  127. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  128. * including the default menu bar. Uses displayHtmlHeader and takes
  129. * JavaScript and locale settings into account.
  130. *
  131. * @param array color the array of theme colors
  132. * @param string mailbox the current mailbox name to display
  133. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  134. * @param string sBodyTagJs js events to be inserted in the body tag
  135. * @return void
  136. */
  137. function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  138. global $reply_focus, $hide_sm_attributions, $frame_top,
  139. $provider_name, $provider_uri, $startMessage,
  140. $javascript_on, $action, $oTemplate;
  141. if (empty($sBodyTagJs)) {
  142. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  143. if ($reply_focus == 'select')
  144. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  145. else if ($reply_focus == 'focus')
  146. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  147. else if ($reply_focus != 'none')
  148. $sBodyTagJs = 'onload="checkForm();"';
  149. }
  150. else
  151. $sBodyTagJs = 'onload="checkForm();"';
  152. }
  153. $urlMailbox = urlencode($mailbox);
  154. $startMessage = (int)$startMessage;
  155. $sTplDir = $oTemplate->template_dir;
  156. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  157. if (!isset($frame_top)) {
  158. $frame_top = '_top';
  159. }
  160. if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  161. $js_includes = $oTemplate->getJavascriptIncludes();
  162. $sJsBlock = '';
  163. foreach ($js_includes as $js_file) {
  164. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  165. }
  166. if ($sHeaderJs) {
  167. $sJsBlock .= "\n<script type=\"text/javascript\">" .
  168. "\n<!--\n" .
  169. $sHeaderJs . "\n\n// -->\n</script>\n";
  170. }
  171. displayHtmlHeader ('SquirrelMail', $sJsBlock);
  172. } else {
  173. /* do not use JavaScript */
  174. displayHtmlHeader ('SquirrelMail');
  175. $sBodyTagJs = '';
  176. }
  177. /*
  178. * this explains the imap_mailbox.php dependency. We should instead store
  179. * the selected mailbox in the session and fallback to the session var.
  180. */
  181. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  182. readShortMailboxName($mailbox, $delimiter)));
  183. if ( $shortBoxName == 'INBOX' ) {
  184. $shortBoxName = _("INBOX");
  185. }
  186. $sm_attributes = '';
  187. if (!$hide_sm_attributions) {
  188. $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
  189. if (empty($provider_uri)) {
  190. $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
  191. } else {
  192. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  193. $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
  194. }
  195. $sm_attributes .= " </td>\n";
  196. }
  197. $oTemplate->assign('body_tag_js', $sBodyTagJs);
  198. $oTemplate->assign('shortBoxName', $shortBoxName);
  199. $oTemplate->assign('sm_attribute_str', $sm_attributes);
  200. $oTemplate->assign('frame_top', $frame_top);
  201. $oTemplate->assign('urlMailbox', $urlMailbox);
  202. $oTemplate->assign('startMessage', $startMessage);
  203. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  204. $oTemplate->display('page_header.tpl');
  205. }
  206. /**
  207. * Blatantly copied/truncated/modified from displayPageHeader.
  208. * Outputs a page header specifically for the compose_in_new popup window
  209. *
  210. * @param array color the array of theme colors
  211. * @param string mailbox the current mailbox name to display
  212. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  213. * @param string sBodyTagJs js events to be inserted in the body tag
  214. * @return void
  215. */
  216. function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  217. global $reply_focus, $javascript_on, $action, $oTemplate;
  218. if (empty($sBodyTagJs)) {
  219. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  220. if ($reply_focus == 'select')
  221. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  222. else if ($reply_focus == 'focus')
  223. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  224. else if ($reply_focus != 'none')
  225. $sBodyTagJs = 'onload="checkForm();"';
  226. }
  227. else
  228. $sBodyTagJs = 'onload="checkForm();"';
  229. }
  230. /*
  231. * Locate the first displayable form element (only when JavaScript on)
  232. */
  233. if($javascript_on) {
  234. if ($sHeaderJs) {
  235. $sJsBlock = "\n<script type=\"text/javascript\">" .
  236. "\n<!--\n" .
  237. $sHeaderJs . "\n\n// -->\n</script>\n";
  238. } else {
  239. $sJsBlock = '';
  240. }
  241. $sJsBlock .= "\n";
  242. $js_includes = $oTemplate->getJavascriptIncludes();
  243. foreach ($js_includes as $js_file) {
  244. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  245. }
  246. displayHtmlHeader (_("Compose"), $sJsBlock);
  247. } else {
  248. /* javascript off */
  249. displayHtmlHeader(_("Compose"));
  250. $onload = '';
  251. }
  252. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  253. }