diff options
author | Thomas Tanghus <thomas@tanghus.net> | 2012-02-09 19:04:07 +0100 |
---|---|---|
committer | Thomas Tanghus <thomas@tanghus.net> | 2012-02-09 19:04:07 +0100 |
commit | ff53b0c2097ae5d0390336238454dc1792158905 (patch) | |
tree | fb31d989dac41784e1fa6e2182d5db1b742a82e2 /apps/contacts/lib/vcard.php | |
parent | 25faa40bd09f35cfc14a699d23d2d747173922d3 (diff) | |
download | nextcloud-server-ff53b0c2097ae5d0390336238454dc1792158905.tar.gz nextcloud-server-ff53b0c2097ae5d0390336238454dc1792158905.zip |
Keep js data structure in sync on changes.
More checks for missing properties.
Diffstat (limited to 'apps/contacts/lib/vcard.php')
-rw-r--r-- | apps/contacts/lib/vcard.php | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index bb5b2da23d5..f9ca427354e 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -134,7 +134,7 @@ class OC_Contacts_VCard{ // Add product ID. $prodid = trim($card->getAsString('PRODID')); if(!$prodid) { - $appinfo = $info=OC_App::getAppInfo('contacts'); + $appinfo = OC_App::getAppInfo('contacts'); $prodid = '//ownCloud//NONSGML '.$appinfo['name'].' '.$appinfo['version'].'//EN'; $card->setString('PRODID', $prodid); } @@ -176,7 +176,7 @@ class OC_Contacts_VCard{ * @return insertid */ public static function addFromDAVData($id,$uri,$data){ - $fn = null; + $fn = $n = null; $email = null; $card = OC_VObject::parse($data); if(!is_null($card)){ @@ -184,19 +184,31 @@ class OC_Contacts_VCard{ if($property->name == 'FN'){ $fn = $property->value; } + if($property->name == 'N'){ + $n = $property->value; + } if($property->name == 'EMAIL' && is_null($email)){ $email = $property->value; } } } if(!$fn) { - if($email) { + if($n){ + $fn = join(' ', array_reverse(array_slice(explode(';', $n), 0, 2))); + } elseif($email) { $fn = $email; } else { $fn = 'Unknown Name'; } $card->addProperty('FN', $fn); $data = $card->serialize(); + OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'FN\' field: '.$n,OC_Log::DEBUG); + } + if(!$n){ // Fix missing 'N' field. + $n = implode(';', array_reverse(array_slice(explode(' ', $fn), 0, 2))).';;;'; + $card->setString('N', $n); + $data = $card->serialize(); + OC_Log::write('contacts','OC_Contacts_VCard::add. Added missing \'N\' field: '.$n,OC_Log::DEBUG); } $stmt = OC_DB::prepare( 'INSERT INTO *PREFIX*contacts_cards (addressbookid,fullname,carddata,uri,lastmodified) VALUES(?,?,?,?,?)' ); |