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_Related extends Horde_Mime_Viewer_Base
24: {
25: 26:
27: protected $_capability = array(
28: 'full' => true,
29: 'info' => false,
30: 'inline' => true,
31: 'raw' => false
32: );
33:
34: 35:
36: protected $_metadata = array(
37: 'compressed' => false,
38: 'embedded' => false,
39: 'forceinline' => true
40: );
41:
42: 43: 44: 45: 46:
47: protected $_related;
48:
49: 50:
51: protected function _render()
52: {
53: return $this->_IMPrender(false);
54: }
55:
56: 57:
58: protected function _renderInline()
59: {
60: return $this->_IMPrender(true);
61: }
62:
63: 64: 65: 66: 67: 68: 69:
70: protected function _IMPrender($inline)
71: {
72: $related_id = $this->_mimepart->getMimeId();
73: $used = array($related_id);
74:
75: if (!($id = $this->_init($inline))) {
76: return array();
77: }
78:
79: $render = $this->getConfigParam('imp_contents')->renderMIMEPart($id, $inline ? IMP_Contents::RENDER_INLINE : IMP_Contents::RENDER_FULL);
80:
81: if (!$inline) {
82: foreach (array_keys($render) as $key) {
83: if (!is_null($render[$key])) {
84: return array($related_id => $render[$key]);
85: }
86: }
87: return null;
88: }
89:
90: $data_id = null;
91: $ret = array_fill_keys(array_keys($this->_mimepart->contentTypeMap()), null);
92:
93: foreach (array_keys($render) as $val) {
94: $ret[$val] = $render[$val];
95: if ($ret[$val]) {
96: $data_id = $val;
97: }
98: }
99:
100: if (!is_null($data_id)) {
101: $this->_mimepart->setMetadata('viewable_part', $data_id);
102:
103: 104: 105: 106: 107:
108: if ($data_id !== $related_id) {
109: $ret[$related_id] = $ret[$data_id];
110: $ret[$data_id] = null;
111: }
112: }
113:
114: 115:
116: if ($cids_used = $this->_mimepart->getMetadata('related_cids_used')) {
117: $used = array_merge($used, $cids_used);
118: }
119:
120: $id_ob = new Horde_Mime_Id($id);
121:
122: foreach (array_diff(array_keys($ret), $used) as $val) {
123: if (($val !== $id) && !$id_ob->isChild($val)) {
124: $summary = $this->getConfigParam('imp_contents')->getSummary(
125: $val,
126: IMP_Contents::SUMMARY_SIZE |
127: IMP_Contents::SUMMARY_ICON |
128: IMP_Contents::SUMMARY_DESCRIP_LINK |
129: IMP_Contents::SUMMARY_DOWNLOAD
130: );
131:
132: $status = new IMP_Mime_Status_RenderIssue(array(
133: _("This part contains an attachment that can not be displayed within this part:"),
134: implode(' ', array(
135: $summary['icon'],
136: $summary['description'],
137: $summary['size'],
138: $summary['download']
139: ))
140: ));
141: $status->action($status::WARNING);
142:
143: if (isset($ret[$related_id]['status'])) {
144: if (!is_array($ret[$related_id]['status'])) {
145: $ret[$related_id]['status'] = array($ret[$related_id]['status']);
146: }
147: } else {
148: $ret[$related_id]['status'] = array();
149: }
150: $ret[$related_id]['status'][] = $status;
151: }
152: }
153:
154: return $ret;
155: }
156:
157: 158: 159: 160: 161: 162: 163:
164: protected function _init($inline)
165: {
166: if (!isset($this->_related)) {
167: $this->_related = new Horde_Mime_Related($this->_mimepart);
168:
169:
170: $this->_mimepart->setMetadata('related_ob', $this->_related);
171: }
172:
173: $start_id = $this->_related->startId();
174:
175: 176:
177: return ($inline && !is_null($start_id) && !$this->getConfigParam('imp_contents')->canDisplay($start_id, IMP_Contents::RENDER_INLINE))
178: ? null
179: : $start_id;
180: }
181:
182: 183:
184: public function canRender($mode)
185: {
186: return (($mode == 'inline') && !$this->_init(true))
187: ? false
188: : parent::canRender($mode);
189: }
190:
191: }
192: