Source for file page_header.php

Documentation is available at page_header.php

  1. <?php
  2.  
  3. /**
  4.  * page_header.php
  5.  *
  6.  * Prints the page header (duh)
  7.  *
  8.  * @copyright 1999-2012 The SquirrelMail Project Team
  9.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  10.  * @version $Id: page_header.php 14345 2012-12-09 11:58:17Z kink $
  11.  * @package squirrelmail
  12.  */
  13.  
  14. /** Include required files from SM */
  15. require_once(SM_PATH 'functions/strings.php');
  16. require_once(SM_PATH 'functions/html.php');
  17. require_once(SM_PATH 'functions/imap_mailbox.php');
  18. require_once(SM_PATH 'functions/global.php');
  19.  
  20. /* Always set up the language before calling these functions */
  21. function displayHtmlHeader$title 'SquirrelMail'$xtra ''$do_hook TRUE {
  22.     global $squirrelmail_language;
  23.  
  24.     if !sqgetGlobalVar('base_uri'$base_uriSQ_SESSION) ) {
  25.         global $base_uri;
  26.     }
  27.     global $theme_css$custom_css$pageheader_sent$browser_rendering_mode;
  28.  
  29.     // prevent clickjack attempts
  30. // 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
  31.     header('X-Frame-Options: SAMEORIGIN');
  32.  
  33.     echo ($browser_rendering_mode === 'standards'
  34.        ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">'
  35.        : ($browser_rendering_mode === 'almost'
  36.          ? '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">'
  37.          : /* "quirks" */ '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">')) .
  38.          "\n\n" html_tag'html' ,'' '''''' "\n<head>\n" .
  39.          "<meta name=\"robots\" content=\"noindex,nofollow\">\n" .
  40.          "<meta http-equiv=\"x-dns-prefetch-control\" content=\"off\">\n";
  41.  
  42.     // prevent clickjack attempts using JavaScript for browsers that
  43.     // don't support the X-Frame-Options header...
  44.     // we check to see if we are *not* the top page, and if not, check
  45.     // whether or not the top page is in the same domain as we are...
  46.     // if not, log out immediately -- this is an attempt to do the same
  47.     // thing that the X-Frame-Options does using JavaScript (never a good
  48.     // idea to rely on JavaScript-based solutions, though)
  49.     echo '<script type="text/javascript" language="JavaScript">'
  50.        . "\n<!--\n"
  51.        . 'if (self != top) { try { if (document.domain != top.document.domain) {'
  52.        . ' 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 = "'
  53.        . sqm_baseuri('src/signout.php"; top.location = "'
  54.        . sqm_baseuri('src/signout.php" } }'
  55.        . "\n// -->\n</script>\n";
  56.  
  57.     if !isset$custom_css || $custom_css == 'none' {
  58.         if ($theme_css != ''{
  59.             echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$theme_css\">";
  60.         }
  61.     else {
  62.         echo '<link rel="stylesheet" type="text/css" href="' .
  63.              $base_uri 'themes/css/'.$custom_css.'">';
  64.     }
  65.  
  66.     if ($squirrelmail_language == 'ja_JP'{
  67.         // Why is it added here? Header ('Content-Type:..) is used in i18n.php
  68.         echo "<!-- \xfd\xfe -->\n";
  69.         echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' "\n";
  70.     }
  71.  
  72.     if ($do_hook{
  73.         do_hook('generic_header');
  74.     }
  75.  
  76.     echo "\n<title>$title</title>$xtra\n";
  77.  
  78.     /* work around IE6's scrollbar bug */
  79.     echo <<<ECHO
  80. <!--[if IE 6]>
  81. <style type="text/css">
  82. /* avoid stupid IE6 bug with frames and scrollbars */
  83. body {
  84.     width: expression(document.documentElement.clientWidth - 30);
  85. }
  86. </style>
  87. <![endif]-->
  88.  
  89. ECHO;
  90.  
  91.     echo "\n</head>\n\n";
  92.  
  93.     /* this is used to check elsewhere whether we should call this function */
  94.     $pageheader_sent TRUE;
  95. }
  96.  
  97. function makeInternalLink($path$text$target=''{
  98.     sqgetGlobalVar('base_uri'$base_uriSQ_SESSION);
  99.     if ($target != ''{
  100.         $target " target=\"$target\"";
  101.     }
  102.     return '<a href="'.$base_uri.$path.'"'.$target.'>'.$text.'</a>';
  103. }
  104.  
  105. function displayInternalLink($path$text$target=''{
  106.     echo makeInternalLink($path$text$target);
  107. }
  108.  
  109. function displayPageHeader($color$mailbox$xtra=''$session=false{
  110.  
  111.            $compose_new_win$compose_width$compose_height,
  112.            $attachemessages$provider_name$provider_uri,
  113.            $javascript_on$default_use_mdn$mdn_user_support,
  114.            $startMessage$org_title;
  115.  
  116.     sqgetGlobalVar('base_uri'$base_uriSQ_SESSION );
  117.     sqgetGlobalVar('delimiter'$delimiterSQ_SESSION );
  118.     if (!isset($frame_top)) {
  119.         $frame_top '_top';
  120.     }
  121.  
  122.     if ($session{
  123.         $compose_uri $base_uri.'src/compose.php?mailbox='.urlencode($mailbox).'&amp;session='."$session";
  124.     else {
  125.         $compose_uri $base_uri.'src/compose.php?newmessage=1';
  126.         $session 0;
  127.     }
  128.  
  129.     // only output JavaScript if actually turned on
  130.     if($javascript_on || strpos($xtra'new_js_autodetect_results.value') ) {
  131.         if !defined('PAGE_NAME') ) define('PAGE_NAME'NULL);
  132.         switch PAGE_NAME {
  133.         case 'read_body':
  134.             $js ='';
  135.  
  136.             // compose in new window code
  137.             if ($compose_new_win == '1'{
  138.                 if (!preg_match("/^[0-9]{3,4}$/"$compose_width)) {
  139.                     $compose_width '640';
  140.                 }
  141.                 if (!preg_match("/^[0-9]{3,4}$/"$compose_height)) {
  142.                     $compose_height '550';
  143.                 }
  144.                 $js .= "function comp_in_new(comp_uri) {\n".
  145.                      "       if (!comp_uri) {\n".
  146.                      '           comp_uri = "'.$compose_uri."\";\n".
  147.                      '       }'"\n".
  148.                      '    var newwin = window.open(comp_uri' .
  149.                      ', "_blank",'.
  150.                      '"width='.$compose_width',height='.$compose_height.
  151.                      ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  152.                      "}\n\n";
  153.             }
  154.  
  155.             // javascript for sending read receipts
  156.             if($default_use_mdn && $mdn_user_support{
  157.                 $js .= "function sendMDN() {\n".
  158.                          "    mdnuri=window.location+'&sendreceipt=1';\n" .
  159.                          "    window.location = mdnuri;\n" .
  160.                        "\n}\n\n";
  161.             }
  162.  
  163.             // if any of the above passes, add the JS tags too.
  164.             if($js{
  165.                 $js "\n".'<script language="JavaScript" type="text/javascript">' .
  166.                       "\n<!--\n" $js "// -->\n</script>\n";
  167.             }
  168.  
  169.             displayHtmlHeader($org_title$js);
  170.             $onload $xtra;
  171.           break;
  172.         case 'compose':
  173.             $js '<script language="JavaScript" type="text/javascript">' .
  174.              "\n<!--\n" .
  175.              "var alreadyFocused = false;\n" .
  176.              "function checkForm() {\n" .
  177.              "\n    if (alreadyFocused) return;\n";
  178.  
  179.             global $action$reply_focus;
  180.             if (strpos($action'reply'!== FALSE && $reply_focus)
  181.             {
  182.                 if ($reply_focus == 'select'$js .= "document.forms['compose'].body.select();}\n";
  183.                 else if ($reply_focus == 'focus'$js .= "document.forms['compose'].body.focus();}\n";
  184.                 else if ($reply_focus == 'none'$js .= "}\n";
  185.             }
  186.             // no reply focus also applies to composing new messages
  187.             else if ($reply_focus == 'none')
  188.             {
  189.                 $js .= "}\n";
  190.             }
  191.             else
  192.                 $js .= "    var f = document.forms.length;\n".
  193.                 "    var i = 0;\n".
  194.                 "    var pos = -1;\n".
  195.                 "    while( pos == -1 && i < f ) {\n".
  196.                 "        var e = document.forms[i].elements.length;\n".
  197.                 "        var j = 0;\n".
  198.                 "        while( pos == -1 && j < e ) {\n".
  199.                 "            if ( document.forms[i].elements[j].type == 'text' ) {\n".
  200.                 "                pos = j;\n".
  201.                 "            }\n".
  202.                 "            j++;\n".
  203.                 "        }\n".
  204.                 "        i++;\n".
  205.                 "    }\n".
  206.                 "    if( pos >= 0 ) {\n".
  207.                 "        document.forms[i-1].elements[pos].focus();\n".
  208.                 "    }\n".
  209.                 "}\n";
  210.  
  211.             $js .= "// -->\n".
  212.                  "</script>\n";
  213.             $onload 'onload="checkForm();"';
  214.             displayHtmlHeader($org_title$js);
  215.             break;
  216.  
  217.         default:
  218.             $js '<script language="JavaScript" type="text/javascript">' .
  219.              "\n<!--\n" .
  220.              "function checkForm() {\n".
  221.              "   var f = document.forms.length;\n".
  222.              "   var i = 0;\n".
  223.              "   var pos = -1;\n".
  224.              "   while( pos == -1 && i < f ) {\n".
  225.              "       var e = document.forms[i].elements.length;\n".
  226.              "       var j = 0;\n".
  227.              "       while( pos == -1 && j < e ) {\n".
  228.              "           if ( document.forms[i].elements[j].type == 'text' " .
  229.              "           || document.forms[i].elements[j].type == 'password' ) {\n".
  230.              "               pos = j;\n".
  231.              "           }\n".
  232.              "           j++;\n".
  233.              "       }\n".
  234.              "   i++;\n".
  235.              "   }\n".
  236.              "   if( pos >= 0 ) {\n".
  237.              "       document.forms[i-1].elements[pos].focus();\n".
  238.              "   }\n".
  239.              "   $xtra\n".
  240.              "}\n";
  241.  
  242.             if ($compose_new_win == '1'{
  243.                 if (!preg_match("/^[0-9]{3,4}$/"$compose_width)) {
  244.                     $compose_width '640';
  245.                 }
  246.                 if (!preg_match("/^[0-9]{3,4}$/"$compose_height)) {
  247.                     $compose_height '550';
  248.                 }
  249.                 $js .= "function comp_in_new(comp_uri) {\n".
  250.                      "       if (!comp_uri) {\n".
  251.                      '           comp_uri = "'.$compose_uri."\";\n".
  252.                      '       }'"\n".
  253.                      '    var newwin = window.open(comp_uri' .
  254.                      ', "_blank",'.
  255.                      '"width='.$compose_width',height='.$compose_height.
  256.                      ',scrollbars=yes,resizable=yes,status=yes");'."\n".
  257.                      "}\n\n";
  258.  
  259.             }
  260.         $js .= "// -->\n""</script>\n";
  261.  
  262.  
  263.         $onload 'onload="checkForm();"';
  264.         displayHtmlHeader($org_title$js);
  265.       // end switch module
  266.     else {
  267.         // JavaScript off
  268.         displayHtmlHeader($org_title);
  269.         $onload '';
  270.     }
  271.  
  272.     echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  273.     /** Here is the header and wrapping table **/
  274.                       readShortMailboxName($mailbox$delimiter)));
  275.     if $shortBoxName == 'INBOX' {
  276.         $shortBoxName _("INBOX");
  277.     }
  278.     echo "<a name=\"pagetop\"></a>\n"
  279.         . html_tag'table'''''$color[4]'border="0" width="100%" cellspacing="0" cellpadding="2"' ."\n"
  280.         . html_tag'tr'''''$color[9."\n"
  281.         . html_tag'td''''left' ."\n";
  282.     if $shortBoxName <> '' && strtolower$shortBoxName <> 'none' {
  283.         echo '         ' _("Current Folder"": <b>$shortBoxName&nbsp;</b>\n";
  284.     else {
  285.         echo '&nbsp;';
  286.     }
  287.     echo  "      </td>\n"
  288.         . html_tag'td''''right' ."<b>\n";
  289.     displayInternalLink ('src/signout.php'_("Sign Out")$frame_top);
  290.     echo "</b></td>\n"
  291.         . "   </tr>\n"
  292.         . html_tag'tr'''''$color[4."\n"
  293.         . ($hide_sm_attributions html_tag'td''''left''''colspan="2"' )
  294.                                  : html_tag'td''''left' ) )
  295.         . "\n";
  296.     $urlMailbox urlencode($mailbox);
  297.     $startMessage = (int)$startMessage;
  298.     echo makeComposeLink('src/compose.php?mailbox='.$urlMailbox.'&amp;startMessage='.$startMessage);
  299.     echo "&nbsp;&nbsp;\n";
  300.     displayInternalLink ('src/addressbook.php'_("Addresses"));
  301.     echo "&nbsp;&nbsp;\n";
  302.     displayInternalLink ('src/folders.php'_("Folders"));
  303.     echo "&nbsp;&nbsp;\n";
  304.     displayInternalLink ('src/options.php'_("Options"));
  305.     echo "&nbsp;&nbsp;\n";
  306.     displayInternalLink ("src/search.php?mailbox=$urlMailbox"_("Search"));
  307.     echo "&nbsp;&nbsp;\n";
  308.     displayInternalLink ('src/help.php'_("Help"));
  309.     echo "&nbsp;&nbsp;\n";
  310.  
  311.     do_hook('menuline');
  312.  
  313.     echo "      </td>\n";
  314.  
  315.     if (!$hide_sm_attributions)
  316.     {
  317.         echo html_tag'td''''right' ."\n";
  318.         if (!isset($provider_uri)) $provider_uri'http://squirrelmail.org/';
  319.         if (!isset($provider_name)) $provider_name'SquirrelMail';
  320.         echo '<a href="'.$provider_uri.'" target="_blank">'.$provider_name.'</a>';
  321.         echo "</td>\n";
  322.     }
  323.     echo "   </tr>\n".
  324.         "</table><br>\n\n";
  325. }
  326.  
  327. /* blatently copied/truncated/modified from the above function */
  328. function compose_Header($color$mailbox{
  329.  
  330.     global $delimiter$hide_sm_attributions$base_uri,
  331.            $data_dir$username$frame_top$compose_new_win;
  332.  
  333.  
  334.     if (!isset($frame_top)) {
  335.         $frame_top '_top';
  336.     }
  337.  
  338.     /*
  339.         Locate the first displayable form element
  340.     */
  341.     if !defined('PAGE_NAME') ) define('PAGE_NAME'NULL);
  342.     switch PAGE_NAME {
  343.     case 'search':
  344.         $pos getPref($data_dir$username'search_pos'1;
  345.         $onload "onload=\"document.forms[$pos].elements[2].focus();\"";
  346.         displayHtmlHeader (_("Compose"));
  347.         break;
  348.     default:
  349.         $js '<script language="JavaScript" type="text/javascript">' .
  350.              "\n<!--\n" .
  351.              "var alreadyFocused = false;\n" .
  352.              "function checkForm() {\n" .
  353.              "\n    if (alreadyFocused) return;\n";
  354.  
  355.             global $action$reply_focus;
  356.             if (strpos($action'reply'!== FALSE && $reply_focus)
  357.             {
  358.                 if ($reply_focus == 'select'$js .= "document.forms['compose'].body.select();}\n";
  359.                 else if ($reply_focus == 'focus'$js .= "document.forms['compose'].body.focus();}\n";
  360.                 else if ($reply_focus == 'none'$js .= "}\n";
  361.             }
  362.             // no reply focus also applies to composing new messages
  363.             else if ($reply_focus == 'none')
  364.             {
  365.                 $js .= "}\n";
  366.             }
  367.             else
  368.                 $js .= "var f = document.forms.length;\n".
  369.                 "var i = 0;\n".
  370.                 "var pos = -1;\n".
  371.                 "while( pos == -1 && i < f ) {\n".
  372.                     "var e = document.forms[i].elements.length;\n".
  373.                     "var j = 0;\n".
  374.                     "while( pos == -1 && j < e ) {\n".
  375.                         "if ( document.forms[i].elements[j].type == 'text' ) {\n".
  376.                             "pos = j;\n".
  377.                         "}\n".
  378.                         "j++;\n".
  379.                     "}\n".
  380.                 "i++;\n".
  381.                 "}\n".
  382.                 "if( pos >= 0 ) {\n".
  383.                     "document.forms[i-1].elements[pos].focus();\n".
  384.                 "}\n".
  385.             "}\n";
  386.         $js .= "// -->\n".
  387.                  "</script>\n";
  388.         $onload 'onload="checkForm();"';
  389.         displayHtmlHeader (_("Compose")$js);
  390.         break;
  391.  
  392.     }
  393.  
  394.     echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\" $onload>\n\n";
  395. }

Documentation generated on Wed, 22 May 2013 04:23:04 +0200 by phpDocumentor 1.4.3