00001 <?PHP
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00035 function encode($string) {
00036
return escape(quoted_printable_encode($string));
00037 }
00038
00039 function escape($string) {
00040
return str_replace(
";",
"\;",$string);
00041 }
00042
00043
00044 function quoted_printable_encode($input, $line_max = 76) {
00045 $hex = array(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F');
00046 $lines = preg_split(
"/(?:\r\n|\r|\n)/", $input);
00047 $eol =
"\r\n";
00048 $linebreak =
"=0D=0A";
00049 $escape =
"=";
00050 $output =
"";
00051
00052
for ($j=0;$j<count($lines);$j++) {
00053 $line = $lines[$j];
00054 $linlen = strlen($line);
00055 $newline =
"";
00056
for($i = 0; $i < $linlen; $i++) {
00057 $c = substr($line, $i, 1);
00058 $dec = ord($c);
00059
if ( ($dec == 32) && ($i == ($linlen - 1)) ) {
00060 $c =
"=20";
00061 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
00062 $h2 = floor($dec/16); $h1 = floor($dec%16);
00063 $c = $escape.$hex[
"$h2"].$hex[
"$h1"];
00064 }
00065
if ( (strlen($newline) + strlen($c)) >= $line_max ) {
00066 $output .= $newline.$escape.$eol;
00067 $newline =
" ";
00068 }
00069 $newline .= $c;
00070 }
00071 $output .= $newline;
00072
if ($j<count($lines)-1) $output .= $linebreak;
00073 }
00074
return trim($output);
00075 }
00076
00083 class vCard {
00084 var $properties;
00085 var $filename;
00086
00093 function
setPhoneNumber($number, $type=
"") {
00094
00095 $key =
"TEL";
00096
if ($type!=
"") $key .=
";".$type;
00097 $key.=
";ENCODING=QUOTED-PRINTABLE";
00098 $this->properties[$key] = quoted_printable_encode($number);
00099 }
00100
00108
00109 function
setPhoto($type, $photo) {
00110 $this->properties[
"PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo);
00111 }
00112
00118 function
setFormattedName($name) {
00119 $this->properties[
"FN"] = quoted_printable_encode($name);
00120 }
00121
00131 function
setName($family=
"", $first=
"", $additional=
"", $prefix=
"", $suffix=
"") {
00132 $this->properties[
"N"] =
"$family;$first;$additional;$prefix;$suffix";
00133 $this->filename =
"$first%20$family.vcf";
00134
if ($this->properties[
"FN"]==
"") $this->setFormattedName(trim(
"$prefix $first $additional $family $suffix"));
00135 }
00136
00142 function
setBirthday($date) {
00143 $this->properties[
"BDAY"] = $date;
00144 }
00145
00158 function
setAddress($postoffice=
"", $extended=
"", $street=
"", $city=
"", $region=
"", $zip=
"", $country=
"", $type=
"HOME;POSTAL") {
00159
00160 $key =
"ADR";
00161
if ($type!=
"") $key.=
";$type";
00162 $key.=
";ENCODING=QUOTED-PRINTABLE";
00163 $this->properties[$key] = encode($name).
";".encode($extended).
";".encode($street).
";".encode($city).
";".encode($region).
";".encode($zip).
";".encode($country);
00164
00165
if ($this->properties[
"LABEL;$type;ENCODING=QUOTED-PRINTABLE"] ==
"") {
00166
00167 }
00168 }
00169
00182 function
setLabel($postoffice=
"", $extended=
"", $street=
"", $city=
"", $region=
"", $zip=
"", $country=
"", $type=
"HOME;POSTAL") {
00183 $label =
"";
00184
if ($postoffice!=
"") $label.=
"$postoffice\r\n";
00185
if ($extended!=
"") $label.=
"$extended\r\n";
00186
if ($street!=
"") $label.=
"$street\r\n";
00187
if ($zip!=
"") $label.=
"$zip ";
00188
if ($city!=
"") $label.=
"$city\r\n";
00189
if ($region!=
"") $label.=
"$region\r\n";
00190
if ($country!=
"") $country.=
"$country\r\n";
00191
00192 $this->properties[
"LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label);
00193 }
00194
00200 function
setEmail($address) {
00201 $this->properties[
"EMAIL;INTERNET"] = $address;
00202 }
00203
00209 function
setNote($note) {
00210 $this->properties[
"NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note);
00211 }
00212
00219 function
setURL($url, $type=
"") {
00220
00221 $key =
"URL";
00222
if ($type!=
"") $key.=
";$type";
00223 $this->properties[$key] = $url;
00224 }
00225
00230 function
getVCard() {
00231 $text =
"BEGIN:VCARD\r\n";
00232 $text.=
"VERSION:2.1\r\n";
00233 foreach($this->properties as $key => $value) {
00234 $text.=
"$key:$value\r\n";
00235 }
00236 $text.=
"REV:".date(
"Y-m-d").
"T".date(
"H:i:s").
"Z\r\n";
00237 $text.=
"MAILER:PHP vCard class by Kai Blankenhorn\r\n";
00238 $text.=
"END:VCARD\r\n";
00239
return $text;
00240 }
00241
00246 function
getFileName() {
00247
return $this->filename;
00248 }
00249 }
00250 ?>