126) ) { // always encode "\t", which is *not* required $h2 = floor($dec/16); $h1 = floor($dec%16); $c = $escape.$hex["$h2"].$hex["$h1"]; } if ( (strlen($newline) + strlen($c)) >= $line_max ) { // CRLF is not counted $output .= $newline.$escape.$eol; // soft line break; " =\r\n" is okay $newline = " "; } $newline .= $c; } // end of for $output .= $newline; if ($jproperties[$key] = quoted_printable_encode($number); } // UNTESTED !!! function setPhoto($type, $photo) { // $type = "GIF" | "JPEG" $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo); } function setFormattedName($name) { $this->properties["FN"] = quoted_printable_encode($name); } function setShow($show) { $this->properties["X-ABShowAS"] = quoted_printable_encode($show); } function setName($family="", $first="", $additional="", $prefix="", $suffix="") { $this->properties["N"] = "$family;$first;$additional;$prefix;$suffix"; } function setOrganization($org) { // $date format is YYYY-MM-DD $this->properties["ORG"] = $org; $this->filename = "$org.vcf"; } function setBirthday($date) { // $date format is YYYY-MM-DD $this->properties["BDAY"] = $date; } function setAddress($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") { // $type may be DOM | INTL | POSTAL | PARCEL | HOME | WORK or any combination of these: e.g. "WORK;PARCEL;POSTAL" $key = "ADR"; if ($type!="") $key.= ";$type"; $key.= ";ENCODING=QUOTED-PRINTABLE"; $this->properties[$key] = encode($name).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country); if ($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] == "") { //$this->setLabel($postoffice, $extended, $street, $city, $region, $zip, $country, $type); } } function setLabel($postoffice="", $extended="", $street="", $city="", $region="", $zip="", $country="", $type="HOME;POSTAL") { $label = ""; if ($postoffice!="") $label.= "$postoffice\r\n"; if ($extended!="") $label.= "$extended\r\n"; if ($street!="") $label.= "$street\r\n"; if ($zip!="") $label.= "$zip "; if ($city!="") $label.= "$city\r\n"; if ($region!="") $label.= "$region\r\n"; if ($country!="") $country.= "$country\r\n"; $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($label); } function setEmail($address) { $this->properties["EMAIL;INTERNET"] = $address; } function setNote($note) { $this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note); } function setURL($url, $type="work") { // $type may be WORK | HOME $key = "URL"; if ($type!="") $key.= ";$type"; $this->properties[$key] = $url; } function getVCard() { $text = "BEGIN:VCARD\r\n"; $text.= "VERSION:2.1\r\n"; foreach($this->properties as $key => $value) { $text.= "$key:$value\r\n"; } $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z\r\n"; $text.= ""; $text.= "END:VCARD\r\n"; return $text; } //writes filename displayed on download function getFileName() { return $this->filename; } } // function runVcard() { // USAGE EXAMPLE $org1 = get_post_meta($post->ID, "Company", true); $fn = get_post_meta($post->ID, "Firstname", true); $sn = get_post_meta($post->ID, "Surname", true); $off = get_post_meta($post->ID, "Office1", true); $adr = get_post_meta($post->ID, "Address1", true); $cou = get_post_meta($post->ID, "Country1", true); $cit = get_post_meta($post->ID, "City1", true); $eml = get_post_meta($post->ID, "Email1", true); $des = get_post_meta($post->ID, "Company", true); $htp = get_post_meta($post->ID, "Website1", true); $phn = get_post_meta($post->ID, "Office1", true); $v = new vCard(); $v->setPhoneNumber("$phn", "PREF;WORK;VOICE"); $v->setName("$sn", "$fn", "", ""); $v->setOrganization ("$org1"); $v->setBirthday(""); $v->setAddress("", "", "$adr", "$cit", "", "", "$cou"); $v->setEmail("$eml"); $v->setNote("$org1 vCard provided by Afridex.net"); $v->setURL("$htp", "WORK"); $v->setShow("COMPANY"); // Get vCard $output = $v->getVCard(); $filename = $v->getFileName(); // Trick Browser into Automatic Download Header("Content-Disposition: attachment; filename=$filename"); Header("Content-Length: ".strlen($output)); Header("Connection: close"); Header("Content-Type: text/x-vCard; name=$filename"); echo $output; // } ?>