Completed
Branch master (69e0e2)
by Johannes
12:46
created
apps/dav/lib/CalDAV/Calendar.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	}
102 102
 
103 103
 	function getACL() {
104
-		$acl =  [
104
+		$acl = [
105 105
 			[
106 106
 				'privilege' => '{DAV:}read',
107 107
 				'principal' => $this->getOwner(),
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 			];
116 116
 		}
117 117
 		if ($this->getOwner() !== parent::getOwner()) {
118
-			$acl[] =  [
118
+			$acl[] = [
119 119
 					'privilege' => '{DAV:}read',
120 120
 					'principal' => parent::getOwner(),
121 121
 					'protected' => true,
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	function delete() {
156 156
 		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
157 157
 			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
158
-			$principal = 'principal:' . parent::getOwner();
158
+			$principal = 'principal:'.parent::getOwner();
159 159
 			$shares = $this->getShares();
160 160
 			$shares = array_filter($shares, function($share) use ($principal){
161 161
 				return $share['href'] === $principal;
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
 
248 248
 		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
249 249
 		if ($this->isShared()) {
250
-			return array_filter($uris, function ($uri) {
250
+			return array_filter($uris, function($uri) {
251 251
 				return $this->childExists($uri);
252 252
 			});
253 253
 		}
Please login to merge, or discard this patch.
Indentation   +261 added lines, -261 removed lines patch added patch discarded remove patch
@@ -32,266 +32,266 @@
 block discarded – undo
32 32
 
33 33
 class Calendar extends \Sabre\CalDAV\Calendar implements IShareable {
34 34
 
35
-	public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
36
-		parent::__construct($caldavBackend, $calendarInfo);
37
-
38
-		if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
39
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
40
-		}
41
-		if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
42
-			$this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
43
-			$this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
44
-		}
45
-	}
46
-
47
-	/**
48
-	 * Updates the list of shares.
49
-	 *
50
-	 * The first array is a list of people that are to be added to the
51
-	 * resource.
52
-	 *
53
-	 * Every element in the add array has the following properties:
54
-	 *   * href - A url. Usually a mailto: address
55
-	 *   * commonName - Usually a first and last name, or false
56
-	 *   * summary - A description of the share, can also be false
57
-	 *   * readOnly - A boolean value
58
-	 *
59
-	 * Every element in the remove array is just the address string.
60
-	 *
61
-	 * @param array $add
62
-	 * @param array $remove
63
-	 * @return void
64
-	 */
65
-	function updateShares(array $add, array $remove) {
66
-		/** @var CalDavBackend $calDavBackend */
67
-		$calDavBackend = $this->caldavBackend;
68
-		$calDavBackend->updateShares($this, $add, $remove);
69
-	}
70
-
71
-	/**
72
-	 * Returns the list of people whom this resource is shared with.
73
-	 *
74
-	 * Every element in this array should have the following properties:
75
-	 *   * href - Often a mailto: address
76
-	 *   * commonName - Optional, for example a first + last name
77
-	 *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
78
-	 *   * readOnly - boolean
79
-	 *   * summary - Optional, a description for the share
80
-	 *
81
-	 * @return array
82
-	 */
83
-	function getShares() {
84
-		/** @var CalDavBackend $calDavBackend */
85
-		$calDavBackend = $this->caldavBackend;
86
-		return $calDavBackend->getShares($this->getResourceId());
87
-	}
88
-
89
-	/**
90
-	 * @return int
91
-	 */
92
-	public function getResourceId() {
93
-		return $this->calendarInfo['id'];
94
-	}
95
-
96
-	/**
97
-	 * @return string
98
-	 */
99
-	public function getPrincipalURI() {
100
-		return $this->calendarInfo['principaluri'];
101
-	}
102
-
103
-	function getACL() {
104
-		$acl =  [
105
-			[
106
-				'privilege' => '{DAV:}read',
107
-				'principal' => $this->getOwner(),
108
-				'protected' => true,
109
-			]];
110
-		if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
111
-			$acl[] = [
112
-				'privilege' => '{DAV:}write',
113
-				'principal' => $this->getOwner(),
114
-				'protected' => true,
115
-			];
116
-		}
117
-		if ($this->getOwner() !== parent::getOwner()) {
118
-			$acl[] =  [
119
-					'privilege' => '{DAV:}read',
120
-					'principal' => parent::getOwner(),
121
-					'protected' => true,
122
-				];
123
-			if ($this->canWrite()) {
124
-				$acl[] = [
125
-					'privilege' => '{DAV:}write',
126
-					'principal' => parent::getOwner(),
127
-					'protected' => true,
128
-				];
129
-			}
130
-		}
131
-		if ($this->isPublic()) {
132
-			$acl[] = [
133
-				'privilege' => '{DAV:}read',
134
-				'principal' => 'principals/system/public',
135
-				'protected' => true,
136
-			];
137
-		}
138
-
139
-		/** @var CalDavBackend $calDavBackend */
140
-		$calDavBackend = $this->caldavBackend;
141
-		return $calDavBackend->applyShareAcl($this->getResourceId(), $acl);
142
-	}
143
-
144
-	function getChildACL() {
145
-		return $this->getACL();
146
-	}
147
-
148
-	function getOwner() {
149
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
150
-			return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
151
-		}
152
-		return parent::getOwner();
153
-	}
154
-
155
-	function delete() {
156
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
157
-			$this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
158
-			$principal = 'principal:' . parent::getOwner();
159
-			$shares = $this->getShares();
160
-			$shares = array_filter($shares, function($share) use ($principal){
161
-				return $share['href'] === $principal;
162
-			});
163
-			if (empty($shares)) {
164
-				throw new Forbidden();
165
-			}
166
-
167
-			/** @var CalDavBackend $calDavBackend */
168
-			$calDavBackend = $this->caldavBackend;
169
-			$calDavBackend->updateShares($this, [], [
170
-				'href' => $principal
171
-			]);
172
-			return;
173
-		}
174
-		parent::delete();
175
-	}
176
-
177
-	function propPatch(PropPatch $propPatch) {
178
-		// parent::propPatch will only update calendars table
179
-		// if calendar is shared, changes have to be made to the properties table
180
-		if (!$this->isShared()) {
181
-			parent::propPatch($propPatch);
182
-		}
183
-	}
184
-
185
-	function getChild($name) {
186
-
187
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
188
-
189
-		if (!$obj) {
190
-			throw new NotFound('Calendar object not found');
191
-		}
192
-
193
-		if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
194
-			throw new NotFound('Calendar object not found');
195
-		}
196
-
197
-		$obj['acl'] = $this->getChildACL();
198
-
199
-		return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
200
-
201
-	}
202
-
203
-	function getChildren() {
204
-
205
-		$objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
206
-		$children = [];
207
-		foreach ($objs as $obj) {
208
-			if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
209
-				continue;
210
-			}
211
-			$obj['acl'] = $this->getChildACL();
212
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
213
-		}
214
-		return $children;
215
-
216
-	}
217
-
218
-	function getMultipleChildren(array $paths) {
219
-
220
-		$objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
221
-		$children = [];
222
-		foreach ($objs as $obj) {
223
-			if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
224
-				continue;
225
-			}
226
-			$obj['acl'] = $this->getChildACL();
227
-			$children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
228
-		}
229
-		return $children;
230
-
231
-	}
232
-
233
-	function childExists($name) {
234
-		$obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
235
-		if (!$obj) {
236
-			return false;
237
-		}
238
-		if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
239
-			return false;
240
-		}
241
-
242
-		return true;
243
-	}
244
-
245
-	function calendarQuery(array $filters) {
246
-
247
-		$uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
248
-		if ($this->isShared()) {
249
-			return array_filter($uris, function ($uri) {
250
-				return $this->childExists($uri);
251
-			});
252
-		}
253
-
254
-		return $uris;
255
-	}
256
-
257
-	/**
258
-	 * @param boolean $value
259
-	 * @return string|null
260
-	 */
261
-	function setPublishStatus($value) {
262
-		$publicUri = $this->caldavBackend->setPublishStatus($value, $this);
263
-		$this->calendarInfo['publicuri'] = $publicUri;
264
-		return $publicUri;
265
-	}
266
-
267
-	/**
268
-	 * @return mixed $value
269
-	 */
270
-	function getPublishStatus() {
271
-		return $this->caldavBackend->getPublishStatus($this);
272
-	}
273
-
274
-	private function canWrite() {
275
-		if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
276
-			return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
277
-		}
278
-		return true;
279
-	}
280
-
281
-	private function isPublic() {
282
-		return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
283
-	}
284
-
285
-	protected function isShared() {
286
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
287
-			return false;
288
-		}
289
-
290
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
291
-	}
292
-
293
-	public function isSubscription() {
294
-		return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
295
-	}
35
+    public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) {
36
+        parent::__construct($caldavBackend, $calendarInfo);
37
+
38
+        if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
39
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays');
40
+        }
41
+        if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI &&
42
+            $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) {
43
+            $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal');
44
+        }
45
+    }
46
+
47
+    /**
48
+     * Updates the list of shares.
49
+     *
50
+     * The first array is a list of people that are to be added to the
51
+     * resource.
52
+     *
53
+     * Every element in the add array has the following properties:
54
+     *   * href - A url. Usually a mailto: address
55
+     *   * commonName - Usually a first and last name, or false
56
+     *   * summary - A description of the share, can also be false
57
+     *   * readOnly - A boolean value
58
+     *
59
+     * Every element in the remove array is just the address string.
60
+     *
61
+     * @param array $add
62
+     * @param array $remove
63
+     * @return void
64
+     */
65
+    function updateShares(array $add, array $remove) {
66
+        /** @var CalDavBackend $calDavBackend */
67
+        $calDavBackend = $this->caldavBackend;
68
+        $calDavBackend->updateShares($this, $add, $remove);
69
+    }
70
+
71
+    /**
72
+     * Returns the list of people whom this resource is shared with.
73
+     *
74
+     * Every element in this array should have the following properties:
75
+     *   * href - Often a mailto: address
76
+     *   * commonName - Optional, for example a first + last name
77
+     *   * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants.
78
+     *   * readOnly - boolean
79
+     *   * summary - Optional, a description for the share
80
+     *
81
+     * @return array
82
+     */
83
+    function getShares() {
84
+        /** @var CalDavBackend $calDavBackend */
85
+        $calDavBackend = $this->caldavBackend;
86
+        return $calDavBackend->getShares($this->getResourceId());
87
+    }
88
+
89
+    /**
90
+     * @return int
91
+     */
92
+    public function getResourceId() {
93
+        return $this->calendarInfo['id'];
94
+    }
95
+
96
+    /**
97
+     * @return string
98
+     */
99
+    public function getPrincipalURI() {
100
+        return $this->calendarInfo['principaluri'];
101
+    }
102
+
103
+    function getACL() {
104
+        $acl =  [
105
+            [
106
+                'privilege' => '{DAV:}read',
107
+                'principal' => $this->getOwner(),
108
+                'protected' => true,
109
+            ]];
110
+        if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) {
111
+            $acl[] = [
112
+                'privilege' => '{DAV:}write',
113
+                'principal' => $this->getOwner(),
114
+                'protected' => true,
115
+            ];
116
+        }
117
+        if ($this->getOwner() !== parent::getOwner()) {
118
+            $acl[] =  [
119
+                    'privilege' => '{DAV:}read',
120
+                    'principal' => parent::getOwner(),
121
+                    'protected' => true,
122
+                ];
123
+            if ($this->canWrite()) {
124
+                $acl[] = [
125
+                    'privilege' => '{DAV:}write',
126
+                    'principal' => parent::getOwner(),
127
+                    'protected' => true,
128
+                ];
129
+            }
130
+        }
131
+        if ($this->isPublic()) {
132
+            $acl[] = [
133
+                'privilege' => '{DAV:}read',
134
+                'principal' => 'principals/system/public',
135
+                'protected' => true,
136
+            ];
137
+        }
138
+
139
+        /** @var CalDavBackend $calDavBackend */
140
+        $calDavBackend = $this->caldavBackend;
141
+        return $calDavBackend->applyShareAcl($this->getResourceId(), $acl);
142
+    }
143
+
144
+    function getChildACL() {
145
+        return $this->getACL();
146
+    }
147
+
148
+    function getOwner() {
149
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
150
+            return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'];
151
+        }
152
+        return parent::getOwner();
153
+    }
154
+
155
+    function delete() {
156
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) &&
157
+            $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) {
158
+            $principal = 'principal:' . parent::getOwner();
159
+            $shares = $this->getShares();
160
+            $shares = array_filter($shares, function($share) use ($principal){
161
+                return $share['href'] === $principal;
162
+            });
163
+            if (empty($shares)) {
164
+                throw new Forbidden();
165
+            }
166
+
167
+            /** @var CalDavBackend $calDavBackend */
168
+            $calDavBackend = $this->caldavBackend;
169
+            $calDavBackend->updateShares($this, [], [
170
+                'href' => $principal
171
+            ]);
172
+            return;
173
+        }
174
+        parent::delete();
175
+    }
176
+
177
+    function propPatch(PropPatch $propPatch) {
178
+        // parent::propPatch will only update calendars table
179
+        // if calendar is shared, changes have to be made to the properties table
180
+        if (!$this->isShared()) {
181
+            parent::propPatch($propPatch);
182
+        }
183
+    }
184
+
185
+    function getChild($name) {
186
+
187
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
188
+
189
+        if (!$obj) {
190
+            throw new NotFound('Calendar object not found');
191
+        }
192
+
193
+        if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
194
+            throw new NotFound('Calendar object not found');
195
+        }
196
+
197
+        $obj['acl'] = $this->getChildACL();
198
+
199
+        return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
200
+
201
+    }
202
+
203
+    function getChildren() {
204
+
205
+        $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']);
206
+        $children = [];
207
+        foreach ($objs as $obj) {
208
+            if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
209
+                continue;
210
+            }
211
+            $obj['acl'] = $this->getChildACL();
212
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
213
+        }
214
+        return $children;
215
+
216
+    }
217
+
218
+    function getMultipleChildren(array $paths) {
219
+
220
+        $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths);
221
+        $children = [];
222
+        foreach ($objs as $obj) {
223
+            if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
224
+                continue;
225
+            }
226
+            $obj['acl'] = $this->getChildACL();
227
+            $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj);
228
+        }
229
+        return $children;
230
+
231
+    }
232
+
233
+    function childExists($name) {
234
+        $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name);
235
+        if (!$obj) {
236
+            return false;
237
+        }
238
+        if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) {
239
+            return false;
240
+        }
241
+
242
+        return true;
243
+    }
244
+
245
+    function calendarQuery(array $filters) {
246
+
247
+        $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters);
248
+        if ($this->isShared()) {
249
+            return array_filter($uris, function ($uri) {
250
+                return $this->childExists($uri);
251
+            });
252
+        }
253
+
254
+        return $uris;
255
+    }
256
+
257
+    /**
258
+     * @param boolean $value
259
+     * @return string|null
260
+     */
261
+    function setPublishStatus($value) {
262
+        $publicUri = $this->caldavBackend->setPublishStatus($value, $this);
263
+        $this->calendarInfo['publicuri'] = $publicUri;
264
+        return $publicUri;
265
+    }
266
+
267
+    /**
268
+     * @return mixed $value
269
+     */
270
+    function getPublishStatus() {
271
+        return $this->caldavBackend->getPublishStatus($this);
272
+    }
273
+
274
+    private function canWrite() {
275
+        if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) {
276
+            return !$this->calendarInfo['{http://owncloud.org/ns}read-only'];
277
+        }
278
+        return true;
279
+    }
280
+
281
+    private function isPublic() {
282
+        return isset($this->calendarInfo['{http://owncloud.org/ns}public']);
283
+    }
284
+
285
+    protected function isShared() {
286
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
287
+            return false;
288
+        }
289
+
290
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
291
+    }
292
+
293
+    public function isSubscription() {
294
+        return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']);
295
+    }
296 296
 
297 297
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/CalendarHome.php 2 patches
Indentation   +66 added lines, -66 removed lines patch added patch discarded remove patch
@@ -33,82 +33,82 @@
 block discarded – undo
33 33
 
34 34
 class CalendarHome extends \Sabre\CalDAV\CalendarHome {
35 35
 
36
-	/** @var \OCP\IL10N */
37
-	private $l10n;
36
+    /** @var \OCP\IL10N */
37
+    private $l10n;
38 38
 
39
-	public function __construct(BackendInterface $caldavBackend, $principalInfo) {
40
-		parent::__construct($caldavBackend, $principalInfo);
41
-		$this->l10n = \OC::$server->getL10N('dav');
42
-	}
39
+    public function __construct(BackendInterface $caldavBackend, $principalInfo) {
40
+        parent::__construct($caldavBackend, $principalInfo);
41
+        $this->l10n = \OC::$server->getL10N('dav');
42
+    }
43 43
 
44
-	/**
45
-	 * @return BackendInterface
46
-	 */
47
-	public function getCalDAVBackend() {
48
-		return $this->caldavBackend;
49
-	}
44
+    /**
45
+     * @return BackendInterface
46
+     */
47
+    public function getCalDAVBackend() {
48
+        return $this->caldavBackend;
49
+    }
50 50
 
51
-	/**
52
-	 * @inheritdoc
53
-	 */
54
-	function getChildren() {
55
-		$calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
56
-		$objects = [];
57
-		foreach ($calendars as $calendar) {
58
-			$objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
59
-		}
51
+    /**
52
+     * @inheritdoc
53
+     */
54
+    function getChildren() {
55
+        $calendars = $this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']);
56
+        $objects = [];
57
+        foreach ($calendars as $calendar) {
58
+            $objects[] = new Calendar($this->caldavBackend, $calendar, $this->l10n);
59
+        }
60 60
 
61
-		if ($this->caldavBackend instanceof SchedulingSupport) {
62
-			$objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
63
-			$objects[] = new Outbox($this->principalInfo['uri']);
64
-		}
61
+        if ($this->caldavBackend instanceof SchedulingSupport) {
62
+            $objects[] = new Inbox($this->caldavBackend, $this->principalInfo['uri']);
63
+            $objects[] = new Outbox($this->principalInfo['uri']);
64
+        }
65 65
 
66
-		// We're adding a notifications node, if it's supported by the backend.
67
-		if ($this->caldavBackend instanceof NotificationSupport) {
68
-			$objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
69
-		}
66
+        // We're adding a notifications node, if it's supported by the backend.
67
+        if ($this->caldavBackend instanceof NotificationSupport) {
68
+            $objects[] = new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
69
+        }
70 70
 
71
-		// If the backend supports subscriptions, we'll add those as well,
72
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
73
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
74
-				$objects[] = new Subscription($this->caldavBackend, $subscription);
75
-			}
76
-		}
71
+        // If the backend supports subscriptions, we'll add those as well,
72
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
73
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
74
+                $objects[] = new Subscription($this->caldavBackend, $subscription);
75
+            }
76
+        }
77 77
 
78
-		return $objects;
79
-	}
78
+        return $objects;
79
+    }
80 80
 
81
-	/**
82
-	 * @inheritdoc
83
-	 */
84
-	function getChild($name) {
85
-		// Special nodes
86
-		if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
87
-			return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
88
-		}
89
-		if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
90
-			return new Outbox($this->principalInfo['uri']);
91
-		}
92
-		if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
93
-			return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
94
-		}
81
+    /**
82
+     * @inheritdoc
83
+     */
84
+    function getChild($name) {
85
+        // Special nodes
86
+        if ($name === 'inbox' && $this->caldavBackend instanceof SchedulingSupport) {
87
+            return new Inbox($this->caldavBackend, $this->principalInfo['uri']);
88
+        }
89
+        if ($name === 'outbox' && $this->caldavBackend instanceof SchedulingSupport) {
90
+            return new Outbox($this->principalInfo['uri']);
91
+        }
92
+        if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
93
+            return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
94
+        }
95 95
 
96
-		// Calendars
97
-		foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
98
-			if ($calendar['uri'] === $name) {
99
-				return new Calendar($this->caldavBackend, $calendar, $this->l10n);
100
-			}
101
-		}
96
+        // Calendars
97
+        foreach ($this->caldavBackend->getCalendarsForUser($this->principalInfo['uri']) as $calendar) {
98
+            if ($calendar['uri'] === $name) {
99
+                return new Calendar($this->caldavBackend, $calendar, $this->l10n);
100
+            }
101
+        }
102 102
 
103
-		if ($this->caldavBackend instanceof SubscriptionSupport) {
104
-			foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
105
-				if ($subscription['uri'] === $name) {
106
-					return new Subscription($this->caldavBackend, $subscription);
107
-				}
108
-			}
103
+        if ($this->caldavBackend instanceof SubscriptionSupport) {
104
+            foreach ($this->caldavBackend->getSubscriptionsForUser($this->principalInfo['uri']) as $subscription) {
105
+                if ($subscription['uri'] === $name) {
106
+                    return new Subscription($this->caldavBackend, $subscription);
107
+                }
108
+            }
109 109
 
110
-		}
110
+        }
111 111
 
112
-		throw new NotFound('Node with name \'' . $name . '\' could not be found');
113
-	}
112
+        throw new NotFound('Node with name \'' . $name . '\' could not be found');
113
+    }
114 114
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -109,6 +109,6 @@
 block discarded – undo
109 109
 
110 110
 		}
111 111
 
112
-		throw new NotFound('Node with name \'' . $name . '\' could not be found');
112
+		throw new NotFound('Node with name \''.$name.'\' could not be found');
113 113
 	}
114 114
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Plugin.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -25,17 +25,17 @@
 block discarded – undo
25 25
 
26 26
 class Plugin extends \Sabre\CalDAV\Plugin {
27 27
 
28
-	/**
29
-	 * @inheritdoc
30
-	 */
31
-	function getCalendarHomeForPrincipal($principalUrl) {
28
+    /**
29
+     * @inheritdoc
30
+     */
31
+    function getCalendarHomeForPrincipal($principalUrl) {
32 32
 
33
-		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
34
-			list(, $principalId) = URLUtil::splitPath($principalUrl);
35
-			return self::CALENDAR_ROOT .'/' . $principalId;
36
-		}
33
+        if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
34
+            list(, $principalId) = URLUtil::splitPath($principalUrl);
35
+            return self::CALENDAR_ROOT .'/' . $principalId;
36
+        }
37 37
 
38
-		return;
39
-	}
38
+        return;
39
+    }
40 40
 
41 41
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
 
33 33
 		if (strrpos($principalUrl, 'principals/users', -strlen($principalUrl)) !== false) {
34 34
 			list(, $principalId) = URLUtil::splitPath($principalUrl);
35
-			return self::CALENDAR_ROOT .'/' . $principalId;
35
+			return self::CALENDAR_ROOT.'/'.$principalId;
36 36
 		}
37 37
 
38 38
 		return;
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/CalendarObject.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -61,19 +61,19 @@
 block discarded – undo
61 61
 
62 62
 		/** @var Component $vElement */
63 63
 		$vElement = null;
64
-		if(isset($vObject->VEVENT)) {
64
+		if (isset($vObject->VEVENT)) {
65 65
 			$vElement = $vObject->VEVENT;
66 66
 		}
67
-		if(isset($vObject->VJOURNAL)) {
67
+		if (isset($vObject->VJOURNAL)) {
68 68
 			$vElement = $vObject->VJOURNAL;
69 69
 		}
70
-		if(isset($vObject->VTODO)) {
70
+		if (isset($vObject->VTODO)) {
71 71
 			$vElement = $vObject->VTODO;
72 72
 		}
73
-		if(!is_null($vElement)) {
73
+		if (!is_null($vElement)) {
74 74
 			foreach ($vElement->children() as &$property) {
75 75
 				/** @var Property $property */
76
-				switch($property->name) {
76
+				switch ($property->name) {
77 77
 					case 'CREATED':
78 78
 					case 'DTSTART':
79 79
 					case 'RRULE':
Please login to merge, or discard this patch.
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
 
33 33
 class CalendarObject extends \Sabre\CalDAV\CalendarObject {
34 34
 
35
-	/**
36
-	 * @inheritdoc
37
-	 */
38
-	function get() {
39
-		$data = parent::get();
40
-		if ($this->isShared() && $this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) {
41
-			return $this->createConfidentialObject($data);
42
-		}
43
-		return $data;
44
-	}
35
+    /**
36
+     * @inheritdoc
37
+     */
38
+    function get() {
39
+        $data = parent::get();
40
+        if ($this->isShared() && $this->objectData['classification'] === CalDavBackend::CLASSIFICATION_CONFIDENTIAL) {
41
+            return $this->createConfidentialObject($data);
42
+        }
43
+        return $data;
44
+    }
45 45
 
46
-	protected function isShared() {
47
-		if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
48
-			return false;
49
-		}
46
+    protected function isShared() {
47
+        if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) {
48
+            return false;
49
+        }
50 50
 
51
-		return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
52
-	}
51
+        return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri'];
52
+    }
53 53
 
54
-	/**
55
-	 * @param string $calData
56
-	 * @return string
57
-	 */
58
-	private static function createConfidentialObject($calData) {
54
+    /**
55
+     * @param string $calData
56
+     * @return string
57
+     */
58
+    private static function createConfidentialObject($calData) {
59 59
 
60
-		$vObject = Reader::read($calData);
60
+        $vObject = Reader::read($calData);
61 61
 
62
-		/** @var Component $vElement */
63
-		$vElement = null;
64
-		if(isset($vObject->VEVENT)) {
65
-			$vElement = $vObject->VEVENT;
66
-		}
67
-		if(isset($vObject->VJOURNAL)) {
68
-			$vElement = $vObject->VJOURNAL;
69
-		}
70
-		if(isset($vObject->VTODO)) {
71
-			$vElement = $vObject->VTODO;
72
-		}
73
-		if(!is_null($vElement)) {
74
-			foreach ($vElement->children() as &$property) {
75
-				/** @var Property $property */
76
-				switch($property->name) {
77
-					case 'CREATED':
78
-					case 'DTSTART':
79
-					case 'RRULE':
80
-					case 'DURATION':
81
-					case 'DTEND':
82
-					case 'CLASS':
83
-					case 'UID':
84
-						break;
85
-					case 'SUMMARY':
86
-						$property->setValue('Busy');
87
-						break;
88
-					default:
89
-						$vElement->__unset($property->name);
90
-						unset($property);
91
-						break;
92
-				}
93
-			}
94
-		}
62
+        /** @var Component $vElement */
63
+        $vElement = null;
64
+        if(isset($vObject->VEVENT)) {
65
+            $vElement = $vObject->VEVENT;
66
+        }
67
+        if(isset($vObject->VJOURNAL)) {
68
+            $vElement = $vObject->VJOURNAL;
69
+        }
70
+        if(isset($vObject->VTODO)) {
71
+            $vElement = $vObject->VTODO;
72
+        }
73
+        if(!is_null($vElement)) {
74
+            foreach ($vElement->children() as &$property) {
75
+                /** @var Property $property */
76
+                switch($property->name) {
77
+                    case 'CREATED':
78
+                    case 'DTSTART':
79
+                    case 'RRULE':
80
+                    case 'DURATION':
81
+                    case 'DTEND':
82
+                    case 'CLASS':
83
+                    case 'UID':
84
+                        break;
85
+                    case 'SUMMARY':
86
+                        $property->setValue('Busy');
87
+                        break;
88
+                    default:
89
+                        $vElement->__unset($property->name);
90
+                        unset($property);
91
+                        break;
92
+                }
93
+            }
94
+        }
95 95
 		
96
-		return $vObject->serialize();
97
-	}
96
+        return $vObject->serialize();
97
+    }
98 98
 
99 99
 }
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/BirthdayService.php 2 patches
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -39,256 +39,256 @@
 block discarded – undo
39 39
 
40 40
 class BirthdayService {
41 41
 
42
-	const BIRTHDAY_CALENDAR_URI = 'contact_birthdays';
42
+    const BIRTHDAY_CALENDAR_URI = 'contact_birthdays';
43 43
 
44
-	/** @var GroupPrincipalBackend */
45
-	private $principalBackend;
44
+    /** @var GroupPrincipalBackend */
45
+    private $principalBackend;
46 46
 
47
-	/** @var CalDavBackend  */
48
-	private $calDavBackEnd;
47
+    /** @var CalDavBackend  */
48
+    private $calDavBackEnd;
49 49
 
50
-	/** @var CardDavBackend  */
51
-	private $cardDavBackEnd;
50
+    /** @var CardDavBackend  */
51
+    private $cardDavBackEnd;
52 52
 
53
-	/**
54
-	 * BirthdayService constructor.
55
-	 *
56
-	 * @param CalDavBackend $calDavBackEnd
57
-	 * @param CardDavBackend $cardDavBackEnd
58
-	 * @param GroupPrincipalBackend $principalBackend
59
-	 */
60
-	public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend) {
61
-		$this->calDavBackEnd = $calDavBackEnd;
62
-		$this->cardDavBackEnd = $cardDavBackEnd;
63
-		$this->principalBackend = $principalBackend;
64
-	}
53
+    /**
54
+     * BirthdayService constructor.
55
+     *
56
+     * @param CalDavBackend $calDavBackEnd
57
+     * @param CardDavBackend $cardDavBackEnd
58
+     * @param GroupPrincipalBackend $principalBackend
59
+     */
60
+    public function __construct(CalDavBackend $calDavBackEnd, CardDavBackend $cardDavBackEnd, GroupPrincipalBackend $principalBackend) {
61
+        $this->calDavBackEnd = $calDavBackEnd;
62
+        $this->cardDavBackEnd = $cardDavBackEnd;
63
+        $this->principalBackend = $principalBackend;
64
+    }
65 65
 
66
-	/**
67
-	 * @param int $addressBookId
68
-	 * @param string $cardUri
69
-	 * @param string $cardData
70
-	 */
71
-	public function onCardChanged($addressBookId, $cardUri, $cardData) {
72
-		$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
66
+    /**
67
+     * @param int $addressBookId
68
+     * @param string $cardUri
69
+     * @param string $cardData
70
+     */
71
+    public function onCardChanged($addressBookId, $cardUri, $cardData) {
72
+        $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
73 73
 		
74
-		$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
75
-		$targetPrincipals[] = $book['principaluri'];
76
-		$datesToSync = [
77
-			['postfix' => '', 'field' => 'BDAY', 'symbol' => '*'],
78
-			['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†"],
79
-			['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
80
-		];
81
-		foreach ($targetPrincipals as $principalUri) {
82
-			$calendar = $this->ensureCalendarExists($principalUri);
83
-			foreach ($datesToSync as $type) {
84
-				$this->updateCalendar($cardUri, $cardData, $book, $calendar['id'], $type);
85
-			}
86
-		}
87
-	}
74
+        $book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
75
+        $targetPrincipals[] = $book['principaluri'];
76
+        $datesToSync = [
77
+            ['postfix' => '', 'field' => 'BDAY', 'symbol' => '*'],
78
+            ['postfix' => '-death', 'field' => 'DEATHDATE', 'symbol' => "†"],
79
+            ['postfix' => '-anniversary', 'field' => 'ANNIVERSARY', 'symbol' => "⚭"],
80
+        ];
81
+        foreach ($targetPrincipals as $principalUri) {
82
+            $calendar = $this->ensureCalendarExists($principalUri);
83
+            foreach ($datesToSync as $type) {
84
+                $this->updateCalendar($cardUri, $cardData, $book, $calendar['id'], $type);
85
+            }
86
+        }
87
+    }
88 88
 
89
-	/**
90
-	 * @param int $addressBookId
91
-	 * @param string $cardUri
92
-	 */
93
-	public function onCardDeleted($addressBookId, $cardUri) {
94
-		$targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
95
-		$book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
96
-		$targetPrincipals[] = $book['principaluri'];
97
-		foreach ($targetPrincipals as $principalUri) {
98
-			$calendar = $this->ensureCalendarExists($principalUri);
99
-			foreach (['', '-death', '-anniversary'] as $tag) {
100
-				$objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
101
-				$this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
102
-			}
103
-		}
104
-	}
89
+    /**
90
+     * @param int $addressBookId
91
+     * @param string $cardUri
92
+     */
93
+    public function onCardDeleted($addressBookId, $cardUri) {
94
+        $targetPrincipals = $this->getAllAffectedPrincipals($addressBookId);
95
+        $book = $this->cardDavBackEnd->getAddressBookById($addressBookId);
96
+        $targetPrincipals[] = $book['principaluri'];
97
+        foreach ($targetPrincipals as $principalUri) {
98
+            $calendar = $this->ensureCalendarExists($principalUri);
99
+            foreach (['', '-death', '-anniversary'] as $tag) {
100
+                $objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
101
+                $this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
102
+            }
103
+        }
104
+    }
105 105
 
106
-	/**
107
-	 * @param string $principal
108
-	 * @return array|null
109
-	 * @throws \Sabre\DAV\Exception\BadRequest
110
-	 */
111
-	public function ensureCalendarExists($principal) {
112
-		$book = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
113
-		if (!is_null($book)) {
114
-			return $book;
115
-		}
116
-		$this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [
117
-			'{DAV:}displayname' => 'Contact birthdays',
118
-			'{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA',
119
-			'components'   => 'VEVENT',
120
-		]);
106
+    /**
107
+     * @param string $principal
108
+     * @return array|null
109
+     * @throws \Sabre\DAV\Exception\BadRequest
110
+     */
111
+    public function ensureCalendarExists($principal) {
112
+        $book = $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
113
+        if (!is_null($book)) {
114
+            return $book;
115
+        }
116
+        $this->calDavBackEnd->createCalendar($principal, self::BIRTHDAY_CALENDAR_URI, [
117
+            '{DAV:}displayname' => 'Contact birthdays',
118
+            '{http://apple.com/ns/ical/}calendar-color' => '#FFFFCA',
119
+            'components'   => 'VEVENT',
120
+        ]);
121 121
 
122
-		return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
123
-	}
122
+        return $this->calDavBackEnd->getCalendarByUri($principal, self::BIRTHDAY_CALENDAR_URI);
123
+    }
124 124
 
125
-	/**
126
-	 * @param string $cardData
127
-	 * @param string $dateField
128
-	 * @param string $summarySymbol
129
-	 * @return null|VCalendar
130
-	 */
131
-	public function buildDateFromContact($cardData, $dateField, $summarySymbol) {
132
-		if (empty($cardData)) {
133
-			return null;
134
-		}
135
-		try {
136
-			$doc = Reader::read($cardData);
137
-			// We're always converting to vCard 4.0 so we can rely on the
138
-			// VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
139
-			if (!$doc instanceof VCard) {
140
-				return null;
141
-			}
142
-			$doc = $doc->convert(Document::VCARD40);
143
-		} catch (Exception $e) {
144
-			return null;
145
-		}
125
+    /**
126
+     * @param string $cardData
127
+     * @param string $dateField
128
+     * @param string $summarySymbol
129
+     * @return null|VCalendar
130
+     */
131
+    public function buildDateFromContact($cardData, $dateField, $summarySymbol) {
132
+        if (empty($cardData)) {
133
+            return null;
134
+        }
135
+        try {
136
+            $doc = Reader::read($cardData);
137
+            // We're always converting to vCard 4.0 so we can rely on the
138
+            // VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
139
+            if (!$doc instanceof VCard) {
140
+                return null;
141
+            }
142
+            $doc = $doc->convert(Document::VCARD40);
143
+        } catch (Exception $e) {
144
+            return null;
145
+        }
146 146
 
147
-		if (!isset($doc->{$dateField})) {
148
-			return null;
149
-		}
150
-		if (!isset($doc->FN)) {
151
-			return null;
152
-		}
153
-		$birthday = $doc->{$dateField};
154
-		if (!(string)$birthday) {
155
-			return null;
156
-		}
157
-		// Skip if the BDAY property is not of the right type.
158
-		if (!$birthday instanceof DateAndOrTime) {
159
-			return null;
160
-		}
147
+        if (!isset($doc->{$dateField})) {
148
+            return null;
149
+        }
150
+        if (!isset($doc->FN)) {
151
+            return null;
152
+        }
153
+        $birthday = $doc->{$dateField};
154
+        if (!(string)$birthday) {
155
+            return null;
156
+        }
157
+        // Skip if the BDAY property is not of the right type.
158
+        if (!$birthday instanceof DateAndOrTime) {
159
+            return null;
160
+        }
161 161
 
162
-		// Skip if we can't parse the BDAY value.
163
-		try {
164
-			$dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
165
-		} catch (InvalidDataException $e) {
166
-			return null;
167
-		}
162
+        // Skip if we can't parse the BDAY value.
163
+        try {
164
+            $dateParts = DateTimeParser::parseVCardDateTime($birthday->getValue());
165
+        } catch (InvalidDataException $e) {
166
+            return null;
167
+        }
168 168
 
169
-		$unknownYear = false;
170
-		if (!$dateParts['year']) {
171
-			$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
169
+        $unknownYear = false;
170
+        if (!$dateParts['year']) {
171
+            $birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
172 172
 
173
-			$unknownYear = true;
174
-		}
173
+            $unknownYear = true;
174
+        }
175 175
 
176
-		try {
177
-			$date = new \DateTime($birthday);
178
-		} catch (Exception $e) {
179
-			return null;
180
-		}
181
-		if ($unknownYear) {
182
-			$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
183
-		} else {
184
-			$year = (int)$date->format('Y');
185
-			$summary = $doc->FN->getValue() . " ($summarySymbol$year)";
186
-		}
187
-		$vCal = new VCalendar();
188
-		$vCal->VERSION = '2.0';
189
-		$vEvent = $vCal->createComponent('VEVENT');
190
-		$vEvent->add('DTSTART');
191
-		$vEvent->DTSTART->setDateTime(
192
-			$date
193
-		);
194
-		$vEvent->DTSTART['VALUE'] = 'DATE';
195
-		$vEvent->add('DTEND');
196
-		$date->add(new \DateInterval('P1D'));
197
-		$vEvent->DTEND->setDateTime(
198
-			$date
199
-		);
200
-		$vEvent->DTEND['VALUE'] = 'DATE';
201
-		$vEvent->{'UID'} = $doc->UID;
202
-		$vEvent->{'RRULE'} = 'FREQ=YEARLY';
203
-		$vEvent->{'SUMMARY'} = $summary;
204
-		$vEvent->{'TRANSP'} = 'TRANSPARENT';
205
-		$alarm = $vCal->createComponent('VALARM');
206
-		$alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
207
-		$alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
208
-		$alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
209
-		$vEvent->add($alarm);
210
-		$vCal->add($vEvent);
211
-		return $vCal;
212
-	}
176
+        try {
177
+            $date = new \DateTime($birthday);
178
+        } catch (Exception $e) {
179
+            return null;
180
+        }
181
+        if ($unknownYear) {
182
+            $summary = $doc->FN->getValue() . ' ' . $summarySymbol;
183
+        } else {
184
+            $year = (int)$date->format('Y');
185
+            $summary = $doc->FN->getValue() . " ($summarySymbol$year)";
186
+        }
187
+        $vCal = new VCalendar();
188
+        $vCal->VERSION = '2.0';
189
+        $vEvent = $vCal->createComponent('VEVENT');
190
+        $vEvent->add('DTSTART');
191
+        $vEvent->DTSTART->setDateTime(
192
+            $date
193
+        );
194
+        $vEvent->DTSTART['VALUE'] = 'DATE';
195
+        $vEvent->add('DTEND');
196
+        $date->add(new \DateInterval('P1D'));
197
+        $vEvent->DTEND->setDateTime(
198
+            $date
199
+        );
200
+        $vEvent->DTEND['VALUE'] = 'DATE';
201
+        $vEvent->{'UID'} = $doc->UID;
202
+        $vEvent->{'RRULE'} = 'FREQ=YEARLY';
203
+        $vEvent->{'SUMMARY'} = $summary;
204
+        $vEvent->{'TRANSP'} = 'TRANSPARENT';
205
+        $alarm = $vCal->createComponent('VALARM');
206
+        $alarm->add($vCal->createProperty('TRIGGER', '-PT0M', ['VALUE' => 'DURATION']));
207
+        $alarm->add($vCal->createProperty('ACTION', 'DISPLAY'));
208
+        $alarm->add($vCal->createProperty('DESCRIPTION', $vEvent->{'SUMMARY'}));
209
+        $vEvent->add($alarm);
210
+        $vCal->add($vEvent);
211
+        return $vCal;
212
+    }
213 213
 
214
-	/**
215
-	 * @param string $user
216
-	 */
217
-	public function syncUser($user) {
218
-		$principal = 'principals/users/'.$user;
219
-		$this->ensureCalendarExists($principal);
220
-		$books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
221
-		foreach($books as $book) {
222
-			$cards = $this->cardDavBackEnd->getCards($book['id']);
223
-			foreach($cards as $card) {
224
-				$this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
225
-			}
226
-		}
227
-	}
214
+    /**
215
+     * @param string $user
216
+     */
217
+    public function syncUser($user) {
218
+        $principal = 'principals/users/'.$user;
219
+        $this->ensureCalendarExists($principal);
220
+        $books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
221
+        foreach($books as $book) {
222
+            $cards = $this->cardDavBackEnd->getCards($book['id']);
223
+            foreach($cards as $card) {
224
+                $this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
225
+            }
226
+        }
227
+    }
228 228
 
229
-	/**
230
-	 * @param string $existingCalendarData
231
-	 * @param VCalendar $newCalendarData
232
-	 * @return bool
233
-	 */
234
-	public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
235
-		try {
236
-			$existingBirthday = Reader::read($existingCalendarData);
237
-		} catch (Exception $ex) {
238
-			return true;
239
-		}
240
-		if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
241
-			$newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
242
-		) {
243
-			return true;
244
-		}
245
-		return false;
246
-	}
229
+    /**
230
+     * @param string $existingCalendarData
231
+     * @param VCalendar $newCalendarData
232
+     * @return bool
233
+     */
234
+    public function birthdayEvenChanged($existingCalendarData, $newCalendarData) {
235
+        try {
236
+            $existingBirthday = Reader::read($existingCalendarData);
237
+        } catch (Exception $ex) {
238
+            return true;
239
+        }
240
+        if ($newCalendarData->VEVENT->DTSTART->getValue() !== $existingBirthday->VEVENT->DTSTART->getValue() ||
241
+            $newCalendarData->VEVENT->SUMMARY->getValue() !== $existingBirthday->VEVENT->SUMMARY->getValue()
242
+        ) {
243
+            return true;
244
+        }
245
+        return false;
246
+    }
247 247
 
248
-	/**
249
-	 * @param integer $addressBookId
250
-	 * @return mixed
251
-	 */
252
-	protected function getAllAffectedPrincipals($addressBookId) {
253
-		$targetPrincipals = [];
254
-		$shares = $this->cardDavBackEnd->getShares($addressBookId);
255
-		foreach ($shares as $share) {
256
-			if ($share['{http://owncloud.org/ns}group-share']) {
257
-				$users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
258
-				foreach ($users as $user) {
259
-					$targetPrincipals[] = $user['uri'];
260
-				}
261
-			} else {
262
-				$targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
263
-			}
264
-		}
265
-		return array_values(array_unique($targetPrincipals, SORT_STRING));
266
-	}
248
+    /**
249
+     * @param integer $addressBookId
250
+     * @return mixed
251
+     */
252
+    protected function getAllAffectedPrincipals($addressBookId) {
253
+        $targetPrincipals = [];
254
+        $shares = $this->cardDavBackEnd->getShares($addressBookId);
255
+        foreach ($shares as $share) {
256
+            if ($share['{http://owncloud.org/ns}group-share']) {
257
+                $users = $this->principalBackend->getGroupMemberSet($share['{http://owncloud.org/ns}principal']);
258
+                foreach ($users as $user) {
259
+                    $targetPrincipals[] = $user['uri'];
260
+                }
261
+            } else {
262
+                $targetPrincipals[] = $share['{http://owncloud.org/ns}principal'];
263
+            }
264
+        }
265
+        return array_values(array_unique($targetPrincipals, SORT_STRING));
266
+    }
267 267
 
268
-	/**
269
-	 * @param string $cardUri
270
-	 * @param string  $cardData
271
-	 * @param array $book
272
-	 * @param int $calendarId
273
-	 * @param string $type
274
-	 */
275
-	private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
276
-		$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
277
-		$calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['symbol']);
278
-		$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
279
-		if (is_null($calendarData)) {
280
-			if (!is_null($existing)) {
281
-				$this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
282
-			}
283
-		} else {
284
-			if (is_null($existing)) {
285
-				$this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
286
-			} else {
287
-				if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
288
-					$this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
289
-				}
290
-			}
291
-		}
292
-	}
268
+    /**
269
+     * @param string $cardUri
270
+     * @param string  $cardData
271
+     * @param array $book
272
+     * @param int $calendarId
273
+     * @param string $type
274
+     */
275
+    private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
276
+        $objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
277
+        $calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['symbol']);
278
+        $existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
279
+        if (is_null($calendarData)) {
280
+            if (!is_null($existing)) {
281
+                $this->calDavBackEnd->deleteCalendarObject($calendarId, $objectUri);
282
+            }
283
+        } else {
284
+            if (is_null($existing)) {
285
+                $this->calDavBackEnd->createCalendarObject($calendarId, $objectUri, $calendarData->serialize());
286
+            } else {
287
+                if ($this->birthdayEvenChanged($existing['calendardata'], $calendarData)) {
288
+                    $this->calDavBackEnd->updateCalendarObject($calendarId, $objectUri, $calendarData->serialize());
289
+                }
290
+            }
291
+        }
292
+    }
293 293
 
294 294
 }
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		foreach ($targetPrincipals as $principalUri) {
98 98
 			$calendar = $this->ensureCalendarExists($principalUri);
99 99
 			foreach (['', '-death', '-anniversary'] as $tag) {
100
-				$objectUri = $book['uri'] . '-' . $cardUri . $tag .'.ics';
100
+				$objectUri = $book['uri'].'-'.$cardUri.$tag.'.ics';
101 101
 				$this->calDavBackEnd->deleteCalendarObject($calendar['id'], $objectUri);
102 102
 			}
103 103
 		}
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
 			return null;
152 152
 		}
153 153
 		$birthday = $doc->{$dateField};
154
-		if (!(string)$birthday) {
154
+		if (!(string) $birthday) {
155 155
 			return null;
156 156
 		}
157 157
 		// Skip if the BDAY property is not of the right type.
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 
169 169
 		$unknownYear = false;
170 170
 		if (!$dateParts['year']) {
171
-			$birthday = '1900-' . $dateParts['month'] . '-' . $dateParts['date'];
171
+			$birthday = '1900-'.$dateParts['month'].'-'.$dateParts['date'];
172 172
 
173 173
 			$unknownYear = true;
174 174
 		}
@@ -179,10 +179,10 @@  discard block
 block discarded – undo
179 179
 			return null;
180 180
 		}
181 181
 		if ($unknownYear) {
182
-			$summary = $doc->FN->getValue() . ' ' . $summarySymbol;
182
+			$summary = $doc->FN->getValue().' '.$summarySymbol;
183 183
 		} else {
184
-			$year = (int)$date->format('Y');
185
-			$summary = $doc->FN->getValue() . " ($summarySymbol$year)";
184
+			$year = (int) $date->format('Y');
185
+			$summary = $doc->FN->getValue()." ($summarySymbol$year)";
186 186
 		}
187 187
 		$vCal = new VCalendar();
188 188
 		$vCal->VERSION = '2.0';
@@ -218,9 +218,9 @@  discard block
 block discarded – undo
218 218
 		$principal = 'principals/users/'.$user;
219 219
 		$this->ensureCalendarExists($principal);
220 220
 		$books = $this->cardDavBackEnd->getAddressBooksForUser($principal);
221
-		foreach($books as $book) {
221
+		foreach ($books as $book) {
222 222
 			$cards = $this->cardDavBackEnd->getCards($book['id']);
223
-			foreach($cards as $card) {
223
+			foreach ($cards as $card) {
224 224
 				$this->onCardChanged($book['id'], $card['uri'], $card['carddata']);
225 225
 			}
226 226
 		}
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	 * @param string $type
274 274
 	 */
275 275
 	private function updateCalendar($cardUri, $cardData, $book, $calendarId, $type) {
276
-		$objectUri = $book['uri'] . '-' . $cardUri . $type['postfix'] . '.ics';
276
+		$objectUri = $book['uri'].'-'.$cardUri.$type['postfix'].'.ics';
277 277
 		$calendarData = $this->buildDateFromContact($cardData, $type['field'], $type['symbol']);
278 278
 		$existing = $this->calDavBackEnd->getCalendarObject($calendarId, $objectUri);
279 279
 		if (is_null($calendarData)) {
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Schedule/Plugin.php 2 patches
Indentation   +55 added lines, -55 removed lines patch added patch discarded remove patch
@@ -34,68 +34,68 @@
 block discarded – undo
34 34
 
35 35
 class Plugin extends \Sabre\CalDAV\Schedule\Plugin {
36 36
 
37
-	/**
38
-	 * Initializes the plugin
39
-	 *
40
-	 * @param Server $server
41
-	 * @return void
42
-	 */
43
-	function initialize(Server $server) {
44
-		parent::initialize($server);
45
-		$server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
46
-	}
37
+    /**
38
+     * Initializes the plugin
39
+     *
40
+     * @param Server $server
41
+     * @return void
42
+     */
43
+    function initialize(Server $server) {
44
+        parent::initialize($server);
45
+        $server->on('propFind', [$this, 'propFindDefaultCalendarUrl'], 90);
46
+    }
47 47
 
48
-	/**
49
-	 * Returns a list of addresses that are associated with a principal.
50
-	 *
51
-	 * @param string $principal
52
-	 * @return array
53
-	 */
54
-	protected function getAddressesForPrincipal($principal) {
55
-		$result = parent::getAddressesForPrincipal($principal);
48
+    /**
49
+     * Returns a list of addresses that are associated with a principal.
50
+     *
51
+     * @param string $principal
52
+     * @return array
53
+     */
54
+    protected function getAddressesForPrincipal($principal) {
55
+        $result = parent::getAddressesForPrincipal($principal);
56 56
 
57
-		if ($result === null) {
58
-			$result = [];
59
-		}
57
+        if ($result === null) {
58
+            $result = [];
59
+        }
60 60
 
61
-		return $result;
62
-	}
61
+        return $result;
62
+    }
63 63
 
64
-	/**
65
-	 * Always use the personal calendar as target for scheduled events
66
-	 *
67
-	 * @param PropFind $propFind
68
-	 * @param INode $node
69
-	 * @return void
70
-	 */
71
-	function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
72
-		if ($node instanceof IPrincipal) {
73
-			$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
74
-				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
75
-				$caldavPlugin = $this->server->getPlugin('caldav');
76
-				$principalUrl = $node->getPrincipalUrl();
64
+    /**
65
+     * Always use the personal calendar as target for scheduled events
66
+     *
67
+     * @param PropFind $propFind
68
+     * @param INode $node
69
+     * @return void
70
+     */
71
+    function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
72
+        if ($node instanceof IPrincipal) {
73
+            $propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
74
+                /** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
75
+                $caldavPlugin = $this->server->getPlugin('caldav');
76
+                $principalUrl = $node->getPrincipalUrl();
77 77
 
78
-				$calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
78
+                $calendarHomePath = $caldavPlugin->getCalendarHomeForPrincipal($principalUrl);
79 79
 
80
-				if (!$calendarHomePath) {
81
-					return null;
82
-				}
80
+                if (!$calendarHomePath) {
81
+                    return null;
82
+                }
83 83
 
84
-				/** @var CalendarHome $calendarHome */
85
-				$calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
86
-				if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
87
-					$calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
88
-						'{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
89
-					]);
90
-				}
84
+                /** @var CalendarHome $calendarHome */
85
+                $calendarHome = $this->server->tree->getNodeForPath($calendarHomePath);
86
+                if (!$calendarHome->childExists(CalDavBackend::PERSONAL_CALENDAR_URI)) {
87
+                    $calendarHome->getCalDAVBackend()->createCalendar($principalUrl, CalDavBackend::PERSONAL_CALENDAR_URI, [
88
+                        '{DAV:}displayname' => CalDavBackend::PERSONAL_CALENDAR_NAME,
89
+                    ]);
90
+                }
91 91
 
92
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
93
-				if (empty($result)) {
94
-					return null;
95
-				}
92
+                $result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
93
+                if (empty($result)) {
94
+                    return null;
95
+                }
96 96
 
97
-				return new LocalHref($result[0]['href']);
98
-			});
99
-		}
100
-	}
97
+                return new LocalHref($result[0]['href']);
98
+            });
99
+        }
100
+    }
101 101
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 	 */
71 71
 	function propFindDefaultCalendarUrl(PropFind $propFind, INode $node) {
72 72
 		if ($node instanceof IPrincipal) {
73
-			$propFind->handle('{' . self::NS_CALDAV . '}schedule-default-calendar-URL', function() use ($node) {
73
+			$propFind->handle('{'.self::NS_CALDAV.'}schedule-default-calendar-URL', function() use ($node) {
74 74
 				/** @var \OCA\DAV\CalDAV\Plugin $caldavPlugin */
75 75
 				$caldavPlugin = $this->server->getPlugin('caldav');
76 76
 				$principalUrl = $node->getPrincipalUrl();
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
 					]);
90 90
 				}
91 91
 
92
-				$result = $this->server->getPropertiesForPath($calendarHomePath . '/' . CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
92
+				$result = $this->server->getPropertiesForPath($calendarHomePath.'/'.CalDavBackend::PERSONAL_CALENDAR_URI, [], 1);
93 93
 				if (empty($result)) {
94 94
 					return null;
95 95
 				}
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/Schedule/IMipPlugin.php 2 patches
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -42,88 +42,88 @@
 block discarded – undo
42 42
  */
43 43
 class IMipPlugin extends SabreIMipPlugin {
44 44
 
45
-	/** @var IMailer */
46
-	private $mailer;
47
-
48
-	/** @var ILogger */
49
-	private $logger;
50
-
51
-	/**
52
-	 * Creates the email handler.
53
-	 *
54
-	 * @param IMailer $mailer
55
-	 */
56
-	function __construct(IMailer $mailer, ILogger $logger) {
57
-		parent::__construct('');
58
-		$this->mailer = $mailer;
59
-		$this->logger = $logger;
60
-	}
61
-
62
-	/**
63
-	 * Event handler for the 'schedule' event.
64
-	 *
65
-	 * @param ITip\Message $iTipMessage
66
-	 * @return void
67
-	 */
68
-	function schedule(ITip\Message $iTipMessage) {
69
-
70
-		// Not sending any emails if the system considers the update
71
-		// insignificant.
72
-		if (!$iTipMessage->significantChange) {
73
-			if (!$iTipMessage->scheduleStatus) {
74
-				$iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
75
-			}
76
-			return;
77
-		}
78
-
79
-		$summary = $iTipMessage->message->VEVENT->SUMMARY;
80
-
81
-		if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
82
-			return;
83
-		}
84
-
85
-		if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
86
-			return;
87
-		}
88
-
89
-		$sender = substr($iTipMessage->sender, 7);
90
-		$recipient = substr($iTipMessage->recipient, 7);
91
-
92
-		$senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null;
93
-		$recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null;
94
-
95
-		$subject = 'SabreDAV iTIP message';
96
-		switch (strtoupper($iTipMessage->method)) {
97
-			case 'REPLY' :
98
-				$subject = 'Re: ' . $summary;
99
-				break;
100
-			case 'REQUEST' :
101
-				$subject = $summary;
102
-				break;
103
-			case 'CANCEL' :
104
-				$subject = 'Cancelled: ' . $summary;
105
-				break;
106
-		}
107
-
108
-		$contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
109
-
110
-		$message = $this->mailer->createMessage();
111
-
112
-		$message->setReplyTo([$sender => $senderName])
113
-			->setTo([$recipient => $recipientName])
114
-			->setSubject($subject)
115
-			->setBody($iTipMessage->message->serialize(), $contentType);
116
-		try {
117
-			$failed = $this->mailer->send($message);
118
-			if ($failed) {
119
-				$this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' =>  implode(', ', $failed)]);
120
-				$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
121
-			}
122
-			$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
123
-		} catch(\Exception $ex) {
124
-			$this->logger->logException($ex, ['app' => 'dav']);
125
-			$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
126
-		}
127
-	}
45
+    /** @var IMailer */
46
+    private $mailer;
47
+
48
+    /** @var ILogger */
49
+    private $logger;
50
+
51
+    /**
52
+     * Creates the email handler.
53
+     *
54
+     * @param IMailer $mailer
55
+     */
56
+    function __construct(IMailer $mailer, ILogger $logger) {
57
+        parent::__construct('');
58
+        $this->mailer = $mailer;
59
+        $this->logger = $logger;
60
+    }
61
+
62
+    /**
63
+     * Event handler for the 'schedule' event.
64
+     *
65
+     * @param ITip\Message $iTipMessage
66
+     * @return void
67
+     */
68
+    function schedule(ITip\Message $iTipMessage) {
69
+
70
+        // Not sending any emails if the system considers the update
71
+        // insignificant.
72
+        if (!$iTipMessage->significantChange) {
73
+            if (!$iTipMessage->scheduleStatus) {
74
+                $iTipMessage->scheduleStatus = '1.0;We got the message, but it\'s not significant enough to warrant an email';
75
+            }
76
+            return;
77
+        }
78
+
79
+        $summary = $iTipMessage->message->VEVENT->SUMMARY;
80
+
81
+        if (parse_url($iTipMessage->sender, PHP_URL_SCHEME) !== 'mailto') {
82
+            return;
83
+        }
84
+
85
+        if (parse_url($iTipMessage->recipient, PHP_URL_SCHEME) !== 'mailto') {
86
+            return;
87
+        }
88
+
89
+        $sender = substr($iTipMessage->sender, 7);
90
+        $recipient = substr($iTipMessage->recipient, 7);
91
+
92
+        $senderName = ($iTipMessage->senderName) ? $iTipMessage->senderName : null;
93
+        $recipientName = ($iTipMessage->recipientName) ? $iTipMessage->recipientName : null;
94
+
95
+        $subject = 'SabreDAV iTIP message';
96
+        switch (strtoupper($iTipMessage->method)) {
97
+            case 'REPLY' :
98
+                $subject = 'Re: ' . $summary;
99
+                break;
100
+            case 'REQUEST' :
101
+                $subject = $summary;
102
+                break;
103
+            case 'CANCEL' :
104
+                $subject = 'Cancelled: ' . $summary;
105
+                break;
106
+        }
107
+
108
+        $contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
109
+
110
+        $message = $this->mailer->createMessage();
111
+
112
+        $message->setReplyTo([$sender => $senderName])
113
+            ->setTo([$recipient => $recipientName])
114
+            ->setSubject($subject)
115
+            ->setBody($iTipMessage->message->serialize(), $contentType);
116
+        try {
117
+            $failed = $this->mailer->send($message);
118
+            if ($failed) {
119
+                $this->logger->error('Unable to deliver message to {failed}', ['app' => 'dav', 'failed' =>  implode(', ', $failed)]);
120
+                $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
121
+            }
122
+            $iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
123
+        } catch(\Exception $ex) {
124
+            $this->logger->logException($ex, ['app' => 'dav']);
125
+            $iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
126
+        }
127
+    }
128 128
 
129 129
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -95,17 +95,17 @@  discard block
 block discarded – undo
95 95
 		$subject = 'SabreDAV iTIP message';
96 96
 		switch (strtoupper($iTipMessage->method)) {
97 97
 			case 'REPLY' :
98
-				$subject = 'Re: ' . $summary;
98
+				$subject = 'Re: '.$summary;
99 99
 				break;
100 100
 			case 'REQUEST' :
101 101
 				$subject = $summary;
102 102
 				break;
103 103
 			case 'CANCEL' :
104
-				$subject = 'Cancelled: ' . $summary;
104
+				$subject = 'Cancelled: '.$summary;
105 105
 				break;
106 106
 		}
107 107
 
108
-		$contentType = 'text/calendar; charset=UTF-8; method=' . $iTipMessage->method;
108
+		$contentType = 'text/calendar; charset=UTF-8; method='.$iTipMessage->method;
109 109
 
110 110
 		$message = $this->mailer->createMessage();
111 111
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 				$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
121 121
 			}
122 122
 			$iTipMessage->scheduleStatus = '1.1; Scheduling message is sent via iMip';
123
-		} catch(\Exception $ex) {
123
+		} catch (\Exception $ex) {
124 124
 			$this->logger->logException($ex, ['app' => 'dav']);
125 125
 			$iTipMessage->scheduleStatus = '5.0; EMail delivery failed';
126 126
 		}
Please login to merge, or discard this patch.
apps/dav/lib/CalDAV/CalendarRoot.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 
25 25
 class CalendarRoot extends \Sabre\CalDAV\CalendarRoot {
26 26
 
27
-	function getChildForPrincipal(array $principal) {
28
-		return new CalendarHome($this->caldavBackend, $principal);
29
-	}
27
+    function getChildForPrincipal(array $principal) {
28
+        return new CalendarHome($this->caldavBackend, $principal);
29
+    }
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
apps/dav/lib/CardDAV/AddressBookImpl.php 2 patches
Indentation   +251 added lines, -251 removed lines patch added patch discarded remove patch
@@ -34,255 +34,255 @@
 block discarded – undo
34 34
 
35 35
 class AddressBookImpl implements IAddressBook {
36 36
 
37
-	/** @var CardDavBackend */
38
-	private $backend;
39
-
40
-	/** @var array */
41
-	private $addressBookInfo;
42
-
43
-	/** @var AddressBook */
44
-	private $addressBook;
45
-
46
-	/** @var IURLGenerator */
47
-	private $urlGenerator;
48
-
49
-	/**
50
-	 * AddressBookImpl constructor.
51
-	 *
52
-	 * @param AddressBook $addressBook
53
-	 * @param array $addressBookInfo
54
-	 * @param CardDavBackend $backend
55
-	 * @param IUrlGenerator $urlGenerator
56
-	 */
57
-	public function __construct(
58
-			AddressBook $addressBook,
59
-			array $addressBookInfo,
60
-			CardDavBackend $backend,
61
-			IURLGenerator $urlGenerator) {
62
-
63
-		$this->addressBook = $addressBook;
64
-		$this->addressBookInfo = $addressBookInfo;
65
-		$this->backend = $backend;
66
-		$this->urlGenerator = $urlGenerator;
67
-	}
68
-
69
-	/**
70
-	 * @return string defining the technical unique key
71
-	 * @since 5.0.0
72
-	 */
73
-	public function getKey() {
74
-		return $this->addressBookInfo['id'];
75
-	}
76
-
77
-	/**
78
-	 * In comparison to getKey() this function returns a human readable (maybe translated) name
79
-	 *
80
-	 * @return mixed
81
-	 * @since 5.0.0
82
-	 */
83
-	public function getDisplayName() {
84
-		return $this->addressBookInfo['{DAV:}displayname'];
85
-	}
86
-
87
-	/**
88
-	 * @param string $pattern which should match within the $searchProperties
89
-	 * @param array $searchProperties defines the properties within the query pattern should match
90
-	 * @param array $options - for future use. One should always have options!
91
-	 * @return array an array of contacts which are arrays of key-value-pairs
92
-	 * @since 5.0.0
93
-	 */
94
-	public function search($pattern, $searchProperties, $options) {
95
-		$results = $this->backend->search($this->getKey(), $pattern, $searchProperties);
96
-
97
-		$vCards = [];
98
-		foreach ($results as $result) {
99
-			$vCards[] = $this->vCard2Array($result['uri'], $this->readCard($result['carddata']));
100
-		}
101
-
102
-		return $vCards;
103
-	}
104
-
105
-	/**
106
-	 * @param array $properties this array if key-value-pairs defines a contact
107
-	 * @return array an array representing the contact just created or updated
108
-	 * @since 5.0.0
109
-	 */
110
-	public function createOrUpdate($properties) {
111
-		$update = false;
112
-		if (!isset($properties['URI'])) { // create a new contact
113
-			$uid = $this->createUid();
114
-			$uri = $uid . '.vcf';
115
-			$vCard = $this->createEmptyVCard($uid);
116
-		} else { // update existing contact
117
-			$uri = $properties['URI'];
118
-			$vCardData = $this->backend->getCard($this->getKey(), $uri);
119
-			$vCard = $this->readCard($vCardData['carddata']);
120
-			$update = true;
121
-		}
122
-
123
-		foreach ($properties as $key => $value) {
124
-			$vCard->$key = $vCard->createProperty($key, $value);
125
-		}
126
-
127
-		if ($update) {
128
-			$this->backend->updateCard($this->getKey(), $uri, $vCard->serialize());
129
-		} else {
130
-			$this->backend->createCard($this->getKey(), $uri, $vCard->serialize());
131
-		}
132
-
133
-		return $this->vCard2Array($uri, $vCard);
134
-
135
-	}
136
-
137
-	/**
138
-	 * @return mixed
139
-	 * @since 5.0.0
140
-	 */
141
-	public function getPermissions() {
142
-		$permissions = $this->addressBook->getACL();
143
-		$result = 0;
144
-		foreach ($permissions as $permission) {
145
-			switch($permission['privilege']) {
146
-				case '{DAV:}read':
147
-					$result |= Constants::PERMISSION_READ;
148
-					break;
149
-				case '{DAV:}write':
150
-					$result |= Constants::PERMISSION_CREATE;
151
-					$result |= Constants::PERMISSION_UPDATE;
152
-					break;
153
-				case '{DAV:}all':
154
-					$result |= Constants::PERMISSION_ALL;
155
-					break;
156
-			}
157
-		}
158
-
159
-		return $result;
160
-	}
161
-
162
-	/**
163
-	 * @param object $id the unique identifier to a contact
164
-	 * @return bool successful or not
165
-	 * @since 5.0.0
166
-	 */
167
-	public function delete($id) {
168
-		$uri = $this->backend->getCardUri($id);
169
-		return $this->backend->deleteCard($this->addressBookInfo['id'], $uri);
170
-	}
171
-
172
-	/**
173
-	 * read vCard data into a vCard object
174
-	 *
175
-	 * @param string $cardData
176
-	 * @return VCard
177
-	 */
178
-	protected function readCard($cardData) {
179
-		return  Reader::read($cardData);
180
-	}
181
-
182
-	/**
183
-	 * create UID for contact
184
-	 *
185
-	 * @return string
186
-	 */
187
-	protected function createUid() {
188
-		do {
189
-			$uid = $this->getUid();
190
-			$contact = $this->backend->getContact($this->getKey(), $uid . '.vcf');
191
-		} while (!empty($contact));
192
-
193
-		return $uid;
194
-	}
195
-
196
-	/**
197
-	 * getUid is only there for testing, use createUid instead
198
-	 */
199
-	protected function getUid() {
200
-		return UUIDUtil::getUUID();
201
-	}
202
-
203
-	/**
204
-	 * create empty vcard
205
-	 *
206
-	 * @param string $uid
207
-	 * @return VCard
208
-	 */
209
-	protected function createEmptyVCard($uid) {
210
-		$vCard = new VCard();
211
-		$vCard->UID = $uid;
212
-		return $vCard;
213
-	}
214
-
215
-	/**
216
-	 * create array with all vCard properties
217
-	 *
218
-	 * @param string $uri
219
-	 * @param VCard $vCard
220
-	 * @return array
221
-	 */
222
-	protected function vCard2Array($uri, VCard $vCard) {
223
-		$result = [
224
-			'URI' => $uri,
225
-		];
226
-
227
-		foreach ($vCard->children() as $property) {
228
-			if ($property->name === 'PHOTO' && $property->getValueType() === 'BINARY') {
229
-				$url = $this->urlGenerator->getAbsoluteURL(
230
-					$this->urlGenerator->linkTo('', 'remote.php') . '/dav/');
231
-				$url .= implode('/', [
232
-					'addressbooks',
233
-					substr($this->addressBookInfo['principaluri'], 11), //cut off 'principals/'
234
-					$this->addressBookInfo['uri'],
235
-					$uri
236
-				]) . '?photo';
237
-
238
-				$result['PHOTO'] = 'VALUE=uri:' . $url;
239
-
240
-			} else if ($property->name === 'X-SOCIALPROFILE') {
241
-				$type = $this->getTypeFromProperty($property);
242
-
243
-				// Type is the social network, when it's empty we don't need this.
244
-				if ($type !== null) {
245
-					if (!isset($result[$property->name])) {
246
-						$result[$property->name] = [];
247
-					}
248
-					$result[$property->name][$type] = $property->getValue();
249
-				}
250
-
251
-			// The following properties can be set multiple times
252
-			} else if (in_array($property->name, ['CLOUD', 'EMAIL', 'IMPP', 'TEL', 'URL'])) {
253
-				if (!isset($result[$property->name])) {
254
-					$result[$property->name] = [];
255
-				}
256
-
257
-				$result[$property->name][] = $property->getValue();
258
-
259
-			} else {
260
-				$result[$property->name] = $property->getValue();
261
-			}
262
-		}
263
-
264
-		if ($this->addressBookInfo['principaluri'] === 'principals/system/system' &&
265
-			$this->addressBookInfo['uri'] === 'system') {
266
-			$result['isLocalSystemBook'] = true;
267
-		}
268
-		return $result;
269
-	}
270
-
271
-	/**
272
-	 * Get the type of the current property
273
-	 *
274
-	 * @param Property $property
275
-	 * @return null|string
276
-	 */
277
-	protected function getTypeFromProperty(Property $property) {
278
-		$parameters = $property->parameters();
279
-		// Type is the social network, when it's empty we don't need this.
280
-		if (isset($parameters['TYPE'])) {
281
-			/** @var \Sabre\VObject\Parameter $type */
282
-			$type = $parameters['TYPE'];
283
-			return $type->getValue();
284
-		}
285
-
286
-		return null;
287
-	}
37
+    /** @var CardDavBackend */
38
+    private $backend;
39
+
40
+    /** @var array */
41
+    private $addressBookInfo;
42
+
43
+    /** @var AddressBook */
44
+    private $addressBook;
45
+
46
+    /** @var IURLGenerator */
47
+    private $urlGenerator;
48
+
49
+    /**
50
+     * AddressBookImpl constructor.
51
+     *
52
+     * @param AddressBook $addressBook
53
+     * @param array $addressBookInfo
54
+     * @param CardDavBackend $backend
55
+     * @param IUrlGenerator $urlGenerator
56
+     */
57
+    public function __construct(
58
+            AddressBook $addressBook,
59
+            array $addressBookInfo,
60
+            CardDavBackend $backend,
61
+            IURLGenerator $urlGenerator) {
62
+
63
+        $this->addressBook = $addressBook;
64
+        $this->addressBookInfo = $addressBookInfo;
65
+        $this->backend = $backend;
66
+        $this->urlGenerator = $urlGenerator;
67
+    }
68
+
69
+    /**
70
+     * @return string defining the technical unique key
71
+     * @since 5.0.0
72
+     */
73
+    public function getKey() {
74
+        return $this->addressBookInfo['id'];
75
+    }
76
+
77
+    /**
78
+     * In comparison to getKey() this function returns a human readable (maybe translated) name
79
+     *
80
+     * @return mixed
81
+     * @since 5.0.0
82
+     */
83
+    public function getDisplayName() {
84
+        return $this->addressBookInfo['{DAV:}displayname'];
85
+    }
86
+
87
+    /**
88
+     * @param string $pattern which should match within the $searchProperties
89
+     * @param array $searchProperties defines the properties within the query pattern should match
90
+     * @param array $options - for future use. One should always have options!
91
+     * @return array an array of contacts which are arrays of key-value-pairs
92
+     * @since 5.0.0
93
+     */
94
+    public function search($pattern, $searchProperties, $options) {
95
+        $results = $this->backend->search($this->getKey(), $pattern, $searchProperties);
96
+
97
+        $vCards = [];
98
+        foreach ($results as $result) {
99
+            $vCards[] = $this->vCard2Array($result['uri'], $this->readCard($result['carddata']));
100
+        }
101
+
102
+        return $vCards;
103
+    }
104
+
105
+    /**
106
+     * @param array $properties this array if key-value-pairs defines a contact
107
+     * @return array an array representing the contact just created or updated
108
+     * @since 5.0.0
109
+     */
110
+    public function createOrUpdate($properties) {
111
+        $update = false;
112
+        if (!isset($properties['URI'])) { // create a new contact
113
+            $uid = $this->createUid();
114
+            $uri = $uid . '.vcf';
115
+            $vCard = $this->createEmptyVCard($uid);
116
+        } else { // update existing contact
117
+            $uri = $properties['URI'];
118
+            $vCardData = $this->backend->getCard($this->getKey(), $uri);
119
+            $vCard = $this->readCard($vCardData['carddata']);
120
+            $update = true;
121
+        }
122
+
123
+        foreach ($properties as $key => $value) {
124
+            $vCard->$key = $vCard->createProperty($key, $value);
125
+        }
126
+
127
+        if ($update) {
128
+            $this->backend->updateCard($this->getKey(), $uri, $vCard->serialize());
129
+        } else {
130
+            $this->backend->createCard($this->getKey(), $uri, $vCard->serialize());
131
+        }
132
+
133
+        return $this->vCard2Array($uri, $vCard);
134
+
135
+    }
136
+
137
+    /**
138
+     * @return mixed
139
+     * @since 5.0.0
140
+     */
141
+    public function getPermissions() {
142
+        $permissions = $this->addressBook->getACL();
143
+        $result = 0;
144
+        foreach ($permissions as $permission) {
145
+            switch($permission['privilege']) {
146
+                case '{DAV:}read':
147
+                    $result |= Constants::PERMISSION_READ;
148
+                    break;
149
+                case '{DAV:}write':
150
+                    $result |= Constants::PERMISSION_CREATE;
151
+                    $result |= Constants::PERMISSION_UPDATE;
152
+                    break;
153
+                case '{DAV:}all':
154
+                    $result |= Constants::PERMISSION_ALL;
155
+                    break;
156
+            }
157
+        }
158
+
159
+        return $result;
160
+    }
161
+
162
+    /**
163
+     * @param object $id the unique identifier to a contact
164
+     * @return bool successful or not
165
+     * @since 5.0.0
166
+     */
167
+    public function delete($id) {
168
+        $uri = $this->backend->getCardUri($id);
169
+        return $this->backend->deleteCard($this->addressBookInfo['id'], $uri);
170
+    }
171
+
172
+    /**
173
+     * read vCard data into a vCard object
174
+     *
175
+     * @param string $cardData
176
+     * @return VCard
177
+     */
178
+    protected function readCard($cardData) {
179
+        return  Reader::read($cardData);
180
+    }
181
+
182
+    /**
183
+     * create UID for contact
184
+     *
185
+     * @return string
186
+     */
187
+    protected function createUid() {
188
+        do {
189
+            $uid = $this->getUid();
190
+            $contact = $this->backend->getContact($this->getKey(), $uid . '.vcf');
191
+        } while (!empty($contact));
192
+
193
+        return $uid;
194
+    }
195
+
196
+    /**
197
+     * getUid is only there for testing, use createUid instead
198
+     */
199
+    protected function getUid() {
200
+        return UUIDUtil::getUUID();
201
+    }
202
+
203
+    /**
204
+     * create empty vcard
205
+     *
206
+     * @param string $uid
207
+     * @return VCard
208
+     */
209
+    protected function createEmptyVCard($uid) {
210
+        $vCard = new VCard();
211
+        $vCard->UID = $uid;
212
+        return $vCard;
213
+    }
214
+
215
+    /**
216
+     * create array with all vCard properties
217
+     *
218
+     * @param string $uri
219
+     * @param VCard $vCard
220
+     * @return array
221
+     */
222
+    protected function vCard2Array($uri, VCard $vCard) {
223
+        $result = [
224
+            'URI' => $uri,
225
+        ];
226
+
227
+        foreach ($vCard->children() as $property) {
228
+            if ($property->name === 'PHOTO' && $property->getValueType() === 'BINARY') {
229
+                $url = $this->urlGenerator->getAbsoluteURL(
230
+                    $this->urlGenerator->linkTo('', 'remote.php') . '/dav/');
231
+                $url .= implode('/', [
232
+                    'addressbooks',
233
+                    substr($this->addressBookInfo['principaluri'], 11), //cut off 'principals/'
234
+                    $this->addressBookInfo['uri'],
235
+                    $uri
236
+                ]) . '?photo';
237
+
238
+                $result['PHOTO'] = 'VALUE=uri:' . $url;
239
+
240
+            } else if ($property->name === 'X-SOCIALPROFILE') {
241
+                $type = $this->getTypeFromProperty($property);
242
+
243
+                // Type is the social network, when it's empty we don't need this.
244
+                if ($type !== null) {
245
+                    if (!isset($result[$property->name])) {
246
+                        $result[$property->name] = [];
247
+                    }
248
+                    $result[$property->name][$type] = $property->getValue();
249
+                }
250
+
251
+            // The following properties can be set multiple times
252
+            } else if (in_array($property->name, ['CLOUD', 'EMAIL', 'IMPP', 'TEL', 'URL'])) {
253
+                if (!isset($result[$property->name])) {
254
+                    $result[$property->name] = [];
255
+                }
256
+
257
+                $result[$property->name][] = $property->getValue();
258
+
259
+            } else {
260
+                $result[$property->name] = $property->getValue();
261
+            }
262
+        }
263
+
264
+        if ($this->addressBookInfo['principaluri'] === 'principals/system/system' &&
265
+            $this->addressBookInfo['uri'] === 'system') {
266
+            $result['isLocalSystemBook'] = true;
267
+        }
268
+        return $result;
269
+    }
270
+
271
+    /**
272
+     * Get the type of the current property
273
+     *
274
+     * @param Property $property
275
+     * @return null|string
276
+     */
277
+    protected function getTypeFromProperty(Property $property) {
278
+        $parameters = $property->parameters();
279
+        // Type is the social network, when it's empty we don't need this.
280
+        if (isset($parameters['TYPE'])) {
281
+            /** @var \Sabre\VObject\Parameter $type */
282
+            $type = $parameters['TYPE'];
283
+            return $type->getValue();
284
+        }
285
+
286
+        return null;
287
+    }
288 288
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 		$update = false;
112 112
 		if (!isset($properties['URI'])) { // create a new contact
113 113
 			$uid = $this->createUid();
114
-			$uri = $uid . '.vcf';
114
+			$uri = $uid.'.vcf';
115 115
 			$vCard = $this->createEmptyVCard($uid);
116 116
 		} else { // update existing contact
117 117
 			$uri = $properties['URI'];
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 		$permissions = $this->addressBook->getACL();
143 143
 		$result = 0;
144 144
 		foreach ($permissions as $permission) {
145
-			switch($permission['privilege']) {
145
+			switch ($permission['privilege']) {
146 146
 				case '{DAV:}read':
147 147
 					$result |= Constants::PERMISSION_READ;
148 148
 					break;
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	protected function createUid() {
188 188
 		do {
189 189
 			$uid = $this->getUid();
190
-			$contact = $this->backend->getContact($this->getKey(), $uid . '.vcf');
190
+			$contact = $this->backend->getContact($this->getKey(), $uid.'.vcf');
191 191
 		} while (!empty($contact));
192 192
 
193 193
 		return $uid;
@@ -227,15 +227,15 @@  discard block
 block discarded – undo
227 227
 		foreach ($vCard->children() as $property) {
228 228
 			if ($property->name === 'PHOTO' && $property->getValueType() === 'BINARY') {
229 229
 				$url = $this->urlGenerator->getAbsoluteURL(
230
-					$this->urlGenerator->linkTo('', 'remote.php') . '/dav/');
230
+					$this->urlGenerator->linkTo('', 'remote.php').'/dav/');
231 231
 				$url .= implode('/', [
232 232
 					'addressbooks',
233 233
 					substr($this->addressBookInfo['principaluri'], 11), //cut off 'principals/'
234 234
 					$this->addressBookInfo['uri'],
235 235
 					$uri
236
-				]) . '?photo';
236
+				]).'?photo';
237 237
 
238
-				$result['PHOTO'] = 'VALUE=uri:' . $url;
238
+				$result['PHOTO'] = 'VALUE=uri:'.$url;
239 239
 
240 240
 			} else if ($property->name === 'X-SOCIALPROFILE') {
241 241
 				$type = $this->getTypeFromProperty($property);
Please login to merge, or discard this patch.