page_header.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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' ? 'u_'.$user_themes[$user_theme_default]['PATH'] : $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. // 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)
  61. // 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?
  62. // $aUserStyles[] = getPref($data_dir, $username, 'sUserStyle', '');
  63. // Steve, can you please document what u_ means? Will it work with the
  64. // new template inheritance system and auto-detection of alternate sheets?
  65. /**
  66. * Stylesheets beginning with a "u_" == user provided stylesheets, e.g. those
  67. * in SM_PATH/css/. Template provided stylesheets (TEMPLATE_DIR/css/alternatives/)
  68. * should begin with 't_'. This was the initial path I took to get it working
  69. * since I wasn't sure what mods to the Template class would be used to handle
  70. * template-provided alt stylesheets.
  71. *
  72. * TODO: Re-evaluate this naming convetion.
  73. */
  74. # var_dump($used_theme);
  75. if (!empty($used_theme)) {
  76. if (substr($used_theme, 0, 2) == 'u_') {
  77. $aUserStyles[] = substr($used_theme, 2) .'/default.css';
  78. } elseif (substr($used_theme, 0, 2) == 't_') {
  79. $aUserStyles[] = SM_PATH . $oTemplate->get_template_file_directory().'css/alternates/'.substr($used_theme, 2);
  80. # $aUserStyles[] = substr($used_theme, 2);
  81. }
  82. }
  83. // 3. src/style.php
  84. $aUserStyles[] = $base_uri .'src/style.php?'
  85. . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
  86. . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
  87. // 3.1. Load the stylesheets we have already
  88. $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
  89. // 4. Optional rtl.css stylesheet
  90. if ($text_direction == 'rtl') {
  91. $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
  92. }
  93. if ($squirrelmail_language == 'ja_JP') {
  94. /*
  95. * force correct detection of charset, when browser does not follow
  96. * http content-type and tries to detect charset from page content.
  97. * Shooting of browser's creator can't be implemented in php.
  98. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  99. * recommendations and switch to unicode.
  100. */
  101. $header_tags .= "<!-- \xfd\xfe -->\n";
  102. $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
  103. }
  104. if ($do_hook) {
  105. // NOTE! plugins here must assign output to template
  106. // and NOT echo anything directly!!
  107. do_hook('generic_header');
  108. }
  109. $header_tags .= $xtra;
  110. $oTemplate->assign('page_title', $title);
  111. /* work around IE6's scrollbar bug */
  112. $header_tags .= <<<EOS
  113. <!--[if IE 6]>
  114. <style type="text/css">
  115. /* avoid stupid IE6 bug with frames and scrollbars */
  116. body {
  117. width: expression(document.documentElement.clientWidth - 30);
  118. }
  119. </style>
  120. <![endif]-->
  121. EOS;
  122. $oTemplate->assign('header_tags', $header_tags);
  123. $oTemplate->display('protocol_header.tpl');
  124. /* this is used to check elsewhere whether we should call this function */
  125. $pageheader_sent = TRUE;
  126. if (isset($oErrorHandler)) {
  127. $oErrorHandler->HeaderSent();
  128. }
  129. }
  130. /**
  131. * Given a path to a SquirrelMail file, return a HTML link to it
  132. *
  133. * @param string path the SquirrelMail file to link to
  134. * @param string text the link text
  135. * @param string target the target frame for this link
  136. */
  137. function makeInternalLink($path, $text, $target='') {
  138. global $base_uri;
  139. // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  140. if ($target != '') {
  141. $target = " target=\"$target\"";
  142. }
  143. // This is an inefficient hook and is only used by
  144. // one plugin that still needs to patch this code,
  145. // plus if we are templat-izing SM, visual hooks
  146. // are not needed. However, I am leaving the code
  147. // here just in case we find a good (non-visual?)
  148. // use for the internal_link hook.
  149. //
  150. //$hooktext = do_hook_function('internal_link',$text);
  151. //if ($hooktext != '')
  152. // $text = $hooktext;
  153. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  154. }
  155. /**
  156. * Same as makeInternalLink, but echoes it too
  157. */
  158. function displayInternalLink($path, $text, $target='') {
  159. // FIXME: should let the template echo all these kinds of things
  160. echo makeInternalLink($path, $text, $target);
  161. }
  162. /**
  163. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  164. * including the default menu bar. Uses displayHtmlHeader and takes
  165. * JavaScript and locale settings into account.
  166. *
  167. * @param array color the array of theme colors
  168. * @param string mailbox the current mailbox name to display
  169. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  170. * @param string sBodyTagJs js events to be inserted in the body tag
  171. * @return void
  172. */
  173. function displayPageHeader($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  174. global $reply_focus, $hide_sm_attributions, $frame_top,
  175. $provider_name, $provider_uri, $startMessage,
  176. $javascript_on, $action, $oTemplate;
  177. if (empty($sBodyTagJs)) {
  178. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  179. if ($reply_focus == 'select')
  180. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  181. else if ($reply_focus == 'focus')
  182. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  183. else if ($reply_focus != 'none')
  184. $sBodyTagJs = 'onload="checkForm();"';
  185. }
  186. else
  187. $sBodyTagJs = 'onload="checkForm();"';
  188. }
  189. $urlMailbox = urlencode($mailbox);
  190. $startMessage = (int)$startMessage;
  191. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  192. if (!isset($frame_top)) {
  193. $frame_top = '_top';
  194. }
  195. if( $javascript_on || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  196. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  197. $sJsBlock = '';
  198. foreach ($js_includes as $js_file) {
  199. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  200. }
  201. if ($sHeaderJs) {
  202. $sJsBlock .= "\n<script type=\"text/javascript\">" .
  203. "\n<!--\n" .
  204. $sHeaderJs . "\n\n// -->\n</script>\n";
  205. }
  206. displayHtmlHeader ('SquirrelMail', $sJsBlock);
  207. } else {
  208. /* do not use JavaScript */
  209. displayHtmlHeader ('SquirrelMail');
  210. $sBodyTagJs = '';
  211. }
  212. /*
  213. * this explains the imap_mailbox.php dependency. We should instead store
  214. * the selected mailbox in the session and fallback to the session var.
  215. */
  216. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  217. readShortMailboxName($mailbox, $delimiter)));
  218. if ( $shortBoxName == 'INBOX' ) {
  219. $shortBoxName = _("INBOX");
  220. }
  221. $sm_attributes = '';
  222. if (!$hide_sm_attributions) {
  223. $sm_attributes .= '<td class="sqm_providerInfo">' ."\n";
  224. if (empty($provider_uri)) {
  225. $sm_attributes .= ' <a href="about.php">SquirrelMail</a>';
  226. } else {
  227. if (empty($provider_name)) $provider_name= 'SquirrelMail';
  228. $sm_attributes .= ' <a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>'."\n";
  229. }
  230. $sm_attributes .= " </td>\n";
  231. }
  232. $oTemplate->assign('body_tag_js', $sBodyTagJs);
  233. $oTemplate->assign('shortBoxName', $shortBoxName);
  234. $oTemplate->assign('sm_attribute_str', $sm_attributes);
  235. $oTemplate->assign('frame_top', $frame_top);
  236. $oTemplate->assign('urlMailbox', $urlMailbox);
  237. $oTemplate->assign('startMessage', $startMessage);
  238. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  239. $oTemplate->display('page_header.tpl');
  240. }
  241. /**
  242. * Blatantly copied/truncated/modified from displayPageHeader.
  243. * Outputs a page header specifically for the compose_in_new popup window
  244. *
  245. * @param array color the array of theme colors
  246. * @param string mailbox the current mailbox name to display
  247. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  248. * @param string sBodyTagJs js events to be inserted in the body tag
  249. * @return void
  250. */
  251. function compose_Header($color, $mailbox, $sHeaderJs='', $sBodyTagJs = '') {
  252. global $reply_focus, $javascript_on, $action, $oTemplate;
  253. if (empty($sBodyTagJs)) {
  254. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  255. if ($reply_focus == 'select')
  256. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  257. else if ($reply_focus == 'focus')
  258. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  259. else if ($reply_focus != 'none')
  260. $sBodyTagJs = 'onload="checkForm();"';
  261. }
  262. else
  263. $sBodyTagJs = 'onload="checkForm();"';
  264. }
  265. /*
  266. * Locate the first displayable form element (only when JavaScript on)
  267. */
  268. if($javascript_on) {
  269. if ($sHeaderJs) {
  270. $sJsBlock = "\n<script type=\"text/javascript\">" .
  271. "\n<!--\n" .
  272. $sHeaderJs . "\n\n// -->\n</script>\n";
  273. } else {
  274. $sJsBlock = '';
  275. }
  276. $sJsBlock .= "\n";
  277. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  278. foreach ($js_includes as $js_file) {
  279. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  280. }
  281. displayHtmlHeader (_("Compose"), $sJsBlock);
  282. } else {
  283. /* javascript off */
  284. displayHtmlHeader(_("Compose"));
  285. $onload = '';
  286. }
  287. // FIXME: should let the template echo all these kinds of things
  288. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $sBodyTagJs>\n\n";
  289. }