vcard.class.inc

来自「国外很不错的一个开源OA系统Group-Office」· INC 代码 · 共 1,194 行 · 第 1/3 页

INC
1,194
字号
	*/	function _get_address_no($address) {		if (!$address_no = strrchr($address, " ")) {			return CHAR_WSP;		}		return trim($address_no);	}}/*** vCard property class containing methods and properties* for creating of vCard properties.** @package  addressbook vcf class* @author   Georg Lorenz <georg@lonux.de>* @since    Group-Office 2.06*/class vcard_property {	var $group;	var $name;	var $parm_encoding;	var $parm_language;	var $parm_value;	var $parm_charset;	var $parm_types;	var $values;	function vcard_property() {		$this->group = null;		$this->name = null;		$this->parm_encoding = null;		$this->parm_language = null;		$this->parm_value = null;		$this->parm_charset = null;		$this->parm_types = array ();		$this->values = array ();	}	/**	* Creates the property object.	*	* @param  string $value		Contains the property data.	* @param  string $key		Contains the fieldname of the db record.	* @access public	* @return void	*/	function set($value, $key = "") {		if (empty ($key)) { // file content			if ($pos = strpos($value, DELIM_COLON)) {				$left_part = trim(substr($value, 0, $pos));				$right_part = trim(substr($value, $pos +1));				$this->_set_name($left_part);				$this->_set_parms($left_part);				$this->_set_values($right_part);			}		} else { // db content			$this->parm_types[0] = "";			switch ($key) {				case "first_name" :					$this->name = "N";					$this->values[N_GIVEN] = $value;					break;				case "middle_name" :					$this->name = "N";					$this->values[N_ADDITIONAL] = $value;					break;				case "last_name" :					$this->name = "N";					$this->values[N_FAMILY] = $value;					break;				case "title" :					$this->name = "N";					$this->values[N_PREFIX] = $value;					break;				case "birthday" :					$this->name = "BDAY";					$this->values[0] = (!empty($value) && $value != '0000-00-00') ? date("Ymd", db_date_to_unixtime($value)) : '';					break;				case "email" :					$this->name = "EMAIL";					$this->parm_types[0] = "INTERNET";					$this->parm_types[1] = "PREF";					$this->values[0] = $value;					break;				case "email2":					$this->name = "EMAIL";					$this->parm_types[0] = "INTERNET";					$this->values[0] = $value;				break;				case "email3":					$this->name = "EMAIL";					$this->parm_types[0] = "INTERNET";					$this->values[0] = $value;				break;				case "function" :					//$this->name = "ROLE";					$this->name = "TITLE";					$this->values[0] = $value;					break;				case "home_phone" :					$this->name = "TEL";					$this->parm_types[0] = "HOME";					$this->values[0] = $value;					break;				case "work_phone" :					$this->name = "TEL";					$this->parm_types[] = "WORK";					$this->values[] = $value;					break;				case "fax" :					$this->name = "TEL";					$this->parm_types[0] = "FAX";					$this->parm_types[1] = "HOME";					$this->values[0] = $value;					break;				case "work_fax" :					$this->name = "TEL";					$this->parm_types[0] = "FAX";					$this->parm_types[1] = "WORK";					$this->values[0] = $value;					break;				case "cellular" :					$this->name = "TEL";					$this->parm_types[0] = "CELL";					$this->values[0] = $value;					break;				case "country" :					$this->name = "ADR";					$this->parm_types[0] = "HOME";					$this->values[ADR_COUNTRY] = $value;					break;				case "state" :					$this->name = "ADR";					$this->parm_types[0] = "HOME";					$this->values[ADR_REGION] = $value;					break;				case "city" :					$this->name = "ADR";					$this->parm_types[0] = "HOME";					$this->values[ADR_LOCALITY] = $value;					break;				case "zip" :					$this->name = "ADR";					$this->parm_types[0] = "HOME";					$this->values[ADR_POSTALCODE] = $value;					break;				case "address" :					$this->name = "ADR";					$this->parm_types[0] = "HOME";					$this->values[ADR_STREET] = $value;					break;				case "comment" :					$this->name = "NOTE";					$this->values[0] = $value;					break;				case "department" :					$this->name = "ORG";					$this->values[ORG_UNIT] = $value;					break;				case "company_name" :					$this->name = "ORG";					$this->values[ORG_NAME] = $value;					break;				case "company_address" :					$this->name = "ADR";					$this->parm_types[0] = "WORK";					$this->values[ADR_STREET] = $value;					break;				case "company_zip" :					$this->name = "ADR";					$this->parm_types[0] = "WORK";					$this->values[ADR_POSTALCODE] = $value;					break;				case "company_city" :					$this->name = "ADR";					$this->parm_types[0] = "WORK";					$this->values[ADR_LOCALITY] = $value;					break;				case "company_state" :					$this->name = "ADR";					$this->parm_types[0] = "WORK";					$this->values[ADR_REGION] = $value;					break;				case "company_country" :					$this->name = "ADR";					$this->parm_types[0] = "WORK";					$this->values[ADR_COUNTRY] = $value;					break;				case "company_homepage" :					$this->name = "URL";					$this->parm_types[0] = "WORK";					$this->values[0] = $value;					break;				case "company_phone" :					$this->name = GO_COMPANY_TEL;					$this->values[0] = $value;					break;				case "company_fax" :					$this->name = GO_COMPANY_FAX;					$this->values[0] = $value;					break;				case "company_email" :					$this->name = GO_COMPANY_EMAIL;					$this->values[0] = $value;					break;				case "company_bank_no" :					$this->name = GO_COMPANY_BANK_NO;					$this->values[0] = $value;					break;				case "company_vat_no" :					$this->name = GO_COMPANY_VAT_NO;					$this->values[0] = $value;					break;				case "company_post_address" :					$this->name = GO_COMPANY_POST_ADDRESS;					$this->values[0] = $value;					break;				case "company_post_address_no" :					$this->name = GO_COMPANY_POST_ADDRESS_NO;					$this->values[0] = $value;					break;				case "company_post_city" :					$this->name = GO_COMPANY_POST_CITY;					$this->values[0] = $value;					break;				case "company_post_zip" :					$this->name = GO_COMPANY_POST_ZIP;					$this->values[0] = $value;					break;				case "company_post_state" :					$this->name = GO_COMPANY_POST_STATE;					$this->values[0] = $value;					break;				case "company_post_country" :					$this->name = GO_COMPANY_POST_COUNTRY;					$this->values[0] = $value;					break;			}		}	}	/**	* Sets the name of the property.	*	* @param  string $text		Contains the property data.	* @access private	* @return void	*/	function _set_name($text) {		/*		//	we need the first element only		//	it may contain a value e.g. ADR or A.ADR		*/		$arr=$this->_split($text, DELIM_SEMICOLON);		$name_part = array_shift($arr);		if ($pos = strpos($name_part, DELIM_DOT)) {			$array = $this->_split($name_part, DELIM_DOT);			$this->group = strtoupper(trim(array_shift($array)));			$this->name = strtoupper(trim(array_shift($array)));		} else {			$this->name = strtoupper(trim($name_part));		}	}	/**	* Sets the parameters of the property.	*	* @param  string $text		Contains the property data.	* @access private	* @return void	*/	function _set_parms($text) {		static $encodings = array ('7BIT', '8BIT', 'BASE64', 'QUOTED-PRINTABLE', 'B');		static $values = array ('INLINE', 'CONTENT-ID', 'CID', 'URL', 'BINARY', 'PHONE-NUMBER', 'TEXT', 'URI', 'UTC-OFFSET', 'VCARD');		$parm_array = $this->_split($text, DELIM_SEMICOLON);		/*remove the first array value - it is the property name, we don't need it*/		array_shift($parm_array);		foreach ($parm_array as $array_value) {			$parm = $this->_split($array_value, DELIM_COMMA);			foreach ($parm as $value) {				$parameter = $this->_split($value, DELIM_EQUAL);				if (count($parameter) > 1) {					switch (strtoupper(trim($parameter[0]))) {						case PARM_ENCODING :							$this->parm_encoding = strtoupper(trim($parameter[1]));							break;						case PARM_VALUE :							$this->parm_value = strtoupper(trim($parameter[1]));							break;						case PARM_CHARSET :							$this->parm_charset = strtoupper(trim($parameter[1]));							break;						case PARM_LANGUAGE :							$this->parm_language = strtoupper(trim($parameter[1]));							break;						default :							$this->parm_types[] = strtoupper(trim($parameter[1]));							break;					}				} else {					$parameter[0] = strtoupper(trim($parameter[0]));					if (in_array($parameter[0], $encodings)) {						$this->parm_encoding = $parameter[0];					}					elseif (in_array($parameter[0], $values)) {						$this->parm_value = $parameter[0];					} else {						$this->parm_types[] = $parameter[0];					}				}			}		}	}	/**	* Sets the values of the property.	*	* @param  string $text		Contains the property data.	* @access private	* @return void	*/	function _set_values($text) {		switch ($this->parm_encoding) {			case 'QUOTED-PRINTABLE' :				$text = quoted_printable_decode($text);				break;			case 'BASE64' :				$text = base64_decode($text);				break;			case 'B' :				break;			case '8BIT' :				break;			case '7BIT' :				break;		} // switch		$values = $this->_split($text, DELIM_SEMICOLON);		switch ($this->name) {			case 'N' :				$this->values[N_FAMILY] = isset ($values[0]) ? $values[0] : "";				$this->values[N_GIVEN] = isset ($values[1]) ? $values[1] : "";				$this->values[N_ADDITIONAL] = isset ($values[2]) ? $values[2] : "";				$this->values[N_PREFIX] = isset ($values[3]) ? $values[3] : "";				$this->values[N_SUFFIX] = isset ($values[4]) ? $values[4] : "";				break;			case 'ADR' :				$this->values[ADR_POBOX] = isset ($values[0]) ? $values[0] : "";				$this->values[ADR_EXTENDED] = isset ($values[1]) ? $values[1] : "";				$this->values[ADR_STREET] = isset ($values[2]) ? $values[2] : "";				$this->values[ADR_LOCALITY] = isset ($values[3]) ? $values[3] : "";				$this->values[ADR_REGION] = isset ($values[4]) ? $values[4] : "";				$this->values[ADR_POSTALCODE] = isset ($values[5]) ? $values[5] : "";				$this->values[ADR_COUNTRY] = isset ($values[6]) ? $values[6] : "";				break;			case 'ORG' :				$this->values[ORG_NAME] = isset ($values[0]) ? $values[0] : "";				$this->values[ORG_UNIT] = isset ($values[1]) ? $values[1] : "";				$this->values[ORG_OPTIONAL_UNIT] = isset ($values[2]) ? $values[2] : "";				break;			default :				$this->values = $this->_split($text, DELIM_SEMICOLON);				break;		}	}	/**	* Splits a string into an array by given delimiter.	*	* @param  string $text		Contains the property data.	* @param  string $delimiter	Contains the delimiter.	* @access private	* @return array	*/	function _split($text, $delimiter) {		switch ($delimiter) {			case DELIM_SEMICOLON :				$delimiter = '\\'.$delimiter;				break;			case DELIM_COMMA :				$delimiter = '\\'.$delimiter;				break;			default :				break;		} // switch		$regex = '/(?<!\\\\)('.$delimiter.')/i';		$array = preg_split($regex, $text);		return $array;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?