Easily generate VCard for your contact profiles
- Kirby V3
- PHP 7.1+
get_headers()
configurated on the server byallow_url_fopen=1
You have three different methods:
Download and copy this repository to /site/plugins/vcard-kirby3
git submodule add https://github.com/isaactopo/vcard-kirby3.git site/plugins/vcard-kirby3
composer require isaactopo/vcard-kirby3
After installing the VCard Plugin you need to create a controller for your page, for example a profile page: site/controllers/profile.php
:
With this controller you can pass a variable to your controller like: yourdomain.com/profile/vcard:download it could be download
or whatever you like if the param vcard
is present
<?php
return function ($page, $pages, $site, $kirby) {
if ($vcard = param('vcard')) {
// Get the VCard Instance
$vcard = $site->vcard();
// Define Variables
$additional = '';
$prefix = '';
$suffix = '';
$lastname = '';
// Get Your data from your Fields
$firstname = $page->firstName();
// add personal data
$vcard->addName($lastname, $firstname, $additional, $prefix, $suffix);
// add work data
$vcard->addCompany('DaCompany');
$vcard->addJobtitle('Web Developer');
$vcard->addRole('Code reviewer');
$vcard->addEmail('[email protected]');
$vcard->addPhoneNumber(666666666, 'PREF;WORK');
$vcard->addPhoneNumber(93888666222, 'WORK');
$vcard->addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium');
$vcard->addLabel('street, worktown, workpostcode Belgium');
$vcard->addURL('http://topo.bz');
// Add a photo
if($img = $page->profilePicture()->toFile()){
$img = $img->crop(400, 400, 85)->save()->root();
$vcard->addPhoto($img);
}
return $vcard->download();
}
}
For Debugging you can echo the VCard as a String
// return vcard as a string
echo $vcard->getOutput();
You can save the VCard on Disk too:
// save vcard on disk
$vcard->setSavePath('/path/to/directory');
$vcard->save();
If you have problems attaching the profile image try to pass the image item as a parameter instead the image URL:
- $vcard->addPhoto($img->url());
+ $vcard->addPhoto($img);
I found certain special characters problems on some servers and solved it specifying:
$vcard->setCharset('ISO-8859-1');
and UTF-Decoding fields:
$firstname = utf8_decode($page->firstName());
This plugin is free but Kirby needs a license
This is a Wrapper for the jeroendesloovere/vcard library.