isaactopo / vcard-kirby3
Kirby 3 的 VCard 插件
0.0.1
2020-05-30 11:57 UTC
Requires
This package is auto-updated.
Last update: 2024-09-29 05:29:49 UTC
README
轻松生成您的联系资料的 VCard
需求
- Kirby V3
- PHP 7.1+
get_headers()
在服务器上配置为allow_url_fopen=1
安装方法
您有三种不同的方法
下载
下载并复制此仓库到 /site/plugins/vcard-kirby3
Git 子模块
git submodule add https://github.com/isaactopo/vcard-kirby3.git site/plugins/vcard-kirby3
Composer
composer require isaactopo/vcard-kirby3
用法
安装 VCard 插件后,您需要为您的页面创建一个控制器,例如个人资料页面:site/controllers/profile.php
: 使用此控制器,您可以将变量传递给控制器,例如:yourdomain.com/profile/vcard:download,它可以是一个 download
或您喜欢的任何名称,如果存在 vcard
参数
<?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('info@topo.bz'); $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(); } }
调试时,您可以以字符串形式输出 VCard
// return vcard as a string echo $vcard->getOutput();
您还可以将 VCard 保存到磁盘上
// save vcard on disk $vcard->setSavePath('/path/to/directory'); $vcard->save();
故障排除
VCard 图片
如果您在附加个人资料图片时遇到问题,请尝试将图片项作为参数传递,而不是图片 URL
- $vcard->addPhoto($img->url()); + $vcard->addPhoto($img);
字符集编码
我在某些服务器上发现了一些特殊字符问题,并通过指定解决
$vcard->setCharset('ISO-8859-1');
和 UTF-Decoding 字段
$firstname = utf8_decode($page->firstName());
许可
此插件免费,但 Kirby 需要许可证
致谢
这是 jeroendesloovere/vcard 库的包装器。