page_header.php 10 KB

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