- refactored code to use a single add_collection method in groupdav class

--> app groupdav classes now get calling groupdav object as parameter
Had a quick test with iOS & OS X addressbook, calendar and with Lightning
This commit is contained in:
Ralf Becker 2011-09-18 10:56:56 +00:00
parent b49aae4675
commit 03ed1d3ddb
6 changed files with 153 additions and 199 deletions

View File

@ -87,13 +87,11 @@ class addressbook_groupdav extends groupdav_handler
* Constructor * Constructor
* *
* @param string $app 'calendar', 'addressbook' or 'infolog' * @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set * @param groupdav $groupdav calling class
* @param string $base_uri=null base url of handler
* @param string $principalURL=null pricipal url of handler
*/ */
function __construct($app,$debug=null,$base_uri=null,$principalURL=null) function __construct($app, groupdav $groupdav)
{ {
parent::__construct($app,$debug,$base_uri,$principalURL); parent::__construct($app, $groupdav);
$this->bo = new addressbook_bo(); $this->bo = new addressbook_bo();

View File

@ -67,13 +67,11 @@ class calendar_groupdav extends groupdav_handler
* Constructor * Constructor
* *
* @param string $app 'calendar', 'addressbook' or 'infolog' * @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set * @param groupdav $groupdav calling class
* @param string $base_uri=null base url of handler
* @param string $principalURL=null principal url of handler
*/ */
function __construct($app,$debug=null, $base_uri=null, $principalURL=null) function __construct($app, groupdav $groupdav)
{ {
parent::__construct($app,$debug,$base_uri,$principalURL); parent::__construct($app, $groupdav);
$this->bo = new calendar_boupdate(); $this->bo = new calendar_boupdate();
$this->vCalendar = new Horde_iCalendar; $this->vCalendar = new Horde_iCalendar;
@ -574,7 +572,7 @@ class calendar_groupdav extends groupdav_handler
} }
if (!($cal_id = $handler->importVCal($vCalendar, $eventId, if (!($cal_id = $handler->importVCal($vCalendar, $eventId,
self::etag2value($this->http_if_match), false, 0, $this->principalURL, $user, $charset, $id))) self::etag2value($this->http_if_match), false, 0, $this->groupdav->current_user_principal, $user, $charset, $id)))
{ {
if ($this->debug) error_log(__METHOD__."(,$id) eventId=$eventId: importVCal('$options[content]') returned false"); if ($this->debug) error_log(__METHOD__."(,$id) eventId=$eventId: importVCal('$options[content]') returned false");
if ($eventId && $cal_id === false) if ($eventId && $cal_id === false)
@ -643,7 +641,7 @@ class calendar_groupdav extends groupdav_handler
list($eventId) = explode(':', $eventId); list($eventId) = explode(':', $eventId);
if (!($cal_id = $handler->importVCal($vCalendar, $eventId, null, if (!($cal_id = $handler->importVCal($vCalendar, $eventId, null,
false, 0, $this->principalURL, $user, $charset))) false, 0, $this->groupdav->current_user_principal, $user, $charset)))
{ {
if ($this->debug) error_log(__METHOD__."() importVCal($eventId) returned false"); if ($this->debug) error_log(__METHOD__."() importVCal($eventId) returned false");
} }

View File

@ -55,13 +55,11 @@ class infolog_groupdav extends groupdav_handler
* Constructor * Constructor
* *
* @param string $app 'calendar', 'addressbook' or 'infolog' * @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set * @param groupdav $groupdav calling class
* @param string $base_uri=null base url of handler
* @param string $principalURL=null pricipal url of handler
*/ */
function __construct($app,$debug=null,$base_uri=null,$principalURL=null) function __construct($app, groupdav $groupdav)
{ {
parent::__construct($app,$debug,$base_uri,$principalURL); parent::__construct($app, $groupdav);
$this->bo = new infolog_bo(); $this->bo = new infolog_bo();
$this->vCalendar = new Horde_iCalendar; $this->vCalendar = new Horde_iCalendar;

View File

@ -87,7 +87,7 @@ class groupdav extends HTTP_WebDAV_Server
'component-set' => array(self::GROUPDAV => 'VTODO'), 'component-set' => array(self::GROUPDAV => 'VTODO'),
), ),
'principals' => array( 'principals' => array(
'resourcetype' => array(self::DAV => 'principal'), 'resourcetype' => array(self::DAV => 'collection'),
) )
); );
/** /**
@ -114,11 +114,11 @@ class groupdav extends HTTP_WebDAV_Server
*/ */
var $handler; var $handler;
/** /**
* principal URL * current-user-principal URL
* *
* @var string * @var string
*/ */
var $principalURL; var $current_user_principal;
/** /**
* Reference to the accounts class * Reference to the accounts class
* *
@ -133,7 +133,9 @@ class groupdav extends HTTP_WebDAV_Server
if ($this->debug > 2) error_log('groupdav: $_SERVER='.array2string($_SERVER)); if ($this->debug > 2) error_log('groupdav: $_SERVER='.array2string($_SERVER));
// identify clients, which do NOT support path AND full url in <D:href> of PROPFIND request // identify clients, which do NOT support path AND full url in <D:href> of PROPFIND request
switch(groupdav_handler::get_agent()) // crrnd: client refuses redundand namespace declarations
// cnrnd: client needs redundand namespace declarations
switch(($agent = groupdav_handler::get_agent()))
{ {
case 'kde': // KAddressbook (at least in 3.5 can NOT subscribe / does NOT find addressbook) case 'kde': // KAddressbook (at least in 3.5 can NOT subscribe / does NOT find addressbook)
$this->client_require_href_as_url = true; $this->client_require_href_as_url = true;
@ -156,6 +158,8 @@ class groupdav extends HTTP_WebDAV_Server
$this->cnrnd = true; // neon clients like cadaver $this->cnrnd = true; // neon clients like cadaver
break; break;
} }
if ($this->debug) error_log(__METHOD__."() HTTP_USER_AGENT='$_SERVER[HTTP_USER_AGENT]' --> '$agent' --> client_requires_href_as_url=$this->client_require_href_as_url, crrnd(client refuses redundand namespace declarations)=$this->crrnd, cnrnd(client needs redundand namespace declarations)=$this->cnrnd");
// adding EGroupware version to X-Dav-Powered-By header eg. "EGroupware 1.8.001 CalDAV/CardDAV/GroupDAV server" // adding EGroupware version to X-Dav-Powered-By header eg. "EGroupware 1.8.001 CalDAV/CardDAV/GroupDAV server"
$this->dav_powered_by = str_replace('EGroupware','EGroupware '.$GLOBALS['egw_info']['server']['versions']['phpgwapi'], $this->dav_powered_by = str_replace('EGroupware','EGroupware '.$GLOBALS['egw_info']['server']['versions']['phpgwapi'],
$this->dav_powered_by); $this->dav_powered_by);
@ -165,19 +169,19 @@ class groupdav extends HTTP_WebDAV_Server
$this->egw_charset = translation::charset(); $this->egw_charset = translation::charset();
if (strpos($this->base_uri, 'http') === 0) if (strpos($this->base_uri, 'http') === 0)
{ {
$this->principalURL = $this->_slashify($this->base_uri); $this->current_user_principal = $this->_slashify($this->base_uri);
} }
else else
{ {
$this->principalURL = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:") . $this->current_user_principal = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:") .
'//' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '/'; '//' . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '/';
} }
$this->principalURL .= 'principals/users/'.$GLOBALS['egw_info']['user']['account_lid'].'/'; $this->current_user_principal .= 'principals/users/'.$GLOBALS['egw_info']['user']['account_lid'].'/';
// if client requires pathes instead of URLs // if client requires pathes instead of URLs
if ($this->client_require_href_as_url === false) if (!$this->client_require_href_as_url)
{ {
$this->principalURL = parse_url($this->principalURL,PHP_URL_PATH); $this->current_user_principal = parse_url($this->current_user_principal,PHP_URL_PATH);
} }
$this->accounts = $GLOBALS['egw']->accounts; $this->accounts = $GLOBALS['egw']->accounts;
} }
@ -190,7 +194,7 @@ class groupdav extends HTTP_WebDAV_Server
*/ */
function app_handler($app) function app_handler($app)
{ {
return groupdav_handler::app_handler($app,$this->debug,$this->base_uri,$this->principalURL); return groupdav_handler::app_handler($app,$this);
} }
/** /**
@ -229,6 +233,53 @@ class groupdav extends HTTP_WebDAV_Server
// not yet implemented: $dav[] = 'access-control'; // not yet implemented: $dav[] = 'access-control';
} }
/**
* Add a collection to a PROPFIND request
*
* @param string $path
* @param array $props=array() extra properties 'resourcetype' is added anyway, name => value pairs or name => HTTP_WebDAV_Server([namespace,]name,value)
* @return array with values for keys 'path' and 'props'
*/
public function add_collection($path, array $props = array())
{
// resourcetype: collection
$props['resourcetype'][] = self::mkprop('collection','');
// props for all collections: current-user-principal and principal-collection-set
$props['current-user-principal'] = array(
self::mkprop('href',$this->current_user_principal));
$props['principal-collection-set'] = array(
self::mkprop('href',$this->base_uri.'/principals/'));
// required props per WebDAV standard
foreach(array(
'displayname' => basename($path),
'getetag' => 'EGw-no-etag-wGE',
'getcontentlength' => '',
'getlastmodified' => '',
'getcontenttype' => 'httpd/unix-directory',
) as $name => $default)
{
if (!isset($props[$name])) $props[$name] = $default;
}
if ($this->debug > 1) error_log(__METHOD__."(path='$path', props=".array2string($props).')');
// convert simple associative properties to HTTP_WebDAV_Server ones
foreach($props as $name => &$prop)
{
if (!is_array($prop) || !isset($prop['name']))
{
$prop = self::mkprop($name, $prop);
}
}
return array(
'path' => $path,
'props' => $props,
);
}
/** /**
* PROPFIND and REPORT method handler * PROPFIND and REPORT method handler
* *
@ -289,49 +340,30 @@ class groupdav extends HTTP_WebDAV_Server
$displayname = translation::convert($displayname, translation::charset(),'utf-8'); $displayname = translation::convert($displayname, translation::charset(),'utf-8');
// self url // self url
$props = array( $files['files'][] = $this->add_collection($path, array(
self::mkprop('displayname',$displayname), 'displayname' => $displayname,
self::mkprop('owner',array(self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/'))), 'owner' => array(self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/')),
self::mkprop('resourcetype',array(self::mkprop('collection',''))), // adding the calendar extra property (calendar-home-set, etc.) here, allows apple iCal to "autodetect" the URL
// adding the calendar extra property (calendar-home-set, etc.) here, allows apple iCal to "autodetect" the URL 'calendar-home-set' => self::mkprop(groupdav::CALDAV,'calendar-home-set',array(
self::mkprop(groupdav::CALDAV,'calendar-home-set',array( self::mkprop('href',$this->base_uri.$user_prefix))),
self::mkprop('href',$this->base_uri.$user_prefix))), 'addressbook-home-set' => self::mkprop(groupdav::CARDDAV,'addressbook-home-set',array(
self::mkprop(groupdav::CARDDAV,'addressbook-home-set',array( self::mkprop('href',$this->base_uri.$user_prefix))),
self::mkprop('href',$this->base_uri.$user_prefix))), 'calendar-user-address-set' => self::mkprop(groupdav::CALDAV,'calendar-user-address-set',$calendar_user_address_set),
self::mkprop('current-user-principal',array(self::mkprop('href',$this->principalURL))), 'email-address-set' => self::mkprop(groupdav::CALENDARSERVER,'email-address-set',array(
self::mkprop(groupdav::CALDAV,'calendar-user-address-set',$calendar_user_address_set), self::mkprop(groupdav::CALENDARSERVER,'email-address',$GLOBALS['egw_info']['user']['email']))),
self::mkprop(groupdav::CALENDARSERVER,'email-address-set',array( // OUTBOX URLs of the current user
self::mkprop(groupdav::CALENDARSERVER,'email-address',$GLOBALS['egw_info']['user']['email']))), 'schedule-outbox-URL' => self::mkprop(groupdav::CALDAV,'schedule-outbox-URL',array(
//self::mkprop('principal-URL',array(self::mkprop('href',$this->principalURL))), self::mkprop(groupdav::DAV,'href',$this->base_uri.'/calendar/'))),
self::mkprop('principal-collection-set',array(self::mkprop('href',$this->base_uri.'/principals/'))), //'current-user-privilege-set' => self::current_user_privilege_set(),
// OUTBOX URLs of the current user ));
self::mkprop(groupdav::CALDAV,'schedule-outbox-URL',array(
self::mkprop(groupdav::DAV,'href',$this->base_uri.'/calendar/'))),
);
//$props = self::current_user_privilege_set($props);
$files['files'][] = array(
'path' => $path,
'props' => $props,
);
if ($options['depth']) if ($options['depth'])
{ {
if (strlen($path) == 1) // GroupDAV Root if (strlen($path) == 1) // GroupDAV Root
{ {
// principals collection // principals collection
$files['files'][] = array( $files['files'][] = $this->add_collection('/principals/', array(
'path' => '/principals/', 'displayname' => lang('Accounts'),
'props' => array( ));
self::mkprop('displayname',lang('Accounts')),
self::mkprop('resourcetype',array(self::mkprop('principals',''),self::mkprop('collection',''))),
self::mkprop('current-user-principal',array(self::mkprop('href',$this->principalURL))),
self::mkprop('principal-collection-set',self::mkprop('href', $this->base_uri.'/principals/')),
//self::mkprop(groupdav::CALDAV,'calendar-home-set',array(
// self::mkprop('href',$this->base_uri.$user_prefix))),
//self::mkprop(groupdav::CARDDAV,'addressbook-home-set',array(
// self::mkprop('href',$this->base_uri.$user_prefix))),
//self::mkprop('principal-URL',array(self::mkprop('href',$this->principalURL))),
),
);
} }
foreach($this->root as $app => $data) foreach($this->root as $app => $data)
{ {
@ -340,19 +372,16 @@ class groupdav extends HTTP_WebDAV_Server
// add ctag if handler implements it // add ctag if handler implements it
if (($handler = self::app_handler($app)) && method_exists($handler,'getctag')) if (($handler = self::app_handler($app)) && method_exists($handler,'getctag'))
{ {
$props[] = self::mkprop( $props['getctag'] = self::mkprop(
groupdav::CALENDARSERVER,'getctag',$handler->getctag($options['path'],$user)); groupdav::CALENDARSERVER,'getctag',$handler->getctag($options['path'],$user));
} }
$props[] = self::mkprop('getetag','EGw-'.$app.'-wGE'); $props['getetag'] = 'EGw-'.$app.'-wGE';
$files['files'][] = array( $files['files'][] = $this->add_collection($path.$app.'/',$props);
'path' => $path.$app.'/',
'props' => $props,
);
} }
} }
return true; return true;
} }
if ($app != 'principals' && !$GLOBALS['egw_info']['user']['apps'][$app]) if ($app != 'principals' && !isset($GLOBALS['egw_info']['user']['apps'][$app]))
{ {
if ($this->debug) error_log(__CLASS__."::$method(path=$options[path]) 403 Forbidden: no app rights for '$app'"); if ($this->debug) error_log(__CLASS__."::$method(path=$options[path]) 403 Forbidden: no app rights for '$app'");
return "403 Forbidden: no app rights for '$app'"; // no rights for the given app return "403 Forbidden: no app rights for '$app'"; // no rights for the given app
@ -361,15 +390,14 @@ class groupdav extends HTTP_WebDAV_Server
{ {
if ($method != 'REPORT' && !$id) // no self URL for REPORT requests (only PROPFIND) or propfinds on an id if ($method != 'REPORT' && !$id) // no self URL for REPORT requests (only PROPFIND) or propfinds on an id
{ {
$files['files'][0] = array( $files['files'][0] = $this->add_collection($path.$app.'/',
'path' => $path.$app.'/',
// KAddressbook doubles the folder, if the self URL contains the GroupDAV/CalDAV resourcetypes // KAddressbook doubles the folder, if the self URL contains the GroupDAV/CalDAV resourcetypes
'props' => $this->_properties($app,$app=='addressbook'&&$handler->get_agent()=='kde',$user,$path), $this->_properties($app,$app=='addressbook'&&$handler->get_agent()=='kde',$user,$path));
);
// add ctag if handler implements it (only for depth 0) // add ctag if handler implements it (only for depth 0)
if (method_exists($handler,'getctag')) if (method_exists($handler,'getctag'))
{ {
$files['files'][0]['props'][] = HTTP_WebDAV_Server::mkprop( $files['files'][0]['props']['getctag'] = self::mkprop(
groupdav::CALENDARSERVER,'getctag',$handler->getctag($options['path'],$user)); groupdav::CALENDARSERVER,'getctag',$handler->getctag($options['path'],$user));
} }
if (!$options['depth']) return true; // depth 0 --> show only the self url if (!$options['depth']) return true; // depth 0 --> show only the self url
@ -380,7 +408,7 @@ class groupdav extends HTTP_WebDAV_Server
} }
/** /**
* Get the properties of a collection * Get properties of an application collection
* *
* @param string $app * @param string $app
* @param boolean $no_extra_types=false should the GroupDAV and CalDAV types be added (KAddressbook has problems with it in self URL) * @param boolean $no_extra_types=false should the GroupDAV and CalDAV types be added (KAddressbook has problems with it in self URL)
@ -431,71 +459,58 @@ class groupdav extends HTTP_WebDAV_Server
} }
$props = array( $props = array(
self::mkprop('current-user-principal',array(self::mkprop('href',$this->principalURL))), 'owner' => array(self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/')),
self::mkprop('owner',array(self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$account_lid.'/'))), 'calendar-user-address-set' => self::mkprop(groupdav::CALDAV,'calendar-user-address-set',array(
//self::mkprop('principal-URL',array(self::mkprop('href',$this->principalURL))),
self::mkprop('alternate-URI-set',array(
self::mkprop('href','MAILTO:'.$GLOBALS['egw_info']['user']['email']))),
self::mkprop('principal-collection-set',array(
self::mkprop('href',$this->base_uri.'/principals/'),
)),
self::mkprop('principal-URL',array(self::mkprop('href',$this->principalURL))),
self::mkprop(groupdav::CALDAV,'calendar-user-address-set',array(
self::mkprop('href','MAILTO:'.$GLOBALS['egw_info']['user']['email']), self::mkprop('href','MAILTO:'.$GLOBALS['egw_info']['user']['email']),
self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$GLOBALS['egw_info']['user']['account_lid'].'/'), self::mkprop('href',$this->base_uri.'/principals/'.$principalType.'/'.$GLOBALS['egw_info']['user']['account_lid'].'/'),
self::mkprop('href','urn:uuid:'.$GLOBALS['egw_info']['user']['account_lid']))), self::mkprop('href','urn:uuid:'.$GLOBALS['egw_info']['user']['account_lid']))),
self::mkprop(groupdav::CALENDARSERVER,'email-address-set',array( 'email-address-set' => self::mkprop(groupdav::CALENDARSERVER,'email-address-set',array(
self::mkprop(groupdav::CALENDARSERVER,'email-address',$GLOBALS['egw_info']['user']['email']))), self::mkprop(groupdav::CALENDARSERVER,'email-address',$GLOBALS['egw_info']['user']['email']))),
self::mkprop('getetag','EGw-no-etag-wGE'), // iPhone addressbook requires an etag here!
); );
$displayname = translation::convert(lang($app).' '.
common::grab_owner_name($user),$this->egw_charset,'utf-8');
switch ($app) switch ($app)
{ {
case 'calendar': case 'calendar':
$props[] = self::mkprop(groupdav::CALDAV,'calendar-home-set',array( $props['calendar-home-set'] = self::mkprop(groupdav::CALDAV,'calendar-home-set',array(
self::mkprop('href',$this->base_uri.$path.'calendar/'))); self::mkprop('href',$this->base_uri.$path.'calendar/')));
// OUTBOX URLs of the current user // OUTBOX URLs of the current user
$props[] = self::mkprop(groupdav::CALDAV,'schedule-outbox-URL', $props['schedule-outbox-URL'] = self::mkprop(groupdav::CALDAV,'schedule-outbox-URL',
array(self::mkprop(groupdav::DAV,'href',$this->base_uri.'/calendar/'))); array(self::mkprop(groupdav::DAV,'href',$this->base_uri.'/calendar/')));
$props[] = self::mkprop(groupdav::ICAL,'calendar-color',$display_color); $props['calendar-color'] = self::mkprop(groupdav::ICAL,'calendar-color',$display_color);
break; break;
case 'infolog': case 'infolog':
$props[] = self::mkprop(groupdav::CALDAV,'calendar-home-set',array( $props['calendar-home-set'] = self::mkprop(groupdav::CALDAV,'calendar-home-set',array(
self::mkprop('href',$this->base_uri.$path.'infolog/'))); self::mkprop('href',$this->base_uri.$path.'infolog/')));
$displayname = translation::convert(lang($app).' '.
common::grab_owner_name($user),$this->egw_charset,'utf-8');
break; break;
default: default:
$props[] = self::mkprop(groupdav::CALDAV,'calendar-home-set',array( $props['calendar-home-set'] = self::mkprop(groupdav::CALDAV,'calendar-home-set',array(
self::mkprop('href',$this->base_uri.$path))); self::mkprop('href',$this->base_uri.$path)));
$displayname = translation::convert(lang($app).' '. $displayname = translation::convert(lang($app).' '.
common::grab_owner_name($user),$this->egw_charset,'utf-8'); common::grab_owner_name($user),$this->egw_charset,'utf-8');
} }
$props[] = self::mkprop(groupdav::CARDDAV,'addressbook-home-set',array( $props['addressbook-home-set'] = self::mkprop(groupdav::CARDDAV,'addressbook-home-set',array(
self::mkprop('href',$this->base_uri.$path))); self::mkprop('href',$this->base_uri.$path)));
$props[] = self::mkprop('displayname',$displayname); $props['displayname'] = $displayname;
foreach((array)$this->root[$app] as $prop => $values) foreach((array)$this->root[$app] as $prop => $values)
{ {
if ($prop == 'resourcetype') if ($prop == 'resourcetype')
{ {
$resourcetype = array(
self::mkprop('collection',''),
);
if (!$no_extra_types) if (!$no_extra_types)
{ {
foreach($this->root[$app]['resourcetype'] as $ns => $type) foreach($this->root[$app]['resourcetype'] as $ns => $type)
{ {
$resourcetype[] = self::mkprop($ns,$type,''); $props['resourcetype'][] = self::mkprop($ns,$type,'');
} }
} }
$props[] = self::mkprop('resourcetype',$resourcetype);
} }
else else
{ {
foreach($values as $ns => $value) foreach($values as $ns => $value)
{ {
$props[] = self::mkprop($ns,$prop,$value); $props[$prop] = self::mkprop($ns,$prop,$value);
} }
} }
} }
@ -990,29 +1005,26 @@ class groupdav extends HTTP_WebDAV_Server
/** /**
* Add the privileges of the current user * Add the privileges of the current user
* *
* @param array $props=array() regular props by the groupdav handler * @return array self::mkprop('privilege',array(...))
* @return array
*/ */
static function current_user_privilege_set(array $props=array()) static function current_user_privilege_set()
{ {
$props[] = HTTP_WebDAV_Server::mkprop('current-user-privilege-set', return array(self::mkprop('privilege',
array(HTTP_WebDAV_Server::mkprop('privilege', array(//self::mkprop('all',''),
array(//HTTP_WebDAV_Server::mkprop('all',''), self::mkprop('read',''),
HTTP_WebDAV_Server::mkprop('read',''), self::mkprop('read-free-busy',''),
HTTP_WebDAV_Server::mkprop('read-free-busy',''), //self::mkprop('read-current-user-privilege-set',''),
//HTTP_WebDAV_Server::mkprop('read-current-user-privilege-set',''), self::mkprop('bind',''),
HTTP_WebDAV_Server::mkprop('bind',''), self::mkprop('unbind',''),
HTTP_WebDAV_Server::mkprop('unbind',''), self::mkprop('schedule-post',''),
HTTP_WebDAV_Server::mkprop('schedule-post',''), self::mkprop('schedule-post-vevent',''),
HTTP_WebDAV_Server::mkprop('schedule-post-vevent',''), self::mkprop('schedule-respond',''),
HTTP_WebDAV_Server::mkprop('schedule-respond',''), self::mkprop('schedule-respond-vevent',''),
HTTP_WebDAV_Server::mkprop('schedule-respond-vevent',''), self::mkprop('schedule-deliver',''),
HTTP_WebDAV_Server::mkprop('schedule-deliver',''), self::mkprop('schedule-deliver-vevent',''),
HTTP_WebDAV_Server::mkprop('schedule-deliver-vevent',''), self::mkprop('write',''),
HTTP_WebDAV_Server::mkprop('write',''), self::mkprop('write-properties',''),
HTTP_WebDAV_Server::mkprop('write-properties',''), self::mkprop('write-content',''),
HTTP_WebDAV_Server::mkprop('write-content',''), )));
))));
return $props;
} }
} }

