From 6401604a3bf3fadff3c3912a1443b16f8724d28a Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 1 Feb 2010 12:35:25 -0700 Subject: [PATCH] Move print generation to separate script. For non-Mozilla browsers, use frames to separate headers from message data. Only show print links for parts that can be displayed in a 'full' render. Re-add support for 'add_printedby' config option. --- imp/config/conf.xml | 6 +++ imp/js/imp.js | 5 +++ imp/lib/Contents.php | 9 ++-- imp/print.php | 96 ++++++++++++++++++++++++++++++++++++++++ imp/templates/print/headers.html | 12 +++++ imp/templates/print/print.html | 8 ++++ 6 files changed, 133 insertions(+), 3 deletions(-) create mode 100644 imp/print.php create mode 100644 imp/templates/print/headers.html create mode 100644 imp/templates/print/print.html diff --git a/imp/config/conf.xml b/imp/config/conf.xml index 17d1a3d5b..a0ca9e35c 100644 --- a/imp/config/conf.xml +++ b/imp/config/conf.xml @@ -139,6 +139,12 @@ + + Print Options + false + + $param_array)); + if (($mask && self::SUMMARY_PRINT) && + $this->canDisplay($id, self::RENDER_FULL)) { + $part['print'] = $this->linkViewJS($mime_part, 'print_attach', '', array('css' => 'printAtc', 'jstext' => _("Print"), 'onload' => 'IMP.printWindow', 'params' => $param_array, 'print' => true)); } /* Strip Attachment? Allow stripping of base parts other than the @@ -808,6 +809,8 @@ class IMP_Contents * fully loaded. * 'params' - (array) A list of any additional parameters that need to be * passed to view.php. (key = name) + * 'print' - (boolean) Generate link to print page? + * DEFAULT: Link to view page. * 'widget' - (boolean) If true use Horde::widget() to generate, * Horde::link() otherwise. * @@ -825,7 +828,7 @@ class IMP_Contents $options['jstext'] = sprintf(_("View %s"), $mime_part->getDescription(true)); } - $url = Horde::popupJs(Horde::applicationUrl('view.php'), array('menu' => true, 'onload' => empty($options['onload']) ? '' : $options['onload'], 'params' => $this->_urlViewParams($mime_part, $actionID, isset($options['params']) ? $options['params'] : array()), 'urlencode' => true)) . 'return false;'; + $url = Horde::popupJs(Horde::applicationUrl(empty($options['print']) ? 'view.php' : 'print.php'), array('menu' => true, 'onload' => empty($options['onload']) ? '' : $options['onload'], 'params' => $this->_urlViewParams($mime_part, $actionID, isset($options['params']) ? $options['params'] : array()), 'urlencode' => true)) . 'return false;'; return empty($options['widget']) ? Horde::link('#', $options['jstext'], empty($options['css']) ? null : $options['css'], null, $url) . $text . '' diff --git a/imp/print.php b/imp/print.php new file mode 100644 index 000000000..66a0139a3 --- /dev/null +++ b/imp/print.php @@ -0,0 +1,96 @@ + + * URL parameters: + * --------------- + * 'id' - (string) The MIME ID of the part to print. + * 'mailbox' - (string) The mailbox of the message. + * 'mode' - (string) The print mode to use ('content', 'headers', empty). + * DEFAULT: Prints frameset page + * 'uid' - (integer) The UID of the message. + * + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (GPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. + * + * @author Michael Slusarz + * @package IMP + */ + +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('imp', array('session_control' => 'readonly')); + +$vars = Horde_Variables::getDefaultVariables(); + +/* Bug #8708 - Mozilla can't print multipage data in frames. No choice but + * to output just the data with no header information. */ +if ($browser->isBrowser('mozilla')) { + $vars->mode = 'content'; +} + +switch ($vars->mode) { +case 'content': +case 'headers': + if (!$vars->uid || !$vars->mailbox || !$vars->id) { + exit; + } + + $contents = IMP_Contents::singleton($vars->uid . IMP::IDX_SEP . $vars->mailbox); + + switch ($vars->mode) { + case 'content': + $render = $contents->renderMIMEPart($vars->id, IMP_Contents::RENDER_FULL); + if (!empty($render)) { + reset($render); + $key = key($render); + $browser->downloadHeaders($render[$key]['name'], $render[$key]['type'], true, strlen($render[$key]['data'])); + echo $render[$key]['data']; + } + break; + + case 'headers': + $imp_ui = new IMP_Ui_Message(); + $basic_headers = $imp_ui->basicHeaders(); + unset($basic_headers['bcc'], $basic_headers['reply-to']); + $headerob = $contents->getHeaderOb(); + + $headers = array(); + foreach ($basic_headers as $key => $val) { + if ($hdr_val = $headerob->getValue($key)) { + $headers[] = array( + 'header' => htmlspecialchars($val), + 'value' => htmlspecialchars($hdr_val) + ); + } + } + + if (!empty($conf['print']['add_printedby'])) { + $user_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp')); + $headers[] = array( + 'header' => htmlspecialchars(_("Printed By")), + 'value' => htmlspecialchars($user_identity->getFullname() ? $user_identity->getFullname() : Horde_Auth::getAuth()) + ); + } + + $t = $injector->createInstance('Horde_Template'); + $t->set('css', Horde_Util::bufferOutput(array('Horde', 'includeStylesheetFiles'))); + + $t->set('headers', $headers); + + echo $t->fetch(IMP_TEMPLATES . '/print/headers.html'); + break; + } + break; + +default: + $self_url = Horde::selfUrl(true, true); + $t = $injector->createInstance('Horde_Template'); + $t->set('headers', $self_url->copy()->add('mode', 'headers')); + $t->set('content', $self_url->copy()->add('mode', 'content')); + echo $t->fetch(IMP_TEMPLATES . '/print/print.html'); + break; +} diff --git a/imp/templates/print/headers.html b/imp/templates/print/headers.html new file mode 100644 index 000000000..61021913a --- /dev/null +++ b/imp/templates/print/headers.html @@ -0,0 +1,12 @@ + + + + + +
+ +
:
+
+
+ + diff --git a/imp/templates/print/print.html b/imp/templates/print/print.html new file mode 100644 index 000000000..29c8e59b0 --- /dev/null +++ b/imp/templates/print/print.html @@ -0,0 +1,8 @@ + + + + + + + + -- 2.11.0