You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.9 KiB
56 lines
1.9 KiB
<?php
|
|
namespace app\common\lib;
|
|
|
|
use think\facade\Db;
|
|
|
|
use JeroenDesloovere\VCard\VCard as VCardApi;
|
|
|
|
class Vcard{
|
|
|
|
public static function genVcf($userid){
|
|
$userInfo = Db::name('user')->where('user_id',$userid)->find();
|
|
if(!$userInfo){
|
|
return false;
|
|
}
|
|
$vcard = new VCardApi();
|
|
|
|
$lastname = $userInfo['real_name'];
|
|
$firstname = '';
|
|
$additional = '';
|
|
$prefix = '';
|
|
$suffix = '';
|
|
|
|
$vcard->addName($lastname, $firstname, $additional, $prefix, $suffix);
|
|
|
|
// add work data
|
|
$vcard->addCompany($userInfo['company']);
|
|
$vcard->addJobtitle($userInfo['title']);
|
|
// $vcard->addRole('Data Protection Officer');
|
|
$vcard->addEmail($userInfo['email']);
|
|
$vcard->addPhoneNumber($userInfo['phone'], 'PREF;CELL');
|
|
$vcard->addPhoneNumber($userInfo['tel'], 'WORK');
|
|
// $vcard->addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium');
|
|
// $vcard->addLabel('street, worktown, workpostcode Belgium');
|
|
if($userInfo['url']){
|
|
// $vcard->addURL(getUrl().'/card/?userid='.$userInfo['user_id']);
|
|
$vcard->addURL($userInfo['url']);
|
|
}
|
|
|
|
// $vcard->addPhoto(__DIR__.'/../../../public/storage/'.$userInfo['user_id'].'/'.$userInfo['user_id'].'_line.jpg');
|
|
|
|
// return vcard as a string
|
|
//return $vcard->getOutput();
|
|
|
|
// return vcard as a download
|
|
// return $vcard->download();
|
|
//判斷目錄是否存在,不存在則建立
|
|
if(!is_dir(__DIR__.'/../../../public/storage/'.$userInfo['user_id'])){
|
|
mkdir(__DIR__.'/../../../public/storage/'.$userInfo['user_id'],0777,true);
|
|
}
|
|
|
|
$vcard->setSavePath(__DIR__.'/../../../public/storage/'.$userInfo['user_id'].'/');
|
|
$vcard->setFilename($userInfo['user_id']);
|
|
$vcard->save();
|
|
return true;
|
|
}
|
|
} |