page_header.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Prints the page header (duh)
  6. *
  7. * @copyright &copy; 1999-2009 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. // don't show version as a security measure
  39. //$oTemplate->header('X-Powered-By: SquirrelMail/' . SM_VERSION, FALSE);
  40. $oTemplate->header('X-Powered-By: SquirrelMail', FALSE);
  41. $oTemplate->assign('frames', $frames);
  42. $oTemplate->assign('lang', $squirrelmail_language);
  43. $header_tags = '';
  44. $header_tags .= "<meta name=\"robots\" content=\"noindex,nofollow\" />\n";
  45. $used_fontset = (!empty($chosen_fontset) ? $chosen_fontset : $default_fontset);
  46. $used_fontsize = (!empty($chosen_fontsize) ? $chosen_fontsize : $default_fontsize);
  47. $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;
  48. /**
  49. * Stylesheets are loaded in the following order:
  50. * 1) All stylesheets provided by the template. Normally, these are
  51. * stylsheets in templates/<template>/css/. This is accomplished by calling
  52. * $oTemplate->fetch_standard_stylesheet_links().
  53. * 2) An optional user-defined stylesheet. This is set in the Display
  54. * Preferences.
  55. * 3) src/style.php which sets some basic font prefs.
  56. * 4) If we are dealing with an RTL language, we load rtl.css from the
  57. * template set.
  58. */
  59. // 1. Stylesheets from the template.
  60. $header_tags .= $oTemplate->fetch_standard_stylesheet_links();
  61. $aUserStyles = array();
  62. // 2. Option user-defined stylesheet from preferences.
  63. if (!empty($used_theme) && $used_theme != 'none') {
  64. /**
  65. * All styles (except "none" - ugh) just point to a directory,
  66. * so we need to include all .css files in that directory.
  67. */
  68. //FIXME: rid ourselves of "none" strings! I didn't do it here because I think the problem is that the theme itself should never be "none" (? well, what else would it be? if "none" theme is actually OK, then is there a constant to use below in stead of a hard-coded string?)
  69. $styles = $used_theme == 'none' ? array()
  70. : list_files($used_theme, '.css');
  71. foreach ($styles as $sheet) {
  72. $aUserStyles[] = $used_theme .'/'.$sheet;
  73. }
  74. }
  75. // 3. src/style.php
  76. $aUserStyles[] = $base_uri .'src/style.php?'
  77. . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
  78. . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
  79. // 3.1. Load the stylesheets we have already
  80. $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
  81. // 4. Optional rtl.css stylesheet
  82. if ($text_direction == 'rtl') {
  83. $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
  84. }
  85. // 5. Printer friendly stylesheet
  86. $header_tags .= create_css_link($base_uri . 'css/print.css', 'printerfriendly', false, 'print');
  87. if ($squirrelmail_language == 'ja_JP') {
  88. /*
  89. * force correct detection of charset, when browser does not follow
  90. * http content-type and tries to detect charset from page content.
  91. * Shooting of browser's creator can't be implemented in php.
  92. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  93. * recommendations and switch to unicode.
  94. */
  95. $header_tags .= "<!-- \xfd\xfe -->\n";
  96. $header_tags .= '<meta http-equiv="Content-type" content="' . $oTemplate->get_content_type() . '; charset=euc-jp" />' . "\n";
  97. }
  98. if ($do_hook) {
  99. // NOTE! plugins here MUST assign output to template
  100. // and NOT echo anything directly!! A common
  101. // approach is if a plugin decides it needs to
  102. // put something at page-top after the standard
  103. // SM page header, to dynamically add itself to
  104. // the page_header_bottom and/or compose_header_bottom
  105. // hooks for the current page request. See
  106. // the Sent Confirmation v1.7 or Restrict Senders v1.2
  107. // plugins for examples of this approach.
  108. ob_start();
  109. $temp = array(&$header_tags);
  110. do_hook('generic_header', $temp);
  111. $output = ob_get_contents();
  112. ob_end_clean();
  113. // plugin authors can debug their errors with one of the following:
  114. //sm_print_r($output);
  115. //echo $output;
  116. if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR);
  117. }
  118. $header_tags .= $xtra;
  119. $oTemplate->assign('page_title', $title);
  120. /* work around IE6's scrollbar bug */
  121. $header_tags .= <<<EOS
  122. <!--[if IE 6]>
  123. <style type="text/css">
  124. /* avoid stupid IE6 bug with frames and scrollbars */
  125. body {
  126. width: expression(document.documentElement.clientWidth - 30);
  127. }
  128. </style>
  129. <![endif]-->
  130. EOS;
  131. $oTemplate->assign('header_tags', $header_tags);
  132. $oTemplate->display('protocol_header.tpl');
  133. /* this is used to check elsewhere whether we should call this function */
  134. $pageheader_sent = TRUE;
  135. if (isset($oErrorHandler)) {
  136. $oErrorHandler->HeaderSent();
  137. }
  138. }
  139. /**
  140. * Given a path to a SquirrelMail file, return a HTML link to it
  141. *
  142. * @param string $path The SquirrelMail file to link to
  143. * (should start with something like "src/..." or
  144. * "functions/..." or "plugins/..." etc.)
  145. * @param string $text The link text
  146. * @param string $target The target frame for this link
  147. * @param string $accesskey The access key to be used, if any
  148. */
  149. function makeInternalLink($path, $text, $target='', $accesskey='NONE') {
  150. global $base_uri, $oTemplate;
  151. // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  152. // This is an inefficient hook and is only used by
  153. // one plugin that still needs to patch this code,
  154. // plus if we are templat-izing SM, visual hooks
  155. // are not needed. However, I am leaving the code
  156. // here just in case we find a good (non-visual?)
  157. // use for the internal_link hook.
  158. //
  159. //do_hook('internal_link', $text);
  160. return create_hyperlink($base_uri . $path, $text, $target,
  161. '', '', '', '',
  162. ($accesskey == 'NONE'
  163. ? array()
  164. : array('accesskey' => $accesskey)));
  165. }
  166. /**
  167. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  168. * including the default menu bar. Uses displayHtmlHeader and takes
  169. * JavaScript and locale settings into account.
  170. *
  171. * @param array color the array of theme colors
  172. * @param string mailbox the current mailbox name to display
  173. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  174. * @param string sOnload JavaScript code to be added inside the body's onload handler
  175. * as of 1.5.2, this replaces $sBodyTagJs argument
  176. * @return void
  177. */
  178. function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sOnload = '') {
  179. global $reply_focus, $hide_sm_attributions, $frame_top,
  180. $provider_name, $provider_uri, $startMessage,
  181. $action, $oTemplate, $org_title, $base_uri,
  182. $data_dir, $username;
  183. if (empty($sOnload)) {
  184. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  185. if ($reply_focus == 'select')
  186. $sOnload = 'checkForm(\'select\');';
  187. else if ($reply_focus == 'focus')
  188. $sOnload = 'checkForm(\'focus\');';
  189. else if ($reply_focus != 'none')
  190. $sOnload = 'checkForm();';
  191. }
  192. else
  193. $sOnload = 'checkForm();';
  194. }
  195. $startMessage = (int)$startMessage;
  196. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  197. if (!isset($frame_top)) {
  198. $frame_top = '_top';
  199. }
  200. //FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary?? (that is, I think checkForJavascript() might already look for new_js_autodetect_results...(?))
  201. if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  202. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  203. $sJsBlock = '';
  204. foreach ($js_includes as $js_file) {
  205. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  206. }
  207. if ($sHeaderJs) {
  208. $sJsBlock .= "\n<script type=\"text/javascript\">" .
  209. "\n<!--\n" .
  210. $sHeaderJs . "\n\n// -->\n</script>\n";
  211. }
  212. displayHtmlHeader ($org_title, $sJsBlock);
  213. } else {
  214. /* do not use JavaScript */
  215. displayHtmlHeader ($org_title);
  216. $sOnload = '';
  217. }
  218. if ($mailbox) {
  219. /*
  220. * this explains the imap_mailbox.php dependency. We should instead store
  221. * the selected mailbox in the session and fallback to the session var.
  222. */
  223. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  224. readShortMailboxName($mailbox, $delimiter)));
  225. if (getPref($data_dir, $username, 'translate_special_folders')) {
  226. global $sent_folder, $trash_folder, $draft_folder;
  227. if ($mailbox == $sent_folder)
  228. $shortBoxName = _("Sent");
  229. else if ($mailbox == $trash_folder)
  230. $shortBoxName = _("Trash");
  231. else if ($mailbox == $sent_folder)
  232. $shortBoxName = _("Drafts");
  233. }
  234. $urlMailbox = urlencode($mailbox);
  235. } else {
  236. $shortBoxName = '';
  237. $urlMailbox = '';
  238. }
  239. $provider_link = '';
  240. if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
  241. $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
  242. }
  243. $oTemplate->assign('onload', $sOnload);
  244. $oTemplate->assign('shortBoxName', $shortBoxName);
  245. $oTemplate->assign('provider_link', $provider_link);
  246. $oTemplate->assign('frame_top', $frame_top);
  247. $oTemplate->assign('urlMailbox', $urlMailbox);
  248. $oTemplate->assign('startMessage', $startMessage);
  249. $oTemplate->assign('hide_sm_attributions', $hide_sm_attributions);
  250. // access keys
  251. //
  252. global $accesskey_menubar_compose, $accesskey_menubar_addresses,
  253. $accesskey_menubar_folders, $accesskey_menubar_options,
  254. $accesskey_menubar_search, $accesskey_menubar_help,
  255. $accesskey_menubar_signout;
  256. $oTemplate->assign('accesskey_menubar_compose', $accesskey_menubar_compose);
  257. $oTemplate->assign('accesskey_menubar_addresses', $accesskey_menubar_addresses);
  258. $oTemplate->assign('accesskey_menubar_folders', $accesskey_menubar_folders);
  259. $oTemplate->assign('accesskey_menubar_options', $accesskey_menubar_options);
  260. $oTemplate->assign('accesskey_menubar_search', $accesskey_menubar_search);
  261. $oTemplate->assign('accesskey_menubar_help', $accesskey_menubar_help);
  262. $oTemplate->assign('accesskey_menubar_signout', $accesskey_menubar_signout);
  263. $oTemplate->display('page_header.tpl');
  264. global $null;
  265. do_hook('page_header_bottom', $null);
  266. }
  267. /**
  268. * Blatantly copied/truncated/modified from displayPageHeader.
  269. * Outputs a page header specifically for the compose_in_new popup window
  270. *
  271. * @param array color the array of theme colors
  272. * @param string mailbox the current mailbox name to display
  273. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  274. * @param string sOnload JavaScript code to be added inside the body's onload handler
  275. * as of 1.5.2, this replaces $sBodyTagJs argument
  276. * @return void
  277. */
  278. function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
  279. global $reply_focus, $action, $oTemplate;
  280. if (empty($sOnload)) {
  281. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  282. if ($reply_focus == 'select')
  283. $sOnload = 'checkForm(\'select\');';
  284. else if ($reply_focus == 'focus')
  285. $sOnload = 'checkForm(\'focus\');';
  286. else if ($reply_focus != 'none')
  287. $sOnload = 'checkForm();';
  288. }
  289. else
  290. $sOnload = 'checkForm();';
  291. }
  292. /*
  293. * Locate the first displayable form element (only when JavaScript on)
  294. */
  295. if(checkForJavascript()) {
  296. if ($sHeaderJs) {
  297. $sJsBlock = "\n<script type=\"text/javascript\">" .
  298. "\n<!--\n" .
  299. $sHeaderJs . "\n\n// -->\n</script>\n";
  300. } else {
  301. $sJsBlock = '';
  302. }
  303. $sJsBlock .= "\n";
  304. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  305. foreach ($js_includes as $js_file) {
  306. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  307. }
  308. displayHtmlHeader (_("Compose"), $sJsBlock);
  309. } else {
  310. /* javascript off */
  311. displayHtmlHeader(_("Compose"));
  312. $sOnload = '';
  313. }
  314. // FIXME: change the colorization attributes below to a CSS class!
  315. $class = '';
  316. $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
  317. 'link' => $color[7], 'vlink' => $color[7],
  318. 'alink' => $color[7]);
  319. // this is template-safe (see create_body() function)
  320. echo create_body($sOnload, $class, $aAttribs);
  321. global $null;
  322. do_hook('compose_header_bottom', $null);
  323. }