/
contact-vcard.php
81 lines (65 loc) · 2.33 KB
/
contact-vcard.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
(@include_once '../../config.core.php') or die("core configuration file not found");
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
$path = $modx->getOption('clientconfig.core_path', null, $modx->getOption('core_path') . 'components/clientconfig/');
$path .= 'model/clientconfig/';
$clientConfig = $modx->getService('clientconfig','ClientConfig', $path);
if ($clientConfig instanceof ClientConfig) {
$settings = $clientConfig->getSettings();
}
$companyName = $modx->getOption('site_name');
$siteUrl = $modx->getOption('site_url');
if($_GET['id']){
$resource = $modx->getObject('modResource', $_GET['id']);
$image = $resource->getTVValue('photo');
$street = $resource->getTVValue('street');
$housenumber = $resource->getTVValue('housenumber');
$zipcode = $resource->getTVValue('zipcode');
$city = $resource->getTVValue('city');
$fax = $resource->getTVValue('fax');
$phone = $resource->getTVValue('phone');
$email = $resource->getTVValue('email');
$fullName = $resource->get('pagetitle');
}
else {
$image = $settings['vcard_logo'];
$street = $settings['street'];
$housenumber = $settings['housenumber'];
$zipcode = $settings['zipcode'];
$city = $settings['city'];
$fax = $settings['fax'];
$phone = $settings['phone'];
$email = $settings['email_client'];
$fullName = $companyName;
}
$getPhoto = file_get_contents($siteUrl . $image);
$b64vcard = base64_encode($getPhoto);
$b64mline = chunk_split($b64vcard,74,"\n");
$b64final = preg_replace('/(.+)/', ' $1', $b64mline);
$photo = $b64final;
header('Content-Type: text/x-vcard');
header('Content-Disposition: inline; filename= "vCard.vcf"');
$vCard = "BEGIN:VCARD\r\n";
$vCard .= "VERSION:3.0\r\n";
$vCard .= "FN:" . $fullName . "\r\n";
$vCard .= "TITLE:" . $companyName . "\r\n";
if($street or $zipcode OR $city){
$vCard .= "ADR;TYPE=work:;;" . $street . ' ' . $housenumber . ";" . $city . ";IL;" . $zipcode . ";\r\n";
}
if($fax){
$vCard .= "TEL;FAX;WORK:" . $fax . "\r\n";
}
if($email){
$vCard .= "EMAIL;TYPE=internet,pref:" . $email . "\r\n";
}
if($getPhoto){
$vCard .= "PHOTO;ENCODING=b;TYPE=JPEG:";
$vCard .= $photo . "\r\n";
}
if($phone){
$vCard .= "TEL;TYPE=work,voice:" . $phone . "\r\n";
}
$vCard .= "END:VCARD\r\n";
echo $vCard;