-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add more vcard exports (#6878)
- Loading branch information
Showing
28 changed files
with
532 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace App\Domains\Contact\ManageContact\Dav; | ||
|
||
use App\Domains\Contact\Dav\ExportVCardResource; | ||
use App\Domains\Contact\Dav\Order; | ||
use App\Models\Contact; | ||
use Sabre\VObject\Component\VCard; | ||
|
||
/** | ||
* @implements ExportVCardResource<Contact> | ||
*/ | ||
#[Order(20)] | ||
class ExportAdr implements ExportVCardResource | ||
{ | ||
public function getType(): string | ||
{ | ||
return Contact::class; | ||
} | ||
|
||
/** | ||
* @param Contact $resource | ||
*/ | ||
public function export(mixed $resource, VCard $vcard): void | ||
{ | ||
$vcard->remove('ADR'); | ||
|
||
if (($addresses = $resource->addresses) !== null) { | ||
foreach ($addresses as $address) { | ||
// https://datatracker.ietf.org/doc/html/rfc6350#section-6.3.1 | ||
$vcard->add('ADR', [ | ||
'', | ||
$address->line_1, | ||
$address->line_2, | ||
$address->city, | ||
$address->province, | ||
$address->postal_code, | ||
$address->country, | ||
], $address->addressType ? [ | ||
'TYPE' => $address->addressType->name, | ||
] : []); | ||
} | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
app/Domains/Contact/ManageContact/Dav/ExportContactInformation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
namespace App\Domains\Contact\ManageContact\Dav; | ||
|
||
use App\Domains\Contact\Dav\Exporter; | ||
use App\Domains\Contact\Dav\ExportVCardResource; | ||
use App\Domains\Contact\Dav\Order; | ||
use App\Models\Contact; | ||
use App\Models\ContactInformation; | ||
use Sabre\VObject\Component\VCard; | ||
|
||
/** | ||
* @implements ExportVCardResource<Contact> | ||
*/ | ||
#[Order(30)] | ||
class ExportContactInformation extends Exporter implements ExportVCardResource | ||
{ | ||
public function getType(): string | ||
{ | ||
return Contact::class; | ||
} | ||
|
||
/** | ||
* @param Contact $resource | ||
*/ | ||
public function export(mixed $resource, VCard $vcard): void | ||
{ | ||
$vcard->remove('TEL'); | ||
$vcard->remove('EMAIL'); | ||
$vcard->remove('socialProfile'); | ||
$vcard->remove('URL'); | ||
|
||
$resource->contactInformations | ||
->each(fn ($contactInformation) => $this->addContactInformationToVCard($vcard, $contactInformation)); | ||
} | ||
|
||
private function addContactInformationToVCard(VCard $vcard, ContactInformation $contactInformation) | ||
{ | ||
switch ($contactInformation->contactInformationType->name) { | ||
case trans('Email address'): | ||
// https://datatracker.ietf.org/doc/html/rfc6350#section-6.4.2 | ||
$vcard->add('EMAIL', $contactInformation->data, [ | ||
// 'TYPE' => $contactInformation->contactInformationType->type, | ||
]); | ||
break; | ||
case trans('Phone'): | ||
// https://datatracker.ietf.org/doc/html/rfc6350#section-6.4.1 | ||
$vcard->add('TEL', $contactInformation->data, [ | ||
//'TYPE' => $contactInformation->contactInformationType->type, | ||
]); | ||
break; | ||
case trans('Facebook'): | ||
$vcard->add('socialProfile', $this->escape('https://www.facebook.com/'.$contactInformation->data), [ | ||
'TYPE' => 'facebook', | ||
]); | ||
break; | ||
case trans('Mastodon'): | ||
$vcard->add('socialProfile', $this->escape($contactInformation->data), [ | ||
'TYPE' => 'Mastodon', | ||
]); | ||
break; | ||
case trans('Whatsapp'): | ||
$vcard->add('socialProfile', $this->escape('https://wa.me/'.$contactInformation->data), [ | ||
'TYPE' => 'whatsapp', | ||
]); | ||
break; | ||
case trans('Telegram'): | ||
$vcard->add('socialProfile', $this->escape('https://t.me/'.$contactInformation->data), [ | ||
'TYPE' => 'telegram', | ||
]); | ||
break; | ||
case trans('LinkedIn'): | ||
$vcard->add('socialProfile', $this->escape('https://www.linkedin.com/in/'.$contactInformation->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($type = $contactInformation->contactInformationType->type)) { | ||
$vcard->add('URL', $this->escape($type.$contactInformation->data)); | ||
} | ||
break; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/Domains/Contact/ManageContact/Dav/ExportImportantDates.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Domains\Contact\ManageContact\Dav; | ||
|
||
use App\Domains\Contact\Dav\Exporter; | ||
use App\Domains\Contact\Dav\ExportVCardResource; | ||
use App\Domains\Contact\Dav\Order; | ||
use App\Models\Contact; | ||
use App\Models\ContactImportantDate; | ||
use Illuminate\Support\Str; | ||
use Sabre\VObject\Component\VCard; | ||
|
||
/** | ||
* @implements ExportVCardResource<Contact> | ||
*/ | ||
#[Order(40)] | ||
class ExportImportantDates extends Exporter implements ExportVCardResource | ||
{ | ||
public function getType(): string | ||
{ | ||
return Contact::class; | ||
} | ||
|
||
/** | ||
* @param Contact $resource | ||
*/ | ||
public function export(mixed $resource, VCard $vcard): void | ||
{ | ||
$vcard->remove('BDAY'); | ||
|
||
$resource->importantDates | ||
->each(fn ($importantDate) => $this->addImportantDateToVCard($vcard, $importantDate)); | ||
} | ||
|
||
public function addImportantDateToVCard(VCard $vcard, ContactImportantDate $importantDate) | ||
{ | ||
if (($type = $importantDate->contactImportantDateType) !== null && mb_strtolower($type->label) === ContactImportantDate::TYPE_BIRTHDATE) { | ||
$date = $importantDate->year ? Str::padLeft((string) $importantDate->year, 2, '0') : '--'; | ||
$date .= $importantDate->month ? Str::padLeft((string) $importantDate->month, 2, '0') : '--'; | ||
$date .= $importantDate->day ? Str::padLeft((string) $importantDate->day, 2, '0') : '--'; | ||
|
||
// https://datatracker.ietf.org/doc/html/rfc6350#section-6.2.5 | ||
$vcard->add('BDAY', $date); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
app/Domains/Contact/ManageContact/Dav/ExportWorkInformation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Domains\Contact\ManageContact\Dav; | ||
|
||
use App\Domains\Contact\Dav\Exporter; | ||
use App\Domains\Contact\Dav\ExportVCardResource; | ||
use App\Domains\Contact\Dav\Order; | ||
use App\Models\Contact; | ||
use Sabre\VObject\Component\VCard; | ||
|
||
/** | ||
* @implements ExportVCardResource<Contact> | ||
*/ | ||
#[Order(40)] | ||
class ExportWorkInformation extends Exporter implements ExportVCardResource | ||
{ | ||
public function getType(): string | ||
{ | ||
return Contact::class; | ||
} | ||
|
||
/** | ||
* @param Contact $resource | ||
*/ | ||
public function export(mixed $resource, VCard $vcard): void | ||
{ | ||
$vcard->remove('ORG'); | ||
$vcard->remove('TITLE'); | ||
|
||
if (($company = $resource->company) !== null) { | ||
// https://datatracker.ietf.org/doc/html/rfc6350#section-6.6.4 | ||
$vcard->add('ORG', $this->escape($company->name)); | ||
} | ||
|
||
if (! empty($resource->job_position)) { | ||
// https://datatracker.ietf.org/doc/html/rfc6350#section-6.6.1 | ||
$vcard->add('TITLE', $this->escape($resource->job_position)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
<?php | ||
|
||
use function Safe\parse_url; | ||
|
||
/** | ||
* Laravel - A PHP Framework For Web Artisans | ||
* | ||
|
Oops, something went wrong.