start);
$end = date('Ymd\THis',$event->end);
$body .= 'BEGIN:VEVENT'."\r\n";
$body .= 'UID:'.$uid."\r\n";
$body .= 'DTSTART:'.$start.'Z'."\r\n";
$body .= 'DTEND:'.$end.'Z'."\r\n";
$body .= 'SUMMARY:'.$event->title."\r\n";
$body .= 'LOCATION:'.$event->location."\r\n";
$body .= 'STATUS:CONFIRMED'."\r\n";
$body .= 'DESCRIPTION:'.$event->description."\r\n";
$body .= 'SEQUENCE:1'."\r\n";
$body .= 'CREATED:'.date('Ymd\THis').'Z'."\r\n";
$body .= 'LAST-MODIFIED:'.date('Ymd\THis').'Z'."\r\n";
if(isset($event->categories)):
foreach($event->categories as $category):
$body .= 'CATEGORIES:'.$category."\r\n";
endforeach;
endif;
if(isset($event->frequency)):
$body .= 'RRULE:FREQ='.strtoupper($event->frequency)."\r\n";
endif;
if(isset($event->alarms)):
foreach($event->alarms as $alarm):
$alarm = strtoupper($alarm);
$alarm = in_array(substr($alarm,-1,1),array('H','M')) ? 'T'.$alarm:$alarm;
$body .= 'BEGIN:VALARM'."\r\n";
$body .= 'ACTION:DISPLAY'."\r\n";
$body .= 'TRIGGER;VALUE=DURATION:-P'.strtoupper($alarm)."\r\n";
$body .= 'DESCRIPTION:'.$event->title."\r\n";
$body .= 'END:VALARM'."\r\n";
endforeach;
endif;
$body .= 'END:VEVENT'."\r\n";
$body .= 'END:VCALENDAR'."\r\n";
$headers = array();
$headers []= 'Content-Type: text/calendar; charset=utf-8';
//if($etag!='') $headers []= 'ETag: "'.$etag.'"';
$out =
self::custom_request(
$this->host.'/'.$this->user.'/'.$this->calendar.'/'.$eventId ,
$this->login.":".$this->password,
'PUT',
$headers,
$body
);
if($out!='') throw new Exception($out);
return $eventId;
}
public function delete_event($ics){
return
self::custom_request(
$this->host.'/'.$this->user.'/'.$this->calendar.'/'.$ics ,
$this->login.":".$this->password,
'DELETE',
array(),
''
);
}
public function get_events($calendar,$start=null,$end=null){
$body = '
'.htmlentities($body).''; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERPWD, $digest); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id()); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); curl_setopt($ch, CURLOPT_POSTFIELDS, $body); $response = curl_exec($ch); curl_close($ch); if(self::debug){ echo '
'.htmlentities($response).''; } return $response; } } class IcalEvent{ public $title,$description,$start,$end,$frequency,$location,$categories,$alarms,$ics; public static function fromFile($ical){ $event = new self(); $lines = array(); foreach(explode("\n",$ical) as $line): $columns = explode(":",$line); if(!isset($columns[1])) continue; $key = $columns[0]; $value = $columns[1]; $keyvalues = explode(';',$key); $key = array_shift($keyvalues); $lines[$key] = $value; endforeach; if(isset($lines['SUMMARY'])) $event->title = $lines['SUMMARY']; if(isset($lines['DESCRIPTION'])) $event->description = $lines['DESCRIPTION']; if(isset($lines['DTSTART'])) $event->start = strtotime($lines['DTSTART']); if(isset($lines['DTEND'])) $event->end = strtotime($lines['DTEND']); if(isset($lines['RRULE'])) $event->frequency = $lines['RRULE']; if(isset($lines['LOCATION'])) $event->location = $lines['LOCATION']; return $event; } } ?>