Skip to content

Commit

Permalink
Fallback to formatted name if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Fensterbank committed Jun 14, 2016
1 parent e7cc5e8 commit a43fc97
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion carddav2fb.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])
Expand All @@ -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']);

Expand Down Expand Up @@ -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';
}

Expand Down

0 comments on commit a43fc97

Please sign in to comment.