page_header.php 12 KB

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