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_Contents_InlineOutput
24: {
25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45:
46: public function getInlineOutput(IMP_Contents $contents,
47: array $options = array())
48: {
49: global $prefs, $registry;
50:
51: $atc_parts = $display_ids = $metadata = $msgtext = $wrap_ids = array();
52: $parts_list = $contents->getContentTypeMap();
53: $text_out = '';
54: $view = $registry->getView();
55:
56: $contents_mask = isset($options['mask'])
57: ? $options['mask']
58: : 0;
59: $display_mask = isset($options['display_mask'])
60: ? $options['display_mask']
61: : $contents::RENDER_INLINE_AUTO;
62: $no_inline_all = !empty($options['no_inline_all']);
63: $part_info_display = isset($options['part_info_display'])
64: ? $options['part_info_display']
65: : array();
66: $show_parts = isset($options['show_parts'])
67: ? $options['show_parts']
68: : $prefs->getValue('parts_display');
69:
70: foreach ($parts_list as $mime_id => $mime_type) {
71: if (isset($display_ids[$mime_id]) ||
72: isset($atc_parts[$mime_id])) {
73: continue;
74: }
75:
76: if (!($render_mode = $contents->canDisplay($mime_id, $display_mask))) {
77: if ($contents->isAttachment($mime_type)) {
78: if ($show_parts == 'atc') {
79: $atc_parts[$mime_id] = 1;
80: }
81:
82: if ($contents_mask) {
83: $msgtext[$mime_id] = array(
84: 'text' => $this->_formatSummary($contents, $mime_id, $contents_mask, $part_info_display, true)
85: );
86: }
87: }
88: continue;
89: }
90:
91: $render_part = $contents->renderMIMEPart($mime_id, $render_mode);
92: if (($show_parts == 'atc') &&
93: $contents->isAttachment($mime_type) &&
94: (empty($render_part) ||
95: !($render_mode & $contents::RENDER_INLINE))) {
96: $atc_parts[$mime_id] = 1;
97: }
98:
99: if (empty($render_part)) {
100: if ($contents_mask &&
101: $contents->isAttachment($mime_type)) {
102: $msgtext[$mime_id] = array(
103: 'text' => $this->_formatSummary($contents, $mime_id, $contents_mask, $part_info_display, true)
104: );
105: }
106: continue;
107: }
108:
109: reset($render_part);
110: while (list($id, $info) = each($render_part)) {
111: $display_ids[$id] = 1;
112:
113: if (empty($info)) {
114: continue;
115: }
116:
117: if ($no_inline_all === 1) {
118: $atc_parts[$id] = 1;
119: continue;
120: }
121:
122: $part_text = ($contents_mask && empty($info['nosummary']))
123: ? $this->_formatSummary($contents, $id, $contents_mask, $part_info_display, !empty($info['attach']))
124: : '';
125:
126: if (empty($info['attach'])) {
127: if (isset($info['status'])) {
128: if (!is_array($info['status'])) {
129: $info['status'] = array($info['status']);
130: }
131:
132: $render_issues = array();
133:
134: foreach ($info['status'] as $val) {
135: if (in_array($view, $val->views)) {
136: if ($val instanceof IMP_Mime_Status_RenderIssue) {
137: $render_issues[] = $val;
138: } else {
139: $part_text .= strval($val);
140: }
141: }
142: }
143:
144: if (!empty($render_issues)) {
145: $render_issues_ob = new IMP_Mime_Status_RenderIssue_Display();
146: $render_issues_ob->addIssues($render_issues);
147: $part_text .= strval($render_issues_ob);
148: }
149: }
150:
151: $part_text .= '<div class="mimePartData">' . $info['data'] . '</div>';
152: } elseif ($show_parts == 'atc') {
153: $atc_parts[$id] = 1;
154: }
155:
156: $msgtext[$id] = array(
157: 'text' => $part_text,
158: 'wrap' => empty($info['wrap']) ? null : $info['wrap']
159: );
160:
161: if (isset($info['metadata'])) {
162:
163: $metadata = array_merge($metadata, $info['metadata']);
164: }
165:
166: if ($no_inline_all) {
167: $no_inline_all = 1;
168: }
169: }
170: }
171:
172: if (!empty($msgtext)) {
173: uksort($msgtext, 'strnatcmp');
174: }
175:
176: reset($msgtext);
177: while (list($id, $part) = each($msgtext)) {
178: while (!empty($wrap_ids)) {
179: $id_ob = new Horde_Mime_Id(end($wrap_ids));
180: if ($id_ob->isChild($id)) {
181: break;
182: }
183: array_pop($wrap_ids);
184: $text_out .= '</div>';
185: }
186:
187: if (!empty($part['wrap'])) {
188: $text_out .= '<div class="' . $part['wrap'] . '">';
189: $wrap_ids[] = $id;
190: }
191:
192: $text_out .= '<div class="mimePartBase">' . $part['text'] . '</div>';
193: }
194:
195: $text_out .= str_repeat('</div>', count($wrap_ids));
196:
197: if (!strlen($text_out)) {
198: $text_out = strval(new IMP_Mime_Status(_("There are no parts that can be shown inline.")));
199: }
200:
201: $atc_parts = ($show_parts == 'all')
202: ? array_keys($parts_list)
203: : array_keys($atc_parts);
204:
205: return array(
206: 'atc_parts' => $atc_parts,
207: 'display_ids' => array_keys($display_ids),
208: 'metadata' => $metadata,
209: 'msgtext' => $text_out,
210: 'one_part' => (count($parts_list) == 1)
211: );
212: }
213:
214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225:
226: protected function _formatSummary(IMP_Contents $contents, $id, $mask,
227: $display, $atc = false)
228: {
229: $summary = $contents->getSummary($id, $mask);
230: $tmp_summary = array();
231:
232: foreach ($display as $val) {
233: if (isset($summary[$val])) {
234: switch ($val) {
235: case 'description':
236: $summary[$val] = '<span class="mimePartInfoDescrip">' . $summary[$val] . '</span>';
237: break;
238:
239: case 'size':
240: $summary[$val] = '<span class="mimePartInfoSize">(' . $summary[$val] . ')</span>';
241: break;
242: }
243: $tmp_summary[] = $summary[$val];
244: }
245: }
246:
247: return '<div class="mimePartInfo' .
248: ($atc ? ' mimePartInfoAtc' : '') .
249: '"><div>' .
250: implode(' ', $tmp_summary) .
251: '</div></div>';
252: }
253:
254: }
255: