page_header.php 11 KB

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