37 define (
"ADR_TYPE_NONE", 0);
38 define (
"ADR_TYPE_DOM", 1);
39 define (
"ADR_TYPE_INTL", 2);
40 define (
"ADR_TYPE_POSTAL", 4);
41 define (
"ADR_TYPE_PARCEL", 8);
42 define (
"ADR_TYPE_HOME", 16);
43 define (
"ADR_TYPE_WORK", 32);
44 define (
"ADR_TYPE_PREF", 64);
51 define (
"TEL_TYPE_NONE", 0);
52 define (
"TEL_TYPE_HOME", 1);
53 define (
"TEL_TYPE_MSG", 2);
54 define (
"TEL_TYPE_WORK", 4);
55 define (
"TEL_TYPE_PREF", 8);
56 define (
"TEL_TYPE_VOICE", 16);
57 define (
"TEL_TYPE_FAX", 32);
58 define (
"TEL_TYPE_CELL", 64);
59 define (
"TEL_TYPE_VIDEO", 128);
60 define (
"TEL_TYPE_PAGER", 256);
61 define (
"TEL_TYPE_BBS", 512);
62 define (
"TEL_TYPE_MODEM", 1024);
63 define (
"TEL_TYPE_CAR", 2048);
64 define (
"TEL_TYPE_ISDN", 4096);
65 define (
"TEL_TYPE_PCS", 8192);
72 define (
"EMAIL_TYPE_NONE", 0);
73 define (
"EMAIL_TYPE_INTERNET", 1);
74 define (
"EMAIL_TYPE_x400", 2);
75 define (
"EMAIL_TYPE_PREF", 4);
100 $this->types =
array(
157 function fold($string =
"", $length = 75)
160 preg_match_all(
"/(.{1,74})/", $string, $matches);
161 for ($i = 0; $i < count($matches[1]); $i++)
163 if ($i < (count($matches[1])-1))
165 $matches[1][$i] .=
"\n";
169 $matches[1][$i] =
" " . $matches[1][$i];
171 $folded_string .= $matches[1][$i];
173 return $folded_string;
187 $string = preg_replace(
"/(?<!\\\\)(\\\\)([^;,n\\\\])/",
"\${1}\${1}\${2}", $string);
188 $string = preg_replace(
"/(?<!\\\\);/",
"\\;", $string);
189 $string = preg_replace(
"/(?<!\\\\),/",
"\\,", $string);
190 $string = preg_replace(
"/\n/",
"\\n", $string);
206 $exploded = explode($separator, $variable);
207 foreach ($exploded as $index => $var)
209 $exploded[$index] = $this->
escape($var);
224 $vcard =
"BEGIN:VCARD\n";
225 $vcard .=
"VERSION:" . $this->types[
"VERSION"] .
"\n";
226 foreach ($this->types as $type => $var)
234 if (strcmp($this->types[
"FN"],
"") != 0)
236 $fn = $this->
fold(
"FN:" . $this->types[
"FN"]) .
"\n";
244 if (strcmp($this->types[
"N"],
"") != 0)
246 $n = $this->
fold(
"N:" . $this->types[
"N"]) .
"\n";
254 if (strcmp($this->types[
"NICKNAME"],
"") != 0)
256 $nickname = $this->
fold(
"NICKNAME:" . $this->types[
"NICKNAME"]) .
"\n";
265 if (is_array($this->types[
"PHOTO"]))
267 if (strcmp($this->types[
"PHOTO"][
"VALUE"],
"") != 0)
269 $photo = $this->
fold(
"PHOTO;VALUE=uri:" . $this->types[
"PHOTO"][
"VALUE"]) .
"\n";
271 elseif (strcmp($this->types[
"PHOTO"][
"ENCODING"],
"") != 0)
273 $photo =
"PHOTO;ENCODING=" . $this->types[
"PHOTO"][
"ENCODING"];
274 if (strcmp($this->types[
"PHOTO"][
"TYPE"],
"") != 0)
276 $photo .=
";TYPE=" . $this->types[
"PHOTO"][
"TYPE"];
278 $photo .=
":" . $this->types[
"PHOTO"][
"PHOTO"];
279 $photo = $this->
fold($photo) .
"\n";
284 if (strcmp($this->types[
"BDAY"],
"") != 0)
286 $bday = $this->
fold(
"BDAY:" . $this->types[
"BDAY"]) .
"\n";
294 if (count($this->types[
"ADR"]))
297 foreach ($this->types[
"ADR"] as $key => $address)
300 foreach ($address as $str)
304 if (strcmp(
$test,
"") != 0)
307 $adr_types =
array();
308 if ($address[
"TYPE"] > 0)
312 array_push($adr_types,
"dom");
316 array_push($adr_types,
"intl");
320 array_push($adr_types,
"postal");
324 array_push($adr_types,
"parcel");
328 array_push($adr_types,
"home");
332 array_push($adr_types,
"work");
336 array_push($adr_types,
"pref");
338 $adr .=
";TYPE=" . join(
",", $adr_types);
340 $adr .=
":" . $address[
"POBOX"] .
";" . $address[
"EXTENDED_ADDRESS"] .
341 ";" . $address[
"STREET_ADDRESS"] .
";" . $address[
"LOCALITY"] .
342 ";" . $address[
"REGION"] .
";" . $address[
"POSTAL_CODE"] .
343 ";" . $address[
"COUNTRY"];
344 $adr = $this->
fold($adr) .
"\n";
357 if (is_array($this->types[
"LABEL"]))
359 if (strcmp($this->types[
"LABEL"][
"LABEL"],
"") != 0)
362 $adr_types =
array();
363 if ($this->types[
"LABEL"][
"TYPE"] > 0)
367 array_push($adr_types,
"dom");
371 array_push($adr_types,
"intl");
375 array_push($adr_types,
"postal");
379 array_push($adr_types,
"parcel");
383 array_push($adr_types,
"home");
387 array_push($adr_types,
"work");
391 array_push($adr_types,
"pref");
393 $label .=
";TYPE=" . join(
",", $adr_types);
395 $label .=
":" . $this->types[
"LABEL"][
"LABEL"];
396 $label = $this->
fold($label) .
"\n";
401 if (count($this->types[
"TEL"]))
404 foreach ($this->types[
"TEL"] as $key => $phone)
406 if (strcmp($phone[
"TEL"],
"") != 0)
409 $tel_types =
array();
410 if ($phone[
"TYPE"] > 0)
414 array_push($tel_types,
"home");
418 array_push($tel_types,
"msg");
422 array_push($tel_types,
"work");
426 array_push($tel_types,
"pref");
430 array_push($tel_types,
"voice");
434 array_push($tel_types,
"fax");
438 array_push($tel_types,
"cell");
442 array_push($tel_types,
"video");
446 array_push($tel_types,
"pager");
450 array_push($tel_types,
"bbs");
454 array_push($tel_types,
"modem");
458 array_push($tel_types,
"car");
462 array_push($tel_types,
"isdn");
466 array_push($tel_types,
"pcs");
468 $tel .=
";TYPE=" . join(
",", $tel_types);
470 $tel .=
":" . $phone[
"TEL"];
471 $tel = $this->
fold($tel) .
"\n";
472 $phonenumbers .= $tel;
475 $tel = $phonenumbers;
483 if (count($this->types[
"EMAIL"]))
486 foreach ($this->types[
"EMAIL"] as $key => $mail)
488 if (strcmp($mail[
"EMAIL"],
"") != 0)
491 $adr_types =
array();
492 if ($mail[
"TYPE"] > 0)
496 array_push($adr_types,
"internet");
500 array_push($adr_types,
"x400");
504 array_push($adr_types,
"pref");
506 $email .=
";TYPE=" . join(
",", $adr_types);
508 $email .=
":" . $mail[
"EMAIL"];
509 $email = $this->
fold($email) .
"\n";
521 if (strcmp($this->types[
"MAILER"],
"") != 0)
523 $mailer = $this->
fold(
"MAILER:" . $this->types[
"MAILER"]) .
"\n";
531 if (strcmp($this->types[
"TZ"],
"") != 0)
533 $tz = $this->
fold(
"TZ:" . $this->types[
"TZ"]) .
"\n";
541 if (is_array($this->types[
"GEO"])
and 542 (strcmp($this->types[
"GEO"][
"LAT"],
"") != 0)
and 543 (strcmp($this->types[
"GEO"][
"LON"],
"") != 0))
545 $geo = $this->
fold(
"GEO:" . $this->types[
"GEO"][
"LAT"] .
";" . $this->types[
"GEO"][
"LON"]) .
"\n";
553 if (strcmp($this->types[
"TITLE"],
"") != 0)
555 $title = $this->
fold(
"TITLE:" . $this->types[
"TITLE"]) .
"\n";
563 if (strcmp($this->types[
"ROLE"],
"") != 0)
565 $role = $this->
fold(
"ROLE:" . $this->types[
"ROLE"]) .
"\n";
574 if (is_array($this->types[
"LOGO"]))
576 if (strcmp($this->types[
"LOGO"][
"VALUE"],
"") != 0)
578 $logo = $this->
fold(
"LOGO;VALUE=uri:" . $this->types[
"LOGO"][
"VALUE"]) .
"\n";
580 elseif (strcmp($this->types[
"LOGO"][
"ENCODING"],
"") != 0)
582 $logo =
"LOGO;ENCODING=" . $this->types[
"LOGO"][
"ENCODING"];
583 if (strcmp($this->types[
"LOGO"][
"TYPE"],
"") != 0)
585 $logo .=
";TYPE=" . $this->types[
"LOGO"][
"TYPE"];
587 $logo .=
":" . $this->types[
"LOGO"][
"LOGO"];
588 $logo = $this->
fold($logo) .
"\n";
593 if (strcmp($this->types[
"AGENT"],
"") != 0)
595 $agent = $this->
fold(
"AGENT:" . $this->types[
"AGENT"]) .
"\n";
603 if (strcmp($this->types[
"ORG"],
"") != 0)
605 $org = $this->
fold(
"ORG:" . $this->types[
"ORG"]) .
"\n";
613 if (strcmp($this->types[
"CATEGORIES"],
"") != 0)
615 $categories = $this->
fold(
"CATEGORIES:" . $this->types[
"CATEGORIES"]) .
"\n";
623 if (strcmp($this->types[
"NOTE"],
"") != 0)
625 $note = $this->
fold(
"NOTE:" . $this->types[
"NOTE"]) .
"\n";
633 if (strcmp($this->types[
"PRODID"],
"") != 0)
635 $prodid = $this->
fold(
"PRODID:" . $this->types[
"PRODID"]) .
"\n";
643 if (strcmp($this->types[
"REV"],
"") != 0)
645 $rev = $this->
fold(
"REV:" . $this->types[
"REV"]) .
"\n";
653 if (strcmp($this->types[
"SORT-STRING"],
"") != 0)
655 $sortstring = $this->
fold(
"SORT-STRING:" . $this->types[
"SORT-STRING"]) .
"\n";
664 if (is_array($this->types[
"SOUND"]))
666 if (strcmp($this->types[
"SOUND"][
"VALUE"],
"") != 0)
668 $sound = $this->
fold(
"SOUND;VALUE=uri:" . $this->types[
"SOUND"][
"VALUE"]) .
"\n";
670 elseif (strcmp($this->types[
"SOUND"][
"ENCODING"],
"") != 0)
672 $sound =
"SOUND;ENCODING=" . $this->types[
"SOUND"][
"ENCODING"];
673 if (strcmp($this->types[
"SOUND"][
"TYPE"],
"") != 0)
675 $sound .=
";TYPE=" . $this->types[
"SOUND"][
"TYPE"];
677 $sound .=
":" . $this->types[
"SOUND"][
"SOUND"];
678 $sound = $this->
fold($sound) .
"\n";
684 if (is_array($this->types[
"UID"]))
686 if (strcmp($this->types[
"UID"][
"UID"],
"") != 0)
689 if (strcmp($this->types[
"UID"][
"TYPE"],
"") != 0)
691 $uid .=
";TYPE=" . $this->types[
"UID"][
"TYPE"];
693 $uid .=
":" . $this->types[
"UID"][
"UID"];
694 $uid = $this->
fold($uid) .
"\n";
699 if (strcmp($this->types[
"URL"],
"") != 0)
701 $url = $this->
fold(
"URL:" . $this->types[
"URL"]) .
"\n";
710 if (is_array($this->types[
"KEY"]))
712 if (strcmp($this->types[
"KEY"][
"KEY"],
"") != 0)
715 if (strcmp($this->types[
"KEY"][
"TYPE"],
"") != 0)
717 $key .=
";TYPE=" . $this->types[
"KEY"][
"TYPE"];
719 if (strcmp($this->types[
"KEY"][
"ENCODING"],
"") != 0)
721 $key .=
";ENCODING=" . $this->types[
"KEY"][
"ENCODING"];
723 $key .=
":" . $this->types[
"KEY"][
"KEY"];
724 $key = $this->
fold($key) .
"\n";
729 if (strcmp($this->types[
"CLASS"],
"") != 0)
731 $class = $this->
fold(
"CLASS:" . $this->types[
"CLASS"]) .
"\n";
740 $vcard .= $fn.$n.$nickname.$photo.$bday.$adr.$label.$tel.$email.$mailer.
741 $tz.$geo.$title.$role.$logo.$agent.$org.$categories.$note.$prodid.
742 $rev.$sortstring.$sound.$uid.$url.$class.$key;
743 $vcard .=
"END:vCard\n";
759 $hex =
array(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F');
760 $lines = preg_split(
"/(?:\r\n|\r|\n)/", $input);
762 $linebreak =
"=0D=0A";
766 for ($j=0;$j<count($lines);$j++) {
768 $linlen = strlen($line);
770 for($i = 0; $i < $linlen; $i++) {
771 $c = substr($line, $i, 1);
773 if ( ($dec == 32) && ($i == ($linlen - 1)) ) {
775 } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) {
776 $h2 = floor($dec/16); $h1 = floor($dec%16);
777 $c = $escape.$hex[
"$h2"].$hex[
"$h1"];
779 if ( (strlen($newline) + strlen($c)) >= $line_max ) {
780 $output .= $newline.$escape.$eol;
786 if ($j<count($lines)-1)
$output .= $linebreak;
813 $this->types[
"FN"] = $this->
escape($formatted_name);
845 function setName($family_name, $given_name =
"", $additional_names =
"", $honorific_prefixes =
"", $honorific_suffixes =
"")
847 $familynames =& $this->
explodeVar($family_name);
848 $givennames =& $this->
explodeVar($given_name);
849 $addnames =& $this->
explodeVar($additional_names);
850 $prefixes =& $this->
explodeVar($honorific_prefixes);
851 $suffixes =& $this->
explodeVar($honorific_suffixes);
854 join(
",", $familynames) .
856 join(
",", $givennames) .
858 join(
",", $addnames) .
860 join(
",", $prefixes) .
862 join(
",", $suffixes);
864 $this->filename =
"$given_name" .
"_" .
"$family_name" .
".vcf";
865 if (strcmp($this->types[
"FN"],
"") == 0)
867 $fn = trim(
"$honorific_prefixes $given_name $additional_names $family_name $honorific_suffixes");
868 $fn = preg_replace(
"/\s{2,10}/",
" ", $fn);
896 $this->types[
"NICKNAME"] = join(
",", $nicknames);
938 if (preg_match(
"/^http/", $photo))
940 $value = $this->
encode($photo);
945 $photo = base64_encode($photo);
947 $this->types[
"PHOTO"] =
array(
950 "ENCODING" => $encoding,
977 if (($year < 1)
or ($day < 1)
or ($month < 1))
979 $this->types[
"BDAY"] =
"";
983 $this->types[
"BDAY"] = sprintf(
"%04d-%02d-%02d", $year, $month, $day);
1048 $extended_address =
"",
1049 $street_address =
"",
1061 $po_box = join(
",", $this->
explodeVar($po_box));
1062 $extended_address = join(
",", $this->
explodeVar($extended_address));
1063 $street_address = join(
",", $this->
explodeVar($street_address));
1064 $locality = join(
",", $this->
explodeVar($locality));
1065 $region = join(
",", $this->
explodeVar($region));
1066 $postal_code = join(
",", $this->
explodeVar($postal_code));
1067 $country = join(
",", $this->
explodeVar($country));
1068 array_push($this->types[
"ADR"],
array(
1070 "EXTENDED_ADDRESS" => $extended_address,
1071 "STREET_ADDRESS" => $street_address,
1072 "LOCALITY" => $locality,
1073 "REGION" => $region,
1074 "POSTAL_CODE" => $postal_code,
1075 "COUNTRY" => $country,
1122 $this->types[
"LABEL"] =
array(
1123 "LABEL" => $this->
escape($label),
1177 array_push($this->types[
"TEL"],
array(
1178 "TEL" => $this->
escape($number),
1211 array_push($this->types[
"EMAIL"],
array(
1212 "EMAIL" => $this->
escape($address),
1239 $this->types[
"MAILER"] = $this->
escape($name);
1267 $this->types[
"TZ"] = $this->
escape($zone);
1306 $this->types[
"GEO"] =
array(
1361 $this->types[
"ROLE"] = $this->
escape($role);
1401 if (preg_match(
"/^http/", $logo))
1403 $value = $this->
encode($logo);
1408 $logo = base64_encode($logo);
1410 $this->types[
"LOGO"] =
array(
1413 "ENCODING" => $encoding,
1447 $this->types[
"AGENT"] = $this->
escape($agent);
1473 $organization = join(
";", $this->
explodeVar($organization,
";"));
1474 $this->types[
"ORG"] = $organization;
1501 $categories = join(
",", $this->
explodeVar($categories));
1502 $this->types[
"CATEGORIES"] = $categories;
1526 $this->types[
"NOTE"] = $this->
escape($note);
1550 $this->types[
"PRODID"] = $this->
escape($product_id);
1576 $this->types[
"REV"] = $this->
escape($revision_date);
1624 $this->types[
"SORT-STRING"] = $this->
escape($string);
1666 if (preg_match(
"/^http/", $sound))
1668 $value = $this->
encode($sound);
1673 $sound = base64_encode($sound);
1675 $this->types[
"SOUND"] =
array(
1678 "ENCODING" => $encoding,
1711 $this->types[
"UID"] =
array(
1712 "UID" => $this->
escape($uid),
1735 $this->types[
"URL"] = $this->
escape($uri);
1756 $this->types[
"VERSION"] =
$version;
1789 $this->types[
"CLASS"] = $this->
escape($classification);
1839 $key = base64_encode($key);
1840 $this->types[
"KEY"] =
array(
1843 "ENCODING" => $encoding
1849 if (strcmp($this->filename,
"") == 0)
1861 return "text/x-vcard";
setCategories($categories)
Sets the value for the vCard CATEGORIES type.
setFormattedName($formatted_name)
Sets the value for the vCard FN type.
setSortString($string="")
Sets the value for the vCard SORT-STRING type.
$types
An array containing the vCard types.
const EMAIL_TYPE_INTERNET
setLabel($label="", $type=ADR_TYPE_NONE)
Sets the value for the vCard LABEL type.
setUID($uid="", $type="")
Sets the value for the vCard UID type.
setBirthday($year, $month, $day)
Sets the value for the vCard BDAY type.
setAgent($agent="")
Sets the value for the vCard AGENT type.
setOrganization($organization="")
Sets the value for the vCard ORG type.
setAddress( $po_box="", $extended_address="", $street_address="", $locality="", $region="", $postal_code="", $country="", $type=ADR_TYPE_NONE)
Sets the value for the vCard ADR type.
& explodeVar($variable, $separator=",")
Splits a variable into an array using a separator and escapes every value.
setProductId($product_id="")
Sets the value for the vCard PRODID type.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\+" &#(? foreach( $entity_files as $file) $output
setTitle($title="")
Sets the value for the vCard TITLE type.
setMailer($name="")
Sets the value for the vCard MAILER type.
$filename
The filename of the vCard used when saving the vCard.
setSound($sound="", $type="")
Sets the value for the vCard SOUND type.
setURL($uri="")
Sets the value for the vCard URL type.
setPosition($latitude="", $longitude="")
Sets the value for the vCard GEO type.
setVersion($version="3.0")
Sets the value for the vCard VERSION type.
fold($string="", $length=75)
Fold a string according to RFC 2425.
buildVCard()
Builds a vCard string out of the attributes of this object.
setTimezone($zone="")
Sets the value for the vCard TZ type.
setNickname($nickname)
Sets the value for the vCard NICKNAME type.
setName($family_name, $given_name="", $additional_names="", $honorific_prefixes="", $honorific_suffixes="")
Sets the value for the vCard N type.
setLogo($logo, $type="")
Sets the value for the vCard LOGO type.
Create styles array
The data for the language used.
setKey($key="", $type="")
Sets the value for the vCard KEY type.
encode($string)
Encode data with "b" type encoding according to RFC 2045.
setNote($note="")
Sets the value for the vCard NOTE type.
const ADR_TYPE_NONE
RFC 2426 vCard MIME Directory Profile 3.0 class.
setRevision($revision_date="")
Sets the value for the vCard REV type.
static getLogger($a_component_id)
Get component logger.
setClassification($classification="")
Sets the value for the vCard CLASS type.
setRole($role="")
Sets the value for the vCard ROLE type.
escape($string)
Escapes a string according to RFC 2426.
quoted_printable_encode($input, $line_max=76)
Creates a quoted printable encoded string according to RFC 2045.
__construct($version="3.0")
ilvCard Constructor
setPhoto($photo, $type="")
Sets the value for the vCard PHOTO type.
setEmail($address="", $type=EMAIL_TYPE_INTERNET)
Sets the value for the vCard EMAIL type.
setPhone($number="", $type=TEL_TYPE_VOICE)
Sets the value for the vCard TEL type.