Source for file printer_friendly_bottom.php

Documentation is available at printer_friendly_bottom.php

  1. <?php
  2.  
  3. /**
  4.  * printer_friendly_bottom.php
  5.  *
  6.  * with javascript on, it is the bottom frame of printer_friendly_main.php
  7.  * else, it is alone in a new window
  8.  *
  9.  * - this is the page that does all the work, really.
  10.  *
  11.  * @copyright &copy; 1999-2006 The SquirrelMail Project Team
  12.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  13.  * @version $Id: printer_friendly_bottom.php,v 1.29.2.13 2006/04/14 22:27:08 jervfors Exp $
  14.  * @package squirrelmail
  15.  */
  16.  
  17. /**
  18.  * Path for SquirrelMail required files.
  19.  * @ignore
  20.  */
  21. define('SM_PATH','../');
  22.  
  23. /* SquirrelMail required files. */
  24. require_once(SM_PATH 'include/validate.php');
  25. require_once(SM_PATH 'functions/imap.php');
  26.  
  27. /* get some of these globals */
  28. sqgetGlobalVar('username'$usernameSQ_SESSION);
  29. sqgetGlobalVar('key'$keySQ_COOKIE);
  30. sqgetGlobalVar('onetimepad'$onetimepadSQ_SESSION);
  31.  
  32. sqgetGlobalVar('passed_id'$passed_idSQ_GET);
  33. sqgetGlobalVar('mailbox'$mailboxSQ_GET);
  34.  
  35. if (sqgetGlobalVar('passed_ent_id'$passed_ent_idSQ_GET||
  36.     preg_match('/^\d+(\.\d+)*$/'$passed_ent_id) ) {
  37.     $passed_ent_id '';
  38. /* end globals */
  39.  
  40. $pf_cleandisplay getPref($data_dir$username'pf_cleandisplay'false);
  41. $imapConnection sqimap_login($username$key$imapServerAddress$imapPort0);
  42. $mbx_response sqimap_mailbox_select($imapConnection$mailbox);
  43. if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
  44.     $message $messages[$mbx_response['UIDVALIDITY']][$passed_id];
  45. else {
  46.     $message sqimap_get_message($imapConnection$passed_id$mailbox);
  47. }
  48. if ($passed_ent_id{
  49.     $message $message->getEntity($passed_ent_id);
  50. }
  51.  
  52. /* --start display setup-- */
  53.  
  54. $rfc822_header $message->rfc822_header
  55. /* From and Date are usually fine as they are... */
  56. $from $rfc822_header->getAddr_s('from');
  57. $date getLongDateString($rfc822_header->date);
  58. $subject trim($rfc822_header->subject);
  59.  
  60. /* we can clean these up if the list is too long... */
  61. $cc $rfc822_header->getAddr_s('cc');
  62. $to $rfc822_header->getAddr_s('to');
  63.  
  64. if ($show_html_default == 1{
  65.     $ent_ar $message->findDisplayEntity(array());
  66. else {
  67.     $ent_ar $message->findDisplayEntity(array()array('text/plain'));
  68. }
  69. $body '';
  70. if ($ent_ar[0!= ''{
  71.   for ($i 0$i count($ent_ar)$i++{
  72.      $body .= formatBody($imapConnection$message$color$wrap_at$ent_ar[$i]$passed_id$mailboxtrue);
  73.      $body .= '<hr noshade size="1" />';
  74.   }
  75.   $hookResults do_hook('message_body'$body);
  76.   $body $hookResults[1];
  77. else {
  78.   $body _("Message not printable");
  79. }
  80.  
  81.  /* now, if they choose to, we clean up the display a bit... */
  82.  
  83. if ($pf_cleandisplay{
  84.  
  85.     $num_leading_spaces 9// nine leading spaces for indentation
  86.  
  87.      // sometimes I see ',,' instead of ',' seperating addresses *shrug*
  88.         $cc pf_clean_string(str_replace(',,'','$cc)$num_leading_spaces);
  89.     $to pf_clean_string(str_replace(',,'','$to)$num_leading_spaces);
  90.  
  91.      // the body should have no leading zeros
  92.     // disabled because it destroys html mail
  93.  
  94. //    $body = pf_clean_string($body, 0);
  95.  
  96.      // clean up everything else...
  97.         $subject pf_clean_string($subject$num_leading_spaces);
  98.     $from pf_clean_string($from$num_leading_spaces);
  99.     $date pf_clean_string($date$num_leading_spaces);
  100.  
  101. // end cleanup
  102.  
  103. $to decodeHeader($to);
  104. $cc decodeHeader($cc);
  105. $from decodeHeader($from);
  106. $subject decodeHeader($subject);
  107.  
  108. // load attachments
  109. $attachments pf_show_attachments($message,$ent_ar,$mailbox,$passed_id);
  110.  
  111. // --end display setup--
  112.  
  113.  
  114. /* --start browser output-- */
  115. displayHtmlHeader$subject''FALSE );
  116.  
  117. echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\n" .
  118.      /* headers (we use table because translations are not all the same width) */
  119.      html_tag'table''''center''''cellspacing="0" cellpadding="0" border="0" width="100%"' .
  120.      html_tag'tr',
  121.          html_tag'td'_("From").':&nbsp;''left' ,'','valign="top"'.
  122.          html_tag'td'$from'left' )
  123.      "\n" .
  124.      html_tag'tr',
  125.          html_tag'td'_("Subject").':&nbsp;''left','','valign="top"' .
  126.          html_tag'td'$subject'left' )
  127.      "\n" .
  128.      html_tag'tr',
  129.          html_tag'td'_("Date").':&nbsp;''left' .
  130.          html_tag'td'htmlspecialchars($date)'left' )
  131.      "\n" .
  132.      html_tag'tr',
  133.          html_tag'td'_("To").':&nbsp;''left','','valign="top"' .
  134.          html_tag'td'$to'left' )
  135.     "\n";
  136.     if strlen($cc/* only show Cc: if it's there... */
  137.          echo html_tag'tr',
  138.              html_tag'td'_("Cc").':&nbsp;''left','','valign="top"' .
  139.              html_tag'td'$cc'left' )
  140.          );
  141.      }
  142.      /* body */
  143.      echo html_tag'tr',
  144.          html_tag'td''<hr noshade size="1" /><br />' "\n" $body'left''''colspan="2"' )
  145.                     "\n";
  146.  
  147.      if (empty($attachments)) {
  148.          // attachments title
  149.                   echo html_tag'tr',
  150.              html_tag'td','<b>'._("Attachments:").'</b>''left''''colspan="2"' )
  151.          "\n" ;
  152.          // list of attachments
  153.                   echo html_tag'tr',
  154.              html_tag'td',$attachments'left''''colspan="2"' )
  155.          "\n" ;
  156.          // add separator line
  157.                   echo html_tag'tr',
  158.              html_tag'td''<hr style="height: 1px;" />''left''''colspan="2"' )
  159.          "\n" ;
  160.      }
  161.  
  162.      echo '</table>' "\n" .
  163.      '</body></html>';
  164.  
  165. /* --end browser output-- */
  166.  
  167.  
  168. /* --start pf-specific functions-- */
  169.  
  170. /**
  171.  * Function should clean layout of printed messages when user
  172.  * enables "Printer Friendly Clean Display" option.
  173.  *
  174.  * @param string unclean_string
  175.  * @param integer num_leading_spaces
  176.  * @return string 
  177.  * @example $string = pf_clean_string($string, 9);
  178.  * @access private
  179.  */
  180. function pf_clean_string $unclean_string$num_leading_spaces {
  181.     global $data_dir$username;
  182.     $unclean_string str_replace('&nbsp;',' ',$unclean_string);
  183.     $wrap_at getPref($data_dir$username'wrap_at'86);
  184.     $wrap_at $wrap_at $num_leading_spaces/* header stuff */
  185.  
  186.     $leading_spaces '';
  187.     while strlen($leading_spaces$num_leading_spaces )
  188.         $leading_spaces .= ' ';
  189.  
  190.     $clean_string '';
  191.     while strlen($unclean_string$wrap_at )
  192.     {
  193.         $this_line substr($unclean_string0$wrap_at);
  194.         if strrpos$this_line"\n" ) ) /* this should NEVER happen with anything but the $body */
  195.         {
  196.             $clean_string .= substr$this_line0strrpos$this_line"\n" ));
  197.             $clean_string .= $leading_spaces;
  198.             $unclean_string substr($unclean_stringstrrpos$this_line"\n" ));
  199.         }
  200.         else
  201.         {
  202.             $i strrpos$this_line' ');
  203.             $clean_string .= substr$this_line0$i);
  204.             $clean_string .= "\n" $leading_spaces;
  205.             $unclean_string substr($unclean_string1+$i);
  206.         }
  207.     }
  208.     $clean_string .= $unclean_string;
  209.  
  210.     return $clean_string;
  211. /* end pf_clean_string() function */
  212.  
  213. /**
  214.  * Displays attachment information
  215.  *
  216.  * Stripped version of formatAttachments() function from functions/mime.php.
  217.  * @param object $message SquirrelMail message object
  218.  * @param array $exclude_id message parts that are not attachments.
  219.  * @param string $mailbox mailbox name
  220.  * @param integer $id message id
  221.  * @since 1.5.1 and 1.4.6
  222.  * @return string html formated attachment information.
  223.  */
  224. function pf_show_attachments($message$exclude_id$mailbox$id{
  225.     global $where$what$startMessage$color$passed_ent_id;
  226.  
  227.     $att_ar $message->getAttachments($exclude_id);
  228.  
  229.     if (!count($att_ar)) return '';
  230.  
  231.     $attachments '';
  232.  
  233.     $urlMailbox urlencode($mailbox);
  234.  
  235.     foreach ($att_ar as $att{
  236.         $ent $att->entity_id;
  237.         $header $att->header;
  238.         $type0 strtolower($header->type0);
  239.         $type1 strtolower($header->type1);
  240.         $name '';
  241.  
  242.         if ($type0 =='message' && $type1 == 'rfc822'{
  243.             $rfc822_header $att->rfc822_header;
  244.             $filename $rfc822_header->subject;
  245.             if (trim$filename == ''{
  246.                 $filename 'untitled-[' $ent ']' ;
  247.             }
  248.             $from_o $rfc822_header->from;
  249.             if (is_object($from_o)) {
  250.                 $from_name decodeHeader($from_o->getAddress(true));
  251.             else {
  252.                 $from_name _("Unknown sender");
  253.             }
  254.             $description '<tr>'.
  255.                 html_tag'td',_("From:")'right'.
  256.                 html_tag'td',$from_name'left'.
  257.                 '</tr>';
  258.         else {
  259.             $filename $att->getFilename();
  260.             if ($header->description{
  261.                 $description '<tr>'.
  262.                     html_tag'td',_("Info:")'right'.
  263.                     html_tag'td',decodeHeader($header->description)'left'.
  264.                     '</tr>';
  265.             else {
  266.                 $description '';
  267.             }
  268.         }
  269.  
  270.         $display_filename $filename;
  271.  
  272.         // TODO: maybe make it nicer?
  273.         $attachments .= '<table cellpadding="0" cellspacing="0" border="1"><tr><th colspan="2">'.decodeHeader($display_filename).'</th></tr>' .
  274.             '<tr border="0">'.
  275.             html_tag'td',_("Size:")'right'.
  276.             html_tag'td',show_readable_size($header->size)'left'.
  277.             '</tr><tr>' .
  278.             html_tag'td',_("Type:")'right'.
  279.             html_tag'td',htmlspecialchars($type0).'/'.htmlspecialchars($type1)'left'
  280.             '</tr>';
  281.         if (empty($description)) {
  282.             $attachments .= $description;
  283.         }
  284.         $attachments .= "</table>\n";
  285.     }
  286.     return $attachments;
  287. }
  288.  
  289.  
  290. /* --end pf-specific functions */
  291. ?>

Documentation generated on Sat, 07 Oct 2006 16:33:05 +0300 by phpDocumentor 1.3.0RC6