Completed
Branch develop (c24f26)
by
unknown
26:13
created
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Notifications/INode.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -22,20 +22,20 @@
 block discarded – undo
22 22
  */
23 23
 interface INode
24 24
 {
25
-    /**
26
-     * This method must return an xml element, using the
27
-     * Sabre\CalDAV\Xml\Notification\NotificationInterface classes.
28
-     *
29
-     * @return NotificationInterface
30
-     */
31
-    public function getNotificationType();
25
+	/**
26
+	 * This method must return an xml element, using the
27
+	 * Sabre\CalDAV\Xml\Notification\NotificationInterface classes.
28
+	 *
29
+	 * @return NotificationInterface
30
+	 */
31
+	public function getNotificationType();
32 32
 
33
-    /**
34
-     * Returns the etag for the notification.
35
-     *
36
-     * The etag must be surrounded by literal double-quotes.
37
-     *
38
-     * @return string
39
-     */
40
-    public function getETag();
33
+	/**
34
+	 * Returns the etag for the notification.
35
+	 *
36
+	 * The etag must be surrounded by literal double-quotes.
37
+	 *
38
+	 * @return string
39
+	 */
40
+	public function getETag();
41 41
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/SharingPlugin.php 2 patches
Indentation   +316 added lines, -316 removed lines patch added patch discarded remove patch
@@ -27,320 +27,320 @@
 block discarded – undo
27 27
  */
28 28
 class SharingPlugin extends DAV\ServerPlugin
29 29
 {
30
-    /**
31
-     * Reference to SabreDAV server object.
32
-     *
33
-     * @var DAV\Server
34
-     */
35
-    protected $server;
36
-
37
-    /**
38
-     * This method should return a list of server-features.
39
-     *
40
-     * This is for example 'versioning' and is added to the DAV: header
41
-     * in an OPTIONS response.
42
-     *
43
-     * @return array
44
-     */
45
-    public function getFeatures()
46
-    {
47
-        return ['calendarserver-sharing'];
48
-    }
49
-
50
-    /**
51
-     * Returns a plugin name.
52
-     *
53
-     * Using this name other plugins will be able to access other plugins
54
-     * using Sabre\DAV\Server::getPlugin
55
-     *
56
-     * @return string
57
-     */
58
-    public function getPluginName()
59
-    {
60
-        return 'caldav-sharing';
61
-    }
62
-
63
-    /**
64
-     * This initializes the plugin.
65
-     *
66
-     * This function is called by Sabre\DAV\Server, after
67
-     * addPlugin is called.
68
-     *
69
-     * This method should set up the required event subscriptions.
70
-     */
71
-    public function initialize(DAV\Server $server)
72
-    {
73
-        $this->server = $server;
74
-
75
-        if (is_null($this->server->getPlugin('sharing'))) {
76
-            throw new \LogicException('The generic "sharing" plugin must be loaded before the caldav sharing plugin. Call $server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); before this one.');
77
-        }
78
-
79
-        array_push(
80
-            $this->server->protectedProperties,
81
-            '{'.Plugin::NS_CALENDARSERVER.'}invite',
82
-            '{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes',
83
-            '{'.Plugin::NS_CALENDARSERVER.'}shared-url'
84
-        );
85
-
86
-        $this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share';
87
-        $this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply';
88
-
89
-        $this->server->on('propFind', [$this, 'propFindEarly']);
90
-        $this->server->on('propFind', [$this, 'propFindLate'], 150);
91
-        $this->server->on('propPatch', [$this, 'propPatch'], 40);
92
-        $this->server->on('method:POST', [$this, 'httpPost']);
93
-    }
94
-
95
-    /**
96
-     * This event is triggered when properties are requested for a certain
97
-     * node.
98
-     *
99
-     * This allows us to inject any properties early.
100
-     */
101
-    public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node)
102
-    {
103
-        if ($node instanceof ISharedCalendar) {
104
-            $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}invite', function () use ($node) {
105
-                return new Xml\Property\Invite(
106
-                    $node->getInvites()
107
-                );
108
-            });
109
-        }
110
-    }
111
-
112
-    /**
113
-     * This method is triggered *after* all properties have been retrieved.
114
-     * This allows us to inject the correct resourcetype for calendars that
115
-     * have been shared.
116
-     */
117
-    public function propFindLate(DAV\PropFind $propFind, DAV\INode $node)
118
-    {
119
-        if ($node instanceof ISharedCalendar) {
120
-            $shareAccess = $node->getShareAccess();
121
-            if ($rt = $propFind->get('{DAV:}resourcetype')) {
122
-                switch ($shareAccess) {
123
-                    case \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER:
124
-                        $rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared-owner');
125
-                        break;
126
-                    case \Sabre\DAV\Sharing\Plugin::ACCESS_READ:
127
-                    case \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE:
128
-                        $rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared');
129
-                        break;
130
-                }
131
-            }
132
-            $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', function () {
133
-                return new Xml\Property\AllowedSharingModes(true, false);
134
-            });
135
-        }
136
-    }
137
-
138
-    /**
139
-     * This method is trigged when a user attempts to update a node's
140
-     * properties.
141
-     *
142
-     * A previous draft of the sharing spec stated that it was possible to use
143
-     * PROPPATCH to remove 'shared-owner' from the resourcetype, thus unsharing
144
-     * the calendar.
145
-     *
146
-     * Even though this is no longer in the current spec, we keep this around
147
-     * because OS X 10.7 may still make use of this feature.
148
-     *
149
-     * @param string $path
150
-     */
151
-    public function propPatch($path, DAV\PropPatch $propPatch)
152
-    {
153
-        $node = $this->server->tree->getNodeForPath($path);
154
-        if (!$node instanceof ISharedCalendar) {
155
-            return;
156
-        }
157
-
158
-        if (\Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $node->getShareAccess() || \Sabre\DAV\Sharing\Plugin::ACCESS_NOTSHARED === $node->getShareAccess()) {
159
-            $propPatch->handle('{DAV:}resourcetype', function ($value) use ($node) {
160
-                if ($value->is('{'.Plugin::NS_CALENDARSERVER.'}shared-owner')) {
161
-                    return false;
162
-                }
163
-                $shares = $node->getInvites();
164
-                foreach ($shares as $share) {
165
-                    $share->access = DAV\Sharing\Plugin::ACCESS_NOACCESS;
166
-                }
167
-                $node->updateInvites($shares);
168
-
169
-                return true;
170
-            });
171
-        }
172
-    }
173
-
174
-    /**
175
-     * We intercept this to handle POST requests on calendars.
176
-     *
177
-     * @return bool|null
178
-     */
179
-    public function httpPost(RequestInterface $request, ResponseInterface $response)
180
-    {
181
-        $path = $request->getPath();
182
-
183
-        // Only handling xml
184
-        $contentType = $request->getHeader('Content-Type');
185
-        if (null === $contentType) {
186
-            return;
187
-        }
188
-        if (false === strpos($contentType, 'application/xml') && false === strpos($contentType, 'text/xml')) {
189
-            return;
190
-        }
191
-
192
-        // Making sure the node exists
193
-        try {
194
-            $node = $this->server->tree->getNodeForPath($path);
195
-        } catch (DAV\Exception\NotFound $e) {
196
-            return;
197
-        }
198
-
199
-        $requestBody = $request->getBodyAsString();
200
-
201
-        // If this request handler could not deal with this POST request, it
202
-        // will return 'null' and other plugins get a chance to handle the
203
-        // request.
204
-        //
205
-        // However, we already requested the full body. This is a problem,
206
-        // because a body can only be read once. This is why we preemptively
207
-        // re-populated the request body with the existing data.
208
-        $request->setBody($requestBody);
209
-
210
-        $message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
211
-
212
-        switch ($documentType) {
213
-            // Both the DAV:share-resource and CALENDARSERVER:share requests
214
-            // behave identically.
215
-            case '{'.Plugin::NS_CALENDARSERVER.'}share':
216
-                $sharingPlugin = $this->server->getPlugin('sharing');
217
-                $sharingPlugin->shareResource($path, $message->sharees);
218
-
219
-                $response->setStatus(200);
220
-                // Adding this because sending a response body may cause issues,
221
-                // and I wanted some type of indicator the response was handled.
222
-                $response->setHeader('X-Sabre-Status', 'everything-went-well');
223
-
224
-                // Breaking the event chain
225
-                return false;
226
-
227
-            // The invite-reply document is sent when the user replies to an
228
-            // invitation of a calendar share.
229
-            case '{'.Plugin::NS_CALENDARSERVER.'}invite-reply':
230
-                // This only works on the calendar-home-root node.
231
-                if (!$node instanceof CalendarHome) {
232
-                    return;
233
-                }
234
-                $this->server->transactionType = 'post-invite-reply';
235
-
236
-                // Getting ACL info
237
-                $acl = $this->server->getPlugin('acl');
238
-
239
-                // If there's no ACL support, we allow everything
240
-                if ($acl) {
241
-                    $acl->checkPrivileges($path, '{DAV:}write');
242
-                }
243
-
244
-                $url = $node->shareReply(
245
-                    $message->href,
246
-                    $message->status,
247
-                    $message->calendarUri,
248
-                    $message->inReplyTo,
249
-                    $message->summary
250
-                );
251
-
252
-                $response->setStatus(200);
253
-                // Adding this because sending a response body may cause issues,
254
-                // and I wanted some type of indicator the response was handled.
255
-                $response->setHeader('X-Sabre-Status', 'everything-went-well');
256
-
257
-                if ($url) {
258
-                    $writer = $this->server->xml->getWriter();
259
-                    $writer->contextUri = $request->getUrl();
260
-                    $writer->openMemory();
261
-                    $writer->startDocument();
262
-                    $writer->startElement('{'.Plugin::NS_CALENDARSERVER.'}shared-as');
263
-                    $writer->write(new LocalHref($url));
264
-                    $writer->endElement();
265
-                    $response->setHeader('Content-Type', 'application/xml');
266
-                    $response->setBody($writer->outputMemory());
267
-                }
268
-
269
-                // Breaking the event chain
270
-                return false;
271
-
272
-            case '{'.Plugin::NS_CALENDARSERVER.'}publish-calendar':
273
-                // We can only deal with IShareableCalendar objects
274
-                if (!$node instanceof ISharedCalendar) {
275
-                    return;
276
-                }
277
-                $this->server->transactionType = 'post-publish-calendar';
278
-
279
-                // Getting ACL info
280
-                $acl = $this->server->getPlugin('acl');
281
-
282
-                // If there's no ACL support, we allow everything
283
-                if ($acl) {
284
-                    $acl->checkPrivileges($path, '{DAV:}share');
285
-                }
286
-
287
-                $node->setPublishStatus(true);
288
-
289
-                // iCloud sends back the 202, so we will too.
290
-                $response->setStatus(202);
291
-
292
-                // Adding this because sending a response body may cause issues,
293
-                // and I wanted some type of indicator the response was handled.
294
-                $response->setHeader('X-Sabre-Status', 'everything-went-well');
295
-
296
-                // Breaking the event chain
297
-                return false;
298
-
299
-            case '{'.Plugin::NS_CALENDARSERVER.'}unpublish-calendar':
300
-                // We can only deal with IShareableCalendar objects
301
-                if (!$node instanceof ISharedCalendar) {
302
-                    return;
303
-                }
304
-                $this->server->transactionType = 'post-unpublish-calendar';
305
-
306
-                // Getting ACL info
307
-                $acl = $this->server->getPlugin('acl');
308
-
309
-                // If there's no ACL support, we allow everything
310
-                if ($acl) {
311
-                    $acl->checkPrivileges($path, '{DAV:}share');
312
-                }
313
-
314
-                $node->setPublishStatus(false);
315
-
316
-                $response->setStatus(200);
317
-
318
-                // Adding this because sending a response body may cause issues,
319
-                // and I wanted some type of indicator the response was handled.
320
-                $response->setHeader('X-Sabre-Status', 'everything-went-well');
321
-
322
-                // Breaking the event chain
323
-                return false;
324
-        }
325
-    }
326
-
327
-    /**
328
-     * Returns a bunch of meta-data about the plugin.
329
-     *
330
-     * Providing this information is optional, and is mainly displayed by the
331
-     * Browser plugin.
332
-     *
333
-     * The description key in the returned array may contain html and will not
334
-     * be sanitized.
335
-     *
336
-     * @return array
337
-     */
338
-    public function getPluginInfo()
339
-    {
340
-        return [
341
-            'name' => $this->getPluginName(),
342
-            'description' => 'Adds support for caldav-sharing.',
343
-            'link' => 'http://sabre.io/dav/caldav-sharing/',
344
-        ];
345
-    }
30
+	/**
31
+	 * Reference to SabreDAV server object.
32
+	 *
33
+	 * @var DAV\Server
34
+	 */
35
+	protected $server;
36
+
37
+	/**
38
+	 * This method should return a list of server-features.
39
+	 *
40
+	 * This is for example 'versioning' and is added to the DAV: header
41
+	 * in an OPTIONS response.
42
+	 *
43
+	 * @return array
44
+	 */
45
+	public function getFeatures()
46
+	{
47
+		return ['calendarserver-sharing'];
48
+	}
49
+
50
+	/**
51
+	 * Returns a plugin name.
52
+	 *
53
+	 * Using this name other plugins will be able to access other plugins
54
+	 * using Sabre\DAV\Server::getPlugin
55
+	 *
56
+	 * @return string
57
+	 */
58
+	public function getPluginName()
59
+	{
60
+		return 'caldav-sharing';
61
+	}
62
+
63
+	/**
64
+	 * This initializes the plugin.
65
+	 *
66
+	 * This function is called by Sabre\DAV\Server, after
67
+	 * addPlugin is called.
68
+	 *
69
+	 * This method should set up the required event subscriptions.
70
+	 */
71
+	public function initialize(DAV\Server $server)
72
+	{
73
+		$this->server = $server;
74
+
75
+		if (is_null($this->server->getPlugin('sharing'))) {
76
+			throw new \LogicException('The generic "sharing" plugin must be loaded before the caldav sharing plugin. Call $server->addPlugin(new \Sabre\DAV\Sharing\Plugin()); before this one.');
77
+		}
78
+
79
+		array_push(
80
+			$this->server->protectedProperties,
81
+			'{'.Plugin::NS_CALENDARSERVER.'}invite',
82
+			'{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes',
83
+			'{'.Plugin::NS_CALENDARSERVER.'}shared-url'
84
+		);
85
+
86
+		$this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}share'] = 'Sabre\\CalDAV\\Xml\\Request\\Share';
87
+		$this->server->xml->elementMap['{'.Plugin::NS_CALENDARSERVER.'}invite-reply'] = 'Sabre\\CalDAV\\Xml\\Request\\InviteReply';
88
+
89
+		$this->server->on('propFind', [$this, 'propFindEarly']);
90
+		$this->server->on('propFind', [$this, 'propFindLate'], 150);
91
+		$this->server->on('propPatch', [$this, 'propPatch'], 40);
92
+		$this->server->on('method:POST', [$this, 'httpPost']);
93
+	}
94
+
95
+	/**
96
+	 * This event is triggered when properties are requested for a certain
97
+	 * node.
98
+	 *
99
+	 * This allows us to inject any properties early.
100
+	 */
101
+	public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node)
102
+	{
103
+		if ($node instanceof ISharedCalendar) {
104
+			$propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}invite', function () use ($node) {
105
+				return new Xml\Property\Invite(
106
+					$node->getInvites()
107
+				);
108
+			});
109
+		}
110
+	}
111
+
112
+	/**
113
+	 * This method is triggered *after* all properties have been retrieved.
114
+	 * This allows us to inject the correct resourcetype for calendars that
115
+	 * have been shared.
116
+	 */
117
+	public function propFindLate(DAV\PropFind $propFind, DAV\INode $node)
118
+	{
119
+		if ($node instanceof ISharedCalendar) {
120
+			$shareAccess = $node->getShareAccess();
121
+			if ($rt = $propFind->get('{DAV:}resourcetype')) {
122
+				switch ($shareAccess) {
123
+					case \Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER:
124
+						$rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared-owner');
125
+						break;
126
+					case \Sabre\DAV\Sharing\Plugin::ACCESS_READ:
127
+					case \Sabre\DAV\Sharing\Plugin::ACCESS_READWRITE:
128
+						$rt->add('{'.Plugin::NS_CALENDARSERVER.'}shared');
129
+						break;
130
+				}
131
+			}
132
+			$propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', function () {
133
+				return new Xml\Property\AllowedSharingModes(true, false);
134
+			});
135
+		}
136
+	}
137
+
138
+	/**
139
+	 * This method is trigged when a user attempts to update a node's
140
+	 * properties.
141
+	 *
142
+	 * A previous draft of the sharing spec stated that it was possible to use
143
+	 * PROPPATCH to remove 'shared-owner' from the resourcetype, thus unsharing
144
+	 * the calendar.
145
+	 *
146
+	 * Even though this is no longer in the current spec, we keep this around
147
+	 * because OS X 10.7 may still make use of this feature.
148
+	 *
149
+	 * @param string $path
150
+	 */
151
+	public function propPatch($path, DAV\PropPatch $propPatch)
152
+	{
153
+		$node = $this->server->tree->getNodeForPath($path);
154
+		if (!$node instanceof ISharedCalendar) {
155
+			return;
156
+		}
157
+
158
+		if (\Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $node->getShareAccess() || \Sabre\DAV\Sharing\Plugin::ACCESS_NOTSHARED === $node->getShareAccess()) {
159
+			$propPatch->handle('{DAV:}resourcetype', function ($value) use ($node) {
160
+				if ($value->is('{'.Plugin::NS_CALENDARSERVER.'}shared-owner')) {
161
+					return false;
162
+				}
163
+				$shares = $node->getInvites();
164
+				foreach ($shares as $share) {
165
+					$share->access = DAV\Sharing\Plugin::ACCESS_NOACCESS;
166
+				}
167
+				$node->updateInvites($shares);
168
+
169
+				return true;
170
+			});
171
+		}
172
+	}
173
+
174
+	/**
175
+	 * We intercept this to handle POST requests on calendars.
176
+	 *
177
+	 * @return bool|null
178
+	 */
179
+	public function httpPost(RequestInterface $request, ResponseInterface $response)
180
+	{
181
+		$path = $request->getPath();
182
+
183
+		// Only handling xml
184
+		$contentType = $request->getHeader('Content-Type');
185
+		if (null === $contentType) {
186
+			return;
187
+		}
188
+		if (false === strpos($contentType, 'application/xml') && false === strpos($contentType, 'text/xml')) {
189
+			return;
190
+		}
191
+
192
+		// Making sure the node exists
193
+		try {
194
+			$node = $this->server->tree->getNodeForPath($path);
195
+		} catch (DAV\Exception\NotFound $e) {
196
+			return;
197
+		}
198
+
199
+		$requestBody = $request->getBodyAsString();
200
+
201
+		// If this request handler could not deal with this POST request, it
202
+		// will return 'null' and other plugins get a chance to handle the
203
+		// request.
204
+		//
205
+		// However, we already requested the full body. This is a problem,
206
+		// because a body can only be read once. This is why we preemptively
207
+		// re-populated the request body with the existing data.
208
+		$request->setBody($requestBody);
209
+
210
+		$message = $this->server->xml->parse($requestBody, $request->getUrl(), $documentType);
211
+
212
+		switch ($documentType) {
213
+			// Both the DAV:share-resource and CALENDARSERVER:share requests
214
+			// behave identically.
215
+			case '{'.Plugin::NS_CALENDARSERVER.'}share':
216
+				$sharingPlugin = $this->server->getPlugin('sharing');
217
+				$sharingPlugin->shareResource($path, $message->sharees);
218
+
219
+				$response->setStatus(200);
220
+				// Adding this because sending a response body may cause issues,
221
+				// and I wanted some type of indicator the response was handled.
222
+				$response->setHeader('X-Sabre-Status', 'everything-went-well');
223
+
224
+				// Breaking the event chain
225
+				return false;
226
+
227
+			// The invite-reply document is sent when the user replies to an
228
+			// invitation of a calendar share.
229
+			case '{'.Plugin::NS_CALENDARSERVER.'}invite-reply':
230
+				// This only works on the calendar-home-root node.
231
+				if (!$node instanceof CalendarHome) {
232
+					return;
233
+				}
234
+				$this->server->transactionType = 'post-invite-reply';
235
+
236
+				// Getting ACL info
237
+				$acl = $this->server->getPlugin('acl');
238
+
239
+				// If there's no ACL support, we allow everything
240
+				if ($acl) {
241
+					$acl->checkPrivileges($path, '{DAV:}write');
242
+				}
243
+
244
+				$url = $node->shareReply(
245
+					$message->href,
246
+					$message->status,
247
+					$message->calendarUri,
248
+					$message->inReplyTo,
249
+					$message->summary
250
+				);
251
+
252
+				$response->setStatus(200);
253
+				// Adding this because sending a response body may cause issues,
254
+				// and I wanted some type of indicator the response was handled.
255
+				$response->setHeader('X-Sabre-Status', 'everything-went-well');
256
+
257
+				if ($url) {
258
+					$writer = $this->server->xml->getWriter();
259
+					$writer->contextUri = $request->getUrl();
260
+					$writer->openMemory();
261
+					$writer->startDocument();
262
+					$writer->startElement('{'.Plugin::NS_CALENDARSERVER.'}shared-as');
263
+					$writer->write(new LocalHref($url));
264
+					$writer->endElement();
265
+					$response->setHeader('Content-Type', 'application/xml');
266
+					$response->setBody($writer->outputMemory());
267
+				}
268
+
269
+				// Breaking the event chain
270
+				return false;
271
+
272
+			case '{'.Plugin::NS_CALENDARSERVER.'}publish-calendar':
273
+				// We can only deal with IShareableCalendar objects
274
+				if (!$node instanceof ISharedCalendar) {
275
+					return;
276
+				}
277
+				$this->server->transactionType = 'post-publish-calendar';
278
+
279
+				// Getting ACL info
280
+				$acl = $this->server->getPlugin('acl');
281
+
282
+				// If there's no ACL support, we allow everything
283
+				if ($acl) {
284
+					$acl->checkPrivileges($path, '{DAV:}share');
285
+				}
286
+
287
+				$node->setPublishStatus(true);
288
+
289
+				// iCloud sends back the 202, so we will too.
290
+				$response->setStatus(202);
291
+
292
+				// Adding this because sending a response body may cause issues,
293
+				// and I wanted some type of indicator the response was handled.
294
+				$response->setHeader('X-Sabre-Status', 'everything-went-well');
295
+
296
+				// Breaking the event chain
297
+				return false;
298
+
299
+			case '{'.Plugin::NS_CALENDARSERVER.'}unpublish-calendar':
300
+				// We can only deal with IShareableCalendar objects
301
+				if (!$node instanceof ISharedCalendar) {
302
+					return;
303
+				}
304
+				$this->server->transactionType = 'post-unpublish-calendar';
305
+
306
+				// Getting ACL info
307
+				$acl = $this->server->getPlugin('acl');
308
+
309
+				// If there's no ACL support, we allow everything
310
+				if ($acl) {
311
+					$acl->checkPrivileges($path, '{DAV:}share');
312
+				}
313
+
314
+				$node->setPublishStatus(false);
315
+
316
+				$response->setStatus(200);
317
+
318
+				// Adding this because sending a response body may cause issues,
319
+				// and I wanted some type of indicator the response was handled.
320
+				$response->setHeader('X-Sabre-Status', 'everything-went-well');
321
+
322
+				// Breaking the event chain
323
+				return false;
324
+		}
325
+	}
326
+
327
+	/**
328
+	 * Returns a bunch of meta-data about the plugin.
329
+	 *
330
+	 * Providing this information is optional, and is mainly displayed by the
331
+	 * Browser plugin.
332
+	 *
333
+	 * The description key in the returned array may contain html and will not
334
+	 * be sanitized.
335
+	 *
336
+	 * @return array
337
+	 */
338
+	public function getPluginInfo()
339
+	{
340
+		return [
341
+			'name' => $this->getPluginName(),
342
+			'description' => 'Adds support for caldav-sharing.',
343
+			'link' => 'http://sabre.io/dav/caldav-sharing/',
344
+		];
345
+	}
346 346
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function propFindEarly(DAV\PropFind $propFind, DAV\INode $node)
102 102
     {
103 103
         if ($node instanceof ISharedCalendar) {
104
-            $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}invite', function () use ($node) {
104
+            $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}invite', function() use ($node) {
105 105
                 return new Xml\Property\Invite(
106 106
                     $node->getInvites()
107 107
                 );
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
                         break;
