Changeset View
Changeset View
Standalone View
Standalone View
plugins/kolab_addressbook/drivers/kolab/kolab_contacts.php
Show First 20 Lines • Show All 160 Lines • ▼ Show 20 Lines | public function __construct($imap_folder = null) | ||||
$this->coltypes['phone']['subtypes'] = array_keys($format->phonetypes); | $this->coltypes['phone']['subtypes'] = array_keys($format->phonetypes); | ||||
$this->coltypes['address']['subtypes'] = array_keys($format->addresstypes); | $this->coltypes['address']['subtypes'] = array_keys($format->addresstypes); | ||||
$rcube = rcube::get_instance(); | $rcube = rcube::get_instance(); | ||||
// set localized labels for proprietary cols | // set localized labels for proprietary cols | ||||
foreach ($this->coltypes as $col => $prop) { | foreach ($this->coltypes as $col => $prop) { | ||||
if (is_string($prop['label'])) { | if (is_string($prop['label'] ?? null)) { | ||||
$this->coltypes[$col]['label'] = $rcube->gettext($prop['label']); | $this->coltypes[$col]['label'] = $rcube->gettext($prop['label']); | ||||
} | } | ||||
} | } | ||||
// fetch objects from the given IMAP folder | // fetch objects from the given IMAP folder | ||||
$this->storagefolder = kolab_storage::get_folder($this->imap_folder); | $this->storagefolder = kolab_storage::get_folder($this->imap_folder); | ||||
$this->ready = $this->storagefolder && !PEAR::isError($this->storagefolder); | $this->ready = $this->storagefolder && !PEAR::isError($this->storagefolder); | ||||
▲ Show 20 Lines • Show All 1,137 Lines • ▼ Show 20 Lines | private function _to_rcube_contact($record) | ||||
return $record; | return $record; | ||||
} | } | ||||
/** | /** | ||||
* Map fields from Roundcube format to internal kolab_format_contact properties | * Map fields from Roundcube format to internal kolab_format_contact properties | ||||
*/ | */ | ||||
private function _from_rcube_contact($contact, $old = array()) | private function _from_rcube_contact($contact, $old = array()) | ||||
{ | { | ||||
if (!$contact['uid'] && $contact['ID']) { | if (!($contact['uid'] ?? null) && ($contact['ID'] ?? null)) { | ||||
$contact['uid'] = $this->id2uid($contact['ID']); | $contact['uid'] = $this->id2uid($contact['ID']); | ||||
} | } | ||||
else if (!$contact['uid'] && $old['uid']) { | else if (!($contact['uid'] ?? null) && ($old['uid'] ?? null)) { | ||||
$contact['uid'] = $old['uid']; | $contact['uid'] = $old['uid']; | ||||
} | } | ||||
$contact['im'] = array_filter($this->get_col_values('im', $contact, true)); | $contact['im'] = array_filter($this->get_col_values('im', $contact, true)); | ||||
// convert email, website, phone values | // convert email, website, phone values | ||||
foreach (array('email'=>'address', 'website'=>'url', 'phone'=>'number') as $col => $propname) { | foreach (array('email'=>'address', 'website'=>'url', 'phone'=>'number') as $col => $propname) { | ||||
$col_values = $this->get_col_values($col, $contact); | $col_values = $this->get_col_values($col, $contact); | ||||
Show All 28 Lines | private function _from_rcube_contact($contact, $old = array()) | ||||
} | } | ||||
unset($contact['address:'.$type]); | unset($contact['address:'.$type]); | ||||
} | } | ||||
$contact['address'] = $addresses; | $contact['address'] = $addresses; | ||||
// categories are not supported in the web client but should be preserved (#2608) | // categories are not supported in the web client but should be preserved (#2608) | ||||
$contact['categories'] = $old['categories']; | $contact['categories'] = $old['categories'] ?? null; | ||||
// copy meta data (starting with _) from old object | // copy meta data (starting with _) from old object | ||||
foreach ((array)$old as $key => $val) { | foreach ((array)$old as $key => $val) { | ||||
if (!isset($contact[$key]) && $key[0] == '_') { | if (!isset($contact[$key]) && $key[0] == '_') { | ||||
$contact[$key] = $val; | $contact[$key] = $val; | ||||
} | } | ||||
} | } | ||||
// convert one-item-array elements into string element | // convert one-item-array elements into string element | ||||
// this is needed e.g. to properly import birthday field | // this is needed e.g. to properly import birthday field | ||||
foreach ($this->coltypes as $type => $col_def) { | foreach ($this->coltypes as $type => $col_def) { | ||||
if ($col_def['limit'] == 1 && is_array($contact[$type])) { | if (($col_def['limit'] ?? null) == 1 && is_array($contact[$type] ?? null)) { | ||||
$contact[$type] = array_shift(array_filter($contact[$type])); | $contact[$type] = array_shift(array_filter($contact[$type])); | ||||
} | } | ||||
} | } | ||||
// When importing contacts 'vcard' data is added, we don't need it (Bug #1711) | // When importing contacts 'vcard' data is added, we don't need it (Bug #1711) | ||||
unset($contact['vcard']); | unset($contact['vcard']); | ||||
// add empty values for some fields which can be removed in the UI | // add empty values for some fields which can be removed in the UI | ||||
Show All 9 Lines |