Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added URLs to be exported in vCards. #5609

Merged
merged 8 commits into from
Oct 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions app/Services/VCard/ExportVCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ private function exportContactFields(Contact $contact, VCard $vcard)
$vcard->remove('TEL');
$vcard->remove('EMAIL');
$vcard->remove('socialProfile');
$vcard->remove('URL');

foreach ($contact->contactFields as $contactField) {
$type = $this->getContactFieldLabel($contactField);
Expand All @@ -261,26 +262,30 @@ private function exportContactFields(Contact $contact, VCard $vcard)
$vcard->add('EMAIL', $this->escape($contactField->data), $type);
break;
default:
break;
}
switch ($contactField->contactFieldType->name) {
// See https://tools.ietf.org/id/draft-george-vcarddav-vcard-extension-02.html
case 'Facebook':
$vcard->add('socialProfile', $this->escape('https://www.facebook.com/'.$contactField->data), ['type' => 'facebook']);
break;
case 'Twitter':
$vcard->add('socialProfile', $this->escape('https://twitter.com/'.$contactField->data), ['type' => 'twitter']);
break;
case 'Whatsapp':
$vcard->add('socialProfile', $this->escape('https://wa.me/'.$contactField->data), ['type' => 'whatsapp']);
break;
case 'Telegram':
$vcard->add('socialProfile', $this->escape('http://t.me/'.$contactField->data), ['type' => 'telegram']);
break;
case 'LinkedIn':
$vcard->add('socialProfile', $this->escape('http://www.linkedin.com/in/'.$contactField->data), ['type' => 'linkedin']);
break;
default:
switch ($contactField->contactFieldType->name) {
// See https://tools.ietf.org/id/draft-george-vcarddav-vcard-extension-02.html
case 'Facebook':
$vcard->add('socialProfile', $this->escape('https://www.facebook.com/'.$contactField->data), ['type' => 'facebook']);
break;
case 'Twitter':
$vcard->add('socialProfile', $this->escape('https://twitter.com/'.$contactField->data), ['type' => 'twitter']);
break;
case 'Whatsapp':
$vcard->add('socialProfile', $this->escape('https://wa.me/'.$contactField->data), ['type' => 'whatsapp']);
break;
case 'Telegram':
$vcard->add('socialProfile', $this->escape('http://t.me/'.$contactField->data), ['type' => 'telegram']);
break;
case 'LinkedIn':
$vcard->add('socialProfile', $this->escape('http://www.linkedin.com/in/'.$contactField->data), ['type' => 'linkedin']);
break;
default:
// If field isn't a supported social profile, but still has a protocol, then export it as a url.
if (! empty($contactField->contactFieldType->protocol)) {
$vcard->add('URL', $this->escape($contactField->contactFieldType->protocol.$contactField->data));
}
break;
}
break;
}
}
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/Services/VCard/ExportVCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,42 @@ public function socialProfileProvider()
];
}

/**
* @test
* @dataProvider contactUrlProvider
*/
public function vcard_add_contact_url($name, $protocol, $data, $result)
{
$account = factory(Account::class)->create();
$contact = factory(Contact::class)->create(['account_id' => $account->id]);
$vCard = new VCard();

$contactFieldType = factory(ContactFieldType::class)->create([
'account_id' => $account->id,
'name' => $name,
'protocol' => $protocol,
'type' => 'URL',
]);
factory(ContactField::class)->create([
'contact_id' => $contact->id,
'account_id' => $account->id,
'contact_field_type_id' => $contactFieldType->id,
'data' => $data,
]);

$exportVCard = app(ExportVCard::class);
$this->invokePrivateMethod($exportVCard, 'exportContactFields', [$contact, $vCard]);
$this->assertStringContainsString($result, $vCard->serialize());
}

public function contactUrlProvider()
{
return [
['Discord', 'https://www.discord.app/user/', 'test123', 'URL;VALUE=URI:https://www.discord.app/user/test123'],
['Facebook Profile', 'https://www.facebook.com/', 'test123', 'URL;VALUE=URI:https://www.facebook.com/test123'],
];
}

/** @test */
public function vcard_add_addresses_empty()
{
Expand Down