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