37define(
"ADR_TYPE_NONE", 0);
 
   38define(
"ADR_TYPE_DOM", 1);
 
   39define(
"ADR_TYPE_INTL", 2);
 
   40define(
"ADR_TYPE_POSTAL", 4);
 
   41define(
"ADR_TYPE_PARCEL", 8);
 
   42define(
"ADR_TYPE_HOME", 16);
 
   43define(
"ADR_TYPE_WORK", 32);
 
   44define(
"ADR_TYPE_PREF", 64);
 
   51define(
"TEL_TYPE_NONE", 0);
 
   52define(
"TEL_TYPE_HOME", 1);
 
   53define(
"TEL_TYPE_MSG", 2);
 
   54define(
"TEL_TYPE_WORK", 4);
 
   55define(
"TEL_TYPE_PREF", 8);
 
   56define(
"TEL_TYPE_VOICE", 16);
 
   57define(
"TEL_TYPE_FAX", 32);
 
   58define(
"TEL_TYPE_CELL", 64);
 
   59define(
"TEL_TYPE_VIDEO", 128);
 
   60define(
"TEL_TYPE_PAGER", 256);
 
   61define(
"TEL_TYPE_BBS", 512);
 
   62define(
"TEL_TYPE_MODEM", 1024);
 
   63define(
"TEL_TYPE_CAR", 2048);
 
   64define(
"TEL_TYPE_ISDN", 4096);
 
   65define(
"TEL_TYPE_PCS", 8192);
 
   72define(
"EMAIL_TYPE_NONE", 0);
 
   73define(
"EMAIL_TYPE_INTERNET", 1);
 
   74define(
"EMAIL_TYPE_x400", 2);
 
   75define(
"EMAIL_TYPE_PREF", 4);
 
  100        $this->types = array(
 
  157    public function fold($string = 
"", $length = 75)
 
  160        preg_match_all(
"/(.{1,74})/", $string, $matches);
 
  161        for (
$i = 0; 
$i < count($matches[1]); 
$i++) {
 
  162            if (
$i < (count($matches[1])-1)) {
 
  163                $matches[1][
$i] .= 
"\n";
 
  166                $matches[1][
$i] = 
" " . $matches[1][
$i];
 
  168            $folded_string .= $matches[1][
$i];
 
  170        return $folded_string;
 
  184        $string = preg_replace(
"/(?<!\\\\)(\\\\)([^;,n\\\\])/", 
"\${1}\${1}\${2}", $string);
 
  185        $string = preg_replace(
"/(?<!\\\\);/", 
"\\;", $string);
 
  186        $string = preg_replace(
"/(?<!\\\\),/", 
"\\,", $string);
 
  187        $string = preg_replace(
"/\n/", 
"\\n", $string);
 
  203        $exploded = explode($separator, $variable);
 
  204        foreach ($exploded as 
$index => $var) {
 
  220        $vcard = 
"BEGIN:VCARD\n";
 
  221        $vcard .= 
"VERSION:" . $this->types[
"VERSION"] . 
"\n";
 
  222        foreach ($this->types as 
$type => $var) {
 
  227                    if (strcmp($this->types[
"FN"], 
"") != 0) {
 
  228                        $fn = $this->
fold(
"FN:" . $this->types[
"FN"]) . 
"\n";
 
  234                    if (strcmp($this->types[
"N"], 
"") != 0) {
 
  235                        $n = $this->
fold(
"N:" . $this->types[
"N"]) . 
"\n";
 
  241                    if (strcmp($this->types[
"NICKNAME"], 
"") != 0) {
 
  242                        $nickname = $this->
fold(
"NICKNAME:" . $this->types[
"NICKNAME"]) . 
"\n";
 
  249                    if (is_array($this->types[
"PHOTO"])) {
 
  250                        if (strcmp($this->types[
"PHOTO"][
"VALUE"], 
"") != 0) {
 
  251                            $photo = $this->
fold(
"PHOTO;VALUE=uri:" . $this->types[
"PHOTO"][
"VALUE"]) . 
"\n";
 
  252                        } elseif (strcmp($this->types[
"PHOTO"][
"ENCODING"], 
"") != 0) {
 
  253                            $photo = 
"PHOTO;ENCODING=" . $this->types[
"PHOTO"][
"ENCODING"];
 
  254                            if (strcmp($this->types[
"PHOTO"][
"TYPE"], 
"") != 0) {
 
  255                                $photo .= 
";TYPE=" . $this->types[
"PHOTO"][
"TYPE"];
 
  257                            $photo .= 
":" . $this->types[
"PHOTO"][
"PHOTO"];
 
  258                            $photo = $this->
fold($photo) . 
"\n";
 
  263                    if (strcmp($this->types[
"BDAY"], 
"") != 0) {
 
  264                        $bday = $this->
fold(
"BDAY:" . $this->types[
"BDAY"]) . 
"\n";
 
  270                    if (count($this->types[
"ADR"])) {
 
  272                        foreach ($this->types[
"ADR"] as 
$key => $address) {
 
  274                            foreach ($address as $str) {
 
  277                            if (strcmp(
$test, 
"") != 0) {
 
  279                                $adr_types = array();
 
  280                                if ($address[
"TYPE"] > 0) {
 
  282                                        array_push($adr_types, 
"dom");
 
  285                                        array_push($adr_types, 
"intl");
 
  288                                        array_push($adr_types, 
"postal");
 
  291                                        array_push($adr_types, 
"parcel");
 
  294                                        array_push($adr_types, 
"home");
 
  297                                        array_push($adr_types, 
"work");
 
  300                                        array_push($adr_types, 
"pref");
 
  302                                    $adr .= 
";TYPE=" . join(
",", $adr_types);
 
  304                                $adr .= 
":" . $address[
"POBOX"] . 
";" . $address[
"EXTENDED_ADDRESS"] .
 
  305                                    ";" . $address[
"STREET_ADDRESS"] . 
";" . $address[
"LOCALITY"] .
 
  306                                    ";" . $address[
"REGION"] . 
";" . $address[
"POSTAL_CODE"] .
 
  307                                    ";" . $address[
"COUNTRY"];
 
  308                                $adr = $this->
fold($adr) . 
"\n";
 
  319                    if (is_array($this->types[
"LABEL"])) {
 
  320                        if (strcmp($this->types[
"LABEL"][
"LABEL"], 
"") != 0) {
 
  322                            $adr_types = array();
 
  323                            if ($this->types[
"LABEL"][
"TYPE"] > 0) {
 
  324                                if (($this->types[
"LABEL"][
"TYPE"] & 
ADR_TYPE_DOM) > 0) {
 
  325                                    array_push($adr_types, 
"dom");
 
  328                                    array_push($adr_types, 
"intl");
 
  331                                    array_push($adr_types, 
"postal");
 
  334                                    array_push($adr_types, 
"parcel");
 
  337                                    array_push($adr_types, 
"home");
 
  340                                    array_push($adr_types, 
"work");
 
  343                                    array_push($adr_types, 
"pref");
 
  345                                $label .= 
";TYPE=" . join(
",", $adr_types);
 
  347                            $label .= 
":" . $this->types[
"LABEL"][
"LABEL"];
 
  348                            $label = $this->
fold($label) . 
"\n";
 
  353                    if (count($this->types[
"TEL"])) {
 
  355                        foreach ($this->types[
"TEL"] as 
$key => $phone) {
 
  356                            if (strcmp($phone[
"TEL"], 
"") != 0) {
 
  358                                $tel_types = array();
 
  359                                if ($phone[
"TYPE"] > 0) {
 
  361                                        array_push($tel_types, 
"home");
 
  364                                        array_push($tel_types, 
"msg");
 
  367                                        array_push($tel_types, 
"work");
 
  370                                        array_push($tel_types, 
"pref");
 
  373                                        array_push($tel_types, 
"voice");
 
  376                                        array_push($tel_types, 
"fax");
 
  379                                        array_push($tel_types, 
"cell");
 
  382                                        array_push($tel_types, 
"video");
 
  385                                        array_push($tel_types, 
"pager");
 
  388                                        array_push($tel_types, 
"bbs");
 
  391                                        array_push($tel_types, 
"modem");
 
  394                                        array_push($tel_types, 
"car");
 
  397                                        array_push($tel_types, 
"isdn");
 
  400                                        array_push($tel_types, 
"pcs");
 
  402                                    $tel .= 
";TYPE=" . join(
",", $tel_types);
 
  404                                $tel .= 
":" . $phone[
"TEL"];
 
  405                                $tel = $this->
fold($tel) . 
"\n";
 
  406                                $phonenumbers .= $tel;
 
  409                        $tel = $phonenumbers;
 
  415                    if (count($this->types[
"EMAIL"])) {
 
  417                        foreach ($this->types[
"EMAIL"] as 
$key => $mail) {
 
  418                            if (strcmp($mail[
"EMAIL"], 
"") != 0) {
 
  420                                $adr_types = array();
 
  421                                if ($mail[
"TYPE"] > 0) {
 
  423                                        array_push($adr_types, 
"internet");
 
  426                                        array_push($adr_types, 
"x400");
 
  429                                        array_push($adr_types, 
"pref");
 
  431                                    $email .= 
";TYPE=" . join(
",", $adr_types);
 
  433                                $email .= 
":" . $mail[
"EMAIL"];
 
  444                    if (strcmp($this->types[
"MAILER"], 
"") != 0) {
 
  445                        $mailer = $this->
fold(
"MAILER:" . $this->types[
"MAILER"]) . 
"\n";
 
  451                    if (strcmp($this->types[
"TZ"], 
"") != 0) {
 
  452                        $tz = $this->
fold(
"TZ:" . $this->types[
"TZ"]) . 
"\n";
 
  458                    if (is_array($this->types[
"GEO"]) and
 
  459                        (strcmp($this->types[
"GEO"][
"LAT"], 
"") != 0) and
 
  460                        (strcmp($this->types[
"GEO"][
"LON"], 
"") != 0)) {
 
  461                        $geo = $this->
fold(
"GEO:" . $this->types[
"GEO"][
"LAT"] . 
";" . $this->types[
"GEO"][
"LON"]) . 
"\n";
 
  467                    if (strcmp($this->types[
"TITLE"], 
"") != 0) {
 
  468                        $title = $this->
fold(
"TITLE:" . $this->types[
"TITLE"]) . 
"\n";
 
  474                    if (strcmp($this->types[
"ROLE"], 
"") != 0) {
 
  475                        $role = $this->
fold(
"ROLE:" . $this->types[
"ROLE"]) . 
"\n";
 
  482                    if (is_array($this->types[
"LOGO"])) {
 
  483                        if (strcmp($this->types[
"LOGO"][
"VALUE"], 
"") != 0) {
 
  484                            $logo = $this->
fold(
"LOGO;VALUE=uri:" . $this->types[
"LOGO"][
"VALUE"]) . 
"\n";
 
  485                        } elseif (strcmp($this->types[
"LOGO"][
"ENCODING"], 
"") != 0) {
 
  486                            $logo = 
"LOGO;ENCODING=" . $this->types[
"LOGO"][
"ENCODING"];
 
  487                            if (strcmp($this->types[
"LOGO"][
"TYPE"], 
"") != 0) {
 
  488                                $logo .= 
";TYPE=" . $this->types[
"LOGO"][
"TYPE"];
 
  490                            $logo .= 
":" . $this->types[
"LOGO"][
"LOGO"];
 
  491                            $logo = $this->
fold($logo) . 
"\n";
 
  496                    if (strcmp($this->types[
"AGENT"], 
"") != 0) {
 
  497                        $agent = $this->
fold(
"AGENT:" . $this->types[
"AGENT"]) . 
"\n";
 
  503                    if (strcmp($this->types[
"ORG"], 
"") != 0) {
 
  504                        $org = $this->
fold(
"ORG:" . $this->types[
"ORG"]) . 
"\n";
 
  510                    if (strcmp($this->types[
"CATEGORIES"], 
"") != 0) {
 
  511                        $categories = $this->
fold(
"CATEGORIES:" . $this->types[
"CATEGORIES"]) . 
"\n";
 
  517                    if (strcmp($this->types[
"NOTE"], 
"") != 0) {
 
  518                        $note = $this->
fold(
"NOTE:" . $this->types[
"NOTE"]) . 
"\n";
 
  524                    if (strcmp($this->types[
"PRODID"], 
"") != 0) {
 
  525                        $prodid = $this->
fold(
"PRODID:" . $this->types[
"PRODID"]) . 
"\n";
 
  531                    if (strcmp($this->types[
"REV"], 
"") != 0) {
 
  532                        $rev = $this->
fold(
"REV:" . $this->types[
"REV"]) . 
"\n";
 
  538                    if (strcmp($this->types[
"SORT-STRING"], 
"") != 0) {
 
  539                        $sortstring = $this->
fold(
"SORT-STRING:" . $this->types[
"SORT-STRING"]) . 
"\n";
 
  546                    if (is_array($this->types[
"SOUND"])) {
 
  547                        if (strcmp($this->types[
"SOUND"][
"VALUE"], 
"") != 0) {
 
  548                            $sound = $this->
fold(
"SOUND;VALUE=uri:" . $this->types[
"SOUND"][
"VALUE"]) . 
"\n";
 
  549                        } elseif (strcmp($this->types[
"SOUND"][
"ENCODING"], 
"") != 0) {
 
  550                            $sound = 
"SOUND;ENCODING=" . $this->types[
"SOUND"][
"ENCODING"];
 
  551                            if (strcmp($this->types[
"SOUND"][
"TYPE"], 
"") != 0) {
 
  552                                $sound .= 
";TYPE=" . $this->types[
"SOUND"][
"TYPE"];
 
  554                            $sound .= 
":" . $this->types[
"SOUND"][
"SOUND"];
 
  555                            $sound = $this->
fold($sound) . 
"\n";
 
  561                    if (is_array($this->types[
"UID"])) {
 
  562                        if (strcmp($this->types[
"UID"][
"UID"], 
"") != 0) {
 
  564                            if (strcmp($this->types[
"UID"][
"TYPE"], 
"") != 0) {
 
  565                                $uid .= 
";TYPE=" . $this->types[
"UID"][
"TYPE"];
 
  567                            $uid .= 
":" . $this->types[
"UID"][
"UID"];
 
  568                            $uid = $this->
fold($uid) . 
"\n";
 
  573                    if (strcmp($this->types[
"URL"], 
"") != 0) {
 
  574                        $url = $this->
fold(
"URL:" . $this->types[
"URL"]) . 
"\n";
 
  581                    if (is_array($this->types[
"KEY"])) {
 
  582                        if (strcmp($this->types[
"KEY"][
"KEY"], 
"") != 0) {
 
  584                            if (strcmp($this->types[
"KEY"][
"TYPE"], 
"") != 0) {
 
  585                                $key .= 
";TYPE=" . $this->types[
"KEY"][
"TYPE"];
 
  587                            if (strcmp($this->types[
"KEY"][
"ENCODING"], 
"") != 0) {
 
  588                                $key .= 
";ENCODING=" . $this->types[
"KEY"][
"ENCODING"];
 
  590                            $key .= 
":" . $this->types[
"KEY"][
"KEY"];
 
  596                    if (strcmp($this->types[
"CLASS"], 
"") != 0) {
 
  597                        $class = $this->
fold(
"CLASS:" . $this->types[
"CLASS"]) . 
"\n";
 
  604        $vcard .= $fn . 
$n . $nickname . $photo . $bday . $adr . $label . $tel . 
$email . $mailer .
 
  605            $tz . $geo . 
$title . $role . $logo . $agent . $org . $categories . $note . $prodid .
 
  606            $rev . $sortstring . $sound . $uid . 
$url . $class . 
$key;
 
  607        $vcard .= 
"END:vCard\n";
 
  624        $hex = array(
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F');
 
  625        $lines = preg_split(
"/(?:\r\n|\r|\n)/", $input);
 
  627        $linebreak = 
"=0D=0A";
 
  631        for ($j=0;$j<count($lines);$j++) {
 
  633            $linlen = strlen($line);
 
  635            for (
$i = 0; 
$i < $linlen; 
$i++) {
 
  636                $c = substr($line, 
$i, 1);
 
  638                if (($dec == 32) && (
$i == ($linlen - 1))) { 
 
  640                } elseif (($dec == 61) || ($dec < 32) || ($dec > 126)) { 
 
  641                    $h2 = floor($dec/16);
 
  642                    $h1 = floor($dec%16);
 
  643                    $c = $escape . $hex[
"$h2"] . $hex[
"$h1"];
 
  645                if ((strlen($newline) + strlen($c)) >= $line_max) { 
 
  646                    $output .= $newline . $escape . $eol; 
 
  652            if ($j<count($lines)-1) {
 
  681        $this->types[
"FN"] = $this->
escape($formatted_name);
 
  713    public function setName($family_name, $given_name = 
"", $additional_names = 
"", $honorific_prefixes = 
"", $honorific_suffixes = 
"")
 
  715        $familynames =&$this->
explodeVar($family_name);
 
  717        $addnames =&$this->
explodeVar($additional_names);
 
  718        $prefixes =&$this->
explodeVar($honorific_prefixes);
 
  719        $suffixes =&$this->
explodeVar($honorific_suffixes);
 
  722            join(
",", $familynames) .
 
  724            join(
",", $givennames) .
 
  726            join(
",", $addnames) .
 
  728            join(
",", $prefixes) .
 
  730            join(
",", $suffixes);
 
  732        $this->filename = 
"$given_name" . 
"_" . 
"$family_name" . 
".vcf";
 
  733        if (strcmp($this->types[
"FN"], 
"") == 0) {
 
  734            $fn = trim(
"$honorific_prefixes $given_name $additional_names $family_name $honorific_suffixes");
 
  735            $fn = preg_replace(
"/\s{2,10}/", 
" ", $fn);
 
  763        $this->types[
"NICKNAME"] = join(
",", $nicknames);
 
  805        if (preg_match(
"/^http/", $photo)) {
 
  806            $value = $this->
encode($photo);
 
  809            $photo = base64_encode($photo);
 
  811        $this->types[
"PHOTO"] = array(
 
  814            "ENCODING" => $encoding,
 
  841        if (($year < 1) or ($day < 1) or ($month < 1)) {
 
  842            $this->types[
"BDAY"] = 
"";
 
  844            $this->types[
"BDAY"] = 
sprintf(
"%04d-%02d-%02d", $year, $month, $day);
 
  909        $extended_address = 
"",
 
  910        $street_address = 
"",
 
  920        $po_box = join(
",", $this->
explodeVar($po_box));
 
  921        $extended_address = join(
",", $this->
explodeVar($extended_address));
 
  922        $street_address = join(
",", $this->
explodeVar($street_address));
 
  923        $locality = join(
",", $this->
explodeVar($locality));
 
  924        $region = join(
",", $this->
explodeVar($region));
 
  925        $postal_code = join(
",", $this->
explodeVar($postal_code));
 
  926        $country = join(
",", $this->
explodeVar($country));
 
  927        array_push($this->types[
"ADR"], array(
 
  929            "EXTENDED_ADDRESS" => $extended_address,
 
  930            "STREET_ADDRESS" => $street_address,
 
  931            "LOCALITY" => $locality,
 
  933            "POSTAL_CODE" => $postal_code,
 
  934            "COUNTRY" => $country,
 
  980        $this->types[
"LABEL"] = array(
 
  981            "LABEL" => $this->
escape($label),
 
 1035        array_push($this->types[
"TEL"], array(
 
 1036            "TEL" => $this->
escape($number),
 
 1069        array_push($this->types[
"EMAIL"], array(
 
 1070            "EMAIL" => $this->
escape($address),
 
 1125        $this->types[
"TZ"] = $this->
escape($zone);
 
 1164        $this->types[
"GEO"] = array(
 
 1219        $this->types[
"ROLE"] = $this->
escape($role);
 
 1259        if (preg_match(
"/^http/", $logo)) {
 
 1260            $value = $this->
encode($logo);
 
 1263            $logo = base64_encode($logo);
 
 1265        $this->types[
"LOGO"] = array(
 
 1268            "ENCODING" => $encoding,
 
 1302        $this->types[
"AGENT"] = $this->
escape($agent);
 
 1328        $organization = join(
";", $this->
explodeVar($organization, 
";"));
 
 1329        $this->types[
"ORG"] = $organization;
 
 1356        $categories = join(
",", $this->
explodeVar($categories));
 
 1357        $this->types[
"CATEGORIES"] = $categories;
 
 1381        $this->types[
"NOTE"] = $this->
escape($note);
 
 1405        $this->types[
"PRODID"] = $this->
escape($product_id);
 
 1431        $this->types[
"REV"] = $this->
escape($revision_date);
 
 1479        $this->types[
"SORT-STRING"] = $this->
escape($string);
 
 1521        if (preg_match(
"/^http/", $sound)) {
 
 1522            $value = $this->
encode($sound);
 
 1525            $sound = base64_encode($sound);
 
 1527        $this->types[
"SOUND"] = array(
 
 1530            "ENCODING" => $encoding,
 
 1563        $this->types[
"UID"] = array(
 
 1564            "UID" => $this->
escape($uid),
 
 1587        $this->types[
"URL"] = $this->
escape($uri);
 
 1608        $this->types[
"VERSION"] = 
$version;
 
 1641        $this->types[
"CLASS"] = $this->
escape($classification);
 
 1692        $this->types[
"KEY"] = array(
 
 1695            "ENCODING" => $encoding
 
 1701        if (strcmp($this->filename, 
"") == 0) {
 
 1710        return "text/x-vcard";
 
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
const ADR_TYPE_NONE
RFC 2426 vCard MIME Directory Profile 3.0 class.
const EMAIL_TYPE_INTERNET
static getLogger($a_component_id)
Get component logger.
setPhoto($photo, $type="")
Sets the value for the vCard PHOTO type.
setFormattedName($formatted_name)
Sets the value for the vCard FN type.
setRevision($revision_date="")
Sets the value for the vCard REV type.
fold($string="", $length=75)
Fold a string according to RFC 2425.
buildVCard()
Builds a vCard string out of the attributes of this object.
setAddress( $po_box="", $extended_address="", $street_address="", $locality="", $region="", $postal_code="", $country="", $type=ADR_TYPE_NONE)
Sets the value for the vCard ADR type.
setLabel($label="", $type=ADR_TYPE_NONE)
Sets the value for the vCard LABEL type.
setLogo($logo, $type="")
Sets the value for the vCard LOGO type.
setNickname($nickname)
Sets the value for the vCard NICKNAME type.
setSortString($string="")
Sets the value for the vCard SORT-STRING type.
encode($string)
Encode data with "b" type encoding according to RFC 2045.
setName($family_name, $given_name="", $additional_names="", $honorific_prefixes="", $honorific_suffixes="")
Sets the value for the vCard N type.
setClassification($classification="")
Sets the value for the vCard CLASS type.
setPosition($latitude="", $longitude="")
Sets the value for the vCard GEO type.
$types
An array containing the vCard types.
setTimezone($zone="")
Sets the value for the vCard TZ type.
setProductId($product_id="")
Sets the value for the vCard PRODID type.
setOrganization($organization="")
Sets the value for the vCard ORG type.
setSound($sound="", $type="")
Sets the value for the vCard SOUND type.
& explodeVar($variable, $separator=",")
Splits a variable into an array using a separator and escapes every value.
setPhone($number="", $type=TEL_TYPE_VOICE)
Sets the value for the vCard TEL type.
setAgent($agent="")
Sets the value for the vCard AGENT type.
setNote($note="")
Sets the value for the vCard NOTE type.
setVersion($version="3.0")
Sets the value for the vCard VERSION type.
__construct($version="3.0")
ilvCard Constructor
setBirthday($year, $month, $day)
Sets the value for the vCard BDAY type.
setURL($uri="")
Sets the value for the vCard URL type.
setKey($key="", $type="")
Sets the value for the vCard KEY type.
quoted_printable_encode($input, $line_max=76)
Creates a quoted printable encoded string according to RFC 2045.
$filename
The filename of the vCard used when saving the vCard.
setEmail($address="", $type=EMAIL_TYPE_INTERNET)
Sets the value for the vCard EMAIL type.
setRole($role="")
Sets the value for the vCard ROLE type.
setTitle($title="")
Sets the value for the vCard TITLE type.
setUID($uid="", $type="")
Sets the value for the vCard UID type.
escape($string)
Escapes a string according to RFC 2426.
setMailer($name="")
Sets the value for the vCard MAILER type.
setCategories($categories)
Sets the value for the vCard CATEGORIES type.
if(!is_dir( $entity_dir)) exit("Fatal Error ([A-Za-z0-9]+)\s+" &#(? foreach( $entity_files as $file) $output