Skip to content

Instantly share code, notes, and snippets.

@rngtng
Created September 29, 2010 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rngtng/602786 to your computer and use it in GitHub Desktop.
Save rngtng/602786 to your computer and use it in GitHub Desktop.
daviCal import file
<?php
require_once("./always.php");
require_once("DAViCalSession.php");
$feeds = array(
'events' => array(
'Bausteln' => 'http://www.google.com/calendar/ical/49lc466l5phf9hvnk3f2rc7lt0%40group.calendar.google.com/public/basic.ics',
'Last.fm' => 'http://ws.audioscrobbler.com/1.0/user/TobiTobes/events.ics',
'IntSwing' => 'http://www.google.com/calendar/ical/0r5fifa7ir3k4hmh2iae8rgtuc%40group.calendar.google.com/public/basic.ics',
//'Last.fm-B' => 'http://ws.audioscrobbler.com/1.0/user/TobiTobes/eventsysrecs.ics',
//'HHSwing' => 'http://www.google.com/calendar/ical/bhk5pvo2kghl5m9gq59v2fhvrc%40group.calendar.google.com/public/basic.ics',
//'Qype' => 'http://www.qype.com/mypage/events_calendar.ics?token=8719a3c157abd7419088d670bf56b3cad3215a23',
//'Concerts' => 'http://www.icalx.com/public/konzerte/Musik.ics'
),
'work' => array(
//'Feiertage' => 'http://pipes.yahoo.com/pipes/pipe.run?_id=BFc8YhAb3hGQ0HtM0z6skA&_render=ical',
//'Qype' => 'http://www.google.com/calendar/ical/calendar%40qype.com/private-364bdf5569ad6e97cf6be7cb9d8d76da/basic.ics'
)
);
$user = getUserByName('tobi'); //new DAViCalUser(1001);
foreach( $feeds AS $res_no => $urls ) {
$resource = getUserByName($res_no);
foreach( $urls AS $path_ics => $url ) {
$ics = trim(file_get_contents($url));
include_once('check_UTF8.php');
if ( check_string($ics) ) {
if ( substr($path_ics,-1,1) != '/' ) $path_ics .= '/'; // ensure that we target a collection
if ( substr($path_ics,0,1) != '/' ) $path_ics = '/'.$path_ics; // ensure that we target a collection
$path = "/".$resource->username.$path_ics;
$c->readonly_webdav_collections = false; // Override this setting so we can create collections/events on import.
$c->skip_bad_event_on_import = true;
require_once("caldav-PUT-functions.php");
if(controlRequestContainer($resource->username, $resource->user_no, $path,false) === -1 ) {
echo "Not found: $path for: ".$resource->username." ".$resource->user_no."<br>";
}
else {
import_collection($ics,$resource->user_no,$path,false,true);
$cnt = 0;
echo "All ".$cnt." events for ".$path." of user ".$user->username." were deleted and replaced by those from the file.<br>";
}
}
else {
echo "The file ".$path." is not UTF-8 encoded, please check the error for more details.<br>";
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment