From a43fc97ef1bc7246da5eca94b890205356585e1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Bolvin?= Date: Tue, 14 Jun 2016 23:47:20 +0200 Subject: [PATCH] Fallback to formatted name if available --- carddav2fb.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/carddav2fb.php b/carddav2fb.php index 09807a67..1579713b 100755 --- a/carddav2fb.php +++ b/carddav2fb.php @@ -248,6 +248,7 @@ public function get_carddav_entries() $prefix = ''; $suffix = ''; $orgname = ''; + $formattedname = ''; // Build name Parts if existing ans switch to true in config if(isset($name_arr['prefixes']) and $this->config['prefix']) @@ -262,6 +263,9 @@ public function get_carddav_entries() if(isset($org_arr['name']) and $this->config['orgname']) $orgname = trim($org_arr['name']); + if (isset($vcard_obj->fn[0])) + $formattedname = $vcard_obj->fn[0]; + $firstname = trim($name_arr['firstname']); $lastname = trim($name_arr['lastname']); @@ -349,9 +353,13 @@ public function get_carddav_entries() // make sure to trim whitespaces and double spaces $name = trim(str_replace(' ', ' ', $name)); + // perform a fallback to formatted name, if we don't have any name and formatted name is available + if(empty($name) and !empty($formattedname)) + $name = $formattedname; + if(empty($name)) { - print ' WARNING: No fullname, lastname or orgname found!'; + print ' WARNING: No fullname, lastname, orgname or formatted name found!' . PHP_EOL; $name = 'UNKNOWN'; }