page_header.php 10 KB

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