3 class Sabre_CalDAV_Backend_Std extends Sabre_CalDAV_Backend_Common
6 public function getNamespace()
8 return CALDAV_NAMESPACE_PRIVATE;
11 public function getCalUrlPrefix()
17 * Creates a new calendar for a principal.
19 * If the creation was a success, an id must be returned that can be used to reference
20 * this calendar in other methods, such as updateCalendar.
22 * @param string $principalUri
23 * @param string $calendarUri
24 * @param array $properties
27 public function createCalendar($principalUri, $calendarUri, array $properties)
29 // TODO: Implement createCalendar() method.
33 * Delete a calendar and all it's objects
35 * @param string $calendarId
38 public function deleteCalendar($calendarId)
40 // TODO: Implement deleteCalendar() method.
45 * Returns all calendar objects within a calendar.
47 * Every item contains an array with the following keys:
48 * * id - unique identifier which will be used for subsequent updates
49 * * calendardata - The iCalendar-compatible calendar data
50 * * uri - a unique key which will be used to construct the uri. This can be any arbitrary string.
51 * * lastmodified - a timestamp of the last modification time
52 * * etag - An arbitrary string, surrounded by double-quotes. (e.g.:
54 * * calendarid - The calendarid as it was passed to this function.
55 * * size - The size of the calendar objects, in bytes.
57 * Note that the etag is optional, but it's highly encouraged to return for
60 * The calendardata is also optional. If it's not returned
61 * 'getCalendarObject' will be called later, which *is* expected to return
64 * If neither etag or size are specified, the calendardata will be
65 * used/fetched to determine these numbers. If both are specified the
66 * amount of times this is needed is reduced by a great degree.
68 * @param string $calendarId
71 function getCalendarObjects($calendarId)
73 $x = explode("-", $calendarId);
74 $objs = q("SELECT * FROM %s%scalendarobjects WHERE `namespace` = %d AND `namespace_id` = %d", CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]));
76 foreach ($objs as $obj) {
78 "id" => IntVal($obj["id"]),
79 "calendardata" => $obj["calendardata"],
81 "lastmodified" => $obj["lastmodified"],
82 "calendarid" => $calendarId,
83 "etag" => $obj["etag"],
84 "size" => IntVal($obj["size"]),
91 * Returns information from a single calendar object, based on it's object
94 * The returned array must have the same keys as getCalendarObjects. The
95 * 'calendardata' object is required here though, while it's not required
96 * for getCalendarObjects.
98 * @param string $calendarId
99 * @param string $objectUri
100 * @throws Sabre_DAV_Exception_FileNotFound
103 function getCalendarObject($calendarId, $objectUri)
105 $x = explode("-", $calendarId);
107 $o = q("SELECT * FROM %s%scalendarobjects WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
108 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($objectUri));
110 $o[0]["calendarid"] = $calendarId;
111 $o[0]["calendardata"] = str_ireplace("Europe/Belgrade", "Europe/Berlin", $o[0]["calendardata"]);
113 } else throw new Sabre_DAV_Exception_FileNotFound($calendarId . " / " . $objectUri);
117 * Creates a new calendar object.
119 * @param string $calendarId
120 * @param string $objectUri
121 * @param string $calendarData
122 * @return null|string|void
124 function createCalendarObject($calendarId, $objectUri, $calendarData)
126 $x = explode("-", $calendarId);
128 q("INSERT INTO %s%scalendarobjects (`namespace`, `namespace_id`, `uri`, `calendardata`, `lastmodified`, `etag`, `size`) VALUES (%d, %d, '%s', '%s', NOW(), '%s', %d)",
129 CALDAV_SQL_DB, CALDAV_SQL_PREFIX,
130 IntVal($x[0]), IntVal($x[1]), dbesc($objectUri), addslashes($calendarData), md5($calendarData), strlen($calendarData)
133 $this->increaseCalendarCtag($x[0], $x[1]);
134 renderCalDavEntry_uri($objectUri);
138 * Updates an existing calendarobject, based on it's uri.
140 * @param string $calendarId
141 * @param string $objectUri
142 * @param string $calendarData
143 * @return null|string|void
145 function updateCalendarObject($calendarId, $objectUri, $calendarData)
147 $x = explode("-", $calendarId);
149 q("UPDATE %s%scalendarobjects SET `calendardata` = '%s', `lastmodified` = NOW(), `etag` = '%s', `size` = %d WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
150 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, dbesc($calendarData), md5($calendarData), strlen($calendarData), IntVal($x[0]), IntVal($x[1]), dbesc($objectUri));
152 $this->increaseCalendarCtag($x[0], $x[1]);
153 renderCalDavEntry_uri($objectUri);
157 * Deletes an existing calendar object.
159 * @param string $calendarId
160 * @param string $objectUri
163 function deleteCalendarObject($calendarId, $objectUri)
165 $x = explode("-", $calendarId);
167 q("DELETE FROM %s%scalendarobjects WHERE `namespace` = %d AND `namespace_id` = %d AND `uri` = '%s'",
168 CALDAV_SQL_DB, CALDAV_SQL_PREFIX, IntVal($x[0]), IntVal($x[1]), dbesc($objectUri)
171 $this->increaseCalendarCtag($x[0], $x[1]);
172 renderCalDavEntry_uri($objectUri);