summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <bruederli@kolabsys.com>2015-04-01 17:09:45 (GMT)
committerThomas Bruederli <bruederli@kolabsys.com>2015-04-02 13:03:11 (GMT)
commit8bdfa604bf281516b389176362a921a510aaa467 (patch)
treed6ba97578d25376c5929204888f3b727ef162e20
parent1c1f1779ce2fc4c610182ca990e47c3b94110bfd (diff)
downloadiRony-iRony-0.2.tar.gz
Fix type parameter parsing and mapping (#4955)iRony-0.2
-rw-r--r--lib/Kolab/CardDAV/ContactsBackend.php41
1 files changed, 26 insertions, 15 deletions
diff --git a/lib/Kolab/CardDAV/ContactsBackend.php b/lib/Kolab/CardDAV/ContactsBackend.php
index a025d7d..fa5258a 100644
--- a/lib/Kolab/CardDAV/ContactsBackend.php
+++ b/lib/Kolab/CardDAV/ContactsBackend.php
@@ -567,8 +567,8 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
private $phonetypes = array(
'main' => 'voice',
- 'homefax' => 'fax',
- 'workfax' => 'fax',
+ 'homefax' => 'home,fax',
+ 'workfax' => 'work,fax',
'mobile' => 'cell',
'other' => 'textphone',
);
@@ -684,19 +684,21 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
$vc->add('X-CHILDREN', join(',', (array)$contact['children']));
foreach ((array)$contact['email'] as $email) {
- $vemail = VObject\Property::create('EMAIL', $email['address'], array('type' => 'INTERNET'));
+ $types = array('INTERNET');
if (!empty($email['type']))
- $vemail->offsetSet(null, new VObject\Parameter('type', strtoupper($email['type'])));
- $vc->add($vemail);
+ $types = array_merge($types, explode(',', strtoupper($email['type'])));
+ $vc->add('EMAIL', $email['address'], array('type' => $types));
}
foreach ((array)$contact['phone'] as $phone) {
$type = $this->phonetypes[$phone['type']] ?: $phone['type'];
- $vc->add('TEL', $phone['number'], array('type' => strtoupper($type)));
+ $params = !empty($type) ? array('type' => explode(',', strtoupper($type))) : array();
+ $vc->add('TEL', $phone['number'], $params);
}
foreach ((array)$contact['website'] as $website) {
- $vc->add('URL', $website['url'], array('type' => strtoupper($website['type'])));
+ $params = !empty($website['type']) ? array('type' => explode(',', strtoupper($website['type']))) : array();
+ $vc->add('URL', $website['url'], $params);
}
$improtocolmap = array_flip($this->improtocols);
@@ -707,7 +709,8 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
}
foreach ((array)$contact['address'] as $adr) {
- $vadr = VObject\Property::create('ADR', null, array('type' => strtoupper($adr['type'])));
+ $params = !empty($adr['type']) ? array('type' => strtoupper($adr['type'])) : array();
+ $vadr = VObject\Property::create('ADR', null, $params);
$vadr->setParts(array('','', $adr['street'], $adr['locality'], $adr['region'], $adr['code'], $adr['country']));
$vc->add($vadr);
}
@@ -808,6 +811,8 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
}
$phonetypemap = array_flip($this->phonetypes);
+ $phonetypemap['fax,home'] = 'homefax';
+ $phonetypemap['fax,work'] = 'workfax';
// map attributes to internal fields
foreach ($vc->children as $prop) {
@@ -841,24 +846,25 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
break;
case 'EMAIL':
- $types = array_values(self::array_filter($prop->offsetGet('type'), 'internet,pref', true));
+ $types = array_values(self::prop_filter($prop->offsetGet('type'), 'internet,pref', true));
$contact['email'][] = array('address' => $prop->value, 'type' => strtolower($types[0] ?: 'other'));
break;
case 'URL':
- $types = array_values(self::array_filter($prop->offsetGet('type'), 'internet,pref', true));
+ $types = array_values(self::prop_filter($prop->offsetGet('type'), 'internet,pref', true));
$contact['website'][] = array('url' => $prop->value, 'type' => strtolower($types[0]));
break;
case 'TEL':
- $types = array_values(self::array_filter($prop->offsetGet('type'), 'internet,pref', true));
- $type = strtolower($types[0]);
+ $types = array_values(self::prop_filter($prop->offsetGet('type'), 'voice,pref', true));
+ $types_ = strtolower(join(',', $types));
+ $type = isset($phonetypemap[$types_]) ? $types_ : strtolower($types[0]);
$contact['phone'][] = array('number' => $prop->value, 'type' => $phonetypemap[$type] ?: $type);
break;
case 'ADR':
- $type = $prop->offsetGet('type');
- $adr = array('type' => strtolower($type));
+ $types = array_values(self::prop_filter($prop->offsetGet('type'), 'pref', true));
+ $adr = array('type' => strtolower(!empty($types) ? strval($types[0]) : $prop->parameters[0]->name));
list(,, $adr['street'], $adr['locality'], $adr['region'], $adr['code'], $adr['country']) = $prop->getParts();
$contact['address'][] = $adr;
break;
@@ -960,12 +966,17 @@ class ContactsBackend extends CardDAV\Backend\AbstractBackend
*
* @return array The filtered array
*/
- private static function array_filter($arr, $values, $inverse = false)
+ private static function prop_filter($arr, $values, $inverse = false)
{
if (!is_array($values)) {
$values = explode(',', $values);
}
+ // explode single, comma-separated value
+ if (count($arr) == 1 && strpos($arr[0], ',')) {
+ $arr = explode(',', $arr[0]);
+ }
+
$result = array();
$keep = array_flip((array)$values);