Changeset View
Changeset View
Standalone View
Standalone View
plugins/libkolab/lib/kolab_format_contact.php
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | class kolab_format_contact extends kolab_format | ||||
*/ | */ | ||||
public function set(&$object) | public function set(&$object) | ||||
{ | { | ||||
// set common object properties | // set common object properties | ||||
parent::set($object); | parent::set($object); | ||||
// do the hard work of setting object values | // do the hard work of setting object values | ||||
$nc = new NameComponents; | $nc = new NameComponents; | ||||
$nc->setSurnames(self::array2vector($object['surname'])); | $nc->setSurnames(self::array2vector($object['surname'] ?? null)); | ||||
$nc->setGiven(self::array2vector($object['firstname'])); | $nc->setGiven(self::array2vector($object['firstname'] ?? null)); | ||||
$nc->setAdditional(self::array2vector($object['middlename'])); | $nc->setAdditional(self::array2vector($object['middlename'] ?? null)); | ||||
$nc->setPrefixes(self::array2vector($object['prefix'])); | $nc->setPrefixes(self::array2vector($object['prefix'] ?? null)); | ||||
$nc->setSuffixes(self::array2vector($object['suffix'])); | $nc->setSuffixes(self::array2vector($object['suffix'] ?? null)); | ||||
$this->obj->setNameComponents($nc); | $this->obj->setNameComponents($nc); | ||||
$this->obj->setName($object['name']); | $this->obj->setName($object['name'] ?? null); | ||||
$this->obj->setCategories(self::array2vector($object['categories'])); | $this->obj->setCategories(self::array2vector($object['categories'] ?? null)); | ||||
if (isset($object['nickname'])) | if (isset($object['nickname'])) | ||||
$this->obj->setNickNames(self::array2vector($object['nickname'])); | $this->obj->setNickNames(self::array2vector($object['nickname'])); | ||||
if (isset($object['jobtitle'])) | if (isset($object['jobtitle'])) | ||||
$this->obj->setTitles(self::array2vector($object['jobtitle'])); | $this->obj->setTitles(self::array2vector($object['jobtitle'])); | ||||
// organisation related properties (affiliation) | // organisation related properties (affiliation) | ||||
$org = new Affiliation; | $org = new Affiliation; | ||||
$offices = new vectoraddress; | $offices = new vectoraddress; | ||||
if ($object['organization']) | if ($object['organization'] ?? null) | ||||
$org->setOrganisation($object['organization']); | $org->setOrganisation($object['organization']); | ||||
if ($object['department']) | if ($object['department'] ?? null) | ||||
$org->setOrganisationalUnits(self::array2vector($object['department'])); | $org->setOrganisationalUnits(self::array2vector($object['department'])); | ||||
if ($object['profession']) | if ($object['profession'] ?? null) | ||||
$org->setRoles(self::array2vector($object['profession'])); | $org->setRoles(self::array2vector($object['profession'])); | ||||
$rels = new vectorrelated; | $rels = new vectorrelated; | ||||
foreach (array('manager','assistant') as $field) { | foreach (array('manager','assistant') as $field) { | ||||
if (!empty($object[$field])) { | if (!empty($object[$field] ?? null)) { | ||||
$reltype = $this->relatedmap[$field]; | $reltype = $this->relatedmap[$field]; | ||||
foreach ((array)$object[$field] as $value) { | foreach ((array)$object[$field] as $value) { | ||||
$rels->push(new Related(Related::Text, $value, $reltype)); | $rels->push(new Related(Related::Text, $value, $reltype)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
$org->setRelateds($rels); | $org->setRelateds($rels); | ||||
// im, email, url | // im, email, url | ||||
$this->obj->setIMaddresses(self::array2vector($object['im'])); | $this->obj->setIMaddresses(self::array2vector($object['im'] ?? null)); | ||||
if (class_exists('vectoremail')) { | if (class_exists('vectoremail')) { | ||||
$vemails = new vectoremail; | $vemails = new vectoremail; | ||||
foreach ((array)$object['email'] as $email) { | foreach ((array)($object['email'] ?? []) as $email) { | ||||
$type = $this->emailtypes[$email['type']]; | $type = $this->emailtypes[$email['type']]; | ||||
$vemails->push(new Email($email['address'], intval($type))); | $vemails->push(new Email($email['address'], intval($type))); | ||||
} | } | ||||
} | } | ||||
else { | else { | ||||
$vemails = self::array2vector(array_map(function($v){ return $v['address']; }, $object['email'])); | $vemails = self::array2vector(array_map(function($v){ return $v['address']; }, $object['email'])); | ||||
} | } | ||||
$this->obj->setEmailAddresses($vemails); | $this->obj->setEmailAddresses($vemails); | ||||
$vurls = new vectorurl; | $vurls = new vectorurl; | ||||
foreach ((array)$object['website'] as $url) { | foreach ((array)($object['website'] ?? []) as $url) { | ||||
$type = $url['type'] == 'blog' ? Url::Blog : Url::NoType; | $type = $url['type'] == 'blog' ? Url::Blog : Url::NoType; | ||||
$vurls->push(new Url($url['url'], $type)); | $vurls->push(new Url($url['url'], $type)); | ||||
} | } | ||||
$this->obj->setUrls($vurls); | $this->obj->setUrls($vurls); | ||||
// addresses | // addresses | ||||
$adrs = new vectoraddress; | $adrs = new vectoraddress; | ||||
foreach ((array)$object['address'] as $address) { | foreach ((array)($object['address'] ?? [])as $address) { | ||||
$adr = new Address; | $adr = new Address; | ||||
$type = $this->addresstypes[$address['type']]; | $type = $this->addresstypes[$address['type']]; | ||||
if (isset($type)) | if (isset($type)) | ||||
$adr->setTypes($type); | $adr->setTypes($type); | ||||
else if ($address['type']) | else if ($address['type'] ?? null) | ||||
$adr->setLabel($address['type']); | $adr->setLabel($address['type']); | ||||
if ($address['street']) | if ($address['street'] ?? null) | ||||
$adr->setStreet($address['street']); | $adr->setStreet($address['street']); | ||||
if ($address['locality']) | if ($address['locality'] ?? null) | ||||
$adr->setLocality($address['locality']); | $adr->setLocality($address['locality']); | ||||
if ($address['code']) | if ($address['code'] ?? null) | ||||
$adr->setCode($address['code']); | $adr->setCode($address['code']); | ||||
if ($address['region']) | if ($address['region'] ?? null) | ||||
$adr->setRegion($address['region']); | $adr->setRegion($address['region']); | ||||
if ($address['country']) | if ($address['country'] ?? null) | ||||
$adr->setCountry($address['country']); | $adr->setCountry($address['country']); | ||||
if ($address['type'] == 'office') | if (($address['type'] ?? null) == 'office') | ||||
$offices->push($adr); | $offices->push($adr); | ||||
else | else | ||||
$adrs->push($adr); | $adrs->push($adr); | ||||
} | } | ||||
$this->obj->setAddresses($adrs); | $this->obj->setAddresses($adrs); | ||||
$org->setAddresses($offices); | $org->setAddresses($offices); | ||||
// add org affiliation after addresses are set | // add org affiliation after addresses are set | ||||
$orgs = new vectoraffiliation; | $orgs = new vectoraffiliation; | ||||
$orgs->push($org); | $orgs->push($org); | ||||
$this->obj->setAffiliations($orgs); | $this->obj->setAffiliations($orgs); | ||||
// telephones | // telephones | ||||
$tels = new vectortelephone; | $tels = new vectortelephone; | ||||
foreach ((array)$object['phone'] as $phone) { | foreach ((array)($object['phone'] ?? []) as $phone) { | ||||
$tel = new Telephone; | $tel = new Telephone; | ||||
if (isset($this->phonetypes[$phone['type']])) | if (isset($this->phonetypes[$phone['type'] ?? null])) | ||||
$tel->setTypes($this->phonetypes[$phone['type']]); | $tel->setTypes($this->phonetypes[$phone['type']]); | ||||
$tel->setNumber($phone['number']); | $tel->setNumber($phone['number'] ?? null); | ||||
$tels->push($tel); | $tels->push($tel); | ||||
} | } | ||||
$this->obj->setTelephones($tels); | $this->obj->setTelephones($tels); | ||||
if (isset($object['gender'])) | if (isset($object['gender'])) | ||||
$this->obj->setGender($this->gendermap[$object['gender']] ? $this->gendermap[$object['gender']] : Contact::NotSet); | $this->obj->setGender($this->gendermap[$object['gender']] ? $this->gendermap[$object['gender']] : Contact::NotSet); | ||||
if (isset($object['notes'])) | if (isset($object['notes'])) | ||||
$this->obj->setNote($object['notes']); | $this->obj->setNote($object['notes']); | ||||
if (isset($object['freebusyurl'])) | if (isset($object['freebusyurl'])) | ||||
$this->obj->setFreeBusyUrl($object['freebusyurl']); | $this->obj->setFreeBusyUrl($object['freebusyurl']); | ||||
if (isset($object['lang'])) | if (isset($object['lang'])) | ||||
$this->obj->setLanguages(self::array2vector($object['lang'])); | $this->obj->setLanguages(self::array2vector($object['lang'])); | ||||
if (isset($object['birthday'])) | if (isset($object['birthday'])) | ||||
$this->obj->setBDay(self::get_datetime($object['birthday'], false, true)); | $this->obj->setBDay(self::get_datetime($object['birthday'], false, true)); | ||||
if (isset($object['anniversary'])) | if (isset($object['anniversary'])) | ||||
$this->obj->setAnniversary(self::get_datetime($object['anniversary'], false, true)); | $this->obj->setAnniversary(self::get_datetime($object['anniversary'], false, true)); | ||||
if (!empty($object['photo'])) { | if (!empty($object['photo'] ?? null)) { | ||||
if ($type = rcube_mime::image_content_type($object['photo'])) | if ($type = rcube_mime::image_content_type($object['photo'])) | ||||
$this->obj->setPhoto($object['photo'], $type); | $this->obj->setPhoto($object['photo'], $type); | ||||
} | } | ||||
else if (isset($object['photo'])) | else if (isset($object['photo'])) | ||||
$this->obj->setPhoto('',''); | $this->obj->setPhoto('',''); | ||||
else if ($this->obj->photoMimetype()) // load saved photo for caching | else if ($this->obj->photoMimetype()) // load saved photo for caching | ||||
$object['photo'] = $this->obj->photo(); | $object['photo'] = $this->obj->photo(); | ||||
// spouse and children are relateds | // spouse and children are relateds | ||||
$rels = new vectorrelated; | $rels = new vectorrelated; | ||||
foreach (array('spouse','children') as $field) { | foreach (array('spouse','children') as $field) { | ||||
if (!empty($object[$field])) { | if (!empty($object[$field])) { | ||||
$reltype = $this->relatedmap[$field]; | $reltype = $this->relatedmap[$field]; | ||||
foreach ((array)$object[$field] as $value) { | foreach ((array)$object[$field] as $value) { | ||||
$rels->push(new Related(Related::Text, $value, $reltype)); | $rels->push(new Related(Related::Text, $value, $reltype)); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// add other relateds | // add other relateds | ||||
if (is_array($object['related'])) { | if (is_array($object['related'] ?? null)) { | ||||
foreach ($object['related'] as $value) { | foreach ($object['related'] as $value) { | ||||
$rels->push(new Related(Related::Text, $value)); | $rels->push(new Related(Related::Text, $value)); | ||||
} | } | ||||
} | } | ||||
$this->obj->setRelateds($rels); | $this->obj->setRelateds($rels); | ||||
// insert/replace crypto keys | // insert/replace crypto keys | ||||
$pgp_index = $pkcs7_index = -1; | $pgp_index = $pkcs7_index = -1; | ||||
$keys = $this->obj->keys(); | $keys = $this->obj->keys(); | ||||
for ($i=0; $i < $keys->size(); $i++) { | for ($i=0; $i < $keys->size(); $i++) { | ||||
$key = $keys->get($i); | $key = $keys->get($i); | ||||
if ($pgp_index < 0 && $key->type() == Key::PGP) | if ($pgp_index < 0 && $key->type() == Key::PGP) | ||||
$pgp_index = $i; | $pgp_index = $i; | ||||
else if ($pkcs7_index < 0 && $key->type() == Key::PKCS7_MIME) | else if ($pkcs7_index < 0 && $key->type() == Key::PKCS7_MIME) | ||||
$pkcs7_index = $i; | $pkcs7_index = $i; | ||||
} | } | ||||
$pgpkey = $object['pgppublickey'] ? new Key($object['pgppublickey'], Key::PGP) : new Key(); | $pgpkey = ($object['pgppublickey'] ?? false) ? new Key($object['pgppublickey'], Key::PGP) : new Key(); | ||||
$pkcs7key = $object['pkcs7publickey'] ? new Key($object['pkcs7publickey'], Key::PKCS7_MIME) : new Key(); | $pkcs7key = ($object['pkcs7publickey'] ?? false) ? new Key($object['pkcs7publickey'], Key::PKCS7_MIME) : new Key(); | ||||
if ($pgp_index >= 0) | if ($pgp_index >= 0) | ||||
$keys->set($pgp_index, $pgpkey); | $keys->set($pgp_index, $pgpkey); | ||||
else if (!empty($object['pgppublickey'])) | else if (!empty($object['pgppublickey'])) | ||||
$keys->push($pgpkey); | $keys->push($pgpkey); | ||||
if ($pkcs7_index >= 0) | if ($pkcs7_index >= 0) | ||||
$keys->set($pkcs7_index, $pkcs7key); | $keys->set($pkcs7_index, $pkcs7key); | ||||
else if (!empty($object['pkcs7publickey'])) | else if (!empty($object['pkcs7publickey'])) | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | class kolab_format_contact extends kolab_format | ||||
* Callback for kolab_storage_cache to get words to index for fulltext search | * Callback for kolab_storage_cache to get words to index for fulltext search | ||||
* | * | ||||
* @return array List of words to save in cache | * @return array List of words to save in cache | ||||
*/ | */ | ||||
public function get_words() | public function get_words() | ||||
{ | { | ||||
$data = ''; | $data = ''; | ||||
foreach (self::$fulltext_cols as $colname) { | foreach (self::$fulltext_cols as $colname) { | ||||
list($col, $field) = explode(':', $colname); | list($col, $field) = array_pad(explode(':', $colname), 2, null); | ||||
if ($field) { | if ($field) { | ||||
$a = array(); | $a = array(); | ||||
foreach ((array)$this->data[$col] as $attr) | foreach ((array)($this->data[$col] ?? []) as $attr) | ||||
$a[] = $attr[$field]; | $a[] = $attr[$field]; | ||||
$val = join(' ', $a); | $val = join(' ', $a); | ||||
} | } | ||||
else { | else { | ||||
$val = is_array($this->data[$col]) ? join(' ', $this->data[$col]) : $this->data[$col]; | $val = is_array($this->data[$col] ?? null) ? join(' ', $this->data[$col] ?? null) : ($this->data[$col] ?? null); | ||||
} | } | ||||
if (strlen($val)) | if (strlen($val)) | ||||
$data .= $val . ' '; | $data .= $val . ' '; | ||||
} | } | ||||
return array_unique(rcube_utils::normalize_string($data, true)); | return array_unique(rcube_utils::normalize_string($data, true)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 65 Lines • Show Last 20 Lines |