From bb8f75bdf177e6d9b13b06ebcc2c6de3fe6ad3c1 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Sun, 9 Apr 2006 18:19:45 +0000 Subject: * Adding CalDAV server landing --- caldav.php | 232 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 caldav.php (limited to 'caldav.php') diff --git a/caldav.php b/caldav.php new file mode 100644 index 0000000..dc7555d --- /dev/null +++ b/caldav.php @@ -0,0 +1,232 @@ +mkprop('creationdate', $stat['ctime']); + $file['props'][] = $this->mkprop('getlastmodified', $stat['mtime']); + + if (is_dir($absolutePath)) { + $file['props'][] = $this->mkprop('resourcetype', 'collection'); + + $handle = opendir($absolutePath); + if (!$handle) { + return; + } + + while (($pathComponent = readdir($handle)) !== false) { + if ($pathComponent != '.' && $pathComponent != '..') { + $paths[] = "$path/$pathComponent"; + } + } + closedir($handle); + } else { + $file['props'][] = $this->mkprop('getcontentlength', + $stat['size']); + $file['props'][] = $this->mkprop('resourcetype', null); + } + + $files[] = $file; + $path = array_pop($paths); + } + + return true; + } + + function put(&$options) { + $absolutePath = HTTP_CalDAV_Server_PHPiCalendar::getBasePath() . '/' . + $options['path']; + if (!is_dir(dirname($absolutePath))) { + return '409 Conflict'; + } + + $options['new'] = !file_exists($absolutePath); + $handle = @fopen($absolutePath, 'w'); + if (!$handle) { + return '403 Forbidden'; + } + + return $handle; + } + + function report($options, &$responses) { + global $ALL_CALENDARS_COMBINED; + + $responses = array(); + $paths = availableCalendars(null, null, $ALL_CALENDARS_COMBINED); + foreach ($paths as $path) { + $response = array(); + + $response['ns_hash'] = array(); + $response['ns_hash']['urn:ietf:params:xml:ns:caldav'] = 'C'; + + $response['href'] = $this->getHref(array_pop(explode('/', $path))); + $response['propstat'] = array(); + + $props = array(); + $props[] = $this->mkprop('urn:ietf:params:xml:ns:caldav', 'calendar-data', file_get_contents($path)); + + $response['propstat']['200 OK'] = $props; + $responses[] = $response; + } + + return true; + } +} + +$server = new HTTP_CalDAV_Server_PHPiCalendar(); +$server->ServeRequest(); +?> -- cgit v1.2.3