Adapt to yet another set of changes in libkolabxml

This commit is contained in:
Thomas B 2012-04-21 18:23:11 +02:00
parent 2559d6ffb7
commit 750b4f15ca
2 changed files with 61 additions and 11 deletions

View file

@ -47,7 +47,7 @@ class rcube_kolab_contacts extends rcube_addressbook
'email' => array('subtypes' => null),
'phone' => array(),
'address' => array('subtypes' => array('home','work','office')),
'website' => array('subtypes' => null),
'website' => array('subtypes' => array('homepage','blog')),
'im' => array('subtypes' => null),
'gender' => array('limit' => 1),
'birthday' => array('limit' => 1),
@ -120,7 +120,7 @@ class rcube_kolab_contacts extends rcube_addressbook
$this->readonly = false;
}
else {
$rights = $this->storagefolder->get_acl();
$rights = $this->storagefolder->get_myrights();
if (!PEAR::isError($rights)) {
if (strpos($rights, 'i') !== false)
$this->readonly = false;
@ -1027,6 +1027,15 @@ class rcube_kolab_contacts extends rcube_addressbook
}
}
if (is_array($record['website'])) {
$urls = $record['website'];
unset($record['website']);
foreach ((array)$urls as $i => $url) {
$key = 'website' . ($url['type'] ? ':' . $url['type'] : '');
$record[$key][] = $url['url'];
}
}
if (is_array($record['address'])) {
$addresses = $record['address'];
unset($record['address']);
@ -1068,8 +1077,15 @@ class rcube_kolab_contacts extends rcube_addressbook
$contact['uid'] = $old['uid'];
$contact['email'] = array_filter($this->get_col_values('email', $contact, true));
$contact['website'] = array_filter($this->get_col_values('website', $contact, true));
$contact['im'] = array_filter($this->get_col_values('im', $contact, true));
foreach ($this->get_col_values('website', $contact) as $type => $values) {
foreach ((array)$values as $url) {
if (!empty($url)) {
$contact['website'][] = array('url' => $url, 'type' => $type);
}
}
}
foreach ($this->get_col_values('phone', $contact) as $type => $values) {
foreach ((array)$values as $phone) {

View file

@ -188,7 +188,13 @@ class kolab_format_contact extends kolab_format
// email, im, url
$this->obj->setEmailAddresses(self::array2vector($object['email']));
$this->obj->setIMaddresses(self::array2vector($object['im']));
$this->obj->setUrls(self::array2vector($object['website']));
$vurls = new vectorurl;
foreach ((array)$object['website'] as $url) {
$type = $url['type'] == 'blog' ? Url::Blog : Url::None;
$vurls->push(new Url($url['url'], $type));
}
$this->obj->setUrls($vurls);
// addresses
$adrs = new vectoraddress;
@ -265,9 +271,27 @@ class kolab_format_contact extends kolab_format
$this->obj->setRelateds($rels);
if (isset($object['pgppublickey'])) {
$crypto = new Crypto;
$crypto->setPGPKey($object['pgppublickey']);
$this->obj->setCrypto($crypto);
$replace = -1;
$keys = $this->obj->keys();
if (!is_object($keys))
$keys = new vectorkey;
for ($i=0; $i < $keys->size(); $i++) {
$key = $keys->get($i);
if ($key->type() == Key::PGP) {
$replace = $i;
break;
}
}
// insert/replace pgp key entry
$key = new Key($object['pgppublickey'], Key::PGP);
if ($replace >= 0)
$keys->set($replace, $key);
else
$keys->push($key);
$this->obj->setKeys($keys);
}
// TODO: handle language, gpslocation, etc.
@ -325,7 +349,13 @@ class kolab_format_contact extends kolab_format
$object['email'] = self::vector2array($this->obj->emailAddresses());
$object['im'] = self::vector2array($this->obj->imAddresses());
$object['website'] = self::vector2array($this->obj->urls());
$urls = $this->obj->urls();
for ($i=0; $i < $urls->size(); $i++) {
$url = $urls->get($i);
$subtype = $url->type() == Url::Blog ? 'blog' : 'homepage';
$object['website'][] = array('url' => $url->url(), 'type' => $subtype);
}
// addresses
$this->read_addresses($this->obj->addresses(), $object);
@ -360,9 +390,13 @@ class kolab_format_contact extends kolab_format
$this->read_relateds($this->obj->relateds(), $object);
// crypto settings: currently only pgpkey is supported
$crypto = $this->obj->crypto();
if ($pgpkey = $crypto->pgpKey())
$object['pgppublickey'] = $pgpkey;
$keys = $this->obj->keys();
for ($i=0; is_object($keys) && $i < $keys->size(); $i++) {
$key = $keys->get($i);
if ($key->type() == Key::PGP) {
$object['pgppublickey'] = $key->key();
}
}
$this->data = $object;
return $this->data;