page_header.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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, $oErroHandler;
  34. if ( !sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION) ) {
  35. global $base_uri;
  36. }
  37. global $theme_css, $custom_css, $pageheader_sent, $theme, $theme_default,
  38. $default_fontset, $chosen_fontset, $default_fontsize, $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"'."\n"
  44. .' "http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd">';
  45. } else {
  46. echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"'."\n"
  47. .' "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">';
  48. }
  49. echo "\n" . html_tag( 'html' ,'' , '', '', 'lang="'.$squirrelmail_language.'"' ) .
  50. "<head>\n<meta name=\"robots\" content=\"noindex,nofollow\">\n";
  51. $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
  52. $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
  53. $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
  54. /*
  55. * Add closing / to link and meta elements only after switching to xhtml 1.0 Transitional.
  56. * It is not compatible with html 4.01 Transitional
  57. */
  58. echo '<link rel="stylesheet" type="text/css" href="'. $base_uri .'src/style.php'
  59. .'?themeid='.$used_theme
  60. .'&amp;templateid='.basename($sTplDir)
  61. .(!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
  62. .(!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '')."\">\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. <style type="text/css">
  85. <!--
  86. /* avoid stupid IE6 bug with frames and scrollbars */
  87. body {
  88. voice-family: "\"}\"";
  89. voice-family: inherit;
  90. width: expression(document.documentElement.clientWidth - 30);
  91. }
  92. -->
  93. </style>
  94. ECHO;
  95. echo "\n</head>\n\n";
  96. /* this is used to check elsewhere whether we should call this function */
  97. $pageheader_sent = TRUE;
  98. if (isset($oErrorHandler)) {
  99. $oErrorHander->HeaderSent();
  100. }
  101. }
  102. /**
  103. * Given a path to a SquirrelMail file, return a HTML link to it
  104. *
  105. * @param string path the SquirrelMail file to link to
  106. * @param string text the link text
  107. * @param string target the target frame for this link
  108. */
  109. function makeInternalLink($path, $text, $target='') {
  110. sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  111. if ($target != '') {
  112. $target = " target=\"$target\"";
  113. }
  114. // This is an inefficient hook and is only used by
  115. // one plugin that still needs to patch this code,
  116. // plus if we are templat-izing SM, visual hooks
  117. // are not needed. However, I am leaving the code
  118. // here just in case we find a good (non-visual?)
  119. // use for the internal_link hook.
  120. //
  121. //$hooktext = do_hook_function('internal_link',$text);
  122. //if ($hooktext != '')
  123. // $text = $hooktext;
  124. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  125. }
  126. /**
  127. * Same as makeInternalLink, but echoes it too
  128. */
  129. function displayInternalLink($path, $text, $target='') {
  130. echo makeInternalLink($path, $text, $target);
  131. }
  132. /**
  133. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  134. * including the default menu bar. Uses displayHtmlHeader and takes
  135. * JavaScript and locale settings into account.
  136. *
  137. * @param array color the array of theme colors
  138. * @param string mailbox the current mailbox name to display
  139. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  140. * @param string sBodyTagJs js events to be inserted in the body tag
  141. * @return void
  142. */
  143. function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  144. global $reply_focus, $hide_sm_attributions, $frame_top,
  145. $provider_name, $provider_uri, $startMessage,
  146. $javascript_on, $action, $oTemplate;
  147. if (empty($sBodyTagJs)) {
  148. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  149. if ($reply_focus == 'select')
  150. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  151. else if ($reply_focus == 'focus')
  152. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  153. else if ($reply_focus != 'none')
  154. $sBodyTagJs = 'onload="checkForm();"';
  155. }
  156. else
  157. $sBodyTagJs = 'onload="checkForm();"';
  158. }
  159. $urlMailbox = urlencode($mailbox);
  160. $startMessage = (int)$startMessage;
  161. $sTplDir = $oTemplate->template_dir;
  162. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  163. if (!isset($frame_top)) {
  164. $frame_top = '_top';
  165. }
  166. if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  167. $sJsBlock = '<script src="'. $sTplDir. 'js/default.js" type="text/javascript"></script>' ."\n";
  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. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  180. readShortMailboxName($mailbox, $delimiter)));
  181. if ( $shortBoxName == 'INBOX' ) {
  182. $shortBoxName = _("INBOX");
  183. }
  184. $sm_attributes = '';
  185. if (!$hide_sm_attributions) {
  186. $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
  187. if (empty($provider_uri)) {
  188. $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
  189. } else {
  190. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  191. $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
  192. }
  193. $sm_attributes .= " </td>\n";
  194. }
  195. $oTemplate->assign('body_tag_js', $sBodyTagJs);
  196. $oTemplate->assign('shortBoxName', $shortBoxName);
  197. $oTemplate->assign('sm_attribute_str', $sm_attributes);
  198. $oTemplate->assign('frame_top', $frame_top);
  199. $oTemplate->assign('urlMailbox', $urlMailbox);
  200. $oTemplate->assign('startMessage', $startMessage);
  201. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  202. $oTemplate->display('page_header.tpl');
  203. }
  204. /**
  205. * Blatantly copied/truncated/modified from displayPageHeader.
  206. * Outputs a page header specifically for the compose_in_new popup window
  207. *
  208. * @param array color the array of theme colors
  209. * @param string mailbox the current mailbox name to display
  210. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  211. * @param string sBodyTagJs js events to be inserted in the body tag
  212. * @return void
  213. */
  214. function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  215. global $reply_focus, $javascript_on, $action;
  216. if (empty($sBodyTagJs)) {
  217. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  218. if ($reply_focus == 'select')
  219. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  220. else if ($reply_focus == 'focus')
  221. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  222. else if ($reply_focus != 'none')
  223. $sBodyTagJs = 'onload="checkForm();"';
  224. }
  225. else
  226. $sBodyTagJs = 'onload="checkForm();"';
  227. }
  228. /*
  229. * Locate the first displayable form element (only when JavaScript on)
  230. */
  231. if($javascript_on) {
  232. if ($sHeaderJs) {
  233. $sJsBlock = "\n<script type=\"text/javascript\">" .
  234. "\n<!--\n" .
  235. $sHeaderJs . "\n\n// -->\n</script>\n";
  236. } else {
  237. $sJsBlock = '';
  238. }
  239. $sJsBlock .= "\n" . '<script src="'. SM_PATH .'templates/default/js/default.js" type="text/javascript"></script>' ."\n";
  240. displayHtmlHeader (_("Compose"), $sJsBlock);
  241. } else {
  242. /* javascript off */
  243. displayHtmlHeader(_("Compose"));
  244. $onload = '';
  245. }
  246. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  247. }
  248. ?>