View File

@ -53,18 +53,18 @@ abstract class groupdav_handler
* @var string * @var string
*/ */
var $app; var $app;
/**
* Calling groupdav object
*
* @var groupdav
*/
var $groupdav;
/** /**
* Base url of handler, need to prefix all pathes not automatic handled by HTTP_WebDAV_Server * Base url of handler, need to prefix all pathes not automatic handled by HTTP_WebDAV_Server
* *
* @var string * @var string
*/ */
var $base_uri; var $base_uri;
/**
* principal URL
*
* @var string
*/
var $principalURL;
/** /**
* HTTP_IF_MATCH / etag of current request / last call to _common_get_put_delete() method * HTTP_IF_MATCH / etag of current request / last call to _common_get_put_delete() method
* *
@ -89,25 +89,14 @@ abstract class groupdav_handler
* Constructor * Constructor
* *
* @param string $app 'calendar', 'addressbook' or 'infolog' * @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set * @param groupdav $groupdav calling class
* @param string $base_uri=null base url of handler
* @param string $principalURL=null pricipal url of handler
*/ */
function __construct($app,$debug=null,$base_uri=null,$principalURL=null) function __construct($app, groupdav $groupdav)
{ {
$this->app = $app; $this->app = $app;
if (!is_null($debug)) $this->debug = $debug; if (!is_null($parent->debug)) $this->debug = $groupdav->debug;
$this->base_uri = is_null($base_uri) ? $base_uri : $_SERVER['SCRIPT_NAME']; $this->base_uri = $groupdav->base_uri;
if (is_null($principalURL)) $this->groupdav = $groupdav;
{
$this->principalURL = (@$_SERVER["HTTPS"] === "on" ? "https:" : "http:") .
'//'.$_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . '/';
}
else
{
$this->principalURL = $principalURL.'principals/users/'.
$GLOBALS['egw_info']['user']['account_lid'].'/';
}
$this->agent = self::get_agent(); $this->agent = self::get_agent();
@ -302,13 +291,10 @@ abstract class groupdav_handler
* *
* @static * @static
* @param string $app 'calendar', 'addressbook' or 'infolog' * @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $user=null owner of the collection, default current user * @param groupdav $groupdav calling class
* @param int $debug=null debug-level to set
* @param string $base_uri=null base url of handler
* @param string $principalURL=null pricipal url of handler
* @return groupdav_handler * @return groupdav_handler
*/ */
static function &app_handler($app,$debug=null,$base_uri=null,$principalURL=null) static function app_handler($app, $groupdav)
{ {
static $handler_cache = array(); static $handler_cache = array();
@ -317,13 +303,10 @@ abstract class groupdav_handler
$class = $app.'_groupdav'; $class = $app.'_groupdav';
if (!class_exists($class) && !class_exists($class = 'groupdav_'.$app)) return null; if (!class_exists($class) && !class_exists($class = 'groupdav_'.$app)) return null;
$handler_cache[$app] = new $class($app,$debug,$base_uri,$principalURL); $handler_cache[$app] = new $class($app, $groupdav);
} }
$handler_cache[$app]->$debug = $debug;
$handler_cache[$app]->$base_uri = $base_uri;
$handler_cache[$app]->$principalURL = $principalURL;
if ($debug) error_log(__METHOD__."('$app', '$base_uri', '$principalURL')"); if ($debug) error_log(__METHOD__."('$app')");
return $handler_cache[$app]; return $handler_cache[$app];
} }

