page_header.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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, $sTemplateID, $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. //FIXME: should change all header() calls in SM core to use $oTemplate->header()!!
  35. $oTemplate->header('Pragma: no-cache'); // http 1.0 (rfc1945)
  36. $oTemplate->header('Cache-Control: private, no-cache, no-store'); // http 1.1 (rfc2616)
  37. $oTemplate->assign('frames', $frames);
  38. $oTemplate->assign('lang', $squirrelmail_language);
  39. $header_tags = '';
  40. $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\">\n";
  41. $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
  42. $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
  43. $used_theme = basename((!empty($chosen_theme) ? $chosen_theme : $theme[$theme_default]['PATH']),'.php');
  44. /**
  45. * Stylesheets are loaded in the following order:
  46. * 1) All stylesheets provided by the template. Normally, these are
  47. * stylsheets in templates/<template>/css/. This is accomplished by calling
  48. * $oTemplate->fetch_standard_stylesheet_links().
  49. * 2) An optional user-defined stylesheet. This is set in the Display
  50. * Preferences.
  51. * 3) src/style.php which sets some basic font prefs.
  52. * 4) If we are dealing with an RTL language, we load rtl.css from the
  53. * template set.
  54. */
  55. // 1. Stylesheets from the template.
  56. $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
  57. $aUserStyles = array();
  58. // 2. Option user-defined stylesheet from preferences.
  59. // FIXME: the following user pref ("sUserStyle"; rename as necessary) will have to be populated by the display prefs screen from a widget similar to the color themes widget (which it replaces) where its values should be full relative paths (from SM_PATH) to the selected css "themes" (either in template css/alternates dir or SM_PATH/css/alternates dir)
  60. // FIXME: uhhh, getPref() is not available yet here. (at least on login page) Ugh. Nor has load_prefs been included yet -- how do we fix this?
  61. // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
  62. // Steve, can you please document what u_ means? Will it work with the
  63. // new template inheritance system and auto-detection of alternate sheets?
  64. if (!empty($chosen_theme) && substr($chosen_theme, 0, 2) == 'u_') {
  65. $aUserStyles[] = substr($chosen_theme, 2) .'default.css';
  66. }
  67. // 3. src/style.php
  68. $aUserStyles[] = $base_uri .'src/style.php?'
  69. . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
  70. . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
  71. $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
  72. // 4. Optional rtl.css stylesheet
  73. if ($text_direction == 'rtl') {
  74. $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
  75. }
  76. if ($squirrelmail_language == 'ja_JP') {
  77. /*
  78. * force correct detection of charset, when browser does not follow
  79. * http content-type and tries to detect charset from page content.
  80. * Shooting of browser's creator can't be implemented in php.
  81. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  82. * recommendations and switch to unicode.
  83. */
  84. $header_tags .= "<!-- \xfd\xfe -->\n";
  85. $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
  86. }
  87. if ($do_hook) {
  88. // NOTE! plugins here must assign output to template
  89. // and NOT echo anything directly!!
  90. do_hook('generic_header');
  91. }
  92. $header_tags .= $xtra;
  93. $oTemplate->assign('page_title', $title);
  94. /* work around IE6's scrollbar bug */
  95. $header_tags .= <<<EOS
  96. <!--[if IE 6]>
  97. <style type="text/css">
  98. /* avoid stupid IE6 bug with frames and scrollbars */
  99. body {
  100. width: expression(document.documentElement.clientWidth - 30);
  101. }
  102. </style>
  103. <![endif]-->
  104. EOS;
  105. $oTemplate->assign('header_tags', $header_tags);
  106. $oTemplate->display('protocol_header.tpl');
  107. /* this is used to check elsewhere whether we should call this function */
  108. $pageheader_sent = TRUE;
  109. if (isset($oErrorHandler)) {
  110. $oErrorHandler->HeaderSent();
  111. }
  112. }
  113. /**
  114. * Given a path to a SquirrelMail file, return a HTML link to it
  115. *
  116. * @param string path the SquirrelMail file to link to
  117. * @param string text the link text
  118. * @param string target the target frame for this link
  119. */
  120. function makeInternalLink($path, $text, $target='') {
  121. global $base_uri;
  122. // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  123. if ($target != '') {
  124. $target = " target=\"$target\"";
  125. }
  126. // This is an inefficient hook and is only used by
  127. // one plugin that still needs to patch this code,
  128. // plus if we are templat-izing SM, visual hooks
  129. // are not needed. However, I am leaving the code
  130. // here just in case we find a good (non-visual?)
  131. // use for the internal_link hook.
  132. //
  133. //$hooktext = do_hook_function('internal_link',$text);
  134. //if ($hooktext != '')
  135. // $text = $hooktext;
  136. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  137. }
  138. /**
  139. * Same as makeInternalLink, but echoes it too
  140. */
  141. function displayInternalLink($path, $text, $target='') {
  142. // FIXME: should let the template echo all these kinds of things
  143. echo makeInternalLink($path, $text, $target);
  144. }
  145. /**
  146. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  147. * including the default menu bar. Uses displayHtmlHeader and takes
  148. * JavaScript and locale settings into account.
  149. *
  150. * @param array color the array of theme colors
  151. * @param string mailbox the current mailbox name to display
  152. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  153. * @param string sBodyTagJs js events to be inserted in the body tag
  154. * @return void
  155. */
  156. function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  157. global $reply_focus, $hide_sm_attributions, $frame_top,
  158. $provider_name, $provider_uri, $startMessage,
  159. $javascript_on, $action, $oTemplate;
  160. if (empty($sBodyTagJs)) {
  161. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  162. if ($reply_focus == 'select')
  163. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  164. else if ($reply_focus == 'focus')
  165. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  166. else if ($reply_focus != 'none')
  167. $sBodyTagJs = 'onload="checkForm();"';
  168. }
  169. else
  170. $sBodyTagJs = 'onload="checkForm();"';
  171. }
  172. $urlMailbox = urlencode($mailbox);
  173. $startMessage = (int)$startMessage;
  174. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  175. if (!isset($frame_top)) {
  176. $frame_top = '_top';
  177. }
  178. if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  179. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  180. $sJsBlock = '';
  181. foreach ($js_includes as $js_file) {
  182. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  183. }
  184. if ($sHeaderJs) {
  185. $sJsBlock .= "\n<script type=\"text/javascript\">" .
  186. "\n<!--\n" .
  187. $sHeaderJs . "\n\n// -->\n</script>\n";
  188. }
  189. displayHtmlHeader ('SquirrelMail', $sJsBlock);
  190. } else {
  191. /* do not use JavaScript */
  192. displayHtmlHeader ('SquirrelMail');
  193. $sBodyTagJs = '';
  194. }
  195. /*
  196. * this explains the imap_mailbox.php dependency. We should instead store
  197. * the selected mailbox in the session and fallback to the session var.
  198. */
  199. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  200. readShortMailboxName($mailbox, $delimiter)));
  201. if ( $shortBoxName == 'INBOX' ) {
  202. $shortBoxName = _("INBOX");
  203. }
  204. $sm_attributes = '';
  205. if (!$hide_sm_attributions) {
  206. $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
  207. if (empty($provider_uri)) {
  208. $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
  209. } else {
  210. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  211. $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
  212. }
  213. $sm_attributes .= " </td>\n";
  214. }
  215. $oTemplate->assign('body_tag_js', $sBodyTagJs);
  216. $oTemplate->assign('shortBoxName', $shortBoxName);
  217. $oTemplate->assign('sm_attribute_str', $sm_attributes);
  218. $oTemplate->assign('frame_top', $frame_top);
  219. $oTemplate->assign('urlMailbox', $urlMailbox);
  220. $oTemplate->assign('startMessage', $startMessage);
  221. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  222. $oTemplate->display('page_header.tpl');
  223. }
  224. /**
  225. * Blatantly copied/truncated/modified from displayPageHeader.
  226. * Outputs a page header specifically for the compose_in_new popup window
  227. *
  228. * @param array color the array of theme colors
  229. * @param string mailbox the current mailbox name to display
  230. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  231. * @param string sBodyTagJs js events to be inserted in the body tag
  232. * @return void
  233. */
  234. function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  235. global $reply_focus, $javascript_on, $action, $oTemplate;
  236. if (empty($sBodyTagJs)) {
  237. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  238. if ($reply_focus == 'select')
  239. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  240. else if ($reply_focus == 'focus')
  241. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  242. else if ($reply_focus != 'none')
  243. $sBodyTagJs = 'onload="checkForm();"';
  244. }
  245. else
  246. $sBodyTagJs = 'onload="checkForm();"';
  247. }
  248. /*
  249. * Locate the first displayable form element (only when JavaScript on)
  250. */
  251. if($javascript_on) {
  252. if ($sHeaderJs) {
  253. $sJsBlock = "\n<script type=\"text/javascript\">" .
  254. "\n<!--\n" .
  255. $sHeaderJs . "\n\n// -->\n</script>\n";
  256. } else {
  257. $sJsBlock = '';
  258. }
  259. $sJsBlock .= "\n";
  260. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  261. foreach ($js_includes as $js_file) {
  262. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  263. }
  264. displayHtmlHeader (_("Compose"), $sJsBlock);
  265. } else {
  266. /* javascript off */
  267. displayHtmlHeader(_("Compose"));
  268. $onload = '';
  269. }
  270. // FIXME: should let the template echo all these kinds of things
  271. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  272. }