Completed
Branch develop (37f7b7)
by
unknown
24:41
created
htdocs/includes/sabre/sabre/dav/lib/CalDAV/CalendarQueryValidator.php 1 patch
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -22,333 +22,333 @@
 block discarded – undo
22 22
  */
23 23
 class CalendarQueryValidator
24 24
 {
25
-    /**
26
-     * Verify if a list of filters applies to the calendar data object.
27
-     *
28
-     * The list of filters must be formatted as parsed by \Sabre\CalDAV\CalendarQueryParser
29
-     *
30
-     * @return bool
31
-     */
32
-    public function validate(VObject\Component\VCalendar $vObject, array $filters)
33
-    {
34
-        // The top level object is always a component filter.
35
-        // We'll parse it manually, as it's pretty simple.
36
-        if ($vObject->name !== $filters['name']) {
37
-            return false;
38
-        }
39
-
40
-        return
41
-            $this->validateCompFilters($vObject, $filters['comp-filters']) &&
42
-            $this->validatePropFilters($vObject, $filters['prop-filters']);
43
-    }
44
-
45
-    /**
46
-     * This method checks the validity of comp-filters.
47
-     *
48
-     * A list of comp-filters needs to be specified. Also the parent of the
49
-     * component we're checking should be specified, not the component to check
50
-     * itself.
51
-     *
52
-     * @return bool
53
-     */
54
-    protected function validateCompFilters(VObject\Component $parent, array $filters)
55
-    {
56
-        foreach ($filters as $filter) {
57
-            $isDefined = isset($parent->{$filter['name']});
58
-
59
-            if ($filter['is-not-defined']) {
60
-                if ($isDefined) {
61
-                    return false;
62
-                } else {
63
-                    continue;
64
-                }
65
-            }
66
-            if (!$isDefined) {
67
-                return false;
68
-            }
69
-
70
-            if (array_key_exists('time-range', $filter) && $filter['time-range']) {
71
-                foreach ($parent->{$filter['name']} as $subComponent) {
72
-                    $start = null;
73
-                    $end = null;
74
-                    if (array_key_exists('start', $filter['time-range'])) {
75
-                        $start = $filter['time-range']['start'];
76
-                    }
77
-                    if (array_key_exists('end', $filter['time-range'])) {
78
-                        $end = $filter['time-range']['end'];
79
-                    }
80
-                    if ($this->validateTimeRange($subComponent, $start, $end)) {
81
-                        continue 2;
82
-                    }
83
-                }
84
-
85
-                return false;
86
-            }
87
-
88
-            if (!$filter['comp-filters'] && !$filter['prop-filters']) {
89
-                continue;
90
-            }
91
-
92
-            // If there are sub-filters, we need to find at least one component
93
-            // for which the subfilters hold true.
94
-            foreach ($parent->{$filter['name']} as $subComponent) {
95
-                if (
96
-                    $this->validateCompFilters($subComponent, $filter['comp-filters']) &&
97
-                    $this->validatePropFilters($subComponent, $filter['prop-filters'])) {
98
-                    // We had a match, so this comp-filter succeeds
99
-                    continue 2;
100
-                }
101
-            }
102
-
103
-            // If we got here it means there were sub-comp-filters or
104
-            // sub-prop-filters and there was no match. This means this filter
105
-            // needs to return false.
106
-            return false;
107
-        }
108
-
109
-        // If we got here it means we got through all comp-filters alive so the
110
-        // filters were all true.
111
-        return true;
112
-    }
113
-
114
-    /**
115
-     * This method checks the validity of prop-filters.
116
-     *
117
-     * A list of prop-filters needs to be specified. Also the parent of the
118
-     * property we're checking should be specified, not the property to check
119
-     * itself.
120
-     *
121
-     * @return bool
122
-     */
123
-    protected function validatePropFilters(VObject\Component $parent, array $filters)
124
-    {
125
-        foreach ($filters as $filter) {
126
-            $isDefined = isset($parent->{$filter['name']});
127
-
128
-            if ($filter['is-not-defined']) {
129
-                if ($isDefined) {
130
-                    return false;
131
-                } else {
132
-                    continue;
133
-                }
134
-            }
135
-            if (!$isDefined) {
136
-                return false;
137
-            }
138
-
139
-            if (array_key_exists('time-range', $filter) && $filter['time-range']) {
140
-                foreach ($parent->{$filter['name']} as $subComponent) {
141
-                    $start = null;
142
-                    $end = null;
143
-                    if (array_key_exists('start', $filter['time-range'])) {
144
-                        $start = $filter['time-range']['start'];
145
-                    }
146
-                    if (array_key_exists('end', $filter['time-range'])) {
147
-                        $end = $filter['time-range']['end'];
148
-                    }
149
-                    if ($this->validateTimeRange($subComponent, $start, $end)) {
150
-                        continue 2;
151
-                    }
152
-                }
153
-
154
-                return false;
155
-            }
156
-
157
-            if (!$filter['param-filters'] && !$filter['text-match']) {
158
-                continue;
159
-            }
160
-
161
-            // If there are sub-filters, we need to find at least one property
162
-            // for which the subfilters hold true.
163
-            foreach ($parent->{$filter['name']} as $subComponent) {
164
-                if (
165
-                    $this->validateParamFilters($subComponent, $filter['param-filters']) &&
166
-                    (!$filter['text-match'] || $this->validateTextMatch($subComponent, $filter['text-match']))
167
-                ) {
168
-                    // We had a match, so this prop-filter succeeds
169
-                    continue 2;
170
-                }
171
-            }
172
-
173
-            // If we got here it means there were sub-param-filters or
174
-            // text-match filters and there was no match. This means the
175
-            // filter needs to return false.
176
-            return false;
177
-        }
178
-
179
-        // If we got here it means we got through all prop-filters alive so the
180
-        // filters were all true.
181
-        return true;
182
-    }
183
-
184
-    /**
185
-     * This method checks the validity of param-filters.
186
-     *
187
-     * A list of param-filters needs to be specified. Also the parent of the
188
-     * parameter we're checking should be specified, not the parameter to check
189
-     * itself.
190
-     *
191
-     * @return bool
192
-     */
193
-    protected function validateParamFilters(VObject\Property $parent, array $filters)
194
-    {
195
-        foreach ($filters as $filter) {
196
-            $isDefined = isset($parent[$filter['name']]);
197
-
198
-            if ($filter['is-not-defined']) {
199
-                if ($isDefined) {
200
-                    return false;
201
-                } else {
202
-                    continue;
203
-                }
204
-            }
205
-            if (!$isDefined) {
206
-                return false;
207
-            }
208
-
209
-            if (!$filter['text-match']) {
210
-                continue;
211
-            }
212
-
213
-            // If there are sub-filters, we need to find at least one parameter
214
-            // for which the subfilters hold true.
215
-            foreach ($parent[$filter['name']]->getParts() as $paramPart) {
216
-                if ($this->validateTextMatch($paramPart, $filter['text-match'])) {
217
-                    // We had a match, so this param-filter succeeds
218
-                    continue 2;
219
-                }
220
-            }
221
-
222
-            // If we got here it means there was a text-match filter and there
223
-            // were no matches. This means the filter needs to return false.
224
-            return false;
225
-        }
226
-
227
-        // If we got here it means we got through all param-filters alive so the
228
-        // filters were all true.
229
-        return true;
230
-    }
231
-
232
-    /**
233
-     * This method checks the validity of a text-match.
234
-     *
235
-     * A single text-match should be specified as well as the specific property
236
-     * or parameter we need to validate.
237
-     *
238
-     * @param VObject\Node|string $check value to check against
239
-     *
240
-     * @return bool
241
-     */
242
-    protected function validateTextMatch($check, array $textMatch)
243
-    {
244
-        if ($check instanceof VObject\Node) {
245
-            $check = $check->getValue();
246
-        }
247
-
248
-        $isMatching = \Sabre\DAV\StringUtil::textMatch($check, $textMatch['value'], $textMatch['collation']);
249
-
250
-        return $textMatch['negate-condition'] xor $isMatching;
251
-    }
252
-
253
-    /**
254
-     * Validates if a component matches the given time range.
255
-     *
256
-     * This is all based on the rules specified in rfc4791, which are quite
257
-     * complex.
258
-     *
259
-     * @param DateTime $start
260
-     * @param DateTime $end
261
-     *
262
-     * @return bool
263
-     */
264
-    protected function validateTimeRange(VObject\Node $component, $start, $end)
265
-    {
266
-        if (is_null($start)) {
267
-            $start = new DateTime('1900-01-01');
268
-        }
269
-        if (is_null($end)) {
270
-            $end = new DateTime('3000-01-01');
271
-        }
272
-
273
-        switch ($component->name) {
274
-            case 'VEVENT':
275
-            case 'VTODO':
276
-            case 'VJOURNAL':
277
-                return $component->isInTimeRange($start, $end);
278
-
279
-            case 'VALARM':
280
-                // If the valarm is wrapped in a recurring event, we need to
281
-                // expand the recursions, and validate each.
282
-                //
283
-                // Our datamodel doesn't easily allow us to do this straight
284
-                // in the VALARM component code, so this is a hack, and an
285
-                // expensive one too.
286
-                if ('VEVENT' === $component->parent->name && $component->parent->RRULE) {
287
-                    // Fire up the iterator!
288
-                    $it = new VObject\Recur\EventIterator($component->parent->parent, (string) $component->parent->UID);
289
-                    while ($it->valid()) {
290
-                        $expandedEvent = $it->getEventObject();
291
-
292
-                        // We need to check from these expanded alarms, which
293
-                        // one is the first to trigger. Based on this, we can
294
-                        // determine if we can 'give up' expanding events.
295
-                        $firstAlarm = null;
296
-                        if (null !== $expandedEvent->VALARM) {
297
-                            foreach ($expandedEvent->VALARM as $expandedAlarm) {
298
-                                $effectiveTrigger = $expandedAlarm->getEffectiveTriggerTime();
299
-                                if ($expandedAlarm->isInTimeRange($start, $end)) {
300
-                                    return true;
301
-                                }
302
-
303
-                                if ('DATE-TIME' === (string) $expandedAlarm->TRIGGER['VALUE']) {
304
-                                    // This is an alarm with a non-relative trigger
305
-                                    // time, likely created by a buggy client. The
306
-                                    // implication is that every alarm in this
307
-                                    // recurring event trigger at the exact same
308
-                                    // time. It doesn't make sense to traverse
309
-                                    // further.
310
-                                } else {
311
-                                    // We store the first alarm as a means to
312
-                                    // figure out when we can stop traversing.
313
-                                    if (!$firstAlarm || $effectiveTrigger < $firstAlarm) {
314
-                                        $firstAlarm = $effectiveTrigger;
315
-                                    }
316
-                                }
317
-                            }
318
-                        }
319
-                        if (is_null($firstAlarm)) {
320
-                            // No alarm was found.
321
-                            //
322
-                            // Or technically: No alarm that will change for
323
-                            // every instance of the recurrence was found,
324
-                            // which means we can assume there was no match.
325
-                            return false;
326
-                        }
327
-                        if ($firstAlarm > $end) {
328
-                            return false;
329
-                        }
330
-                        $it->next();
331
-                    }
332
-
333
-                    return false;
334
-                } else {
335
-                    return $component->isInTimeRange($start, $end);
336
-                }
337
-
338
-                // no break
339
-            case 'VFREEBUSY':
340
-                throw new \Sabre\DAV\Exception\NotImplemented('time-range filters are currently not supported on '.$component->name.' components');
341
-            case 'COMPLETED':
342
-            case 'CREATED':
343
-            case 'DTEND':
344
-            case 'DTSTAMP':
345
-            case 'DTSTART':
346
-            case 'DUE':
347
-            case 'LAST-MODIFIED':
348
-                return $start <= $component->getDateTime() && $end >= $component->getDateTime();
349
-
350
-            default:
351
-                throw new \Sabre\DAV\Exception\BadRequest('You cannot create a time-range filter on a '.$component->name.' component');
352
-        }
353
-    }
25
+	/**
26
+	 * Verify if a list of filters applies to the calendar data object.
27
+	 *
28
+	 * The list of filters must be formatted as parsed by \Sabre\CalDAV\CalendarQueryParser
29
+	 *
30
+	 * @return bool
31
+	 */
32
+	public function validate(VObject\Component\VCalendar $vObject, array $filters)
33
+	{
34
+		// The top level object is always a component filter.
35
+		// We'll parse it manually, as it's pretty simple.
36
+		if ($vObject->name !== $filters['name']) {
37
+			return false;
38
+		}
39
+
40
+		return
41
+			$this->validateCompFilters($vObject, $filters['comp-filters']) &&
42
+			$this->validatePropFilters($vObject, $filters['prop-filters']);
43
+	}
44
+
45
+	/**
46
+	 * This method checks the validity of comp-filters.
47
+	 *
48
+	 * A list of comp-filters needs to be specified. Also the parent of the
49
+	 * component we're checking should be specified, not the component to check
50
+	 * itself.
51
+	 *
52
+	 * @return bool
53
+	 */
54
+	protected function validateCompFilters(VObject\Component $parent, array $filters)
55
+	{
56
+		foreach ($filters as $filter) {
57
+			$isDefined = isset($parent->{$filter['name']});
58
+
59
+			if ($filter['is-not-defined']) {
60
+				if ($isDefined) {
61
+					return false;
62
+				} else {
63
+					continue;
64
+				}
65
+			}
66
+			if (!$isDefined) {
67
+				return false;
68
+			}
69
+
70
+			if (array_key_exists('time-range', $filter) && $filter['time-range']) {
71
+				foreach ($parent->{$filter['name']} as $subComponent) {
72
+					$start = null;
73
+					$end = null;
74
+					if (array_key_exists('start', $filter['time-range'])) {
75
+						$start = $filter['time-range']['start'];
76
+					}
77
+					if (array_key_exists('end', $filter['time-range'])) {
78
+						$end = $filter['time-range']['end'];
79
+					}
80
+					if ($this->validateTimeRange($subComponent, $start, $end)) {
81
+						continue 2;
82
+					}
83
+				}
84
+
85
+				return false;
86
+			}
87
+
88
+			if (!$filter['comp-filters'] && !$filter['prop-filters']) {
89
+				continue;
90
+			}
91
+
92
+			// If there are sub-filters, we need to find at least one component
93
+			// for which the subfilters hold true.
94
+			foreach ($parent->{$filter['name']} as $subComponent) {
95
+				if (
96
+					$this->validateCompFilters($subComponent, $filter['comp-filters']) &&
97
+					$this->validatePropFilters($subComponent, $filter['prop-filters'])) {
98
+					// We had a match, so this comp-filter succeeds
99
+					continue 2;
100
+				}
101
+			}
102
+
103
+			// If we got here it means there were sub-comp-filters or
104
+			// sub-prop-filters and there was no match. This means this filter
105
+			// needs to return false.
106
+			return false;
107
+		}
108
+
109
+		// If we got here it means we got through all comp-filters alive so the
110
+		// filters were all true.
111
+		return true;
112
+	}
113
+
114
+	/**
115
+	 * This method checks the validity of prop-filters.
116
+	 *
117
+	 * A list of prop-filters needs to be specified. Also the parent of the
118
+	 * property we're checking should be specified, not the property to check
119
+	 * itself.
120
+	 *
121
+	 * @return bool
122
+	 */
123
+	protected function validatePropFilters(VObject\Component $parent, array $filters)
124
+	{
125
+		foreach ($filters as $filter) {
126
+			$isDefined = isset($parent->{$filter['name']});
127
+
128
+			if ($filter['is-not-defined']) {
129
+				if ($isDefined) {
130
+					return false;
131
+				} else {
132
+					continue;
133
+				}
134
+			}
135
+			if (!$isDefined) {
136
+				return false;
137
+			}
138
+
139
+			if (array_key_exists('time-range', $filter) && $filter['time-range']) {
140
+				foreach ($parent->{$filter['name']} as $subComponent) {
141
+					$start = null;
142
+					$end = null;
143
+					if (array_key_exists('start', $filter['time-range'])) {
144
+						$start = $filter['time-range']['start'];
145
+					}
146
+					if (array_key_exists('end', $filter['time-range'])) {
147
+						$end = $filter['time-range']['end'];
148
+					}
149
+					if ($this->validateTimeRange($subComponent, $start, $end)) {
150
+						continue 2;
151
+					}
152
+				}
153
+
154
+				return false;
155
+			}
156
+
157
+			if (!$filter['param-filters'] && !$filter['text-match']) {
158
+				continue;
159
+			}
160
+
161
+			// If there are sub-filters, we need to find at least one property
162
+			// for which the subfilters hold true.
163
+			foreach ($parent->{$filter['name']} as $subComponent) {
164
+				if (
165
+					$this->validateParamFilters($subComponent, $filter['param-filters']) &&
166
+					(!$filter['text-match'] || $this->validateTextMatch($subComponent, $filter['text-match']))
167
+				) {
168
+					// We had a match, so this prop-filter succeeds
169
+					continue 2;
170
+				}
171
+			}
172
+
173
+			// If we got here it means there were sub-param-filters or
174
+			// text-match filters and there was no match. This means the
175
+			// filter needs to return false.
176
+			return false;
177
+		}
178
+
179
+		// If we got here it means we got through all prop-filters alive so the
180
+		// filters were all true.
181
+		return true;
182
+	}
183
+
184
+	/**
185
+	 * This method checks the validity of param-filters.
186
+	 *
187
+	 * A list of param-filters needs to be specified. Also the parent of the
188
+	 * parameter we're checking should be specified, not the parameter to check
189
+	 * itself.
190
+	 *
191
+	 * @return bool
192
+	 */
193
+	protected function validateParamFilters(VObject\Property $parent, array $filters)
194
+	{
195
+		foreach ($filters as $filter) {
196
+			$isDefined = isset($parent[$filter['name']]);
197
+
198
+			if ($filter['is-not-defined']) {
199
+				if ($isDefined) {
200
+					return false;
201
+				} else {
202
+					continue;
203
+				}
204
+			}
205
+			if (!$isDefined) {
206
+				return false;
207
+			}
208
+
209
+			if (!$filter['text-match']) {
210
+				continue;
211
+			}
212
+
213
+			// If there are sub-filters, we need to find at least one parameter
214
+			// for which the subfilters hold true.
215
+			foreach ($parent[$filter['name']]->getParts() as $paramPart) {
216
+				if ($this->validateTextMatch($paramPart, $filter['text-match'])) {
217
+					// We had a match, so this param-filter succeeds
218
+					continue 2;
219
+				}
220
+			}
221
+
222
+			// If we got here it means there was a text-match filter and there
223
+			// were no matches. This means the filter needs to return false.
224
+			return false;
225
+		}
226
+
227
+		// If we got here it means we got through all param-filters alive so the
228
+		// filters were all true.
229
+		return true;
230
+	}
231
+
232
+	/**
233
+	 * This method checks the validity of a text-match.
234
+	 *
235
+	 * A single text-match should be specified as well as the specific property
236
+	 * or parameter we need to validate.
237
+	 *
238
+	 * @param VObject\Node|string $check value to check against
239
+	 *
240
+	 * @return bool
241
+	 */
242
+	protected function validateTextMatch($check, array $textMatch)
243
+	{
244
+		if ($check instanceof VObject\Node) {
245
+			$check = $check->getValue();
246
+		}
247
+
248
+		$isMatching = \Sabre\DAV\StringUtil::textMatch($check, $textMatch['value'], $textMatch['collation']);
249
+
250
+		return $textMatch['negate-condition'] xor $isMatching;
251
+	}
252
+
253
+	/**
254
+	 * Validates if a component matches the given time range.
255
+	 *
256
+	 * This is all based on the rules specified in rfc4791, which are quite
257
+	 * complex.
258
+	 *
259
+	 * @param DateTime $start
260
+	 * @param DateTime $end
261
+	 *
262
+	 * @return bool
263
+	 */
264
+	protected function validateTimeRange(VObject\Node $component, $start, $end)
265
+	{
266
+		if (is_null($start)) {
267
+			$start = new DateTime('1900-01-01');
268
+		}
269
+		if (is_null($end)) {
270
+			$end = new DateTime('3000-01-01');
271
+		}
272
+
273
+		switch ($component->name) {
274
+			case 'VEVENT':
275
+			case 'VTODO':
276
+			case 'VJOURNAL':
277
+				return $component->isInTimeRange($start, $end);
278
+
279
+			case 'VALARM':
280
+				// If the valarm is wrapped in a recurring event, we need to
281
+				// expand the recursions, and validate each.
282
+				//
283
+				// Our datamodel doesn't easily allow us to do this straight
284
+				// in the VALARM component code, so this is a hack, and an
285
+				// expensive one too.
286
+				if ('VEVENT' === $component->parent->name && $component->parent->RRULE) {
287
+					// Fire up the iterator!
288
+					$it = new VObject\Recur\EventIterator($component->parent->parent, (string) $component->parent->UID);
289
+					while ($it->valid()) {
290
+						$expandedEvent = $it->getEventObject();
291
+
292
+						// We need to check from these expanded alarms, which
293
+						// one is the first to trigger. Based on this, we can
294
+						// determine if we can 'give up' expanding events.
295
+						$firstAlarm = null;
296
+						if (null !== $expandedEvent->VALARM) {
297
+							foreach ($expandedEvent->VALARM as $expandedAlarm) {
298
+								$effectiveTrigger = $expandedAlarm->getEffectiveTriggerTime();
299
+								if ($expandedAlarm->isInTimeRange($start, $end)) {
300
+									return true;
301
+								}
302
+
303
+								if ('DATE-TIME' === (string) $expandedAlarm->TRIGGER['VALUE']) {
304
+									// This is an alarm with a non-relative trigger
305
+									// time, likely created by a buggy client. The
306
+									// implication is that every alarm in this
307
+									// recurring event trigger at the exact same
308
+									// time. It doesn't make sense to traverse
309
+									// further.
310
+								} else {
311
+									// We store the first alarm as a means to
312
+									// figure out when we can stop traversing.
313
+									if (!$firstAlarm || $effectiveTrigger < $firstAlarm) {
314
+										$firstAlarm = $effectiveTrigger;
315
+									}
316
+								}
317
+							}
318
+						}
319
+						if (is_null($firstAlarm)) {
320
+							// No alarm was found.
321
+							//
322
+							// Or technically: No alarm that will change for
323
+							// every instance of the recurrence was found,
324
+							// which means we can assume there was no match.
325
+							return false;
326
+						}
327
+						if ($firstAlarm > $end) {
328
+							return false;
329
+						}
330
+						$it->next();
331
+					}
332
+
333
+					return false;
334
+				} else {
335
+					return $component->isInTimeRange($start, $end);
336
+				}
337
+
338
+				// no break
339
+			case 'VFREEBUSY':
340
+				throw new \Sabre\DAV\Exception\NotImplemented('time-range filters are currently not supported on '.$component->name.' components');
341
+			case 'COMPLETED':
342
+			case 'CREATED':
343
+			case 'DTEND':
344
+			case 'DTSTAMP':
345
+			case 'DTSTART':
346
+			case 'DUE':
347
+			case 'LAST-MODIFIED':
348
+				return $start <= $component->getDateTime() && $end >= $component->getDateTime();
349
+
350
+			default:
351
+				throw new \Sabre\DAV\Exception\BadRequest('You cannot create a time-range filter on a '.$component->name.' component');
352
+		}
353
+	}
354 354
 }
Please login to merge, or discard this patch.
includes/sabre/sabre/dav/lib/CalDAV/Exception/InvalidComponentType.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -16,16 +16,16 @@
 block discarded – undo
16 16
  */
17 17
 class InvalidComponentType extends DAV\Exception\Forbidden
18 18
 {
19
-    /**
20
-     * Adds in extra information in the xml response.
21
-     *
22
-     * This method adds the {CALDAV:}supported-calendar-component as defined in rfc4791
23
-     */
24
-    public function serialize(DAV\Server $server, \DOMElement $errorNode)
25
-    {
26
-        $doc = $errorNode->ownerDocument;
19
+	/**
20
+	 * Adds in extra information in the xml response.
21
+	 *
22
+	 * This method adds the {CALDAV:}supported-calendar-component as defined in rfc4791
23
+	 */
24
+	public function serialize(DAV\Server $server, \DOMElement $errorNode)
25
+	{
26
+		$doc = $errorNode->ownerDocument;
27 27
 
28
-        $np = $doc->createElementNS(CalDAV\Plugin::NS_CALDAV, 'cal:supported-calendar-component');
29
-        $errorNode->appendChild($np);
30
-    }
28
+		$np = $doc->createElementNS(CalDAV\Plugin::NS_CALDAV, 'cal:supported-calendar-component');
29
+		$errorNode->appendChild($np);
30
+	}
31 31
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Notifications/Plugin.php 2 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -28,134 +28,134 @@
 block discarded – undo
28 28
  */
29 29
 class Plugin extends ServerPlugin
30 30
 {
31
-    /**
32
-     * This is the namespace for the proprietary calendarserver extensions.
33
-     */
34
-    const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
35
-
36
-    /**
37
-     * Reference to the main server object.
38
-     *
39
-     * @var Server
40
-     */
41
-    protected $server;
42
-
43
-    /**
44
-     * Returns a plugin name.
45
-     *
46
-     * Using this name other plugins will be able to access other plugins
47
-     * using \Sabre\DAV\Server::getPlugin
48
-     *
49
-     * @return string
50
-     */
51
-    public function getPluginName()
52
-    {
53
-        return 'notifications';
54
-    }
55
-
56
-    /**
57
-     * This initializes the plugin.
58
-     *
59
-     * This function is called by Sabre\DAV\Server, after
60
-     * addPlugin is called.
61
-     *
62
-     * This method should set up the required event subscriptions.
63
-     */
64
-    public function initialize(Server $server)
65
-    {
66
-        $this->server = $server;
67
-        $server->on('method:GET', [$this, 'httpGet'], 90);
68
-        $server->on('propFind', [$this, 'propFind']);
69
-
70
-        $server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs';
71
-        $server->resourceTypeMapping['\\Sabre\\CalDAV\\Notifications\\ICollection'] = '{'.self::NS_CALENDARSERVER.'}notification';
72
-
73
-        array_push($server->protectedProperties,
74
-            '{'.self::NS_CALENDARSERVER.'}notification-URL',
75
-            '{'.self::NS_CALENDARSERVER.'}notificationtype'
76
-        );
77
-    }
78
-
79
-    /**
80
-     * PropFind.
81
-     */
82
-    public function propFind(PropFind $propFind, BaseINode $node)
83
-    {
84
-        $caldavPlugin = $this->server->getPlugin('caldav');
85
-
86
-        if ($node instanceof DAVACL\IPrincipal) {
87
-            $principalUrl = $node->getPrincipalUrl();
88
-
89
-            // notification-URL property
90
-            $propFind->handle('{'.self::NS_CALENDARSERVER.'}notification-URL', function () use ($principalUrl, $caldavPlugin) {
91
-                $notificationPath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl).'/notifications/';
92
-
93
-                return new DAV\Xml\Property\Href($notificationPath);
94
-            });
95
-        }
96
-
97
-        if ($node instanceof INode) {
98
-            $propFind->handle(
99
-                '{'.self::NS_CALENDARSERVER.'}notificationtype',
100
-                [$node, 'getNotificationType']
101
-            );
102
-        }
103
-    }
104
-
105
-    /**
106
-     * This event is triggered before the usual GET request handler.
107
-     *
108
-     * We use this to intercept GET calls to notification nodes, and return the
109
-     * proper response.
110
-     */
111
-    public function httpGet(RequestInterface $request, ResponseInterface $response)
112
-    {
113
-        $path = $request->getPath();
114
-
115
-        try {
116
-            $node = $this->server->tree->getNodeForPath($path);
117
-        } catch (DAV\Exception\NotFound $e) {
118
-            return;
119
-        }
120
-
121
-        if (!$node instanceof INode) {
122
-            return;
123
-        }
124
-
125
-        $writer = $this->server->xml->getWriter();
126
-        $writer->contextUri = $this->server->getBaseUri();
127
-        $writer->openMemory();
128
-        $writer->startDocument('1.0', 'UTF-8');
129
-        $writer->startElement('{http://calendarserver.org/ns/}notification');
130
-        $node->getNotificationType()->xmlSerializeFull($writer);
131
-        $writer->endElement();
132
-
133
-        $response->setHeader('Content-Type', 'application/xml');
134
-        $response->setHeader('ETag', $node->getETag());
135
-        $response->setStatus(200);
136
-        $response->setBody($writer->outputMemory());
137
-
138
-        // Return false to break the event chain.
139
-        return false;
140
-    }
141
-
142
-    /**
143
-     * Returns a bunch of meta-data about the plugin.
144
-     *
145
-     * Providing this information is optional, and is mainly displayed by the
146
-     * Browser plugin.
147
-     *
148
-     * The description key in the returned array may contain html and will not
149
-     * be sanitized.
150
-     *
151
-     * @return array
152
-     */
153
-    public function getPluginInfo()
154
-    {
155
-        return [
156
-            'name' => $this->getPluginName(),
157
-            'description' => 'Adds support for caldav-notifications, which is required to enable caldav-sharing.',
158
-            'link' => 'http://sabre.io/dav/caldav-sharing/',
159
-        ];
160
-    }
31
+	/**
32
+	 * This is the namespace for the proprietary calendarserver extensions.
33
+	 */
34
+	const NS_CALENDARSERVER = 'http://calendarserver.org/ns/';
35
+
36
+	/**
37
+	 * Reference to the main server object.
38
+	 *
39
+	 * @var Server
40
+	 */
41
+	protected $server;
42
+
43
+	/**
44
+	 * Returns a plugin name.
45
+	 *
46
+	 * Using this name other plugins will be able to access other plugins
47
+	 * using \Sabre\DAV\Server::getPlugin
48
+	 *
49
+	 * @return string
50
+	 */
51
+	public function getPluginName()
52
+	{
53
+		return 'notifications';
54
+	}
55
+
56
+	/**
57
+	 * This initializes the plugin.
58
+	 *
59
+	 * This function is called by Sabre\DAV\Server, after
60
+	 * addPlugin is called.
61
+	 *
62
+	 * This method should set up the required event subscriptions.
63
+	 */
64
+	public function initialize(Server $server)
65
+	{
66
+		$this->server = $server;
67
+		$server->on('method:GET', [$this, 'httpGet'], 90);
68
+		$server->on('propFind', [$this, 'propFind']);
69
+
70
+		$server->xml->namespaceMap[self::NS_CALENDARSERVER] = 'cs';
71
+		$server->resourceTypeMapping['\\Sabre\\CalDAV\\Notifications\\ICollection'] = '{'.self::NS_CALENDARSERVER.'}notification';
72
+
73
+		array_push($server->protectedProperties,
74
+			'{'.self::NS_CALENDARSERVER.'}notification-URL',
75
+			'{'.self::NS_CALENDARSERVER.'}notificationtype'
76
+		);
77
+	}
78
+
79
+	/**
80
+	 * PropFind.
81
+	 */
82
+	public function propFind(PropFind $propFind, BaseINode $node)
83
+	{
84
+		$caldavPlugin = $this->server->getPlugin('caldav');
85
+
86
+		if ($node instanceof DAVACL\IPrincipal) {
87
+			$principalUrl = $node->getPrincipalUrl();
88
+
89
+			// notification-URL property
90
+			$propFind->handle('{'.self::NS_CALENDARSERVER.'}notification-URL', function () use ($principalUrl, $caldavPlugin) {
91
+				$notificationPath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl).'/notifications/';
92
+
93
+				return new DAV\Xml\Property\Href($notificationPath);
94
+			});
95
+		}
96
+
97
+		if ($node instanceof INode) {
98
+			$propFind->handle(
99
+				'{'.self::NS_CALENDARSERVER.'}notificationtype',
100
+				[$node, 'getNotificationType']
101
+			);
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * This event is triggered before the usual GET request handler.
107
+	 *
108
+	 * We use this to intercept GET calls to notification nodes, and return the
109
+	 * proper response.
110
+	 */
111
+	public function httpGet(RequestInterface $request, ResponseInterface $response)
112
+	{
113
+		$path = $request->getPath();
114
+
115
+		try {
116
+			$node = $this->server->tree->getNodeForPath($path);
117
+		} catch (DAV\Exception\NotFound $e) {
118
+			return;
119
+		}
120
+
121
+		if (!$node instanceof INode) {
122
+			return;
123
+		}
124
+
125
+		$writer = $this->server->xml->getWriter();
126
+		$writer->contextUri = $this->server->getBaseUri();
127
+		$writer->openMemory();
128
+		$writer->startDocument('1.0', 'UTF-8');
129
+		$writer->startElement('{http://calendarserver.org/ns/}notification');
130
+		$node->getNotificationType()->xmlSerializeFull($writer);
131
+		$writer->endElement();
132
+
133
+		$response->setHeader('Content-Type', 'application/xml');
134
+		$response->setHeader('ETag', $node->getETag());
135
+		$response->setStatus(200);
136
+		$response->setBody($writer->outputMemory());
137
+
138
+		// Return false to break the event chain.
139
+		return false;
140
+	}
141
+
142
+	/**
143
+	 * Returns a bunch of meta-data about the plugin.
144
+	 *
145
+	 * Providing this information is optional, and is mainly displayed by the
146
+	 * Browser plugin.
147
+	 *
148
+	 * The description key in the returned array may contain html and will not
149
+	 * be sanitized.
150
+	 *
151
+	 * @return array
152
+	 */
153
+	public function getPluginInfo()
154
+	{
155
+		return [
156
+			'name' => $this->getPluginName(),
157
+			'description' => 'Adds support for caldav-notifications, which is required to enable caldav-sharing.',
158
+			'link' => 'http://sabre.io/dav/caldav-sharing/',
159
+		];
160
+	}
161 161
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@
 block discarded – undo
87 87
             $principalUrl = $node->getPrincipalUrl();
88 88
 
89 89
             // notification-URL property
90
-            $propFind->handle('{'.self::NS_CALENDARSERVER.'}notification-URL', function () use ($principalUrl, $caldavPlugin) {
90
+            $propFind->handle('{'.self::NS_CALENDARSERVER.'}notification-URL', function() use ($principalUrl, $caldavPlugin) {
91 91
                 $notificationPath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl).'/notifications/';
92 92
 
93 93
                 return new DAV\Xml\Property\Href($notificationPath);
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Notifications/Collection.php 1 patch
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -24,73 +24,73 @@
 block discarded – undo
24 24
  */
25 25
 class Collection extends DAV\Collection implements ICollection, DAVACL\IACL
26 26
 {
27
-    use DAVACL\ACLTrait;
27
+	use DAVACL\ACLTrait;
28 28
 
29
-    /**
30
-     * The notification backend.
31
-     *
32
-     * @var CalDAV\Backend\NotificationSupport
33
-     */
34
-    protected $caldavBackend;
29
+	/**
30
+	 * The notification backend.
31
+	 *
32
+	 * @var CalDAV\Backend\NotificationSupport
33
+	 */
34
+	protected $caldavBackend;
35 35
 
36
-    /**
37
-     * Principal uri.
38
-     *
39
-     * @var string
40
-     */
41
-    protected $principalUri;
36
+	/**
37
+	 * Principal uri.
38
+	 *
39
+	 * @var string
40
+	 */
41
+	protected $principalUri;
42 42
 
43
-    /**
44
-     * Constructor.
45
-     *
46
-     * @param string $principalUri
47
-     */
48
-    public function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri)
49
-    {
50
-        $this->caldavBackend = $caldavBackend;
51
-        $this->principalUri = $principalUri;
52
-    }
43
+	/**
44
+	 * Constructor.
45
+	 *
46
+	 * @param string $principalUri
47
+	 */
48
+	public function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri)
49
+	{
50
+		$this->caldavBackend = $caldavBackend;
51
+		$this->principalUri = $principalUri;
52
+	}
53 53
 
54
-    /**
55
-     * Returns all notifications for a principal.
56
-     *
57
-     * @return array
58
-     */
59
-    public function getChildren()
60
-    {
61
-        $children = [];
62
-        $notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri);
54
+	/**
55
+	 * Returns all notifications for a principal.
56
+	 *
57
+	 * @return array
58
+	 */
59
+	public function getChildren()
60
+	{
61
+		$children = [];
62
+		$notifications = $this->caldavBackend->getNotificationsForPrincipal($this->principalUri);
63 63
 
64
-        foreach ($notifications as $notification) {
65
-            $children[] = new Node(
66
-                $this->caldavBackend,
67
-                $this->principalUri,
68
-                $notification
69
-            );
70
-        }
64
+		foreach ($notifications as $notification) {
65
+			$children[] = new Node(
66
+				$this->caldavBackend,
67
+				$this->principalUri,
68
+				$notification
69
+			);
70
+		}
71 71
 
72
-        return $children;
73
-    }
72
+		return $children;
73
+	}
74 74
 
75
-    /**
76
-     * Returns the name of this object.
77
-     *
78
-     * @return string
79
-     */
80
-    public function getName()
81
-    {
82
-        return 'notifications';
83
-    }
75
+	/**
76
+	 * Returns the name of this object.
77
+	 *
78
+	 * @return string
79
+	 */
80
+	public function getName()
81
+	{
82
+		return 'notifications';
83
+	}
84 84
 
85
-    /**
86
-     * Returns the owner principal.
87
-     *
88
-     * This must be a url to a principal, or null if there's no owner
89
-     *
90
-     * @return string|null
91
-     */
92
-    public function getOwner()
93
-    {
94
-        return $this->principalUri;
95
-    }
85
+	/**
86
+	 * Returns the owner principal.
87
+	 *
88
+	 * This must be a url to a principal, or null if there's no owner
89
+	 *
90
+	 * @return string|null
91
+	 */
92
+	public function getOwner()
93
+	{
94
+		return $this->principalUri;
95
+	}
96 96
 }
Please login to merge, or discard this patch.
htdocs/includes/sabre/sabre/dav/lib/CalDAV/Notifications/Node.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -22,91 +22,91 @@
 block discarded – undo
22 22
  */
23 23
 class Node extends DAV\File implements INode, DAVACL\IACL
24 24
 {
25
-    use DAVACL\ACLTrait;
25
+	use DAVACL\ACLTrait;
26 26
 
27
-    /**
28
-     * The notification backend.
29
-     *
30
-     * @var CalDAV\Backend\NotificationSupport
31
-     */
32
-    protected $caldavBackend;
27
+	/**
28
+	 * The notification backend.
29
+	 *
30
+	 * @var CalDAV\Backend\NotificationSupport
31
+	 */
32
+	protected $caldavBackend;
33 33
 
34
-    /**
35
-     * The actual notification.
36
-     *
37
-     * @var NotificationInterface
38
-     */
39
-    protected $notification;
34
+	/**
35
+	 * The actual notification.
36
+	 *
37
+	 * @var NotificationInterface
38
+	 */
39
+	protected $notification;
40 40
 
41
-    /**
42
-     * Owner principal of the notification.
43
-     *
44
-     * @var string
45
-     */
46
-    protected $principalUri;
41
+	/**
42
+	 * Owner principal of the notification.
43
+	 *
44
+	 * @var string
45
+	 */
46
+	protected $principalUri;
47 47
 
48
-    /**
49
-     * Constructor.
50
-     *
51
-     * @param string $principalUri
52
-     */
53
-    public function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification)
54
-    {
55
-        $this->caldavBackend = $caldavBackend;
56
-        $this->principalUri = $principalUri;
57
-        $this->notification = $notification;
58
-    }
48
+	/**
49
+	 * Constructor.
50
+	 *
51
+	 * @param string $principalUri
52
+	 */
53
+	public function __construct(CalDAV\Backend\NotificationSupport $caldavBackend, $principalUri, NotificationInterface $notification)
54
+	{
55
+		$this->caldavBackend = $caldavBackend;
56
+		$this->principalUri = $principalUri;
57
+		$this->notification = $notification;
58
+	}
59 59
 
60
-    /**
61
-     * Returns the path name for this notification.
62
-     *
63
-     * @return string
64
-     */
65
-    public function getName()
66
-    {
67
-        return $this->notification->getId().'.xml';
68
-    }
60
+	/**
61
+	 * Returns the path name for this notification.
62
+	 *
63
+	 * @return string
64
+	 */
65
+	public function getName()
66
+	{
67
+		return $this->notification->getId().'.xml';
68
+	}
69 69
 
70
-    /**
71
-     * Returns the etag for the notification.
72
-     *
73
-     * The etag must be surrounded by litteral double-quotes.
74
-     *
75
-     * @return string
76
-     */
77
-    public function getETag()
78
-    {
79
-        return $this->notification->getETag();
80
-    }
70
+	/**
71
+	 * Returns the etag for the notification.
72
+	 *
73
+	 * The etag must be surrounded by litteral double-quotes.
74
+	 *
75
+	 * @return string
76
+	 */
77
+	public function getETag()
78
+	{
79
+		return $this->notification->getETag();
80
+	}
81 81
 
82
-    /**
83
-     * This method must return an xml element, using the
84
-     * Sabre\CalDAV\Xml\Notification\NotificationInterface classes.
85
-     *
86
-     * @return NotificationInterface
87
-     */
88
-    public function getNotificationType()
89
-    {
90
-        return $this->notification;
91
-    }
82
+	/**
83
+	 * This method must return an xml element, using the
84
+	 * Sabre\CalDAV\Xml\Notification\NotificationInterface classes.
85
+	 *
86
+	 * @return NotificationInterface
87
+	 */
88
+	public function getNotificationType()
89
+	{
90
+		return $this->notification;
91
+	}
92 92
 
93
-    /**
94
-     * Deletes this notification.
95
-     */
96
-    public function delete()
97
-    {
98
-        $this->caldavBackend->deleteNotification($this->getOwner(), $this->notification);
99
-    }
93
+	/**
94
+	 * Deletes this notification.
95
+	 */
96
+	public function delete()
97
+	{
98
+		$this->caldavBackend->deleteNotification($this->getOwner(), $this->notification);
99
+	}
100 100
 
101
-    /**
102
-     * Returns the owner principal.
103
-     *
104
-     * This must be a url to a principal, or null if there's no owner
105
-     *
106
-     * @return string|null
107
-     */
108
-    public function getOwner()
109
-    {
110
-        return $this->principalUri;
111
-    }
101
+	/**
102
+	 * Returns the owner principal.
103
+	 *
104
+	 * This must be a url to a principal, or null if there's no owner
105
+	 *
106
+	 * @return string|null
107
+	 */
108
+	public function getOwner()
109
+	{
110
+		return $this->principalUri;
111
+	}
112 112
 }
Please login to merge, or discard this patch.
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.