function simpleCalDAVconnect($url, $user, $pass) { // Check for missing arguments if (!(isset($url) && isset($user) && isset($pass))) { return array(1, 'Missing arguments'); } // Connect to CalDAV-Server and log in $client = new CalDAVClient($url, $user, $pass); // Check for errors if (!$client->CheckValidCalDAV()) { if ($client->GetHttpResultCode() == '401') { return array(2, 'Login failed', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } elseif ($client->GetHttpResultCode() == '') { return array(3, 'Can\'t reach server', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } else { return array(4, 'Recieved unknown HTTP status while checking the connection after establishing it', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } } // set url to our calendar (CalDAV-protocol supports multiple calendars) $client->SetCalendar($url); // Is valid calendar? if (count($client->GetCalendarDetailsByURL($url)) == 0) { return array(5, 'Can\'t find the calendar on the CalDAV-server', $client->GetHttpRequest(), $client->GetBody(), $client->GetResponseHeaders(), $client->GetXmlResponse()); } return array(0, $client); }
// printf( "No calendars found based on '%s'\n", $args->url ); // } // // // Now we have all of the remote calendars, we will look for the URL that // // matches what we were originally supplied. While this seems laborious // // because we already have it, it means we could provide a match in some // // other way (e.g. on displayname) and we could also present a list to // // the user which is built from following the above process. // foreach( $calendars AS $k => $a_calendar ) { // if ( $a_calendar->url == $args->url ) $calendar = $a_calendar; // } // if ( !isset($calendar) ) $calendar = $calendars[0]; // In reality we could have omitted all of the above parts, If we really do // know the correct URL at the start. // Everything now will be at our calendar URL $caldav->SetCalendar($args->url); $calendar = $caldav->GetCalendarDetails(); printf("Remote calendar '%s' is at %s\n", $calendar->displayname, $calendar->url); // Generate a consistent filename for our synchronisation cache if (!file_exists($args->cache_directory) && !is_dir($args->cache_directory)) { mkdir($args->cache_directory, 0750); // Not incredibly sensitive file contents - URLs and ETags } $sync_cache_filename = $args->cache_directory . '/' . md5($args->user . $calendar->url); // Do we just need to sync everything across and overwrite all the local stuff? $sync_all = !file_exists($sync_cache_filename) || $args->sync_all; $sync_in = false; $sync_out = false; if ($args->sync_in || !$args->sync_out) { $sync_in = true; }