page_header.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. /** @ignore */
  13. if (! defined('SM_PATH')) define('SM_PATH','../');
  14. /** Include required files from SM */
  15. require_once(SM_PATH . 'functions/strings.php');
  16. require_once(SM_PATH . 'functions/html.php');
  17. require_once(SM_PATH . 'functions/imap_mailbox.php');
  18. require_once(SM_PATH . 'functions/global.php');
  19. include_once(SM_PATH . 'class/template/template.class.php');
  20. /**
  21. * Output a SquirrelMail page header, from <!doctype> to </head>
  22. * Always set up the language before calling these functions.
  23. *
  24. * Since 1.5.1 function sends http headers. Function should be called
  25. * before any output is started.
  26. * @param string title the page title, default SquirrelMail.
  27. * @param string xtra extra HTML to insert into the header
  28. * @param bool do_hook whether to execute hooks, default true
  29. * @param bool frames generate html frameset doctype (since 1.5.1)
  30. * @return void
  31. */
  32. function displayHtmlHeader( $title = 'SquirrelMail', $xtra = '', $do_hook = true, $frames = false ) {
  33. global $squirrelmail_language, $sTplDir;
  34. if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
  35. global $base_uri;
  36. }
  37. global $theme_css, $custom_css, $pageheader_sent,
  38. $chosen_fontset, $chosen_fontsize, $chosen_theme;
  39. /* add no cache headers here */
  40. header('Pragma: no-cache'); // http 1.0 (rfc1945)
  41. header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
  42. if ($frames) {
  43. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">';
  44. } else {
  45. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
  46. }
  47. echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
  48. "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
  49. $used_theme = basename($chosen_theme,'.php');
  50. /*
  51. * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
  52. * It is not compatible with html 4.01 Transitional
  53. */
  54. echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
  55. .'?fontset='.$chosen_fontset
  56. .'&themeid='.$used_theme
  57. .(isset($chosen_fontsize) ? '&fontsize='.$chosen_fontsize : '')."\">\n";
  58. // load custom style sheet (deprecated)
  59. if ( !isset( $theme_css ) || empty($theme_css) ) {
  60. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
  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. }
  94. /**
  95. * Given a path to a SquirrelMail file, return a HTML link to it
  96. *
  97. * @param string path the SquirrelMail file to link to
  98. * @param string text the link text
  99. * @param string target the target frame for this link
  100. */
  101. function makeInternalLink($path, $text, $target='') {
  102. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  103. if ($target != '') {
  104. $target = " target=\"$target\"";
  105. }
  106. // This is an inefficient hook and is only used by
  107. // one plugin that still needs to patch this code,
  108. // plus if we are templat-izing SM, visual hooks
  109. // are not needed. However, I am leaving the code
  110. // here just in case we find a good (non-visual?)
  111. // use for the internal_link hook.
  112. //
  113. //$hooktext = do_hook_function('internal_link',$text);
  114. //if ($hooktext != '')
  115. // $text = $hooktext;
  116. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  117. }
  118. /**
  119. * Same as makeInternalLink, but echoes it too
  120. */
  121. function displayInternalLink($path, $text, $target='') {
  122. echo makeInternalLink($path, $text, $target);
  123. }
  124. /**
  125. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  126. * including the default menu bar. Uses displayHtmlHeader and takes
  127. * JavaScript and locale settings into account.
  128. *
  129. * @param array color the array of theme colors
  130. * @param string mailbox the current mailbox name to display
  131. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  132. * @param string sBodyTagJs js events to be inserted in the body tag
  133. * @return void
  134. */
  135. function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  136. global $reply_focus, $hide_sm_attributions, $frame_top,
  137. $provider_name, $provider_uri, $startMessage,
  138. $javascript_on, $action, $oTemplate;
  139. if (empty($sBodyTagJs)) {
  140. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  141. if ($reply_focus == 'select')
  142. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  143. else if ($reply_focus == 'focus')
  144. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  145. else if ($reply_focus != 'none')
  146. $sBodyTagJs = 'onload="checkForm();"';
  147. }
  148. else
  149. $sBodyTagJs = 'onload="checkForm();"';
  150. }
  151. $urlMailbox = urlencode($mailbox);
  152. $startMessage = (int)$startMessage;
  153. $sTplDir = $oTemplate->template_dir;
  154. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  155. if (!isset($frame_top)) {
  156. $frame_top = '_top';
  157. }
  158. if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  159. $sJsBlock = '<script src="'. $sTplDir. 'js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
  160. if ($sHeaderJs) {
  161. $sJsBlock .= "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
  162. "\n<!--\n" .
  163. $sHeaderJs . "\n\n// -->\n</script>\n";
  164. }
  165. displayHtmlHeader ('SquirrelMail', $sJsBlock);
  166. } else {
  167. /* do not use JavaScript */
  168. displayHtmlHeader ('SquirrelMail');
  169. $sBodyTagJs = '';
  170. }
  171. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  172. readShortMailboxName($mailbox, $delimiter)));
  173. if ( $shortBoxName == 'INBOX' ) {
  174. $shortBoxName = _("INBOX");
  175. }
  176. $sm_attributes = '';
  177. if (!$hide_sm_attributions) {
  178. $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
  179. if (empty($provider_uri)) {
  180. $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
  181. } else {
  182. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  183. $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
  184. }
  185. $sm_attributes .= " </td>\n";
  186. }
  187. $oTemplate->assign('body_tag_js', $sBodyTagJs);
  188. $oTemplate->assign('shortBoxName', $shortBoxName);
  189. $oTemplate->assign('sm_attribute_str', $sm_attributes);
  190. $oTemplate->assign('frame_top', $frame_top);
  191. $oTemplate->assign('urlMailbox', $urlMailbox);
  192. $oTemplate->assign('startMessage', $startMessage);
  193. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  194. $oTemplate->display('page_header.tpl');
  195. }
  196. /**
  197. * Blatantly copied/truncated/modified from displayPageHeader.
  198. * Outputs a page header specifically for the compose_in_new popup window
  199. *
  200. * @param array color the array of theme colors
  201. * @param string mailbox the current mailbox name to display
  202. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  203. * @param string sBodyTagJs js events to be inserted in the body tag
  204. * @return void
  205. */
  206. function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  207. global $reply_focus, $javascript_on, $action;
  208. if (empty($sBodyTagJs)) {
  209. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  210. if ($reply_focus == 'select')
  211. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  212. else if ($reply_focus == 'focus')
  213. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  214. else if ($reply_focus != 'none')
  215. $sBodyTagJs = 'onload="checkForm();"';
  216. }
  217. else
  218. $sBodyTagJs = 'onload="checkForm();"';
  219. }
  220. /*
  221. * Locate the first displayable form element (only when JavaScript on)
  222. */
  223. if($javascript_on) {
  224. if ($sHeaderJs) {
  225. $sJsBlock = "\n<script language=\"JavaScript\" type=\"text/javascript\">" .
  226. "\n<!--\n" .
  227. $sHeaderJs . "\n\n// -->\n</script>\n";
  228. } else {
  229. $sJsBlock = '';
  230. }
  231. $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript" language="JavaScript"></script>' ."\n";
  232. displayHtmlHeader (_("Compose"), $sJsBlock);
  233. } else {
  234. /* javascript off */
  235. displayHtmlHeader(_("Compose"));
  236. $onload = '';
  237. }
  238. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  239. }
  240. ?>