go_ical.class.inc

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

INC
656
字号
<?php/*Copyright Intermesh 2003Author: Merijn Schering <mschering@intermesh.nl>Version: 1.0 Release date: 14 March 2004This program is free software; you can redistribute it and/or modify itunder the terms of the GNU General Public License as published by theFree Software Foundation; either version 2 of the License, or (at youroption) any later version.TODO: Attendee and VTODO support*/class go_ical extends calendar{	var $calendar_properties = '';	var $events = array();	var $datetime_format = 'Ymd\THis';	var $date_format = 'Ymd';	var $timezone_id = '';	var $version;	var $local_times;	var $line_break="\n";	function go_ical($version='2.0', $local_times=false)	{		$this->db();		$this->version = $version;		$this->local_times = $local_times;		$this->calendar_properties =			"VERSION:".$version.$this->line_break.			"PRODID:-//Intermesh//NONSGML Group-Office//EN".$this->line_break.			"CALSCALE:GREGORIAN".$this->line_break.			"METHOD:PUBLISH".$this->line_break;	}	function export_calendar_header($with_timezones=true)	{		$str= "BEGIN:VCALENDAR".$this->line_break.		$this->calendar_properties;		if($this->version=='2.0' && $with_timezones)		{			$str .= $this->export_timezone();		}		return $str;	}	function export_calendar_footer()	{		return "END:VCALENDAR".$this->line_break;	}	function format_timezone($timezone)	{		if($timezone < 10 && $timezone > -10)		{			if($timezone > 0)			{				$timezone = '+0'.$timezone.'00';			}else			{				$timezone = '-0'.($timezone*-1).'00';			}		}else		{			if($timezone > 0)			{				$timezone = '+'.$timezone.'00';			}else			{				$timezone = '-'.$timezone.'00';			}		}		return $timezone;	}	function export_timezone()	{		global $GO_LANGUAGE;		$this->timezone_id = $GO_LANGUAGE->language['description'];		$timezone =	"BEGIN:VTIMEZONE".$this->line_break.								"TZID:".$this->timezone_id.$this->line_break;								"LAST-MODIFIED:".date($this->date_format, get_time()).$this->line_break;								$dst_tz_offset_from = $this->format_timezone($_SESSION['GO_SESSION']['timezone']);								$dst_tz_offset_to = $this->format_timezone($_SESSION['GO_SESSION']['DST']+$_SESSION['GO_SESSION']['timezone']);								if($_SESSION['GO_SESSION']['DST'] > 0)								{									$timezone .= 	"BEGIN:DAYLIGHT".$this->line_break.										"DTSTART:19700329T030000".$this->line_break.																				"TZOFFSETTO:".$dst_tz_offset_to.$this->line_break.										"TZOFFSETFROM:".$dst_tz_offset_from.$this->line_break.										"TZNAME:GMT".$dst_tz_offset_to.$this->line_break.										"RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=3".$this->line_break.										"END:DAYLIGHT".$this->line_break;								}								$timezone .=  "BEGIN:STANDARD".$this->line_break.									"TZOFFSETTO:".$dst_tz_offset_from.$this->line_break.									"TZOFFSETFROM:".$dst_tz_offset_to.$this->line_break.									"TZNAME:GMT".$dst_tz_offset_from.$this->line_break;									if($_SESSION['GO_SESSION']['DST'] > 0)									{										$timezone .= 	"DTSTART:19701025T040000".$this->line_break.											"RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=-1SU;BYMONTH=10".$this->line_break;									}else									{										$timezone .= "DTSTART:19700101T000000".$this->line_break;									}									$timezone .= 	"END:STANDARD".$this->line_break.									"END:VTIMEZONE".$this->line_break;									return $timezone;	}	function export_event($event_id, $with_timezones=true)	{		$ics = $this->export_calendar_header($with_timezones);		$ics .= $this->convert_event($this->get_event($event_id));		$ics .= $this->export_calendar_footer();		return $ics;	}	function export_calendar($calendar_id)	{		$ics = $this->export_calendar_header();		$cal = new calendar();		$cal->get_events(false,true,false, $calendar_id);		while($cal->next_record())		{			$ics .= $this->convert_event($cal->Record);		}		$ics .= $this->export_calendar_footer();		return $ics;	}	function format_line($name_part, $value_part)	{		global $charset;		$value_part = str_replace("\r\n","\n", $value_part);		/*if(!strpos($value_part, "\n"))		{			return array($name_part.';CHARSET='.$charset.":".$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("\n", "\n ", $qp_value_part);			$qp_value_part = str_replace('=0A', "=0D=0A", $qp_value_part)."\n";						return explode("\n", $name_part.$qp_value_part);		}else		{			$name_part .= ';CHARSET='.$charset.':';					}		return array($name_part.$value_part);			}		function convert_event($event)	{		global $GO_CONFIG, $GO_SECURITY, $charset;				if($this->timezone_id != '' || $this->local_times)		{		  			$timezone_offset = get_timezone_offset($event['start_time'])*3600;		}else		{			$timezone_offset = 0;			}				$lines = array();			if($event['todo']=='1')		{			$lines[] = "BEGIN:VTODO";		}else		{			$lines[] = "BEGIN:VEVENT";		}		$lines[] = "UID:".$event['id'];							$lines = array_merge($lines, $this->format_line('SUMMARY', $event['name']));		if ($event['description'] != '')		{		//$lines =$this->format_line('DESCRIPTION', $event['description']);		//var_dump($lines);			$lines = array_merge($lines, $this->format_line('DESCRIPTION', $event['description']));		}		if ($event['location'] != '')		{			$lines = array_merge($lines, $this->format_line('LOCATION', $event['location']));		}				$status = $this->get_status($event['status_id']);		$lines[] =	"STATUS:".$status['name'];					if($event['permissions'] == PRIVATE_EVENT)		{			$lines[] ="CLASS:PRIVATE";		}else		{			$lines[] ="CLASS:PUBLIC";		}		if($this->version == '1.0' && $event['all_day_event'] == '1')		{			$line = "DTSTART:".date($this->datetime_format, $event['start_time']+$timezone_offset);			if(!$this->local_times) $line .= "Z";			$lines[] = $line;						if($event['todo'] == '1')			{				$line = "DUE:";			}else			{				$line = "DTEND:";							}			//was 59 before nexthaus			$line .= date($this->datetime_format, $event['end_time']+$timezone_offset+60);			if(!$this->local_times) $line .= "Z";			$lines[] = $line;									if($event['completion_time']>0)			{				$line = "COMPLETED:".date($this->datetime_format, $event['start_time']+$timezone_offset);				if(!$this->local_times) $line .= "Z";				$lines[] = $line;			}					}else		{			$DT_format = $event['all_day_event'] == '1' ? $this->date_format : $this->datetime_format;						$line = "DTSTART";						if ($event['all_day_event'] == '1')			{				$line .= ";VALUE=DATE";			}						if($this->timezone_id != '') 			{				$line .= ";TZID=".$this->timezone_id.":".date($DT_format, $event['start_time']+$timezone_offset);			}else			{				$line .= ":".date($DT_format, $event['start_time']+$timezone_offset);							if(!$this->local_times) $line .= "Z";			}				$lines[]=$line;			if($event['todo'] == '1')			{				$line = "DUE";			}else			{				$line = "DTEND";			}			if ($event['all_day_event'] == '1')			{				$line .= ";VALUE=DATE";			}						if($this->timezone_id != '') 			{				$line .= ";TZID=".$this->timezone_id.":".date($DT_format, $event['end_time']+$timezone_offset);			}else			{				$line .= ":".date($DT_format, $event['end_time']+$timezone_offset);								if(!$this->local_times) $line .= "Z";			}						$lines[]=$line;						if($event['completion_time']>0)			{				$line = "COMPLETED";							if ($event['all_day_event'] == '1')				{					$line .= ";VALUE=DATE";				}							if($this->timezone_id != '') 				{					$line .= ";TZID=".$this->timezone_id.":".date($DT_format, $event['start_time']+$timezone_offset);				}else				{					$line .= ":".date($DT_format, $event['start_time']+$timezone_offset);								if(!$this->local_times) $line .= "Z";				}					$lines[]=$line;			}		}								if($this->local_times)		{			$event = $this->shift_days_to_local($event);		}			if($event['todo'] == '0')		{			switch($event['repeat_type'])			{				case REPEAT_DAILY:					if($this->version == '1.0')					{						$line = 'RRULE:D'.$event['repeat_every'];

⌨️ 快捷键说明

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