1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Mime_Viewer_Pdf extends Horde_Mime_Viewer_Pdf
24: {
25: 26: 27: 28: 29:
30: protected $_capability = array(
31: 'full' => true,
32: 'info' => true,
33: 'inline' => false,
34: 'raw' => false
35: );
36:
37: 38: 39: 40: 41: 42: 43: 44:
45: protected function _render()
46: {
47:
48: if (!$GLOBALS['injector']->getInstance('Horde_Variables')->pdf_view_thumbnail) {
49: return parent::_render();
50: }
51:
52: $img = $this->_getHordeImageOb(true);
53:
54: if ($img) {
55: $img->resize(150, 150, true);
56: $type = $img->getContentType();
57: $data = $img->raw(true);
58: }
59:
60: if (!$img || !$data) {
61: $type = 'image/png';
62: $img_ob = Horde_Themes::img('mini-error.png', 'imp');
63: $data = file_get_contents($img_ob->fs);
64: }
65:
66: return array(
67: $this->_mimepart->getMimeId() => array(
68: 'data' => $data,
69: 'type' => $type
70: )
71: );
72: }
73:
74: 75: 76: 77: 78:
79: protected function _renderInfo()
80: {
81:
82: if (!$this->_getHordeImageOb(false)) {
83: return array();
84: }
85:
86: $status = new IMP_Mime_Status(_("This is a thumbnail of a PDF file attachment."));
87: $status->icon('mime/image.png');
88:
89: switch ($GLOBALS['registry']->getView()) {
90: case Horde_Registry::VIEW_MINIMAL:
91: $status->addText(Horde::link($this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach')) . $this->_outputImgTag() . '</a>');
92: break;
93:
94: default:
95: $status->addText($this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', $this->_outputImgTag(), null, null, null));
96: break;
97: }
98:
99: return array(
100: $this->_mimepart->getMimeId() => array(
101: 'data' => '',
102: 'status' => $status,
103: 'type' => 'text/html; charset=' . $this->getConfigParam('charset')
104: )
105: );
106: }
107:
108: 109: 110: 111: 112: 113: 114:
115: protected function _getHordeImageOb($load)
116: {
117: if (!$this->getConfigParam('thumbnails')) {
118: return false;
119: }
120:
121: try {
122: $img = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Image')->create();
123: } catch (Horde_Exception $e) {
124: return false;
125: }
126: if (!$img->hasCapability('multipage') && !$img->hasCapability('pdf')) {
127: return false;
128: }
129:
130: if ($load) {
131: try {
132: $img->loadString($this->_mimepart->getContents());
133: } catch (Horde_Image_Exception $e) {
134: return false;
135: }
136: }
137:
138: try {
139: if ($img instanceof Horde_Image_Imagick) {
140:
141: $img->imagick->setImageBackgroundColor('white');
142: return $GLOBALS['injector']->getInstance('Horde_Core_Factory_Image')->create(array(
143: 'data' => $img->imagick->flattenImages()->getImageBlob()
144: ));
145: }
146:
147: return $img->getImageAtIndex(0);
148: } catch (Horde_Image_Exception $e) {
149: return false;
150: }
151: }
152:
153: 154: 155: 156: 157:
158: protected function _outputImgTag()
159: {
160: return '<img src="' . $this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach', array('params' => array('pdf_view_thumbnail' => 1)))->setRaw(false) . '" alt="' . htmlspecialchars(_("View PDF File"), ENT_COMPAT, $this->getConfigParam('charset')) . '" />';
161: }
162:
163: }
164: