("=0D=0A"), "\r" => ("=0D=0A"), "\n" => ("=0D=0A"))); } else { return escape(quoted_printable_encode($string)); }; } function escape($string) { return str_replace(";","\;",$string); } function gps_sour($gps, $direction = false, $arr = false) { if ($direction) { $suffix = $gps > 0 ? 'E' : 'W'; $tmp = abs ($gps % 360); if ($tmp > 180) { $gps = 360 - $gps; }; } else { $suffix = $gps > 0 ? 'N' : 'S'; $tmp = abs ($gps % 360); if ($tmp > 180) { $gps = 360 - $gps; }; }; $dgr = floor($gps); $gps -= $dgr; $gps *= 60; $min = floor($gps); $gps -= $min; $gps *= 60; $sec = $gps; if ($arr) { return(array($dgr, $min, $sec)); } else { return($dgr . '°' . $min . "'" . number_format($sec, 4, '.', ' ') . "''" . $suffix); }; }; // taken from PHP documentation comments /* function quoted_printable_encode($input) { return(imap_8bit($input)); } /**/ /**/ // use this if imap_8bit does not work /* function quoted_printable_encode($sText, $bEmulate_imap_8bit = true) { // split text into lines $aLines=explode(chr(13).chr(10), $sText); for ($i=0;$iproperties[$key] = quoted_printable_encode($number); if (strpos($key, 'HOME') !== false) { $this->phone_home = $number; } if (strpos($key, 'WORK') !== false) { $this->phone_work = $number; } if (strpos($key, 'HOME') !== false) { $this->phone_home = $number; } if (strpos($key, 'CELL') !== false) { $this->cellular = $number; } if (strpos($key, 'FAX') !== false) { $this->fax = $number; } } // UNTESTED !!! function setPhoto($type, $photo) { // $type = "GIF" | "JPEG" $this->properties["PHOTO;TYPE=$type;ENCODING=BASE64"] = base64_encode($photo); } function setPhotoURL($type, $url) { // $type = "GIF" | "JPEG" $url in form http://www.something.com/somefile.extension $this->properties["PHOTO;TYPE=$type;VALUE=URL"] = $url; } function setFormattedName($name) { $this->properties["FN" . ";ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($name); } function setName($family="", $first="", $additional="", $prefix="", $suffix="", $display="") { $this->first_name = $first; $this->last_name = $family; $this->middle_name = $additional; $this->prefix = $prefix; $this->suffic = $suffix; $this->properties["N" . ";ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode(trim("$family;$first;$additional;$prefix;$suffix")); $this->filename = "$first%20$family.vcf"; if ($display != "") { $this->setFormattedName($display); $this->display_name = $display; } elseif (!isset($this->properties["FN" . ";ENCODING=QUOTED-PRINTABLE"]) || ($this->properties["FN" . ";ENCODING=QUOTED-PRINTABLE"]=="")) { $this->setFormattedName(trim("$prefix $first $additional $family $suffix")); $this->display_name = trim("$prefix $first $additional $family $suffix"); }; } function setIco($ico="", $dico="") { $this->ico = $ico; $this->dico = $dico; } function setGeo($geo_x = "", $geo_y = "") { $this->geo_x = floatval($geo_x); $this->geo_y = floatval($geo_y); } 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($postoffice).";".encode($extended).";".encode($street).";".encode($city).";".encode($region).";".encode($zip).";".encode($country); if (!isset($this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"]) || ($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" . chr(13) . chr(10); $this->zip = $postoffice; } if ($extended!="") { $label.= "$extended" . chr(13) . chr(10); $this->extended_address = $extended; } if ($street!="") { $label.= "$street" . chr(13) . chr(10); $this->street_address = $street; } if ($zip!="") { $label.= "$zip "; $this->zip = $zip; } if ($city!="") { $label.= "$city" . chr(13) . chr(10); $this->city = $city; } if ($region!="") { $label.= "$region" . chr(13) . chr(10); $this->state = $region; } if ($country!="") { $label.= "$country" . chr(13) . chr(10); $this->country = $country; } $this->properties["LABEL;$type;ENCODING=QUOTED-PRINTABLE"] = encode($label, true); } function setEmail($address) { $this->properties["EMAIL;INTERNET"] = $address; $this->email = $address; } function setNote($note) { $this->note = $note; $this->properties["NOTE;ENCODING=QUOTED-PRINTABLE"] = quoted_printable_encode($note); } function setURL($url, $type="") { // $type may be WORK | HOME $key = "URL"; if ($type!="") { $key.= ";$type"; } $this->properties[$key] = $url; $this->url = $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.= "MAILER:PHP vCard class by Kai Blankenhorn\r\n"; $text.= "END:VCARD\r\n"; return $text; } function getHCard() { $out = '
'; //$out .= ' '; $out .= '

' . $this->display_name . '

'; if ($this->note != '') { $out .= '

' . $this->note . '

'; } if ($this->ico != "") { $out .= '

IČO ' . $this->ico . '

'; } if ($this->dico != "") { $out .= '

DIČ ' . $this->dico . '

'; } if ($this->cellular != "") { $out .= '

Mobil ' . $this->cellular . '

'; } if ($this->phone_home != "") { $out .= '

Tel ' . $this->phone_home . '

'; } if ($this->phone_work != "") { $out .= '

Tel ' . $this->phone_work . '

'; } if ($this->fax != "") { $out .= '

Fax ' . $this->fax . '

'; } if ($this->email != "") { $out .= '

Email

'; } $out .= '

'; if ($this->street_address != '') { $out .= ' '. $this->street_address . ''; }; if ($this->zip != '') { $out .= '
'. $this->zip . ''; } if ($this->city != '') { $out .= ' '. $this->city . ''; } if ($this->state != '') { $out .= '
'. $this->state . ''; } if ($this->country != '') { $out .= '
'. $this->country . ''; } $out .= '

'; if ($this->geo_x != '') { $out .= '

' . gps_sour($this->geo_x, false, false) . ', ' . gps_sour($this->geo_y, true, false) . '

'; } if ($this->url != '') { $out .= '

' . $this->url . '

'; } $out .= '
'; return($out); } function getFileName() { return $this->filename; } } // USAGE EXAMPLE ?>