2 /***************************************************************************
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 ***************************************************************************/
27 function encode($string) {
28 return escape(quoted_printable_encode($string));
31 function escape($string) {
32 return str_replace(";","\;",$string);
35 if (!function_exists("quoted_printable_encode")) {
36 // taken from PHP documentation comments
37 function quoted_printable_encode($input, $line_max = 76) {
38 $hex = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
39 $lines = preg_split("/(?:\r\n|\r|\n)/", $input);
41 $linebreak = "=0D=0A";
45 for ($j=0;$j<count($lines);$j++) {
47 $linlen = strlen($line);
49 for($i = 0; $i < $linlen; $i++) {
50 $c = substr($line, $i, 1);
52 if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only
54 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode "\t", which is *not* required
55 $h2 = floor($dec/16); $h1 = floor($dec%16);
56 $c = $escape.$hex["$h2"].$hex["$h1"];
58 if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted
59 $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay
65 if ($j<count($lines)-1) $output .= $linebreak;
75 function setPhoneNumber($number, $type="") {
76 // 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"
78 if ($type!="") $key .= ";".$type;
79 $key.= ";ENCODING=QUOTED-PRINTABLE";
80 $this->properties[$key] = quoted_printable_encode($number);
84 function setPhoto($type, $photo) { // $type = "GIF" | "JPEG"
85 $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo);
88 function setFormattedName($name) {
89 $this->properties["FN"] = quoted_printable_encode($name);
92 function setName($family="", $first="", $additional="", $prefix="", $suffix="") {
93 $this->properties["N"] = "$family;$first;$additional;$prefix;$suffix";
94 $this->filename = "$first%20$family.vcf";
95 if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix"));
98 function setBirthday($date) { // $date format is YYYY-MM-DD
99 $this->properties["BDAY"] = $date;
102 function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") {
103 // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL"
105 if ($type!="") $key.= ";$type";
106 $key.= ";ENCODING=QUOTED-PRINTABLE";
107 $this->properties[$key] = encode($name).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country);
109 if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == "") {
110 //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type);
114 function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") {
116 if ($postoffice!="") $label.= "$postoffice\r\n";
117 if ($extended!="") $label.= "$extended\r\n";
118 if ($street!="") $label.= "$street\r\n";
119 if ($zip!="") $label.= "$zip ";
120 if ($city!="") $label.= "$city\r\n";
121 if ($region!="") $label.= "$region\r\n";
122 if ($country!="") $country.= "$country\r\n";
124 $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label);
127 function setEmail($address) {
128 $this->properties["EMAIL;INTERNET"] = $address;
131 function setNote($note) {
132 $this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note);
135 function setURL($url, $type="") {
136 // $type may be WORK | HOME
138 if ($type!="") $key.= ";$type";
139 $this->properties[$key] = $url;
142 function getVCard() {
143 $text = "BEGIN:VCARD\r\n";
144 $text.= "VERSION:2.1\r\n";
145 foreach($this->properties as $key => $value) {
146 $text.= "$key:$value\r\n";
148 $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n";
149 //$text.= "MAILER:PHP vCard class by Kai Blankenhorn\r\n";
150 $text.= "END:VCARD\r\n";
154 function getFileName() {
155 return $this->filename;