A more efficient query for GET including sub-collections.
[davical.git] / scripts / export_calendar.php
blobfd2abed345600554ac3b0cb1fd7ad0c3848ffa3d
1 #!/usr/bin/env php
2 <?php
3 /**
4 * Script to export a calendar in iCalendar format from the command line.
5 */
7 if ( $argc < 3 ) {
9 $basename = $argv[0];
10 echo <<<USAGE
11 Usage:
13 $basename davical.example.com /username/calendar/ calendarfile.ics
15 Where:
16 'davical.example.com' is the hostname of your DAViCal server.
17 '/username/calendar/' is the (sub-)path of the calendar to be updated.
19 This script can be used to export whole calendars in iCalendar format to
20 stdout.
22 USAGE;
23 exit(1);
26 $_SERVER['SERVER_NAME'] = $argv[1];
27 $source = $argv[2];
29 // Change into the web application root directory so includes work.
30 $script_file = __FILE__;
31 chdir(preg_replace('{/scripts/[^/]+.php$}','/htdocs',$script_file));
32 require_once("./always.php");
34 class FakeSession {
36 var $user_no;
37 var $principal_id;
38 var $username;
39 var $email;
40 var $dav_name;
41 var $principal;
42 var $logged_in;
44 function __construct($user_no = null) {
45 if ( empty($user_no) ) {
46 $this->user_no = -1;
47 $this->principal_id = -1;
48 $this->logged_in = false;
49 return;
52 $this->user_no = $user_no;
53 $principal = new Principal('user_no',$user_no);
54 // Assign each field in the selected record to the object
55 foreach( $principal AS $k => $v ) {
56 $this->{$k} = $v;
58 $this->username = $principal->username();
59 $this->principal_id = $principal->principal_id();
60 $this->email = $principal->email();
61 $this->dav_name = $principal->dav_name();
62 $this->principal = $principal;
64 $this->logged_in = true;
68 function AllowedTo($do_something) {
69 return $this->logged_in;
72 $session = new FakeSession();
74 require("caldav-GET-functions.php");
75 $calendar = new DAVResource($source);
77 echo export_iCalendar($calendar);