📄 vcard.class.inc
字号:
<?php/* Copyright Lorenz Softwareentwicklung & Systemintegration 2004 Author: Georg Lorenz <georg@lonux.de> Version: 0.99 Release date: 17 May 2004 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. */define("ADR_POBOX", "ADR_0");define("ADR_EXTENDED", "ADR_1");define("ADR_STREET", "ADR_2");define("ADR_LOCALITY", "ADR_3");define("ADR_REGION", "ADR_4");define("ADR_POSTALCODE", "ADR_5");define("ADR_COUNTRY", "ADR_6");define("N_FAMILY", "N_0");define("N_GIVEN", "N_1");define("N_ADDITIONAL", "N_2");define("N_PREFIX", "N_3");define("N_SUFFIX", "N_4");define("ORG_NAME", "ORG_0");define("ORG_UNIT", "ORG_1");define("ORG_OPTIONAL_UNIT", "ORG_2");define("GO_COMPANY_POST_ADDRESS", "X-GO-COMPANY-POST-ADDRESS");define("GO_COMPANY_POST_ADDRESS_NO", "X-GO-COMPANY-POST-ADDRESS-NO");define("GO_COMPANY_POST_CITY", "X-GO-COMPANY-POST-CITY");define("GO_COMPANY_POST_ZIP", "X-GO-COMPANY-POST-ZIP");define("GO_COMPANY_POST_STATE", "X-GO-COMPANY-POST-STATE");define("GO_COMPANY_POST_COUNTRY", "X-GO-COMPANY-POST-COUNTRY");define("GO_COMPANY_TEL", "X-GO-COMPANY-TEL");define("GO_COMPANY_FAX", "X-GO-COMPANY-FAX");define("GO_COMPANY_URL", "X-GO-COMPANY-URL");define("GO_COMPANY_EMAIL", "X-GO-COMPANY-EMAIL");define("GO_COMPANY_BANK_NO", "X-GO-COMPANY-BANK-NO");define("GO_COMPANY_VAT_NO", "X-GO-COMPANY-VAT-NO");define("PARM_TYPE", "TYPE");define("PARM_ENCODING", "ENCODING");define("PARM_VALUE", "VALUE");define("PARM_CHARSET", "CHARSET");define("PARM_LANGUAGE", "LANGUAGE");define("DELIM_DOT", ".");define("DELIM_COLON", ":");define("DELIM_SEMICOLON", ";");define("DELIM_COMMA", ",");define("DELIM_EQUAL", "=");define("LINE_LENGTH", 75);define("FOLDING_CHAR", chr(13).chr(10).chr(32));define("WORD_WRAP_DOS", chr(13).chr(10));define("WORD_WRAP_MAC", chr(13));define("WORD_WRAP_UNIX", chr(10));define("CHAR_WSP", chr(32));define("CHAR_HTAB", chr(9));/*** vCard class containing methods and properties* for dealing with vCard files (vcf)** @package addressbook vcf class* @author Georg Lorenz <georg@lonux.de>* @since Group-Office 2.06*/class vcard extends addressbook { var $index; var $instance; var $version; var $revision; var $vcf; function vcard() { $this->index = null; $this->instance = array (); $this->version = 'VERSION:2.1'; $this->_set_revision(); $this->addressbook(); $this->vcf = ''; } /** * Imports personal data from a vcf file into users addressbook. * * @param string $file Contains the file name to be imported. * @param int $user_id Users id. * @param int $addressbook_id Addressbook id. * @access public * @return boolean */ function import($file, $user_id, $addressbook_id) { if ($content = $this->_get_file_content($file)) { if ($this->_set_vcard($content, "file")) { foreach ($this->instance as $vcard) { $record = $this->_get_vcard_contact($vcard); $contact = array_map('addslashes', $record['contact']); $company = array_map('addslashes', $record['company']); global $GO_SECURITY; if ($ab = $this->get_addressbook($addressbook_id)) { $contact['addressbook_id'] = $company['addressbook_id']= $addressbook_id; if(trim($contact['company_name']) != '') { if(!$contact['company_id'] = $this->get_company_id_by_name($contact['company_name'], $addressbook_id)) { $contact['company_id'] = $this->add_company($company); } } unset($contact['company_name']); $this->add_contact($contact); } else { return false; } } } else { return false; } } else { return false; } return true; } function vcf_to_go($vcf_string) { $vcf_string = str_replace(WORD_WRAP_DOS, WORD_WRAP_UNIX, $vcf_string); /*word wrap - replace <CR> by <LF> (mac)*/ $vcf_string = str_replace(WORD_WRAP_MAC, WORD_WRAP_UNIX, $vcf_string); /*unfolding lines ending up in '=<LF>', originally '=<CRLF>'*/ $regex = '/('.DELIM_EQUAL.WORD_WRAP_UNIX.')/i'; $vcf_string = preg_replace($regex, "", $vcf_string); $regex = '/('.WORD_WRAP_UNIX.')(['.CHAR_WSP.'|'.CHAR_HTAB.'])/i'; $vcf_string = preg_replace($regex, "", $vcf_string); $content = preg_split('/'.WORD_WRAP_UNIX.'/', $vcf_string); if($this->_set_vcard($content, "file")) { return $this->_get_vcard_contact($this->instance[0]); } return false; } /** * Creates a vcf file from addressbook contacts. * * @param int $addressbook_id Addressbook id. * @access public * @return string */ function export_addressbook($addressbook_id) { $records = $this->_get_addressbook($addressbook_id); if ($records) { return $this->_create_vcard($records); } return false; } /** * Creates a vcf file for a contact. * * @param int $contact_id Contact id. * @access public * @return string */ function export_contact($contact_id) { $records = $this->_get_contact($contact_id); if ($records) { return $this->_create_vcard($records); } return false; } /** * Creates a vcf file from users personal data. * * @param int $user_id Users id. * @access public * @return string */ function create($user_id) { $records = $this->_get_user($user_id); if ($records) { return $this->_create_vcard($records); } return false; } /** * Determines the count of vcards. * * @param string $file vCard file. * @access public * @return int */ function get_count($file) { if ($content = $this->_get_file_content($file)) { if ($this->_set_vcard($content, "file")) { return count($this->instance); } } return false; } /** * Returns the vCard record. * * @param int $index index of vCard. * @access public * @return array */ function get_vcard_contact($index) { if (isset ($this->instance[$index])) { return $this->_get_vcard_contact($this->instance[$index]); } return false; } /** * Returns the formatted record for database storage. * * @param array $vcard vCard record. * @access private * @return array */ function _get_vcard_contact($vcard) { $record = array (); //$record['contact'] = array ('source_id' => '0', 'first_name' => '', 'middle_name' => '', 'last_name' => '', 'title' => '', 'function' => '', 'birthday' => '', 'sex' => 'M', 'initials' => '', 'country' => '', 'state' => '', 'city' => '', 'zip' => '', 'address' => '', 'address_no' => '', 'fax' => '', 'home_phone' => '', 'work_fax' => '', 'work_phone' => '', 'cellular' => '', 'email' => '', 'company_id' => '0', 'company_name' => '', 'department' => '', 'comment' => ''); //$record['company'] = array ('name' => '', 'homepage' => '', 'country' => '', 'state' => '', 'city' => '', 'zip' => '', 'address' => '', 'address_no' => '', 'phone' => '', 'fax' => '', 'email' => '', 'bank_no' => '', 'vat_no' => '', 'post_address' => '', 'post_address_no' => '', 'post_state' => '', 'post_city' => '', 'post_zip' => '', 'post_country' => '');//go_log(LOG_DEBUG, var_export($vcard, true)); foreach ($vcard as $property) { switch ($property->name) { case "N" : $record['contact']['title'] = isset ($property->values[N_PREFIX]) ? $property->values[N_PREFIX] : ""; $record['contact']['last_name'] = isset ($property->values[N_FAMILY]) ? $property->values[N_FAMILY] : ""; $record['contact']['first_name'] = isset ($property->values[N_GIVEN]) ? $property->values[N_GIVEN] : ""; $record['contact']['middle_name'] = isset ($property->values[N_ADDITIONAL]) ? $property->values[N_ADDITIONAL] : ""; //MS: TODO add suffix field to GO? break; case "TITLE" : $record['contact']['function'] = empty ($property->values[0]) ? '' : $property->values[0]; break; case "ROLE" : //$record['contact']['function'] = empty ($property->values[0]) ? '' : $property->values[0]; break; case "BDAY" : if (!empty ($property->values[0])) { if (!is_numeric($property->values[0])) { $date = explode("-", $property->values[0]); $property->values[0] = date("Ymd", mktime(0, 0, 0, $date[1], $date[2], $date[0])); } $record['contact']['birthday'] = $property->values[0]; } break; case "ADR" : if (in_array('WORK', $property->parm_types)) { $record['company']['country'] = isset ($property->values[ADR_COUNTRY]) ? $property->values[ADR_COUNTRY] : ""; $record['company']['state'] = isset ($property->values[ADR_REGION]) ? $property->values[ADR_REGION] : ""; $record['company']['city'] = isset ($property->values[ADR_LOCALITY]) ? $property->values[ADR_LOCALITY] : ""; $record['company']['zip'] = isset ($property->values[ADR_POSTALCODE]) ? $property->values[ADR_POSTALCODE] : ""; $record['company']['address'] = isset ($property->values[ADR_STREET]) ? $this->_get_address($property->values[ADR_STREET]) : ""; $record['company']['address_no'] = isset ($property->values[ADR_STREET]) ? $this->_get_address_no($property->values[ADR_STREET]) : ""; } elseif(in_array('HOME', $property->parm_types)) { $record['contact']['country'] = isset ($property->values[ADR_COUNTRY]) ? $property->values[ADR_COUNTRY] : ""; $record['contact']['state'] = isset ($property->values[ADR_REGION]) ? $property->values[ADR_REGION] : ""; $record['contact']['city'] = isset ($property->values[ADR_LOCALITY]) ? $property->values[ADR_LOCALITY] : ""; $record['contact']['zip'] = isset ($property->values[ADR_POSTALCODE]) ? $property->values[ADR_POSTALCODE] : ""; $record['contact']['address'] = isset ($property->values[ADR_STREET]) ? $this->_get_address($property->values[ADR_STREET]) : ""; $record['contact']['address_no'] = isset ($property->values[ADR_STREET]) ? $this->_get_address_no($property->values[ADR_STREET]) : ""; } break; case "TEL" : if (in_array('HOME', $property->parm_types)) { if (in_array('FAX', $property->parm_types)) { $record['contact']['fax'] = $property->values[0]; } if (in_array('VOICE', $property->parm_types)) { $record['contact']['home_phone'] = $property->values[0]; } if (!in_array('FAX', $property->parm_types) && !in_array('VOICE', $property->parm_types)) { $record['contact']['home_phone'] = $property->values[0]; } } if (in_array('WORK', $property->parm_types)) { if (in_array('FAX', $property->parm_types)) { $record['contact']['work_fax'] = $property->values[0]; } if (in_array('VOICE', $property->parm_types)) { $record['contact']['work_phone'] = $property->values[0]; } if (!in_array('FAX', $property->parm_types) && !in_array('VOICE', $property->parm_types)) { $record['contact']['work_phone'] = $property->values[0]; } }elseif (in_array('CELL', $property->parm_types)) { $record['contact']['cellular'] = $property->values[0]; }else { if (in_array('FAX', $property->parm_types)) { if(!isset($record['contact']['fax'])) { $record['contact']['fax'] = $property->values[0]; } } if (in_array('VOICE', $property->parm_types)) { if(!isset($record['contact']['home_phone'])) { $record['contact']['home_phone'] = $property->values[0]; } } if (!in_array('FAX', $property->parm_types) && !in_array('VOICE', $property->parm_types)) { if(!isset($record['contact']['home_phone'])) { $record['contact']['home_phone'] = $property->values[0]; } } } break; case "EMAIL" : if(isset($record['contact']['email3'])) { //we ran out of email addres storage sorry. }elseif(isset($record['contact']['email2'])) { $record['contact']['email3'] = $property->values[0]; }elseif(isset($record['contact']['email'])) { $record['contact']['email2'] = $property->values[0]; }else { $record['contact']['email'] = $property->values[0]; } break; case "ORG" : //$record['contact']['company_name'] = isset ($property->values[ORG_NAME]) ? $property->values[ORG_NAME] : ""; $record['contact']['department'] = isset ($property->values[ORG_UNIT]) ? $property->values[ORG_UNIT] : ""; $record['company']['name'] = isset ($property->values[ORG_NAME]) ? $property->values[ORG_NAME] : ""; break; case "URL" : if (in_array('WORK', $property->parm_types)) { $record['company']['homepage'] = $property->values[0]; } break; case "NOTE" : $record['contact']['comment'] = $property->values[0]; break; case "TZ" : break; case GO_COMPANY_POST_ADDRESS : $record['company']['post_address'] = $property->values[0]; break; case GO_COMPANY_POST_ADDRESS_NO : $record['company']['post_address_no'] = $property->values[0]; break; case GO_COMPANY_POST_CITY : $record['company']['post_city'] = $property->values[0]; break; case GO_COMPANY_POST_ZIP : $record['company']['post_zip'] = $property->values[0]; break; case GO_COMPANY_POST_STATE : $record['company']['post_state'] = $property->values[0]; break; case GO_COMPANY_POST_COUNTRY : $record['company']['post_country'] = $property->values[0]; break; case GO_COMPANY_TEL : $record['company']['phone'] = $property->values[0]; break; case GO_COMPANY_FAX : $record['company']['fax'] = $property->values[0]; break; case GO_COMPANY_EMAIL : $record['company']['email'] = $property->values[0]; break; case GO_COMPANY_BANK_NO : $record['company']['bank_no'] = $property->values[0]; break; case GO_COMPANY_VAT_NO : $record['company']['vat_no'] = $property->values[0]; break; } } return $record;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -