⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vcard.class.inc

📁 国外很不错的一个开源OA系统Group-Office
💻 INC
📖 第 1 页 / 共 3 页
字号:
	}	/**	* Gets a file content and creates an array line by line.	*	* @param  string $file		Contains the filename (full path).	* @access private	* @return array	*/	function _get_file_content($file) {		$content = "";		if (!$handle = fopen($file, "r")) {			return false;		}		while (!feof($handle)) {			$line = fgets($handle, 4096);			if (strlen($line) > 0) {				/*word wrap - replace <CRLF> by <LF> (dos)*/				$line = str_replace(WORD_WRAP_DOS, WORD_WRAP_UNIX, $line);				/*word wrap - replace <CR> by <LF> (mac)*/				$line = str_replace(WORD_WRAP_MAC, WORD_WRAP_UNIX, $line);				/*unfolding lines ending up in '=<LF>', originally '=<CRLF>'*/				$regex = '/('.DELIM_EQUAL.WORD_WRAP_UNIX.')/i';				$content .= preg_replace($regex, "", $line);			}		}		fclose($handle);		/*unfolding lines as specified in RFC2425*/		$regex = '/('.WORD_WRAP_UNIX.')(['.CHAR_WSP.'|'.CHAR_HTAB.'])/i';		$content = preg_replace($regex, "", $content);		$content = preg_split('/'.WORD_WRAP_UNIX.'/', $content);		return $content;	}		/**	* Gets the addressbook content and creates an array containing the records.	*	* @param  int $addressbook_id	Contains the addressbook id.	* @access private	* @return array	*/	function _get_addressbook($addressbook_id) {		$records = array ();		if ($this->get_contacts($addressbook_id)) {			while ($this->next_record()) {				$records[] = $this->Record;			}		} else {			return false;		}		for ($i = 0; $i < count($records); $i ++) {			$records[$i]['address'] .= !empty ($records[$i]['address_no']) ? CHAR_WSP.$records[$i]['address_no'] : "";			if ($records[$i]['company_id'] > 0) {				if($company = $this->get_company($records[$i]['company_id']))				{					$company['address'] .= !empty ($company['address_no']) ? CHAR_WSP.$company['address_no'] : "";					foreach ($company as $key => $value) {						$field_name = 'company_'.$key;						$records[$i][$field_name] = $value;					}				}			}		}		return $records;	}	/**	* Gets the contact record and creates an array containing the record.	*	* @param  int $contact_id		Contains the contact id.	* @access private	* @return array	*/	function _get_contact($contact_id) {		$records = array ();		$records[] = $this->get_contact($contact_id);		if (count($records)) {			for ($i = 0; $i < count($records); $i ++) {				$records[$i]['address'] .= !empty ($records[$i]['address_no']) ? CHAR_WSP.$records[$i]['address_no'] : "";				if ($records[$i]['company_id'] > 0) {					if($company = $this->get_company($records[$i]['company_id']))					{						$company['address'] .= !empty ($company['address_no']) ? CHAR_WSP.$company['address_no'] : "";						foreach ($company as $key => $value) {							$field_name = 'company_'.$key;							$records[$i][$field_name] = $value;						}					}				}			}		} else {			return false;		}		return $records;	}	/**	* Gets the users personal data record and creates an array containing the record.	*	* @param  int $user_id			Contains the users id.	* @access private	* @return array	*/	function _get_user($user_id = 0) {		global $GO_USERS;		$records = array ();		if (!$user_id) {			global $GO_SECURITY;			$user_id = $GO_SECURITY->user_id;		}		$records[] = $GO_USERS->get_user($user_id);		if (count($records)) {			return $records;		} else {			return false;		}	}		function format_line($name_part, $value_part)	{		global $charset;		$value_part = str_replace("\r\n","\n", $value_part);		$qp_value_part = quoted_printable_encode($value_part);				if($value_part != $qp_value_part)		{			$name_part .= ';ENCODING=QUOTED-PRINTABLE;CHARSET='.$charset.":=\n";			$qp_value_part = str_replace('=0A', '=0D=0A', $qp_value_part);						return explode("\n", $name_part.$qp_value_part);		}else		{			$name_part .= ':';					}		return array($name_part.$value_part);			}	/**	* Creates the vCard file.	*	* @param  array $records		Contains the array with database records.	* @access private	* @return boolean	*/	function _create_vcard($records) {		$lines = array ();		if (is_array($records)) {			/*			if(count($records) > 1) {							$lines[] = "BEGIN:VCARD";						}*/			foreach ($records as $record) {				if ($this->_set_vcard($record, "db")) {					foreach ($this->instance as $vcard) {						//BEGIN:VCARD						$lines[] = "BEGIN:VCARD";						$lines[] = $this->version;												foreach ($vcard as $property) {							switch ($property->name) {								case "N" :									$name_part = $property->name;																																				$value_part =																				$property->values[N_FAMILY].DELIM_SEMICOLON.										$property->values[N_GIVEN].DELIM_SEMICOLON.										$property->values[N_ADDITIONAL].DELIM_SEMICOLON.										$property->values[N_PREFIX];																										$lines = array_merge($lines, $this->format_line($name_part, $value_part));																										$name_part = "FN";									$value_part = $property->values[N_GIVEN].CHAR_WSP.$property->values[N_FAMILY];									$lines = array_merge($lines, $this->format_line($name_part, $value_part));									break;								case "ADR" :									if (!empty ($property->values[ADR_STREET])) {										$parm_types = "";										foreach ($property->parm_types as $parm_type) {											//											$parm_types .= DELIM_SEMICOLON . PARM_TYPE . DELIM_EQUAL . $parm_type;											$parm_types .= DELIM_SEMICOLON.$parm_type;										}										$name_part=$property->name.$parm_types;										$value_part = DELIM_SEMICOLON.DELIM_SEMICOLON.											$property->values[ADR_STREET].DELIM_SEMICOLON.											$property->values[ADR_LOCALITY].DELIM_SEMICOLON.											$property->values[ADR_REGION].DELIM_SEMICOLON.											$property->values[ADR_POSTALCODE].DELIM_SEMICOLON.											$property->values[ADR_COUNTRY];																					$lines = array_merge($lines, $this->format_line($name_part, $value_part));									}									break;								case "EMAIL" :									if (!empty ($property->values[0])) {										$line = $property->name;														foreach ($property->parm_types as $parm_type) {											if(!empty($parm_type))											{												$line .= DELIM_SEMICOLON.$parm_type;											}										}																				$line .= DELIM_COLON.$property->values[0];										$lines[] = $line;									}									break;								case "TEL" :									if (!empty ($property->values[0])) {										$parm_types = "";										foreach ($property->parm_types as $parm_type) {											//											$parm_types .= DELIM_SEMICOLON . PARM_TYPE . DELIM_EQUAL . $parm_type;											$parm_types .= DELIM_SEMICOLON.$parm_type;										}										$lines[] = $property->name.$parm_types.DELIM_COLON.$property->values[0];									}									break;								case "ORG" :									if (!empty ($property->values[ORG_NAME])) {																				$name_part = $property->name;										$value_part = $property->values[ORG_NAME].DELIM_SEMICOLON.$property->values[ORG_UNIT];																				$lines = array_merge($lines, $this->format_line($name_part, $value_part));															}									break;								case "URL" :									if (!empty ($property->values[0])) {										$parm_types = "";										foreach ($property->parm_types as $parm_type) {											//											$parm_types .= DELIM_SEMICOLON . PARM_TYPE . DELIM_EQUAL . $parm_type;											$parm_types .= DELIM_SEMICOLON.$parm_type;										}																				$lines[] = $property->name.$parm_types.DELIM_COLON.$property->values[0];									}									break;								case "BDAY" :													if (intval($property->values[0]) > 0) {										//$lines[] = $property->name.DELIM_COLON.$property->values[0];										$lines = array_merge($lines, $this->format_line($property->name, $property->values[0]));									}									break;								default :									if (!empty ($property->values[0])) {										$lines = array_merge($lines, $this->format_line($property->name, $property->values[0]));									}							}						}						$lines[] = $this->revision;						//END:VCARD						$lines[] = "END:VCARD";					}					unset ($this->instance);				}			}			/*			if(count($records) > 1) {							$lines[] = "END:VCARD";						}*/		}				foreach ($lines as $line) {			$line_parts = array();							while(strlen($line)>LINE_LENGTH)			{				$test = substr($line,0,LINE_LENGTH);								for($i=strlen($test)-1;$i>=0;$i--)				{											$char=$test[$i];					if($char==' ' || $char==';' || $char==':' || $char=='=')					{												$line_parts[] = substr($line, 0, $i+1);						$line = substr($line, $i+1);						break;					}				}			}			$line_parts[] = $line;			for($i=0;$i<count($line_parts);$i++)			{				if($i>0)				{					$this->vcf .= CHAR_WSP;										}							$this->vcf .= $line_parts[$i].WORD_WRAP_DOS;			}		}		if (empty ($this->vcf)) {			return false;		}		return true;	}	/**	* Creates a vcard object.	*	* @param  array $content		Data for the vcf file.	* @param  string $source		Contains information about the source the data comes from "db" or "file".	* @access private	* @return boolean	*/	function _set_vcard($content, $source) {		if (!is_array($content)) {			return false;		}		foreach ($content as $key => $value) {			$property = new vcard_property();			if ($source == "file") {				$property->set($value);				if (count($property->values)) {					if (strtoupper($property->name) == 'BEGIN' && strtoupper($property->values[0]) == 'VCARD') {						$this->index = isset ($this->index) ? $this->index + 1 : 0;					}				}			} else {				$property->set($value, $key);				$this->index = 0;			}			$array_merged = false;			if ($source == "db") {				if ($property->name == "N" || $property->name == "ADR" || $property->name == "ORG") {					for ($i = 0; $i < count($this->instance[$this->index]); $i ++) {						if ($this->instance[$this->index][$i]->name == $property->name) {							if ($this->instance[$this->index][$i]->parm_types[0] == $property->parm_types[0]) {								$this->instance[$this->index][$i]->values = array_merge($this->instance[$this->index][$i]->values, $property->values);								$array_merged = true;							}						}					}				}			}			if (!$array_merged) {				$this->instance[$this->index][] = $property;			}			unset ($property);		}		return true;	}	/**	* Sets the revision of the vCard.	*	* @param  void	* @access private	* @return void	*/	function _set_revision() {		$date = date("Ymd", time());		$time = gmdate("His", time());		$this->revision = "REV".DELIM_COLON.$date.'T'.$time.'Z';	}	/**	* Gets the street name from address.	*	* @param  string	$address Contains the address (street-name and house-number)	* @access private	* @return string	*/	function _get_address($address) {		if (!$address = substr($address, 0, strrpos($address, " "))) {			return CHAR_WSP;		}		return trim($address);	}	/**	* Gets the house-number from address.	*	* @param  string	$address Contains the address (street-name and house-number)	* @access private	* @return string

⌨️ 快捷键说明

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