Overview

Packages

  • IMP
  • None

Classes

  • IMP
  • IMP_Ajax_Application
  • IMP_Ajax_Imple_ContactAutoCompleter
  • IMP_Ajax_Imple_PassphraseDialog
  • IMP_Ajax_Queue
  • IMP_Api
  • IMP_Auth
  • IMP_Block_Newmail
  • IMP_Block_Summary
  • IMP_Compose
  • IMP_Compose_Exception
  • IMP_Compose_Stationery
  • IMP_Contents
  • IMP_Crypt_Pgp
  • IMP_Crypt_Smime
  • IMP_Dimp
  • IMP_Exception
  • IMP_Factory_AuthImap
  • IMP_Factory_Compose
  • IMP_Factory_Contents
  • IMP_Factory_Flags
  • IMP_Factory_Identity
  • IMP_Factory_Imap
  • IMP_Factory_Imaptree
  • IMP_Factory_Mail
  • IMP_Factory_Mailbox
  • IMP_Factory_MailboxList
  • IMP_Factory_MimeViewer
  • IMP_Factory_Pgp
  • IMP_Factory_Quota
  • IMP_Factory_Search
  • IMP_Factory_Sentmail
  • IMP_Factory_Smime
  • IMP_Filter
  • IMP_Flag_Base
  • IMP_Flag_Imap
  • IMP_Flag_Imap_Answered
  • IMP_Flag_Imap_Deleted
  • IMP_Flag_Imap_Draft
  • IMP_Flag_Imap_Flagged
  • IMP_Flag_Imap_Forwarded
  • IMP_Flag_Imap_Junk
  • IMP_Flag_Imap_NotJunk
  • IMP_Flag_Imap_Seen
  • IMP_Flag_System_Attachment
  • IMP_Flag_System_Encrypted
  • IMP_Flag_System_HighPriority
  • IMP_Flag_System_List
  • IMP_Flag_System_LowPriority
  • IMP_Flag_System_Match_Address
  • IMP_Flag_System_Match_Flag
  • IMP_Flag_System_Match_Header
  • IMP_Flag_System_Personal
  • IMP_Flag_System_Signed
  • IMP_Flag_System_Unseen
  • IMP_Flag_User
  • IMP_Flags
  • IMP_Imap
  • IMP_Imap_Acl
  • IMP_Imap_Exception
  • IMP_Imap_PermanentFlags
  • IMP_Imap_Thread
  • IMP_Imap_Tree
  • IMP_Indices
  • IMP_Indices_Form
  • IMP_LoginTasks_SystemTask_GarbageCollection
  • IMP_LoginTasks_SystemTask_Upgrade
  • IMP_LoginTasks_SystemTask_UpgradeAuth
  • IMP_LoginTasks_Task_Autocreate
  • IMP_LoginTasks_Task_DeleteAttachmentsMonthly
  • IMP_LoginTasks_Task_DeleteSentmailMonthly
  • IMP_LoginTasks_Task_FilterOnLogin
  • IMP_LoginTasks_Task_PurgeSentmail
  • IMP_LoginTasks_Task_PurgeSpam
  • IMP_LoginTasks_Task_PurgeTrash
  • IMP_LoginTasks_Task_RecoverDraft
  • IMP_LoginTasks_Task_RenameSentmailMonthly
  • IMP_Mailbox
  • IMP_Mailbox_List
  • IMP_Mailbox_List_Track
  • IMP_Maillog
  • IMP_Menu_Dimp
  • IMP_Message
  • IMP_Mime_Status
  • IMP_Mime_Viewer_Alternative
  • IMP_Mime_Viewer_Appledouble
  • IMP_Mime_Viewer_Audio
  • IMP_Mime_Viewer_Enriched
  • IMP_Mime_Viewer_Externalbody
  • IMP_Mime_Viewer_Html
  • IMP_Mime_Viewer_Images
  • IMP_Mime_Viewer_Itip
  • IMP_Mime_Viewer_Mdn
  • IMP_Mime_Viewer_Partial
  • IMP_Mime_Viewer_Pdf
  • IMP_Mime_Viewer_Pgp
  • IMP_Mime_Viewer_Plain
  • IMP_Mime_Viewer_Related
  • IMP_Mime_Viewer_Rfc822
  • IMP_Mime_Viewer_Smil
  • IMP_Mime_Viewer_Smime
  • IMP_Mime_Viewer_Status
  • IMP_Mime_Viewer_Vcard
  • IMP_Mime_Viewer_Video
  • IMP_Mime_Viewer_Zip
  • IMP_Notification_Event_Status
  • IMP_Notification_Handler_Decorator_ImapAlerts
  • IMP_Notification_Handler_Decorator_NewmailNotify
  • IMP_Notification_Listener_AjaxStatus
  • Imp_Prefs_Identity
  • IMP_Prefs_Ui
  • IMP_Quota
  • IMP_Quota_Base
  • IMP_Quota_Command
  • IMP_Quota_Hook
  • IMP_Quota_Imap
  • IMP_Quota_Maildir
  • IMP_Quota_Mdaemon
  • IMP_Quota_Mercury32
  • IMP_Quota_Null
  • IMP_Quota_Sql
  • IMP_Search
  • IMP_Search_Element
  • IMP_Search_Element_Attachment
  • IMP_Search_Element_Autogenerated
  • IMP_Search_Element_Bulk
  • IMP_Search_Element_Contacts
  • IMP_Search_Element_Date
  • IMP_Search_Element_Flag
  • IMP_Search_Element_Header
  • IMP_Search_Element_Mailinglist
  • IMP_Search_Element_Or
  • IMP_Search_Element_Personal
  • IMP_Search_Element_Recipient
  • IMP_Search_Element_Size
  • IMP_Search_Element_Text
  • IMP_Search_Element_Within
  • IMP_Search_Filter
  • IMP_Search_Filter_Attachment
  • IMP_Search_Filter_Autogenerated
  • IMP_Search_Filter_Builtin
  • IMP_Search_Filter_Bulk
  • IMP_Search_Filter_Contacts
  • IMP_Search_Filter_Mailinglist
  • IMP_Search_Filter_Personal
  • IMP_Search_Query
  • IMP_Search_Vfolder
  • IMP_Search_Vfolder_Builtin
  • IMP_Search_Vfolder_Vinbox
  • IMP_Search_Vfolder_Vtrash
  • IMP_Sentmail
  • IMP_Sentmail_Base
  • IMP_Sentmail_Null
  • IMP_Sentmail_Sql
  • IMP_Spam
  • IMP_Test
  • IMP_Tree_Flist
  • IMP_Tree_Jquerymobile
  • IMP_Tree_Simplehtml
  • IMP_Ui_Compose
  • IMP_Ui_Editor
  • IMP_Ui_Folder
  • IMP_Ui_Headers
  • IMP_Ui_Imageview
  • IMP_Ui_Mailbox
  • IMP_Ui_Message
  • IMP_Ui_Mimp
  • IMP_Ui_Search
  • IMP_Views_Compose
  • IMP_Views_ListMessages
  • IMP_Views_ShowMessage
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * The IMP_Mime_Viewer_Images class allows display of images attached
  4:  * to a message.
  5:  *
  6:  * Copyright 2002-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file COPYING for license information (GPL). If you
  9:  * did not receive this file, see http://www.horde.org/licenses/gpl.
 10:  *
 11:  * @author   Michael Slusarz <slusarz@horde.org>
 12:  * @category Horde
 13:  * @license  http://www.horde.org/licenses/gpl GPL
 14:  * @package  IMP
 15:  */
 16: class IMP_Mime_Viewer_Images extends Horde_Mime_Viewer_Images
 17: {
 18:     /**
 19:      * This driver's display capabilities.
 20:      *
 21:      * @var array
 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:             /* Only display raw images we know the browser supports, and we
 40:              * know can't cause any sort of security issue. */
 41:             if ($browser->isViewable($this->_getType())) {
 42:                 return true;
 43:             }
 44:             break;
 45: 
 46:         case 'inline':
 47:             /* For minimal view: allow rendering of attachments inline (on the
 48:              * view parts page). */
 49:             if (IMP::getViewMode() == 'mimp') {
 50:                 return true;
 51:             }
 52:             break;
 53:         }
 54: 
 55:         return parent::canRender($mode);
 56:     }
 57: 
 58:     /**
 59:      * Return the full rendered version of the Horde_Mime_Part object.
 60:      *
 61:      * URL parameters used by this function:
 62:      * <pre>
 63:      * imp_img_view - (string) One of the following:
 64:      *   data - Output the image directly.
 65:      *   view_convert - Convert the image to browser-viewable format and
 66:      *                  display.
 67:      *   view_thumbnail - Create thumbnail and display.
 68:      * </pre>
 69:      *
 70:      * @return array  See parent::render().
 71:      */
 72:     protected function _render()
 73:     {
 74:         switch (Horde_Util::getFormData('imp_img_view')) {
 75:         case 'data':
 76:             /* If calling page is asking us to output data, do that without
 77:              * any further delay and exit. */
 78:             return parent::_render();
 79: 
 80:         case 'view_convert':
 81:             /* Convert image to browser-viewable format and display. */
 82:             return $this->_viewConvert(false);
 83: 
 84:         case 'view_thumbnail':
 85:             /* Create thumbnail and display. */
 86:             return $this->_viewConvert(true);
 87: 
 88:         default:
 89:             return parent::_render();
 90:         }
 91:     }
 92: 
 93:     /**
 94:      * Return the rendered inline version of the Horde_Mime_Part object.
 95:      *
 96:      * @return array  See parent::render().
 97:      */
 98:     protected function _renderInline()
 99:     {
100:         /* Only display the image inline if the browser can display it and the
101:          * size of the image is below the config value. */
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:                 /* For mimp - allow rendering of attachments inline (on the
109:                  * view parts page). */
110:                 $showimg = (IMP::getViewMode() == 'mimp');
111:             }
112: 
113:             if (!$showimg) {
114:                 return $this->_renderInfo();
115:             }
116: 
117:             /* Viewing inline, and the browser can handle the image type
118:              * directly. So output an <img> tag to load the image. */
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:         /* The browser cannot view this image. Inform the user of this and
128:          * ask user if we should convert to another image type. */
129:         $status = new IMP_Mime_Status(_("Your browser does not support inline display of this image type."));
130: 
131:         /* See if we can convert to an inline browser viewable form. */
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:      * Return the rendered information about the Horde_Mime_Part object.
152:      *
153:      * @return array  See parent::render().
154:      */
155:     protected function _renderInfo()
156:     {
157:         /* Check to see if convert utility is available. */
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:      * Return the full rendered version of the Horde_Mime_Part object.
182:      *
183:      * @return array  See parent::render().
184:      */
185:     protected function _renderRaw()
186:     {
187:         return parent::_render();
188:     }
189: 
190:     /**
191:      * Convert image.
192:      *
193:      * @param boolean $thumb  View image in thumbnail size?
194:      *
195:      * @return string  The image data.
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:      * Return a Horde_Image object.
230:      *
231:      * @param boolean $load  Whether to load the image data.
232:      *
233:      * @return mixed  The Horde_Image object, or false on error.
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:      * Output an image tag.
251:      *
252:      * @param string $type  The view type.
253:      * @param string $alt   The ALT text.
254:      *
255:      * @return string  An image tag.
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: 
API documentation generated by ApiGen