summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Bruederli <thomas@roundcube.net>2013-03-28 16:49:28 (GMT)
committerThomas Bruederli <thomas@roundcube.net>2013-03-28 16:49:28 (GMT)
commit44ebf31c47b5f66ba6da1720948cee01d6f89ccd (patch)
tree6192a50383ce08c79e727b408de20e273734e972
parentff6f3e573202006a1ee3ea71d8b47c726d431c82 (diff)
downloadiRony-44ebf31c47b5f66ba6da1720948cee01d6f89ccd.tar.gz
Support calendar access through real folder names as an alternative to UIDs
-rw-r--r--lib/Kolab/CalDAV/CalendarBackend.php34
-rw-r--r--lib/Kolab/CalDAV/UserCalendars.php30
2 files changed, 62 insertions, 2 deletions
diff --git a/lib/Kolab/CalDAV/CalendarBackend.php b/lib/Kolab/CalDAV/CalendarBackend.php
index c6d1aa3..72e8a7a 100644
--- a/lib/Kolab/CalDAV/CalendarBackend.php
+++ b/lib/Kolab/CalDAV/CalendarBackend.php
@@ -43,6 +43,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
{
private $calendars;
private $folders;
+ private $aliases;
private $useragent;
/**
@@ -56,7 +57,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
// get all folders that have "event" type
$folders = kolab_storage::get_folders('event');
- $this->calendars = $this->folders = array();
+ $this->calendars = $this->folders = $this->aliases = array();
// convert to UTF8 and sort
$names = array();
@@ -80,6 +81,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
'{urn:ietf:params:xml:ns:caldav}supported-calendar-component-set' => new CalDAV\Property\SupportedCalendarComponentSet(array('VEVENT')),
'{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp' => new CalDAV\Property\ScheduleCalendarTransp('opaque'),
);
+ $this->aliases[$utf7name] = $id;
// these properties are used for sahring supprt (not yet active)
if (false && $folder->get_namespace() != 'personal') {
@@ -101,6 +103,11 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
*/
public function get_storage_folder($id)
{
+ // resolve alias name
+ if ($this->aliases[$id]) {
+ $id = $this->aliases[$id];
+ }
+
if ($this->folders[$id]) {
return $this->folders[$id];
}
@@ -142,6 +149,8 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
*/
public function getCalendarsForUser($principalUri)
{
+ console(__METHOD__, $principalUri);
+
$this->_read_calendars();
$calendars = array();
@@ -154,6 +163,27 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
}
/**
+ * Returns calendar properties for a specific node identified by name/uri
+ *
+ * @param string Node name/uri
+ * @return array Hash array with calendar properties or null if not found
+ */
+ public function getCalendarByName($calendarUri)
+ {
+ console(__METHOD__, $calendarUri);
+
+ $this->_read_calendars();
+ $id = $calendarUri;
+
+ // resolve aliases (calendar by folder name)
+ if ($this->aliases[$calendarUri]) {
+ $id = $this->aliases[$calendarUri];
+ }
+
+ return $this->calendars[$id];
+ }
+
+ /**
* Creates a new calendar for a principal.
*
* If the creation was a success, an id must be returned that can be used to reference
@@ -255,7 +285,7 @@ class CalendarBackend extends CalDAV\Backend\AbstractBackend
case '{DAV:}displayname':
// restrict renaming to personal folders only
if ($folder->get_namespace() == 'personal') {
- $parts = explode('/', $val);
+ $parts = preg_split('!(\s*/\s*|\s+[ยป:]\s+)!', $val);
$updates['oldname'] = $folder->name;
$updates['name'] = array_pop($parts);
$updates['parent'] = join('/', $parts);
diff --git a/lib/Kolab/CalDAV/UserCalendars.php b/lib/Kolab/CalDAV/UserCalendars.php
index b00b1b6..ab39185 100644
--- a/lib/Kolab/CalDAV/UserCalendars.php
+++ b/lib/Kolab/CalDAV/UserCalendars.php
@@ -71,6 +71,36 @@ class UserCalendars extends \Sabre\CalDAV\UserCalendars implements DAV\IExtended
}
/**
+ * Returns a single calendar, by name
+ *
+ * @param string $name
+ * @return Calendar
+ */
+ public function getChild($name)
+ {
+ if ($calendar = $this->caldavBackend->getCalendarByName($name)) {
+ $calendar['principaluri'] = $this->principalInfo['uri'];
+ return new Calendar($this->caldavBackend, $calendar);
+ }
+
+ throw new DAV\Exception\NotFound('Calendar with name \'' . $name . '\' could not be found');
+ }
+
+ /**
+ * Checks if a calendar exists.
+ *
+ * @param string $name
+ * @return bool
+ */
+ public function childExists($name)
+ {
+ if ($this->caldavBackend->getCalendarByName($name)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* Returns a list of ACE's for this node.
*
* Each ACE has the following properties: