How to create a VCF card?
First you need to call your settings and generate a vcf. You can even create an image or create a button rather than text to give more style on your website.
Code:
<a href="vcard.settings.php">Download VCF Card</a>
Below is a sample file called vcard.settings.php
Code:
<a href="vcard.settings.php">Download VCF Card</a>
Below is a sample file called vcard.settings.php
require_once('./vcard.class.php'); //Path of your vcard class $vc = new vcard(); //Creating new vcard object $vc->filename = "Melanie Borja"; $vc->revision_date = ""; //If you leave this blank, the current timestamp will be used. $vc->class = "PUBLIC"; /* Contact's name data.*/ $vc->data['display_name'] = ""; $vc->data['first_name'] = "Melanie Kaethleen"; $vc->data['last_name'] = "Borja"; #$vc->data['additional_name'] = ""; //Middle name #$vc->data['name_prefix'] = ""; //Mr. Mrs. Dr. #$vc->data['name_suffix'] = ""; //DDS, MD, III, other designations. #$vc->data['nickname'] = "Kaetz"; /* Contact's company, department, title, profession */ #$vc->data['company'] = ""; #$vc->data['department'] = ""; $vc->data['title'] = "Web Developer"; $vc->data['role'] = "PHP Developer"; /* Contact's work address */ #$vc->data['work_po_box'] = ""; #$vc->data['work_extended_address'] = ""; $vc->data['work_address'] = ""; $vc->data['work_city'] = ""; $vc->data['work_state'] = ""; $vc->data['work_postal_code'] = ""; #$vc->data['work_country'] = ""; /* Contact's home address */ $vc->data['home_po_box'] = "Blk 3 Lot 10"; #$vc->data['home_extended_address'] = ""; $vc->data['home_address'] = "Happy Homes"; $vc->data['home_city'] = "Quezon City"; $vc->data['home_state'] = ""; $vc->data['home_postal_code'] = "1116"; #$vc->data['home_country'] = "Philippines"; /* Contact's telephone numbers. */ $vc->data['office_tel'] = ""; #$vc->data['home_tel'] = ""; $vc->data['cell_tel'] = "(+63) 922-4898-744"; $vc->data['fax_tel'] = ""; #$vc->data['pager_tel'] = ""; /* Contact's email addresses */ $vc->data['email1'] = "kaethleen@gmail.com"; $vc->data['email2'] = "kaetz_888@yahoo.com"; /* Contact's website */ $vc->data['url'] = "http://www.kaethleenborja.com"; /* Some other contact data. */ #$vc->data['photo'] = ""; //Enter a URL. $vc->data['birthday'] = "1985-04-14"; $vc->data['timezone'] = "-06:00"; $vc->data['sort_string'] = ""; /* Notes about this contact. */ #$vc->data['note'] = "Melanie Borja you're the best"; /* Generate card and send as a .vcf file to user's browser for download. */ $vc->download(); |
- filename: the name of the .vcf file that will be sent to the user if you call the download() method. If you leave it blank, the class will automatically build a filename using the contact's data.
- class: Possible values are PUBLIC, PRIVATE, and CONFIDENTIAL. If you leave class blank, it will default to PUBLIC.
- display_name: If you leave display_name blank, it will be built using the first and last name.
- sort_string: If you leave this blank, the class will default to using last_name or company.
Code for vcard.class.php
class vcard { var $log; var $data; //array of this vcard's contact data var $filename; var $class; var $revision_date; var $card; /* The class constructor. You can set some defaults here if desired. */ function vcard() { $this->log = "New vcard() called<br />"; $this->data = array( "display_name"=>null ,"first_name"=>null ,"last_name"=>null ,"additional_name"=>null ,"name_prefix"=>null ,"name_suffix"=>null ,"nickname"=>null ,"title"=>null ,"role"=>null ,"department"=>null ,"company"=>null ,"work_po_box"=>null ,"work_extended_address"=>null ,"work_address"=>null ,"work_city"=>null ,"work_state"=>null ,"work_postal_code"=>null ,"work_country"=>null ,"home_po_box"=>null ,"home_extended_address"=>null ,"home_address"=>null ,"home_city"=>null ,"home_state"=>null ,"home_postal_code"=>null ,"home_country"=>null ,"office_tel"=>null ,"home_tel"=>null ,"cell_tel"=>null ,"fax_tel"=>null ,"pager_tel"=>null ,"email1"=>null ,"email2"=>null ,"url"=>null ,"photo"=>null ,"birthday"=>null ,"timezone"=>null ,"sort_string"=>null ,"note"=>null ); return true; } function build() { $this->log .= "vcard build() called<br />"; /* For many of the values, if they are not passed in, we set defaults or build them based on other values.*/ if (!$this->class) { $this->class = "PUBLIC"; } if (!$this->data['display_name']) { $this->data['display_name'] = trim($this->data['first_name']." ".$this->data['last_name']); } if (!$this->data['sort_string']) { $this->data['sort_string'] = $this->data['last_name']; } if (!$this->data['sort_string']) { $this->data['sort_string'] = $this->data['company']; } if (!$this->data['timezone']) { $this->data['timezone'] = date("O"); } if (!$this->revision_date) { $this->revision_date = date('Y-m-d H:i:s'); } $this->card = "BEGIN:VCARD\r\n"; $this->card .= "VERSION:3.0\r\n"; $this->card .= "CLASS:".$this->class."\r\n"; $this->card .= "PRODID:-//class_vcard from TroyWolf.com//NONSGML Version 1//EN\r\n"; $this->card .= "REV:".$this->revision_date."\r\n"; $this->card .= "FN:".$this->data['display_name']."\r\n"; $this->card .= "N:" .$this->data['last_name'].";" .$this->data['first_name'].";" .$this->data['additional_name'].";" .$this->data['name_prefix'].";" .$this->data['name_suffix']."\r\n"; if ($this->data['nickname']) { $this->card .= "NICKNAME:".$this->data['nickname']."\r\n"; } if ($this->data['title']) { $this->card .= "TITLE:".$this->data['title']."\r\n"; } if ($this->data['company']) { $this->card .= "ORG:".$this->data['company']; } if ($this->data['department']) { $this->card .= ";".$this->data['department']; } $this->card .= "\r\n"; if ($this->data['work_po_box'] || $this->data['work_extended_address'] || $this->data['work_address'] || $this->data['work_city'] || $this->data['work_state'] || $this->data['work_postal_code'] || $this->data['work_country']) { $this->card .= "ADR;TYPE=work:" .$this->data['work_po_box'].";" .$this->data['work_extended_address'].";" .$this->data['work_address'].";" .$this->data['work_city'].";" .$this->data['work_state'].";" .$this->data['work_postal_code'].";" .$this->data['work_country']."\r\n"; } if ($this->data['home_po_box'] || $this->data['home_extended_address'] || $this->data['home_address'] || $this->data['home_city'] || $this->data['home_state'] || $this->data['home_postal_code'] || $this->data['home_country']) { $this->card .= "ADR;TYPE=home:" .$this->data['home_po_box'].";" .$this->data['home_extended_address'].";" .$this->data['home_address'].";" .$this->data['home_city'].";" .$this->data['home_state'].";" .$this->data['home_postal_code'].";" .$this->data['home_country']."\r\n"; } if ($this->data['email1']) { $this->card .= "EMAIL;TYPE=internet,pref:".$this->data['email1']."\r\n"; } if ($this->data['email2']) { $this->card .= "EMAIL;TYPE=internet:".$this->data['email2']."\r\n"; } if ($this->data['office_tel']) { $this->card .= "TEL;TYPE=work,voice:".$this->data['office_tel']."\r\n"; } if ($this->data['home_tel']) { $this->card .= "TEL;TYPE=home,voice:".$this->data['home_tel']."\r\n"; } if ($this->data['cell_tel']) { $this->card .= "TEL;TYPE=cell,voice:".$this->data['cell_tel']."\r\n"; } if ($this->data['fax_tel']) { $this->card .= "TEL;TYPE=work,fax:".$this->data['fax_tel']."\r\n"; } if ($this->data['pager_tel']) { $this->card .= "TEL;TYPE=work,pager:".$this->data['pager_tel']."\r\n"; } if ($this->data['url']) { $this->card .= "URL;TYPE=work:".$this->data['url']."\r\n"; } if ($this->data['birthday']) { $this->card .= "BDAY:".$this->data['birthday']."\r\n"; } if ($this->data['role']) { $this->card .= "ROLE:".$this->data['role']."\r\n"; } if ($this->data['note']) { $this->card .= "NOTE:".$this->data['note']."\r\n"; } $this->card .= "TZ:".$this->data['timezone']."\r\n"; $this->card .= "END:VCARD\r\n"; } function download() { $this->log .= "vcard download() called<br />"; if (!$this->card) { $this->build(); } if (!$this->filename) { $this->filename = trim($this->data['display_name']); } $this->filename = str_replace(" ", "_", $this->filename); header("Content-type: text/directory"); header("Content-Disposition: attachment; filename=".$this->filename.".vcf"); header("Pragma: public"); echo $this->card; return true; } } |
- function build(): checks all the values, builds appropriate defaults for missing values, generates the vcard data string.
- function download(): streams the vcard to the browser client.
Comments
Post a Comment