);
/**
+ * URL that can be used as a callback for displaying images.
+ *
+ * @var Horde_Url
+ */
+ protected $_imageUrl;
+
+ /**
* Return the full rendered version of the Horde_Mime_Part object.
*
* @return array See Horde_Mime_Viewer_Driver::render().
$html .= '<table cellspacing="1" border="0" cellpadding="1">';
- $i = 0;
- foreach ($iCal->getComponents() as $vc) {
+ foreach ($iCal->getComponents() as $i => $vc) {
if ($i > 0) {
$html .= '<tr><td colspan="2"> </td></tr>';
}
- ++$i;
$html .= '<tr><td colspan="2" class="header">';
$fullname = $vc->getAttributeDefault('FN', false);
}
$photos = $vc->getAllAttributes('PHOTO');
- foreach ($photos as $photo) {
+ foreach ($photos as $p => $photo) {
if (isset($photo['params']['VALUE']) &&
Horde_String::upper($photo['params']['VALUE']) == 'URI') {
$html .= $this->_row(_("Photo"),
false);
} elseif (isset($photo['params']['ENCODING']) &&
Horde_String::upper($photo['params']['ENCODING']) == 'B' &&
- isset($photo['params']['TYPE']) &&
- ($GLOBALS['browser']->hasFeature('datauri') === true ||
- $GLOBALS['browser']->hasFeature('datauri') >= strlen($photo['value']))) {
- $html .= $this->_row(_("Photo"),
- '<img src="data:' . htmlspecialchars($photo['params']['TYPE'] . ';base64,' . $photo['value']) . '" />',
- false);
+ isset($photo['params']['TYPE'])) {
+ if ($GLOBALS['browser']->hasFeature('datauri') === true ||
+ $GLOBALS['browser']->hasFeature('datauri') >= strlen($photo['value'])) {
+ $html .= $this->_row(_("Photo"),
+ '<img src="data:' . htmlspecialchars($photo['params']['TYPE'] . ';base64,' . $photo['value']) . '" />',
+ false);
+ } elseif ($this->_imageUrl) {
+ $html .= $this->_row(_("Photo"),
+ '<img src="' . htmlspecialchars($this->_imageUrl->add(array('c' => $i, 'p' => $p))) . '" />',
+ false);
+ }
}
}
* smime S/MIME signed/encrypted messages
* status Mail delivery status messages
* tnef MS-TNEF attachments
+ * vcard vCards
* zip ZIP attachments
*/
$mime_drivers_map['imp']['registered'] = array(
'alternative', 'appledouble', 'enriched', 'html', 'images', 'itip',
'mdn', 'partial', 'pdf', 'pgp', 'plain', 'related', 'rfc822', 'smil',
- 'smime', 'status', 'tnef', 'zip'
+ 'smime', 'status', 'tnef', 'vcard', 'zip'
);
/**
);
/**
+ * vCard driver settings
+ */
+$mime_drivers['imp']['vcard'] = array(
+ 'handles' => array(
+ 'text/vcard', 'text/x-vcard', 'text/directory'
+ ),
+ 'icons' => array(
+ 'default' => 'vcard.png'
+ )
+);
+
+/**
* Zip File Attachments settings
*/
$mime_drivers['imp']['zip'] = array(
--- /dev/null
+<?php
+/**
+ * The IMP_Horde_Mime_Viewer_Vcard class renders out the contents of vCard
+ * files in HTML format and allows inline display of embedded photos.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author Jan Schneider <jan@horde.org>
+ * @package IMP
+ */
+class IMP_Horde_Mime_Viewer_Vcard extends Horde_Mime_Viewer_Vcard
+{
+ /**
+ * Return the full rendered version of the Horde_Mime_Part object.
+ *
+ * URL parameters used by this function:
+ * <pre>
+ * 'c' - (integer) The VCARD component that contains an image.
+ * 'p' - (integer) The index of image inside the component to display.
+ * </pre>
+ *
+ * @return array See Horde_Mime_Viewer_Driver::render().
+ * @throws Horde_Exception
+ */
+ protected function _render()
+ {
+ if (is_null(Horde_Util::getFormData('p'))) {
+ $this->_imageUrl = $this->_params['contents']->urlView($this->_mimepart, 'download_render');
+ return parent::_render();
+ }
+
+ /* Send the requested photo. */
+ $data = $this->_mimepart->getContents();
+ $ical = new Horde_iCalendar();
+ if (!$ical->parsevCalendar($data, 'VCALENDAR', $this->_mimepart->getCharset())) {
+ // TODO: Error reporting
+ return array();
+ }
+ $components = $ical->getComponents();
+ $c = Horde_Util::getFormData('c');
+ $p = Horde_Util::getFormData('p');
+ if (!isset($components[$c])) {
+ // TODO: Error reporting
+ return array();
+ }
+ $name = $components[$c]->getAttributeDefault('FN', false);
+ if ($name === false) {
+ $name = $components[$c]->printableName();
+ }
+ if (empty($name)) {
+ $name = preg_replace('/\..*?$/', '', $this->_mimepart->getName());
+ }
+
+ $photos = $components[$c]->getAllAttributes('PHOTO');
+ if (!isset($photos[$p])) {
+ // TODO: Error reporting
+ return array();
+ }
+ return array(
+ $this->_mimepart->getMimeId() => array(
+ 'data' => base64_decode($photos[$p]['value']),
+ 'name' => $name . '.' . Horde_Mime_Magic::mimeToExt($photos[$p]['params']['TYPE']),
+ 'status' => array(),
+ 'type' => $photos[$p]['params']['TYPE'],
+ )
+ );
+ }
+
+}