Working freebusy refactored to use a single core routine.

This commit is contained in:
Andrew McMillan committed 2010-08-30 18:55:23 +12:00
1 parent 3503f2f0fa
commit 50fccc73d8
4 files changed
+85 -135

No files matched your search

+37 -11
View File
@@ -11,6 +11,7 @@ else {
$session = new HTTPAuthSession();
}
/**
* Submission parameters recommended by calconnect, plus some generous alternatives
*/
@@ -27,26 +28,52 @@ if ( !isset($fb_start) || $fb_start == '' ) $fb_start = date('Y-m-d\TH:i:s', t
if ( (!isset($fb_period) && !isset($fb_end)) || ($fb_period == '' && $fb_end == '') )
$fb_period = 'P44D'; // 44 days - 2 days more than recommended default
/**
* If fb_user (user, userid, user_no or email parameter) then we adjust
* the path of the request to suit.
*/
if ( isset($fb_user) ) $_SERVER['PATH_INFO'] = '/'.$fb_user.'/';
/**
* We also allow URLs like .../freebusy.php/user@example.com to work, so long as
* the e-mail matches a single user whose calendar we have rights to.
* @NOTE: It is OK for there to *be* duplicate e-mail addresses, just so long as we
* only have read permission (or more) for only one of them.
*/
require_once("CalDAVRequest.php");
$request = new CalDAVRequest(array("allow_by_email" => 1));
$path_match = '^'.$request->path;
if ( preg_match( '{^/(\S+@[a-z0-9][a-z0-9-]*[.][a-z0-9.-]+)/?$}i', $request->path, $matches ) ) {
$u = getUserByEMail($matches[1]);
$path_match = '^/'.$u->username.'/';
}
if ( isset($fb_format) && $fb_format != 'text/calendar' ) {
$request->DoResponse( 406, 'This server only supports the text/calendar format for freebusy URLs' );
}
/**
* We also allow URLs like .../freebusy.php/user@example.com to work, so long as
* the e-mail matches a single user whose calendar we have rights to.
* NOTE: It is OK for there to *be* duplicate e-mail addresses, just so long as we
* only have read permission (or more) for only one of them.
*/
$request = new CalDAVRequest(array("allow_by_email" => 1));
if ( ! $request->HavePrivilegeTo('read-free-busy') ) $request->DoResponse( 404 );
require_once("freebusy-functions.php");
switch ( $_SERVER['REQUEST_METHOD'] ) {
case 'GET':
include_once("freebusy-GET.php");
$range_start = new RepeatRuleDateTime($fb_start);
if ( !isset($fb_end) ) {
$range_end = clone($range_start);
$range_end->modify($fb_period);
}
else {
$range_end = new RepeatRuleDateTime($fb_end);
}
$freebusy = get_freebusy( $path_match, $range_start, $range_end );
$result = new iCalComponent();
$result->VCalendar();
$result->AddComponent($freebusy);
$request->DoResponse( 200, $result->Render(), 'text/calendar' );
break;
default:
@@ -56,4 +83,3 @@ switch ( $_SERVER['REQUEST_METHOD'] ) {
dbg_error_log( "freebusy", "RAW: %s", str_replace("\n", "",str_replace("\r", "", $raw_post)) );
}