1: <?php
 2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 
13: 
14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 
24: class IMP_Mime_Viewer_Vcard extends Horde_Core_Mime_Viewer_Vcard
25: {
26:     27: 28: 29: 30: 
31:     protected $_metadata = array(
32:         'compressed' => false,
33:         'embedded' => false,
34:         'forceinline' => true
35:     );
36: 
37:     38: 39: 40: 41: 42: 43: 44: 45: 46: 
47:     protected function _renderInline()
48:     {
49:         $vars = $GLOBALS['injector']->getInstance('Horde_Variables');
50: 
51:         if (!isset($vars->p)) {
52:             $imp_contents = $this->getConfigParam('imp_contents');
53: 
54:             $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('IMP_Ajax_Imple_VcardImport', array(
55:                 'mime_id' => $this->_mimepart->getMimeId(),
56:                 'muid' => strval($imp_contents->getIndicesOb())
57:             ));
58:             $this->_imageUrl = $this->getConfigParam('imp_contents')->urlView($this->_mimepart, 'download_render', array('params' => array('mode' => IMP_Contents::RENDER_INLINE)));
59:             return parent::_renderInline();
60:         }
61: 
62:         
63:         $data = $this->_mimepart->getContents();
64:         $ical = new Horde_Icalendar();
65:         if (!$ical->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) {
66:             
67:             return array();
68:         }
69:         $components = $ical->getComponents();
70:         if (!isset($components[$vars->c])) {
71:             
72:             return array();
73:         }
74:         $name = $components[$vars->c]->getAttributeDefault('FN', false);
75:         if ($name === false) {
76:             $name = $components[$vars->c]->printableName();
77:         }
78:         if (empty($name)) {
79:             $name = preg_replace('/\..*?$/', '', $this->_mimepart->getName());
80:         }
81: 
82:         $photos = $components[$vars->c]->getAllAttributes('PHOTO');
83:         if (!isset($photos[$vars->p])) {
84:             
85:             return array();
86:         }
87:         $type = 'image/' . Horde_String::lower($photos[$vars->p]['params']['TYPE']);
88:         return array(
89:             $this->_mimepart->getMimeId() => array(
90:                 'data' => base64_decode($photos[$vars->p]['value']),
91:                 'name' => $name . '.' . Horde_Mime_Magic::mimeToExt($type),
92:                 'type' => $type,
93:             )
94:         );
95:     }
96: 
97: }
98: