Projet

Général

Profil

Paste
Statistiques
| Branche: | Révision:

ryxeo-glpi-git / lib / vcardclass / classes-vcard.php @ b67d8923

Historique | Voir | Annoter | Télécharger (5,79 ko)

1
<?php
2
/**************************************************************************
3
PHP vCard class v2.0
4
(c) Kai Blankenhorn
5
www.bitfolge.de/en
6
kaib@bitfolge.de
7
This program is free software; you can redistribute it and/or
8
modify it under the terms of the GNU General Public License
9
as published by the Free Software Foundation; either version 2
10
of the License, or (at your option) any later version.
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
***************************************************************************/
19

    
20

    
21
function encode($string) {
22
    return escape(quoted_printable_encode($string));
23
}
24

    
25
function escape($string) {
26
    return str_replace(";","\;",$string);
27
}
28

    
29
// taken from PHP documentation comments
30
function quoted_printable_encode($input, $line_max = 76) {
31
    $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
32
    $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
33
    $eol = "\r\n";
34
    $linebreak = "=0D=0A";
35
    $escape = "=";
36
    $output = "";
37

    
38
    for ($j=0;$j<count($lines);$j++) {
39
        $line = $lines[$j];
40
        $linlen = strlen($line);
41
        $newline = "";
42
        for($i = 0; $i < $linlen; $i++) {
43
            $c = substr($line, $i, 1);
44
            $dec = ord($c);
45
            if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
46
                $c = "=20"; 
47
            } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
48
                $h2 = floor($dec/16); $h1 = floor($dec%16); 
49
                $c = $escape.$hex["$h2"].$hex["$h1"]; 
50
            }
51
            if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
52
                $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
53
                $newline = "    ";
54
            }
55
            $newline .= $c;
56
        } // end of for
57
        $output .= $newline;
58
        if ($j<count($lines)-1) $output .= $linebreak;
59
    }
60
    return trim($output);
61
}
62

    
63
class vCard {
64
    var $properties;
65
    var $filename;
66
    
67
    function setPhoneNumber($number, $type="") {
68
    // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE"
69
        $key = "TEL";
70
        if ($type!="") $key .= ";".$type;
71
        $key.= ";ENCODING=QUOTED-PRINTABLE";
72
        $this->properties[$key] = quoted_printable_encode($number);
73
    }
74
    
75
    // UNTESTED !!!
76
    function setPhoto($type, $photo) { // $type = "GIF" | "JPEG"
77
        $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo);
78
    }
79
    
80
    function setFormattedName($name) {
81
        $this->properties["FN"] = quoted_printable_encode($name);
82
    }
83
    
84
    function setName($family="", $first="", $additional="", $prefix="", $suffix="") {
85
        $this->properties["N"] = "$family;$first;$additional;$prefix;$suffix";
86
        // MODIF GLPI
87
        if (empty($first))
88
                $this->filename = "$family.vcf";
89
        else 
90
                $this->filename = "$first%20$family.vcf";
91
     //   if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
92
    }
93
    
94
    function setBirthday($date) { // $date format is YYYY-MM-DD
95
        $this->properties["BDAY"] = $date;
96
    }
97
    
98
    function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") {
99
    // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
100
        $key = "ADR";
101
        if ($type!="") $key.= ";$type";
102
        $key.= ";ENCODING=QUOTED-PRINTABLE";
103
        $this->properties[$key] = encode($postoffice).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
104
        
105
//        if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == "") {
106
            //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type);
107
        //}
108
    }
109
    
110
    function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") {
111
        $label = "";
112
        if ($postoffice!="") $label.= "$postoffice\r\n";
113
        if ($extended!="") $label.= "$extended\r\n";
114
        if ($street!="") $label.= "$street\r\n";
115
        if ($zip!="") $label.= "$zip ";
116
        if ($city!="") $label.= "$city\r\n";
117
        if ($region!="") $label.= "$region\r\n";
118
        if ($country!="") $country.= "$country\r\n";
119
        
120
        $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label);
121
    }
122
    
123
    function setEmail($address) {
124
        $this->properties["EMAIL;INTERNET"] = $address;
125
    }
126
    
127
    function setNote($note) {
128
        $this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note);
129
    }
130
    
131
    function setURL($url, $type="") {
132
    // $type may be WORK | HOME
133
        $key = "URL";
134
        if ($type!="") $key.= ";$type";
135
        $this->properties[$key] = $url;
136
    }
137
    
138
    function getVCard() {
139
        $text = "BEGIN:VCARD\r\n";
140
        $text.= "VERSION:2.1\r\n";
141
        foreach($this->properties as $key => $value) {
142
            $text.= "$key:$value\r\n";
143
        }
144
        $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n";
145
        $text.= "MAILER:PHP vCard class by Kai Blankenhorn\r\n";
146
        $text.= "END:VCARD\r\n";
147
        return $text;
148
    }
149
    
150
    function getFileName() {
151
        return $this->filename;
152
    }
153
}
154
?>
Redmine Appliance - Powered by TurnKey Linux