Source for file page_header.php

Documentation is available at page_header.php

  1. <?php
  2. /**
  3. * page_header.php
  4. *
  5. * Prints the page header (duh)
  6. *
  7. * @copyright 1999-2020 The SquirrelMail Project Team
  8. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  9. * @version $Id: page_header.php 14840 2020年01月07日 07:42:38Z pdontthink $
  10. * @package squirrelmail
  11. */
  12. /** Include required files from SM */
  13. require_once(SM_PATH . 'functions/strings.php');
  14. require_once(SM_PATH . 'functions/html.php');
  15. require_once(SM_PATH . 'functions/imap_mailbox.php');
  16. require_once(SM_PATH . 'functions/global.php');
  17. /* Always set up the language before calling these functions */
  18. /**
  19. * @param string $title This is placed directly in the HTML <title> tag,
  20. * so should be sanitized and ready to go
  21. * @param boolean $xtra_param Any additional HTML code that should be
  22. * included in the <head> tag - this is also
  23. * sent to the browser as-is, so should be pre-
  24. * sanitized
  25. * @param boolean $do_hook When TRUE, the "generic_header" hook is fired
  26. * herein.
  27. * @param array $script_libs_param A list of strings which each point to
  28. * a script to be added to the <head> of
  29. * the page being built. Each string can
  30. * be:
  31. * - One of the pre-defined SM_SCRIPT_LIB_XXX
  32. * constants (see functions/constants.php)
  33. * that correspond to libraries that come
  34. * with SquirrelMail
  35. * - A path to a custom script (say, in a
  36. * plugin directory) (detected by the
  37. * existence of at least one path separator
  38. * in the string) - the script is assumed
  39. * to be and is included as JavaScript
  40. * - A full tag ("<script>", "<style>" or
  41. * other) that will be placed verbatim in
  42. * the page header (detected by the presence
  43. * of a "<" character at the beginning of
  44. * the string). NOTE that $xtra provides the
  45. * same function, without needing the string
  46. * to start with "<"
  47. */
  48. function displayHtmlHeader ($title='SquirrelMail', $xtra_param='', $do_hook=TRUE, $script_libs_param=array()) {
  49. global $squirrelmail_language, $xtra, $script_libs;
  50. // $script_libs and $xtra are globalized to allow plugins to
  51. // modify them on the generic_header hook, but we also want to
  52. // respect the values passed in from the function args, thus:
  53. $xtra = $xtra_param;
  54. $script_libs = $script_libs_param;
  55. if (!is_array ($script_libs))
  56. $script_libs = array($script_libs);
  57. if ( !sqgetGlobalVar ('base_uri', $base_uri, SQ_SESSION ) ) {
  58. global $base_uri;
  59. }
  60. global $theme_css , $custom_css, $pageheader_sent, $browser_rendering_mode , $head_tag_extra;
  61. // prevent clickjack attempts
  62. // FIXME: should we use DENY instead? We can also make this a configurable value, including giving the admin the option of removing this entirely in case they WANT to be framed by an external domain
  63. header ('X-Frame-Options: SAMEORIGIN');
  64. echo ($browser_rendering_mode === 'standards'
  65. ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
  66. : ($browser_rendering_mode === 'almost'
  67. ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
  68. : /* "quirks" */ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">')) .
  69. "\n\n" . html_tag ( 'html' ,'' , '', '', '' ) . "\n<head>\n" .
  70. "<meta name=\"robots\" content=\"noindex,nofollow\">\n" .
  71. "<meta http-equiv=\"x-dns-prefetch-control\" content=\"off\">\n"
  72. // For adding a favicon or anything else that should be inserted in *ALL* <head> for *ALL* documents,
  73. // define $head_tag_extra in config/config_local.php
  74. // The string "###SM BASEURI###" will be replaced with the base URI for this SquirrelMail installation.
  75. // When not defined, a default is provided that displays the default favicon.ico.
  76. // If you override this and still want to use the default favicon.ico, you'll have to include the following
  77. // following in your $head_tag_extra string:
  78. // $head_tag_extra = '<link rel="shortcut icon" href="###SM BASEURI###favicon.ico" />...<YOUR CONTENT HERE>...';
  79. //
  80. . (empty($head_tag_extra) ? '<link rel="shortcut icon" href="' . sqm_baseuri () . 'favicon.ico" />'
  81. : str_replace ('###SM BASEURI###', sqm_baseuri (), $head_tag_extra))
  82. // prevent clickjack attempts using JavaScript for browsers that
  83. // don't support the X-Frame-Options header...
  84. // we check to see if we are *not* the top page, and if not, check
  85. // whether or not the top page is in the same domain as we are...
  86. // if not, log out immediately -- this is an attempt to do the same
  87. // thing that the X-Frame-Options does using JavaScript (never a good
  88. // idea to rely on JavaScript-based solutions, though)
  89. . '<script type="text/javascript" language="JavaScript">'
  90. . "\n<!--\n"
  91. . 'if (self != top) { try { if (document.domain != top.document.domain) {'
  92. . ' throw "Clickjacking security violation! Please log out immediately!"; /* this code should never execute - exception should already have been thrown since it\'s a security violation in this case to even try to access top.document.domain (but it\'s left here just to be extra safe) */ } } catch (e) { self.location = "'
  93. . sqm_baseuri () . 'src/signout.php"; top.location = "'
  94. . sqm_baseuri () . 'src/signout.php" } }'
  95. . "\n// -->\n</script>\n";
  96. if ( !isset( $custom_css ) || $custom_css == 'none' ) {
  97. if ($theme_css != '') {
  98. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
  99. }
  100. } else {
  101. echo '<link rel="stylesheet" type="text/css" href="' .
  102. $base_uri . 'themes/css/'.$custom_css.'">';
  103. }
  104. if ($squirrelmail_language == 'ja_JP') {
  105. // Why is it added here? Header ('Content-Type:..) is used in i18n.php
  106. echo "<!-- \xfd\xfe -->\n";
  107. echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
  108. }
  109. if ($do_hook) {
  110. do_hook ('generic_header');
  111. }
  112. echo "\n<title>$title</title>$xtra\n";
  113. // output <script> tags as needed (use array_unique so
  114. // more than one plugin can ask for the same library)
  115. //
  116. // usage of $script_libs is discussed in the docs for this function above
  117. //
  118. foreach (array_unique ($script_libs) as $item) {
  119. if ($item{0} === '<')
  120. echo $item . "\n";
  121. else if (strpos ($item, '/') !== FALSE || strpos ($item, '\\') !== FALSE)
  122. echo '<script language="JavaScript" type="text/javascript" src="' . $item . '"></script>' . "\n";
  123. else
  124. echo '<script language="JavaScript" type="text/javascript" src="' . $base_uri . 'scripts/' . $item . '"></script>' . "\n";
  125. }
  126. /* work around IE6's scrollbar bug */
  127. echo <<<ECHO
  128. <!--[if IE 6]>
  129. <style type="text/css">
  130. /* avoid stupid IE6 bug with frames and scrollbars */
  131. body {
  132. width: expression(document.documentElement.clientWidth - 30);
  133. }
  134. </style>
  135. <![endif]-->
  136. ECHO;
  137. echo "\n</head>\n\n";
  138. /* this is used to check elsewhere whether we should call this function */
  139. $pageheader_sent = TRUE;
  140. }
  141. function makeInternalLink ($path, $text, $target='') {
  142. sqgetGlobalVar ('base_uri', $base_uri, SQ_SESSION );
  143. if ($target != '') {
  144. $target = " target=\"$target\"";
  145. }
  146. return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  147. }
  148. function displayInternalLink ($path, $text, $target='') {
  149. echo makeInternalLink ($path, $text, $target);
  150. }
  151. function displayPageHeader ($color, $mailbox, $xtra='', $session=false) {
  152. $compose_new_win, $compose_width, $compose_height,
  153. $attachemessages, $provider_name , $provider_uri ,
  154. $javascript_on, $default_use_mdn , $mdn_user_support,
  155. $startMessage, $org_title ;
  156. sqgetGlobalVar ('base_uri', $base_uri, SQ_SESSION );
  157. sqgetGlobalVar ('delimiter', $delimiter, SQ_SESSION );
  158. if (!isset($frame_top)) {
  159. $frame_top = '_top';
  160. }
  161. if ($session) {
  162. $compose_uri = $base_uri.'src/compose.php?mailbox='.urlencode ($mailbox).'&amp;session='."$session";
  163. } else {
  164. $compose_uri = $base_uri.'src/compose.php?newmessage=1';
  165. $session = 0;
  166. }
  167. // only output JavaScript if actually turned on
  168. if($javascript_on || strpos ($xtra, 'new_js_autodetect_results.value') ) {
  169. if ( !defined ('PAGE_NAME') ) define ('PAGE_NAME', NULL);
  170. switch ( PAGE_NAME ) {
  171. case 'read_body':
  172. $js ='';
  173. // compose in new window code
  174. if ($compose_new_win == '1') {
  175. if (!preg_match ("/^[0-9]{3,4}$/", $compose_width)) {
  176. $compose_width = '640';
  177. }
  178. if (!preg_match ("/^[0-9]{3,4}$/", $compose_height)) {
  179. $compose_height = '550';
  180. }
  181. $js .= "function comp_in_new(comp_uri) {\n".
  182. " if (!comp_uri) {\n".
  183. ' comp_uri = "'.$compose_uri."\";\n".
  184. ' }'. "\n".
  185. ' var newwin = window.open(comp_uri' .
  186. ', "_blank",'.
  187. '"width='.$compose_width. ',height='.$compose_height.
  188. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  189. "}\n\n";
  190. }
  191. // javascript for sending read receipts
  192. if($default_use_mdn && $mdn_user_support) {
  193. $js .= "function sendMDN() {\n".
  194. " mdnuri=window.location+'&sendreceipt=1';\n" .
  195. " window.location = mdnuri;\n" .
  196. "\n}\n\n";
  197. }
  198. // if any of the above passes, add the JS tags too.
  199. if($js) {
  200. $js = "\n".'<script language="JavaScript" type="text/javascript">' .
  201. "\n<!--\n" . $js . "// -->\n</script>\n";
  202. }
  203. displayHtmlHeader ($org_title, $js);
  204. $onload = $xtra;
  205. break;
  206. case 'compose':
  207. $js = '<script language="JavaScript" type="text/javascript">' .
  208. "\n<!--\n" .
  209. "var alreadyFocused = false;\n" .
  210. "function cursorToTop(element) {\n" .
  211. " if (typeof element.selectionStart == 'number')\n" .
  212. // also works:
  213. // " element.setSelectionRange(0, 0);\n" .
  214. " element.selectionStart = element.selectionEnd = 0;\n" .
  215. " else if (typeof element.createTextRange != 'undefined') {\n" .
  216. " var selectionRange = element.createTextRange();\n" .
  217. // also works, but maybe more recent?:
  218. // " selectionRange.collapse(true);\n" .
  219. " selectionRange.moveStart('character', 0);\n" .
  220. " selectionRange.select();\n" .
  221. " }\n" .
  222. "}\n" .
  223. "function checkForm() {\n" .
  224. "\n if (alreadyFocused) return;\n";
  225. global $action, $reply_focus;
  226. if (strpos ($action, 'reply') !== FALSE && $reply_focus)
  227. {
  228. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  229. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus(); cursorToTop(document.forms['compose'].body);}\n";
  230. else if ($reply_focus == 'none') $js .= "}\n";
  231. }
  232. // no reply focus also applies to composing new messages
  233. else if ($reply_focus == 'none')
  234. {
  235. $js .= "}\n";
  236. }
  237. else
  238. $js .= " var f = document.forms.length;\n".
  239. " var i = 0;\n".
  240. " var remembered_form = -1;\n".
  241. " var pos = -1;\n".
  242. " var remembered_pos = -1;\n".
  243. " while( pos == -1 && i < f ) {\n".
  244. " var e = document.forms[i].elements.length;\n".
  245. " var j = 0;\n".
  246. " while( pos == -1 && j < e ) {\n".
  247. " if ( document.forms[i].elements[j].type == 'text' ) {\n".
  248. " if ( document.forms[i].elements[j].id.substring(0, 13) == '__lastfocus__' ) {\n".
  249. " remembered_pos = j;\n".
  250. " remembered_form = i;\n".
  251. " } else if ( document.forms[i].elements[j].id.substring(0, 11) != '__nofocus__' ) {\n".
  252. " pos = j;\n".
  253. " }\n".
  254. " }\n".
  255. " j++;\n".
  256. " }\n".
  257. " i++;\n".
  258. " }\n".
  259. " if( pos >= 0 ) {\n".
  260. " document.forms[i-1].elements[pos].focus();\n".
  261. " } else if ( remembered_pos >= 0 ) {\n".
  262. " document.forms[remembered_form].elements[remembered_pos].focus();\n".
  263. " }\n".
  264. "}\n";
  265. $js .= "// -->\n".
  266. "</script>\n";
  267. $onload = 'onload="checkForm();"';
  268. displayHtmlHeader ($org_title, $js);
  269. break;
  270. default:
  271. $js = '<script language="JavaScript" type="text/javascript">' .
  272. "\n<!--\n" .
  273. "var alreadyFocused = false;\n" .
  274. "function checkForm() {\n".
  275. " if (alreadyFocused) return;\n".
  276. " var f = document.forms.length;\n".
  277. " var i = 0;\n".
  278. " var remembered_form = -1;\n".
  279. " var pos = -1;\n".
  280. " var remembered_pos = -1;\n".
  281. " while( pos == -1 && i < f ) {\n".
  282. " var e = document.forms[i].elements.length;\n".
  283. " var j = 0;\n".
  284. " while( pos == -1 && j < e ) {\n".
  285. " if ( document.forms[i].elements[j].type == 'text' " .
  286. " || document.forms[i].elements[j].type == 'password' ) {\n".
  287. " if ( document.forms[i].elements[j].id.substring(0, 13) == '__lastfocus__' ) {\n".
  288. " remembered_pos = j;\n".
  289. " remembered_form = i;\n".
  290. " } else if ( document.forms[i].elements[j].id.substring(0, 11) != '__nofocus__' ) {\n".
  291. " pos = j;\n".
  292. " }\n".
  293. " }\n".
  294. " j++;\n".
  295. " }\n".
  296. " i++;\n".
  297. " }\n".
  298. " if( pos >= 0 ) {\n".
  299. " document.forms[i-1].elements[pos].focus();\n".
  300. " } else if ( remembered_pos >= 0 ) {\n".
  301. " document.forms[remembered_form].elements[remembered_pos].focus();\n".
  302. " }\n".
  303. " $xtra\n".
  304. "}\n";
  305. if ($compose_new_win == '1') {
  306. if (!preg_match ("/^[0-9]{3,4}$/", $compose_width)) {
  307. $compose_width = '640';
  308. }
  309. if (!preg_match ("/^[0-9]{3,4}$/", $compose_height)) {
  310. $compose_height = '550';
  311. }
  312. $js .= "function comp_in_new(comp_uri) {\n".
  313. " if (!comp_uri) {\n".
  314. ' comp_uri = "'.$compose_uri."\";\n".
  315. ' }'. "\n".
  316. ' var newwin = window.open(comp_uri' .
  317. ', "_blank",'.
  318. '"width='.$compose_width. ',height='.$compose_height.
  319. ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  320. "}\n\n";
  321. }
  322. $js .= "// -->\n". "</script>\n";
  323. $onload = 'onload="checkForm();"';
  324. displayHtmlHeader ($org_title, $js);
  325. } // end switch module
  326. } else {
  327. // JavaScript off
  328. displayHtmlHeader ($org_title);
  329. $onload = '';
  330. }
  331. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  332. /** Here is the header and wrapping table **/
  333. readShortMailboxName ($mailbox, $delimiter)));
  334. if ( $shortBoxName == 'INBOX' ) {
  335. $shortBoxName = _ ("INBOX");
  336. }
  337. echo "<a name=\"pagetop\"></a>\n"
  338. . html_tag ( 'table', '', '', $color[4], 'border="0" width="100%" cellspacing="0" cellpadding="2"' ) ."\n"
  339. . html_tag ( 'tr', '', '', $color[9] ) ."\n"
  340. . html_tag ( 'td', '', 'left' ) ."\n";
  341. if ( $shortBoxName <> '' && strtolower ( $shortBoxName ) <> 'none' ) {
  342. echo ' ' . _ ("Current Folder") . ": <b>$shortBoxName&nbsp;</b>\n";
  343. } else {
  344. echo '&nbsp;';
  345. }
  346. echo " </td>\n"
  347. . html_tag ( 'td', '', 'right' ) ."<b>\n";
  348. displayInternalLink ('src/signout.php', _ ("Sign Out"), $frame_top);
  349. echo "</b></td>\n"
  350. . " </tr>\n"
  351. . html_tag ( 'tr', '', '', $color[4] ) ."\n"
  352. . ($hide_sm_attributions ? html_tag ( 'td', '', 'left', '', 'colspan="2"' )
  353. : html_tag ( 'td', '', 'left' ) )
  354. . "\n";
  355. $urlMailbox = urlencode ($mailbox);
  356. $startMessage = (int)$startMessage;
  357. echo makeComposeLink ('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
  358. echo "&nbsp;&nbsp;\n";
  359. displayInternalLink ('src/addressbook.php', _ ("Addresses"));
  360. echo "&nbsp;&nbsp;\n";
  361. displayInternalLink ('src/folders.php', _ ("Folders"));
  362. echo "&nbsp;&nbsp;\n";
  363. displayInternalLink ('src/options.php', _ ("Options"));
  364. echo "&nbsp;&nbsp;\n";
  365. displayInternalLink ("src/search.php?mailbox=$urlMailbox&amp;what=", _ ("Search"));
  366. echo "&nbsp;&nbsp;\n";
  367. displayInternalLink ('src/help.php', _ ("Help"));
  368. echo "&nbsp;&nbsp;\n";
  369. do_hook ('menuline');
  370. echo " </td>\n";
  371. if (!$hide_sm_attributions)
  372. {
  373. echo html_tag ( 'td', '', 'right' ) ."\n";
  374. if (!isset($provider_uri)) $provider_uri= 'http://squirrelmail.org/';
  375. if (!isset($provider_name)) $provider_name= 'SquirrelMail';
  376. echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  377. echo "</td>\n";
  378. }
  379. echo " </tr>\n".
  380. "</table><br>\n\n";
  381. }
  382. /* blatently copied/truncated/modified from the above function */
  383. function compose_Header ($color, $mailbox) {
  384. global $delimiter, $hide_sm_attributions , $base_uri,
  385. $data_dir , $username, $frame_top , $compose_new_win;
  386. if (!isset($frame_top)) {
  387. $frame_top = '_top';
  388. }
  389. /*
  390. Locate the first displayable form element
  391. */
  392. if ( !defined ('PAGE_NAME') ) define ('PAGE_NAME', NULL);
  393. switch ( PAGE_NAME ) {
  394. case 'search':
  395. $pos = getPref ($data_dir, $username, 'search_pos', 0 ) - 1;
  396. $onload = "onload=\"document.forms[$pos].elements[2].focus();\"";
  397. displayHtmlHeader (_ ("Compose"));
  398. break;
  399. default:
  400. $js = '<script language="JavaScript" type="text/javascript">' .
  401. "\n<!--\n" .
  402. "var alreadyFocused = false;\n" .
  403. "function checkForm() {\n" .
  404. "\n if (alreadyFocused) return;\n";
  405. global $action, $reply_focus;
  406. if (strpos ($action, 'reply') !== FALSE && $reply_focus)
  407. {
  408. if ($reply_focus == 'select') $js .= "document.forms['compose'].body.select();}\n";
  409. else if ($reply_focus == 'focus') $js .= "document.forms['compose'].body.focus();}\n";
  410. else if ($reply_focus == 'none') $js .= "}\n";
  411. }
  412. // no reply focus also applies to composing new messages
  413. else if ($reply_focus == 'none')
  414. {
  415. $js .= "}\n";
  416. }
  417. else
  418. $js .= "var f = document.forms.length;\n".
  419. "var i = 0;\n".
  420. "var remembered_form = -1;\n".
  421. "var pos = -1;\n".
  422. "var remembered_pos = -1;\n".
  423. "while( pos == -1 && i < f ) {\n".
  424. "var e = document.forms[i].elements.length;\n".
  425. "var j = 0;\n".
  426. "while( pos == -1 && j < e ) {\n".
  427. "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  428. "if ( document.forms[i].elements[j].id.substring(0, 13) == '__lastfocus__' ) {\n".
  429. "remembered_pos = j;\n".
  430. "remembered_form = i;\n".
  431. "} else if ( document.forms[i].elements[j].id.substring(0, 11) != '__nofocus__' ) {\n".
  432. "pos = j;\n".
  433. "}\n".
  434. "}\n".
  435. "j++;\n".
  436. "}\n".
  437. "i++;\n".
  438. "}\n".
  439. "if( pos >= 0 ) {\n".
  440. "document.forms[i-1].elements[pos].focus();\n".
  441. "} else if ( remembered_pos >= 0 ) {\n".
  442. "document.forms[remembered_form].elements[remembered_pos].focus();\n".
  443. "}\n".
  444. "}\n";
  445. $js .= "// -->\n".
  446. "</script>\n";
  447. $onload = 'onload="checkForm();"';
  448. displayHtmlHeader (_ ("Compose"), $js);
  449. break;
  450. }
  451. echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  452. }

Documentation generated on 2020年1月13日 04:25:09 +0100 by phpDocumentor 1.4.3

AltStyle によって変換されたページ (->オリジナル) /