From: Michael M Slusarz Date: Tue, 11 Nov 2008 20:04:40 +0000 (-0700) Subject: Update PDF viewer. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6bf93afd9055a35e1e11e35cee8706e0cc6519da;p=horde.git Update PDF viewer. --- diff --git a/imp/lib/Mime/Viewer/pdf.php b/imp/lib/Mime/Viewer/pdf.php index 6ee5b36aa..1eecbf232 100644 --- a/imp/lib/Mime/Viewer/pdf.php +++ b/imp/lib/Mime/Viewer/pdf.php @@ -11,93 +11,86 @@ * @author Michael Slusarz * @package Horde_Mime_Viewer */ -class IMP_Horde_Mime_Viewer_pdf extends Horde_Mime_Viewer_Driver +class IMP_Horde_Mime_Viewer_pdf extends Horde_Mime_Viewer_pdf { /** - * The content-type of the generated data. + * Can this driver render various views? * - * @var string + * @var boolean */ - protected $_contentType; + protected $_capability = array( + 'embedded' => false, + 'full' => true, + 'info' => true, + 'inline' => false + ); /** - * Render out the currently set contents. + * Return the full rendered version of the Horde_Mime_Part object. * - * @param array $params An array with a reference to a MIME_Contents - * object. + * URL parameters used by this function: + *
+     * 'pdf_view_thumbnail' - (boolean) Output the thumbnail info.
+     * 
* - * @return string The rendered information. + * @return array See Horde_Mime_Viewer_Driver::render(). */ - public function render($params) + protected function _render() { /* Create the thumbnail and display. */ - if (Util::getFormData('images_view_thumbnail')) { - $mime = $this->mime_part; - $img = $this->_getHordeImageOb(); + if (!Util::getFormData('pdf_view_thumbnail')) { + return parent::_render(); + } - if ($img) { - $img->resize(96, 96, true); - $type = $img->getContentType(); - $data = $img->raw(true); - } + $img = $this->_getHordeImageOb(true); - if (!$img || !$data) { - $type = 'image/png'; - $data = file_get_contents(IMP_BASE . '/themes/graphics/mini-error.png'); - } - - $mime->setType($type); - $this->_contentType = $type; - $mime->setContents($data); + if ($img) { + $img->resize(96, 96, true); + $type = $img->getContentType(); + $data = $img->raw(true); + } - return $mime->getContents(); + if (!$img || !$data) { + $type = 'image/png'; + $data = file_get_contents(IMP_BASE . '/themes/graphics/mini-error.png'); } - return parent::render($params); + return array( + 'data' => $data, + 'type' => $type + ); } /** - * Render out attachment information. - * - * @param array $params An array with a reference to a MIME_Contents - * object. + * Return the rendered information about the Horde_Mime_Part object. * - * @return string The rendered text in HTML. + * @return array See Horde_Mime_Viewer_Driver::render(). */ - public function renderAttachmentInfo($params) + public function _renderInfo() { - $contents = &$params[0]; - - if (is_a($contents, 'IMP_Contents')) { - $this->mime_part = &$contents->getDecodedMIMEPart($this->mime_part->getMIMEId(), true); - } - /* Check to see if convert utility is available. */ if (!$this->_getHordeImageOb(false)) { - return ''; + return array(); } $status = array( - sprintf(_("A PDF file named %s is attached to this message. A thumbnail is below."), - $this->mime_part->getName(true)), + sprintf(_("A PDF file named %s is attached to this message. A thumbnail is below."), $this->_mimepart->getName(true)), ); - if (!$GLOBALS['browser']->hasFeature('javascript')) { - $status[] = Horde::link($contents->urlView($this->mime_part, - 'view_attach')) . - Horde::img($contents->urlView($this->mime_part, - 'view_attach', array('images_view_thumbnail' => 1), false), - _("View Attachment"), null, '') . ''; + if ($GLOBALS['browser']->hasFeature('javascript')) { + $status[] = $this->_params['contents']->linkViewJS($this->_mimepart, 'view_attach', Horde::img($this->_params['contents']->urlView($this->_mimepart, 'view_attach', array('params' => array('pdf_view_thumbnail' => 1)), false), _("View Attachment"), null, ''), null, null, null); } else { - $status[] = $contents->linkViewJS($this->mime_part, 'view_attach', - Horde::img($contents->urlView($this->mime_part, - 'view_attach', array('images_view_thumbnail' => 1), - false), _("View Attachment"), null, ''), null, null, - null); + $status[] = Horde::link($this->_params['contents']->urlView($this->_mimepart, 'view_attach')) . Horde::img($this->_params['contents']->urlView($this->_mimepart, 'view_attach', array('params' => array('pdf_view_thumbnail' => 1)), false), _("View Attachment"), null, '') . ''; } - return $this->formatStatusMsg($status, Horde::img('mime/image.png', - _("Thumbnail of attached PDF file"), null, $GLOBALS['registry']->getImageDir('horde')), false); + return array( + 'status' => array( + array( + 'icon' => Horde::img('mime/image.png', _("Thumbnail of attached PDF file")), + 'text' => $status + ) + ) + ); } /** @@ -105,22 +98,21 @@ class IMP_Horde_Mime_Viewer_pdf extends Horde_Mime_Viewer_Driver * * @param boolean $load Whether to load the image data. * - * @return Horde_Image The requested object. + * @return mixed The Hore_Image object, or false on error. */ - protected function _getHordeImageOb($load = true) + protected function _getHordeImageOb($load) { if (empty($GLOBALS['conf']['image']['convert'])) { return false; } - include_once 'Horde/Image.php'; $img = &Horde_Image::singleton('im', array('temp' => Horde::getTempdir())); if (is_a($img, 'PEAR_Error')) { return false; } if ($load) { - $ret = $img->loadString(1, $this->mime_part->getContents()); + $ret = $img->loadString(1, $this->_mimepart->getContents()); if (is_a($ret, 'PEAR_Error')) { return false; } @@ -128,14 +120,4 @@ class IMP_Horde_Mime_Viewer_pdf extends Horde_Mime_Viewer_Driver return $img; } - - /** - * Return the content-type - * - * @return string The content-type of the output. - */ - public function getType() - { - return ($this->_contentType) ? $this->_contentType : parent::getType(); - } }