blob: cc2b6181e4e579876a230a9e16634895a288b7f2 (
plain)
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
|
<?php
/**
* vCard.php - HelperClass to ceate vCard string of a user object
*
* Use the export function to create a vCard string of a single user
* element or an array of userelements
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Florian Bieringer <florian.bieringer@uni-passau.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
* @copyright 2014 Stud.IP Core-Group
*/
class vCard {
/**
* Transforms a user or an array of users into a vCard export string
*
* @param User $users Userobject
* @return String vCard export string
*/
public static function export($users) {
// Non array fallback
if ($users instanceof User) {
return self::exportUser($users);
}
$export = '';
foreach ($users as $user) {
$export .= self::exportUser($user);
}
return $export;
}
/**
* Export of a single user
*
* @param User $user Userobject
* @return String vCard export string
*/
private static function exportUser(User $user) {
// If user is not visible export nothing
if (!get_visibility_by_id($user->id)) {
return "";
}
// vCard exportheader
$vCard['BEGIN'] = 'VCARD';
$vCard['VERSION'] = '3.0';
$vCard['PRODID'] = 'Stud.IP//' . Config::get()->UNI_NAME_CLEAN . '//DE';
$vCard['REV'] = date('Y-m-d H:i:s');
$vCard['TZ'] = date('O');
// User specific data
//Fullname
$vCard['FN'] = $user->getFullname();
//Name
$vCard['N'][] = $user->Nachname;
$vCard['N'][] = $user->Vorname;
$vCard['N'][] = $user->info->title_rear;
$vCard['N'][] = $user->info->title_front;
// Adress
if (Visibility::verify('privadr', $user->id)) {
$vCard['ADR;TYPE=HOME'] = $user->info->privadr;
}
// Tel
if (Visibility::verify('private_phone', $user->id)) {
$vCard['TEL;TYPE=HOME'] = $user->info->privatnr;
}
if (Visibility::verify('private_cell', $user->id)) {
$vCard['TEL;TYPE=CELL'] = $user->info->privatcell;
}
// Email
if (get_local_visibility_by_id($user->id, 'email')) {
$vCard['EMAIL'] = $user->email;
}
// Photo
if (Visibility::verify('picture', $user->id)) {
// Fetch avatar
$avatar = Avatar::getAvatar($user->id);
// Only export if
if ($avatar->is_customized()) {
$vCard['PHOTO;JPEG;ENCODING=BASE64'] = base64_encode(file_get_contents($avatar->getFilename(Avatar::NORMAL)));
}
}
// vCard end
$vCard['END'] = 'VCARD';
// Produce string
$exportString = '';
foreach ($vCard as $index => $value) {
$exportString .= $value ? $index . ':' . (is_array($value) ? join(';', $value) : $value) . "\r\n" : "";
}
return $exportString;
}
}
|