下载vCard脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了下载vCard脚本相关的知识,希望对你有一定的参考价值。
Features: Complies to version 2.1 of the vCard specificationSupports the following attributes:
* Name
* Formatted Name
* Phone and fax numbers
* Birthday
* Address
* Address label
* email address
* notes
* URL
<? /*************************************************************************** php vCard class v2.0 (c) Kai Blankenhorn www.bitfolge.de/en This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ***************************************************************************/ function encode($string) { return escape(quoted_printable_encode($string)); } function escape($string) { } // taken from PHP documentation comments function quoted_printable_encode($input, $line_max = 76) { | | )/", $input); $eol = " "; $linebreak = "=0D=0A"; $escape = "="; $output = ""; $line = $lines[$j]; $newline = ""; for($i = 0; $i < $linlen; $i++) { if ( ($dec == 32) && ($i == ($linlen - 1)) ) { // convert space at eol only $c = "=20"; } elseif ( ($dec == 61) || ($dec < 32 ) || ($dec > 126) ) { // always encode " ", which is *not* required $c = $escape.$hex["$h2"].$hex["$h1"]; } $output .= $newline.$escape.$eol; // soft line break; " = " is okay $newline = " "; } $newline .= $c; } // end of for $output .= $newline; if ($j<count($lines)-1) $output .= $linebreak; } return trim($output); } class vCard { var $properties; var $filename; function setPhoneNumber($number, $type="") { // type may be PREF | WORK | HOME | VOICE | FAX | MSG | CELL | PAGER | BBS | CAR | MODEM | ISDN | VIDEO or any senseful combination, e.g. "PREF;WORK;VOICE" $key = "TEL"; if ($type!="") $key .= ";".$type; $key.= ";ENCODING=QUOTED-PRINTABLE"; $this->properties[$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 setName($family="", $first="", $additional="", $prefix="", $suffix="") { $this->properties["N"] = "$family;$first;$additional;$prefix;$suffix"; $this->filename = "$first%20$family.vcf"; if ($this->properties["FN"]=="") $this->setFormattedName(trim("$prefix $first $additional $family $suffix")); } 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 "; if ($extended!="") $label.= "$extended "; if ($street!="") $label.= "$street "; if ($zip!="") $label.= "$zip "; if ($city!="") $label.= "$city "; if ($region!="") $label.= "$region "; if ($country!="") $country.= "$country "; $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="") { // $type may be WORK | HOME $key = "URL"; if ($type!="") $key.= ";$type"; $this->properties[$key] = $url; } function getVCard() { $text = "BEGIN:VCARD "; $text.= "VERSION:2.1 "; foreach($this->properties as $key => $value) { $text.= "$key:$value "; } $text.= "REV:".date("Y-m-d")."T".date("H:i:s")."Z "; $text.= "MAILER:PHP vCard class by Kai Blankenhorn "; "; return $text; } function getFileName() { return $this->filename; } } // USAGE EXAMPLE $v = new vCard(); $v->setPhoneNumber("+49 23 456789", "PREF;HOME;VOICE"); $v->setName("Mustermann", "Thomas", "", "Herr"); $v->setBirthday("1960-07-31"); $v->setAddress("", "", "Musterstrasse 20", "Musterstadt", "", "98765", "Deutschland"); $v->setEmail("thomas.mustermann@thomas-mustermann.de"); $v->setNote("You can take some notes here. Multiple lines are supported via \r\n."); $v->setURL("http://www.thomas-mustermann.de", "WORK"); $output = $v->getVCard(); $filename = $v->getFileName(); echo $output; ?>
以上是关于下载vCard脚本的主要内容,如果未能解决你的问题,请参考以下文章