setLastName('Mustermann'); * ... * $vCard->writeCardFile(); * header('Location:' . $vCard->getCardFilePath()); * * @access public * @author Michael Wimmer * @copyright Michael Wimmer * @link http://www.flaimo.com/ flaimo.com * @version 1.001 */ class vCard { /* V A R I A B L E S */ var $first_name; var $middle_name; var $last_name; var $edu_title; var $addon; var $nickname; var $company; var $organisation; var $department; var $job_title; var $note; var $tel_work1_voice; var $tel_work2_voice; var $tel_home1_voice; var $tel_home2_voice; var $tel_cell_voice; var $tel_car_voice; var $tel_pager_voice; var $tel_additional; var $tel_work_fax; var $tel_home_fax; var $tel_isdn; var $tel_preferred; var $tel_telex; var $work_street; var $work_zip; var $work_city; var $work_region; var $work_country; var $home_street; var $home_zip; var $home_city; var $home_region; var $home_country; var $postal_street; var $postal_zip; var $postal_city; var $postal_region; var $postal_country; var $url_work; var $role; var $birthday; var $email; var $rev; var $lang; /* C O N S T R U C T O R */ /** * Constructor * * Only job is to set all the variablesnames * * @param (string) downloaddir * @param (string) lang * @return (void) * @access private * @since 1.000 - 2002/10/10 */ function vCard($downloaddir = '', $lang = '') { $this->setLanguage($lang); } // end function /* F U N C T I O N S */ /** * Set Language (iso code) for the Strings in the vCard file * * @param (string) isocode * @return (void) * @access private * @since 1.000 - 2002/10/10 */ function setLanguage($isocode = '') { if ($this->isValidLanguageCode($isocode) == true) { $this->lang = (string) ';LANGUAGE=' . $isocode; } else { $this->lang = (string) ''; } // end if } // end function /** * Encodes a string for QUOTE-PRINTABLE * * @param (string) quotprint String to be encoded * @return (string) Encodes string * @access private * @since 1.000 - 2002/10/20 * @author Harald Huemer */ function quotedPrintableEncode($quotprint) { /* //beim Mac Umlaute nicht kodieren !!!! sonst Fehler beim Import if ($progid == 3) { $quotprintenc = preg_replace("~([\x01-\x1F\x3D\x7F-\xBF])~e", "sprintf('=%02X', ord('\\1'))", $quotprint); return($quotprintenc); } //bei Windows und Linux alle Sonderzeichen kodieren else {*/ return (string) preg_replace("~([\x01-\x1F\x3D\x7F-\xFF])~e", "sprintf('=%02X', ord('\\1'))", $quotprint); } // end function /** * Checks if a given string is a valid iso-language-code * * @param (string) code String that should validated * @return (boolean) isvalid If string is valid or not * @access private * @since 1.000 - 2002/10/20 */ function isValidLanguageCode($code) // PHP5: protected { $isvalid = (boolean) false; if (preg_match('(^([a-z]{2})$|^([a-z]{2}_[a-z]{2})$|^([a-z]{2}-[a-z]{2})$)',trim($code)) > 0) { $isvalid = (boolean) true; } // end if return (boolean) $isvalid; } // end function function setFirstName($input) { $this->first_name = (string) $input; } // end function function setMiddleName($input) { $this->middle_name = (string) $input; } // end function function setLastName($input) { $this->last_name = (string) $input; } // end function function setEducationTitle($input) { $this->edu_title = (string) $input; } // end function function setAddon($input) { $this->addon = (string) $input; } // end function function setNickname($input) { $this->nickname = (string) $input; } // end function function setCompany($input) { $this->company = (string) $input; } // end function function setOrganisation($input) { $this->organisation = (string) $input; } // end function function setDepartment($input) { $this->department = (string) $input; } // end function function setJobTitle($input) { $this->job_title = (string) $input; } // end function function setNote($input) { $this->note = (string) $input; } // end function function setTelephoneWork1($input) { $this->tel_work1_voice = (string) $input; } // end function function setTelephoneWork2($input) { $this->tel_work2_voice = (string) $input; } // end function function setTelephoneHome1($input) { $this->tel_home1_voice = (string) $input; } // end function function setTelephoneHome2($input) { $this->tel_home2_voice = (string) $input; } // end function function setCellphone($input) { $this->tel_cell_voice = (string) $input; } // end function function setCarphone($input) { $this->tel_car_voice = (string) $input; } // end function function setPager($input) { $this->tel_pager_voice = (string) $input; } // end function function setAdditionalTelephone($input) { $this->tel_additional = (string) $input; } // end function function setFaxWork($input) { $this->tel_work_fax = (string) $input; } // end function function setFaxHome($input) { $this->tel_work_home = (string) $input; } // end function function setISDN($input) { $this->tel_isdn = (string) $input; } // end function function setPreferredTelephone($input) { $this->tel_preferred = (string) $input; } // end function function setTelex($input) { $this->tel_telex = (string) $input; } // end function function setWorkStreet($input) { $this->work_street = (string) $input; } // end function function setWorkZIP($input) { $this->work_zip = (string) $input; } // end function function setWorkCity($input) { $this->work_city = (string) $input; } // end function function setWorkRegion($input) { $this->work_region = (string) $input; } // end function function setWorkCountry($input) { $this->work_country = (string) $input; } // end function function setHomeStreet($input) { $this->home_street = (string) $input; } // end function function setHomeZIP($input) { $this->home_zip = (string) $input; } // end function function setHomeCity($input) { $this->home_city = (string) $input; } // end function function setHomeRegion($input) { $this->home_region = (string) $input; } // end function function setHomeCountry($input) { $this->home_country = (string) $input; } // end function function setPostalStreet($input) { $this->postal_street = (string) $input; } // end function function setPostalZIP($input) { $this->postal_zip = (string) $input; } // end function function setPostalCity($input) { $this->postal_city = (string) $input; } // end function function setPostalRegion($input) { $this->postal_region = (string) $input; } // end function function setPostalCountry($input) { $this->postal_country = (string) $input; } // end function function setURLWork($input) { $this->url_work = (string) $input; } // end function function setRole($input) { $this->role = (string) $input; } // end function function setBirthday($timestamp) { $this->birthday = (int) date('Ymd',$timestamp); } // end function function setEMail($input) { $this->email = (string) $input; } // end function /** * Generates the string to be written in the file later on * * @return (void) * @see getCardOutput(), writeCardFile() * @access public * @since 1.000 - 2002/10/10 */ function generateCardOutput() { $this->output = (string) "BEGIN:VCARD\r\n"; $this->output .= (string) "VERSION:2.1\r\n"; $this->output .= (string) "N;ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->last_name . ";" . $this->first_name . ";" . $this->middle_name . ";" . $this->addon) . "\r\n"; $this->output .= (string) "FN;ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->first_name . " " . $this->middle_name . " " . $this->last_name . " " . $this->addon) . "\r\n"; if (strlen(trim($this->nickname)) > 0) { $this->output .= (string) "NICKNAME;ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->nickname) . "\r\n"; } // end if $this->output .= (string) "ORG" . $this->lang . ";ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->organisation) . ";" . $this->quotedPrintableEncode($this->department) . "\r\n"; if (strlen(trim($this->job_title)) > 0) { $this->output .= (string) "TITLE" . $this->lang . ";ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->job_title) . "\r\n"; } // end if if (strlen(trim($this->note)) > 0) { $this->output .= (string) "NOTE" . $this->lang . ";ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->note) . "\r\n"; } // end if if (strlen(trim($this->tel_work1_voice)) > 0) { $this->output .= (string) "TEL;WORK;VOICE:" . $this->tel_work1_voice . "\r\n"; } // end if if (strlen(trim($this->tel_work2_voice)) > 0) { $this->output .= (string) "TEL;WORK;VOICE:" . $this->tel_work1_voice . "\r\n"; } // end if if (strlen(trim($this->tel_home1_voice)) > 0) { $this->output .= (string) "TEL;HOME;VOICE:" . $this->tel_home1_voice . "\r\n"; } // end if if (strlen(trim($this->tel_cell_voice)) > 0) { $this->output .= (string) "TEL;CELL;VOICE:" . $this->tel_cell_voice . "\r\n"; } // end if if (strlen(trim($this->tel_car_voice)) > 0) { $this->output .= (string) "TEL;CAR;VOICE:" . $this->tel_car_voice . "\r\n"; } // end if if (strlen(trim($this->tel_additional)) > 0) { $this->output .= (string) "TEL;VOICE:" . $this->tel_additional . "\r\n"; } // end if if (strlen(trim($this->tel_pager_voice)) > 0) { $this->output .= (string) "TEL;PAGER;VOICE:" . $this->tel_pager_voice . "\r\n"; } // end if if (strlen(trim($this->tel_work_fax)) > 0) { $this->output .= (string) "TEL;WORK;FAX:" . $this->tel_work_fax . "\r\n"; } // end if if (strlen(trim($this->tel_home_fax)) > 0) { $this->output .= (string) "TEL;HOME;FAX:" . $this->tel_home_fax . "\r\n"; } // end if if (strlen(trim($this->tel_home2_voice)) > 0) { $this->output .= (string) "TEL;HOME:" . $this->tel_home2_voice . "\r\n"; } // end if if (strlen(trim($this->tel_isdn)) > 0) { $this->output .= (string) "TEL;ISDN:" . $this->tel_isdn . "\r\n"; } // end if if (strlen(trim($this->tel_preferred)) > 0) { $this->output .= (string) "TEL;PREF:" . $this->tel_preferred . "\r\n"; } // end if $this->output .= (string) "ADR;WORK:;" . $this->company . ";" . $this->work_street . ";" . $this->work_city . ";" . $this->work_region . ";" . $this->work_zip . ";" . $this->work_country . "\r\n"; $this->output .= (string) "LABEL;WORK;ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->company) . "=0D=0A" . $this->quotedPrintableEncode($this->work_street) . "=0D=0A" . $this->quotedPrintableEncode($this->work_city) . ", " . $this->quotedPrintableEncode($this->work_region) . " " . $this->quotedPrintableEncode($this->work_zip) . "=0D=0A" . $this->quotedPrintableEncode($this->work_country) . "\r\n"; $this->output .= (string) "ADR;HOME;;" . $this->home_street . ";" . $this->home_city . ";" . $this->home_region . ";" . $this->home_zip . ";" . $this->home_country . "\r\n"; $this->output .= (string) "LABEL;WORK;ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->home_street) . "=0D=0A" . $this->quotedPrintableEncode($this->home_city) . ", " . $this->quotedPrintableEncode($this->home_region) . " " . $this->quotedPrintableEncode($this->home_zip) . "=0D=0A" . $this->quotedPrintableEncode($this->home_country) . "\r\n"; $this->output .= (string) "ADR;POSTAL;;" . $this->postal_street . ";" . $this->postal_city . ";" . $this->postal_region . ";" . $this->postal_zip . ";" . $this->postal_country . "\r\n"; $this->output .= (string) "LABEL;POSTAL;ENCODING=QUOTED-PRINTABLE:" . $this->quotedPrintableEncode($this->postal_street) . "=0D=0A" . $this->quotedPrintableEncode($this->postal_city) . ", " . $this->quotedPrintableEncode($this->postal_region) . " " . $this->quotedPrintableEncode($this->postal_zip) . "=0D=0A" . $this->quotedPrintableEncode($this->postal_country) . "\r\n"; if (strlen(trim($this->url_work)) > 0) { $this->output .= (string) "URL;WORK:" . $this->url_work . "\r\n"; } // end if if (strlen(trim($this->role)) > 0) { $this->output .= (string) "ROLE" . $this->lang . ":" . $this->role . "\r\n"; } // end if if (strlen(trim($this->birthday)) > 0) { $this->output .= (string) "BDAY:" . $this->birthday . "\r\n"; } // end if if (strlen(trim($this->email)) > 0) { $this->output .= (string) "EMAIL;PREF;INTERNET:" . $this->email . "\r\n"; } // end if if (strlen(trim($this->tel_telex)) > 0) { $this->output .= (string) "EMAIL;TLX:" . $this->tel_telex . "\r\n"; } // end if $this->output .= (string) "REV:" . $this->rev . "\r\n"; $this->output .= (string) "END:VCARD\r\n"; } // end function /** * Loads the string into the variable if it hasn't been set before * * @return (string) output * @see generateCardOutput(), writeCardFile() * @access public * @since 1.000 - 2002/10/10 */ function getCardOutput() { if (!isset($this->output)) { $this->generateCardOutput(); } // end if return (string) $this->output; } // end function }; //class ?>