page_header.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Prints the page header (duh)
  6. *
  7. * @copyright &copy; 1999-2007 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) && $used_theme != 'none') {
  61. /**
  62. * All styles (except "none" - ugh) just point to a directory,
  63. * so we need to include all .css files in that directory.
  64. */
  65. //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?)
  66. $styles = $used_theme == 'none' ? array()
  67. : list_files($used_theme, '.css');
  68. foreach ($styles as $sheet) {
  69. $aUserStyles[] = $used_theme .'/'.$sheet;
  70. }
  71. }
  72. // 3. src/style.php
  73. $aUserStyles[] = $base_uri .'src/style.php?'
  74. . (!empty($used_fontset) ? '&amp;fontset='.$used_fontset : '')
  75. . (!empty($used_fontsize) ? '&amp;fontsize='.$used_fontsize : '');
  76. // 3.1. Load the stylesheets we have already
  77. $header_tags .= $oTemplate->fetch_external_stylesheet_links($aUserStyles);
  78. // 4. Optional rtl.css stylesheet
  79. if ($text_direction == 'rtl') {
  80. $header_tags .= $oTemplate->fetch_right_to_left_stylesheet_link();
  81. }
  82. if ($squirrelmail_language == 'ja_JP') {
  83. /*
  84. * force correct detection of charset, when browser does not follow
  85. * http content-type and tries to detect charset from page content.
  86. * Shooting of browser's creator can't be implemented in php.
  87. * We might get rid of it, if we follow http://www.w3.org/TR/japanese-xml/
  88. * recommendations and switch to unicode.
  89. */
  90. $header_tags .= "<!-- \xfd\xfe -->\n";
  91. $header_tags .= '<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />' . "\n";
  92. }
  93. if ($do_hook) {
  94. // NOTE! plugins here MUST assign output to template
  95. // and NOT echo anything directly!! A common
  96. // approach is if a plugin decides it needs to
  97. // put something at page-top after the standard
  98. // SM page header, to dynamically add itself to
  99. // the page_header_bottom and/or compose_header_bottom
  100. // hooks for the current page request. See
  101. // the Sent Confirmation v1.7 or Restrict Senders v1.2
  102. // plugins for examples of this approach.
  103. global $null;
  104. ob_start();
  105. do_hook('generic_header', $null);
  106. $output = ob_get_contents();
  107. ob_end_clean();
  108. // plugin authors can debug their errors with one of the following:
  109. //sm_print_r($output);
  110. //echo $output;
  111. if (!empty($output)) trigger_error('A plugin on the "generic_header" hook has attempted to output directly to the browser', E_USER_ERROR);
  112. }
  113. $header_tags .= $xtra;
  114. $oTemplate->assign('page_title', $title);
  115. /* work around IE6's scrollbar bug */
  116. $header_tags .= <<<EOS
  117. <!--[if IE 6]>
  118. <style type="text/css">
  119. /* avoid stupid IE6 bug with frames and scrollbars */
  120. body {
  121. width: expression(document.documentElement.clientWidth - 30);
  122. }
  123. </style>
  124. <![endif]-->
  125. EOS;
  126. $oTemplate->assign('header_tags', $header_tags);
  127. $oTemplate->display('protocol_header.tpl');
  128. /* this is used to check elsewhere whether we should call this function */
  129. $pageheader_sent = TRUE;
  130. if (isset($oErrorHandler)) {
  131. $oErrorHandler->HeaderSent();
  132. }
  133. }
  134. /**
  135. * Given a path to a SquirrelMail file, return a HTML link to it
  136. *
  137. * @param string path the SquirrelMail file to link to
  138. * @param string text the link text
  139. * @param string target the target frame for this link
  140. */
  141. function makeInternalLink($path, $text, $target='') {
  142. global $base_uri, $oTemplate;
  143. // sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
  144. // This is an inefficient hook and is only used by
  145. // one plugin that still needs to patch this code,
  146. // plus if we are templat-izing SM, visual hooks
  147. // are not needed. However, I am leaving the code
  148. // here just in case we find a good (non-visual?)
  149. // use for the internal_link hook.
  150. //
  151. //do_hook('internal_link', $text);
  152. return create_hyperlink($base_uri . $path, $text, $target);
  153. }
  154. /**
  155. * Outputs a complete SquirrelMail page header, starting with <!doctype> and
  156. * including the default menu bar. Uses displayHtmlHeader and takes
  157. * JavaScript and locale settings into account.
  158. *
  159. * @param array color the array of theme colors
  160. * @param string mailbox the current mailbox name to display
  161. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  162. * @param string sBodyTagJs js events to be inserted in the body tag
  163. * @return void
  164. */
  165. function displayPageHeader($color, $mailbox='', $sHeaderJs='', $sBodyTagJs = '') {
  166. global $reply_focus, $hide_sm_attributions, $frame_top,
  167. $provider_name, $provider_uri, $startMessage,
  168. $action, $oTemplate, $org_title, $base_uri,
  169. $data_dir, $username;
  170. //FIXME: $sBodyTag should be turned into $sOnload and should only contain the contents of the onload attribute (not the attribute name nor any quotes).... only question is if anyone was using $sBodyTag for anything but onload event handlers? (see function compose_Header() below for how to fix it once we confirm it can be changed)
  171. if (empty($sBodyTagJs)) {
  172. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  173. if ($reply_focus == 'select')
  174. $sBodyTagJs = 'onload="checkForm(\'select\');"';
  175. else if ($reply_focus == 'focus')
  176. $sBodyTagJs = 'onload="checkForm(\'focus\');"';
  177. else if ($reply_focus != 'none')
  178. $sBodyTagJs = 'onload="checkForm();"';
  179. }
  180. else
  181. $sBodyTagJs = 'onload="checkForm();"';
  182. }
  183. $startMessage = (int)$startMessage;
  184. sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION );
  185. if (!isset($frame_top)) {
  186. $frame_top = '_top';
  187. }
  188. //FIXME: does checkForJavascript() make the 2nd part of the if() below unneccessary??
  189. if( checkForJavascript() || strpos($sHeaderJs, 'new_js_autodetect_results.value') ) {
  190. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  191. $sJsBlock = '';
  192. foreach ($js_includes as $js_file) {
  193. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  194. }
  195. if ($sHeaderJs) {
  196. $sJsBlock .= "\n<script type=\"text/javascript\">" .
  197. "\n<!--\n" .
  198. $sHeaderJs . "\n\n// -->\n</script>\n";
  199. }
  200. displayHtmlHeader ($org_title, $sJsBlock);
  201. } else {
  202. /* do not use JavaScript */
  203. displayHtmlHeader ($org_title);
  204. $sBodyTagJs = '';
  205. }
  206. if ($mailbox) {
  207. /*
  208. * this explains the imap_mailbox.php dependency. We should instead store
  209. * the selected mailbox in the session and fallback to the session var.
  210. */
  211. $shortBoxName = htmlspecialchars(imap_utf7_decode_local(
  212. readShortMailboxName($mailbox, $delimiter)));
  213. if (getPref($data_dir, $username, 'translate_special_folders')) {
  214. $shortBoxName = _($shortBoxName);
  215. }
  216. $urlMailbox = urlencode($mailbox);
  217. } else {
  218. $shortBoxName = '';
  219. $urlMailbox = '';
  220. }
  221. $provider_link = '';
  222. if (!empty($provider_uri) && !empty($provider_name) && $provider_name != 'SquirrelMail') {
  223. $provider_link = create_hyperlink($provider_uri, $provider_name, '_blank');
  224. }
  225. $oTemplate->assign('body_tag_js', $sBodyTagJs);
  226. $oTemplate->assign('shortBoxName', $shortBoxName);
  227. $oTemplate->assign('provider_link', $provider_link);
  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. global $null;
  234. do_hook('page_header_bottom', $null);
  235. }
  236. /**
  237. * Blatantly copied/truncated/modified from displayPageHeader.
  238. * Outputs a page header specifically for the compose_in_new popup window
  239. *
  240. * @param array color the array of theme colors
  241. * @param string mailbox the current mailbox name to display
  242. * @param string sHeaderJs javascipt code to be inserted in a script block in the header
  243. * @param string sOnload JavaScript code to be added inside the body's onload handler
  244. * as of 1.5.2, this replaces $sBodyTagJs argument
  245. * @return void
  246. */
  247. function compose_Header($color, $mailbox, $sHeaderJs='', $sOnload = '') {
  248. global $reply_focus, $action, $oTemplate;
  249. if (empty($sOnload)) {
  250. if (strpos($action, 'reply') !== FALSE && $reply_focus) {
  251. if ($reply_focus == 'select')
  252. $sOnload = 'checkForm(\'select\');';
  253. else if ($reply_focus == 'focus')
  254. $sOnload = 'checkForm(\'focus\');';
  255. else if ($reply_focus != 'none')
  256. $sOnload = 'checkForm();';
  257. }
  258. else
  259. $sOnload = 'checkForm();';
  260. }
  261. /*
  262. * Locate the first displayable form element (only when JavaScript on)
  263. */
  264. if(checkForJavascript()) {
  265. if ($sHeaderJs) {
  266. $sJsBlock = "\n<script type=\"text/javascript\">" .
  267. "\n<!--\n" .
  268. $sHeaderJs . "\n\n// -->\n</script>\n";
  269. } else {
  270. $sJsBlock = '';
  271. }
  272. $sJsBlock .= "\n";
  273. $js_includes = $oTemplate->get_javascript_includes(TRUE);
  274. foreach ($js_includes as $js_file) {
  275. $sJsBlock .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
  276. }
  277. displayHtmlHeader (_("Compose"), $sJsBlock);
  278. } else {
  279. /* javascript off */
  280. displayHtmlHeader(_("Compose"));
  281. $onload = '';
  282. }
  283. // FIXME: change the colorization attributes below to a CSS class!
  284. $class = '';
  285. $aAttribs = array('text' => $color[8], 'bgcolor' => $color[4],
  286. 'link' => $color[7], 'vlink' => $color[7],
  287. 'alink' => $color[7]);
  288. // this is template-safe (see create_body() function)
  289. echo create_body($sOnload, $class, $aAttribs);
  290. global $null;
  291. do_hook('compose_header_bottom', $null);
  292. }