[ Index ] |
|
Code source de IMP H3 (4.1.5) |
1 <?php 2 /** 3 * The IMP_MIME_Viewer_alternative class renders out messages from 4 * multipart/alternative content types. 5 * 6 * $Horde: imp/lib/MIME/Viewer/alternative.php,v 1.45.10.8 2007/01/02 13:55:00 jan Exp $ 7 * 8 * Copyright 2002-2007 Michael Slusarz <slusarz@bigworm.colorado.edu> 9 * 10 * See the enclosed file COPYING for license information (GPL). If you 11 * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. 12 * 13 * @author Michael Slusarz <slusarz@bigworm.colorado.edu> 14 * @since IMP 4.0 15 * @package Horde_MIME_Viewer 16 */ 17 class IMP_MIME_Viewer_alternative extends MIME_Viewer { 18 19 /** 20 * The content-type of the preferred part. 21 * Default: application/octet-stream 22 * 23 * @var string 24 */ 25 var $_contentType = 'application/octet-stream'; 26 27 /** 28 * The alternative ID for this part. 29 * 30 * @var string 31 */ 32 var $_altID = '-'; 33 34 /** 35 * Render out the currently set contents. 36 * 37 * @param array $params An array with a reference to a MIME_Contents 38 * object. 39 * 40 * @return string The rendered text in HTML. 41 */ 42 function render($params) 43 { 44 $contents = &$params[0]; 45 46 $display = array(); 47 $display_id = null; 48 $partList = $this->mime_part->getParts(); 49 50 /* Default: Nothing displayed. */ 51 $text = null; 52 53 /* We need to override the MIME key to ensure that only one 54 alternative part is displayed. */ 55 $this->_getAltID($contents, $partList); 56 57 /* Now we need to remove any multipart/mixed entries that may be 58 present in the parts list, since they are simple containers 59 for parts. */ 60 $partList = $this->_removeMultipartMixed($partList); 61 62 /* RFC 2046: We show the LAST choice that can be displayed inline. */ 63 foreach ($partList as $part) { 64 if ($contents->canDisplayInline($part)) { 65 $display_list[] = $part; 66 } 67 } 68 69 /* We need to set the summary here if we have a display part. */ 70 if (!empty($display_list)) { 71 while (!empty($display_list)) { 72 $display = array_pop($display_list); 73 $text = $contents->renderMIMEPart($display); 74 if (!empty($text)) { 75 $this->_contentType = $display->getType(); 76 $contents->setSummary($display, 'part'); 77 $display_id = $display->getMIMEId(); 78 break; 79 } 80 } 81 } 82 83 /* Show links to alternative parts. */ 84 if (is_null($text) || (count($partList) > 1)) { 85 if (is_null($text)) { 86 $text = '<em>' . _("There are no alternative parts that can be displayed inline.") . '</em>'; 87 } 88 89 /* Generate the list of summaries to use. */ 90 $summaryList = array(); 91 foreach ($partList as $part) { 92 $id = $part->getMIMEId(); 93 if ($id && (is_null($display) || ($id != $display_id))) { 94 $summary = $contents->partSummary($part); 95 96 /* We don't want to show the MIME ID for alt parts. */ 97 if (!empty($summary)) { 98 array_splice($summary, 1, 1); 99 $summaryList[] = $summary; 100 } 101 } 102 } 103 104 /* Make sure there is at least one summary before showing the 105 alternative parts. */ 106 if (!empty($summaryList) && 107 !$contents->viewAsAttachment() && 108 $this->getConfigParam('show')) { 109 $status_array = array(); 110 $status = _("Alternative parts for this section:"); 111 if ($contents->showSummaryLinks()) { 112 $status .= ' ' . Help::link('imp', 'alternative-msg'); 113 } 114 $status_array[] = $status; 115 $status = '<table border="0" cellspacing="1" cellpadding="1">'; 116 foreach ($summaryList as $summary) { 117 $status .= '<tr valign="middle">'; 118 foreach ($summary as $val) { 119 if (!empty($val)) { 120 $status .= "<td>$val </td>\n"; 121 } 122 } 123 $status .= "</tr>\n"; 124 } 125 $status .= '</table>'; 126 $status_array[] = $status; 127 $text = $contents->formatStatusMsg($status_array, Horde::img('mime/binary.png', _("Multipart/alternative"), null, $GLOBALS['registry']->getImageDir('horde')), false) . $text; 128 } 129 } 130 131 /* No longer force the alternative MIME ID for IMP_Contents methods. */ 132 if (!empty($this->_altID)) { 133 $contents->setMIMEKeyOverride(); 134 } 135 136 return $text; 137 } 138 139 /** 140 * Determine the alternative ID 141 * 142 * @access private 143 * 144 * @param MIME_Contents &$contents A MIME_Contents object. 145 * @param array &$partList The list of parts in this alternative 146 * section. 147 */ 148 function _getAltID(&$contents, &$partList) 149 { 150 $altID = null; 151 $override = $contents->getMIMEKeyOverride(); 152 153 if (is_null($override)) { 154 $altID = $this->mime_part->getInformation('alternative'); 155 if ($altID === false) { 156 foreach ($partList as $part) { 157 $altID = $part->getInformation('alternative'); 158 if ($altID !== false) { 159 break; 160 } 161 } 162 } 163 } 164 165 if ($altID !== false) { 166 $contents->setMIMEKeyOverride($altID); 167 $this->_altID = $altID; 168 } 169 } 170 171 /** 172 * Remove multipart/mixed entries from an array of MIME_Parts and replace 173 * with the contents of that part. 174 * 175 * @access private 176 * 177 * @param array $list A list of MIME_Part objects. 178 * 179 * @return array The list of objects with multipart/mixed parts removed. 180 */ 181 function _removeMultipartMixed($list) 182 { 183 $output = array(); 184 185 foreach ($list as $part) { 186 $output = array_merge($output, ($part->getType() == 'multipart/mixed') ? $this->_removeMultipartMixed($part->getParts()) : array($part)); 187 } 188 189 return $output; 190 } 191 192 /** 193 * Return the content-type. 194 * 195 * @return string The content-type of the message. 196 * Returns 'application/octet-stream' until actual 197 * content type of the message can be determined. 198 */ 199 function getType() 200 { 201 return $this->_contentType; 202 } 203 204 }
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 |
![]() |