130 130
                 }
131 131
             }
132
-            $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', function () {
132
+            $propFind->handle('{'.Plugin::NS_CALENDARSERVER.'}allowed-sharing-modes', function() {
133 133
                 return new Xml\Property\AllowedSharingModes(true, false);
134 134
             });
135 135
         }
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         }
157 157
 
158 158
         if (\Sabre\DAV\Sharing\Plugin::ACCESS_SHAREDOWNER === $node->getShareAccess() || \Sabre\DAV\Sharing\Plugin::ACCESS_NOTSHARED === $node->getShareAccess()) {
159
-            $propPatch->handle('{DAV:}resourcetype', function ($value) use ($node) {
159
+            $propPatch->handle('{DAV:}resourcetype', function($value) use ($node) {
160 160
                 if ($value->is('{'.Plugin::NS_CALENDARSERVER.'}shared-owner')) {
161 161
                     return false;
162 162
                 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/ICalendarObjectContainer.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -19,21 +19,21 @@
 block discarded – undo
19 19
  */
20 20
 interface ICalendarObjectContainer extends \Sabre\DAV\ICollection
21 21
 {
22
-    /**
23
-     * Performs a calendar-query on the contents of this calendar.
24
-     *
25
-     * The calendar-query is defined in RFC4791 : CalDAV. Using the
26
-     * calendar-query it is possible for a client to request a specific set of
27
-     * object, based on contents of iCalendar properties, date-ranges and
28
-     * iCalendar component types (VTODO, VEVENT).
29
-     *
30
-     * This method should just return a list of (relative) urls that match this
31
-     * query.
32
-     *
33
-     * The list of filters are specified as an array. The exact array is
34
-     * documented by \Sabre\CalDAV\CalendarQueryParser.
35
-     *
36
-     * @return array
37
-     */
38
-    public function calendarQuery(array $filters);
22
+	/**
23
+	 * Performs a calendar-query on the contents of this calendar.
24
+	 *
25
+	 * The calendar-query is defined in RFC4791 : CalDAV. Using the
26
+	 * calendar-query it is possible for a client to request a specific set of
27
+	 * object, based on contents of iCalendar properties, date-ranges and
28
+	 * iCalendar component types (VTODO, VEVENT).
29
+	 *
30
+	 * This method should just return a list of (relative) urls that match this
31
+	 * query.
32
+	 *
33
+	 * The list of filters are specified as an array. The exact array is
34
+	 * documented by \Sabre\CalDAV\CalendarQueryParser.
35
+	 *
36
+	 * @return array
37
+	 */
38
+	public function calendarQuery(array $filters);
39 39
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/CalendarObject.php 1 patch
Indentation   +207 added lines, -207 removed lines patch added patch discarded remove patch
@@ -13,211 +13,211 @@
 block discarded – undo
13 13
  */
14 14
 class CalendarObject extends \Sabre\DAV\File implements ICalendarObject, \Sabre\DAVACL\IACL
15 15
 {
16
-    use \Sabre\DAVACL\ACLTrait;
17
-
18
-    /**
19
-     * Sabre\CalDAV\Backend\BackendInterface.
20
-     *
21
-     * @var Backend\AbstractBackend
22
-     */
23
-    protected $caldavBackend;
24
-
25
-    /**
26
-     * Array with information about this CalendarObject.
27
-     *
28
-     * @var array
29
-     */
30
-    protected $objectData;
31
-
32
-    /**
33
-     * Array with information about the containing calendar.
34
-     *
35
-     * @var array
36
-     */
37
-    protected $calendarInfo;
38
-
39
-    /**
40
-     * Constructor.
41
-     *
42
-     * The following properties may be passed within $objectData:
43
-     *
44
-     *   * calendarid - This must refer to a calendarid from a caldavBackend
45
-     *   * uri - A unique uri. Only the 'basename' must be passed.
46
-     *   * calendardata (optional) - The iCalendar data
47
-     *   * etag - (optional) The etag for this object, MUST be encloded with
48
-     *            double-quotes.
49
-     *   * size - (optional) The size of the data in bytes.
50
-     *   * lastmodified - (optional) format as a unix timestamp.
51
-     *   * acl - (optional) Use this to override the default ACL for the node.
52
-     */
53
-    public function __construct(Backend\BackendInterface $caldavBackend, array $calendarInfo, array $objectData)
54
-    {
55
-        $this->caldavBackend = $caldavBackend;
56
-
57
-        if (!isset($objectData['uri'])) {
58
-            throw new \InvalidArgumentException('The objectData argument must contain an \'uri\' property');
59
-        }
60
-
61
-        $this->calendarInfo = $calendarInfo;
62
-        $this->objectData = $objectData;
63
-    }
64
-
65
-    /**
66
-     * Returns the uri for this object.
67
-     *
68
-     * @return string
69
-     */
70
-    public function getName()
71
-    {
72
-        return $this->objectData['uri'];
73
-    }
74
-
75
-    /**
76
-     * Returns the ICalendar-formatted object.
77
-     *
78
-     * @return string
79
-     */
80
-    public function get()
81
-    {
82
-        // Pre-populating the 'calendardata' is optional, if we don't have it
83
-        // already we fetch it from the backend.
84
-        if (!isset($this->objectData['calendardata'])) {
85
-            $this->objectData = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $this->objectData['uri']);
86
-        }
87
-
88
-        return $this->objectData['calendardata'];
89
-    }
90
-
91
-    /**
92
-     * Updates the ICalendar-formatted object.
93
-     *
94
-     * @param string|resource $calendarData
95
-     *
96
-     * @return string
97
-     */
98
-    public function put($calendarData)
99
-    {
100
-        if (is_resource($calendarData)) {
101
-            $calendarData = stream_get_contents($calendarData);
102
-        }
103
-        $etag = $this->caldavBackend->updateCalendarObject($this->calendarInfo['id'], $this->objectData['uri'], $calendarData);
104
-        $this->objectData['calendardata'] = $calendarData;
105
-        $this->objectData['etag'] = $etag;
106
-
107
-        return $etag;
108
-    }
109
-
110
-    /**
111
-     * Deletes the calendar object.
112
-     */
113
-    public function delete()
114
-    {
115
-        $this->caldavBackend->deleteCalendarObject($this->calendarInfo['id'], $this->objectData['uri']);
116
-    }
117
-
118
-    /**
119
-     * Returns the mime content-type.
120
-     *
121
-     * @return string
122
-     */
123
-    public function getContentType()
124
-    {
125
-        $mime = 'text/calendar; charset=utf-8';
126
-        if (isset($this->objectData['component']) && $this->objectData['component']) {
127
-            $mime .= '; component='.$this->objectData['component'];
128
-        }
129
-
130
-        return $mime;
131
-    }
132
-
133
-    /**
134
-     * Returns an ETag for this object.
135
-     *
136
-     * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
137
-     *
138
-     * @return string
139
-     */
140
-    public function getETag()
141
-    {
142
-        if (isset($this->objectData['etag'])) {
143
-            return $this->objectData['etag'];
144
-        } else {
145
-            return '"'.md5($this->get()).'"';
146
-        }
147
-    }
148
-
149
-    /**
150
-     * Returns the last modification date as a unix timestamp.
151
-     *
152
-     * @return int
153
-     */
154
-    public function getLastModified()
155
-    {
156
-        return $this->objectData['lastmodified'];
157
-    }
158
-
159
-    /**
160
-     * Returns the size of this object in bytes.
161
-     *
162
-     * @return int
163
-     */
164
-    public function getSize()
165
-    {
166
-        if (array_key_exists('size', $this->objectData)) {
167
-            return $this->objectData['size'];
168
-        } else {
169
-            return strlen($this->get());
170
-        }
171
-    }
172
-
173
-    /**
174
-     * Returns the owner principal.
175
-     *
176
-     * This must be a url to a principal, or null if there's no owner
177
-     *
178
-     * @return string|null
179
-     */
180
-    public function getOwner()
181
-    {
182
-        return $this->calendarInfo['principaluri'];
183
-    }
184
-
185
-    /**
186
-     * Returns a list of ACE's for this node.
187
-     *
188
-     * Each ACE has the following properties:
189
-     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
190
-     *     currently the only supported privileges
191
-     *   * 'principal', a url to the principal who owns the node
192
-     *   * 'protected' (optional), indicating that this ACE is not allowed to
193
-     *      be updated.
194
-     *
195
-     * @return array
196
-     */
197
-    public function getACL()
198
-    {
199
-        // An alternative acl may be specified in the object data.
200
-        if (isset($this->objectData['acl'])) {
201
-            return $this->objectData['acl'];
202
-        }
203
-
204
-        // The default ACL
205
-        return [
206
-            [
207
-                'privilege' => '{DAV:}all',
208
-                'principal' => $this->calendarInfo['principaluri'],
209
-                'protected' => true,
210
-            ],
211
-            [
212
-                'privilege' => '{DAV:}all',
213
-                'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
214
-                'protected' => true,
215
-            ],
216
-            [
217
-                'privilege' => '{DAV:}read',
218
-                'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read',
219
-                'protected' => true,
220
-            ],
221
-        ];
222
-    }
16
+	use \Sabre\DAVACL\ACLTrait;
17
+
18
+	/**
19
+	 * Sabre\CalDAV\Backend\BackendInterface.
20
+	 *
21
+	 * @var Backend\AbstractBackend
22
+	 */
23
+	protected $caldavBackend;
24
+
25
+	/**
26
+	 * Array with information about this CalendarObject.
27
+	 *
28
+	 * @var array
29
+	 */
30
+	protected $objectData;
31
+
32
+	/**
33
+	 * Array with information about the containing calendar.
34
+	 *
35
+	 * @var array
36
+	 */
37
+	protected $calendarInfo;
38
+
39
+	/**
40
+	 * Constructor.
41
+	 *
42
+	 * The following properties may be passed within $objectData:
43
+	 *
44
+	 *   * calendarid - This must refer to a calendarid from a caldavBackend
45
+	 *   * uri - A unique uri. Only the 'basename' must be passed.
46
+	 *   * calendardata (optional) - The iCalendar data
47
+	 *   * etag - (optional) The etag for this object, MUST be encloded with
48
+	 *            double-quotes.
49
+	 *   * size - (optional) The size of the data in bytes.
50
+	 *   * lastmodified - (optional) format as a unix timestamp.
51
+	 *   * acl - (optional) Use this to override the default ACL for the node.
52
+	 */
53
+	public function __construct(Backend\BackendInterface $caldavBackend, array $calendarInfo, array $objectData)
54
+	{
55
+		$this->caldavBackend = $caldavBackend;
56
+
57
+		if (!isset($objectData['uri'])) {
58
+			throw new \InvalidArgumentException('The objectData argument must contain an \'uri\' property');
59
+		}
60
+
61
+		$this->calendarInfo = $calendarInfo;
62
+		$this->objectData = $objectData;
63
+	}
64
+
65
+	/**
66
+	 * Returns the uri for this object.
67
+	 *
68
+	 * @return string
69
+	 */
70
+	public function getName()
71
+	{
72
+		return $this->objectData['uri'];
73
+	}
74
+
75
+	/**
76
+	 * Returns the ICalendar-formatted object.
77
+	 *
78
+	 * @return string
79
+	 */
80
+	public function get()
81
+	{
82
+		// Pre-populating the 'calendardata' is optional, if we don't have it
83
+		// already we fetch it from the backend.
84
+		if (!isset($this->objectData['calendardata'])) {
85
+			$this->objectData = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $this->objectData['uri']);
86
+		}
87
+
88
+		return $this->objectData['calendardata'];
89
+	}
90
+
91
+	/**
92
+	 * Updates the ICalendar-formatted object.
93
+	 *
94
+	 * @param string|resource $calendarData
95
+	 *
96
+	 * @return string
97
+	 */
98
+	public function put($calendarData)
99
+	{
100
+		if (is_resource($calendarData)) {
101
+			$calendarData = stream_get_contents($calendarData);
102
+		}
103
+		$etag = $this->caldavBackend->updateCalendarObject($this->calendarInfo['id'], $this->objectData['uri'], $calendarData);
104
+		$this->objectData['calendardata'] = $calendarData;
105
+		$this->objectData['etag'] = $etag;
106
+
107
+		return $etag;
108
+	}
109
+
110
+	/**
111
+	 * Deletes the calendar object.
112
+	 */
113
+	public function delete()
114
+	{
115
+		$this->caldavBackend->deleteCalendarObject($this->calendarInfo['id'], $this->objectData['uri']);
116
+	}
117
+
118
+	/**
119
+	 * Returns the mime content-type.
120
+	 *
121
+	 * @return string
122
+	 */
123
+	public function getContentType()
124
+	{
125
+		$mime = 'text/calendar; charset=utf-8';
126
+		if (isset($this->objectData['component']) && $this->objectData['component']) {
127
+			$mime .= '; component='.$this->objectData['component'];
128
+		}
129
+
130
+		return $mime;
131
+	}
132
+
133
+	/**
134
+	 * Returns an ETag for this object.
135
+	 *
136
+	 * The ETag is an arbitrary string, but MUST be surrounded by double-quotes.
137
+	 *
138
+	 * @return string
139
+	 */
140
+	public function getETag()
141
+	{
142
+		if (isset($this->objectData['etag'])) {
143
+			return $this->objectData['etag'];
144
+		} else {
145
+			return '"'.md5($this->get()).'"';
146
+		}
147
+	}
148
+
149
+	/**
150
+	 * Returns the last modification date as a unix timestamp.
151
+	 *
152
+	 * @return int
153
+	 */
154
+	public function getLastModified()
155
+	{
156
+		return $this->objectData['lastmodified'];
157
+	}
158
+
159
+	/**
160
+	 * Returns the size of this object in bytes.
161
+	 *
162
+	 * @return int
163
+	 */
164
+	public function getSize()
165
+	{
166
+		if (array_key_exists('size', $this->objectData)) {
167
+			return $this->objectData['size'];
168
+		} else {
169
+			return strlen($this->get());
170
+		}
171
+	}
172
+
173
+	/**
174
+	 * Returns the owner principal.
175
+	 *
176
+	 * This must be a url to a principal, or null if there's no owner
177
+	 *
178
+	 * @return string|null
179
+	 */
180
+	public function getOwner()
181
+	{
182
+		return $this->calendarInfo['principaluri'];
183
+	}
184
+
185
+	/**
186
+	 * Returns a list of ACE's for this node.
187
+	 *
188
+	 * Each ACE has the following properties:
189
+	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
190
+	 *     currently the only supported privileges
191
+	 *   * 'principal', a url to the principal who owns the node
192
+	 *   * 'protected' (optional), indicating that this ACE is not allowed to
193
+	 *      be updated.
194
+	 *
195
+	 * @return array
196
+	 */
197
+	public function getACL()
198
+	{
199
+		// An alternative acl may be specified in the object data.
200
+		if (isset($this->objectData['acl'])) {
201
+			return $this->objectData['acl'];
202
+		}
203
+
204
+		// The default ACL
205
+		return [
206
+			[
207
+				'privilege' => '{DAV:}all',
208
+				'principal' => $this->calendarInfo['principaluri'],
209
+				'protected' => true,
210
+			],
211
+			[
212
+				'privilege' => '{DAV:}all',
213
+				'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-write',
214
+				'protected' => true,
215
+			],
216
+			[
217
+				'privilege' => '{DAV:}read',
218
+				'principal' => $this->calendarInfo['principaluri'].'/calendar-proxy-read',
219
+				'protected' => true,
220
+			],
221
+		];
222
+	}
223 223
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/ISharedCalendar.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -15,13 +15,13 @@
 block discarded – undo
15 15
  */
16 16
 interface ISharedCalendar extends ISharedNode
17 17
 {
18
-    /**
19
-     * Marks this calendar as published.
20
-     *
21
-     * Publishing a calendar should automatically create a read-only, public,
22
-     * subscribable calendar.
23
-     *
24
-     * @param bool $value
25
-     */
26
-    public function setPublishStatus($value);
18
+	/**
19
+	 * Marks this calendar as published.
20
+	 *
21
+	 * Publishing a calendar should automatically create a read-only, public,
22
+	 * subscribable calendar.
23
+	 *
24
+	 * @param bool $value
25
+	 */
26
+	public function setPublishStatus($value);
27 27
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Schedule/Outbox.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -21,99 +21,99 @@
 block discarded – undo
21 21
  */
22 22
 class Outbox extends DAV\Collection implements IOutbox
23 23
 {
24
-    use DAVACL\ACLTrait;
24
+	use DAVACL\ACLTrait;
25 25
 
26
-    /**
27
-     * The principal Uri.
28
-     *
29
-     * @var string
30
-     */
31
-    protected $principalUri;
26
+	/**
27
+	 * The principal Uri.
28
+	 *
29
+	 * @var string
30
+	 */
31
+	protected $principalUri;
32 32
 
33
-    /**
34
-     * Constructor.
35
-     *
36
-     * @param string $principalUri
37
-     */
38
-    public function __construct($principalUri)
39
-    {
40
-        $this->principalUri = $principalUri;
41
-    }
33
+	/**
34
+	 * Constructor.
35
+	 *
36
+	 * @param string $principalUri
37
+	 */
38
+	public function __construct($principalUri)
39
+	{
40
+		$this->principalUri = $principalUri;
41
+	}
42 42
 
43
-    /**
44
-     * Returns the name of the node.
45
-     *
46
-     * This is used to generate the url.
47
-     *
48
-     * @return string
49
-     */
50
-    public function getName()
51
-    {
52
-        return 'outbox';
53
-    }
43
+	/**
44
+	 * Returns the name of the node.
45
+	 *
46
+	 * This is used to generate the url.
47
+	 *
48
+	 * @return string
49
+	 */
50
+	public function getName()
51
+	{
52
+		return 'outbox';
53
+	}
54 54
 
55
-    /**
56
-     * Returns an array with all the child nodes.
57
-     *
58
-     * @return \Sabre\DAV\INode[]
59
-     */
60
-    public function getChildren()
61
-    {
62
-        return [];
63
-    }
55
+	/**
56
+	 * Returns an array with all the child nodes.
57
+	 *
58
+	 * @return \Sabre\DAV\INode[]
59
+	 */
60
+	public function getChildren()
61
+	{
62
+		return [];
63
+	}
64 64
 
65
-    /**
66
-     * Returns the owner principal.
67
-     *
68
-     * This must be a url to a principal, or null if there's no owner
69
-     *
70
-     * @return string|null
71
-     */
72
-    public function getOwner()
73
-    {
74
-        return $this->principalUri;
75
-    }
65
+	/**
66
+	 * Returns the owner principal.
67
+	 *
68
+	 * This must be a url to a principal, or null if there's no owner
69
+	 *
70
+	 * @return string|null
71
+	 */
72
+	public function getOwner()
73
+	{
74
+		return $this->principalUri;
75
+	}
76 76
 
77
-    /**
78
-     * Returns a list of ACE's for this node.
79
-     *
80
-     * Each ACE has the following properties:
81
-     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
82
-     *     currently the only supported privileges
83
-     *   * 'principal', a url to the principal who owns the node
84
-     *   * 'protected' (optional), indicating that this ACE is not allowed to
85
-     *      be updated.
86
-     *
87
-     * @return array
88
-     */
89
-    public function getACL()
90
-    {
91
-        return [
92
-            [
93
-                'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
94
-                'principal' => $this->getOwner(),
95
-                'protected' => true,
96
-            ],
97
-            [
98
-                'privilege' => '{DAV:}read',
99
-                'principal' => $this->getOwner(),
100
-                'protected' => true,
101
-            ],
102
-            [
103
-                'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
104
-                'principal' => $this->getOwner().'/calendar-proxy-write',
105
-                'protected' => true,
106
-            ],
107
-            [
108
-                'privilege' => '{DAV:}read',
109
-                'principal' => $this->getOwner().'/calendar-proxy-read',
110
-                'protected' => true,
111
-            ],
112
-            [
113
-                'privilege' => '{DAV:}read',
114
-                'principal' => $this->getOwner().'/calendar-proxy-write',
115
-                'protected' => true,
116
-            ],
117
-        ];
118
-    }
77
+	/**
78
+	 * Returns a list of ACE's for this node.
79
+	 *
80
+	 * Each ACE has the following properties:
81
+	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
82
+	 *     currently the only supported privileges
83
+	 *   * 'principal', a url to the principal who owns the node
84
+	 *   * 'protected' (optional), indicating that this ACE is not allowed to
85
+	 *      be updated.
86
+	 *
87
+	 * @return array
88
+	 */
89
+	public function getACL()
90
+	{
91
+		return [
92
+			[
93
+				'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
94
+				'principal' => $this->getOwner(),
95
+				'protected' => true,
96
+			],
97
+			[
98
+				'privilege' => '{DAV:}read',
99
+				'principal' => $this->getOwner(),
100
+				'protected' => true,
101
+			],
102
+			[
103
+				'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-send',
104
+				'principal' => $this->getOwner().'/calendar-proxy-write',
105
+				'protected' => true,
106
+			],
107
+			[
108
+				'privilege' => '{DAV:}read',
109
+				'principal' => $this->getOwner().'/calendar-proxy-read',
110
+				'protected' => true,
111
+			],
112
+			[
113
+				'privilege' => '{DAV:}read',
114
+				'principal' => $this->getOwner().'/calendar-proxy-write',
115
+				'protected' => true,
116
+			],
117
+		];
118
+	}
119 119
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Schedule/Plugin.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
             $principalUrl = $node->getPrincipalUrl();
199 199
 
200 200
             // schedule-outbox-URL property
201
-            $propFind->handle('{'.self::NS_CALDAV.'}schedule-outbox-URL', function () use ($principalUrl, $caldavPlugin) {
201
+            $propFind->handle('{'.self::NS_CALDAV.'}schedule-outbox-URL', function() use ($principalUrl, $caldavPlugin) {
202 202
                 $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
203 203
                 if (!$calendarHomePath) {
204 204
                     return null;
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 return new LocalHref($outboxPath);
209 209
             });
210 210
             // schedule-inbox-URL property
211
-            $propFind->handle('{'.self::NS_CALDAV.'}schedule-inbox-URL', function () use ($principalUrl, $caldavPlugin) {
211
+            $propFind->handle('{'.self::NS_CALDAV.'}schedule-inbox-URL', function() use ($principalUrl, $caldavPlugin) {
212 212
                 $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
213 213
                 if (!$calendarHomePath) {
214 214
                     return null;
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
                 return new LocalHref($inboxPath);
219 219
             });
220 220
 
221
-            $propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function () use ($principalUrl, $caldavPlugin) {
221
+            $propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function() use ($principalUrl, $caldavPlugin) {
222 222
                 // We don't support customizing this property yet, so in the
223 223
                 // meantime we just grab the first calendar in the home-set.
224 224
                 $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
@@ -258,13 +258,13 @@  discard block
 block discarded – undo
258 258
 
259 259
             // The server currently reports every principal to be of type
260 260
             // 'INDIVIDUAL'
261
-            $propFind->handle('{'.self::NS_CALDAV.'}calendar-user-type', function () {
261
+            $propFind->handle('{'.self::NS_CALDAV.'}calendar-user-type', function() {
262 262
                 return 'INDIVIDUAL';
263 263
             });
264 264
         }
265 265
 
266 266
         // Mapping the old property to the new property.
267
-        $propFind->handle('{http://calendarserver.org/ns/}calendar-availability', function () use ($propFind, $node) {
267
+        $propFind->handle('{http://calendarserver.org/ns/}calendar-availability', function() use ($propFind, $node) {
268 268
             // In case it wasn't clear, the only difference is that we map the
269 269
             // old property to a different namespace.
270 270
             $availProp = '{'.self::NS_CALDAV.'}calendar-availability';
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
     public function propPatch($path, PropPatch $propPatch)
295 295
     {
296 296
         // Mapping the old property to the new property.
297
-        $propPatch->handle('{http://calendarserver.org/ns/}calendar-availability', function ($value) use ($path) {
297
+        $propPatch->handle('{http://calendarserver.org/ns/}calendar-availability', function($value) use ($path) {
298 298
             $availProp = '{'.self::NS_CALDAV.'}calendar-availability';
299 299
             $subPropPatch = new PropPatch([$availProp => $value]);
300 300
             $this->server->emit('propPatch', [$path, $subPropPatch]);
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
                 'time-range' => null,
920 920
             ]);
921 921
 
922
-            $calObjects = array_map(function ($url) use ($node) {
922
+            $calObjects = array_map(function($url) use ($node) {
923 923
                 $obj = $node->getChild($url)->get();
924 924
 
925 925
                 return $obj;
Please login to merge, or discard this patch.
Indentation   +931 added lines, -931 removed lines patch added patch discarded remove patch
@@ -57,941 +57,941 @@
 block discarded – undo
57 57
  */
58 58
 class Plugin extends ServerPlugin
59 59
 {
60
-    /**
61
-     * This is the official CalDAV namespace.
62
-     */
63
-    const NS_CALDAV = 'urn:ietf:params:xml:ns:caldav';
64
-
65
-    /**
66
-     * Reference to main Server object.
67
-     *
68
-     * @var Server
69
-     */
70
-    protected $server;
71
-
72
-    /**
73
-     * Returns a list of features for the DAV: HTTP header.
74
-     *
75
-     * @return array
76
-     */
77
-    public function getFeatures()
78
-    {
79
-        return ['calendar-auto-schedule', 'calendar-availability'];
80
-    }
81
-
82
-    /**
83
-     * Returns the name of the plugin.
84
-     *
85
-     * Using this name other plugins will be able to access other plugins
86
-     * using Server::getPlugin
87
-     *
88
-     * @return string
89
-     */
90
-    public function getPluginName()
91
-    {
92
-        return 'caldav-schedule';
93
-    }
94
-
95
-    /**
96
-     * Initializes the plugin.
97
-     */
98
-    public function initialize(Server $server)
99
-    {
100
-        $this->server = $server;
101
-        $server->on('method:POST', [$this, 'httpPost']);
102
-        $server->on('propFind', [$this, 'propFind']);
103
-        $server->on('propPatch', [$this, 'propPatch']);
104
-        $server->on('calendarObjectChange', [$this, 'calendarObjectChange']);
105
-        $server->on('beforeUnbind', [$this, 'beforeUnbind']);
106
-        $server->on('schedule', [$this, 'scheduleLocalDelivery']);
107
-        $server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);
108
-
109
-        $ns = '{'.self::NS_CALDAV.'}';
110
-
111
-        /*
60
+	/**
61
+	 * This is the official CalDAV namespace.
62
+	 */
63
+	const NS_CALDAV = 'urn:ietf:params:xml:ns:caldav';
64
+
65
+	/**
66
+	 * Reference to main Server object.
67
+	 *
68
+	 * @var Server
69
+	 */
70
+	protected $server;
71
+
72
+	/**
73
+	 * Returns a list of features for the DAV: HTTP header.
74
+	 *
75
+	 * @return array
76
+	 */
77
+	public function getFeatures()
78
+	{
79
+		return ['calendar-auto-schedule', 'calendar-availability'];
80
+	}
81
+
82
+	/**
83
+	 * Returns the name of the plugin.
84
+	 *
85
+	 * Using this name other plugins will be able to access other plugins
86
+	 * using Server::getPlugin
87
+	 *
88
+	 * @return string
89
+	 */
90
+	public function getPluginName()
91
+	{
92
+		return 'caldav-schedule';
93
+	}
94
+
95
+	/**
96
+	 * Initializes the plugin.
97
+	 */
98
+	public function initialize(Server $server)
99
+	{
100
+		$this->server = $server;
101
+		$server->on('method:POST', [$this, 'httpPost']);
102
+		$server->on('propFind', [$this, 'propFind']);
103
+		$server->on('propPatch', [$this, 'propPatch']);
104
+		$server->on('calendarObjectChange', [$this, 'calendarObjectChange']);
105
+		$server->on('beforeUnbind', [$this, 'beforeUnbind']);
106
+		$server->on('schedule', [$this, 'scheduleLocalDelivery']);
107
+		$server->on('getSupportedPrivilegeSet', [$this, 'getSupportedPrivilegeSet']);
108
+
109
+		$ns = '{'.self::NS_CALDAV.'}';
110
+
111
+		/*
112 112
          * This information ensures that the {DAV:}resourcetype property has
113 113
          * the correct values.
114 114
          */
115
-        $server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IOutbox'] = $ns.'schedule-outbox';
116
-        $server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IInbox'] = $ns.'schedule-inbox';
115
+		$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IOutbox'] = $ns.'schedule-outbox';
116
+		$server->resourceTypeMapping['\\Sabre\\CalDAV\\Schedule\\IInbox'] = $ns.'schedule-inbox';
117 117
 
118
-        /*
118
+		/*
119 119
          * Properties we protect are made read-only by the server.
120 120
          */
121
-        array_push($server->protectedProperties,
122
-            $ns.'schedule-inbox-URL',
123
-            $ns.'schedule-outbox-URL',
124
-            $ns.'calendar-user-address-set',
125
-            $ns.'calendar-user-type',
126
-            $ns.'schedule-default-calendar-URL'
127
-        );
128
-    }
129
-
130
-    /**
131
-     * Use this method to tell the server this plugin defines additional
132
-     * HTTP methods.
133
-     *
134
-     * This method is passed a uri. It should only return HTTP methods that are
135
-     * available for the specified uri.
136
-     *
137
-     * @param string $uri
138
-     *
139
-     * @return array
140
-     */
141
-    public function getHTTPMethods($uri)
142
-    {
143
-        try {
144
-            $node = $this->server->tree->getNodeForPath($uri);
145
-        } catch (NotFound $e) {
146
-            return [];
147
-        }
148
-
149
-        if ($node instanceof IOutbox) {
150
-            return ['POST'];
151
-        }
152
-
153
-        return [];
154
-    }
155
-
156
-    /**
157
-     * This method handles POST request for the outbox.
158
-     *
159
-     * @return bool
160
-     */
161
-    public function httpPost(RequestInterface $request, ResponseInterface $response)
162
-    {
163
-        // Checking if this is a text/calendar content type
164
-        $contentType = $request->getHeader('Content-Type');
165
-        if (!$contentType || 0 !== strpos($contentType, 'text/calendar')) {
166
-            return;
167
-        }
168
-
169
-        $path = $request->getPath();
170
-
171
-        // Checking if we're talking to an outbox
172
-        try {
173
-            $node = $this->server->tree->getNodeForPath($path);
174
-        } catch (NotFound $e) {
175
-            return;
176
-        }
177
-        if (!$node instanceof IOutbox) {
178
-            return;
179
-        }
180
-
181
-        $this->server->transactionType = 'post-caldav-outbox';
182
-        $this->outboxRequest($node, $request, $response);
183
-
184
-        // Returning false breaks the event chain and tells the server we've
185
-        // handled the request.
186
-        return false;
187
-    }
188
-
189
-    /**
190
-     * This method handler is invoked during fetching of properties.
191
-     *
192
-     * We use this event to add calendar-auto-schedule-specific properties.
193
-     */
194
-    public function propFind(PropFind $propFind, INode $node)
195
-    {
196
-        if ($node instanceof DAVACL\IPrincipal) {
197
-            $caldavPlugin = $this->server->getPlugin('caldav');
198
-            $principalUrl = $node->getPrincipalUrl();
199
-
200
-            // schedule-outbox-URL property
201
-            $propFind->handle('{'.self::NS_CALDAV.'}schedule-outbox-URL', function () use ($principalUrl, $caldavPlugin) {
202
-                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
203
-                if (!$calendarHomePath) {
204
-                    return null;
205
-                }
206
-                $outboxPath = $calendarHomePath.'/outbox/';
207
-
208
-                return new LocalHref($outboxPath);
209
-            });
210
-            // schedule-inbox-URL property
211
-            $propFind->handle('{'.self::NS_CALDAV.'}schedule-inbox-URL', function () use ($principalUrl, $caldavPlugin) {
212
-                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
213
-                if (!$calendarHomePath) {
214
-                    return null;
215
-                }
216
-                $inboxPath = $calendarHomePath.'/inbox/';
217
-
218
-                return new LocalHref($inboxPath);
219
-            });
220
-
221
-            $propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function () use ($principalUrl, $caldavPlugin) {
222
-                // We don't support customizing this property yet, so in the
223
-                // meantime we just grab the first calendar in the home-set.
224
-                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
225
-
226
-                if (!$calendarHomePath) {
227
-                    return null;
228
-                }
229
-
230
-                $sccs = '{'.self::NS_CALDAV.'}supported-calendar-component-set';
231
-
232
-                $result = $this->server->getPropertiesForPath($calendarHomePath, [
233
-                    '{DAV:}resourcetype',
234
-                    '{DAV:}share-access',
235
-                    $sccs,
236
-                ], 1);
237
-
238
-                foreach ($result as $child) {
239
-                    if (!isset($child[200]['{DAV:}resourcetype']) || !$child[200]['{DAV:}resourcetype']->is('{'.self::NS_CALDAV.'}calendar')) {
240
-                        // Node is either not a calendar
241
-                        continue;
242
-                    }
243
-                    if (isset($child[200]['{DAV:}share-access'])) {
244
-                        $shareAccess = $child[200]['{DAV:}share-access']->getValue();
245
-                        if (Sharing\Plugin::ACCESS_NOTSHARED !== $shareAccess && Sharing\Plugin::ACCESS_SHAREDOWNER !== $shareAccess) {
246
-                            // Node is a shared node, not owned by the relevant
247
-                            // user.
248
-                            continue;
249
-                        }
250
-                    }
251
-                    if (!isset($child[200][$sccs]) || in_array('VEVENT', $child[200][$sccs]->getValue())) {
252
-                        // Either there is no supported-calendar-component-set
253
-                        // (which is fine) or we found one that supports VEVENT.
254
-                        return new LocalHref($child['href']);
255
-                    }
256
-                }
257
-            });
258
-
259
-            // The server currently reports every principal to be of type
260
-            // 'INDIVIDUAL'
261
-            $propFind->handle('{'.self::NS_CALDAV.'}calendar-user-type', function () {
262
-                return 'INDIVIDUAL';
263
-            });
264
-        }
265
-
266
-        // Mapping the old property to the new property.
267
-        $propFind->handle('{http://calendarserver.org/ns/}calendar-availability', function () use ($propFind, $node) {
268
-            // In case it wasn't clear, the only difference is that we map the
269
-            // old property to a different namespace.
270
-            $availProp = '{'.self::NS_CALDAV.'}calendar-availability';
271
-            $subPropFind = new PropFind(
272
-                 $propFind->getPath(),
273
-                 [$availProp]
274
-             );
275
-
276
-            $this->server->getPropertiesByNode(
277
-                 $subPropFind,
278
-                 $node
279
-             );
280
-
281
-            $propFind->set(
282
-                 '{http://calendarserver.org/ns/}calendar-availability',
283
-                 $subPropFind->get($availProp),
284
-                 $subPropFind->getStatus($availProp)
285
-             );
286
-        });
287
-    }
288
-
289
-    /**
290
-     * This method is called during property updates.
291
-     *
292
-     * @param string $path
293
-     */
294
-    public function propPatch($path, PropPatch $propPatch)
295
-    {
296
-        // Mapping the old property to the new property.
297
-        $propPatch->handle('{http://calendarserver.org/ns/}calendar-availability', function ($value) use ($path) {
298
-            $availProp = '{'.self::NS_CALDAV.'}calendar-availability';
299
-            $subPropPatch = new PropPatch([$availProp => $value]);
300
-            $this->server->emit('propPatch', [$path, $subPropPatch]);
301
-            $subPropPatch->commit();
302
-
303
-            return $subPropPatch->getResult()[$availProp];
304
-        });
305
-    }
306
-
307
-    /**
308
-     * This method is triggered whenever there was a calendar object gets
309
-     * created or updated.
310
-     *
311
-     * @param RequestInterface  $request      HTTP request
312
-     * @param ResponseInterface $response     HTTP Response
313
-     * @param VCalendar         $vCal         Parsed iCalendar object
314
-     * @param mixed             $calendarPath Path to calendar collection
315
-     * @param mixed             $modified     the iCalendar object has been touched
316
-     * @param mixed             $isNew        Whether this was a new item or we're updating one
317
-     */
318
-    public function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew)
319
-    {
320
-        if (!$this->scheduleReply($this->server->httpRequest)) {
321
-            return;
322
-        }
323
-
324
-        $calendarNode = $this->server->tree->getNodeForPath($calendarPath);
325
-
326
-        $addresses = $this->getAddressesForPrincipal(
327
-            $calendarNode->getOwner()
328
-        );
329
-
330
-        if (!$isNew) {
331
-            $node = $this->server->tree->getNodeForPath($request->getPath());
332
-            $oldObj = Reader::read($node->get());
333
-        } else {
334
-            $oldObj = null;
335
-        }
336
-
337
-        $this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
338
-
339
-        if ($oldObj) {
340
-            // Destroy circular references so PHP will GC the object.
341
-            $oldObj->destroy();
342
-        }
343
-    }
344
-
345
-    /**
346
-     * This method is responsible for delivering the ITip message.
347
-     */
348
-    public function deliver(ITip\Message $iTipMessage)
349
-    {
350
-        $this->server->emit('schedule', [$iTipMessage]);
351
-        if (!$iTipMessage->scheduleStatus) {
352
-            $iTipMessage->scheduleStatus = '5.2;There was no system capable of delivering the scheduling message';
353
-        }
354
-        // In case the change was considered 'insignificant', we are going to
355
-        // remove any error statuses, if any. See ticket #525.
356
-        list($baseCode) = explode('.', $iTipMessage->scheduleStatus);
357
-        if (!$iTipMessage->significantChange && in_array($baseCode, ['3', '5'])) {
358
-            $iTipMessage->scheduleStatus = null;
359
-        }
360
-    }
361
-
362
-    /**
363
-     * This method is triggered before a file gets deleted.
364
-     *
365
-     * We use this event to make sure that when this happens, attendees get
366
-     * cancellations, and organizers get 'DECLINED' statuses.
367
-     *
368
-     * @param string $path
369
-     */
370
-    public function beforeUnbind($path)
371
-    {
372
-        // FIXME: We shouldn't trigger this functionality when we're issuing a
373
-        // MOVE. This is a hack.
374
-        if ('MOVE' === $this->server->httpRequest->getMethod()) {
375
-            return;
376
-        }
377
-
378
-        $node = $this->server->tree->getNodeForPath($path);
379
-
380
-        if (!$node instanceof ICalendarObject || $node instanceof ISchedulingObject) {
381
-            return;
382
-        }
383
-
384
-        if (!$this->scheduleReply($this->server->httpRequest)) {
385
-            return;
386
-        }
387
-
388
-        $addresses = $this->getAddressesForPrincipal(
389
-            $node->getOwner()
390
-        );
391
-
392
-        $broker = new ITip\Broker();
393
-        $messages = $broker->parseEvent(null, $addresses, $node->get());
394
-
395
-        foreach ($messages as $message) {
396
-            $this->deliver($message);
397
-        }
398
-    }
399
-
400
-    /**
401
-     * Event handler for the 'schedule' event.
402
-     *
403
-     * This handler attempts to look at local accounts to deliver the
404
-     * scheduling object.
405
-     */
406
-    public function scheduleLocalDelivery(ITip\Message $iTipMessage)
407
-    {
408
-        $aclPlugin = $this->server->getPlugin('acl');
409
-
410
-        // Local delivery is not available if the ACL plugin is not loaded.
411
-        if (!$aclPlugin) {
412
-            return;
413
-        }
414
-
415
-        $caldavNS = '{'.self::NS_CALDAV.'}';
416
-
417
-        $principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
418
-        if (!$principalUri) {
419
-            $iTipMessage->scheduleStatus = '3.7;Could not find principal.';
420
-
421
-            return;
422
-        }
423
-
424
-        // We found a principal URL, now we need to find its inbox.
425
-        // Unfortunately we may not have sufficient privileges to find this, so
426
-        // we are temporarily turning off ACL to let this come through.
427
-        //
428
-        // Once we support PHP 5.5, this should be wrapped in a try..finally
429
-        // block so we can ensure that this privilege gets added again after.
430
-        $this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
431
-
432
-        $result = $this->server->getProperties(
433
-            $principalUri,
434
-            [
435
-                '{DAV:}principal-URL',
436
-                 $caldavNS.'calendar-home-set',
437
-                 $caldavNS.'schedule-inbox-URL',
438
-                 $caldavNS.'schedule-default-calendar-URL',
439
-                '{http://sabredav.org/ns}email-address',
440
-            ]
441
-        );
442
-
443
-        // Re-registering the ACL event
444
-        $this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
445
-
446
-        if (!isset($result[$caldavNS.'schedule-inbox-URL'])) {
447
-            $iTipMessage->scheduleStatus = '5.2;Could not find local inbox';
448
-
449
-            return;
450
-        }
451
-        if (!isset($result[$caldavNS.'calendar-home-set'])) {
452
-            $iTipMessage->scheduleStatus = '5.2;Could not locate a calendar-home-set';
453
-
454
-            return;
455
-        }
456
-        if (!isset($result[$caldavNS.'schedule-default-calendar-URL'])) {
457
-            $iTipMessage->scheduleStatus = '5.2;Could not find a schedule-default-calendar-URL property';
458
-
459
-            return;
460
-        }
461
-
462
-        $calendarPath = $result[$caldavNS.'schedule-default-calendar-URL']->getHref();
463
-        $homePath = $result[$caldavNS.'calendar-home-set']->getHref();
464
-        $inboxPath = $result[$caldavNS.'schedule-inbox-URL']->getHref();
465
-
466
-        if ('REPLY' === $iTipMessage->method) {
467
-            $privilege = 'schedule-deliver-reply';
468
-        } else {
469
-            $privilege = 'schedule-deliver-invite';
470
-        }
471
-
472
-        if (!$aclPlugin->checkPrivileges($inboxPath, $caldavNS.$privilege, DAVACL\Plugin::R_PARENT, false)) {
473
-            $iTipMessage->scheduleStatus = '3.8;insufficient privileges: '.$privilege.' is required on the recipient schedule inbox.';
474
-
475
-            return;
476
-        }
477
-
478
-        // Next, we're going to find out if the item already exits in one of
479
-        // the users' calendars.
480
-        $uid = $iTipMessage->uid;
481
-
482
-        $newFileName = 'sabredav-'.\Sabre\DAV\UUIDUtil::getUUID().'.ics';
483
-
484
-        $home = $this->server->tree->getNodeForPath($homePath);
485
-        $inbox = $this->server->tree->getNodeForPath($inboxPath);
486
-
487
-        $currentObject = null;
488
-        $objectNode = null;
489
-        $oldICalendarData = null;
490
-        $isNewNode = false;
491
-
492
-        $result = $home->getCalendarObjectByUID($uid);
493
-        if ($result) {
494
-            // There was an existing object, we need to update probably.
495
-            $objectPath = $homePath.'/'.$result;
496
-            $objectNode = $this->server->tree->getNodeForPath($objectPath);
497
-            $oldICalendarData = $objectNode->get();
498
-            $currentObject = Reader::read($oldICalendarData);
499
-        } else {
500
-            $isNewNode = true;
501
-        }
502
-
503
-        $broker = new ITip\Broker();
504
-        $newObject = $broker->processMessage($iTipMessage, $currentObject);
505
-
506
-        $inbox->createFile($newFileName, $iTipMessage->message->serialize());
507
-
508
-        if (!$newObject) {
509
-            // We received an iTip message referring to a UID that we don't
510
-            // have in any calendars yet, and processMessage did not give us a
511
-            // calendarobject back.
512
-            //
513
-            // The implication is that processMessage did not understand the
514
-            // iTip message.
515
-            $iTipMessage->scheduleStatus = '5.0;iTip message was not processed by the server, likely because we didn\'t understand it.';
516
-
517
-            return;
518
-        }
519
-
520
-        // Note that we are bypassing ACL on purpose by calling this directly.
521
-        // We may need to look a bit deeper into this later. Supporting ACL
522
-        // here would be nice.
523
-        if ($isNewNode) {
524
-            $calendar = $this->server->tree->getNodeForPath($calendarPath);
525
-            $calendar->createFile($newFileName, $newObject->serialize());
526
-        } else {
527
-            // If the message was a reply, we may have to inform other
528
-            // attendees of this attendees status. Therefore we're shooting off
529
-            // another itipMessage.
530
-            if ('REPLY' === $iTipMessage->method) {
531
-                $this->processICalendarChange(
532
-                    $oldICalendarData,
533
-                    $newObject,
534
-                    [$iTipMessage->recipient],
535
-                    [$iTipMessage->sender]
536
-                );
537
-            }
538
-            $objectNode->put($newObject->serialize());
539
-        }
540
-        $iTipMessage->scheduleStatus = '1.2;Message delivered locally';
541
-    }
542
-
543
-    /**
544
-     * This method is triggered whenever a subsystem requests the privileges
545
-     * that are supported on a particular node.
546
-     *
547
-     * We need to add a number of privileges for scheduling purposes.
548
-     */
549
-    public function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilegeSet)
550
-    {
551
-        $ns = '{'.self::NS_CALDAV.'}';
552
-        if ($node instanceof IOutbox) {
553
-            $supportedPrivilegeSet[$ns.'schedule-send'] = [
554
-                'abstract' => false,
555
-                'aggregates' => [
556
-                    $ns.'schedule-send-invite' => [
557
-                        'abstract' => false,
558
-                        'aggregates' => [],
559
-                    ],
560
-                    $ns.'schedule-send-reply' => [
561
-                        'abstract' => false,
562
-                        'aggregates' => [],
563
-                    ],
564
-                    $ns.'schedule-send-freebusy' => [
565
-                        'abstract' => false,
566
-                        'aggregates' => [],
567
-                    ],
568
-                    // Privilege from an earlier scheduling draft, but still
569
-                    // used by some clients.
570
-                    $ns.'schedule-post-vevent' => [
571
-                        'abstract' => false,
572
-                        'aggregates' => [],
573
-                    ],
574
-                ],
575
-            ];
576
-        }
577
-        if ($node instanceof IInbox) {
578
-            $supportedPrivilegeSet[$ns.'schedule-deliver'] = [
579
-                'abstract' => false,
580
-                'aggregates' => [
581
-                    $ns.'schedule-deliver-invite' => [
582
-                        'abstract' => false,
583
-                        'aggregates' => [],
584
-                    ],
585
-                    $ns.'schedule-deliver-reply' => [
586
-                        'abstract' => false,
587
-                        'aggregates' => [],
588
-                    ],
589
-                    $ns.'schedule-query-freebusy' => [
590
-                        'abstract' => false,
591
-                        'aggregates' => [],
592
-                    ],
593
-                ],
594
-            ];
595
-        }
596
-    }
597
-
598
-    /**
599
-     * This method looks at an old iCalendar object, a new iCalendar object and
600
-     * starts sending scheduling messages based on the changes.
601
-     *
602
-     * A list of addresses needs to be specified, so the system knows who made
603
-     * the update, because the behavior may be different based on if it's an
604
-     * attendee or an organizer.
605
-     *
606
-     * This method may update $newObject to add any status changes.
607
-     *
608
-     * @param VCalendar|string|null $oldObject
609
-     * @param array                 $ignore    any addresses to not send messages to
610
-     * @param bool                  $modified  a marker to indicate that the original object modified by this process
611
-     */
612
-    protected function processICalendarChange($oldObject, VCalendar $newObject, array $addresses, array $ignore = [], &$modified = false)
613
-    {
614
-        $broker = new ITip\Broker();
615
-        $messages = $broker->parseEvent($newObject, $addresses, $oldObject);
616
-
617
-        if ($messages) {
618
-            $modified = true;
619
-        }
620
-
621
-        foreach ($messages as $message) {
622
-            if (in_array($message->recipient, $ignore)) {
623
-                continue;
624
-            }
625
-
626
-            $this->deliver($message);
627
-
628
-            if (isset($newObject->VEVENT->ORGANIZER) && ($newObject->VEVENT->ORGANIZER->getNormalizedValue() === $message->recipient)) {
629
-                if ($message->scheduleStatus) {
630
-                    $newObject->VEVENT->ORGANIZER['SCHEDULE-STATUS'] = $message->getScheduleStatus();
631
-                }
632
-                unset($newObject->VEVENT->ORGANIZER['SCHEDULE-FORCE-SEND']);
633
-            } else {
634
-                if (isset($newObject->VEVENT->ATTENDEE)) {
635
-                    foreach ($newObject->VEVENT->ATTENDEE as $attendee) {
636
-                        if ($attendee->getNormalizedValue() === $message->recipient) {
637
-                            if ($message->scheduleStatus) {
638
-                                $attendee['SCHEDULE-STATUS'] = $message->getScheduleStatus();
639
-                            }
640
-                            unset($attendee['SCHEDULE-FORCE-SEND']);
641
-                            break;
642
-                        }
643
-                    }
644
-                }
645
-            }
646
-        }
647
-    }
648
-
649
-    /**
650
-     * Returns a list of addresses that are associated with a principal.
651
-     *
652
-     * @param string $principal
653
-     *
654
-     * @return array
655
-     */
656
-    protected function getAddressesForPrincipal($principal)
657
-    {
658
-        $CUAS = '{'.self::NS_CALDAV.'}calendar-user-address-set';
659
-
660
-        $properties = $this->server->getProperties(
661
-            $principal,
662
-            [$CUAS]
663
-        );
664
-
665
-        // If we can't find this information, we'll stop processing
666
-        if (!isset($properties[$CUAS])) {
667
-            return [];
668
-        }
669
-
670
-        $addresses = $properties[$CUAS]->getHrefs();
671
-
672
-        return $addresses;
673
-    }
674
-
675
-    /**
676
-     * This method handles POST requests to the schedule-outbox.
677
-     *
678
-     * Currently, two types of requests are supported:
679
-     *   * FREEBUSY requests from RFC 6638
680
-     *   * Simple iTIP messages from draft-desruisseaux-caldav-sched-04
681
-     *
682
-     * The latter is from an expired early draft of the CalDAV scheduling
683
-     * extensions, but iCal depends on a feature from that spec, so we
684
-     * implement it.
685
-     */
686
-    public function outboxRequest(IOutbox $outboxNode, RequestInterface $request, ResponseInterface $response)
687
-    {
688
-        $outboxPath = $request->getPath();
689
-
690
-        // Parsing the request body
691
-        try {
692
-            $vObject = VObject\Reader::read($request->getBody());
693
-        } catch (VObject\ParseException $e) {
694
-            throw new BadRequest('The request body must be a valid iCalendar object. Parse error: '.$e->getMessage());
695
-        }
696
-
697
-        // The incoming iCalendar object must have a METHOD property, and a
698
-        // component. The combination of both determines what type of request
699
-        // this is.
700
-        $componentType = null;
701
-        foreach ($vObject->getComponents() as $component) {
702
-            if ('VTIMEZONE' !== $component->name) {
703
-                $componentType = $component->name;
704
-                break;
705
-            }
706
-        }
707
-        if (is_null($componentType)) {
708
-            throw new BadRequest('We expected at least one VTODO, VJOURNAL, VFREEBUSY or VEVENT component');
709
-        }
710
-
711
-        // Validating the METHOD
712
-        $method = strtoupper((string) $vObject->METHOD);
713
-        if (!$method) {
714
-            throw new BadRequest('A METHOD property must be specified in iTIP messages');
715
-        }
716
-
717
-        // So we support one type of request:
718
-        //
719
-        // REQUEST with a VFREEBUSY component
720
-
721
-        $acl = $this->server->getPlugin('acl');
722
-
723
-        if ('VFREEBUSY' === $componentType && 'REQUEST' === $method) {
724
-            $acl && $acl->checkPrivileges($outboxPath, '{'.self::NS_CALDAV.'}schedule-send-freebusy');
725
-            $this->handleFreeBusyRequest($outboxNode, $vObject, $request, $response);
726
-
727
-            // Destroy circular references so PHP can GC the object.
728
-            $vObject->destroy();
729
-            unset($vObject);
730
-        } else {
731
-            throw new NotImplemented('We only support VFREEBUSY (REQUEST) on this endpoint');
732
-        }
733
-    }
734
-
735
-    /**
736
-     * This method is responsible for parsing a free-busy query request and
737
-     * returning its result in $response.
738
-     */
739
-    protected function handleFreeBusyRequest(IOutbox $outbox, VObject\Component $vObject, RequestInterface $request, ResponseInterface $response)
740
-    {
741
-        $vFreeBusy = $vObject->VFREEBUSY;
742
-        $organizer = $vFreeBusy->ORGANIZER;
743
-
744
-        $organizer = (string) $organizer;
745
-
746
-        // Validating if the organizer matches the owner of the inbox.
747
-        $owner = $outbox->getOwner();
748
-
749
-        $caldavNS = '{'.self::NS_CALDAV.'}';
750
-
751
-        $uas = $caldavNS.'calendar-user-address-set';
752
-        $props = $this->server->getProperties($owner, [$uas]);
753
-
754
-        if (empty($props[$uas]) || !in_array($organizer, $props[$uas]->getHrefs())) {
755
-            throw new Forbidden('The organizer in the request did not match any of the addresses for the owner of this inbox');
756
-        }
757
-
758
-        if (!isset($vFreeBusy->ATTENDEE)) {
759
-            throw new BadRequest('You must at least specify 1 attendee');
760
-        }
761
-
762
-        $attendees = [];
763
-        foreach ($vFreeBusy->ATTENDEE as $attendee) {
764
-            $attendees[] = (string) $attendee;
765
-        }
766
-
767
-        if (!isset($vFreeBusy->DTSTART) || !isset($vFreeBusy->DTEND)) {
768
-            throw new BadRequest('DTSTART and DTEND must both be specified');
769
-        }
770
-
771
-        $startRange = $vFreeBusy->DTSTART->getDateTime();
772
-        $endRange = $vFreeBusy->DTEND->getDateTime();
773
-
774
-        $results = [];
775
-        foreach ($attendees as $attendee) {
776
-            $results[] = $this->getFreeBusyForEmail($attendee, $startRange, $endRange, $vObject);
777
-        }
778
-
779
-        $dom = new \DOMDocument('1.0', 'utf-8');
780
-        $dom->formatOutput = true;
781
-        $scheduleResponse = $dom->createElement('cal:schedule-response');
782
-        foreach ($this->server->xml->namespaceMap as $namespace => $prefix) {
783
-            $scheduleResponse->setAttribute('xmlns:'.$prefix, $namespace);
784
-        }
785
-        $dom->appendChild($scheduleResponse);
786
-
787
-        foreach ($results as $result) {
788
-            $xresponse = $dom->createElement('cal:response');
789
-
790
-            $recipient = $dom->createElement('cal:recipient');
791
-            $recipientHref = $dom->createElement('d:href');
792
-
793
-            $recipientHref->appendChild($dom->createTextNode($result['href']));
794
-            $recipient->appendChild($recipientHref);
795
-            $xresponse->appendChild($recipient);
796
-
797
-            $reqStatus = $dom->createElement('cal:request-status');
798
-            $reqStatus->appendChild($dom->createTextNode($result['request-status']));
799
-            $xresponse->appendChild($reqStatus);
800
-
801
-            if (isset($result['calendar-data'])) {
802
-                $calendardata = $dom->createElement('cal:calendar-data');
803
-                $calendardata->appendChild($dom->createTextNode(str_replace("\r\n", "\n", $result['calendar-data']->serialize())));
804
-                $xresponse->appendChild($calendardata);
805
-            }
806
-            $scheduleResponse->appendChild($xresponse);
807
-        }
808
-
809
-        $response->setStatus(200);
810
-        $response->setHeader('Content-Type', 'application/xml');
811
-        $response->setBody($dom->saveXML());
812
-    }
813
-
814
-    /**
815
-     * Returns free-busy information for a specific address. The returned
816
-     * data is an array containing the following properties:.
817
-     *
818
-     * calendar-data : A VFREEBUSY VObject
819
-     * request-status : an iTip status code.
820
-     * href: The principal's email address, as requested
821
-     *
822
-     * The following request status codes may be returned:
823
-     *   * 2.0;description
824
-     *   * 3.7;description
825
-     *
826
-     * @param string $email address
827
-     *
828
-     * @return array
829
-     */
830
-    protected function getFreeBusyForEmail($email, \DateTimeInterface $start, \DateTimeInterface $end, VObject\Component $request)
831
-    {
832
-        $caldavNS = '{'.self::NS_CALDAV.'}';
833
-
834
-        $aclPlugin = $this->server->getPlugin('acl');
835
-        if ('mailto:' === substr($email, 0, 7)) {
836
-            $email = substr($email, 7);
837
-        }
838
-
839
-        $result = $aclPlugin->principalSearch(
840
-            ['{http://sabredav.org/ns}email-address' => $email],
841
-            [
842
-                '{DAV:}principal-URL',
843
-                $caldavNS.'calendar-home-set',
844
-                $caldavNS.'schedule-inbox-URL',
845
-                '{http://sabredav.org/ns}email-address',
846
-            ]
847
-        );
848
-
849
-        if (!count($result)) {
850
-            return [
851
-                'request-status' => '3.7;Could not find principal',
852
-                'href' => 'mailto:'.$email,
853
-            ];
854
-        }
855
-
856
-        if (!isset($result[0][200][$caldavNS.'calendar-home-set'])) {
857
-            return [
858
-                'request-status' => '3.7;No calendar-home-set property found',
859
-                'href' => 'mailto:'.$email,
860
-            ];
861
-        }
862
-        if (!isset($result[0][200][$caldavNS.'schedule-inbox-URL'])) {
863
-            return [
864
-                'request-status' => '3.7;No schedule-inbox-URL property found',
865
-                'href' => 'mailto:'.$email,
866
-            ];
867
-        }
868
-        $homeSet = $result[0][200][$caldavNS.'calendar-home-set']->getHref();
869
-        $inboxUrl = $result[0][200][$caldavNS.'schedule-inbox-URL']->getHref();
870
-
871
-        // Do we have permission?
872
-        $aclPlugin->checkPrivileges($inboxUrl, $caldavNS.'schedule-query-freebusy');
873
-
874
-        // Grabbing the calendar list
875
-        $objects = [];
876
-        $calendarTimeZone = new DateTimeZone('UTC');
877
-
878
-        foreach ($this->server->tree->getNodeForPath($homeSet)->getChildren() as $node) {
879
-            if (!$node instanceof ICalendar) {
880
-                continue;
881
-            }
882
-
883
-            $sct = $caldavNS.'schedule-calendar-transp';
884
-            $ctz = $caldavNS.'calendar-timezone';
885
-            $props = $node->getProperties([$sct, $ctz]);
886
-
887
-            if (isset($props[$sct]) && ScheduleCalendarTransp::TRANSPARENT == $props[$sct]->getValue()) {
888
-                // If a calendar is marked as 'transparent', it means we must
889
-                // ignore it for free-busy purposes.
890
-                continue;
891
-            }
892
-
893
-            if (isset($props[$ctz])) {
894
-                $vtimezoneObj = VObject\Reader::read($props[$ctz]);
895
-                $calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
896
-
897
-                // Destroy circular references so PHP can garbage collect the object.
898
-                $vtimezoneObj->destroy();
899
-            }
900
-
901
-            // Getting the list of object uris within the time-range
902
-            $urls = $node->calendarQuery([
903
-                'name' => 'VCALENDAR',
904
-                'comp-filters' => [
905
-                    [
906
-                        'name' => 'VEVENT',
907
-                        'comp-filters' => [],
908
-                        'prop-filters' => [],
909
-                        'is-not-defined' => false,
910
-                        'time-range' => [
911
-                            'start' => $start,
912
-                            'end' => $end,
913
-                        ],
914
-                    ],
915
-                ],
916
-                'prop-filters' => [],
917
-                'is-not-defined' => false,
918
-                'time-range' => null,
919
-            ]);
920
-
921
-            $calObjects = array_map(function ($url) use ($node) {
922
-                $obj = $node->getChild($url)->get();
923
-
924
-                return $obj;
925
-            }, $urls);
926
-
927
-            $objects = array_merge($objects, $calObjects);
928
-        }
929
-
930
-        $inboxProps = $this->server->getProperties(
931
-            $inboxUrl,
932
-            $caldavNS.'calendar-availability'
933
-        );
934
-
935
-        $vcalendar = new VObject\Component\VCalendar();
936
-        $vcalendar->METHOD = 'REPLY';
937
-
938
-        $generator = new VObject\FreeBusyGenerator();
939
-        $generator->setObjects($objects);
940
-        $generator->setTimeRange($start, $end);
941
-        $generator->setBaseObject($vcalendar);
942
-        $generator->setTimeZone($calendarTimeZone);
943
-
944
-        if ($inboxProps) {
945
-            $generator->setVAvailability(
946
-                VObject\Reader::read(
947
-                    $inboxProps[$caldavNS.'calendar-availability']
948
-                )
949
-            );
950
-        }
951
-
952
-        $result = $generator->getResult();
953
-
954
-        $vcalendar->VFREEBUSY->ATTENDEE = 'mailto:'.$email;
955
-        $vcalendar->VFREEBUSY->UID = (string) $request->VFREEBUSY->UID;
956
-        $vcalendar->VFREEBUSY->ORGANIZER = clone $request->VFREEBUSY->ORGANIZER;
957
-
958
-        return [
959
-            'calendar-data' => $result,
960
-            'request-status' => '2.0;Success',
961
-            'href' => 'mailto:'.$email,
962
-        ];
963
-    }
964
-
965
-    /**
966
-     * This method checks the 'Schedule-Reply' header
967
-     * and returns false if it's 'F', otherwise true.
968
-     *
969
-     * @return bool
970
-     */
971
-    protected function scheduleReply(RequestInterface $request)
972
-    {
973
-        $scheduleReply = $request->getHeader('Schedule-Reply');
974
-
975
-        return 'F' !== $scheduleReply;
976
-    }
977
-
978
-    /**
979
-     * Returns a bunch of meta-data about the plugin.
980
-     *
981
-     * Providing this information is optional, and is mainly displayed by the
982
-     * Browser plugin.
983
-     *
984
-     * The description key in the returned array may contain html and will not
985
-     * be sanitized.
986
-     *
987
-     * @return array
988
-     */
989
-    public function getPluginInfo()
990
-    {
991
-        return [
992
-            'name' => $this->getPluginName(),
993
-            'description' => 'Adds calendar-auto-schedule, as defined in rfc6638',
994
-            'link' => 'http://sabre.io/dav/scheduling/',
995
-        ];
996
-    }
121
+		array_push($server->protectedProperties,
122
+			$ns.'schedule-inbox-URL',
123
+			$ns.'schedule-outbox-URL',
124
+			$ns.'calendar-user-address-set',
125
+			$ns.'calendar-user-type',
126
+			$ns.'schedule-default-calendar-URL'
127
+		);
128
+	}
129
+
130
+	/**
131
+	 * Use this method to tell the server this plugin defines additional
132
+	 * HTTP methods.
133
+	 *
134
+	 * This method is passed a uri. It should only return HTTP methods that are
135
+	 * available for the specified uri.
136
+	 *
137
+	 * @param string $uri
138
+	 *
139
+	 * @return array
140
+	 */
141
+	public function getHTTPMethods($uri)
142
+	{
143
+		try {
144
+			$node = $this->server->tree->getNodeForPath($uri);
145
+		} catch (NotFound $e) {
146
+			return [];
147
+		}
148
+
149
+		if ($node instanceof IOutbox) {
150
+			return ['POST'];
151
+		}
152
+
153
+		return [];
154
+	}
155
+
156
+	/**
157
+	 * This method handles POST request for the outbox.
158
+	 *
159
+	 * @return bool
160
+	 */
161
+	public function httpPost(RequestInterface $request, ResponseInterface $response)
162
+	{
163
+		// Checking if this is a text/calendar content type
164
+		$contentType = $request->getHeader('Content-Type');
165
+		if (!$contentType || 0 !== strpos($contentType, 'text/calendar')) {
166
+			return;
167
+		}
168
+
169
+		$path = $request->getPath();
170
+
171
+		// Checking if we're talking to an outbox
172
+		try {
173
+			$node = $this->server->tree->getNodeForPath($path);
174
+		} catch (NotFound $e) {
175
+			return;
176
+		}
177
+		if (!$node instanceof IOutbox) {
178
+			return;
179
+		}
180
+
181
+		$this->server->transactionType = 'post-caldav-outbox';
182
+		$this->outboxRequest($node, $request, $response);
183
+
184
+		// Returning false breaks the event chain and tells the server we've
185
+		// handled the request.
186
+		return false;
187
+	}
188
+
189
+	/**
190
+	 * This method handler is invoked during fetching of properties.
191
+	 *
192
+	 * We use this event to add calendar-auto-schedule-specific properties.
193
+	 */
194
+	public function propFind(PropFind $propFind, INode $node)
195
+	{
196
+		if ($node instanceof DAVACL\IPrincipal) {
197
+			$caldavPlugin = $this->server->getPlugin('caldav');
198
+			$principalUrl = $node->getPrincipalUrl();
199
+
200
+			// schedule-outbox-URL property
201
+			$propFind->handle('{'.self::NS_CALDAV.'}schedule-outbox-URL', function () use ($principalUrl, $caldavPlugin) {
202
+				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
203
+				if (!$calendarHomePath) {
204
+					return null;
205
+				}
206
+				$outboxPath = $calendarHomePath.'/outbox/';
207
+
208
+				return new LocalHref($outboxPath);
209
+			});
210
+			// schedule-inbox-URL property
211
+			$propFind->handle('{'.self::NS_CALDAV.'}schedule-inbox-URL', function () use ($principalUrl, $caldavPlugin) {
212
+				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
213
+				if (!$calendarHomePath) {
214
+					return null;
215
+				}
216
+				$inboxPath = $calendarHomePath.'/inbox/';
217
+
218
+				return new LocalHref($inboxPath);
219
+			});
220
+
221
+			$propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function () use ($principalUrl, $caldavPlugin) {
222
+				// We don't support customizing this property yet, so in the
223
+				// meantime we just grab the first calendar in the home-set.
224
+				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
225
+
226
+				if (!$calendarHomePath) {
227
+					return null;
228
+				}
229
+
230
+				$sccs = '{'.self::NS_CALDAV.'}supported-calendar-component-set';
231
+
232
+				$result = $this->server->getPropertiesForPath($calendarHomePath, [
233
+					'{DAV:}resourcetype',
234
+					'{DAV:}share-access',
235
+					$sccs,
236
+				], 1);
237
+
238
+				foreach ($result as $child) {
239
+					if (!isset($child[200]['{DAV:}resourcetype']) || !$child[200]['{DAV:}resourcetype']->is('{'.self::NS_CALDAV.'}calendar')) {
240
+						// Node is either not a calendar
241
+						continue;
242
+					}
243
+					if (isset($child[200]['{DAV:}share-access'])) {
244
+						$shareAccess = $child[200]['{DAV:}share-access']->getValue();
245
+						if (Sharing\Plugin::ACCESS_NOTSHARED !== $shareAccess && Sharing\Plugin::ACCESS_SHAREDOWNER !== $shareAccess) {
246
+							// Node is a shared node, not owned by the relevant
247
+							// user.
248
+							continue;
249
+						}
250
+					}
251
+					if (!isset($child[200][$sccs]) || in_array('VEVENT', $child[200][$sccs]->getValue())) {
252
+						// Either there is no supported-calendar-component-set
253
+						// (which is fine) or we found one that supports VEVENT.
254
+						return new LocalHref($child['href']);
255
+					}
256
+				}
257
+			});
258
+
259
+			// The server currently reports every principal to be of type
260
+			// 'INDIVIDUAL'
261
+			$propFind->handle('{'.self::NS_CALDAV.'}calendar-user-type', function () {
262
+				return 'INDIVIDUAL';
263
+			});
264
+		}
265
+
266
+		// Mapping the old property to the new property.
267
+		$propFind->handle('{http://calendarserver.org/ns/}calendar-availability', function () use ($propFind, $node) {
268
+			// In case it wasn't clear, the only difference is that we map the
269
+			// old property to a different namespace.
270
+			$availProp = '{'.self::NS_CALDAV.'}calendar-availability';
271
+			$subPropFind = new PropFind(
272
+				 $propFind->getPath(),
273
+				 [$availProp]
274
+			 );
275
+
276
+			$this->server->getPropertiesByNode(
277
+				 $subPropFind,
278
+				 $node
279
+			 );
280
+
281
+			$propFind->set(
282
+				 '{http://calendarserver.org/ns/}calendar-availability',
283
+				 $subPropFind->get($availProp),
284
+				 $subPropFind->getStatus($availProp)
285
+			 );
286
+		});
287
+	}
288
+
289
+	/**
290
+	 * This method is called during property updates.
291
+	 *
292
+	 * @param string $path
293
+	 */
294
+	public function propPatch($path, PropPatch $propPatch)
295
+	{
296
+		// Mapping the old property to the new property.
297
+		$propPatch->handle('{http://calendarserver.org/ns/}calendar-availability', function ($value) use ($path) {
298
+			$availProp = '{'.self::NS_CALDAV.'}calendar-availability';
299
+			$subPropPatch = new PropPatch([$availProp => $value]);
300
+			$this->server->emit('propPatch', [$path, $subPropPatch]);
301
+			$subPropPatch->commit();
302
+
303
+			return $subPropPatch->getResult()[$availProp];
304
+		});
305
+	}
306
+
307
+	/**
308
+	 * This method is triggered whenever there was a calendar object gets
309
+	 * created or updated.
310
+	 *
311
+	 * @param RequestInterface  $request      HTTP request
312
+	 * @param ResponseInterface $response     HTTP Response
313
+	 * @param VCalendar         $vCal         Parsed iCalendar object
314
+	 * @param mixed             $calendarPath Path to calendar collection
315
+	 * @param mixed             $modified     the iCalendar object has been touched
316
+	 * @param mixed             $isNew        Whether this was a new item or we're updating one
317
+	 */
318
+	public function calendarObjectChange(RequestInterface $request, ResponseInterface $response, VCalendar $vCal, $calendarPath, &$modified, $isNew)
319
+	{
320
+		if (!$this->scheduleReply($this->server->httpRequest)) {
321
+			return;
322
+		}
323
+
324
+		$calendarNode = $this->server->tree->getNodeForPath($calendarPath);
325
+
326
+		$addresses = $this->getAddressesForPrincipal(
327
+			$calendarNode->getOwner()
328
+		);
329
+
330
+		if (!$isNew) {
331
+			$node = $this->server->tree->getNodeForPath($request->getPath());
332
+			$oldObj = Reader::read($node->get());
333
+		} else {
334
+			$oldObj = null;
335
+		}
336
+
337
+		$this->processICalendarChange($oldObj, $vCal, $addresses, [], $modified);
338
+
339
+		if ($oldObj) {
340
+			// Destroy circular references so PHP will GC the object.
341
+			$oldObj->destroy();
342
+		}
343
+	}
344
+
345
+	/**
346
+	 * This method is responsible for delivering the ITip message.
347
+	 */
348
+	public function deliver(ITip\Message $iTipMessage)
349
+	{
350
+		$this->server->emit('schedule', [$iTipMessage]);
351
+		if (!$iTipMessage->scheduleStatus) {
352
+			$iTipMessage->scheduleStatus = '5.2;There was no system capable of delivering the scheduling message';
353
+		}
354
+		// In case the change was considered 'insignificant', we are going to
355
+		// remove any error statuses, if any. See ticket #525.
356
+		list($baseCode) = explode('.', $iTipMessage->scheduleStatus);
357
+		if (!$iTipMessage->significantChange && in_array($baseCode, ['3', '5'])) {
358
+			$iTipMessage->scheduleStatus = null;
359
+		}
360
+	}
361
+
362
+	/**
363
+	 * This method is triggered before a file gets deleted.
364
+	 *
365
+	 * We use this event to make sure that when this happens, attendees get
366
+	 * cancellations, and organizers get 'DECLINED' statuses.
367
+	 *
368
+	 * @param string $path
369
+	 */
370
+	public function beforeUnbind($path)
371
+	{
372
+		// FIXME: We shouldn't trigger this functionality when we're issuing a
373
+		// MOVE. This is a hack.
374
+		if ('MOVE' === $this->server->httpRequest->getMethod()) {
375
+			return;
376
+		}
377
+
378
+		$node = $this->server->tree->getNodeForPath($path);
379
+
380
+		if (!$node instanceof ICalendarObject || $node instanceof ISchedulingObject) {
381
+			return;
382
+		}
383
+
384
+		if (!$this->scheduleReply($this->server->httpRequest)) {
385
+			return;
386
+		}
387
+
388
+		$addresses = $this->getAddressesForPrincipal(
389
+			$node->getOwner()
390
+		);
391
+
392
+		$broker = new ITip\Broker();
393
+		$messages = $broker->parseEvent(null, $addresses, $node->get());
394
+
395
+		foreach ($messages as $message) {
396
+			$this->deliver($message);
397
+		}
398
+	}
399
+
400
+	/**
401
+	 * Event handler for the 'schedule' event.
402
+	 *
403
+	 * This handler attempts to look at local accounts to deliver the
404
+	 * scheduling object.
405
+	 */
406
+	public function scheduleLocalDelivery(ITip\Message $iTipMessage)
407
+	{
408
+		$aclPlugin = $this->server->getPlugin('acl');
409
+
410
+		// Local delivery is not available if the ACL plugin is not loaded.
411
+		if (!$aclPlugin) {
412
+			return;
413
+		}
414
+
415
+		$caldavNS = '{'.self::NS_CALDAV.'}';
416
+
417
+		$principalUri = $aclPlugin->getPrincipalByUri($iTipMessage->recipient);
418
+		if (!$principalUri) {
419
+			$iTipMessage->scheduleStatus = '3.7;Could not find principal.';
420
+
421
+			return;
422
+		}
423
+
424
+		// We found a principal URL, now we need to find its inbox.
425
+		// Unfortunately we may not have sufficient privileges to find this, so
426
+		// we are temporarily turning off ACL to let this come through.
427
+		//
428
+		// Once we support PHP 5.5, this should be wrapped in a try..finally
429
+		// block so we can ensure that this privilege gets added again after.
430
+		$this->server->removeListener('propFind', [$aclPlugin, 'propFind']);
431
+
432
+		$result = $this->server->getProperties(
433
+			$principalUri,
434
+			[
435
+				'{DAV:}principal-URL',
436
+				 $caldavNS.'calendar-home-set',
437
+				 $caldavNS.'schedule-inbox-URL',
438
+				 $caldavNS.'schedule-default-calendar-URL',
439
+				'{http://sabredav.org/ns}email-address',
440
+			]
441
+		);
442
+
443
+		// Re-registering the ACL event
444
+		$this->server->on('propFind', [$aclPlugin, 'propFind'], 20);
445
+
446
+		if (!isset($result[$caldavNS.'schedule-inbox-URL'])) {
447
+			$iTipMessage->scheduleStatus = '5.2;Could not find local inbox';
448
+
449
+			return;
450
+		}
451
+		if (!isset($result[$caldavNS.'calendar-home-set'])) {
452
+			$iTipMessage->scheduleStatus = '5.2;Could not locate a calendar-home-set';
453
+
454
+			return;
455
+		}
456
+		if (!isset($result[$caldavNS.'schedule-default-calendar-URL'])) {
457
+			$iTipMessage->scheduleStatus = '5.2;Could not find a schedule-default-calendar-URL property';
458
+
459
+			return;
460
+		}
461
+
462
+		$calendarPath = $result[$caldavNS.'schedule-default-calendar-URL']->getHref();
463
+		$homePath = $result[$caldavNS.'calendar-home-set']->getHref();
464
+		$inboxPath = $result[$caldavNS.'schedule-inbox-URL']->getHref();
465
+
466
+		if ('REPLY' === $iTipMessage->method) {
467
+			$privilege = 'schedule-deliver-reply';
468
+		} else {
469
+			$privilege = 'schedule-deliver-invite';
470
+		}
471
+
472
+		if (!$aclPlugin->checkPrivileges($inboxPath, $caldavNS.$privilege, DAVACL\Plugin::R_PARENT, false)) {
473
+			$iTipMessage->scheduleStatus = '3.8;insufficient privileges: '.$privilege.' is required on the recipient schedule inbox.';
474
+
475
+			return;
476
+		}
477
+
478
+		// Next, we're going to find out if the item already exits in one of
479
+		// the users' calendars.
480
+		$uid = $iTipMessage->uid;
481
+
482
+		$newFileName = 'sabredav-'.\Sabre\DAV\UUIDUtil::getUUID().'.ics';
483
+
484
+		$home = $this->server->tree->getNodeForPath($homePath);
485
+		$inbox = $this->server->tree->getNodeForPath($inboxPath);
486
+
487
+		$currentObject = null;
488
+		$objectNode = null;
489
+		$oldICalendarData = null;
490
+		$isNewNode = false;
491
+
492
+		$result = $home->getCalendarObjectByUID($uid);
493
+		if ($result) {
494
+			// There was an existing object, we need to update probably.
495
+			$objectPath = $homePath.'/'.$result;
496
+			$objectNode = $this->server->tree->getNodeForPath($objectPath);
497
+			$oldICalendarData = $objectNode->get();
498
+			$currentObject = Reader::read($oldICalendarData);
499
+		} else {
500
+			$isNewNode = true;
501
+		}
502
+
503
+		$broker = new ITip\Broker();
504
+		$newObject = $broker->processMessage($iTipMessage, $currentObject);
505
+
506
+		$inbox->createFile($newFileName, $iTipMessage->message->serialize());
507
+
508
+		if (!$newObject) {
509
+			// We received an iTip message referring to a UID that we don't
510
+			// have in any calendars yet, and processMessage did not give us a
511
+			// calendarobject back.
512
+			//
513
+			// The implication is that processMessage did not understand the
514
+			// iTip message.
515
+			$iTipMessage->scheduleStatus = '5.0;iTip message was not processed by the server, likely because we didn\'t understand it.';
516
+
517
+			return;
518
+		}
519
+
520
+		// Note that we are bypassing ACL on purpose by calling this directly.
521
+		// We may need to look a bit deeper into this later. Supporting ACL
522
+		// here would be nice.
523
+		if ($isNewNode) {
524
+			$calendar = $this->server->tree->getNodeForPath($calendarPath);
525
+			$calendar->createFile($newFileName, $newObject->serialize());
526
+		} else {
527
+			// If the message was a reply, we may have to inform other
528
+			// attendees of this attendees status. Therefore we're shooting off
529
+			// another itipMessage.
530
+			if ('REPLY' === $iTipMessage->method) {
531
+				$this->processICalendarChange(
532
+					$oldICalendarData,
533
+					$newObject,
534
+					[$iTipMessage->recipient],
535
+					[$iTipMessage->sender]
536
+				);
537
+			}
538
+			$objectNode->put($newObject->serialize());
539
+		}
540
+		$iTipMessage->scheduleStatus = '1.2;Message delivered locally';
541
+	}
542
+
543
+	/**
544
+	 * This method is triggered whenever a subsystem requests the privileges
545
+	 * that are supported on a particular node.
546
+	 *
547
+	 * We need to add a number of privileges for scheduling purposes.
548
+	 */
549
+	public function getSupportedPrivilegeSet(INode $node, array &$supportedPrivilegeSet)
550
+	{
551
+		$ns = '{'.self::NS_CALDAV.'}';
552
+		if ($node instanceof IOutbox) {
553
+			$supportedPrivilegeSet[$ns.'schedule-send'] = [
554
+				'abstract' => false,
555
+				'aggregates' => [
556
+					$ns.'schedule-send-invite' => [
557
+						'abstract' => false,
558
+						'aggregates' => [],
559
+					],
560
+					$ns.'schedule-send-reply' => [
561
+						'abstract' => false,
562
+						'aggregates' => [],
563
+					],
564
+					$ns.'schedule-send-freebusy' => [
565
+						'abstract' => false,
566
+						'aggregates' => [],
567
+					],
568
+					// Privilege from an earlier scheduling draft, but still
569
+					// used by some clients.
570
+					$ns.'schedule-post-vevent' => [
571
+						'abstract' => false,
572
+						'aggregates' => [],
573
+					],
574
+				],
575
+			];
576
+		}
577
+		if ($node instanceof IInbox) {
578
+			$supportedPrivilegeSet[$ns.'schedule-deliver'] = [
579
+				'abstract' => false,
580
+				'aggregates' => [
581
+					$ns.'schedule-deliver-invite' => [
582
+						'abstract' => false,
583
+						'aggregates' => [],
584
+					],
585
+					$ns.'schedule-deliver-reply' => [
586
+						'abstract' => false,
587
+						'aggregates' => [],
588
+					],
589
+					$ns.'schedule-query-freebusy' => [
590
+						'abstract' => false,
591
+						'aggregates' => [],
592
+					],
593
+				],
594
+			];
595
+		}
596
+	}
597
+
598
+	/**
599
+	 * This method looks at an old iCalendar object, a new iCalendar object and
600
+	 * starts sending scheduling messages based on the changes.
601
+	 *
602
+	 * A list of addresses needs to be specified, so the system knows who made
603
+	 * the update, because the behavior may be different based on if it's an
604
+	 * attendee or an organizer.
605
+	 *
606
+	 * This method may update $newObject to add any status changes.
607
+	 *
608
+	 * @param VCalendar|string|null $oldObject
609
+	 * @param array                 $ignore    any addresses to not send messages to
610
+	 * @param bool                  $modified  a marker to indicate that the original object modified by this process
611
+	 */
612
+	protected function processICalendarChange($oldObject, VCalendar $newObject, array $addresses, array $ignore = [], &$modified = false)
613
+	{
614
+		$broker = new ITip\Broker();
615
+		$messages = $broker->parseEvent($newObject, $addresses, $oldObject);
616
+
617
+		if ($messages) {
618
+			$modified = true;
619
+		}
620
+
621
+		foreach ($messages as $message) {
622
+			if (in_array($message->recipient, $ignore)) {
623
+				continue;
624
+			}
625
+
626
+			$this->deliver($message);
627
+
628
+			if (isset($newObject->VEVENT->ORGANIZER) && ($newObject->VEVENT->ORGANIZER->getNormalizedValue() === $message->recipient)) {
629
+				if ($message->scheduleStatus) {
630
+					$newObject->VEVENT->ORGANIZER['SCHEDULE-STATUS'] = $message->getScheduleStatus();
631
+				}
632
+				unset($newObject->VEVENT->ORGANIZER['SCHEDULE-FORCE-SEND']);
633
+			} else {
634
+				if (isset($newObject->VEVENT->ATTENDEE)) {
635
+					foreach ($newObject->VEVENT->ATTENDEE as $attendee) {
636
+						if ($attendee->getNormalizedValue() === $message->recipient) {
637
+							if ($message->scheduleStatus) {
638
+								$attendee['SCHEDULE-STATUS'] = $message->getScheduleStatus();
639
+							}
640
+							unset($attendee['SCHEDULE-FORCE-SEND']);
641
+							break;
642
+						}
643
+					}
644
+				}
645
+			}
646
+		}
647
+	}
648
+
649
+	/**
650
+	 * Returns a list of addresses that are associated with a principal.
651
+	 *
652
+	 * @param string $principal
653
+	 *
654
+	 * @return array
655
+	 */
656
+	protected function getAddressesForPrincipal($principal)
657
+	{
658
+		$CUAS = '{'.self::NS_CALDAV.'}calendar-user-address-set';
659
+
660
+		$properties = $this->server->getProperties(
661
+			$principal,
662
+			[$CUAS]
663
+		);
664
+
665
+		// If we can't find this information, we'll stop processing
666
+		if (!isset($properties[$CUAS])) {
667
+			return [];
668
+		}
669
+
670
+		$addresses = $properties[$CUAS]->getHrefs();
671
+
672
+		return $addresses;
673
+	}
674
+
675
+	/**
676
+	 * This method handles POST requests to the schedule-outbox.
677
+	 *
678
+	 * Currently, two types of requests are supported:
679
+	 *   * FREEBUSY requests from RFC 6638
680
+	 *   * Simple iTIP messages from draft-desruisseaux-caldav-sched-04
681
+	 *
682
+	 * The latter is from an expired early draft of the CalDAV scheduling
683
+	 * extensions, but iCal depends on a feature from that spec, so we
684
+	 * implement it.
685
+	 */
686
+	public function outboxRequest(IOutbox $outboxNode, RequestInterface $request, ResponseInterface $response)
687
+	{
688
+		$outboxPath = $request->getPath();
689
+
690
+		// Parsing the request body
691
+		try {
692
+			$vObject = VObject\Reader::read($request->getBody());
693
+		} catch (VObject\ParseException $e) {
694
+			throw new BadRequest('The request body must be a valid iCalendar object. Parse error: '.$e->getMessage());
695
+		}
696
+
697
+		// The incoming iCalendar object must have a METHOD property, and a
698
+		// component. The combination of both determines what type of request
699
+		// this is.
700
+		$componentType = null;
701
+		foreach ($vObject->getComponents() as $component) {
702
+			if ('VTIMEZONE' !== $component->name) {
703
+				$componentType = $component->name;
704
+				break;
705
+			}
706
+		}
707
+		if (is_null($componentType)) {
708
+			throw new BadRequest('We expected at least one VTODO, VJOURNAL, VFREEBUSY or VEVENT component');
709
+		}
710
+
711
+		// Validating the METHOD
712
+		$method = strtoupper((string) $vObject->METHOD);
713
+		if (!$method) {
714
+			throw new BadRequest('A METHOD property must be specified in iTIP messages');
715
+		}
716
+
717
+		// So we support one type of request:
718
+		//
719
+		// REQUEST with a VFREEBUSY component
720
+
721
+		$acl = $this->server->getPlugin('acl');
722
+
723
+		if ('VFREEBUSY' === $componentType && 'REQUEST' === $method) {
724
+			$acl && $acl->checkPrivileges($outboxPath, '{'.self::NS_CALDAV.'}schedule-send-freebusy');
725
+			$this->handleFreeBusyRequest($outboxNode, $vObject, $request, $response);
726
+
727
+			// Destroy circular references so PHP can GC the object.
728
+			$vObject->destroy();
729
+			unset($vObject);
730
+		} else {
731
+			throw new NotImplemented('We only support VFREEBUSY (REQUEST) on this endpoint');
732
+		}
733
+	}
734
+
735
+	/**
736
+	 * This method is responsible for parsing a free-busy query request and
737
+	 * returning its result in $response.
738
+	 */
739
+	protected function handleFreeBusyRequest(IOutbox $outbox, VObject\Component $vObject, RequestInterface $request, ResponseInterface $response)
740
+	{
741
+		$vFreeBusy = $vObject->VFREEBUSY;
742
+		$organizer = $vFreeBusy->ORGANIZER;
743
+
744
+		$organizer = (string) $organizer;
745
+
746
+		// Validating if the organizer matches the owner of the inbox.
747
+		$owner = $outbox->getOwner();
748
+
749
+		$caldavNS = '{'.self::NS_CALDAV.'}';
750
+
751
+		$uas = $caldavNS.'calendar-user-address-set';
752
+		$props = $this->server->getProperties($owner, [$uas]);
753
+
754
+		if (empty($props[$uas]) || !in_array($organizer, $props[$uas]->getHrefs())) {
755
+			throw new Forbidden('The organizer in the request did not match any of the addresses for the owner of this inbox');
756
+		}
757
+
758
+		if (!isset($vFreeBusy->ATTENDEE)) {
759
+			throw new BadRequest('You must at least specify 1 attendee');
760
+		}
761
+
762
+		$attendees = [];
763
+		foreach ($vFreeBusy->ATTENDEE as $attendee) {
764
+			$attendees[] = (string) $attendee;
765
+		}
766
+
767
+		if (!isset($vFreeBusy->DTSTART) || !isset($vFreeBusy->DTEND)) {
768
+			throw new BadRequest('DTSTART and DTEND must both be specified');
769
+		}
770
+
771
+		$startRange = $vFreeBusy->DTSTART->getDateTime();
772
+		$endRange = $vFreeBusy->DTEND->getDateTime();
773
+
774
+		$results = [];
775
+		foreach ($attendees as $attendee) {
776
+			$results[] = $this->getFreeBusyForEmail($attendee, $startRange, $endRange, $vObject);
777
+		}
778
+
779
+		$dom = new \DOMDocument('1.0', 'utf-8');
780
+		$dom->formatOutput = true;
781
+		$scheduleResponse = $dom->createElement('cal:schedule-response');
782
+		foreach ($this->server->xml->namespaceMap as $namespace => $prefix) {
783
+			$scheduleResponse->setAttribute('xmlns:'.$prefix, $namespace);
784
+		}
785
+		$dom->appendChild($scheduleResponse);
786
+
787
+		foreach ($results as $result) {
788
+			$xresponse = $dom->createElement('cal:response');
789
+
790
+			$recipient = $dom->createElement('cal:recipient');
791
+			$recipientHref = $dom->createElement('d:href');
792
+
793
+			$recipientHref->appendChild($dom->createTextNode($result['href']));
794
+			$recipient->appendChild($recipientHref);
795
+			$xresponse->appendChild($recipient);
796
+
797
+			$reqStatus = $dom->createElement('cal:request-status');
798
+			$reqStatus->appendChild($dom->createTextNode($result['request-status']));
799
+			$xresponse->appendChild($reqStatus);
800
+
801
+			if (isset($result['calendar-data'])) {
802
+				$calendardata = $dom->createElement('cal:calendar-data');
803
+				$calendardata->appendChild($dom->createTextNode(str_replace("\r\n", "\n", $result['calendar-data']->serialize())));
804
+				$xresponse->appendChild($calendardata);
805
+			}
806
+			$scheduleResponse->appendChild($xresponse);
807
+		}
808
+
809
+		$response->setStatus(200);
810
+		$response->setHeader('Content-Type', 'application/xml');
811
+		$response->setBody($dom->saveXML());
812
+	}
813
+
814
+	/**
815
+	 * Returns free-busy information for a specific address. The returned
816
+	 * data is an array containing the following properties:.
817
+	 *
818
+	 * calendar-data : A VFREEBUSY VObject
819
+	 * request-status : an iTip status code.
820
+	 * href: The principal's email address, as requested
821
+	 *
822
+	 * The following request status codes may be returned:
823
+	 *   * 2.0;description
824
+	 *   * 3.7;description
825
+	 *
826
+	 * @param string $email address
827
+	 *
828
+	 * @return array
829
+	 */
830
+	protected function getFreeBusyForEmail($email, \DateTimeInterface $start, \DateTimeInterface $end, VObject\Component $request)
831
+	{
832
+		$caldavNS = '{'.self::NS_CALDAV.'}';
833
+
834
+		$aclPlugin = $this->server->getPlugin('acl');
835
+		if ('mailto:' === substr($email, 0, 7)) {
836
+			$email = substr($email, 7);
837
+		}
838
+
839
+		$result = $aclPlugin->principalSearch(
840
+			['{http://sabredav.org/ns}email-address' => $email],
841
+			[
842
+				'{DAV:}principal-URL',
843
+				$caldavNS.'calendar-home-set',
844
+				$caldavNS.'schedule-inbox-URL',
845
+				'{http://sabredav.org/ns}email-address',
846
+			]
847
+		);
848
+
849
+		if (!count($result)) {
850
+			return [
851
+				'request-status' => '3.7;Could not find principal',
852
+				'href' => 'mailto:'.$email,
853
+			];
854
+		}
855
+
856
+		if (!isset($result[0][200][$caldavNS.'calendar-home-set'])) {
857
+			return [
858
+				'request-status' => '3.7;No calendar-home-set property found',
859
+				'href' => 'mailto:'.$email,
860
+			];
861
+		}
862
+		if (!isset($result[0][200][$caldavNS.'schedule-inbox-URL'])) {
863
+			return [
864
+				'request-status' => '3.7;No schedule-inbox-URL property found',
865
+				'href' => 'mailto:'.$email,
866
+			];
867
+		}
868
+		$homeSet = $result[0][200][$caldavNS.'calendar-home-set']->getHref();
869
+		$inboxUrl = $result[0][200][$caldavNS.'schedule-inbox-URL']->getHref();
870
+
871
+		// Do we have permission?
872
+		$aclPlugin->checkPrivileges($inboxUrl, $caldavNS.'schedule-query-freebusy');
873
+
874
+		// Grabbing the calendar list
875
+		$objects = [];
876
+		$calendarTimeZone = new DateTimeZone('UTC');
877
+
878
+		foreach ($this->server->tree->getNodeForPath($homeSet)->getChildren() as $node) {
879
+			if (!$node instanceof ICalendar) {
880
+				continue;
881
+			}
882
+
883
+			$sct = $caldavNS.'schedule-calendar-transp';
884
+			$ctz = $caldavNS.'calendar-timezone';
885
+			$props = $node->getProperties([$sct, $ctz]);
886
+
887
+			if (isset($props[$sct]) && ScheduleCalendarTransp::TRANSPARENT == $props[$sct]->getValue()) {
888
+				// If a calendar is marked as 'transparent', it means we must
889
+				// ignore it for free-busy purposes.
890
+				continue;
891
+			}
892
+
893
+			if (isset($props[$ctz])) {
894
+				$vtimezoneObj = VObject\Reader::read($props[$ctz]);
895
+				$calendarTimeZone = $vtimezoneObj->VTIMEZONE->getTimeZone();
896
+
897
+				// Destroy circular references so PHP can garbage collect the object.
898
+				$vtimezoneObj->destroy();
899
+			}
900
+
901
+			// Getting the list of object uris within the time-range
902
+			$urls = $node->calendarQuery([
903
+				'name' => 'VCALENDAR',
904
+				'comp-filters' => [
905
+					[
906
+						'name' => 'VEVENT',
907
+						'comp-filters' => [],
908
+						'prop-filters' => [],
909
+						'is-not-defined' => false,
910
+						'time-range' => [
911
+							'start' => $start,
912
+							'end' => $end,
913
+						],
914
+					],
915
+				],
916
+				'prop-filters' => [],
917
+				'is-not-defined' => false,
918
+				'time-range' => null,
919
+			]);
920
+
921
+			$calObjects = array_map(function ($url) use ($node) {
922
+				$obj = $node->getChild($url)->get();
923
+
924
+				return $obj;
925
+			}, $urls);
926
+
927
+			$objects = array_merge($objects, $calObjects);
928
+		}
929
+
930
+		$inboxProps = $this->server->getProperties(
931
+			$inboxUrl,
932
+			$caldavNS.'calendar-availability'
933
+		);
934
+
935
+		$vcalendar = new VObject\Component\VCalendar();
936
+		$vcalendar->METHOD = 'REPLY';
937
+
938
+		$generator = new VObject\FreeBusyGenerator();
939
+		$generator->setObjects($objects);
940
+		$generator->setTimeRange($start, $end);
941
+		$generator->setBaseObject($vcalendar);
942
+		$generator->setTimeZone($calendarTimeZone);
943
+
944
+		if ($inboxProps) {
945
+			$generator->setVAvailability(
946
+				VObject\Reader::read(
947
+					$inboxProps[$caldavNS.'calendar-availability']
948
+				)
949
+			);
950
+		}
951
+
952
+		$result = $generator->getResult();
953
+
954
+		$vcalendar->VFREEBUSY->ATTENDEE = 'mailto:'.$email;
955
+		$vcalendar->VFREEBUSY->UID = (string) $request->VFREEBUSY->UID;
956
+		$vcalendar->VFREEBUSY->ORGANIZER = clone $request->VFREEBUSY->ORGANIZER;
957
+
958
+		return [
959
+			'calendar-data' => $result,
960
+			'request-status' => '2.0;Success',
961
+			'href' => 'mailto:'.$email,
962
+		];
963
+	}
964
+
965
+	/**
966
+	 * This method checks the 'Schedule-Reply' header
967
+	 * and returns false if it's 'F', otherwise true.
968
+	 *
969
+	 * @return bool
970
+	 */
971
+	protected function scheduleReply(RequestInterface $request)
972
+	{
973
+		$scheduleReply = $request->getHeader('Schedule-Reply');
974
+
975
+		return 'F' !== $scheduleReply;
976
+	}
977
+
978
+	/**
979
+	 * Returns a bunch of meta-data about the plugin.
980
+	 *
981
+	 * Providing this information is optional, and is mainly displayed by the
982
+	 * Browser plugin.
983
+	 *
984
+	 * The description key in the returned array may contain html and will not
985
+	 * be sanitized.
986
+	 *
987
+	 * @return array
988
+	 */
989
+	public function getPluginInfo()
990
+	{
991
+		return [
992
+			'name' => $this->getPluginName(),
993
+			'description' => 'Adds calendar-auto-schedule, as defined in rfc6638',
994
+			'link' => 'http://sabre.io/dav/scheduling/',
995
+		];
996
+	}
997 997
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Schedule/Inbox.php 1 patch
Indentation   +176 added lines, -176 removed lines patch added patch discarded remove patch
@@ -19,180 +19,180 @@
 block discarded – undo
19 19
  */
20 20
 class Inbox extends DAV\Collection implements IInbox
21 21
 {
22
-    use DAVACL\ACLTrait;
23
-
24
-    /**
25
-     * CalDAV backend.
26
-     *
27
-     * @var Backend\BackendInterface
28
-     */
29
-    protected $caldavBackend;
30
-
31
-    /**
32
-     * The principal Uri.
33
-     *
34
-     * @var string
35
-     */
36
-    protected $principalUri;
37
-
38
-    /**
39
-     * Constructor.
40
-     *
41
-     * @param string $principalUri
42
-     */
43
-    public function __construct(Backend\SchedulingSupport $caldavBackend, $principalUri)
44
-    {
45
-        $this->caldavBackend = $caldavBackend;
46
-        $this->principalUri = $principalUri;
47
-    }
48
-
49
-    /**
50
-     * Returns the name of the node.
51
-     *
52
-     * This is used to generate the url.
53
-     *
54
-     * @return string
55
-     */
56
-    public function getName()
57
-    {
58
-        return 'inbox';
59
-    }
60
-
61
-    /**
62
-     * Returns an array with all the child nodes.
63
-     *
64
-     * @return \Sabre\DAV\INode[]
65
-     */
66
-    public function getChildren()
67
-    {
68
-        $objs = $this->caldavBackend->getSchedulingObjects($this->principalUri);
69
-        $children = [];
70
-        foreach ($objs as $obj) {
71
-            //$obj['acl'] = $this->getACL();
72
-            $obj['principaluri'] = $this->principalUri;
73
-            $children[] = new SchedulingObject($this->caldavBackend, $obj);
74
-        }
75
-
76
-        return $children;
77
-    }
78
-
79
-    /**
80
-     * Creates a new file in the directory.
81
-     *
82
-     * Data will either be supplied as a stream resource, or in certain cases
83
-     * as a string. Keep in mind that you may have to support either.
84
-     *
85
-     * After successful creation of the file, you may choose to return the ETag
86
-     * of the new file here.
87
-     *
88
-     * The returned ETag must be surrounded by double-quotes (The quotes should
89
-     * be part of the actual string).
90
-     *
91
-     * If you cannot accurately determine the ETag, you should not return it.
92
-     * If you don't store the file exactly as-is (you're transforming it
93
-     * somehow) you should also not return an ETag.
94
-     *
95
-     * This means that if a subsequent GET to this new file does not exactly
96
-     * return the same contents of what was submitted here, you are strongly
97
-     * recommended to omit the ETag.
98
-     *
99
-     * @param string          $name Name of the file
100
-     * @param resource|string $data Initial payload
101
-     *
102
-     * @return string|null
103
-     */
104
-    public function createFile($name, $data = null)
105
-    {
106
-        $this->caldavBackend->createSchedulingObject($this->principalUri, $name, $data);
107
-    }
108
-
109
-    /**
110
-     * Returns the owner principal.
111
-     *
112
-     * This must be a url to a principal, or null if there's no owner
113
-     *
114
-     * @return string|null
115
-     */
116
-    public function getOwner()
117
-    {
118
-        return $this->principalUri;
119
-    }
120
-
121
-    /**
122
-     * Returns a list of ACE's for this node.
123
-     *
124
-     * Each ACE has the following properties:
125
-     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
126
-     *     currently the only supported privileges
127
-     *   * 'principal', a url to the principal who owns the node
128
-     *   * 'protected' (optional), indicating that this ACE is not allowed to
129
-     *      be updated.
130
-     *
131
-     * @return array
132
-     */
133
-    public function getACL()
134
-    {
135
-        return [
136
-            [
137
-                'privilege' => '{DAV:}read',
138
-                'principal' => '{DAV:}authenticated',
139
-                'protected' => true,
140
-            ],
141
-            [
142
-                'privilege' => '{DAV:}write-properties',
143
-                'principal' => $this->getOwner(),
144
-                'protected' => true,
145
-            ],
146
-            [
147
-                'privilege' => '{DAV:}unbind',
148
-                'principal' => $this->getOwner(),
149
-                'protected' => true,
150
-            ],
151
-            [
152
-                'privilege' => '{DAV:}unbind',
153
-                'principal' => $this->getOwner().'/calendar-proxy-write',
154
-                'protected' => true,
155
-            ],
156
-            [
157
-                'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-deliver',
158
-                'principal' => '{DAV:}authenticated',
159
-                'protected' => true,
160
-            ],
161
-        ];
162
-    }
163
-
164
-    /**
165
-     * Performs a calendar-query on the contents of this calendar.
166
-     *
167
-     * The calendar-query is defined in RFC4791 : CalDAV. Using the
168
-     * calendar-query it is possible for a client to request a specific set of
169
-     * object, based on contents of iCalendar properties, date-ranges and
170
-     * iCalendar component types (VTODO, VEVENT).
171
-     *
172
-     * This method should just return a list of (relative) urls that match this
173
-     * query.
174
-     *
175
-     * The list of filters are specified as an array. The exact array is
176
-     * documented by \Sabre\CalDAV\CalendarQueryParser.
177
-     *
178
-     * @return array
179
-     */
180
-    public function calendarQuery(array $filters)
181
-    {
182
-        $result = [];
183
-        $validator = new CalDAV\CalendarQueryValidator();
184
-
185
-        $objects = $this->caldavBackend->getSchedulingObjects($this->principalUri);
186
-        foreach ($objects as $object) {
187
-            $vObject = VObject\Reader::read($object['calendardata']);
188
-            if ($validator->validate($vObject, $filters)) {
189
-                $result[] = $object['uri'];
190
-            }
191
-
192
-            // Destroy circular references to PHP will GC the object.
193
-            $vObject->destroy();
194
-        }
195
-
196
-        return $result;
197
-    }
22
+	use DAVACL\ACLTrait;
23
+
24
+	/**
25
+	 * CalDAV backend.
26
+	 *
27
+	 * @var Backend\BackendInterface
28
+	 */
29
+	protected $caldavBackend;
30
+
31
+	/**
32
+	 * The principal Uri.
33
+	 *
34
+	 * @var string
35
+	 */
36
+	protected $principalUri;
37
+
38
+	/**
39
+	 * Constructor.
40
+	 *
41
+	 * @param string $principalUri
42
+	 */
43
+	public function __construct(Backend\SchedulingSupport $caldavBackend, $principalUri)
44
+	{
45
+		$this->caldavBackend = $caldavBackend;
46
+		$this->principalUri = $principalUri;
47
+	}
48
+
49
+	/**
50
+	 * Returns the name of the node.
51
+	 *
52
+	 * This is used to generate the url.
53
+	 *
54
+	 * @return string
55
+	 */
56
+	public function getName()
57
+	{
58
+		return 'inbox';
59
+	}
60
+
61
+	/**
62
+	 * Returns an array with all the child nodes.
63
+	 *
64
+	 * @return \Sabre\DAV\INode[]
65
+	 */
66
+	public function getChildren()
67
+	{
68
+		$objs = $this->caldavBackend->getSchedulingObjects($this->principalUri);
69
+		$children = [];
70
+		foreach ($objs as $obj) {
71
+			//$obj['acl'] = $this->getACL();
72
+			$obj['principaluri'] = $this->principalUri;
73
+			$children[] = new SchedulingObject($this->caldavBackend, $obj);
74
+		}
75
+
76
+		return $children;
77
+	}
78
+
79
+	/**
80
+	 * Creates a new file in the directory.
81
+	 *
82
+	 * Data will either be supplied as a stream resource, or in certain cases
83
+	 * as a string. Keep in mind that you may have to support either.
84
+	 *
85
+	 * After successful creation of the file, you may choose to return the ETag
86
+	 * of the new file here.
87
+	 *
88
+	 * The returned ETag must be surrounded by double-quotes (The quotes should
89
+	 * be part of the actual string).
90
+	 *
91
+	 * If you cannot accurately determine the ETag, you should not return it.
92
+	 * If you don't store the file exactly as-is (you're transforming it
93
+	 * somehow) you should also not return an ETag.
94
+	 *
95
+	 * This means that if a subsequent GET to this new file does not exactly
96
+	 * return the same contents of what was submitted here, you are strongly
97
+	 * recommended to omit the ETag.
98
+	 *
99
+	 * @param string          $name Name of the file
100
+	 * @param resource|string $data Initial payload
101
+	 *
102
+	 * @return string|null
103
+	 */
104
+	public function createFile($name, $data = null)
105
+	{
106
+		$this->caldavBackend->createSchedulingObject($this->principalUri, $name, $data);
107
+	}
108
+
109
+	/**
110
+	 * Returns the owner principal.
111
+	 *
112
+	 * This must be a url to a principal, or null if there's no owner
113
+	 *
114
+	 * @return string|null
115
+	 */
116
+	public function getOwner()
117
+	{
118
+		return $this->principalUri;
119
+	}
120
+
121
+	/**
122
+	 * Returns a list of ACE's for this node.
123
+	 *
124
+	 * Each ACE has the following properties:
125
+	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
126
+	 *     currently the only supported privileges
127
+	 *   * 'principal', a url to the principal who owns the node
128
+	 *   * 'protected' (optional), indicating that this ACE is not allowed to
129
+	 *      be updated.
130
+	 *
131
+	 * @return array
132
+	 */
133
+	public function getACL()
134
+	{
135
+		return [
136
+			[
137
+				'privilege' => '{DAV:}read',
138
+				'principal' => '{DAV:}authenticated',
139
+				'protected' => true,
140
+			],
141
+			[
142
+				'privilege' => '{DAV:}write-properties',
143
+				'principal' => $this->getOwner(),
144
+				'protected' => true,
145
+			],
146
+			[
147
+				'privilege' => '{DAV:}unbind',
148
+				'principal' => $this->getOwner(),
149
+				'protected' => true,
150
+			],
151
+			[
152
+				'privilege' => '{DAV:}unbind',
153
+				'principal' => $this->getOwner().'/calendar-proxy-write',
154
+				'protected' => true,
155
+			],
156
+			[
157
+				'privilege' => '{'.CalDAV\Plugin::NS_CALDAV.'}schedule-deliver',
158
+				'principal' => '{DAV:}authenticated',
159
+				'protected' => true,
160
+			],
161
+		];
162
+	}
163
+
164
+	/**
165
+	 * Performs a calendar-query on the contents of this calendar.
166
+	 *
167
+	 * The calendar-query is defined in RFC4791 : CalDAV. Using the
168
+	 * calendar-query it is possible for a client to request a specific set of
169
+	 * object, based on contents of iCalendar properties, date-ranges and
170
+	 * iCalendar component types (VTODO, VEVENT).
171
+	 *
172
+	 * This method should just return a list of (relative) urls that match this
173
+	 * query.
174
+	 *
175
+	 * The list of filters are specified as an array. The exact array is
176
+	 * documented by \Sabre\CalDAV\CalendarQueryParser.
177
+	 *
178
+	 * @return array
179
+	 */
180
+	public function calendarQuery(array $filters)
181
+	{
182
+		$result = [];
183
+		$validator = new CalDAV\CalendarQueryValidator();
184
+
185
+		$objects = $this->caldavBackend->getSchedulingObjects($this->principalUri);
186
+		foreach ($objects as $object) {
187
+			$vObject = VObject\Reader::read($object['calendardata']);
188
+			if ($validator->validate($vObject, $filters)) {
189
+				$result[] = $object['uri'];
190
+			}
191
+
192
+			// Destroy circular references to PHP will GC the object.
193
+			$vObject->destroy();
194
+		}
195
+
196
+		return $result;
197
+	}
198 198
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Schedule/SchedulingObject.php 1 patch
Indentation   +102 added lines, -102 removed lines patch added patch discarded remove patch
@@ -16,115 +16,115 @@
 block discarded – undo
16 16
  */
17 17
 class SchedulingObject extends \Sabre\CalDAV\CalendarObject implements ISchedulingObject
18 18
 {
19
-    /**
20
-     * Constructor.
21
-     *
22
-     * The following properties may be passed within $objectData:
23
-     *
24
-     *   * uri - A unique uri. Only the 'basename' must be passed.
25
-     *   * principaluri - the principal that owns the object.
26
-     *   * calendardata (optional) - The iCalendar data
27
-     *   * etag - (optional) The etag for this object, MUST be encloded with
28
-     *            double-quotes.
29
-     *   * size - (optional) The size of the data in bytes.
30
-     *   * lastmodified - (optional) format as a unix timestamp.
31
-     *   * acl - (optional) Use this to override the default ACL for the node.
32
-     */
33
-    public function __construct(Backend\SchedulingSupport $caldavBackend, array $objectData)
34
-    {
35
-        parent::__construct($caldavBackend, [], $objectData);
19
+	/**
20
+	 * Constructor.
21
+	 *
22
+	 * The following properties may be passed within $objectData:
23
+	 *
24
+	 *   * uri - A unique uri. Only the 'basename' must be passed.
25
+	 *   * principaluri - the principal that owns the object.
26
+	 *   * calendardata (optional) - The iCalendar data
27
+	 *   * etag - (optional) The etag for this object, MUST be encloded with
28
+	 *            double-quotes.
29
+	 *   * size - (optional) The size of the data in bytes.
30
+	 *   * lastmodified - (optional) format as a unix timestamp.
31
+	 *   * acl - (optional) Use this to override the default ACL for the node.
32
+	 */
33
+	public function __construct(Backend\SchedulingSupport $caldavBackend, array $objectData)
34
+	{
35
+		parent::__construct($caldavBackend, [], $objectData);
36 36
 
37
-        if (!isset($objectData['uri'])) {
38
-            throw new \InvalidArgumentException('The objectData argument must contain an \'uri\' property');
39
-        }
40
-    }
37
+		if (!isset($objectData['uri'])) {
38
+			throw new \InvalidArgumentException('The objectData argument must contain an \'uri\' property');
39
+		}
40
+	}
41 41
 
42
-    /**
43
-     * Returns the ICalendar-formatted object.
44
-     *
45
-     * @return string
46
-     */
47
-    public function get()
48
-    {
49
-        // Pre-populating the 'calendardata' is optional, if we don't have it
50
-        // already we fetch it from the backend.
51
-        if (!isset($this->objectData['calendardata'])) {
52
-            $this->objectData = $this->caldavBackend->getSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']);
53
-        }
42
+	/**
43
+	 * Returns the ICalendar-formatted object.
44
+	 *
45
+	 * @return string
46
+	 */
47
+	public function get()
48
+	{
49
+		// Pre-populating the 'calendardata' is optional, if we don't have it
50
+		// already we fetch it from the backend.
51
+		if (!isset($this->objectData['calendardata'])) {
52
+			$this->objectData = $this->caldavBackend->getSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']);
53
+		}
54 54
 
55
-        return $this->objectData['calendardata'];
56
-    }
55
+		return $this->objectData['calendardata'];
56
+	}
57 57
 
58
-    /**
59
-     * Updates the ICalendar-formatted object.
60
-     *
61
-     * @param string|resource $calendarData
62
-     *
63
-     * @return string
64
-     */
65
-    public function put($calendarData)
66
-    {
67
-        throw new MethodNotAllowed('Updating scheduling objects is not supported');
68
-    }
58
+	/**
59
+	 * Updates the ICalendar-formatted object.
60
+	 *
61
+	 * @param string|resource $calendarData
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function put($calendarData)
66
+	{
67
+		throw new MethodNotAllowed('Updating scheduling objects is not supported');
68
+	}
69 69
 
70
-    /**
71
-     * Deletes the scheduling message.
72
-     */
73
-    public function delete()
74
-    {
75
-        $this->caldavBackend->deleteSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']);
76
-    }
70
+	/**
71
+	 * Deletes the scheduling message.
72
+	 */
73
+	public function delete()
74
+	{
75
+		$this->caldavBackend->deleteSchedulingObject($this->objectData['principaluri'], $this->objectData['uri']);
76
+	}
77 77
 
78
-    /**
79
-     * Returns the owner principal.
80
-     *
81
-     * This must be a url to a principal, or null if there's no owner
82
-     *
83
-     * @return string|null
84
-     */
85
-    public function getOwner()
86
-    {
87
-        return $this->objectData['principaluri'];
88
-    }
78
+	/**
79
+	 * Returns the owner principal.
80
+	 *
81
+	 * This must be a url to a principal, or null if there's no owner
82
+	 *
83
+	 * @return string|null
84
+	 */
85
+	public function getOwner()
86
+	{
87
+		return $this->objectData['principaluri'];
88
+	}
89 89
 
90
-    /**
91
-     * Returns a list of ACE's for this node.
92
-     *
93
-     * Each ACE has the following properties:
94
-     *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
95
-     *     currently the only supported privileges
96
-     *   * 'principal', a url to the principal who owns the node
97
-     *   * 'protected' (optional), indicating that this ACE is not allowed to
98
-     *      be updated.
99
-     *
100
-     * @return array
101
-     */
102
-    public function getACL()
103
-    {
104
-        // An alternative acl may be specified in the object data.
105
-        //
90
+	/**
91
+	 * Returns a list of ACE's for this node.
92
+	 *
93
+	 * Each ACE has the following properties:
94
+	 *   * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
95
+	 *     currently the only supported privileges
96
+	 *   * 'principal', a url to the principal who owns the node
97
+	 *   * 'protected' (optional), indicating that this ACE is not allowed to
98
+	 *      be updated.
99
+	 *
100
+	 * @return array
101
+	 */
102
+	public function getACL()
103
+	{
104
+		// An alternative acl may be specified in the object data.
105
+		//
106 106
 
107
-        if (isset($this->objectData['acl'])) {
108
-            return $this->objectData['acl'];
109
-        }
107
+		if (isset($this->objectData['acl'])) {
108
+			return $this->objectData['acl'];
109
+		}
110 110
 
111
-        // The default ACL
112
-        return [
113
-            [
114
-                'privilege' => '{DAV:}all',
115
-                'principal' => '{DAV:}owner',
116
-                'protected' => true,
117
-            ],
118
-            [
119
-                'privilege' => '{DAV:}all',
120
-                'principal' => $this->objectData['principaluri'].'/calendar-proxy-write',
121
-                'protected' => true,
122
-            ],
123
-            [
124
-                'privilege' => '{DAV:}read',
125
-                'principal' => $this->objectData['principaluri'].'/calendar-proxy-read',
126
-                'protected' => true,
127
-            ],
128
-        ];
129
-    }
111
+		// The default ACL
112
+		return [
113
+			[
114
+				'privilege' => '{DAV:}all',
115
+				'principal' => '{DAV:}owner',
116
+				'protected' => true,
117
+			],
118
+			[
119
+				'privilege' => '{DAV:}all',
120
+				'principal' => $this->objectData['principaluri'].'/calendar-proxy-write',
121
+				'protected' => true,
122
+			],
123
+			[
124
+				'privilege' => '{DAV:}read',
125
+				'principal' => $this->objectData['principaluri'].'/calendar-proxy-read',
126
+				'protected' => true,
127
+			],
128
+		];
129
+	}
130 130
 }
Please login to merge, or discard this patch.