forked from extern/egroupware
new method groupdav_principals::url2uid to convert a principal url to a calendar uid, fixes emclient uses urn:uuid urls in outbox posts to get freebusy
This commit is contained in:
parent
196f461de7
commit
b2ea1a7d05
@ -2236,7 +2236,7 @@ class calendar_ical extends calendar_boupdate
|
||||
* @param array $component VEVENT
|
||||
* @param string $version vCal version (1.0/2.0)
|
||||
* @param array $supportedFields supported fields of the device
|
||||
* @param string $principalURL='' Used for CalDAV imports
|
||||
* @param string $principalURL='' Used for CalDAV imports, no longer used in favor of groupdav_principals::url2uid()
|
||||
* @param string $check_component='Horde_iCalendar_vevent'
|
||||
*
|
||||
* @return array|boolean event on success, false on failure
|
||||
@ -2705,29 +2705,6 @@ class calendar_ical extends calendar_boupdate
|
||||
{
|
||||
$role = $attributes['params']['ROLE'];
|
||||
}
|
||||
// try pricipal url from CalDAV
|
||||
if (strpos($attributes['value'], 'http') === 0)
|
||||
{
|
||||
if (!empty($principalURL) && strstr($attributes['value'], $principalURL) !== false)
|
||||
{
|
||||
$uid = $this->user;
|
||||
if ($this->log)
|
||||
{
|
||||
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
||||
. "(): Found myself: '$uid'\n",3,$this->logfile);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->log)
|
||||
{
|
||||
error_log(__FILE__.'['.__LINE__.'] '.__METHOD__
|
||||
. '(): Unknown URI: ' . $attributes['value']
|
||||
. "\n",3,$this->logfile);
|
||||
}
|
||||
$attributes['value'] = '';
|
||||
}
|
||||
}
|
||||
// parse email and cn from attendee
|
||||
if (preg_match('/MAILTO:([@.a-z0-9_-]+)|MAILTO:"?([.a-z0-9_ -]*)"?[ ]*<([@.a-z0-9_-]*)>/i',
|
||||
$attributes['value'],$matches))
|
||||
@ -2767,6 +2744,9 @@ class calendar_ical extends calendar_boupdate
|
||||
// we use the current user
|
||||
$uid = $this->user;
|
||||
}
|
||||
// check principal url from CalDAV here after X-EGROUPWARE-UID and to get optional X-EGROUPWARE-QUANTITY
|
||||
if (!$uid) $uid = groupdav_principals::url2uid($attributes['value']);
|
||||
|
||||
// try to find an email address
|
||||
if (!$uid && $email && ($uid = $GLOBALS['egw']->accounts->name2id($email, 'account_email')))
|
||||
{
|
||||
|
@ -722,6 +722,62 @@ class groupdav_principals extends groupdav_handler
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert CalDAV principal URL to a calendar uid
|
||||
*
|
||||
* @param string $url
|
||||
* @param string|array $only_type=null allowed types, return false for other (valid) types, eg. "users", "groups" or "resources", default all
|
||||
* @return int|string|boolean integer account_id, string calendar uid or false if not a supported uid
|
||||
*/
|
||||
static public function url2uid($url, $only_type=null)
|
||||
{
|
||||
if (!$only_type) $only_type = array('accounts', 'groups', 'resources', 'mailto');
|
||||
|
||||
if ($url[0] == '/')
|
||||
{
|
||||
$schema = 'http';
|
||||
}
|
||||
else
|
||||
{
|
||||
list($schema, $rest) = explode(':', $url, 2);
|
||||
}
|
||||
if (empty($rest)) return false;
|
||||
|
||||
switch(strtolower($schema))
|
||||
{
|
||||
case 'http':
|
||||
case 'https':
|
||||
list(,$rest) = explode($GLOBALS['egw_info']['server']['webserver_url'].'/groupdav.php/principals/', $url);
|
||||
list($type, $name) = explode('/', $rest);
|
||||
$uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid', $type[0]); // u=users, g=groups
|
||||
break;
|
||||
|
||||
case 'mailto':
|
||||
if (($uid = $GLOBALS['egw']->accounts->name2id($rest, 'account_email')))
|
||||
{
|
||||
$type = $uid > 0 ? 'accounts' : 'groups';
|
||||
break;
|
||||
}
|
||||
// todo: contacts (uid "c"<contact-id>
|
||||
break;
|
||||
|
||||
case 'urn':
|
||||
list($urn_type, $name) = explode(':', $rest, 2);
|
||||
if ($urn_type === 'uuid' && ($uid = $GLOBALS['egw']->accounts->name2id($name, 'account_lid')))
|
||||
{
|
||||
$type = $uid > 0 ? 'accounts' : 'groups';
|
||||
break;
|
||||
}
|
||||
// todo: resources
|
||||
break;
|
||||
|
||||
default:
|
||||
error_log(__METHOD__."('$url') unsupported principal type '$schema'!");
|
||||
return false;
|
||||
}
|
||||
return $uid && in_array($type, $only_type) ? $uid : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add collection of a single group to a collection
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user