1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class IMP_Mime_Viewer_Images extends Horde_Mime_Viewer_Images
17: {
18: 19: 20: 21: 22:
23: protected $_capability = array(
24: 'full' => false,
25: 'info' => true,
26: 'inline' => true,
27: 'raw' => false
28: );
29:
30: 31:
32: public function canRender($mode)
33: {
34: global $browser;
35:
36: switch ($mode) {
37: case 'full':
38: case 'raw':
39: 40:
41: if ($browser->isViewable($this->_getType())) {
42: return true;
43: }
44: break;
45:
46: case 'inline':
47: 48:
49: if (IMP::getViewMode() == 'mimp') {
50: return true;
51: }
52: break;
53: }
54:
55: return parent::canRender($mode);
56: }
57:
58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71:
72: protected function _render()
73: {
74: switch (Horde_Util::getFormData('imp_img_view')) {
75: case 'data':
76: 77:
78: return parent::_render();
79:
80: case 'view_convert':
81:
82: return $this->_viewConvert(false);
83:
84: case 'view_thumbnail':
85:
86: return $this->_viewConvert(true);
87:
88: default:
89: return parent::_render();
90: }
91: }
92:
93: 94: 95: 96: 97:
98: protected function _renderInline()
99: {
100: 101:
102: if ($GLOBALS['browser']->isViewable($this->_getType())) {
103: if (!isset($this->_conf['inlinesize']) ||
104: ($this->_mimepart->getBytes() < $this->_conf['inlinesize'])) {
105: $imgview = new IMP_Ui_Imageview();
106: $showimg = $imgview->showInlineImage($this->getConfigParam('imp_contents'));
107: } else {
108: 109:
110: $showimg = (IMP::getViewMode() == 'mimp');
111: }
112:
113: if (!$showimg) {
114: return $this->_renderInfo();
115: }
116:
117: 118:
119: return array(
120: $this->_mimepart->getMimeId() => array(
121: 'data' => $this->_outputImgTag('data', $this->_mimepart->getName(true)),
122: 'type' => 'text/html; charset=' . $this->getConfigParam('charset')
123: )
124: );
125: }
126:
127: 128:
129: $status = new IMP_Mime_Status(_("Your browser does not support inline display of this image type."));
130:
131:
132: if ($GLOBALS['browser']->hasFeature('javascript')) {
133: $img = $this->_getHordeImageOb(false);
134: if ($img &&
135: $GLOBALS['browser']->isViewable($img->getContentType())) {
136: $convert_link = $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("HERE"), array('params' => array('imp_img_view' => 'view_convert')));
137: $status->addText(sprintf(_("Click %s to convert the image file into a format your browser can attempt to view."), $convert_link));
138: }
139: }
140:
141: return array(
142: $this->_mimepart->getMimeId() => array(
143: 'data' => '',
144: 'status' => $status,
145: 'type' => 'text/html; charset=' . $this->getConfigParam('charset')
146: )
147: );
148: }
149:
150: 151: 152: 153: 154:
155: protected function _renderInfo()
156: {
157:
158: if (!$this->_getHordeImageOb(false)) {
159: return array();
160: }
161:
162: $status = new IMP_Mime_Status(_("This is a thumbnail of an image attachment."));
163: $status->icon('mime/image.png');
164:
165: if ($GLOBALS['browser']->hasFeature('javascript')) {
166: $status->addText($this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', $this->_outputImgTag('view_thumbnail', _("View Attachment")), null, null, null));
167: } else {
168: $status->addText(Horde::link($this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach')) . $this->_outputImgTag('view_thumbnail', _("View Attachment")) . '</a>');
169: }
170:
171: return array(
172: $this->_mimepart->getMimeId() => array(
173: 'data' => '',
174: 'status' => $status,
175: 'type' => 'text/html; charset=' . $this->getConfigParam('charset')
176: )
177: );
178: }
179:
180: 181: 182: 183: 184:
185: protected function _renderRaw()
186: {
187: return parent::_render();
188: }
189:
190: 191: 192: 193: 194: 195: 196:
197: protected function _viewConvert($thumb)
198: {
199: $img = $this->_getHordeImageOb(true);
200:
201: if ($img) {
202: if ($thumb) {
203: $dim = $img->getDimensions();
204: if (($dim['height'] > 96) || ($dim['width'] > 96)) {
205: $img->resize(96, 96, true);
206: }
207: }
208: $type = $img->getContentType();
209: try {
210: $data = $img->raw(true);
211: } catch (Exception $e) {}
212: }
213:
214: if (!$img || !$data) {
215: $type = 'image/png';
216: $img_ob = Horde_Themes::img('mini-error.png', 'imp');
217: $data = file_get_contents($img_ob->fs);
218: }
219:
220: return array(
221: $this->_mimepart->getMimeId() => array(
222: 'data' => $data,
223: 'type' => $type
224: )
225: );
226: }
227:
228: 229: 230: 231: 232: 233: 234:
235: protected function _getHordeImageOb($load)
236: {
237: try {
238: if (($img = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Image')->create()) && $load) {
239: $img->loadString($this->_mimepart->getContents());
240: }
241: return $img;
242: } catch (Horde_Exception $e) {
243: Horde::logMessage($e, 'DEBUG');
244: }
245:
246: return false;
247: }
248:
249: 250: 251: 252: 253: 254: 255: 256:
257: protected function _outputImgTag($type, $alt)
258: {
259: return '<img src="' . $this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'view_attach', array('params' => array('imp_img_view' => $type))) . '" alt="' . htmlspecialchars($alt, ENT_COMPAT, $this->getConfigParam('charset')) . '" />';
260: }
261:
262: }
263: