Completed
Push — stable13 ( 2d5d8b...1a016f )
by Roeland
17:00
created
apps/dav/lib/CardDAV/SyncService.php 3 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 			if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
100 100
 				// remote server revoked access to the address book, remove it
101 101
 				$this->backend->deleteAddressBook($addressBookId);
102
-				$this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
102
+				$this->logger->info('Authorization failed, remove address book: '.$url, ['app' => 'dav']);
103 103
 				throw $ex;
104 104
 			}
105 105
 		}
@@ -149,7 +149,7 @@  discard block
 block discarded – undo
149 149
 	 */
150 150
 	protected function getClient($url, $userName, $sharedSecret) {
151 151
 		$settings = [
152
-			'baseUri' => $url . '/',
152
+			'baseUri' => $url.'/',
153 153
 			'userName' => $userName,
154 154
 			'password' => $sharedSecret,
155 155
 		];
@@ -269,7 +269,7 @@  discard block
 block discarded – undo
269 269
 	 */
270 270
 	public function deleteUser($userOrCardId) {
271 271
 		$systemAddressBook = $this->getLocalSystemAddressBook();
272
-		if ($userOrCardId instanceof IUser){
272
+		if ($userOrCardId instanceof IUser) {
273 273
 			$name = $userOrCardId->getBackendClassName();
274 274
 			$userId = $userOrCardId->getUID();
275 275
 
@@ -285,7 +285,7 @@  discard block
 block discarded – undo
285 285
 		if (is_null($this->localSystemAddressBook)) {
286 286
 			$systemPrincipal = "principals/system/system";
287 287
 			$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
288
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
288
+				'{'.Plugin::NS_CARDDAV.'}addressbook-description' => 'System addressbook which holds all users of this instance'
289 289
 			]);
290 290
 		}
291 291
 
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
 
304 304
 		// remove no longer existing
305 305
 		$allCards = $this->backend->getCards($systemAddressBook['id']);
306
-		foreach($allCards as $card) {
306
+		foreach ($allCards as $card) {
307 307
 			$vCard = Reader::read($card['carddata']);
308 308
 			$uid = $vCard->UID->getValue();
309 309
 			// load backend and see if user exists
Please login to merge, or discard this patch.
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -163,7 +163,6 @@  discard block
 block discarded – undo
163 163
 	/**
164 164
 	 * @param string $url
165 165
 	 * @param string $userName
166
-	 * @param string $addressBookUrl
167 166
 	 * @param string $sharedSecret
168 167
 	 * @return Client
169 168
 	 */
@@ -301,7 +300,7 @@  discard block
 block discarded – undo
301 300
 	}
302 301
 
303 302
 	/**
304
-	 * @return array|null
303
+	 * @return string
305 304
 	 */
306 305
 	public function getLocalSystemAddressBook() {
307 306
 		if (is_null($this->localSystemAddressBook)) {
Please login to merge, or discard this patch.
Indentation   +296 added lines, -296 removed lines patch added patch discarded remove patch
@@ -38,302 +38,302 @@
 block discarded – undo
38 38
 
39 39
 class SyncService {
40 40
 
41
-	/** @var CardDavBackend */
42
-	private $backend;
43
-
44
-	/** @var IUserManager */
45
-	private $userManager;
46
-
47
-	/** @var ILogger */
48
-	private $logger;
49
-
50
-	/** @var array */
51
-	private $localSystemAddressBook;
52
-
53
-	/** @var AccountManager */
54
-	private $accountManager;
55
-
56
-	/** @var string */
57
-	protected $certPath;
58
-
59
-	/**
60
-	 * SyncService constructor.
61
-	 *
62
-	 * @param CardDavBackend $backend
63
-	 * @param IUserManager $userManager
64
-	 * @param ILogger $logger
65
-	 * @param AccountManager $accountManager
66
-	 */
67
-	public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) {
68
-		$this->backend = $backend;
69
-		$this->userManager = $userManager;
70
-		$this->logger = $logger;
71
-		$this->accountManager = $accountManager;
72
-		$this->certPath = '';
73
-	}
74
-
75
-	/**
76
-	 * @param string $url
77
-	 * @param string $userName
78
-	 * @param string $addressBookUrl
79
-	 * @param string $sharedSecret
80
-	 * @param string $syncToken
81
-	 * @param int $targetBookId
82
-	 * @param string $targetPrincipal
83
-	 * @param array $targetProperties
84
-	 * @return string
85
-	 * @throws \Exception
86
-	 */
87
-	public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) {
88
-		// 1. create addressbook
89
-		$book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties);
90
-		$addressBookId = $book['id'];
91
-
92
-		// 2. query changes
93
-		try {
94
-			$response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken);
95
-		} catch (ClientHttpException $ex) {
96
-			if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
97
-				// remote server revoked access to the address book, remove it
98
-				$this->backend->deleteAddressBook($addressBookId);
99
-				$this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
100
-				throw $ex;
101
-			}
102
-		}
103
-
104
-		// 3. apply changes
105
-		// TODO: use multi-get for download
106
-		foreach ($response['response'] as $resource => $status) {
107
-			$cardUri = basename($resource);
108
-			if (isset($status[200])) {
109
-				$vCard = $this->download($url, $userName, $sharedSecret, $resource);
110
-				$existingCard = $this->backend->getCard($addressBookId, $cardUri);
111
-				if ($existingCard === false) {
112
-					$this->backend->createCard($addressBookId, $cardUri, $vCard['body']);
113
-				} else {
114
-					$this->backend->updateCard($addressBookId, $cardUri, $vCard['body']);
115
-				}
116
-			} else {
117
-				$this->backend->deleteCard($addressBookId, $cardUri);
118
-			}
119
-		}
120
-
121
-		return $response['token'];
122
-	}
123
-
124
-	/**
125
-	 * @param string $principal
126
-	 * @param string $id
127
-	 * @param array $properties
128
-	 * @return array|null
129
-	 * @throws \Sabre\DAV\Exception\BadRequest
130
-	 */
131
-	public function ensureSystemAddressBookExists($principal, $id, $properties) {
132
-		$book = $this->backend->getAddressBooksByUri($principal, $id);
133
-		if (!is_null($book)) {
134
-			return $book;
135
-		}
136
-		$this->backend->createAddressBook($principal, $id, $properties);
137
-
138
-		return $this->backend->getAddressBooksByUri($principal, $id);
139
-	}
140
-
141
-	/**
142
-	 * Check if there is a valid certPath we should use
143
-	 *
144
-	 * @return string
145
-	 */
146
-	protected function getCertPath() {
147
-
148
-		// we already have a valid certPath
149
-		if ($this->certPath !== '') {
150
-			return $this->certPath;
151
-		}
152
-
153
-		/** @var ICertificateManager $certManager */
154
-		$certManager = \OC::$server->getCertificateManager(null);
155
-		$certPath = $certManager->getAbsoluteBundlePath();
156
-		if (file_exists($certPath)) {
157
-			$this->certPath = $certPath;
158
-		}
159
-
160
-		return $this->certPath;
161
-	}
162
-
163
-	/**
164
-	 * @param string $url
165
-	 * @param string $userName
166
-	 * @param string $addressBookUrl
167
-	 * @param string $sharedSecret
168
-	 * @return Client
169
-	 */
170
-	protected function getClient($url, $userName, $sharedSecret) {
171
-		$settings = [
172
-			'baseUri' => $url . '/',
173
-			'userName' => $userName,
174
-			'password' => $sharedSecret,
175
-		];
176
-		$client = new Client($settings);
177
-		$certPath = $this->getCertPath();
178
-		$client->setThrowExceptions(true);
179
-
180
-		if ($certPath !== '' && strpos($url, 'http://') !== 0) {
181
-			$client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
182
-		}
183
-
184
-		return $client;
185
-	}
186
-
187
-	/**
188
-	 * @param string $url
189
-	 * @param string $userName
190
-	 * @param string $addressBookUrl
191
-	 * @param string $sharedSecret
192
-	 * @param string $syncToken
193
-	 * @return array
194
-	 */
195
-	 protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) {
196
-		 $client = $this->getClient($url, $userName, $sharedSecret);
197
-
198
-		 $body = $this->buildSyncCollectionRequestBody($syncToken);
199
-
200
-		 $response = $client->request('REPORT', $addressBookUrl, $body, [
201
-			 'Content-Type' => 'application/xml'
202
-		 ]);
203
-
204
-		 return $this->parseMultiStatus($response['body']);
205
-	 }
206
-
207
-	/**
208
-	 * @param string $url
209
-	 * @param string $userName
210
-	 * @param string $sharedSecret
211
-	 * @param string $resourcePath
212
-	 * @return array
213
-	 */
214
-	protected function download($url, $userName, $sharedSecret, $resourcePath) {
215
-		$client = $this->getClient($url, $userName, $sharedSecret);
216
-		return $client->request('GET', $resourcePath);
217
-	}
218
-
219
-	/**
220
-	 * @param string|null $syncToken
221
-	 * @return string
222
-	 */
223
-	private function buildSyncCollectionRequestBody($syncToken) {
224
-
225
-		$dom = new \DOMDocument('1.0', 'UTF-8');
226
-		$dom->formatOutput = true;
227
-		$root = $dom->createElementNS('DAV:', 'd:sync-collection');
228
-		$sync = $dom->createElement('d:sync-token', $syncToken);
229
-		$prop = $dom->createElement('d:prop');
230
-		$cont = $dom->createElement('d:getcontenttype');
231
-		$etag = $dom->createElement('d:getetag');
232
-
233
-		$prop->appendChild($cont);
234
-		$prop->appendChild($etag);
235
-		$root->appendChild($sync);
236
-		$root->appendChild($prop);
237
-		$dom->appendChild($root);
238
-		$body = $dom->saveXML();
239
-
240
-		return $body;
241
-	}
242
-
243
-	/**
244
-	 * @param string $body
245
-	 * @return array
246
-	 * @throws \Sabre\Xml\ParseException
247
-	 */
248
-	private function parseMultiStatus($body) {
249
-		$xml = new Service();
250
-
251
-		/** @var MultiStatus $multiStatus */
252
-		$multiStatus = $xml->expect('{DAV:}multistatus', $body);
253
-
254
-		$result = [];
255
-		foreach ($multiStatus->getResponses() as $response) {
256
-			$result[$response->getHref()] = $response->getResponseProperties();
257
-		}
258
-
259
-		return ['response' => $result, 'token' => $multiStatus->getSyncToken()];
260
-	}
261
-
262
-	/**
263
-	 * @param IUser $user
264
-	 */
265
-	public function updateUser($user) {
266
-		$systemAddressBook = $this->getLocalSystemAddressBook();
267
-		$addressBookId = $systemAddressBook['id'];
268
-		$converter = new Converter($this->accountManager);
269
-		$name = $user->getBackendClassName();
270
-		$userId = $user->getUID();
271
-
272
-		$cardId = "$name:$userId.vcf";
273
-		$card = $this->backend->getCard($addressBookId, $cardId);
274
-		if ($card === false) {
275
-			$vCard = $converter->createCardFromUser($user);
276
-			if ($vCard !== null) {
277
-				$this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
278
-			}
279
-		} else {
280
-			$vCard = $converter->createCardFromUser($user);
281
-			if (is_null($vCard)) {
282
-				$this->backend->deleteCard($addressBookId, $cardId);
283
-			} else {
284
-				$this->backend->updateCard($addressBookId, $cardId, $vCard->serialize());
285
-			}
286
-		}
287
-	}
288
-
289
-	/**
290
-	 * @param IUser|string $userOrCardId
291
-	 */
292
-	public function deleteUser($userOrCardId) {
293
-		$systemAddressBook = $this->getLocalSystemAddressBook();
294
-		if ($userOrCardId instanceof IUser){
295
-			$name = $userOrCardId->getBackendClassName();
296
-			$userId = $userOrCardId->getUID();
297
-
298
-			$userOrCardId = "$name:$userId.vcf";
299
-		}
300
-		$this->backend->deleteCard($systemAddressBook['id'], $userOrCardId);
301
-	}
302
-
303
-	/**
304
-	 * @return array|null
305
-	 */
306
-	public function getLocalSystemAddressBook() {
307
-		if (is_null($this->localSystemAddressBook)) {
308
-			$systemPrincipal = "principals/system/system";
309
-			$this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
310
-				'{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
311
-			]);
312
-		}
313
-
314
-		return $this->localSystemAddressBook;
315
-	}
316
-
317
-	public function syncInstance(\Closure $progressCallback = null) {
318
-		$systemAddressBook = $this->getLocalSystemAddressBook();
319
-		$this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) {
320
-			$this->updateUser($user);
321
-			if (!is_null($progressCallback)) {
322
-				$progressCallback();
323
-			}
324
-		});
325
-
326
-		// remove no longer existing
327
-		$allCards = $this->backend->getCards($systemAddressBook['id']);
328
-		foreach($allCards as $card) {
329
-			$vCard = Reader::read($card['carddata']);
330
-			$uid = $vCard->UID->getValue();
331
-			// load backend and see if user exists
332
-			if (!$this->userManager->userExists($uid)) {
333
-				$this->deleteUser($card['uri']);
334
-			}
335
-		}
336
-	}
41
+    /** @var CardDavBackend */
42
+    private $backend;
43
+
44
+    /** @var IUserManager */
45
+    private $userManager;
46
+
47
+    /** @var ILogger */
48
+    private $logger;
49
+
50
+    /** @var array */
51
+    private $localSystemAddressBook;
52
+
53
+    /** @var AccountManager */
54
+    private $accountManager;
55
+
56
+    /** @var string */
57
+    protected $certPath;
58
+
59
+    /**
60
+     * SyncService constructor.
61
+     *
62
+     * @param CardDavBackend $backend
63
+     * @param IUserManager $userManager
64
+     * @param ILogger $logger
65
+     * @param AccountManager $accountManager
66
+     */
67
+    public function __construct(CardDavBackend $backend, IUserManager $userManager, ILogger $logger, AccountManager $accountManager) {
68
+        $this->backend = $backend;
69
+        $this->userManager = $userManager;
70
+        $this->logger = $logger;
71
+        $this->accountManager = $accountManager;
72
+        $this->certPath = '';
73
+    }
74
+
75
+    /**
76
+     * @param string $url
77
+     * @param string $userName
78
+     * @param string $addressBookUrl
79
+     * @param string $sharedSecret
80
+     * @param string $syncToken
81
+     * @param int $targetBookId
82
+     * @param string $targetPrincipal
83
+     * @param array $targetProperties
84
+     * @return string
85
+     * @throws \Exception
86
+     */
87
+    public function syncRemoteAddressBook($url, $userName, $addressBookUrl, $sharedSecret, $syncToken, $targetBookId, $targetPrincipal, $targetProperties) {
88
+        // 1. create addressbook
89
+        $book = $this->ensureSystemAddressBookExists($targetPrincipal, $targetBookId, $targetProperties);
90
+        $addressBookId = $book['id'];
91
+
92
+        // 2. query changes
93
+        try {
94
+            $response = $this->requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken);
95
+        } catch (ClientHttpException $ex) {
96
+            if ($ex->getCode() === Http::STATUS_UNAUTHORIZED) {
97
+                // remote server revoked access to the address book, remove it
98
+                $this->backend->deleteAddressBook($addressBookId);
99
+                $this->logger->info('Authorization failed, remove address book: ' . $url, ['app' => 'dav']);
100
+                throw $ex;
101
+            }
102
+        }
103
+
104
+        // 3. apply changes
105
+        // TODO: use multi-get for download
106
+        foreach ($response['response'] as $resource => $status) {
107
+            $cardUri = basename($resource);
108
+            if (isset($status[200])) {
109
+                $vCard = $this->download($url, $userName, $sharedSecret, $resource);
110
+                $existingCard = $this->backend->getCard($addressBookId, $cardUri);
111
+                if ($existingCard === false) {
112
+                    $this->backend->createCard($addressBookId, $cardUri, $vCard['body']);
113
+                } else {
114
+                    $this->backend->updateCard($addressBookId, $cardUri, $vCard['body']);
115
+                }
116
+            } else {
117
+                $this->backend->deleteCard($addressBookId, $cardUri);
118
+            }
119
+        }
120
+
121
+        return $response['token'];
122
+    }
123
+
124
+    /**
125
+     * @param string $principal
126
+     * @param string $id
127
+     * @param array $properties
128
+     * @return array|null
129
+     * @throws \Sabre\DAV\Exception\BadRequest
130
+     */
131
+    public function ensureSystemAddressBookExists($principal, $id, $properties) {
132
+        $book = $this->backend->getAddressBooksByUri($principal, $id);
133
+        if (!is_null($book)) {
134
+            return $book;
135
+        }
136
+        $this->backend->createAddressBook($principal, $id, $properties);
137
+
138
+        return $this->backend->getAddressBooksByUri($principal, $id);
139
+    }
140
+
141
+    /**
142
+     * Check if there is a valid certPath we should use
143
+     *
144
+     * @return string
145
+     */
146
+    protected function getCertPath() {
147
+
148
+        // we already have a valid certPath
149
+        if ($this->certPath !== '') {
150
+            return $this->certPath;
151
+        }
152
+
153
+        /** @var ICertificateManager $certManager */
154
+        $certManager = \OC::$server->getCertificateManager(null);
155
+        $certPath = $certManager->getAbsoluteBundlePath();
156
+        if (file_exists($certPath)) {
157
+            $this->certPath = $certPath;
158
+        }
159
+
160
+        return $this->certPath;
161
+    }
162
+
163
+    /**
164
+     * @param string $url
165
+     * @param string $userName
166
+     * @param string $addressBookUrl
167
+     * @param string $sharedSecret
168
+     * @return Client
169
+     */
170
+    protected function getClient($url, $userName, $sharedSecret) {
171
+        $settings = [
172
+            'baseUri' => $url . '/',
173
+            'userName' => $userName,
174
+            'password' => $sharedSecret,
175
+        ];
176
+        $client = new Client($settings);
177
+        $certPath = $this->getCertPath();
178
+        $client->setThrowExceptions(true);
179
+
180
+        if ($certPath !== '' && strpos($url, 'http://') !== 0) {
181
+            $client->addCurlSetting(CURLOPT_CAINFO, $this->certPath);
182
+        }
183
+
184
+        return $client;
185
+    }
186
+
187
+    /**
188
+     * @param string $url
189
+     * @param string $userName
190
+     * @param string $addressBookUrl
191
+     * @param string $sharedSecret
192
+     * @param string $syncToken
193
+     * @return array
194
+     */
195
+        protected function requestSyncReport($url, $userName, $addressBookUrl, $sharedSecret, $syncToken) {
196
+            $client = $this->getClient($url, $userName, $sharedSecret);
197
+
198
+            $body = $this->buildSyncCollectionRequestBody($syncToken);
199
+
200
+            $response = $client->request('REPORT', $addressBookUrl, $body, [
201
+                'Content-Type' => 'application/xml'
202
+            ]);
203
+
204
+            return $this->parseMultiStatus($response['body']);
205
+        }
206
+
207
+    /**
208
+     * @param string $url
209
+     * @param string $userName
210
+     * @param string $sharedSecret
211
+     * @param string $resourcePath
212
+     * @return array
213
+     */
214
+    protected function download($url, $userName, $sharedSecret, $resourcePath) {
215
+        $client = $this->getClient($url, $userName, $sharedSecret);
216
+        return $client->request('GET', $resourcePath);
217
+    }
218
+
219
+    /**
220
+     * @param string|null $syncToken
221
+     * @return string
222
+     */
223
+    private function buildSyncCollectionRequestBody($syncToken) {
224
+
225
+        $dom = new \DOMDocument('1.0', 'UTF-8');
226
+        $dom->formatOutput = true;
227
+        $root = $dom->createElementNS('DAV:', 'd:sync-collection');
228
+        $sync = $dom->createElement('d:sync-token', $syncToken);
229
+        $prop = $dom->createElement('d:prop');
230
+        $cont = $dom->createElement('d:getcontenttype');
231
+        $etag = $dom->createElement('d:getetag');
232
+
233
+        $prop->appendChild($cont);
234
+        $prop->appendChild($etag);
235
+        $root->appendChild($sync);
236
+        $root->appendChild($prop);
237
+        $dom->appendChild($root);
238
+        $body = $dom->saveXML();
239
+
240
+        return $body;
241
+    }
242
+
243
+    /**
244
+     * @param string $body
245
+     * @return array
246
+     * @throws \Sabre\Xml\ParseException
247
+     */
248
+    private function parseMultiStatus($body) {
249
+        $xml = new Service();
250
+
251
+        /** @var MultiStatus $multiStatus */
252
+        $multiStatus = $xml->expect('{DAV:}multistatus', $body);
253
+
254
+        $result = [];
255
+        foreach ($multiStatus->getResponses() as $response) {
256
+            $result[$response->getHref()] = $response->getResponseProperties();
257
+        }
258
+
259
+        return ['response' => $result, 'token' => $multiStatus->getSyncToken()];
260
+    }
261
+
262
+    /**
263
+     * @param IUser $user
264
+     */
265
+    public function updateUser($user) {
266
+        $systemAddressBook = $this->getLocalSystemAddressBook();
267
+        $addressBookId = $systemAddressBook['id'];
268
+        $converter = new Converter($this->accountManager);
269
+        $name = $user->getBackendClassName();
270
+        $userId = $user->getUID();
271
+
272
+        $cardId = "$name:$userId.vcf";
273
+        $card = $this->backend->getCard($addressBookId, $cardId);
274
+        if ($card === false) {
275
+            $vCard = $converter->createCardFromUser($user);
276
+            if ($vCard !== null) {
277
+                $this->backend->createCard($addressBookId, $cardId, $vCard->serialize());
278
+            }
279
+        } else {
280
+            $vCard = $converter->createCardFromUser($user);
281
+            if (is_null($vCard)) {
282
+                $this->backend->deleteCard($addressBookId, $cardId);
283
+            } else {
284
+                $this->backend->updateCard($addressBookId, $cardId, $vCard->serialize());
285
+            }
286
+        }
287
+    }
288
+
289
+    /**
290
+     * @param IUser|string $userOrCardId
291
+     */
292
+    public function deleteUser($userOrCardId) {
293
+        $systemAddressBook = $this->getLocalSystemAddressBook();
294
+        if ($userOrCardId instanceof IUser){
295
+            $name = $userOrCardId->getBackendClassName();
296
+            $userId = $userOrCardId->getUID();
297
+
298
+            $userOrCardId = "$name:$userId.vcf";
299
+        }
300
+        $this->backend->deleteCard($systemAddressBook['id'], $userOrCardId);
301
+    }
302
+
303
+    /**
304
+     * @return array|null
305
+     */
306
+    public function getLocalSystemAddressBook() {
307
+        if (is_null($this->localSystemAddressBook)) {
308
+            $systemPrincipal = "principals/system/system";
309
+            $this->localSystemAddressBook = $this->ensureSystemAddressBookExists($systemPrincipal, 'system', [
310
+                '{' . Plugin::NS_CARDDAV . '}addressbook-description' => 'System addressbook which holds all users of this instance'
311
+            ]);
312
+        }
313
+
314
+        return $this->localSystemAddressBook;
315
+    }
316
+
317
+    public function syncInstance(\Closure $progressCallback = null) {
318
+        $systemAddressBook = $this->getLocalSystemAddressBook();
319
+        $this->userManager->callForAllUsers(function($user) use ($systemAddressBook, $progressCallback) {
320
+            $this->updateUser($user);
321
+            if (!is_null($progressCallback)) {
322
+                $progressCallback();
323
+            }
324
+        });
325
+
326
+        // remove no longer existing
327
+        $allCards = $this->backend->getCards($systemAddressBook['id']);
328
+        foreach($allCards as $card) {
329
+            $vCard = Reader::read($card['carddata']);
330
+            $uid = $vCard->UID->getValue();
331
+            // load backend and see if user exists
332
+            if (!$this->userManager->userExists($uid)) {
333
+                $this->deleteUser($card['uri']);
334
+            }
335
+        }
336
+    }
337 337
 
338 338
 
339 339
 }
Please login to merge, or discard this patch.
lib/private/Files/FileInfo.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
 	 * @param \OCP\Files\Mount\IMountPoint $mount
88 88
 	 * @param \OCP\IUser|null $owner
89 89
 	 */
90
-	public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) {
90
+	public function __construct($path, $storage, $internalPath, $data, $mount, $owner = null) {
91 91
 		$this->path = $path;
92 92
 		$this->storage = $storage;
93 93
 		$this->internalPath = $internalPath;
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 	 * @return int|null
154 154
 	 */
155 155
 	public function getId() {
156
-		return isset($this->data['fileid']) ? (int)  $this->data['fileid'] : null;
156
+		return isset($this->data['fileid']) ? (int) $this->data['fileid'] : null;
157 157
 	}
158 158
 
159 159
 	/**
@@ -183,7 +183,7 @@  discard block
 block discarded – undo
183 183
 	public function getEtag() {
184 184
 		$this->updateEntryfromSubMounts();
185 185
 		if (count($this->childEtags) > 0) {
186
-			$combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
186
+			$combinedEtag = $this->data['etag'].'::'.implode('::', $this->childEtags);
187 187
 			return md5($combinedEtag);
188 188
 		} else {
189 189
 			return $this->data['etag'];
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
 			$relativeEntryPath = substr($entryPath, strlen($this->getPath()));
380 380
 			// attach the permissions to propagate etag on permision changes of submounts
381 381
 			$permissions = isset($data['permissions']) ? $data['permissions'] : 0;
382
-			$this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
382
+			$this->childEtags[] = $relativeEntryPath.'/'.$data['etag'].$permissions;
383 383
 		}
384 384
 	}
385 385
 
Please login to merge, or discard this patch.
Indentation   +352 added lines, -352 removed lines patch added patch discarded remove patch
@@ -35,356 +35,356 @@
 block discarded – undo
35 35
 use OCP\IUser;
36 36
 
37 37
 class FileInfo implements \OCP\Files\FileInfo, \ArrayAccess {
38
-	/**
39
-	 * @var array $data
40
-	 */
41
-	private $data;
42
-
43
-	/**
44
-	 * @var string $path
45
-	 */
46
-	private $path;
47
-
48
-	/**
49
-	 * @var \OC\Files\Storage\Storage $storage
50
-	 */
51
-	private $storage;
52
-
53
-	/**
54
-	 * @var string $internalPath
55
-	 */
56
-	private $internalPath;
57
-
58
-	/**
59
-	 * @var \OCP\Files\Mount\IMountPoint
60
-	 */
61
-	private $mount;
62
-
63
-	/**
64
-	 * @var IUser
65
-	 */
66
-	private $owner;
67
-
68
-	/**
69
-	 * @var string[]
70
-	 */
71
-	private $childEtags = [];
72
-
73
-	/**
74
-	 * @var IMountPoint[]
75
-	 */
76
-	private $subMounts = [];
77
-
78
-	private $subMountsUsed = false;
79
-
80
-	/**
81
-	 * @param string|boolean $path
82
-	 * @param Storage\Storage $storage
83
-	 * @param string $internalPath
84
-	 * @param array|ICacheEntry $data
85
-	 * @param \OCP\Files\Mount\IMountPoint $mount
86
-	 * @param \OCP\IUser|null $owner
87
-	 */
88
-	public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) {
89
-		$this->path = $path;
90
-		$this->storage = $storage;
91
-		$this->internalPath = $internalPath;
92
-		$this->data = $data;
93
-		$this->mount = $mount;
94
-		$this->owner = $owner;
95
-	}
96
-
97
-	public function offsetSet($offset, $value) {
98
-		$this->data[$offset] = $value;
99
-	}
100
-
101
-	public function offsetExists($offset) {
102
-		return isset($this->data[$offset]);
103
-	}
104
-
105
-	public function offsetUnset($offset) {
106
-		unset($this->data[$offset]);
107
-	}
108
-
109
-	public function offsetGet($offset) {
110
-		if ($offset === 'type') {
111
-			return $this->getType();
112
-		} else if ($offset === 'etag') {
113
-			return $this->getEtag();
114
-		} else if ($offset === 'size') {
115
-			return $this->getSize();
116
-		} else if ($offset === 'mtime') {
117
-			return $this->getMTime();
118
-		} elseif ($offset === 'permissions') {
119
-			return $this->getPermissions();
120
-		} elseif (isset($this->data[$offset])) {
121
-			return $this->data[$offset];
122
-		} else {
123
-			return null;
124
-		}
125
-	}
126
-
127
-	/**
128
-	 * @return string
129
-	 */
130
-	public function getPath() {
131
-		return $this->path;
132
-	}
133
-
134
-	/**
135
-	 * @return \OCP\Files\Storage
136
-	 */
137
-	public function getStorage() {
138
-		return $this->storage;
139
-	}
140
-
141
-	/**
142
-	 * @return string
143
-	 */
144
-	public function getInternalPath() {
145
-		return $this->internalPath;
146
-	}
147
-
148
-	/**
149
-	 * Get FileInfo ID or null in case of part file
150
-	 *
151
-	 * @return int|null
152
-	 */
153
-	public function getId() {
154
-		return isset($this->data['fileid']) ? (int)  $this->data['fileid'] : null;
155
-	}
156
-
157
-	/**
158
-	 * @return string
159
-	 */
160
-	public function getMimetype() {
161
-		return $this->data['mimetype'];
162
-	}
163
-
164
-	/**
165
-	 * @return string
166
-	 */
167
-	public function getMimePart() {
168
-		return $this->data['mimepart'];
169
-	}
170
-
171
-	/**
172
-	 * @return string
173
-	 */
174
-	public function getName() {
175
-		return basename($this->getPath());
176
-	}
177
-
178
-	/**
179
-	 * @return string
180
-	 */
181
-	public function getEtag() {
182
-		$this->updateEntryfromSubMounts();
183
-		if (count($this->childEtags) > 0) {
184
-			$combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
185
-			return md5($combinedEtag);
186
-		} else {
187
-			return $this->data['etag'];
188
-		}
189
-	}
190
-
191
-	/**
192
-	 * @return int
193
-	 */
194
-	public function getSize() {
195
-		$this->updateEntryfromSubMounts();
196
-		return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
197
-	}
198
-
199
-	/**
200
-	 * @return int
201
-	 */
202
-	public function getMTime() {
203
-		$this->updateEntryfromSubMounts();
204
-		return (int) $this->data['mtime'];
205
-	}
206
-
207
-	/**
208
-	 * @return bool
209
-	 */
210
-	public function isEncrypted() {
211
-		return $this->data['encrypted'];
212
-	}
213
-
214
-	/**
215
-	 * Return the currently version used for the HMAC in the encryption app
216
-	 *
217
-	 * @return int
218
-	 */
219
-	public function getEncryptedVersion() {
220
-		return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1;
221
-	}
222
-
223
-	/**
224
-	 * @return int
225
-	 */
226
-	public function getPermissions() {
227
-		$perms = (int) $this->data['permissions'];
228
-		if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) {
229
-			$perms = $perms & ~\OCP\Constants::PERMISSION_SHARE;
230
-		}
231
-		return (int) $perms;
232
-	}
233
-
234
-	/**
235
-	 * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
236
-	 */
237
-	public function getType() {
238
-		if (!isset($this->data['type'])) {
239
-			$this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE;
240
-		}
241
-		return $this->data['type'];
242
-	}
243
-
244
-	public function getData() {
245
-		return $this->data;
246
-	}
247
-
248
-	/**
249
-	 * @param int $permissions
250
-	 * @return bool
251
-	 */
252
-	protected function checkPermissions($permissions) {
253
-		return ($this->getPermissions() & $permissions) === $permissions;
254
-	}
255
-
256
-	/**
257
-	 * @return bool
258
-	 */
259
-	public function isReadable() {
260
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
261
-	}
262
-
263
-	/**
264
-	 * @return bool
265
-	 */
266
-	public function isUpdateable() {
267
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
268
-	}
269
-
270
-	/**
271
-	 * Check whether new files or folders can be created inside this folder
272
-	 *
273
-	 * @return bool
274
-	 */
275
-	public function isCreatable() {
276
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
277
-	}
278
-
279
-	/**
280
-	 * @return bool
281
-	 */
282
-	public function isDeletable() {
283
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
284
-	}
285
-
286
-	/**
287
-	 * @return bool
288
-	 */
289
-	public function isShareable() {
290
-		return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
291
-	}
292
-
293
-	/**
294
-	 * Check if a file or folder is shared
295
-	 *
296
-	 * @return bool
297
-	 */
298
-	public function isShared() {
299
-		$sid = $this->getStorage()->getId();
300
-		if (!is_null($sid)) {
301
-			$sid = explode(':', $sid);
302
-			return ($sid[0] === 'shared');
303
-		}
304
-
305
-		return false;
306
-	}
307
-
308
-	public function isMounted() {
309
-		$storage = $this->getStorage();
310
-		if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
311
-			return false;
312
-		}
313
-		$sid = $storage->getId();
314
-		if (!is_null($sid)) {
315
-			$sid = explode(':', $sid);
316
-			return ($sid[0] !== 'home' and $sid[0] !== 'shared');
317
-		}
318
-
319
-		return false;
320
-	}
321
-
322
-	/**
323
-	 * Get the mountpoint the file belongs to
324
-	 *
325
-	 * @return \OCP\Files\Mount\IMountPoint
326
-	 */
327
-	public function getMountPoint() {
328
-		return $this->mount;
329
-	}
330
-
331
-	/**
332
-	 * Get the owner of the file
333
-	 *
334
-	 * @return \OCP\IUser
335
-	 */
336
-	public function getOwner() {
337
-		return $this->owner;
338
-	}
339
-
340
-	/**
341
-	 * @param IMountPoint[] $mounts
342
-	 */
343
-	public function setSubMounts(array $mounts) {
344
-		$this->subMounts = $mounts;
345
-	}
346
-
347
-	private function updateEntryfromSubMounts() {
348
-		if ($this->subMountsUsed) {
349
-			return;
350
-		}
351
-		$this->subMountsUsed = true;
352
-		foreach ($this->subMounts as $mount) {
353
-			$subStorage = $mount->getStorage();
354
-			if ($subStorage) {
355
-				$subCache = $subStorage->getCache('');
356
-				$rootEntry = $subCache->get('');
357
-				$this->addSubEntry($rootEntry, $mount->getMountPoint());
358
-			}
359
-		}
360
-	}
361
-
362
-	/**
363
-	 * Add a cache entry which is the child of this folder
364
-	 *
365
-	 * Sets the size, etag and size to for cross-storage childs
366
-	 *
367
-	 * @param array|ICacheEntry $data cache entry for the child
368
-	 * @param string $entryPath full path of the child entry
369
-	 */
370
-	public function addSubEntry($data, $entryPath) {
371
-		$this->data['size'] += isset($data['size']) ? $data['size'] : 0;
372
-		if (isset($data['mtime'])) {
373
-			$this->data['mtime'] = max($this->data['mtime'], $data['mtime']);
374
-		}
375
-		if (isset($data['etag'])) {
376
-			// prefix the etag with the relative path of the subentry to propagate etag on mount moves
377
-			$relativeEntryPath = substr($entryPath, strlen($this->getPath()));
378
-			// attach the permissions to propagate etag on permision changes of submounts
379
-			$permissions = isset($data['permissions']) ? $data['permissions'] : 0;
380
-			$this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
381
-		}
382
-	}
383
-
384
-	/**
385
-	 * @inheritdoc
386
-	 */
387
-	public function getChecksum() {
388
-		return $this->data['checksum'];
389
-	}
38
+    /**
39
+     * @var array $data
40
+     */
41
+    private $data;
42
+
43
+    /**
44
+     * @var string $path
45
+     */
46
+    private $path;
47
+
48
+    /**
49
+     * @var \OC\Files\Storage\Storage $storage
50
+     */
51
+    private $storage;
52
+
53
+    /**
54
+     * @var string $internalPath
55
+     */
56
+    private $internalPath;
57
+
58
+    /**
59
+     * @var \OCP\Files\Mount\IMountPoint
60
+     */
61
+    private $mount;
62
+
63
+    /**
64
+     * @var IUser
65
+     */
66
+    private $owner;
67
+
68
+    /**
69
+     * @var string[]
70
+     */
71
+    private $childEtags = [];
72
+
73
+    /**
74
+     * @var IMountPoint[]
75
+     */
76
+    private $subMounts = [];
77
+
78
+    private $subMountsUsed = false;
79
+
80
+    /**
81
+     * @param string|boolean $path
82
+     * @param Storage\Storage $storage
83
+     * @param string $internalPath
84
+     * @param array|ICacheEntry $data
85
+     * @param \OCP\Files\Mount\IMountPoint $mount
86
+     * @param \OCP\IUser|null $owner
87
+     */
88
+    public function __construct($path, $storage, $internalPath, $data, $mount, $owner= null) {
89
+        $this->path = $path;
90
+        $this->storage = $storage;
91
+        $this->internalPath = $internalPath;
92
+        $this->data = $data;
93
+        $this->mount = $mount;
94
+        $this->owner = $owner;
95
+    }
96
+
97
+    public function offsetSet($offset, $value) {
98
+        $this->data[$offset] = $value;
99
+    }
100
+
101
+    public function offsetExists($offset) {
102
+        return isset($this->data[$offset]);
103
+    }
104
+
105
+    public function offsetUnset($offset) {
106
+        unset($this->data[$offset]);
107
+    }
108
+
109
+    public function offsetGet($offset) {
110
+        if ($offset === 'type') {
111
+            return $this->getType();
112
+        } else if ($offset === 'etag') {
113
+            return $this->getEtag();
114
+        } else if ($offset === 'size') {
115
+            return $this->getSize();
116
+        } else if ($offset === 'mtime') {
117
+            return $this->getMTime();
118
+        } elseif ($offset === 'permissions') {
119
+            return $this->getPermissions();
120
+        } elseif (isset($this->data[$offset])) {
121
+            return $this->data[$offset];
122
+        } else {
123
+            return null;
124
+        }
125
+    }
126
+
127
+    /**
128
+     * @return string
129
+     */
130
+    public function getPath() {
131
+        return $this->path;
132
+    }
133
+
134
+    /**
135
+     * @return \OCP\Files\Storage
136
+     */
137
+    public function getStorage() {
138
+        return $this->storage;
139
+    }
140
+
141
+    /**
142
+     * @return string
143
+     */
144
+    public function getInternalPath() {
145
+        return $this->internalPath;
146
+    }
147
+
148
+    /**
149
+     * Get FileInfo ID or null in case of part file
150
+     *
151
+     * @return int|null
152
+     */
153
+    public function getId() {
154
+        return isset($this->data['fileid']) ? (int)  $this->data['fileid'] : null;
155
+    }
156
+
157
+    /**
158
+     * @return string
159
+     */
160
+    public function getMimetype() {
161
+        return $this->data['mimetype'];
162
+    }
163
+
164
+    /**
165
+     * @return string
166
+     */
167
+    public function getMimePart() {
168
+        return $this->data['mimepart'];
169
+    }
170
+
171
+    /**
172
+     * @return string
173
+     */
174
+    public function getName() {
175
+        return basename($this->getPath());
176
+    }
177
+
178
+    /**
179
+     * @return string
180
+     */
181
+    public function getEtag() {
182
+        $this->updateEntryfromSubMounts();
183
+        if (count($this->childEtags) > 0) {
184
+            $combinedEtag = $this->data['etag'] . '::' . implode('::', $this->childEtags);
185
+            return md5($combinedEtag);
186
+        } else {
187
+            return $this->data['etag'];
188
+        }
189
+    }
190
+
191
+    /**
192
+     * @return int
193
+     */
194
+    public function getSize() {
195
+        $this->updateEntryfromSubMounts();
196
+        return isset($this->data['size']) ? 0 + $this->data['size'] : 0;
197
+    }
198
+
199
+    /**
200
+     * @return int
201
+     */
202
+    public function getMTime() {
203
+        $this->updateEntryfromSubMounts();
204
+        return (int) $this->data['mtime'];
205
+    }
206
+
207
+    /**
208
+     * @return bool
209
+     */
210
+    public function isEncrypted() {
211
+        return $this->data['encrypted'];
212
+    }
213
+
214
+    /**
215
+     * Return the currently version used for the HMAC in the encryption app
216
+     *
217
+     * @return int
218
+     */
219
+    public function getEncryptedVersion() {
220
+        return isset($this->data['encryptedVersion']) ? (int) $this->data['encryptedVersion'] : 1;
221
+    }
222
+
223
+    /**
224
+     * @return int
225
+     */
226
+    public function getPermissions() {
227
+        $perms = (int) $this->data['permissions'];
228
+        if (\OCP\Util::isSharingDisabledForUser() || ($this->isShared() && !\OC\Share\Share::isResharingAllowed())) {
229
+            $perms = $perms & ~\OCP\Constants::PERMISSION_SHARE;
230
+        }
231
+        return (int) $perms;
232
+    }
233
+
234
+    /**
235
+     * @return string \OCP\Files\FileInfo::TYPE_FILE|\OCP\Files\FileInfo::TYPE_FOLDER
236
+     */
237
+    public function getType() {
238
+        if (!isset($this->data['type'])) {
239
+            $this->data['type'] = ($this->getMimetype() === 'httpd/unix-directory') ? self::TYPE_FOLDER : self::TYPE_FILE;
240
+        }
241
+        return $this->data['type'];
242
+    }
243
+
244
+    public function getData() {
245
+        return $this->data;
246
+    }
247
+
248
+    /**
249
+     * @param int $permissions
250
+     * @return bool
251
+     */
252
+    protected function checkPermissions($permissions) {
253
+        return ($this->getPermissions() & $permissions) === $permissions;
254
+    }
255
+
256
+    /**
257
+     * @return bool
258
+     */
259
+    public function isReadable() {
260
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_READ);
261
+    }
262
+
263
+    /**
264
+     * @return bool
265
+     */
266
+    public function isUpdateable() {
267
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_UPDATE);
268
+    }
269
+
270
+    /**
271
+     * Check whether new files or folders can be created inside this folder
272
+     *
273
+     * @return bool
274
+     */
275
+    public function isCreatable() {
276
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_CREATE);
277
+    }
278
+
279
+    /**
280
+     * @return bool
281
+     */
282
+    public function isDeletable() {
283
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_DELETE);
284
+    }
285
+
286
+    /**
287
+     * @return bool
288
+     */
289
+    public function isShareable() {
290
+        return $this->checkPermissions(\OCP\Constants::PERMISSION_SHARE);
291
+    }
292
+
293
+    /**
294
+     * Check if a file or folder is shared
295
+     *
296
+     * @return bool
297
+     */
298
+    public function isShared() {
299
+        $sid = $this->getStorage()->getId();
300
+        if (!is_null($sid)) {
301
+            $sid = explode(':', $sid);
302
+            return ($sid[0] === 'shared');
303
+        }
304
+
305
+        return false;
306
+    }
307
+
308
+    public function isMounted() {
309
+        $storage = $this->getStorage();
310
+        if ($storage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
311
+            return false;
312
+        }
313
+        $sid = $storage->getId();
314
+        if (!is_null($sid)) {
315
+            $sid = explode(':', $sid);
316
+            return ($sid[0] !== 'home' and $sid[0] !== 'shared');
317
+        }
318
+
319
+        return false;
320
+    }
321
+
322
+    /**
323
+     * Get the mountpoint the file belongs to
324
+     *
325
+     * @return \OCP\Files\Mount\IMountPoint
326
+     */
327
+    public function getMountPoint() {
328
+        return $this->mount;
329
+    }
330
+
331
+    /**
332
+     * Get the owner of the file
333
+     *
334
+     * @return \OCP\IUser
335
+     */
336
+    public function getOwner() {
337
+        return $this->owner;
338
+    }
339
+
340
+    /**
341
+     * @param IMountPoint[] $mounts
342
+     */
343
+    public function setSubMounts(array $mounts) {
344
+        $this->subMounts = $mounts;
345
+    }
346
+
347
+    private function updateEntryfromSubMounts() {
348
+        if ($this->subMountsUsed) {
349
+            return;
350
+        }
351
+        $this->subMountsUsed = true;
352
+        foreach ($this->subMounts as $mount) {
353
+            $subStorage = $mount->getStorage();
354
+            if ($subStorage) {
355
+                $subCache = $subStorage->getCache('');
356
+                $rootEntry = $subCache->get('');
357
+                $this->addSubEntry($rootEntry, $mount->getMountPoint());
358
+            }
359
+        }
360
+    }
361
+
362
+    /**
363
+     * Add a cache entry which is the child of this folder
364
+     *
365
+     * Sets the size, etag and size to for cross-storage childs
366
+     *
367
+     * @param array|ICacheEntry $data cache entry for the child
368
+     * @param string $entryPath full path of the child entry
369
+     */
370
+    public function addSubEntry($data, $entryPath) {
371
+        $this->data['size'] += isset($data['size']) ? $data['size'] : 0;
372
+        if (isset($data['mtime'])) {
373
+            $this->data['mtime'] = max($this->data['mtime'], $data['mtime']);
374
+        }
375
+        if (isset($data['etag'])) {
376
+            // prefix the etag with the relative path of the subentry to propagate etag on mount moves
377
+            $relativeEntryPath = substr($entryPath, strlen($this->getPath()));
378
+            // attach the permissions to propagate etag on permision changes of submounts
379
+            $permissions = isset($data['permissions']) ? $data['permissions'] : 0;
380
+            $this->childEtags[] = $relativeEntryPath . '/' . $data['etag'] . $permissions;
381
+        }
382
+    }
383
+
384
+    /**
385
+     * @inheritdoc
386
+     */
387
+    public function getChecksum() {
388
+        return $this->data['checksum'];
389
+    }
390 390
 }
Please login to merge, or discard this patch.
lib/private/Template/SCSSCacher.php 4 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -114,8 +114,8 @@
 block discarded – undo
114 114
 	}
115 115
 
116 116
 	/**
117
-	 * @param $appName
118
-	 * @param $fileName
117
+	 * @param string $appName
118
+	 * @param string $fileName
119 119
 	 * @return ISimpleFile
120 120
 	 */
121 121
 	public function getCachedCSS($appName, $fileName) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -272,8 +272,9 @@
 block discarded – undo
272 272
 	 * @return string SCSS code for variables from OC_Defaults
273 273
 	 */
274 274
 	private function getInjectedVariables() {
275
-		if ($this->injectedVariables !== null)
276
-			return $this->injectedVariables;
275
+		if ($this->injectedVariables !== null) {
276
+					return $this->injectedVariables;
277
+		}
277 278
 		$variables = '';
278 279
 		foreach ($this->defaults->getScssVariables() as $key => $value) {
279 280
 			$variables .= '$' . $key . ': ' . $value . ';';
Please login to merge, or discard this patch.
Indentation   +321 added lines, -321 removed lines patch added patch discarded remove patch
@@ -46,325 +46,325 @@
 block discarded – undo
46 46
 
47 47
 class SCSSCacher {
48 48
 
49
-	/** @var ILogger */
50
-	protected $logger;
51
-
52
-	/** @var IAppData */
53
-	protected $appData;
54
-
55
-	/** @var IURLGenerator */
56
-	protected $urlGenerator;
57
-
58
-	/** @var IConfig */
59
-	protected $config;
60
-
61
-	/** @var string */
62
-	protected $serverRoot;
63
-
64
-	/** @var ICache */
65
-	protected $depsCache;
66
-
67
-	/** @var null|string */
68
-	protected $injectedVariables = null;
69
-
70
-	/** @var ICacheFactory */
71
-	private $cacheFactory;
72
-
73
-	/**
74
-	 * @param ILogger $logger
75
-	 * @param Factory $appDataFactory
76
-	 * @param IURLGenerator $urlGenerator
77
-	 * @param IConfig $config
78
-	 * @param \OC_Defaults $defaults
79
-	 * @param string $serverRoot
80
-	 * @param ICacheFactory $cacheFactory
81
-	 */
82
-	public function __construct(ILogger $logger,
83
-								Factory $appDataFactory,
84
-								IURLGenerator $urlGenerator,
85
-								IConfig $config,
86
-								\OC_Defaults $defaults,
87
-								$serverRoot,
88
-								ICacheFactory $cacheFactory) {
89
-		$this->logger = $logger;
90
-		$this->appData = $appDataFactory->get('css');
91
-		$this->urlGenerator = $urlGenerator;
92
-		$this->config = $config;
93
-		$this->defaults = $defaults;
94
-		$this->serverRoot = $serverRoot;
95
-		$this->cacheFactory = $cacheFactory;
96
-		$this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl()));
97
-	}
98
-
99
-	/**
100
-	 * Process the caching process if needed
101
-	 * @param string $root Root path to the nextcloud installation
102
-	 * @param string $file
103
-	 * @param string $app The app name
104
-	 * @return boolean
105
-	 */
106
-	public function process($root, $file, $app) {
107
-		$path = explode('/', $root . '/' . $file);
108
-
109
-		$fileNameSCSS = array_pop($path);
110
-		$fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app);
111
-
112
-		$path = implode('/', $path);
113
-		$webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT);
114
-
115
-		try {
116
-			$folder = $this->appData->getFolder($app);
117
-		} catch(NotFoundException $e) {
118
-			// creating css appdata folder
119
-			$folder = $this->appData->newFolder($app);
120
-		}
121
-
122
-
123
-		if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
124
-			return true;
125
-		}
126
-		return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir);
127
-	}
128
-
129
-	/**
130
-	 * @param $appName
131
-	 * @param $fileName
132
-	 * @return ISimpleFile
133
-	 */
134
-	public function getCachedCSS($appName, $fileName) {
135
-		$folder = $this->appData->getFolder($appName);
136
-		$cachedFileName = $this->prependVersionPrefix($this->prependBaseurlPrefix($fileName), $appName);
137
-		return $folder->getFile($cachedFileName);
138
-	}
139
-
140
-	/**
141
-	 * Check if the file is cached or not
142
-	 * @param string $fileNameCSS
143
-	 * @param ISimpleFolder $folder
144
-	 * @return boolean
145
-	 */
146
-	private function isCached($fileNameCSS, ISimpleFolder $folder) {
147
-		try {
148
-			$cachedFile = $folder->getFile($fileNameCSS);
149
-			if ($cachedFile->getSize() > 0) {
150
-				$depFileName = $fileNameCSS . '.deps';
151
-				$deps = $this->depsCache->get($folder->getName() . '-' . $depFileName);
152
-				if ($deps === null) {
153
-					$depFile = $folder->getFile($depFileName);
154
-					$deps = $depFile->getContent();
155
-					//Set to memcache for next run
156
-					$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
157
-				}
158
-				$deps = json_decode($deps, true);
159
-
160
-				foreach ($deps as $file=>$mtime) {
161
-					if (!file_exists($file) || filemtime($file) > $mtime) {
162
-						return false;
163
-					}
164
-				}
165
-				return true;
166
-			}
167
-			return false;
168
-		} catch(NotFoundException $e) {
169
-			return false;
170
-		}
171
-	}
172
-
173
-	/**
174
-	 * Check if the variables file has changed
175
-	 * @return bool
176
-	 */
177
-	private function variablesChanged() {
178
-		$injectedVariables = $this->getInjectedVariables();
179
-		if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
180
-			$this->resetCache();
181
-			$this->config->setAppValue('core', 'scss.variables', md5($injectedVariables));
182
-			return true;
183
-		}
184
-		return false;
185
-	}
186
-
187
-	/**
188
-	 * Cache the file with AppData
189
-	 * @param string $path
190
-	 * @param string $fileNameCSS
191
-	 * @param string $fileNameSCSS
192
-	 * @param ISimpleFolder $folder
193
-	 * @param string $webDir
194
-	 * @return boolean
195
-	 */
196
-	private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) {
197
-		$scss = new Compiler();
198
-		$scss->setImportPaths([
199
-			$path,
200
-			$this->serverRoot . '/core/css/',
201
-		]);
202
-		// Continue after throw
203
-		$scss->setIgnoreErrors(true);
204
-		if($this->config->getSystemValue('debug')) {
205
-			// Debug mode
206
-			$scss->setFormatter(Expanded::class);
207
-			$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
208
-		} else {
209
-			// Compression
210
-			$scss->setFormatter(Crunched::class);
211
-		}
212
-
213
-		try {
214
-			$cachedfile = $folder->getFile($fileNameCSS);
215
-		} catch(NotFoundException $e) {
216
-			$cachedfile = $folder->newFile($fileNameCSS);
217
-		}
218
-
219
-		$depFileName = $fileNameCSS . '.deps';
220
-		try {
221
-			$depFile = $folder->getFile($depFileName);
222
-		} catch (NotFoundException $e) {
223
-			$depFile = $folder->newFile($depFileName);
224
-		}
225
-
226
-		// Compile
227
-		try {
228
-			$compiledScss = $scss->compile(
229
-				'@import "variables.scss";' .
230
-				$this->getInjectedVariables() .
231
-				'@import "'.$fileNameSCSS.'";');
232
-		} catch(ParserException $e) {
233
-			$this->logger->error($e, ['app' => 'core']);
234
-			return false;
235
-		}
236
-
237
-		// Gzip file
238
-		try {
239
-			$gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
240
-		} catch (NotFoundException $e) {
241
-			$gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
242
-		}
243
-
244
-		try {
245
-			$data = $this->rebaseUrls($compiledScss, $webDir);
246
-			$cachedfile->putContent($data);
247
-			$deps = json_encode($scss->getParsedFiles());
248
-			$depFile->putContent($deps);
249
-			$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
250
-			$gzipFile->putContent(gzencode($data, 9));
251
-			$this->logger->debug('SCSSCacher: '.$webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']);
252
-			return true;
253
-		} catch(NotPermittedException $e) {
254
-			$this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS);
255
-			return false;
256
-		}
257
-	}
258
-
259
-	/**
260
-	 * Reset scss cache by deleting all generated css files
261
-	 * We need to regenerate all files when variables change
262
-	 */
263
-	public function resetCache() {
264
-		$this->injectedVariables = null;
265
-		$this->cacheFactory->createDistributed('SCSS-')->clear();
266
-		$appDirectory = $this->appData->getDirectoryListing();
267
-		foreach ($appDirectory as $folder) {
268
-			foreach ($folder->getDirectoryListing() as $file) {
269
-				try {
270
-					$file->delete();
271
-				} catch(NotPermittedException $e) {
272
-					$this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]);
273
-				}
274
-			}
275
-		}
276
-	}
277
-
278
-	/**
279
-	 * @return string SCSS code for variables from OC_Defaults
280
-	 */
281
-	private function getInjectedVariables() {
282
-		if ($this->injectedVariables !== null)
283
-			return $this->injectedVariables;
284
-		$variables = '';
285
-		foreach ($this->defaults->getScssVariables() as $key => $value) {
286
-			$variables .= '$' . $key . ': ' . $value . ';';
287
-		}
288
-
289
-		// check for valid variables / otherwise fall back to defaults
290
-		try {
291
-			$scss = new Compiler();
292
-			$scss->compile($variables);
293
-			$this->injectedVariables = $variables;
294
-		} catch (ParserException $e) {
295
-			$this->logger->error($e, ['app' => 'core']);
296
-		}
297
-
298
-		return $variables;
299
-	}
300
-
301
-	/**
302
-	 * Add the correct uri prefix to make uri valid again
303
-	 * @param string $css
304
-	 * @param string $webDir
305
-	 * @return string
306
-	 */
307
-	private function rebaseUrls($css, $webDir) {
308
-		$re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x';
309
-		$subst = 'url(\''.$webDir.'/$1\')';
310
-		return preg_replace($re, $subst, $css);
311
-	}
312
-
313
-	/**
314
-	 * Return the cached css file uri
315
-	 * @param string $appName the app name
316
-	 * @param string $fileName
317
-	 * @return string
318
-	 */
319
-	public function getCachedSCSS($appName, $fileName) {
320
-		$tmpfileLoc = explode('/', $fileName);
321
-		$fileName = array_pop($tmpfileLoc);
322
-		$fileName = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)), $appName);
323
-
324
-		return substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1);
325
-	}
326
-
327
-	/**
328
-	 * Prepend hashed base url to the css file
329
-	 * @param string $cssFile
330
-	 * @return string
331
-	 */
332
-	private function prependBaseurlPrefix($cssFile) {
333
-		$frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
334
-		return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 4) . '-' . $cssFile;
335
-	}
336
-
337
-	/**
338
-	 * Prepend hashed app version hash
339
-	 * @param string $cssFile
340
-	 * @param string $appId
341
-	 * @return string
342
-	 */
343
-	private function prependVersionPrefix($cssFile, $appId) {
344
-		$appVersion = \OC_App::getAppVersion($appId);
345
-		if ($appVersion !== '0') {
346
-			return substr(md5($appVersion), 0, 4) . '-' . $cssFile;
347
-		}
348
-		$coreVersion = \OC_Util::getVersionString();
349
-		return substr(md5($coreVersion), 0, 4) . '-' . $cssFile;
350
-	}
351
-
352
-	/**
353
-	 * Get WebDir root
354
-	 * @param string $path the css file path
355
-	 * @param string $appName the app name
356
-	 * @param string $serverRoot the server root path
357
-	 * @param string $webRoot the nextcloud installation root path
358
-	 * @return string the webDir
359
-	 */
360
-	private function getWebDir($path, $appName, $serverRoot, $webRoot) {
361
-		// Detect if path is within server root AND if path is within an app path
362
-		if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) {
363
-			// Get the file path within the app directory
364
-			$appDirectoryPath = explode($appName, $path)[1];
365
-			// Remove the webroot
366
-			return str_replace($webRoot, '', $appWebPath.$appDirectoryPath);
367
-		}
368
-		return $webRoot.substr($path, strlen($serverRoot));
369
-	}
49
+    /** @var ILogger */
50
+    protected $logger;
51
+
52
+    /** @var IAppData */
53
+    protected $appData;
54
+
55
+    /** @var IURLGenerator */
56
+    protected $urlGenerator;
57
+
58
+    /** @var IConfig */
59
+    protected $config;
60
+
61
+    /** @var string */
62
+    protected $serverRoot;
63
+
64
+    /** @var ICache */
65
+    protected $depsCache;
66
+
67
+    /** @var null|string */
68
+    protected $injectedVariables = null;
69
+
70
+    /** @var ICacheFactory */
71
+    private $cacheFactory;
72
+
73
+    /**
74
+     * @param ILogger $logger
75
+     * @param Factory $appDataFactory
76
+     * @param IURLGenerator $urlGenerator
77
+     * @param IConfig $config
78
+     * @param \OC_Defaults $defaults
79
+     * @param string $serverRoot
80
+     * @param ICacheFactory $cacheFactory
81
+     */
82
+    public function __construct(ILogger $logger,
83
+                                Factory $appDataFactory,
84
+                                IURLGenerator $urlGenerator,
85
+                                IConfig $config,
86
+                                \OC_Defaults $defaults,
87
+                                $serverRoot,
88
+                                ICacheFactory $cacheFactory) {
89
+        $this->logger = $logger;
90
+        $this->appData = $appDataFactory->get('css');
91
+        $this->urlGenerator = $urlGenerator;
92
+        $this->config = $config;
93
+        $this->defaults = $defaults;
94
+        $this->serverRoot = $serverRoot;
95
+        $this->cacheFactory = $cacheFactory;
96
+        $this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl()));
97
+    }
98
+
99
+    /**
100
+     * Process the caching process if needed
101
+     * @param string $root Root path to the nextcloud installation
102
+     * @param string $file
103
+     * @param string $app The app name
104
+     * @return boolean
105
+     */
106
+    public function process($root, $file, $app) {
107
+        $path = explode('/', $root . '/' . $file);
108
+
109
+        $fileNameSCSS = array_pop($path);
110
+        $fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app);
111
+
112
+        $path = implode('/', $path);
113
+        $webDir = $this->getWebDir($path, $app, $this->serverRoot, \OC::$WEBROOT);
114
+
115
+        try {
116
+            $folder = $this->appData->getFolder($app);
117
+        } catch(NotFoundException $e) {
118
+            // creating css appdata folder
119
+            $folder = $this->appData->newFolder($app);
120
+        }
121
+
122
+
123
+        if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
124
+            return true;
125
+        }
126
+        return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir);
127
+    }
128
+
129
+    /**
130
+     * @param $appName
131
+     * @param $fileName
132
+     * @return ISimpleFile
133
+     */
134
+    public function getCachedCSS($appName, $fileName) {
135
+        $folder = $this->appData->getFolder($appName);
136
+        $cachedFileName = $this->prependVersionPrefix($this->prependBaseurlPrefix($fileName), $appName);
137
+        return $folder->getFile($cachedFileName);
138
+    }
139
+
140
+    /**
141
+     * Check if the file is cached or not
142
+     * @param string $fileNameCSS
143
+     * @param ISimpleFolder $folder
144
+     * @return boolean
145
+     */
146
+    private function isCached($fileNameCSS, ISimpleFolder $folder) {
147
+        try {
148
+            $cachedFile = $folder->getFile($fileNameCSS);
149
+            if ($cachedFile->getSize() > 0) {
150
+                $depFileName = $fileNameCSS . '.deps';
151
+                $deps = $this->depsCache->get($folder->getName() . '-' . $depFileName);
152
+                if ($deps === null) {
153
+                    $depFile = $folder->getFile($depFileName);
154
+                    $deps = $depFile->getContent();
155
+                    //Set to memcache for next run
156
+                    $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
157
+                }
158
+                $deps = json_decode($deps, true);
159
+
160
+                foreach ($deps as $file=>$mtime) {
161
+                    if (!file_exists($file) || filemtime($file) > $mtime) {
162
+                        return false;
163
+                    }
164
+                }
165
+                return true;
166
+            }
167
+            return false;
168
+        } catch(NotFoundException $e) {
169
+            return false;
170
+        }
171
+    }
172
+
173
+    /**
174
+     * Check if the variables file has changed
175
+     * @return bool
176
+     */
177
+    private function variablesChanged() {
178
+        $injectedVariables = $this->getInjectedVariables();
179
+        if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
180
+            $this->resetCache();
181
+            $this->config->setAppValue('core', 'scss.variables', md5($injectedVariables));
182
+            return true;
183
+        }
184
+        return false;
185
+    }
186
+
187
+    /**
188
+     * Cache the file with AppData
189
+     * @param string $path
190
+     * @param string $fileNameCSS
191
+     * @param string $fileNameSCSS
192
+     * @param ISimpleFolder $folder
193
+     * @param string $webDir
194
+     * @return boolean
195
+     */
196
+    private function cache($path, $fileNameCSS, $fileNameSCSS, ISimpleFolder $folder, $webDir) {
197
+        $scss = new Compiler();
198
+        $scss->setImportPaths([
199
+            $path,
200
+            $this->serverRoot . '/core/css/',
201
+        ]);
202
+        // Continue after throw
203
+        $scss->setIgnoreErrors(true);
204
+        if($this->config->getSystemValue('debug')) {
205
+            // Debug mode
206
+            $scss->setFormatter(Expanded::class);
207
+            $scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
208
+        } else {
209
+            // Compression
210
+            $scss->setFormatter(Crunched::class);
211
+        }
212
+
213
+        try {
214
+            $cachedfile = $folder->getFile($fileNameCSS);
215
+        } catch(NotFoundException $e) {
216
+            $cachedfile = $folder->newFile($fileNameCSS);
217
+        }
218
+
219
+        $depFileName = $fileNameCSS . '.deps';
220
+        try {
221
+            $depFile = $folder->getFile($depFileName);
222
+        } catch (NotFoundException $e) {
223
+            $depFile = $folder->newFile($depFileName);
224
+        }
225
+
226
+        // Compile
227
+        try {
228
+            $compiledScss = $scss->compile(
229
+                '@import "variables.scss";' .
230
+                $this->getInjectedVariables() .
231
+                '@import "'.$fileNameSCSS.'";');
232
+        } catch(ParserException $e) {
233
+            $this->logger->error($e, ['app' => 'core']);
234
+            return false;
235
+        }
236
+
237
+        // Gzip file
238
+        try {
239
+            $gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
240
+        } catch (NotFoundException $e) {
241
+            $gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
242
+        }
243
+
244
+        try {
245
+            $data = $this->rebaseUrls($compiledScss, $webDir);
246
+            $cachedfile->putContent($data);
247
+            $deps = json_encode($scss->getParsedFiles());
248
+            $depFile->putContent($deps);
249
+            $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
250
+            $gzipFile->putContent(gzencode($data, 9));
251
+            $this->logger->debug('SCSSCacher: '.$webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']);
252
+            return true;
253
+        } catch(NotPermittedException $e) {
254
+            $this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS);
255
+            return false;
256
+        }
257
+    }
258
+
259
+    /**
260
+     * Reset scss cache by deleting all generated css files
261
+     * We need to regenerate all files when variables change
262
+     */
263
+    public function resetCache() {
264
+        $this->injectedVariables = null;
265
+        $this->cacheFactory->createDistributed('SCSS-')->clear();
266
+        $appDirectory = $this->appData->getDirectoryListing();
267
+        foreach ($appDirectory as $folder) {
268
+            foreach ($folder->getDirectoryListing() as $file) {
269
+                try {
270
+                    $file->delete();
271
+                } catch(NotPermittedException $e) {
272
+                    $this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]);
273
+                }
274
+            }
275
+        }
276
+    }
277
+
278
+    /**
279
+     * @return string SCSS code for variables from OC_Defaults
280
+     */
281
+    private function getInjectedVariables() {
282
+        if ($this->injectedVariables !== null)
283
+            return $this->injectedVariables;
284
+        $variables = '';
285
+        foreach ($this->defaults->getScssVariables() as $key => $value) {
286
+            $variables .= '$' . $key . ': ' . $value . ';';
287
+        }
288
+
289
+        // check for valid variables / otherwise fall back to defaults
290
+        try {
291
+            $scss = new Compiler();
292
+            $scss->compile($variables);
293
+            $this->injectedVariables = $variables;
294
+        } catch (ParserException $e) {
295
+            $this->logger->error($e, ['app' => 'core']);
296
+        }
297
+
298
+        return $variables;
299
+    }
300
+
301
+    /**
302
+     * Add the correct uri prefix to make uri valid again
303
+     * @param string $css
304
+     * @param string $webDir
305
+     * @return string
306
+     */
307
+    private function rebaseUrls($css, $webDir) {
308
+        $re = '/url\([\'"]([^\/][\.\w?=\/-]*)[\'"]\)/x';
309
+        $subst = 'url(\''.$webDir.'/$1\')';
310
+        return preg_replace($re, $subst, $css);
311
+    }
312
+
313
+    /**
314
+     * Return the cached css file uri
315
+     * @param string $appName the app name
316
+     * @param string $fileName
317
+     * @return string
318
+     */
319
+    public function getCachedSCSS($appName, $fileName) {
320
+        $tmpfileLoc = explode('/', $fileName);
321
+        $fileName = array_pop($tmpfileLoc);
322
+        $fileName = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileName)), $appName);
323
+
324
+        return substr($this->urlGenerator->linkToRoute('core.Css.getCss', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1);
325
+    }
326
+
327
+    /**
328
+     * Prepend hashed base url to the css file
329
+     * @param string $cssFile
330
+     * @return string
331
+     */
332
+    private function prependBaseurlPrefix($cssFile) {
333
+        $frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
334
+        return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 4) . '-' . $cssFile;
335
+    }
336
+
337
+    /**
338
+     * Prepend hashed app version hash
339
+     * @param string $cssFile
340
+     * @param string $appId
341
+     * @return string
342
+     */
343
+    private function prependVersionPrefix($cssFile, $appId) {
344
+        $appVersion = \OC_App::getAppVersion($appId);
345
+        if ($appVersion !== '0') {
346
+            return substr(md5($appVersion), 0, 4) . '-' . $cssFile;
347
+        }
348
+        $coreVersion = \OC_Util::getVersionString();
349
+        return substr(md5($coreVersion), 0, 4) . '-' . $cssFile;
350
+    }
351
+
352
+    /**
353
+     * Get WebDir root
354
+     * @param string $path the css file path
355
+     * @param string $appName the app name
356
+     * @param string $serverRoot the server root path
357
+     * @param string $webRoot the nextcloud installation root path
358
+     * @return string the webDir
359
+     */
360
+    private function getWebDir($path, $appName, $serverRoot, $webRoot) {
361
+        // Detect if path is within server root AND if path is within an app path
362
+        if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) {
363
+            // Get the file path within the app directory
364
+            $appDirectoryPath = explode($appName, $path)[1];
365
+            // Remove the webroot
366
+            return str_replace($webRoot, '', $appWebPath.$appDirectoryPath);
367
+        }
368
+        return $webRoot.substr($path, strlen($serverRoot));
369
+    }
370 370
 }
Please login to merge, or discard this patch.
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 		$this->defaults = $defaults;
94 94
 		$this->serverRoot = $serverRoot;
95 95
 		$this->cacheFactory = $cacheFactory;
96
-		$this->depsCache = $cacheFactory->createDistributed('SCSS-' . md5($this->urlGenerator->getBaseUrl()));
96
+		$this->depsCache = $cacheFactory->createDistributed('SCSS-'.md5($this->urlGenerator->getBaseUrl()));
97 97
 	}
98 98
 
99 99
 	/**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 	 * @return boolean
105 105
 	 */
106 106
 	public function process($root, $file, $app) {
107
-		$path = explode('/', $root . '/' . $file);
107
+		$path = explode('/', $root.'/'.$file);
108 108
 
109 109
 		$fileNameSCSS = array_pop($path);
110 110
 		$fileNameCSS = $this->prependVersionPrefix($this->prependBaseurlPrefix(str_replace('.scss', '.css', $fileNameSCSS)), $app);
@@ -114,13 +114,13 @@  discard block
 block discarded – undo
114 114
 
115 115
 		try {
116 116
 			$folder = $this->appData->getFolder($app);
117
-		} catch(NotFoundException $e) {
117
+		} catch (NotFoundException $e) {
118 118
 			// creating css appdata folder
119 119
 			$folder = $this->appData->newFolder($app);
120 120
 		}
121 121
 
122 122
 
123
-		if(!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
123
+		if (!$this->variablesChanged() && $this->isCached($fileNameCSS, $folder)) {
124 124
 			return true;
125 125
 		}
126 126
 		return $this->cache($path, $fileNameCSS, $fileNameSCSS, $folder, $webDir);
@@ -147,13 +147,13 @@  discard block
 block discarded – undo
147 147
 		try {
148 148
 			$cachedFile = $folder->getFile($fileNameCSS);
149 149
 			if ($cachedFile->getSize() > 0) {
150
-				$depFileName = $fileNameCSS . '.deps';
151
-				$deps = $this->depsCache->get($folder->getName() . '-' . $depFileName);
150
+				$depFileName = $fileNameCSS.'.deps';
151
+				$deps = $this->depsCache->get($folder->getName().'-'.$depFileName);
152 152
 				if ($deps === null) {
153 153
 					$depFile = $folder->getFile($depFileName);
154 154
 					$deps = $depFile->getContent();
155 155
 					//Set to memcache for next run
156
-					$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
156
+					$this->depsCache->set($folder->getName().'-'.$depFileName, $deps);
157 157
 				}
158 158
 				$deps = json_decode($deps, true);
159 159
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 				return true;
166 166
 			}
167 167
 			return false;
168
-		} catch(NotFoundException $e) {
168
+		} catch (NotFoundException $e) {
169 169
 			return false;
170 170
 		}
171 171
 	}
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	private function variablesChanged() {
178 178
 		$injectedVariables = $this->getInjectedVariables();
179
-		if($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
179
+		if ($this->config->getAppValue('core', 'scss.variables') !== md5($injectedVariables)) {
180 180
 			$this->resetCache();
181 181
 			$this->config->setAppValue('core', 'scss.variables', md5($injectedVariables));
182 182
 			return true;
@@ -197,11 +197,11 @@  discard block
 block discarded – undo
197 197
 		$scss = new Compiler();
198 198
 		$scss->setImportPaths([
199 199
 			$path,
200
-			$this->serverRoot . '/core/css/',
200
+			$this->serverRoot.'/core/css/',
201 201
 		]);
202 202
 		// Continue after throw
203 203
 		$scss->setIgnoreErrors(true);
204
-		if($this->config->getSystemValue('debug')) {
204
+		if ($this->config->getSystemValue('debug')) {
205 205
 			// Debug mode
206 206
 			$scss->setFormatter(Expanded::class);
207 207
 			$scss->setLineNumberStyle(Compiler::LINE_COMMENTS);
@@ -212,11 +212,11 @@  discard block
 block discarded – undo
212 212
 
213 213
 		try {
214 214
 			$cachedfile = $folder->getFile($fileNameCSS);
215
-		} catch(NotFoundException $e) {
215
+		} catch (NotFoundException $e) {
216 216
 			$cachedfile = $folder->newFile($fileNameCSS);
217 217
 		}
218 218
 
219
-		$depFileName = $fileNameCSS . '.deps';
219
+		$depFileName = $fileNameCSS.'.deps';
220 220
 		try {
221 221
 			$depFile = $folder->getFile($depFileName);
222 222
 		} catch (NotFoundException $e) {
@@ -226,19 +226,19 @@  discard block
 block discarded – undo
226 226
 		// Compile
227 227
 		try {
228 228
 			$compiledScss = $scss->compile(
229
-				'@import "variables.scss";' .
230
-				$this->getInjectedVariables() .
229
+				'@import "variables.scss";'.
230
+				$this->getInjectedVariables().
231 231
 				'@import "'.$fileNameSCSS.'";');
232
-		} catch(ParserException $e) {
232
+		} catch (ParserException $e) {
233 233
 			$this->logger->error($e, ['app' => 'core']);
234 234
 			return false;
235 235
 		}
236 236
 
237 237
 		// Gzip file
238 238
 		try {
239
-			$gzipFile = $folder->getFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
239
+			$gzipFile = $folder->getFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz
240 240
 		} catch (NotFoundException $e) {
241
-			$gzipFile = $folder->newFile($fileNameCSS . '.gzip'); # Safari doesn't like .gz
241
+			$gzipFile = $folder->newFile($fileNameCSS.'.gzip'); # Safari doesn't like .gz
242 242
 		}
243 243
 
244 244
 		try {
@@ -246,12 +246,12 @@  discard block
 block discarded – undo
246 246
 			$cachedfile->putContent($data);
247 247
 			$deps = json_encode($scss->getParsedFiles());
248 248
 			$depFile->putContent($deps);
249
-			$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
249
+			$this->depsCache->set($folder->getName().'-'.$depFileName, $deps);
250 250
 			$gzipFile->putContent(gzencode($data, 9));
251 251
 			$this->logger->debug('SCSSCacher: '.$webDir.'/'.$fileNameSCSS.' compiled and successfully cached', ['app' => 'core']);
252 252
 			return true;
253
-		} catch(NotPermittedException $e) {
254
-			$this->logger->error('SCSSCacher: unable to cache: ' . $fileNameSCSS);
253
+		} catch (NotPermittedException $e) {
254
+			$this->logger->error('SCSSCacher: unable to cache: '.$fileNameSCSS);
255 255
 			return false;
256 256
 		}
257 257
 	}
@@ -268,8 +268,8 @@  discard block
 block discarded – undo
268 268
 			foreach ($folder->getDirectoryListing() as $file) {
269 269
 				try {
270 270
 					$file->delete();
271
-				} catch(NotPermittedException $e) {
272
-					$this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: ' . $file->getName()]);
271
+				} catch (NotPermittedException $e) {
272
+					$this->logger->logException($e, ['message' => 'SCSSCacher: unable to delete file: '.$file->getName()]);
273 273
 				}
274 274
 			}
275 275
 		}
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 			return $this->injectedVariables;
284 284
 		$variables = '';
285 285
 		foreach ($this->defaults->getScssVariables() as $key => $value) {
286
-			$variables .= '$' . $key . ': ' . $value . ';';
286
+			$variables .= '$'.$key.': '.$value.';';
287 287
 		}
288 288
 
289 289
 		// check for valid variables / otherwise fall back to defaults
@@ -331,7 +331,7 @@  discard block
 block discarded – undo
331 331
 	 */
332 332
 	private function prependBaseurlPrefix($cssFile) {
333 333
 		$frontendController = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');
334
-		return substr(md5($this->urlGenerator->getBaseUrl() . $frontendController), 0, 4) . '-' . $cssFile;
334
+		return substr(md5($this->urlGenerator->getBaseUrl().$frontendController), 0, 4).'-'.$cssFile;
335 335
 	}
336 336
 
337 337
 	/**
@@ -343,10 +343,10 @@  discard block
 block discarded – undo
343 343
 	private function prependVersionPrefix($cssFile, $appId) {
344 344
 		$appVersion = \OC_App::getAppVersion($appId);
345 345
 		if ($appVersion !== '0') {
346
-			return substr(md5($appVersion), 0, 4) . '-' . $cssFile;
346
+			return substr(md5($appVersion), 0, 4).'-'.$cssFile;
347 347
 		}
348 348
 		$coreVersion = \OC_Util::getVersionString();
349
-		return substr(md5($coreVersion), 0, 4) . '-' . $cssFile;
349
+		return substr(md5($coreVersion), 0, 4).'-'.$cssFile;
350 350
 	}
351 351
 
352 352
 	/**
@@ -359,7 +359,7 @@  discard block
 block discarded – undo
359 359
 	 */
360 360
 	private function getWebDir($path, $appName, $serverRoot, $webRoot) {
361 361
 		// Detect if path is within server root AND if path is within an app path
362
-		if ( strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) {
362
+		if (strpos($path, $serverRoot) === false && $appWebPath = \OC_App::getAppWebPath($appName)) {
363 363
 			// Get the file path within the app directory
364 364
 			$appDirectoryPath = explode($appName, $path)[1];
365 365
 			// Remove the webroot
Please login to merge, or discard this patch.
lib/private/RedisFactory.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -23,86 +23,86 @@
 block discarded – undo
23 23
 namespace OC;
24 24
 
25 25
 class RedisFactory {
26
-	/** @var  \Redis */
27
-	private $instance;
26
+    /** @var  \Redis */
27
+    private $instance;
28 28
 
29
-	/** @var  SystemConfig */
30
-	private $config;
29
+    /** @var  SystemConfig */
30
+    private $config;
31 31
 
32
-	/**
33
-	 * RedisFactory constructor.
34
-	 *
35
-	 * @param SystemConfig $config
36
-	 */
37
-	public function __construct(SystemConfig $config) {
38
-		$this->config = $config;
39
-	}
32
+    /**
33
+     * RedisFactory constructor.
34
+     *
35
+     * @param SystemConfig $config
36
+     */
37
+    public function __construct(SystemConfig $config) {
38
+        $this->config = $config;
39
+    }
40 40
 
41
-	private function create() {
42
-		if ($config = $this->config->getValue('redis.cluster', [])) {
43
-			if (!class_exists('RedisCluster')) {
44
-				throw new \Exception('Redis Cluster support is not available');
45
-			}
46
-			// cluster config
47
-			if (isset($config['timeout'])) {
48
-				$timeout = $config['timeout'];
49
-			} else {
50
-				$timeout = null;
51
-			}
52
-			if (isset($config['read_timeout'])) {
53
-				$readTimeout = $config['read_timeout'];
54
-			} else {
55
-				$readTimeout = null;
56
-			}
57
-			$this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout);
41
+    private function create() {
42
+        if ($config = $this->config->getValue('redis.cluster', [])) {
43
+            if (!class_exists('RedisCluster')) {
44
+                throw new \Exception('Redis Cluster support is not available');
45
+            }
46
+            // cluster config
47
+            if (isset($config['timeout'])) {
48
+                $timeout = $config['timeout'];
49
+            } else {
50
+                $timeout = null;
51
+            }
52
+            if (isset($config['read_timeout'])) {
53
+                $readTimeout = $config['read_timeout'];
54
+            } else {
55
+                $readTimeout = null;
56
+            }
57
+            $this->instance = new \RedisCluster(null, $config['seeds'], $timeout, $readTimeout);
58 58
 
59
-			if (isset($config['failover_mode'])) {
60
-				$this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']);
61
-			}
62
-		} else {
59
+            if (isset($config['failover_mode'])) {
60
+                $this->instance->setOption(\RedisCluster::OPT_SLAVE_FAILOVER, $config['failover_mode']);
61
+            }
62
+        } else {
63 63
 
64
-			$this->instance = new \Redis();
65
-			$config = $this->config->getValue('redis', []);
66
-			if (isset($config['host'])) {
67
-				$host = $config['host'];
68
-			} else {
69
-				$host = '127.0.0.1';
70
-			}
71
-			if (isset($config['port'])) {
72
-				$port = $config['port'];
73
-			} else {
74
-				$port = 6379;
75
-			}
76
-			if (isset($config['timeout'])) {
77
-				$timeout = $config['timeout'];
78
-			} else {
79
-				$timeout = 0.0; // unlimited
80
-			}
64
+            $this->instance = new \Redis();
65
+            $config = $this->config->getValue('redis', []);
66
+            if (isset($config['host'])) {
67
+                $host = $config['host'];
68
+            } else {
69
+                $host = '127.0.0.1';
70
+            }
71
+            if (isset($config['port'])) {
72
+                $port = $config['port'];
73
+            } else {
74
+                $port = 6379;
75
+            }
76
+            if (isset($config['timeout'])) {
77
+                $timeout = $config['timeout'];
78
+            } else {
79
+                $timeout = 0.0; // unlimited
80
+            }
81 81
 
82
-			$this->instance->connect($host, $port, $timeout);
83
-			if (isset($config['password']) && $config['password'] !== '') {
84
-				$this->instance->auth($config['password']);
85
-			}
82
+            $this->instance->connect($host, $port, $timeout);
83
+            if (isset($config['password']) && $config['password'] !== '') {
84
+                $this->instance->auth($config['password']);
85
+            }
86 86
 
87
-			if (isset($config['dbindex'])) {
88
-				$this->instance->select($config['dbindex']);
89
-			}
90
-		}
91
-	}
87
+            if (isset($config['dbindex'])) {
88
+                $this->instance->select($config['dbindex']);
89
+            }
90
+        }
91
+    }
92 92
 
93
-	public function getInstance() {
94
-		if (!$this->isAvailable()) {
95
-			throw new \Exception('Redis support is not available');
96
-		}
97
-		if (!$this->instance instanceof \Redis) {
98
-			$this->create();
99
-		}
93
+    public function getInstance() {
94
+        if (!$this->isAvailable()) {
95
+            throw new \Exception('Redis support is not available');
96
+        }
97
+        if (!$this->instance instanceof \Redis) {
98
+            $this->create();
99
+        }
100 100
 
101
-		return $this->instance;
102
-	}
101
+        return $this->instance;
102
+    }
103 103
 
104
-	public function isAvailable() {
105
-		return extension_loaded('redis')
106
-		&& version_compare(phpversion('redis'), '2.2.5', '>=');
107
-	}
104
+    public function isAvailable() {
105
+        return extension_loaded('redis')
106
+        && version_compare(phpversion('redis'), '2.2.5', '>=');
107
+    }
108 108
 }
Please login to merge, or discard this patch.
apps/dav/lib/Avatars/AvatarHome.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -98,6 +98,9 @@
 block discarded – undo
98 98
 		throw new Forbidden('Permission denied to delete this folder');
99 99
 	}
100 100
 
101
+	/**
102
+	 * @return string
103
+	 */
101 104
 	public function getName() {
102 105
 		list(,$name) = Uri\split($this->principalInfo['uri']);
103 106
 		return $name;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	public function getChild($name) {
60 60
 		$elements = pathinfo($name);
61 61
 		$ext = isset($elements['extension']) ? $elements['extension'] : '';
62
-		$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
62
+		$size = (int) (isset($elements['filename']) ? $elements['filename'] : '64');
63 63
 		if (!in_array($ext, ['jpeg', 'png'], true)) {
64 64
 			throw new MethodNotAllowed('File format not allowed');
65 65
 		}
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 			return [
79 79
 				$this->getChild('96.jpeg')
80 80
 			];
81
-		} catch(NotFound $exception) {
81
+		} catch (NotFound $exception) {
82 82
 			return [];
83 83
 		}
84 84
 	}
Please login to merge, or discard this patch.
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -32,89 +32,89 @@
 block discarded – undo
32 32
 
33 33
 class AvatarHome implements ICollection {
34 34
 
35
-	/** @var array */
36
-	private $principalInfo;
37
-	/** @var IAvatarManager */
38
-	private $avatarManager;
39
-
40
-	/**
41
-	 * AvatarHome constructor.
42
-	 *
43
-	 * @param array $principalInfo
44
-	 * @param IAvatarManager $avatarManager
45
-	 */
46
-	public function __construct($principalInfo, IAvatarManager $avatarManager) {
47
-		$this->principalInfo = $principalInfo;
48
-		$this->avatarManager = $avatarManager;
49
-	}
50
-
51
-	public function createFile($name, $data = null) {
52
-		throw new Forbidden('Permission denied to create a file');
53
-	}
54
-
55
-	public function createDirectory($name) {
56
-		throw new Forbidden('Permission denied to create a folder');
57
-	}
58
-
59
-	public function getChild($name) {
60
-		$elements = pathinfo($name);
61
-		$ext = isset($elements['extension']) ? $elements['extension'] : '';
62
-		$size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
63
-		if (!in_array($ext, ['jpeg', 'png'], true)) {
64
-			throw new MethodNotAllowed('File format not allowed');
65
-		}
66
-		if ($size <= 0 || $size > 1024) {
67
-			throw new MethodNotAllowed('Invalid image size');
68
-		}
69
-		$avatar = $this->avatarManager->getAvatar($this->getName());
70
-		if ($avatar === null || !$avatar->exists()) {
71
-			throw new NotFound();
72
-		}
73
-		return new AvatarNode($size, $ext, $avatar);
74
-	}
75
-
76
-	public function getChildren() {
77
-		try {
78
-			return [
79
-				$this->getChild('96.jpeg')
80
-			];
81
-		} catch(NotFound $exception) {
82
-			return [];
83
-		}
84
-	}
85
-
86
-	public function childExists($name) {
87
-		try {
88
-			$ret = $this->getChild($name);
89
-			return $ret !== null;
90
-		} catch (NotFound $ex) {
91
-			return false;
92
-		} catch (MethodNotAllowed $ex) {
93
-			return false;
94
-		}
95
-	}
96
-
97
-	public function delete() {
98
-		throw new Forbidden('Permission denied to delete this folder');
99
-	}
100
-
101
-	public function getName() {
102
-		list(,$name) = Uri\split($this->principalInfo['uri']);
103
-		return $name;
104
-	}
105
-
106
-	public function setName($name) {
107
-		throw new Forbidden('Permission denied to rename this folder');
108
-	}
109
-
110
-	/**
111
-	 * Returns the last modification time, as a unix timestamp
112
-	 *
113
-	 * @return int|null
114
-	 */
115
-	public function getLastModified() {
116
-		return null;
117
-	}
35
+    /** @var array */
36
+    private $principalInfo;
37
+    /** @var IAvatarManager */
38
+    private $avatarManager;
39
+
40
+    /**
41
+     * AvatarHome constructor.
42
+     *
43
+     * @param array $principalInfo
44
+     * @param IAvatarManager $avatarManager
45
+     */
46
+    public function __construct($principalInfo, IAvatarManager $avatarManager) {
47
+        $this->principalInfo = $principalInfo;
48
+        $this->avatarManager = $avatarManager;
49
+    }
50
+
51
+    public function createFile($name, $data = null) {
52
+        throw new Forbidden('Permission denied to create a file');
53
+    }
54
+
55
+    public function createDirectory($name) {
56
+        throw new Forbidden('Permission denied to create a folder');
57
+    }
58
+
59
+    public function getChild($name) {
60
+        $elements = pathinfo($name);
61
+        $ext = isset($elements['extension']) ? $elements['extension'] : '';
62
+        $size = (int)(isset($elements['filename']) ? $elements['filename'] : '64');
63
+        if (!in_array($ext, ['jpeg', 'png'], true)) {
64
+            throw new MethodNotAllowed('File format not allowed');
65
+        }
66
+        if ($size <= 0 || $size > 1024) {
67
+            throw new MethodNotAllowed('Invalid image size');
68
+        }
69
+        $avatar = $this->avatarManager->getAvatar($this->getName());
70
+        if ($avatar === null || !$avatar->exists()) {
71
+            throw new NotFound();
72
+        }
73
+        return new AvatarNode($size, $ext, $avatar);
74
+    }
75
+
76
+    public function getChildren() {
77
+        try {
78
+            return [
79
+                $this->getChild('96.jpeg')
80
+            ];
81
+        } catch(NotFound $exception) {
82
+            return [];
83
+        }
84
+    }
85
+
86
+    public function childExists($name) {
87
+        try {
88
+            $ret = $this->getChild($name);
89
+            return $ret !== null;
90
+        } catch (NotFound $ex) {
91
+            return false;
92
+        } catch (MethodNotAllowed $ex) {
93
+            return false;
94
+        }
95
+    }
96
+
97
+    public function delete() {
98
+        throw new Forbidden('Permission denied to delete this folder');
99
+    }
100
+
101
+    public function getName() {
102
+        list(,$name) = Uri\split($this->principalInfo['uri']);
103
+        return $name;
104
+    }
105
+
106
+    public function setName($name) {
107
+        throw new Forbidden('Permission denied to rename this folder');
108
+    }
109
+
110
+    /**
111
+     * Returns the last modification time, as a unix timestamp
112
+     *
113
+     * @return int|null
114
+     */
115
+    public function getLastModified() {
116
+        return null;
117
+    }
118 118
 
119 119
 
120 120
 }
Please login to merge, or discard this patch.
apps/dav/lib/Avatars/AvatarNode.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
 	public function getLastModified() {
90 90
 		$timestamp = $this->avatar->getFile($this->size)->getMTime();
91 91
 		if (!empty($timestamp)) {
92
-			return (int)$timestamp;
92
+			return (int) $timestamp;
93 93
 		}
94 94
 		return $timestamp;
95 95
 
Please login to merge, or discard this patch.
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -27,72 +27,72 @@
 block discarded – undo
27 27
 use Sabre\DAV\File;
28 28
 
29 29
 class AvatarNode extends File {
30
-	private $ext;
31
-	private $size;
32
-	private $avatar;
30
+    private $ext;
31
+    private $size;
32
+    private $avatar;
33 33
 
34
-	/**
35
-	 * AvatarNode constructor.
36
-	 *
37
-	 * @param integer $size
38
-	 * @param string $ext
39
-	 * @param IAvatar $avatar
40
-	 */
41
-	public function __construct($size, $ext, $avatar) {
42
-		$this->size = $size;
43
-		$this->ext = $ext;
44
-		$this->avatar = $avatar;
45
-	}
34
+    /**
35
+     * AvatarNode constructor.
36
+     *
37
+     * @param integer $size
38
+     * @param string $ext
39
+     * @param IAvatar $avatar
40
+     */
41
+    public function __construct($size, $ext, $avatar) {
42
+        $this->size = $size;
43
+        $this->ext = $ext;
44
+        $this->avatar = $avatar;
45
+    }
46 46
 
47
-	/**
48
-	 * Returns the name of the node.
49
-	 *
50
-	 * This is used to generate the url.
51
-	 *
52
-	 * @return string
53
-	 */
54
-	public function getName() {
55
-		return "$this->size.$this->ext";
56
-	}
47
+    /**
48
+     * Returns the name of the node.
49
+     *
50
+     * This is used to generate the url.
51
+     *
52
+     * @return string
53
+     */
54
+    public function getName() {
55
+        return "$this->size.$this->ext";
56
+    }
57 57
 
58
-	public function get() {
59
-		$image = $this->avatar->get($this->size);
60
-		$res = $image->resource();
58
+    public function get() {
59
+        $image = $this->avatar->get($this->size);
60
+        $res = $image->resource();
61 61
 
62
-		ob_start();
63
-		if ($this->ext === 'png') {
64
-			imagepng($res);
65
-		} else {
66
-			imagejpeg($res);
67
-		}
62
+        ob_start();
63
+        if ($this->ext === 'png') {
64
+            imagepng($res);
65
+        } else {
66
+            imagejpeg($res);
67
+        }
68 68
 
69
-		return ob_get_clean();
70
-	}
69
+        return ob_get_clean();
70
+    }
71 71
 
72
-	/**
73
-	 * Returns the mime-type for a file
74
-	 *
75
-	 * If null is returned, we'll assume application/octet-stream
76
-	 *
77
-	 * @return string|null
78
-	 */
79
-	public function getContentType() {
80
-		if ($this->ext === 'png') {
81
-			return 'image/png';
82
-		}
83
-		return 'image/jpeg';
84
-	}
72
+    /**
73
+     * Returns the mime-type for a file
74
+     *
75
+     * If null is returned, we'll assume application/octet-stream
76
+     *
77
+     * @return string|null
78
+     */
79
+    public function getContentType() {
80
+        if ($this->ext === 'png') {
81
+            return 'image/png';
82
+        }
83
+        return 'image/jpeg';
84
+    }
85 85
 
86
-	public function getETag() {
87
-		return $this->avatar->getFile($this->size)->getEtag();
88
-	}
86
+    public function getETag() {
87
+        return $this->avatar->getFile($this->size)->getEtag();
88
+    }
89 89
 
90
-	public function getLastModified() {
91
-		$timestamp = $this->avatar->getFile($this->size)->getMTime();
92
-		if (!empty($timestamp)) {
93
-			return (int)$timestamp;
94
-		}
95
-		return $timestamp;
90
+    public function getLastModified() {
91
+        $timestamp = $this->avatar->getFile($this->size)->getMTime();
92
+        if (!empty($timestamp)) {
93
+            return (int)$timestamp;
94
+        }
95
+        return $timestamp;
96 96
 
97
-	}
97
+    }
98 98
 }
Please login to merge, or discard this patch.
apps/dav/lib/Avatars/RootCollection.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,23 +7,23 @@
 block discarded – undo
7 7
 
8 8
 class RootCollection extends AbstractPrincipalCollection {
9 9
 
10
-	/**
11
-	 * This method returns a node for a principal.
12
-	 *
13
-	 * The passed array contains principal information, and is guaranteed to
14
-	 * at least contain a uri item. Other properties may or may not be
15
-	 * supplied by the authentication backend.
16
-	 *
17
-	 * @param array $principalInfo
18
-	 * @return AvatarHome
19
-	 */
20
-	public function getChildForPrincipal(array $principalInfo) {
21
-		$avatarManager = \OC::$server->getAvatarManager();
22
-		return new AvatarHome($principalInfo, $avatarManager);
23
-	}
10
+    /**
11
+     * This method returns a node for a principal.
12
+     *
13
+     * The passed array contains principal information, and is guaranteed to
14
+     * at least contain a uri item. Other properties may or may not be
15
+     * supplied by the authentication backend.
16
+     *
17
+     * @param array $principalInfo
18
+     * @return AvatarHome
19
+     */
20
+    public function getChildForPrincipal(array $principalInfo) {
21
+        $avatarManager = \OC::$server->getAvatarManager();
22
+        return new AvatarHome($principalInfo, $avatarManager);
23
+    }
24 24
 
25
-	public function getName() {
26
-		return 'avatars';
27
-	}
25
+    public function getName() {
26
+        return 'avatars';
27
+    }
28 28
 
29 29
 }
Please login to merge, or discard this patch.
apps/dav/lib/Migration/CalDAVRemoveEmptyValue.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -97,6 +97,9 @@
 block discarded – undo
97 97
 		}
98 98
 	}
99 99
 
100
+	/**
101
+	 * @param string $pattern
102
+	 */
100 103
 	protected function getInvalidObjects($pattern) {
101 104
 		$query = $this->db->getQueryBuilder();
102 105
 		$query->select(['calendarid', 'uri'])
Please login to merge, or discard this patch.
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -33,87 +33,87 @@
 block discarded – undo
33 33
 
34 34
 class CalDAVRemoveEmptyValue implements IRepairStep {
35 35
 
36
-	/** @var IDBConnection */
37
-	private $db;
38
-
39
-	/** @var CalDavBackend */
40
-	private $calDavBackend;
41
-
42
-	/** @var ILogger */
43
-	private $logger;
44
-
45
-	/**
46
-	 * @param IDBConnection $db
47
-	 * @param CalDavBackend $calDavBackend
48
-	 * @param ILogger $logger
49
-	 */
50
-	public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) {
51
-		$this->db = $db;
52
-		$this->calDavBackend = $calDavBackend;
53
-		$this->logger = $logger;
54
-	}
55
-
56
-	public function getName() {
57
-		return 'Fix broken values of calendar objects';
58
-	}
59
-
60
-	public function run(IOutput $output) {
61
-		$pattern = ';VALUE=:';
62
-		$count = $warnings = 0;
63
-
64
-		$objects = $this->getInvalidObjects($pattern);
65
-
66
-		$output->startProgress(count($objects));
67
-		foreach ($objects as $row) {
68
-			$calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']);
69
-			$data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']);
70
-
71
-			if ($data !== $calObject['calendardata']) {
72
-				$output->advance();
73
-
74
-				try {
75
-					$this->calDavBackend->getDenormalizedData($data);
76
-				} catch (InvalidDataException $e) {
77
-					$this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [
78
-						'app' => 'dav',
79
-						'cal' => (int)$row['calendarid'],
80
-						'uri' => $row['uri'],
81
-					]);
82
-					$warnings++;
83
-					continue;
84
-				}
85
-
86
-				$this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data);
87
-				$count++;
88
-			}
89
-		}
90
-		$output->finishProgress();
91
-
92
-		if ($warnings > 0) {
93
-			$output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings));
94
-		}
95
-		if ($count > 0) {
96
-			$output->info(sprintf('Updated %d events', $count));
97
-		}
98
-	}
99
-
100
-	protected function getInvalidObjects($pattern) {
101
-		$query = $this->db->getQueryBuilder();
102
-		$query->select(['calendarid', 'uri'])
103
-			->from('calendarobjects')
104
-			->where($query->expr()->like(
105
-				'calendardata',
106
-				$query->createNamedParameter(
107
-					'%' . $this->db->escapeLikeParameter($pattern) . '%',
108
-					IQueryBuilder::PARAM_STR
109
-				),
110
-				IQueryBuilder::PARAM_STR
111
-			));
112
-
113
-		$result = $query->execute();
114
-		$rows = $result->fetchAll();
115
-		$result->closeCursor();
116
-
117
-		return $rows;
118
-	}
36
+    /** @var IDBConnection */
37
+    private $db;
38
+
39
+    /** @var CalDavBackend */
40
+    private $calDavBackend;
41
+
42
+    /** @var ILogger */
43
+    private $logger;
44
+
45
+    /**
46
+     * @param IDBConnection $db
47
+     * @param CalDavBackend $calDavBackend
48
+     * @param ILogger $logger
49
+     */
50
+    public function __construct(IDBConnection $db, CalDavBackend $calDavBackend, ILogger $logger) {
51
+        $this->db = $db;
52
+        $this->calDavBackend = $calDavBackend;
53
+        $this->logger = $logger;
54
+    }
55
+
56
+    public function getName() {
57
+        return 'Fix broken values of calendar objects';
58
+    }
59
+
60
+    public function run(IOutput $output) {
61
+        $pattern = ';VALUE=:';
62
+        $count = $warnings = 0;
63
+
64
+        $objects = $this->getInvalidObjects($pattern);
65
+
66
+        $output->startProgress(count($objects));
67
+        foreach ($objects as $row) {
68
+            $calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']);
69
+            $data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']);
70
+
71
+            if ($data !== $calObject['calendardata']) {
72
+                $output->advance();
73
+
74
+                try {
75
+                    $this->calDavBackend->getDenormalizedData($data);
76
+                } catch (InvalidDataException $e) {
77
+                    $this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [
78
+                        'app' => 'dav',
79
+                        'cal' => (int)$row['calendarid'],
80
+                        'uri' => $row['uri'],
81
+                    ]);
82
+                    $warnings++;
83
+                    continue;
84
+                }
85
+
86
+                $this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data);
87
+                $count++;
88
+            }
89
+        }
90
+        $output->finishProgress();
91
+
92
+        if ($warnings > 0) {
93
+            $output->warning(sprintf('%d events could not be updated, see log file for more information', $warnings));
94
+        }
95
+        if ($count > 0) {
96
+            $output->info(sprintf('Updated %d events', $count));
97
+        }
98
+    }
99
+
100
+    protected function getInvalidObjects($pattern) {
101
+        $query = $this->db->getQueryBuilder();
102
+        $query->select(['calendarid', 'uri'])
103
+            ->from('calendarobjects')
104
+            ->where($query->expr()->like(
105
+                'calendardata',
106
+                $query->createNamedParameter(
107
+                    '%' . $this->db->escapeLikeParameter($pattern) . '%',
108
+                    IQueryBuilder::PARAM_STR
109
+                ),
110
+                IQueryBuilder::PARAM_STR
111
+            ));
112
+
113
+        $result = $query->execute();
114
+        $rows = $result->fetchAll();
115
+        $result->closeCursor();
116
+
117
+        return $rows;
118
+    }
119 119
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -65,8 +65,8 @@  discard block
 block discarded – undo
65 65
 
66 66
 		$output->startProgress(count($objects));
67 67
 		foreach ($objects as $row) {
68
-			$calObject = $this->calDavBackend->getCalendarObject((int)$row['calendarid'], $row['uri']);
69
-			$data = preg_replace('/' . $pattern . '/', ':', $calObject['calendardata']);
68
+			$calObject = $this->calDavBackend->getCalendarObject((int) $row['calendarid'], $row['uri']);
69
+			$data = preg_replace('/'.$pattern.'/', ':', $calObject['calendardata']);
70 70
 
71 71
 			if ($data !== $calObject['calendardata']) {
72 72
 				$output->advance();
@@ -76,14 +76,14 @@  discard block
 block discarded – undo
76 76
 				} catch (InvalidDataException $e) {
77 77
 					$this->logger->info('Calendar object for calendar {cal} with uri {uri} still invalid', [
78 78
 						'app' => 'dav',
79
-						'cal' => (int)$row['calendarid'],
79
+						'cal' => (int) $row['calendarid'],
80 80
 						'uri' => $row['uri'],
81 81
 					]);
82 82
 					$warnings++;
83 83
 					continue;
84 84
 				}
85 85
 
86
-				$this->calDavBackend->updateCalendarObject((int)$row['calendarid'], $row['uri'], $data);
86
+				$this->calDavBackend->updateCalendarObject((int) $row['calendarid'], $row['uri'], $data);
87 87
 				$count++;
88 88
 			}
89 89
 		}
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
 			->where($query->expr()->like(
105 105
 				'calendardata',
106 106
 				$query->createNamedParameter(
107
-					'%' . $this->db->escapeLikeParameter($pattern) . '%',
107
+					'%'.$this->db->escapeLikeParameter($pattern).'%',
108 108
 					IQueryBuilder::PARAM_STR
109 109
 				),
110 110
 				IQueryBuilder::PARAM_STR
Please login to merge, or discard this patch.
core/templates/layout.user.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,9 +4,9 @@
 block discarded – undo
4 4
 		<meta charset="utf-8">
5 5
 		<title>
6 6
 			<?php
7
-				p(!empty($_['application'])?$_['application'].' - ':'');
8
-				p($theme->getTitle());
9
-			?>
7
+                p(!empty($_['application'])?$_['application'].' - ':'');
8
+                p($theme->getTitle());
9
+            ?>
10 10
 		</title>
11 11
 		<meta http-equiv="X-UA-Compatible" content="IE=edge">
12 12
 		<meta name="referrer" content="never">
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
 		<meta charset="utf-8">
5 5
 		<title>
6 6
 			<?php
7
-				p(!empty($_['application'])?$_['application'].' - ':'');
7
+				p(!empty($_['application']) ? $_['application'].' - ' : '');
8 8
 				p($theme->getTitle());
9 9
 			?>
10 10
 		</title>
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 		<meta name="apple-itunes-app" content="app-id=<?php p($theme->getiTunesAppId()); ?>">
15 15
 		<meta name="apple-mobile-web-app-capable" content="yes">
16 16
 		<meta name="apple-mobile-web-app-status-bar-style" content="black">
17
-		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid']!='files')? $_['application']:$theme->getTitle()); ?>">
17
+		<meta name="apple-mobile-web-app-title" content="<?php p((!empty($_['application']) && $_['appid'] != 'files') ? $_['application'] : $theme->getTitle()); ?>">
18 18
 		<meta name="mobile-web-app-capable" content="yes">
19 19
 		<meta name="theme-color" content="<?php p($theme->getColorPrimary()); ?>">
20 20
 		<link rel="icon" href="<?php print_unescaped(image_path($_['appid'], 'favicon.ico')); /* IE11+ supports png */ ?>">
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
 		<?php emit_script_loading_tags($_); ?>
26 26
 		<?php print_unescaped($_['headers']); ?>
27 27
 	</head>
28
-	<body id="<?php p($_['bodyid']);?>">
28
+	<body id="<?php p($_['bodyid']); ?>">
29 29
 	<?php include('layout.noscript.warning.php'); ?>
30 30
 	<div id="notification-container">
31 31
 		<div id="notification"></div>
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 					id="nextcloud">
37 37
 					<div class="logo logo-icon">
38 38
 						<h1 class="hidden-visually">
39
-							<?php p($theme->getName()); ?> <?php p(!empty($_['application'])?$_['application']: $l->t('Apps')); ?>
39
+							<?php p($theme->getName()); ?> <?php p(!empty($_['application']) ? $_['application'] : $l->t('Apps')); ?>
40 40
 						</h1>
41 41
 					</div>
42 42
 				</a>
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 										<?php if ($_['themingInvertMenu']) { ?>
52 52
 										<defs><filter id="invertMenuMain-<?php p($entry['id']); ?>"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" /></filter></defs>
53 53
 										<?php } ?>
54
-										<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"  class="app-icon" />
54
+										<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet"<?php if ($_['themingInvertMenu']) { ?> filter="url(#invertMenuMain-<?php p($entry['id']); ?>)"<?php } ?> xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"  class="app-icon" />
55 55
 									</svg>
56 56
 								<div class="icon-loading-small-dark"
57 57
 									 style="display:none;"></div>
@@ -74,14 +74,14 @@  discard block
 block discarded – undo
74 74
 					<div id="navigation" style="display: none;"  aria-label="<?php p($l->t('More apps menu')); ?>">
75 75
 						<div id="apps">
76 76
 							<ul>
77
-								<?php foreach($_['navigation'] as $entry): ?>
77
+								<?php foreach ($_['navigation'] as $entry): ?>
78 78
 									<li data-id="<?php p($entry['id']); ?>">
79 79
 									<a href="<?php print_unescaped($entry['href']); ?>"
80
-										<?php if( $entry['active'] ): ?> class="active"<?php endif; ?>
80
+										<?php if ($entry['active']): ?> class="active"<?php endif; ?>
81 81
 										aria-label="<?php p($entry['name']); ?>">
82 82
 										<svg width="16" height="16" viewBox="0 0 16 16" alt="">
83 83
 											<defs><filter id="invertMenuMore-<?php p($entry['id']); ?>"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0"></feColorMatrix></filter></defs>
84
-											<image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>"  class="app-icon"></image>
84
+											<image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invertMenuMore-<?php p($entry['id']); ?>)" xlink:href="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>"  class="app-icon"></image>
85 85
 										</svg>
86 86
 										<div class="icon-loading-small-dark" style="display:none;"></div>
87 87
 										<span><?php p($entry['name']); ?></span>
@@ -98,43 +98,43 @@  discard block
 block discarded – undo
98 98
 			<div class="header-right">
99 99
 				<form class="searchbox" action="#" method="post" role="search" novalidate>
100 100
 					<label for="searchbox" class="hidden-visually">
101
-						<?php p($l->t('Search'));?>
101
+						<?php p($l->t('Search')); ?>
102 102
 					</label>
103 103
 					<input id="searchbox" type="search" name="query"
104 104
 						value="" required
105 105
 						autocomplete="off">
106
-					<button class="icon-close-white" type="reset"><span class="hidden-visually"><?php p($l->t('Reset search'));?></span></button>
106
+					<button class="icon-close-white" type="reset"><span class="hidden-visually"><?php p($l->t('Reset search')); ?></span></button>
107 107
 				</form>
108 108
 				<div id="contactsmenu">
109 109
 					<div class="icon-contacts menutoggle" tabindex="0" role="button"
110 110
 					aria-haspopup="true" aria-controls="contactsmenu-menu" aria-expanded="false">
111
-						<span class="hidden-visually"><?php p($l->t('Contacts'));?>
111
+						<span class="hidden-visually"><?php p($l->t('Contacts')); ?>
112 112
 					</div>
113 113
 					<div id="contactsmenu-menu" class="menu"
114
-						aria-label="<?php p($l->t('Contacts menu'));?>"></div>
114
+						aria-label="<?php p($l->t('Contacts menu')); ?>"></div>
115 115
 				</div>
116 116
 				<div id="settings">
117 117
 					<div id="expand" tabindex="0" role="button" class="menutoggle"
118
-						aria-label="<?php p($l->t('Settings'));?>"
118
+						aria-label="<?php p($l->t('Settings')); ?>"
119 119
 						aria-haspopup="true" aria-controls="expanddiv" aria-expanded="false">
120 120
 						<div class="avatardiv<?php if ($_['userAvatarSet']) { print_unescaped(' avatardiv-shown'); } else { print_unescaped('" style="display: none'); } ?>">
121 121
 							<?php if ($_['userAvatarSet']): ?>
122 122
 								<img alt="" width="32" height="32"
123
-								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']]));?>"
124
-								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']]));?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']]));?> 4x"
123
+								src="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 32, 'v' => $_['userAvatarVersion']])); ?>"
124
+								srcset="<?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 64, 'v' => $_['userAvatarVersion']])); ?> 2x, <?php p(\OC::$server->getURLGenerator()->linkToRoute('core.avatar.getAvatar', ['userId' => $_['user_uid'], 'size' => 128, 'v' => $_['userAvatarVersion']])); ?> 4x"
125 125
 								>
126 126
 							<?php endif; ?>
127 127
 						</div>
128 128
 						<div id="expandDisplayName" class="icon-settings-white"></div>
129 129
 					</div>
130 130
 					<nav id="expanddiv" style="display:none;"
131
-						aria-label="<?php p($l->t('Settings menu'));?>">
131
+						aria-label="<?php p($l->t('Settings menu')); ?>">
132 132
 					<ul>
133
-					<?php foreach($_['settingsnavigation'] as $entry):?>
133
+					<?php foreach ($_['settingsnavigation'] as $entry):?>
134 134
 						<li>
135 135
 							<a href="<?php print_unescaped($entry['href']); ?>"
136
-								<?php if( $entry["active"] ): ?> class="active"<?php endif; ?>>
137
-								<img alt="" src="<?php print_unescaped($entry['icon'] . '?v=' . $_['versionHash']); ?>">
136
+								<?php if ($entry["active"]): ?> class="active"<?php endif; ?>>
137
+								<img alt="" src="<?php print_unescaped($entry['icon'].'?v='.$_['versionHash']); ?>">
138 138
 								<?php p($entry['name']) ?>
139 139
 							</a>
140 140
 						</li>
Please login to merge, or discard this patch.