forked from nuovo/vCard-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
216 lines (202 loc) · 4.57 KB
/
test.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<style type="text/css">
body
{
font-family: Corbel, Arial, sans-serif;
padding: 20px 50px;
}
div.Agent
{
padding: 20px;
border: 1px solid #ddd;
background-color: #fafafa;
}
img
{
float: right;
margin: 10px;
padding: 10px;
border: 1px solid #ddd;
}
</style>
</head>
<body>
<?php
require_once('vCard.php');
/**
* Test function for vCard content output
* @param vCard vCard object
*/
function OutputvCard(vCard $vCard)
{
echo '<h2>'.$vCard -> FN[0].'</h2>';
if ($vCard -> PHOTO)
{
foreach ($vCard -> PHOTO as $Photo)
{
if ($Photo['Encoding'] == 'b')
{
echo '<img src="data:image/'.$Photo['Type'][0].';base64,'.$Photo['Value'].'" /><br />';
}
else
{
echo '<img src="'.$Photo['Value'].'" /><br />';
}
/*
// It can also be saved to a file
try
{
$vCard -> SaveFile('photo', 0, 'test_image.jpg');
// The parameters are:
// - name of the file we want to save (photo, logo or sound)
// - index of the file in case of multiple files (defaults to 0)
// - target path to save to, including the filenam
}
catch (Exception $E)
{
// Target path not writable
}
*/
}
}
foreach ($vCard -> N as $Name)
{
echo '<h3>Name: '.$Name['FirstName'].' '.$Name['LastName'].'</h3>';
}
foreach ($vCard -> ORG as $Organization)
{
echo '<h3>Organization: '.$Organization['Name'].
($Organization['Unit1'] || $Organization['Unit2'] ?
' ('.implode(', ', array($Organization['Unit1'], $Organization['Unit2'])).')' :
''
).'</h3>';
}
if ($vCard -> TEL)
{
echo '<p><h4>Phone</h4>';
foreach ($vCard -> TEL as $Tel)
{
if (is_scalar($Tel))
{
echo $Tel.'<br />';
}
else
{
echo $Tel['Value'].' ('.implode(', ', $Tel['Type']).')<br />';
}
}
echo '</p>';
}
if ($vCard -> EMAIL)
{
echo '<p><h4>Email</h4>';
foreach ($vCard -> EMAIL as $Email)
{
if (is_scalar($Email))
{
echo $Email;
}
else
{
echo $Email['Value'].' ('.implode(', ', $Email['Type']).')<br />';
}
}
echo '</p>';
}
if ($vCard -> URL)
{
echo '<p><h4>URL</h4>';
foreach ($vCard -> URL as $URL)
{
if (is_scalar($URL))
{
echo $URL.'<br />';
}
else
{
echo $URL['Value'].'<br />';
}
}
echo '</p>';
}
if ($vCard -> IMPP)
{
echo '<p><h4>Instant messaging</h4>';
foreach ($vCard -> IMPP as $IMPP)
{
if (is_scalar($IMPP))
{
echo $IMPP.'<br />';
}
else
{
echo $IMPP['Value'].'<br/ >';
}
}
echo '</p>';
}
if ($vCard -> ADR)
{
foreach ($vCard -> ADR as $Address)
{
echo '<p><h4>Address ('.implode(', ', $Address['Type']).')</h4>';
echo 'Street address: <strong>'.($Address['StreetAddress'] ? $Address['StreetAddress'] : '-').'</strong><br />'.
'PO Box: <strong>'.($Address['POBox'] ? $Address['POBox'] : '-').'</strong><br />'.
'Extended address: <strong>'.($Address['ExtendedAddress'] ? $Address['ExtendedAddress'] : '-').'</strong><br />'.
'Locality: <strong>'.($Address['Locality'] ? $Address['Locality'] : '-').'</strong><br />'.
'Region: <strong>'.($Address['Region'] ? $Address['Region'] : '-').'</strong><br />'.
'ZIP/Post code: <strong>'.($Address['PostalCode'] ? $Address['PostalCode'] : '-').'</strong><br />'.
'Country: <strong>'.($Address['Country'] ? $Address['Country'] : '-').'</strong>';
}
echo '</p>';
}
if ($vCard -> AGENT)
{
echo '<h4>Agents</h4>';
foreach ($vCard -> AGENT as $Agent)
{
if (is_scalar($Agent))
{
echo '<div class="Agent">'.$Agent.'</div>';
}
elseif (is_a($Agent, 'vCard'))
{
echo '<div class="Agent">';
OutputvCard($Agent);
echo '</div>';
}
}
}
}
$vCard = new vCard(
'Example3.0.vcf', // Path to vCard file
false, // Raw vCard text, can be used instead of a file
array( // Option array
// This lets you get single values for elements that could contain multiple values but have only one value.
// This defaults to false so every value that could have multiple values is returned as array.
'Collapse' => false
)
);
if (count($vCard) == 0)
{
throw new Exception('vCard test: empty vCard!');
}
// if the file contains a single vCard, it is accessible directly.
elseif (count($vCard) == 1)
{
OutputvCard($vCard);
}
// if the file contains multiple vCards, they are accessible as elements of an array
else
{
foreach ($vCard as $Index => $vCardPart)
{
OutputvCard($vCardPart);
}
}
?>
</body>
</html>