View File

@ -41,13 +41,11 @@ class groupdav_principals extends groupdav_handler
* Constructor * Constructor
* *
* @param string $app 'calendar', 'addressbook' or 'infolog' * @param string $app 'calendar', 'addressbook' or 'infolog'
* @param int $debug=null debug-level to set * @param groupdav $groupdav calling class
* @param string $base_uri=null base url of handler
* @param string $principalURL=null principal url of handler
*/ */
function __construct($app,$debug=null,$base_uri=null,$principalURL=null) function __construct($app, groupdav $groupdav)
{ {
parent::__construct($app,$debug,$base_uri,$principalURL); parent::__construct($app, $groupdav);
$this->accounts = $GLOBALS['egw']->accounts; $this->accounts = $GLOBALS['egw']->accounts;
$this->acl = $GLOBALS['egw']->acl; $this->acl = $GLOBALS['egw']->acl;
@ -415,44 +413,11 @@ class groupdav_principals extends groupdav_handler
* *
* @param string $path * @param string $path
* @param array $props=array() extra properties 'resourcetype' is added anyway, name => value pairs or name => HTTP_WebDAV_Server([namespace,]name,value) * @param array $props=array() extra properties 'resourcetype' is added anyway, name => value pairs or name => HTTP_WebDAV_Server([namespace,]name,value)
* @param array $additional_resource_types=array() additional resource-types, collection and principal are always added
* @return array with values for keys 'path' and 'props' * @return array with values for keys 'path' and 'props'
*/ */
protected function add_collection($path, array $props = array()) protected function add_collection($path, array $props = array())
{ {
// resourcetype: collection + $additional_resource_types return $this->groupdav->add_collection($path, $props);
$props['resourcetype'][] = HTTP_WebDAV_Server::mkprop('collection','');
// props for all collections: current-user-principal and principal-collection-set
$props['current-user-principal'] = array(
HTTP_WebDAV_Server::mkprop('href',$this->base_uri.'/principals/users/'.$GLOBALS['egw_info']['user']['account_lid'].'/'));
$props['principal-collection-set'] = array(
HTTP_WebDAV_Server::mkprop('href',$this->base_uri.'/principals/'));
$props['supported-report-set'] = $this->supported_report_set($path);
// required props per WebDAV standard
if (!isset($props['displayname'])) $props['displayname'] = basename($path);
if (!isset($props['getetag'])) $props['getetag'] = 'EGw-no-etag-wGE';
foreach(array('getcontentlength','getlastmodified','getlastmodified','getlastmodified') as $name)
{
if (!isset($props[$name])) $props[$name] = '';
}
if ($this->debug > 1) error_log(__METHOD__."(path='$path', props=".array2string($props).')');
// convert simple associative properties to HTTP_WebDAV_Server ones
foreach($props as $name => &$prop)
{
if (!is_array($prop) || !isset($prop['name']))
{
$prop = HTTP_WebDAV_Server::mkprop($name, $prop);
}
}
return array(
'path' => $path,
'props' => $props,
);
} }
/** /**