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