1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the 2amigos/yii2-qrcode-component project. |
5
|
|
|
* |
6
|
|
|
* (c) 2amigOS! <http://2amigos.us/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view |
9
|
|
|
* the LICENSE file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Da\QrCode\Format; |
13
|
|
|
|
14
|
|
|
use Da\QrCode\Exception\InvalidConfigException; |
15
|
|
|
use Da\QrCode\Traits\EmailTrait; |
16
|
|
|
use Da\QrCode\Traits\UrlTrait; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class vCard creates a valid vCard 4.0 QrCode string |
20
|
|
|
* |
21
|
|
|
* @author Antonio Ramirez <[email protected]> |
22
|
|
|
* @link http://www.ramirezcobos.com/ |
23
|
|
|
* @link http://www.2amigos.us/ |
24
|
|
|
* @package Da\QrCode\Format |
25
|
|
|
*/ |
26
|
|
|
class vCardFormat extends AbstractFormat |
27
|
|
|
{ |
28
|
|
|
use EmailTrait; |
29
|
|
|
use UrlTrait; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var string the name |
33
|
|
|
*/ |
34
|
|
|
public $name; |
35
|
|
|
/** |
36
|
|
|
* @var string the full name |
37
|
|
|
*/ |
38
|
|
|
public $fullName; |
39
|
|
|
/** |
40
|
|
|
* @var string the address |
41
|
|
|
*/ |
42
|
|
|
public $address; |
43
|
|
|
/** |
44
|
|
|
* @var string the nickname |
45
|
|
|
*/ |
46
|
|
|
public $nickName; |
47
|
|
|
/** |
48
|
|
|
* @var string the work phone |
49
|
|
|
*/ |
50
|
|
|
public $workPhone; |
51
|
|
|
/** |
52
|
|
|
* @var string the home phone |
53
|
|
|
*/ |
54
|
|
|
public $homePhone; |
55
|
|
|
/** |
56
|
|
|
* @var string a date in the format YYYY-MM-DD or ISO 860 |
57
|
|
|
*/ |
58
|
|
|
public $birthday; |
59
|
|
|
/** |
60
|
|
|
* @var string a date in the format YYYY-MM-DD or ISO 860 |
61
|
|
|
*/ |
62
|
|
|
public $anniversary; |
63
|
|
|
/** |
64
|
|
|
* @var string the gender |
65
|
|
|
*/ |
66
|
|
|
public $gender; |
67
|
|
|
/** |
68
|
|
|
* @var string the categories. A list of "tags" that can be used to describe the object represented by this vCard. |
69
|
|
|
* e.g., developer,designer,climber,swimmer |
70
|
|
|
*/ |
71
|
|
|
public $categories; |
72
|
|
|
/** |
73
|
|
|
* @var string the instant messaging and presence protocol (instant messenger id) |
74
|
|
|
*/ |
75
|
|
|
public $impp; |
76
|
|
|
/** |
77
|
|
|
* @var string the photo |
78
|
|
|
*/ |
79
|
|
|
public $photo; |
80
|
|
|
/** |
81
|
|
|
* @var string the role e.g., Executive |
82
|
|
|
*/ |
83
|
|
|
public $role; |
84
|
|
|
/** |
85
|
|
|
* @var string the name and optionally the unit(s) of the organization |
86
|
|
|
* associated with the vCard object. This property is based on the X.520 Organization Name |
87
|
|
|
* attribute and the X.520 Organization Unit attribute. |
88
|
|
|
*/ |
89
|
|
|
public $organization; |
90
|
|
|
/** |
91
|
|
|
* @var string notes |
92
|
|
|
*/ |
93
|
|
|
public $note; |
94
|
|
|
/** |
95
|
|
|
* @var string language of the user |
96
|
|
|
*/ |
97
|
|
|
public $lang; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @return string |
101
|
|
|
*/ |
102
|
|
|
public function getText() |
103
|
|
|
{ |
104
|
|
|
$data = []; |
105
|
|
|
$data[] = "BEGIN:VCARD"; |
106
|
|
|
$data[] = "VERSION:4.0"; |
107
|
|
|
$data[] = "N:{$this->name}"; |
108
|
|
|
$data[] = "FN:{$this->fullName}"; |
109
|
|
|
$data[] = "ADR:{$this->address}"; |
110
|
|
|
$data[] = "NICKNAME:{$this->nickName}"; |
111
|
|
|
$data[] = "EMAIL;TYPE=PREF,INTERNET:{$this->email}"; |
112
|
|
|
$data[] = "TEL;TYPE=WORK:{$this->workPhone}"; |
113
|
|
|
$data[] = "TEL;TYPE=HOME:{$this->homePhone}"; |
114
|
|
|
$data[] = "BDAY:{$this->birthday}"; |
115
|
|
|
$data[] = "GENDER:{$this->gender}"; |
116
|
|
|
$data[] = "IMPP:{$this->impp}"; |
117
|
|
|
$data[] = $this->getFormattedPhoto(); |
118
|
|
|
$data[] = "ROLE:{$this->role}"; |
119
|
|
|
$data[] = "URL:{$this->url}"; |
120
|
|
|
$data[] = "ORG:{$this->organization}"; |
121
|
|
|
$data[] = "NOTE:{$this->note}"; |
122
|
|
|
$data[] = "ORG:{$this->organization}"; |
123
|
|
|
$data[] = "LANG:{$this->lang}"; |
124
|
|
|
$data[] = "END:VCARD"; |
125
|
|
|
|
126
|
|
|
return implode("\n", array_filter($data)); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* @throws \yii\base\InvalidConfigException |
131
|
|
|
* @return string the formatted photo. Makes sure is of the right image extension. |
132
|
|
|
*/ |
133
|
|
|
protected function getFormattedPhoto() |
134
|
|
|
{ |
135
|
|
|
if ($this->photo !== null) { |
136
|
|
|
$ext = strtolower(substr(strrchr($this->photo, '.'), 1)); |
137
|
|
|
if ($ext == 'jpeg' || $ext == 'jpg' || $ext == 'png' || $ext == 'gif') { |
138
|
|
|
$ext = strtoupper($ext); |
139
|
|
|
} else { |
140
|
|
|
throw new InvalidConfigException('Invalid format Image!'); |
141
|
|
|
} |
142
|
|
|
return 'PHOTO;VALUE=URL;TYPE=' . $ext . ':' . $this->photo; |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
return null; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|