--- /dev/null
+<?php
+/**
+ * This class implements a Horde CalDAV backend for SabreDAV.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * @package Sabre
+ * @author Jan Schneider <jan@horde.org>
+ * @license @todo
+ */
+class Sabre_CalDAV_Backend_Horde extends Sabre_CalDAV_Backend_Abstract
+{
+ /**
+ * @var Horde_Registry
+ */
+ protected $_registry;
+
+ public function __construct(Horde_Registry $registry)
+ {
+ $this->_registry = $registry;
+ }
+
+ /**
+ * Returns a list of calendars for a users' uri
+ *
+ * The uri is not a full path, just the actual last part
+ *
+ * @param string $userUri
+ * @return array
+ */
+ public function getCalendarsForUser($userUri)
+ {
+ // If possible we should ressamble the existing WebDAV structure with
+ // CalDAV. Listing just the calendars is not sufficient for this.
+ $result = array();
+ $owners = $this->_registry->calendar->browse('', array('name'));
+ foreach (reset($owners) as $owner) {
+ $calendars = $this->_registry->calendar->browse($owner['name'], array('name'));
+ foreach ($calendars as $name => $calendar) {
+ $result[] = substr($name, strrpos($name, '/'));
+ }
+ }
+ return $result;
+
+ // Alternative solution (without hierarchy):
+ return $this->_registry->calendar->listCalendars();
+ }
+
+ /**
+ * Creates a new calendar for a user
+ *
+ * The userUri and calendarUri are not full paths, just the 'basename'.
+ *
+ * @param string $userUri
+ * @param string $calendarUri
+ * @param string $displayName
+ * @param string $description
+ * @return void
+ */
+ public function createCalendar($userUri, $calendarUri, $displayName,
+ $description)
+ {
+ // To be implemented. We can't create the Horde_Share directly,
+ // because each application defines its own share namespace
+ // (e.g. horde.shares.kronolith), but this namespace is unknown
+ // outside of the application.
+ // Why Uri? Is it anything different than the plain user name and
+ // calendar ID?
+ $this->_registry->calendar->createCalendar($userUri, $calendarUri, $displayName, $description);
+ }
+
+ /**
+ * Updates a calendar's basic information
+ *
+ * @param string $calendarId
+ * @param string $displayName
+ * @param string $description
+ * @return void
+ */
+ public function updateCalendar($calendarId, $displayName, $description)
+ {
+ // To be implemented.
+ // ID == calendar name in Horde.
+ $this->_registry->calendar->updateCalendar($calendarId, $displayName, $description);
+ }
+
+ /**
+ * Returns all calendar objects within a calendar object.
+ *
+ * @param string $calendarId
+ * @return array
+ */
+ public function getCalendarObjects($calendarId)
+ {
+ // browse() assumes an intermediate owner directory at the moment.
+ $owner = 'foo';
+ $events = $this->_registry->calendar->browse($owner . '/' . $calendarId, array('name'));
+
+ // Return format?
+ return $events;
+ }
+
+ /**
+ * Returns information from a single calendar object, based on it's object
+ * uri.
+ *
+ * @param mixed $calendarId
+ * @param string $objectUri
+ * @return array
+ */
+ public function getCalendarObject($calendarId, $objectUri)
+ {
+ // browse() assumes an intermediate owner directory at the moment.
+ $owner = 'foo';
+ $event = $this->_registry->calendar->browse($owner . '/' . $calendarId . '/' . $objectUri);
+ return array('calendardata' => $event['data'],
+ 'lastmodified' => $event['mtime']);
+ // What else to return? Mime type?
+ }
+
+ /**
+ * Creates a new calendar object.
+ *
+ * @param mixed $calendarId
+ * @param string $objectUri
+ * @param string $calendarData
+ * @return void
+ */
+ public function createCalendarObject($calendarId, $objectUri, $calendarData)
+ {
+ // No Content-Type?
+ // We don't accept object ids at the moment.
+ $this->_registry->import($calendarData, 'text/calendar', $calendarId);
+ }
+
+ /**
+ * Updates an existing calendarobject, based on it's uri.
+ *
+ * @param mixed $calendarId
+ * @param string $objectUri
+ * @param string $calendarData
+ * @return void
+ */
+ public function updateCalendarObject($calendarId, $objectUri, $calendarData)
+ {
+ // No Content-Type?
+ // Object ID or UID?
+ $this->_registry->import($objectUri, $calendarData, 'text/calendar');
+ }
+
+ /**
+ * Deletes an existing calendar object.
+ *
+ * @param mixed $calendarId
+ * @param string $objectUri
+ * @return void
+ */
+ public function deleteCalendarObject($calendarId, $objectUri)
+ {
+ // Object ID or UID?
+ $this->_registry->delete($objectUri);
+ }
+
+}
--- /dev/null
+<?php
+/**
+ * This class implements an authentication backend for Sabre_DAV based on
+ * Horde_Auth.
+ *
+ * Copyright 2009 The Horde Project (http://www.horde.org/)
+ *
+ * @package Sabre
+ * @author Jan Schneider <jan@horde.org>
+ * @license @todo
+ */
+class Sabre_DAV_Auth_Backend_Horde extends Sabre_DAV_Auth_Backend_Abstract
+{
+ /**
+ * @var Horde_Auth
+ */
+ protected $_auth;
+
+ public function __construct(Horde_Auth $auth)
+ {
+ $this->_auth = $auth;
+ }
+
+ /**
+ * Returns the HTTP Digest hash for a username
+ *
+ * This must be the A1 part of the digest hash
+ *
+ * @param string $username
+ * @return string
+ */
+ public function getDigestHash($username)
+ {
+ // We don't have the A1 hash stored, and we don't have the plaintext
+ // passwords. Workaround?
+ }
+
+ public function getUserList()
+ {
+ if (!$this->_auth->hasCapability('list')) {
+ return array();
+ }
+
+ $users = array();
+ foreach ($this->_auth->listUsers() as $user) {
+ $users[] = array('href' => $user);
+ // We could potentially get {DAV:}displayname from the users'
+ // identities, but we should only do that if this method is not
+ // supposed to be called too often.
+ }
+
+ return $users;
+ }
+
+}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<package packagerversion="1.4.9" version="2.0" xmlns="http://pear.php.net/dtd/package-2.0" xmlns:tasks="http://pear.php.net/dtd/tasks-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pear.php.net/dtd/tasks-1.0
+http://pear.php.net/dtd/tasks-1.0.xsd
+http://pear.php.net/dtd/package-2.0
+http://pear.php.net/dtd/package-2.0.xsd">
+ <name>Sabre</name>
+ <channel>pear.horde.org</channel>
+ <summary>Backend implementations for SabreDAV</summary>
+ <description>This package contains all Horde-specific backend implementations for Sabre's abstract classes.</description>
+ <lead>
+ <name>Jan Schneider</name>
+ <user>jan</user>
+ <email>jan@horde.org</email>
+ <active>yes</active>
+ </lead>
+ <date>2009-12-31</date>
+ <version>
+ <release>0.1.0</release>
+ <api>0.1.0</api>
+ </version>
+ <stability>
+ <release>beta</release>
+ <api>beta</api>
+ </stability>
+ <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
+ <notes>* Initial Horde 4 package.</notes>
+ <contents>
+ <dir name="/">
+ <dir name="lib">
+ <dir name="Sabre">
+ <dir name="CalDAV">
+ <dir name="Backend">
+ <file name="Horde.php" role="php" />
+ </dir> <!-- /lib/Sabre/CalDAV/Backend -->
+ </dir> <!-- /lib/Sabre/CalDAV -->
+ <dir name="DAV">
+ <dir name="Auth">
+ <dir name="Backend">
+ <file name="Horde.php" role="php" />
+ </dir> <!-- /lib/Sabre/DAV/Auth/Backend -->
+ </dir> <!-- /lib/Sabre/DAV/Auth -->
+ </dir> <!-- /lib/Sabre/DAV -->
+ </dir> <!-- /lib/Sabre -->
+ </dir> <!-- /lib -->
+ </dir> <!-- / -->
+ </contents>
+ <dependencies>
+ <required>
+ <php>
+ <min>5.2.0</min>
+ </php>
+ <pearinstaller>
+ <min>1.5.0</min>
+ </pearinstaller>
+ <package>
+ <name>Core</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ <package>
+ <name>Auth</name>
+ <channel>pear.horde.org</channel>
+ </package>
+ </required>
+ </dependencies>
+ <phprelease>
+ <filelist>
+ <install name="lib/Sabre/DAV/Auth/Backend/Horde.php" as="Sabre/DAV/Auth/Backend/Horde.php" />
+ <install name="lib/Sabre/CalDAV/Backend/Horde.php" as="Sabre/CalDAV/Backend/Horde.php" />
+ </filelist>
+ </phprelease>
+ <changelog>
+ </changelog>
+</package>