[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 3 require_once 'Horde/MIME/Viewer/images.php'; 4 5 /** 6 * The IMP_MIME_Viewer_images class allows images to be displayed 7 * inline in a message. 8 * 9 * $Horde: imp/lib/MIME/Viewer/images.php,v 1.43.10.20 2007/01/02 13:55:00 jan Exp $ 10 * 11 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 12 * 13 * See the enclosed file COPYING for license information (GPL). If you 14 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 15 * 16 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 17 * @since IMP 3.2 18 * @package Horde_MIME_Viewer 19 */ 20 class IMP_MIME_Viewer_images extends MIME_Viewer_images { 21 22 /** 23 * The content-type of the generated data. 24 * 25 * @var string 26 */ 27 var $_contentType; 28 29 /** 30 * Render out the currently set contents. 31 * 32 * @param array $params An array with a reference to a MIME_Contents 33 * object. 34 * 35 * @return string The rendered information. 36 */ 37 function render($params) 38 { 39 $contents = $params[0]; 40 41 global $browser; 42 43 /* If calling page is asking us to output data, do that without any 44 * further delay and exit. */ 45 if (Util::getFormData('img_data')) { 46 $this->_contentType = parent::getType(); 47 return parent::render(); 48 } 49 50 /* Convert the image to browser-viewable format and display. */ 51 if (Util::getFormData('images_view_convert')) { 52 return $this->_viewConvert(); 53 } 54 55 /* Create the thumbnail and display. */ 56 if (Util::getFormData('images_view_thumbnail')) { 57 return $this->_viewConvert(true); 58 } 59 60 /* This page has been called with the thumbnail parameter. See if we 61 * can convert to an inline browser viewable form. */ 62 if (Util::getFormData('view_thumbnail')) { 63 $img = $this->_getHordeImageOb(); 64 if ($img) { 65 return $this->_popupImageWindow(); 66 } else { 67 return $contents->formatStatusMsg(_("The server was not able to create a thumbnail of this image.")); 68 } 69 } 70 71 if (Util::getFormData('images_load_convert')) { 72 return $this->_popupImageWindow(); 73 } 74 75 if ($contents->viewAsAttachment()) { 76 if (!$browser->hasFeature('javascript') || 77 !$contents->viewAsAttachment(true)) { 78 /* If either: 79 + The browser doesn't support javascript 80 + We are not viewing in a popup window 81 Then simply render the image data. */ 82 $this->_contentType = parent::getType(); 83 return parent::render(); 84 } elseif ($browser->isViewable(parent::getType())) { 85 /* The browser can display the image type directly - just 86 output the javascript code to render the auto resize popup 87 image window. */ 88 return $this->_popupImageWindow(); 89 } 90 } 91 92 if ($browser->isViewable($this->mime_part->getType())) { 93 /* If we are viewing inline, and the browser can handle the image 94 type directly, output an <img> tag to load the image. */ 95 $alt = $this->mime_part->getName(false, true); 96 return Horde::img($contents->urlView($this->mime_part, 'view_attach'), $alt, null, ''); 97 } else { 98 /* If we have made it this far, than the browser cannot view this 99 image inline. Inform the user of this and, possibly, ask user 100 if we should convert to another image type. */ 101 $msg = _("Your browser does not support inline display of this image type."); 102 103 if ($contents->viewAsAttachment()) { 104 $msg .= '<br />' . sprintf(_("Click %s to download the image."), $contents->linkView($this->mime_part, 'download_attach', _("HERE"), array('viewparams' => array('img_data' => 1)), true)); 105 } 106 107 /* See if we can convert to an inline browser viewable form. */ 108 $img = $this->_getHordeImageOb(); 109 if ($img && $browser->isViewable($img->getContentType())) { 110 if ($contents->viewAsAttachment()) { 111 $convert_link = Horde::link($contents->urlView($this->mime_part, 'view_attach', array('images_load_convert' => 1, 'popup_view' => 1))) . _("HERE") . '</a>'; 112 } else { 113 $convert_link = $contents->linkViewJS($this->mime_part, 'view_attach', _("HERE"), null, null, array('images_load_convert' => 1)); 114 } 115 $msg .= '<br />' . sprintf(_("Click %s to convert the image file into a format your browser can view."), $convert_link); 116 } 117 118 return $contents->formatStatusMsg($msg); 119 } 120 } 121 122 /** 123 * Return the content-type 124 * 125 * @return string The content-type of the output. 126 */ 127 function getType() 128 { 129 if ($this->_contentType) { 130 return $this->_contentType; 131 } else { 132 return 'text/html; charset=' . NLS::getCharset(); 133 } 134 } 135 136 /** 137 * Render out attachment information. 138 * 139 * @param array $params An array with a reference to a MIME_Contents 140 * object. 141 * 142 * @return string The rendered text in HTML. 143 */ 144 function renderAttachmentInfo($params) 145 { 146 $contents = &$params[0]; 147 148 /* Display the thumbnail link only if size is greater than 50 KB and 149 there is an image conversion utility available. */ 150 if ($this->mime_part->getBytes() < 51200) { 151 return ''; 152 } 153 154 if (is_a($contents, 'IMP_Contents')) { 155 $this->mime_part = &$contents->getDecodedMIMEPart($this->mime_part->getMIMEId(), true); 156 } 157 158 if (!$this->_getHordeImageOb()) { 159 return ''; 160 } 161 162 $status = array( 163 sprintf(_("A large image named %s is attached to this message."), $this->mime_part->getName(true)), 164 sprintf(_("Click %s to view a thumbnail of this image."), $contents->linkViewJS($this->mime_part, 'view_attach', _("HERE"), _("View Thumbnail"), null, array('view_thumbnail' => 1))) 165 ); 166 return $contents->formatStatusMsg($status, Horde::img('mime/image.png', _("View Thumbnail"), null, $GLOBALS['registry']->getImageDir('horde'))); 167 } 168 169 /** 170 * Generate the HTML output for the JS auto-resize view window. 171 * 172 * @access private 173 * 174 * @return string The HTML output. 175 */ 176 function _popupImageWindow() 177 { 178 $params = $remove_params = array(); 179 if (Util::getFormData('view_thumbnail')) { 180 $params['images_view_thumbnail'] = 1; 181 $remove_params[] = 'view_thumbnail'; 182 } elseif (Util::getFormData('images_load_convert')) { 183 $params['images_view_convert'] = 1; 184 $remove_params[] = 'images_load_convert'; 185 } else { 186 $params['img_data'] = 1; 187 } 188 $self_url = Util::addParameter(Util::removeParameter(Horde::selfUrl(true), $remove_params), $params); 189 $title = MIME::decode($this->mime_part->getName(false, true)); 190 return parent::_popupImageWindow($self_url, $title); 191 } 192 193 /** 194 * View thumbnail sized image. 195 * 196 * @access private 197 * 198 * @param boolean $thumb View thumbnail size? 199 * 200 * @return string The image data. 201 */ 202 function _viewConvert($thumb = false) 203 { 204 $mime = $this->mime_part; 205 $img = $this->_getHordeImageOb(); 206 207 if ($thumb) { 208 $img->resize(96, 96, true); 209 } 210 $mime->setType($img->getContentType()); 211 $mime->setContents($img->raw(true)); 212 213 $this->_contentType = $img->getContentType(); 214 215 return $mime->getContents(); 216 } 217 218 /** 219 * Return a Horde_Image object. 220 * 221 * @access private 222 * 223 * @return Horde_Image The requested object. 224 */ 225 function _getHordeImageOb() 226 { 227 include_once 'Horde/Image.php'; 228 $params = array('temp' => Horde::getTempdir()); 229 if (!empty($GLOBALS['conf']['image']['convert'])) { 230 $img = &Horde_Image::singleton('im', $params); 231 } elseif (Util::extensionExists('gd')) { 232 $img = &Horde_Image::singleton('gd', $params); 233 } else { 234 return false; 235 } 236 237 if (is_a($img, 'PEAR_Error')) { 238 return false; 239 } 240 241 $ret = $img->loadString(1, $this->mime_part->getContents()); 242 if (is_a($ret, 'PEAR_Error')) { 243 return false; 244 } 245 246 return $img; 247 } 248 249 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 12:30:07 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |