Completed
Pull Request — master (#4617)
by Julius
14:00
created
lib/private/Activity/LegacyFilter.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -26,83 +26,83 @@
 block discarded – undo
26 26
 
27 27
 class LegacyFilter implements IFilter {
28 28
 
29
-	/** @var IManager */
30
-	protected $manager;
31
-	/** @var string */
32
-	protected $identifier;
33
-	/** @var string */
34
-	protected $name;
35
-	/** @var bool */
36
-	protected $isTopFilter;
29
+    /** @var IManager */
30
+    protected $manager;
31
+    /** @var string */
32
+    protected $identifier;
33
+    /** @var string */
34
+    protected $name;
35
+    /** @var bool */
36
+    protected $isTopFilter;
37 37
 
38
-	/**
39
-	 * LegacySetting constructor.
40
-	 *
41
-	 * @param IManager $manager
42
-	 * @param string $identifier
43
-	 * @param string $name
44
-	 * @param bool $isTopFilter
45
-	 */
46
-	public function __construct(IManager $manager,
47
-								$identifier,
48
-								$name,
49
-								$isTopFilter) {
50
-		$this->manager = $manager;
51
-		$this->identifier = $identifier;
52
-		$this->name = $name;
53
-		$this->isTopFilter = $isTopFilter;
54
-	}
38
+    /**
39
+     * LegacySetting constructor.
40
+     *
41
+     * @param IManager $manager
42
+     * @param string $identifier
43
+     * @param string $name
44
+     * @param bool $isTopFilter
45
+     */
46
+    public function __construct(IManager $manager,
47
+                                $identifier,
48
+                                $name,
49
+                                $isTopFilter) {
50
+        $this->manager = $manager;
51
+        $this->identifier = $identifier;
52
+        $this->name = $name;
53
+        $this->isTopFilter = $isTopFilter;
54
+    }
55 55
 
56
-	/**
57
-	 * @return string Lowercase a-z and underscore only identifier
58
-	 * @since 11.0.0
59
-	 */
60
-	public function getIdentifier() {
61
-		return $this->identifier;
62
-	}
56
+    /**
57
+     * @return string Lowercase a-z and underscore only identifier
58
+     * @since 11.0.0
59
+     */
60
+    public function getIdentifier() {
61
+        return $this->identifier;
62
+    }
63 63
 
64
-	/**
65
-	 * @return string A translated string
66
-	 * @since 11.0.0
67
-	 */
68
-	public function getName() {
69
-		return $this->name;
70
-	}
64
+    /**
65
+     * @return string A translated string
66
+     * @since 11.0.0
67
+     */
68
+    public function getName() {
69
+        return $this->name;
70
+    }
71 71
 
72
-	/**
73
-	 * @return int whether the filter should be rather on the top or bottom of
74
-	 * the admin section. The filters are arranged in ascending order of the
75
-	 * priority values. It is required to return a value between 0 and 100.
76
-	 * @since 11.0.0
77
-	 */
78
-	public function getPriority() {
79
-		return $this->isTopFilter ? 40 : 50;
80
-	}
72
+    /**
73
+     * @return int whether the filter should be rather on the top or bottom of
74
+     * the admin section. The filters are arranged in ascending order of the
75
+     * priority values. It is required to return a value between 0 and 100.
76
+     * @since 11.0.0
77
+     */
78
+    public function getPriority() {
79
+        return $this->isTopFilter ? 40 : 50;
80
+    }
81 81
 
82
-	/**
83
-	 * @return string Full URL to an icon, empty string when none is given
84
-	 * @since 11.0.0
85
-	 */
86
-	public function getIcon() {
87
-		// Old API was CSS class, so we can not use this...
88
-		return '';
89
-	}
82
+    /**
83
+     * @return string Full URL to an icon, empty string when none is given
84
+     * @since 11.0.0
85
+     */
86
+    public function getIcon() {
87
+        // Old API was CSS class, so we can not use this...
88
+        return '';
89
+    }
90 90
 
91
-	/**
92
-	 * @param string[] $types
93
-	 * @return string[] An array of allowed apps from which activities should be displayed
94
-	 * @since 11.0.0
95
-	 */
96
-	public function filterTypes(array $types) {
97
-		return $this->manager->filterNotificationTypes($types, $this->getIdentifier());
98
-	}
91
+    /**
92
+     * @param string[] $types
93
+     * @return string[] An array of allowed apps from which activities should be displayed
94
+     * @since 11.0.0
95
+     */
96
+    public function filterTypes(array $types) {
97
+        return $this->manager->filterNotificationTypes($types, $this->getIdentifier());
98
+    }
99 99
 
100
-	/**
101
-	 * @return string[] An array of allowed apps from which activities should be displayed
102
-	 * @since 11.0.0
103
-	 */
104
-	public function allowedApps() {
105
-		return [];
106
-	}
100
+    /**
101
+     * @return string[] An array of allowed apps from which activities should be displayed
102
+     * @since 11.0.0
103
+     */
104
+    public function allowedApps() {
105
+        return [];
106
+    }
107 107
 }
108 108
 
Please login to merge, or discard this patch.
lib/private/Activity/Manager.php 1 patch
Indentation   +667 added lines, -667 removed lines patch added patch discarded remove patch
@@ -39,671 +39,671 @@
 block discarded – undo
39 39
 use OCP\RichObjectStrings\IValidator;
40 40
 
41 41
 class Manager implements IManager {
42
-	/** @var IRequest */
43
-	protected $request;
44
-
45
-	/** @var IUserSession */
46
-	protected $session;
47
-
48
-	/** @var IConfig */
49
-	protected $config;
50
-
51
-	/** @var IValidator */
52
-	protected $validator;
53
-
54
-	/** @var string */
55
-	protected $formattingObjectType;
56
-
57
-	/** @var int */
58
-	protected $formattingObjectId;
59
-
60
-	/** @var string */
61
-	protected $currentUserId;
62
-
63
-	/**
64
-	 * constructor of the controller
65
-	 *
66
-	 * @param IRequest $request
67
-	 * @param IUserSession $session
68
-	 * @param IConfig $config
69
-	 * @param IValidator $validator
70
-	 */
71
-	public function __construct(IRequest $request,
72
-								IUserSession $session,
73
-								IConfig $config,
74
-								IValidator $validator) {
75
-		$this->request = $request;
76
-		$this->session = $session;
77
-		$this->config = $config;
78
-		$this->validator = $validator;
79
-	}
80
-
81
-	/** @var \Closure[] */
82
-	private $consumersClosures = array();
83
-
84
-	/** @var IConsumer[] */
85
-	private $consumers = array();
86
-
87
-	/** @var \Closure[] */
88
-	private $extensionsClosures = array();
89
-
90
-	/** @var IExtension[] */
91
-	private $extensions = array();
92
-
93
-	/** @var array list of filters "name" => "is valid" */
94
-	protected $validFilters = array(
95
-		'all'	=> true,
96
-		'by'	=> true,
97
-		'self'	=> true,
98
-	);
99
-
100
-	/** @var array list of type icons "type" => "css class" */
101
-	protected $typeIcons = array();
102
-
103
-	/** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */
104
-	protected $specialParameters = array();
105
-
106
-	/**
107
-	 * @return \OCP\Activity\IConsumer[]
108
-	 */
109
-	protected function getConsumers() {
110
-		if (!empty($this->consumers)) {
111
-			return $this->consumers;
112
-		}
113
-
114
-		$this->consumers = [];
115
-		foreach($this->consumersClosures as $consumer) {
116
-			$c = $consumer();
117
-			if ($c instanceof IConsumer) {
118
-				$this->consumers[] = $c;
119
-			} else {
120
-				throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface');
121
-			}
122
-		}
123
-
124
-		return $this->consumers;
125
-	}
126
-
127
-	/**
128
-	 * @return \OCP\Activity\IExtension[]
129
-	 */
130
-	protected function getExtensions() {
131
-		if (!empty($this->extensions)) {
132
-			return $this->extensions;
133
-		}
134
-
135
-		$this->extensions = [];
136
-		foreach($this->extensionsClosures as $extension) {
137
-			$e = $extension();
138
-			if ($e instanceof IExtension) {
139
-				$this->extensions[] = $e;
140
-			} else {
141
-				throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface');
142
-			}
143
-		}
144
-
145
-		return $this->extensions;
146
-	}
147
-
148
-	/**
149
-	 * Generates a new IEvent object
150
-	 *
151
-	 * Make sure to call at least the following methods before sending it to the
152
-	 * app with via the publish() method:
153
-	 *  - setApp()
154
-	 *  - setType()
155
-	 *  - setAffectedUser()
156
-	 *  - setSubject()
157
-	 *
158
-	 * @return IEvent
159
-	 */
160
-	public function generateEvent() {
161
-		return new Event($this->validator);
162
-	}
163
-
164
-	/**
165
-	 * Publish an event to the activity consumers
166
-	 *
167
-	 * Make sure to call at least the following methods before sending an Event:
168
-	 *  - setApp()
169
-	 *  - setType()
170
-	 *  - setAffectedUser()
171
-	 *  - setSubject()
172
-	 *
173
-	 * @param IEvent $event
174
-	 * @throws \BadMethodCallException if required values have not been set
175
-	 */
176
-	public function publish(IEvent $event) {
177
-		if ($event->getAuthor() === '') {
178
-			if ($this->session->getUser() instanceof IUser) {
179
-				$event->setAuthor($this->session->getUser()->getUID());
180
-			}
181
-		}
182
-
183
-		if (!$event->getTimestamp()) {
184
-			$event->setTimestamp(time());
185
-		}
186
-
187
-		if (!$event->isValid()) {
188
-			throw new \BadMethodCallException('The given event is invalid');
189
-		}
190
-
191
-		foreach ($this->getConsumers() as $c) {
192
-			$c->receive($event);
193
-		}
194
-	}
195
-
196
-	/**
197
-	 * @param string $app           The app where this event is associated with
198
-	 * @param string $subject       A short description of the event
199
-	 * @param array  $subjectParams Array with parameters that are filled in the subject
200
-	 * @param string $message       A longer description of the event
201
-	 * @param array  $messageParams Array with parameters that are filled in the message
202
-	 * @param string $file          The file including path where this event is associated with
203
-	 * @param string $link          A link where this event is associated with
204
-	 * @param string $affectedUser  Recipient of the activity
205
-	 * @param string $type          Type of the notification
206
-	 * @param int    $priority      Priority of the notification
207
-	 */
208
-	public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) {
209
-		$event = $this->generateEvent();
210
-		$event->setApp($app)
211
-			->setType($type)
212
-			->setAffectedUser($affectedUser)
213
-			->setSubject($subject, $subjectParams)
214
-			->setMessage($message, $messageParams)
215
-			->setObject('', 0, $file)
216
-			->setLink($link);
217
-
218
-		$this->publish($event);
219
-	}
220
-
221
-	/**
222
-	 * In order to improve lazy loading a closure can be registered which will be called in case
223
-	 * activity consumers are actually requested
224
-	 *
225
-	 * $callable has to return an instance of OCA\Activity\IConsumer
226
-	 *
227
-	 * @param \Closure $callable
228
-	 */
229
-	public function registerConsumer(\Closure $callable) {
230
-		array_push($this->consumersClosures, $callable);
231
-		$this->consumers = [];
232
-	}
233
-
234
-	/**
235
-	 * In order to improve lazy loading a closure can be registered which will be called in case
236
-	 * activity consumers are actually requested
237
-	 *
238
-	 * $callable has to return an instance of OCA\Activity\IExtension
239
-	 *
240
-	 * @param \Closure $callable
241
-	 */
242
-	public function registerExtension(\Closure $callable) {
243
-		array_push($this->extensionsClosures, $callable);
244
-		$this->extensions = [];
245
-	}
246
-
247
-	/** @var string[] */
248
-	protected $filterClasses = [];
249
-
250
-	/** @var IFilter[] */
251
-	protected $filters = [];
252
-
253
-	/** @var bool */
254
-	protected $loadedLegacyFilters = false;
255
-
256
-	/**
257
-	 * @param string $filter Class must implement OCA\Activity\IFilter
258
-	 * @return void
259
-	 */
260
-	public function registerFilter($filter) {
261
-		$this->filterClasses[$filter] = false;
262
-	}
263
-
264
-	/**
265
-	 * @return IFilter[]
266
-	 * @throws \InvalidArgumentException
267
-	 */
268
-	public function getFilters() {
269
-		if (!$this->loadedLegacyFilters) {
270
-			$legacyFilters = $this->getNavigation();
271
-
272
-			foreach ($legacyFilters['top'] as $filter => $data) {
273
-				$this->filters[$filter] = new LegacyFilter(
274
-					$this, $filter, $data['name'], true
275
-				);
276
-			}
277
-
278
-			foreach ($legacyFilters['apps'] as $filter => $data) {
279
-				$this->filters[$filter] = new LegacyFilter(
280
-					$this, $filter, $data['name'], false
281
-				);
282
-			}
283
-			$this->loadedLegacyFilters = true;
284
-		}
285
-
286
-		foreach ($this->filterClasses as $class => $false) {
287
-			/** @var IFilter $filter */
288
-			$filter = \OC::$server->query($class);
289
-
290
-			if (!$filter instanceof IFilter) {
291
-				throw new \InvalidArgumentException('Invalid activity filter registered');
292
-			}
293
-
294
-			$this->filters[$filter->getIdentifier()] = $filter;
295
-
296
-			unset($this->filterClasses[$class]);
297
-		}
298
-		return $this->filters;
299
-	}
300
-
301
-	/**
302
-	 * @param string $id
303
-	 * @return IFilter
304
-	 * @throws \InvalidArgumentException when the filter was not found
305
-	 * @since 11.0.0
306
-	 */
307
-	public function getFilterById($id) {
308
-		$filters = $this->getFilters();
309
-
310
-		if (isset($filters[$id])) {
311
-			return $filters[$id];
312
-		}
313
-
314
-		throw new \InvalidArgumentException('Requested filter does not exist');
315
-	}
316
-
317
-	/** @var string[] */
318
-	protected $providerClasses = [];
319
-
320
-	/** @var IProvider[] */
321
-	protected $providers = [];
322
-
323
-	/**
324
-	 * @param string $provider Class must implement OCA\Activity\IProvider
325
-	 * @return void
326
-	 */
327
-	public function registerProvider($provider) {
328
-		$this->providerClasses[$provider] = false;
329
-	}
330
-
331
-	/**
332
-	 * @return IProvider[]
333
-	 * @throws \InvalidArgumentException
334
-	 */
335
-	public function getProviders() {
336
-		foreach ($this->providerClasses as $class => $false) {
337
-			/** @var IProvider $provider */
338
-			$provider = \OC::$server->query($class);
339
-
340
-			if (!$provider instanceof IProvider) {
341
-				throw new \InvalidArgumentException('Invalid activity provider registered');
342
-			}
343
-
344
-			$this->providers[] = $provider;
345
-
346
-			unset($this->providerClasses[$class]);
347
-		}
348
-		return $this->providers;
349
-	}
350
-
351
-	/** @var string[] */
352
-	protected $settingsClasses = [];
353
-
354
-	/** @var ISetting[] */
355
-	protected $settings = [];
356
-
357
-	/** @var bool */
358
-	protected $loadedLegacyTypes = false;
359
-
360
-	/**
361
-	 * @param string $setting Class must implement OCA\Activity\ISetting
362
-	 * @return void
363
-	 */
364
-	public function registerSetting($setting) {
365
-		$this->settingsClasses[$setting] = false;
366
-	}
367
-
368
-	/**
369
-	 * @return ISetting[]
370
-	 * @throws \InvalidArgumentException
371
-	 */
372
-	public function getSettings() {
373
-		if (!$this->loadedLegacyTypes) {
374
-			$l = \OC::$server->getL10N('core');
375
-			$legacyTypes = $this->getNotificationTypes($l->getLanguageCode());
376
-			$streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM);
377
-			$mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL);
378
-			foreach ($legacyTypes as $type => $data) {
379
-				if (is_string($data)) {
380
-					$desc = $data;
381
-					$canChangeStream = true;
382
-					$canChangeMail = true;
383
-				} else {
384
-					$desc = $data['desc'];
385
-					$canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']);
386
-					$canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']);
387
-				}
388
-
389
-				$this->settings[$type] = new LegacySetting(
390
-					$type, $desc,
391
-					$canChangeStream, in_array($type, $streamTypes),
392
-					$canChangeMail, in_array($type, $mailTypes)
393
-				);
394
-			}
395
-			$this->loadedLegacyTypes = true;
396
-		}
397
-
398
-		foreach ($this->settingsClasses as $class => $false) {
399
-			/** @var ISetting $setting */
400
-			$setting = \OC::$server->query($class);
401
-
402
-			if (!$setting instanceof ISetting) {
403
-				throw new \InvalidArgumentException('Invalid activity filter registered');
404
-			}
405
-
406
-			$this->settings[$setting->getIdentifier()] = $setting;
407
-
408
-			unset($this->settingsClasses[$class]);
409
-		}
410
-		return $this->settings;
411
-	}
412
-
413
-	/**
414
-	 * @param string $id
415
-	 * @return ISetting
416
-	 * @throws \InvalidArgumentException when the setting was not found
417
-	 * @since 11.0.0
418
-	 */
419
-	public function getSettingById($id) {
420
-		$settings = $this->getSettings();
421
-
422
-		if (isset($settings[$id])) {
423
-			return $settings[$id];
424
-		}
425
-
426
-		throw new \InvalidArgumentException('Requested setting does not exist');
427
-	}
428
-
429
-	/**
430
-	 * @param string $type
431
-	 * @return string
432
-	 */
433
-	public function getTypeIcon($type) {
434
-		if (isset($this->typeIcons[$type])) {
435
-			return $this->typeIcons[$type];
436
-		}
437
-
438
-		foreach ($this->getExtensions() as $c) {
439
-			$icon = $c->getTypeIcon($type);
440
-			if (is_string($icon)) {
441
-				$this->typeIcons[$type] = $icon;
442
-				return $icon;
443
-			}
444
-		}
445
-
446
-		$this->typeIcons[$type] = '';
447
-		return '';
448
-	}
449
-
450
-	/**
451
-	 * @param string $type
452
-	 * @param string $id
453
-	 */
454
-	public function setFormattingObject($type, $id) {
455
-		$this->formattingObjectType = $type;
456
-		$this->formattingObjectId = (string) $id;
457
-	}
458
-
459
-	/**
460
-	 * @return bool
461
-	 */
462
-	public function isFormattingFilteredObject() {
463
-		return $this->formattingObjectType !== null && $this->formattingObjectId !== null
464
-			&& $this->formattingObjectType === $this->request->getParam('object_type')
465
-			&& $this->formattingObjectId === $this->request->getParam('object_id');
466
-	}
467
-
468
-	/**
469
-	 * @param string $app
470
-	 * @param string $text
471
-	 * @param array $params
472
-	 * @param boolean $stripPath
473
-	 * @param boolean $highlightParams
474
-	 * @param string $languageCode
475
-	 * @return string|false
476
-	 */
477
-	public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
478
-		foreach ($this->getExtensions() as $c) {
479
-			$translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
480
-			if (is_string($translation)) {
481
-				return $translation;
482
-			}
483
-		}
484
-
485
-		return false;
486
-	}
487
-
488
-	/**
489
-	 * @param string $app
490
-	 * @param string $text
491
-	 * @return array|false
492
-	 */
493
-	public function getSpecialParameterList($app, $text) {
494
-		if (isset($this->specialParameters[$app][$text])) {
495
-			return $this->specialParameters[$app][$text];
496
-		}
497
-
498
-		if (!isset($this->specialParameters[$app])) {
499
-			$this->specialParameters[$app] = array();
500
-		}
501
-
502
-		foreach ($this->getExtensions() as $c) {
503
-			$specialParameter = $c->getSpecialParameterList($app, $text);
504
-			if (is_array($specialParameter)) {
505
-				$this->specialParameters[$app][$text] = $specialParameter;
506
-				return $specialParameter;
507
-			}
508
-		}
509
-
510
-		$this->specialParameters[$app][$text] = false;
511
-		return false;
512
-	}
513
-
514
-	/**
515
-	 * @param array $activity
516
-	 * @return integer|false
517
-	 */
518
-	public function getGroupParameter($activity) {
519
-		foreach ($this->getExtensions() as $c) {
520
-			$parameter = $c->getGroupParameter($activity);
521
-			if ($parameter !== false) {
522
-				return $parameter;
523
-			}
524
-		}
525
-
526
-		return false;
527
-	}
528
-
529
-	/**
530
-	 * Set the user we need to use
531
-	 *
532
-	 * @param string|null $currentUserId
533
-	 * @throws \UnexpectedValueException If the user is invalid
534
-	 */
535
-	public function setCurrentUserId($currentUserId) {
536
-		if (!is_string($currentUserId) && $currentUserId !== null) {
537
-			throw new \UnexpectedValueException('The given current user is invalid');
538
-		}
539
-		$this->currentUserId = $currentUserId;
540
-	}
541
-
542
-	/**
543
-	 * Get the user we need to use
544
-	 *
545
-	 * Either the user is logged in, or we try to get it from the token
546
-	 *
547
-	 * @return string
548
-	 * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
549
-	 */
550
-	public function getCurrentUserId() {
551
-		if ($this->currentUserId !== null) {
552
-			return $this->currentUserId;
553
-		} else if (!$this->session->isLoggedIn()) {
554
-			return $this->getUserFromToken();
555
-		} else {
556
-			return $this->session->getUser()->getUID();
557
-		}
558
-	}
559
-
560
-	/**
561
-	 * Get the user for the token
562
-	 *
563
-	 * @return string
564
-	 * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
565
-	 */
566
-	protected function getUserFromToken() {
567
-		$token = (string) $this->request->getParam('token', '');
568
-		if (strlen($token) !== 30) {
569
-			throw new \UnexpectedValueException('The token is invalid');
570
-		}
571
-
572
-		$users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
573
-
574
-		if (sizeof($users) !== 1) {
575
-			// No unique user found
576
-			throw new \UnexpectedValueException('The token is invalid');
577
-		}
578
-
579
-		// Token found login as that user
580
-		return array_shift($users);
581
-	}
582
-
583
-	/**
584
-	 * @return array
585
-	 * @deprecated 11.0.0 - Use getFilters() instead
586
-	 */
587
-	public function getNavigation() {
588
-		$entries = array(
589
-			'apps' => array(),
590
-			'top' => array(),
591
-		);
592
-		foreach ($this->getExtensions() as $c) {
593
-			$additionalEntries = $c->getNavigation();
594
-			if (is_array($additionalEntries)) {
595
-				$entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']);
596
-				$entries['top'] = array_merge($entries['top'], $additionalEntries['top']);
597
-			}
598
-		}
599
-
600
-		return $entries;
601
-	}
602
-
603
-	/**
604
-	 * @param string $filterValue
605
-	 * @return boolean
606
-	 * @deprecated 11.0.0 - Use getFilterById() instead
607
-	 */
608
-	public function isFilterValid($filterValue) {
609
-		if (isset($this->validFilters[$filterValue])) {
610
-			return $this->validFilters[$filterValue];
611
-		}
612
-
613
-		foreach ($this->getExtensions() as $c) {
614
-			if ($c->isFilterValid($filterValue) === true) {
615
-				$this->validFilters[$filterValue] = true;
616
-				return true;
617
-			}
618
-		}
619
-
620
-		$this->validFilters[$filterValue] = false;
621
-		return false;
622
-	}
623
-
624
-	/**
625
-	 * @param array $types
626
-	 * @param string $filter
627
-	 * @return array
628
-	 * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead
629
-	 */
630
-	public function filterNotificationTypes($types, $filter) {
631
-		if (!$this->isFilterValid($filter)) {
632
-			return $types;
633
-		}
634
-
635
-		foreach ($this->getExtensions() as $c) {
636
-			$result = $c->filterNotificationTypes($types, $filter);
637
-			if (is_array($result)) {
638
-				$types = $result;
639
-			}
640
-		}
641
-		return $types;
642
-	}
643
-
644
-	/**
645
-	 * @param string $filter
646
-	 * @return array
647
-	 * @deprecated 11.0.0 - Use getFilterById() instead
648
-	 */
649
-	public function getQueryForFilter($filter) {
650
-		if (!$this->isFilterValid($filter)) {
651
-			return [null, null];
652
-		}
653
-
654
-		$conditions = array();
655
-		$parameters = array();
656
-
657
-		foreach ($this->getExtensions() as $c) {
658
-			$result = $c->getQueryForFilter($filter);
659
-			if (is_array($result)) {
660
-				list($condition, $parameter) = $result;
661
-				if ($condition && is_array($parameter)) {
662
-					$conditions[] = $condition;
663
-					$parameters = array_merge($parameters, $parameter);
664
-				}
665
-			}
666
-		}
667
-
668
-		if (empty($conditions)) {
669
-			return array(null, null);
670
-		}
671
-
672
-		return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
673
-	}
674
-
675
-	/**
676
-	 * Will return additional notification types as specified by other apps
677
-	 *
678
-	 * @param string $languageCode
679
-	 * @return array
680
-	 * @deprecated 11.0.0 - Use getSettings() instead
681
-	 */
682
-	public function getNotificationTypes($languageCode) {
683
-		$notificationTypes = $sharingNotificationTypes = [];
684
-		foreach ($this->getExtensions() as $c) {
685
-			$result = $c->getNotificationTypes($languageCode);
686
-			if (is_array($result)) {
687
-				$notificationTypes = array_merge($notificationTypes, $result);
688
-			}
689
-		}
690
-
691
-		return array_merge($sharingNotificationTypes, $notificationTypes);
692
-	}
693
-
694
-	/**
695
-	 * @param string $method
696
-	 * @return array
697
-	 * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead
698
-	 */
699
-	public function getDefaultTypes($method) {
700
-		$defaultTypes = array();
701
-		foreach ($this->getExtensions() as $c) {
702
-			$types = $c->getDefaultTypes($method);
703
-			if (is_array($types)) {
704
-				$defaultTypes = array_merge($types, $defaultTypes);
705
-			}
706
-		}
707
-		return $defaultTypes;
708
-	}
42
+    /** @var IRequest */
43
+    protected $request;
44
+
45
+    /** @var IUserSession */
46
+    protected $session;
47
+
48
+    /** @var IConfig */
49
+    protected $config;
50
+
51
+    /** @var IValidator */
52
+    protected $validator;
53
+
54
+    /** @var string */
55
+    protected $formattingObjectType;
56
+
57
+    /** @var int */
58
+    protected $formattingObjectId;
59
+
60
+    /** @var string */
61
+    protected $currentUserId;
62
+
63
+    /**
64
+     * constructor of the controller
65
+     *
66
+     * @param IRequest $request
67
+     * @param IUserSession $session
68
+     * @param IConfig $config
69
+     * @param IValidator $validator
70
+     */
71
+    public function __construct(IRequest $request,
72
+                                IUserSession $session,
73
+                                IConfig $config,
74
+                                IValidator $validator) {
75
+        $this->request = $request;
76
+        $this->session = $session;
77
+        $this->config = $config;
78
+        $this->validator = $validator;
79
+    }
80
+
81
+    /** @var \Closure[] */
82
+    private $consumersClosures = array();
83
+
84
+    /** @var IConsumer[] */
85
+    private $consumers = array();
86
+
87
+    /** @var \Closure[] */
88
+    private $extensionsClosures = array();
89
+
90
+    /** @var IExtension[] */
91
+    private $extensions = array();
92
+
93
+    /** @var array list of filters "name" => "is valid" */
94
+    protected $validFilters = array(
95
+        'all'	=> true,
96
+        'by'	=> true,
97
+        'self'	=> true,
98
+    );
99
+
100
+    /** @var array list of type icons "type" => "css class" */
101
+    protected $typeIcons = array();
102
+
103
+    /** @var array list of special parameters "app" => ["text" => ["parameter" => "type"]] */
104
+    protected $specialParameters = array();
105
+
106
+    /**
107
+     * @return \OCP\Activity\IConsumer[]
108
+     */
109
+    protected function getConsumers() {
110
+        if (!empty($this->consumers)) {
111
+            return $this->consumers;
112
+        }
113
+
114
+        $this->consumers = [];
115
+        foreach($this->consumersClosures as $consumer) {
116
+            $c = $consumer();
117
+            if ($c instanceof IConsumer) {
118
+                $this->consumers[] = $c;
119
+            } else {
120
+                throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface');
121
+            }
122
+        }
123
+
124
+        return $this->consumers;
125
+    }
126
+
127
+    /**
128
+     * @return \OCP\Activity\IExtension[]
129
+     */
130
+    protected function getExtensions() {
131
+        if (!empty($this->extensions)) {
132
+            return $this->extensions;
133
+        }
134
+
135
+        $this->extensions = [];
136
+        foreach($this->extensionsClosures as $extension) {
137
+            $e = $extension();
138
+            if ($e instanceof IExtension) {
139
+                $this->extensions[] = $e;
140
+            } else {
141
+                throw new \InvalidArgumentException('The given extension does not implement the \OCP\Activity\IExtension interface');
142
+            }
143
+        }
144
+
145
+        return $this->extensions;
146
+    }
147
+
148
+    /**
149
+     * Generates a new IEvent object
150
+     *
151
+     * Make sure to call at least the following methods before sending it to the
152
+     * app with via the publish() method:
153
+     *  - setApp()
154
+     *  - setType()
155
+     *  - setAffectedUser()
156
+     *  - setSubject()
157
+     *
158
+     * @return IEvent
159
+     */
160
+    public function generateEvent() {
161
+        return new Event($this->validator);
162
+    }
163
+
164
+    /**
165
+     * Publish an event to the activity consumers
166
+     *
167
+     * Make sure to call at least the following methods before sending an Event:
168
+     *  - setApp()
169
+     *  - setType()
170
+     *  - setAffectedUser()
171
+     *  - setSubject()
172
+     *
173
+     * @param IEvent $event
174
+     * @throws \BadMethodCallException if required values have not been set
175
+     */
176
+    public function publish(IEvent $event) {
177
+        if ($event->getAuthor() === '') {
178
+            if ($this->session->getUser() instanceof IUser) {
179
+                $event->setAuthor($this->session->getUser()->getUID());
180
+            }
181
+        }
182
+
183
+        if (!$event->getTimestamp()) {
184
+            $event->setTimestamp(time());
185
+        }
186
+
187
+        if (!$event->isValid()) {
188
+            throw new \BadMethodCallException('The given event is invalid');
189
+        }
190
+
191
+        foreach ($this->getConsumers() as $c) {
192
+            $c->receive($event);
193
+        }
194
+    }
195
+
196
+    /**
197
+     * @param string $app           The app where this event is associated with
198
+     * @param string $subject       A short description of the event
199
+     * @param array  $subjectParams Array with parameters that are filled in the subject
200
+     * @param string $message       A longer description of the event
201
+     * @param array  $messageParams Array with parameters that are filled in the message
202
+     * @param string $file          The file including path where this event is associated with
203
+     * @param string $link          A link where this event is associated with
204
+     * @param string $affectedUser  Recipient of the activity
205
+     * @param string $type          Type of the notification
206
+     * @param int    $priority      Priority of the notification
207
+     */
208
+    public function publishActivity($app, $subject, $subjectParams, $message, $messageParams, $file, $link, $affectedUser, $type, $priority) {
209
+        $event = $this->generateEvent();
210
+        $event->setApp($app)
211
+            ->setType($type)
212
+            ->setAffectedUser($affectedUser)
213
+            ->setSubject($subject, $subjectParams)
214
+            ->setMessage($message, $messageParams)
215
+            ->setObject('', 0, $file)
216
+            ->setLink($link);
217
+
218
+        $this->publish($event);
219
+    }
220
+
221
+    /**
222
+     * In order to improve lazy loading a closure can be registered which will be called in case
223
+     * activity consumers are actually requested
224
+     *
225
+     * $callable has to return an instance of OCA\Activity\IConsumer
226
+     *
227
+     * @param \Closure $callable
228
+     */
229
+    public function registerConsumer(\Closure $callable) {
230
+        array_push($this->consumersClosures, $callable);
231
+        $this->consumers = [];
232
+    }
233
+
234
+    /**
235
+     * In order to improve lazy loading a closure can be registered which will be called in case
236
+     * activity consumers are actually requested
237
+     *
238
+     * $callable has to return an instance of OCA\Activity\IExtension
239
+     *
240
+     * @param \Closure $callable
241
+     */
242
+    public function registerExtension(\Closure $callable) {
243
+        array_push($this->extensionsClosures, $callable);
244
+        $this->extensions = [];
245
+    }
246
+
247
+    /** @var string[] */
248
+    protected $filterClasses = [];
249
+
250
+    /** @var IFilter[] */
251
+    protected $filters = [];
252
+
253
+    /** @var bool */
254
+    protected $loadedLegacyFilters = false;
255
+
256
+    /**
257
+     * @param string $filter Class must implement OCA\Activity\IFilter
258
+     * @return void
259
+     */
260
+    public function registerFilter($filter) {
261
+        $this->filterClasses[$filter] = false;
262
+    }
263
+
264
+    /**
265
+     * @return IFilter[]
266
+     * @throws \InvalidArgumentException
267
+     */
268
+    public function getFilters() {
269
+        if (!$this->loadedLegacyFilters) {
270
+            $legacyFilters = $this->getNavigation();
271
+
272
+            foreach ($legacyFilters['top'] as $filter => $data) {
273
+                $this->filters[$filter] = new LegacyFilter(
274
+                    $this, $filter, $data['name'], true
275
+                );
276
+            }
277
+
278
+            foreach ($legacyFilters['apps'] as $filter => $data) {
279
+                $this->filters[$filter] = new LegacyFilter(
280
+                    $this, $filter, $data['name'], false
281
+                );
282
+            }
283
+            $this->loadedLegacyFilters = true;
284
+        }
285
+
286
+        foreach ($this->filterClasses as $class => $false) {
287
+            /** @var IFilter $filter */
288
+            $filter = \OC::$server->query($class);
289
+
290
+            if (!$filter instanceof IFilter) {
291
+                throw new \InvalidArgumentException('Invalid activity filter registered');
292
+            }
293
+
294
+            $this->filters[$filter->getIdentifier()] = $filter;
295
+
296
+            unset($this->filterClasses[$class]);
297
+        }
298
+        return $this->filters;
299
+    }
300
+
301
+    /**
302
+     * @param string $id
303
+     * @return IFilter
304
+     * @throws \InvalidArgumentException when the filter was not found
305
+     * @since 11.0.0
306
+     */
307
+    public function getFilterById($id) {
308
+        $filters = $this->getFilters();
309
+
310
+        if (isset($filters[$id])) {
311
+            return $filters[$id];
312
+        }
313
+
314
+        throw new \InvalidArgumentException('Requested filter does not exist');
315
+    }
316
+
317
+    /** @var string[] */
318
+    protected $providerClasses = [];
319
+
320
+    /** @var IProvider[] */
321
+    protected $providers = [];
322
+
323
+    /**
324
+     * @param string $provider Class must implement OCA\Activity\IProvider
325
+     * @return void
326
+     */
327
+    public function registerProvider($provider) {
328
+        $this->providerClasses[$provider] = false;
329
+    }
330
+
331
+    /**
332
+     * @return IProvider[]
333
+     * @throws \InvalidArgumentException
334
+     */
335
+    public function getProviders() {
336
+        foreach ($this->providerClasses as $class => $false) {
337
+            /** @var IProvider $provider */
338
+            $provider = \OC::$server->query($class);
339
+
340
+            if (!$provider instanceof IProvider) {
341
+                throw new \InvalidArgumentException('Invalid activity provider registered');
342
+            }
343
+
344
+            $this->providers[] = $provider;
345
+
346
+            unset($this->providerClasses[$class]);
347
+        }
348
+        return $this->providers;
349
+    }
350
+
351
+    /** @var string[] */
352
+    protected $settingsClasses = [];
353
+
354
+    /** @var ISetting[] */
355
+    protected $settings = [];
356
+
357
+    /** @var bool */
358
+    protected $loadedLegacyTypes = false;
359
+
360
+    /**
361
+     * @param string $setting Class must implement OCA\Activity\ISetting
362
+     * @return void
363
+     */
364
+    public function registerSetting($setting) {
365
+        $this->settingsClasses[$setting] = false;
366
+    }
367
+
368
+    /**
369
+     * @return ISetting[]
370
+     * @throws \InvalidArgumentException
371
+     */
372
+    public function getSettings() {
373
+        if (!$this->loadedLegacyTypes) {
374
+            $l = \OC::$server->getL10N('core');
375
+            $legacyTypes = $this->getNotificationTypes($l->getLanguageCode());
376
+            $streamTypes = $this->getDefaultTypes(IExtension::METHOD_STREAM);
377
+            $mailTypes = $this->getDefaultTypes(IExtension::METHOD_MAIL);
378
+            foreach ($legacyTypes as $type => $data) {
379
+                if (is_string($data)) {
380
+                    $desc = $data;
381
+                    $canChangeStream = true;
382
+                    $canChangeMail = true;
383
+                } else {
384
+                    $desc = $data['desc'];
385
+                    $canChangeStream = in_array(IExtension::METHOD_STREAM, $data['methods']);
386
+                    $canChangeMail = in_array(IExtension::METHOD_MAIL, $data['methods']);
387
+                }
388
+
389
+                $this->settings[$type] = new LegacySetting(
390
+                    $type, $desc,
391
+                    $canChangeStream, in_array($type, $streamTypes),
392
+                    $canChangeMail, in_array($type, $mailTypes)
393
+                );
394
+            }
395
+            $this->loadedLegacyTypes = true;
396
+        }
397
+
398
+        foreach ($this->settingsClasses as $class => $false) {
399
+            /** @var ISetting $setting */
400
+            $setting = \OC::$server->query($class);
401
+
402
+            if (!$setting instanceof ISetting) {
403
+                throw new \InvalidArgumentException('Invalid activity filter registered');
404
+            }
405
+
406
+            $this->settings[$setting->getIdentifier()] = $setting;
407
+
408
+            unset($this->settingsClasses[$class]);
409
+        }
410
+        return $this->settings;
411
+    }
412
+
413
+    /**
414
+     * @param string $id
415
+     * @return ISetting
416
+     * @throws \InvalidArgumentException when the setting was not found
417
+     * @since 11.0.0
418
+     */
419
+    public function getSettingById($id) {
420
+        $settings = $this->getSettings();
421
+
422
+        if (isset($settings[$id])) {
423
+            return $settings[$id];
424
+        }
425
+
426
+        throw new \InvalidArgumentException('Requested setting does not exist');
427
+    }
428
+
429
+    /**
430
+     * @param string $type
431
+     * @return string
432
+     */
433
+    public function getTypeIcon($type) {
434
+        if (isset($this->typeIcons[$type])) {
435
+            return $this->typeIcons[$type];
436
+        }
437
+
438
+        foreach ($this->getExtensions() as $c) {
439
+            $icon = $c->getTypeIcon($type);
440
+            if (is_string($icon)) {
441
+                $this->typeIcons[$type] = $icon;
442
+                return $icon;
443
+            }
444
+        }
445
+
446
+        $this->typeIcons[$type] = '';
447
+        return '';
448
+    }
449
+
450
+    /**
451
+     * @param string $type
452
+     * @param string $id
453
+     */
454
+    public function setFormattingObject($type, $id) {
455
+        $this->formattingObjectType = $type;
456
+        $this->formattingObjectId = (string) $id;
457
+    }
458
+
459
+    /**
460
+     * @return bool
461
+     */
462
+    public function isFormattingFilteredObject() {
463
+        return $this->formattingObjectType !== null && $this->formattingObjectId !== null
464
+            && $this->formattingObjectType === $this->request->getParam('object_type')
465
+            && $this->formattingObjectId === $this->request->getParam('object_id');
466
+    }
467
+
468
+    /**
469
+     * @param string $app
470
+     * @param string $text
471
+     * @param array $params
472
+     * @param boolean $stripPath
473
+     * @param boolean $highlightParams
474
+     * @param string $languageCode
475
+     * @return string|false
476
+     */
477
+    public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode) {
478
+        foreach ($this->getExtensions() as $c) {
479
+            $translation = $c->translate($app, $text, $params, $stripPath, $highlightParams, $languageCode);
480
+            if (is_string($translation)) {
481
+                return $translation;
482
+            }
483
+        }
484
+
485
+        return false;
486
+    }
487
+
488
+    /**
489
+     * @param string $app
490
+     * @param string $text
491
+     * @return array|false
492
+     */
493
+    public function getSpecialParameterList($app, $text) {
494
+        if (isset($this->specialParameters[$app][$text])) {
495
+            return $this->specialParameters[$app][$text];
496
+        }
497
+
498
+        if (!isset($this->specialParameters[$app])) {
499
+            $this->specialParameters[$app] = array();
500
+        }
501
+
502
+        foreach ($this->getExtensions() as $c) {
503
+            $specialParameter = $c->getSpecialParameterList($app, $text);
504
+            if (is_array($specialParameter)) {
505
+                $this->specialParameters[$app][$text] = $specialParameter;
506
+                return $specialParameter;
507
+            }
508
+        }
509
+
510
+        $this->specialParameters[$app][$text] = false;
511
+        return false;
512
+    }
513
+
514
+    /**
515
+     * @param array $activity
516
+     * @return integer|false
517
+     */
518
+    public function getGroupParameter($activity) {
519
+        foreach ($this->getExtensions() as $c) {
520
+            $parameter = $c->getGroupParameter($activity);
521
+            if ($parameter !== false) {
522
+                return $parameter;
523
+            }
524
+        }
525
+
526
+        return false;
527
+    }
528
+
529
+    /**
530
+     * Set the user we need to use
531
+     *
532
+     * @param string|null $currentUserId
533
+     * @throws \UnexpectedValueException If the user is invalid
534
+     */
535
+    public function setCurrentUserId($currentUserId) {
536
+        if (!is_string($currentUserId) && $currentUserId !== null) {
537
+            throw new \UnexpectedValueException('The given current user is invalid');
538
+        }
539
+        $this->currentUserId = $currentUserId;
540
+    }
541
+
542
+    /**
543
+     * Get the user we need to use
544
+     *
545
+     * Either the user is logged in, or we try to get it from the token
546
+     *
547
+     * @return string
548
+     * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
549
+     */
550
+    public function getCurrentUserId() {
551
+        if ($this->currentUserId !== null) {
552
+            return $this->currentUserId;
553
+        } else if (!$this->session->isLoggedIn()) {
554
+            return $this->getUserFromToken();
555
+        } else {
556
+            return $this->session->getUser()->getUID();
557
+        }
558
+    }
559
+
560
+    /**
561
+     * Get the user for the token
562
+     *
563
+     * @return string
564
+     * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
565
+     */
566
+    protected function getUserFromToken() {
567
+        $token = (string) $this->request->getParam('token', '');
568
+        if (strlen($token) !== 30) {
569
+            throw new \UnexpectedValueException('The token is invalid');
570
+        }
571
+
572
+        $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
573
+
574
+        if (sizeof($users) !== 1) {
575
+            // No unique user found
576
+            throw new \UnexpectedValueException('The token is invalid');
577
+        }
578
+
579
+        // Token found login as that user
580
+        return array_shift($users);
581
+    }
582
+
583
+    /**
584
+     * @return array
585
+     * @deprecated 11.0.0 - Use getFilters() instead
586
+     */
587
+    public function getNavigation() {
588
+        $entries = array(
589
+            'apps' => array(),
590
+            'top' => array(),
591
+        );
592
+        foreach ($this->getExtensions() as $c) {
593
+            $additionalEntries = $c->getNavigation();
594
+            if (is_array($additionalEntries)) {
595
+                $entries['apps'] = array_merge($entries['apps'], $additionalEntries['apps']);
596
+                $entries['top'] = array_merge($entries['top'], $additionalEntries['top']);
597
+            }
598
+        }
599
+
600
+        return $entries;
601
+    }
602
+
603
+    /**
604
+     * @param string $filterValue
605
+     * @return boolean
606
+     * @deprecated 11.0.0 - Use getFilterById() instead
607
+     */
608
+    public function isFilterValid($filterValue) {
609
+        if (isset($this->validFilters[$filterValue])) {
610
+            return $this->validFilters[$filterValue];
611
+        }
612
+
613
+        foreach ($this->getExtensions() as $c) {
614
+            if ($c->isFilterValid($filterValue) === true) {
615
+                $this->validFilters[$filterValue] = true;
616
+                return true;
617
+            }
618
+        }
619
+
620
+        $this->validFilters[$filterValue] = false;
621
+        return false;
622
+    }
623
+
624
+    /**
625
+     * @param array $types
626
+     * @param string $filter
627
+     * @return array
628
+     * @deprecated 11.0.0 - Use getFilterById()->filterTypes() instead
629
+     */
630
+    public function filterNotificationTypes($types, $filter) {
631
+        if (!$this->isFilterValid($filter)) {
632
+            return $types;
633
+        }
634
+
635
+        foreach ($this->getExtensions() as $c) {
636
+            $result = $c->filterNotificationTypes($types, $filter);
637
+            if (is_array($result)) {
638
+                $types = $result;
639
+            }
640
+        }
641
+        return $types;
642
+    }
643
+
644
+    /**
645
+     * @param string $filter
646
+     * @return array
647
+     * @deprecated 11.0.0 - Use getFilterById() instead
648
+     */
649
+    public function getQueryForFilter($filter) {
650
+        if (!$this->isFilterValid($filter)) {
651
+            return [null, null];
652
+        }
653
+
654
+        $conditions = array();
655
+        $parameters = array();
656
+
657
+        foreach ($this->getExtensions() as $c) {
658
+            $result = $c->getQueryForFilter($filter);
659
+            if (is_array($result)) {
660
+                list($condition, $parameter) = $result;
661
+                if ($condition && is_array($parameter)) {
662
+                    $conditions[] = $condition;
663
+                    $parameters = array_merge($parameters, $parameter);
664
+                }
665
+            }
666
+        }
667
+
668
+        if (empty($conditions)) {
669
+            return array(null, null);
670
+        }
671
+
672
+        return array(' and ((' . implode(') or (', $conditions) . '))', $parameters);
673
+    }
674
+
675
+    /**
676
+     * Will return additional notification types as specified by other apps
677
+     *
678
+     * @param string $languageCode
679
+     * @return array
680
+     * @deprecated 11.0.0 - Use getSettings() instead
681
+     */
682
+    public function getNotificationTypes($languageCode) {
683
+        $notificationTypes = $sharingNotificationTypes = [];
684
+        foreach ($this->getExtensions() as $c) {
685
+            $result = $c->getNotificationTypes($languageCode);
686
+            if (is_array($result)) {
687
+                $notificationTypes = array_merge($notificationTypes, $result);
688
+            }
689
+        }
690
+
691
+        return array_merge($sharingNotificationTypes, $notificationTypes);
692
+    }
693
+
694
+    /**
695
+     * @param string $method
696
+     * @return array
697
+     * @deprecated 11.0.0 - Use getSettings()->isDefaulEnabled<method>() instead
698
+     */
699
+    public function getDefaultTypes($method) {
700
+        $defaultTypes = array();
701
+        foreach ($this->getExtensions() as $c) {
702
+            $types = $c->getDefaultTypes($method);
703
+            if (is_array($types)) {
704
+                $defaultTypes = array_merge($types, $defaultTypes);
705
+            }
706
+        }
707
+        return $defaultTypes;
708
+    }
709 709
 }
Please login to merge, or discard this patch.
lib/private/Activity/LegacySetting.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -25,99 +25,99 @@
 block discarded – undo
25 25
 
26 26
 class LegacySetting implements ISetting {
27 27
 
28
-	/** @var string */
29
-	protected $identifier;
30
-	/** @var string */
31
-	protected $name;
32
-	/** @var bool */
33
-	protected $canChangeStream;
34
-	/** @var bool */
35
-	protected $isDefaultEnabledStream;
36
-	/** @var bool */
37
-	protected $canChangeMail;
38
-	/** @var bool */
39
-	protected $isDefaultEnabledMail;
28
+    /** @var string */
29
+    protected $identifier;
30
+    /** @var string */
31
+    protected $name;
32
+    /** @var bool */
33
+    protected $canChangeStream;
34
+    /** @var bool */
35
+    protected $isDefaultEnabledStream;
36
+    /** @var bool */
37
+    protected $canChangeMail;
38
+    /** @var bool */
39
+    protected $isDefaultEnabledMail;
40 40
 
41
-	/**
42
-	 * LegacySetting constructor.
43
-	 *
44
-	 * @param string $identifier
45
-	 * @param string $name
46
-	 * @param bool $canChangeStream
47
-	 * @param bool $isDefaultEnabledStream
48
-	 * @param bool $canChangeMail
49
-	 * @param bool $isDefaultEnabledMail
50
-	 */
51
-	public function __construct($identifier,
52
-								$name,
53
-								$canChangeStream,
54
-								$isDefaultEnabledStream,
55
-								$canChangeMail,
56
-								$isDefaultEnabledMail) {
57
-		$this->identifier = $identifier;
58
-		$this->name = $name;
59
-		$this->canChangeStream = $canChangeStream;
60
-		$this->isDefaultEnabledStream = $isDefaultEnabledStream;
61
-		$this->canChangeMail = $canChangeMail;
62
-		$this->isDefaultEnabledMail = $isDefaultEnabledMail;
63
-	}
41
+    /**
42
+     * LegacySetting constructor.
43
+     *
44
+     * @param string $identifier
45
+     * @param string $name
46
+     * @param bool $canChangeStream
47
+     * @param bool $isDefaultEnabledStream
48
+     * @param bool $canChangeMail
49
+     * @param bool $isDefaultEnabledMail
50
+     */
51
+    public function __construct($identifier,
52
+                                $name,
53
+                                $canChangeStream,
54
+                                $isDefaultEnabledStream,
55
+                                $canChangeMail,
56
+                                $isDefaultEnabledMail) {
57
+        $this->identifier = $identifier;
58
+        $this->name = $name;
59
+        $this->canChangeStream = $canChangeStream;
60
+        $this->isDefaultEnabledStream = $isDefaultEnabledStream;
61
+        $this->canChangeMail = $canChangeMail;
62
+        $this->isDefaultEnabledMail = $isDefaultEnabledMail;
63
+    }
64 64
 
65
-	/**
66
-	 * @return string Lowercase a-z and underscore only identifier
67
-	 * @since 11.0.0
68
-	 */
69
-	public function getIdentifier() {
70
-		return $this->identifier;
71
-	}
65
+    /**
66
+     * @return string Lowercase a-z and underscore only identifier
67
+     * @since 11.0.0
68
+     */
69
+    public function getIdentifier() {
70
+        return $this->identifier;
71
+    }
72 72
 
73
-	/**
74
-	 * @return string A translated string
75
-	 * @since 11.0.0
76
-	 */
77
-	public function getName() {
78
-		return $this->name;
79
-	}
73
+    /**
74
+     * @return string A translated string
75
+     * @since 11.0.0
76
+     */
77
+    public function getName() {
78
+        return $this->name;
79
+    }
80 80
 
81
-	/**
82
-	 * @return int whether the filter should be rather on the top or bottom of
83
-	 * the admin section. The filters are arranged in ascending order of the
84
-	 * priority values. It is required to return a value between 0 and 100.
85
-	 * @since 11.0.0
86
-	 */
87
-	public function getPriority() {
88
-		return 70;
89
-	}
81
+    /**
82
+     * @return int whether the filter should be rather on the top or bottom of
83
+     * the admin section. The filters are arranged in ascending order of the
84
+     * priority values. It is required to return a value between 0 and 100.
85
+     * @since 11.0.0
86
+     */
87
+    public function getPriority() {
88
+        return 70;
89
+    }
90 90
 
91
-	/**
92
-	 * @return bool True when the option can be changed for the stream
93
-	 * @since 11.0.0
94
-	 */
95
-	public function canChangeStream() {
96
-		return $this->canChangeStream;
97
-	}
91
+    /**
92
+     * @return bool True when the option can be changed for the stream
93
+     * @since 11.0.0
94
+     */
95
+    public function canChangeStream() {
96
+        return $this->canChangeStream;
97
+    }
98 98
 
99
-	/**
100
-	 * @return bool True when the option can be changed for the stream
101
-	 * @since 11.0.0
102
-	 */
103
-	public function isDefaultEnabledStream() {
104
-		return $this->isDefaultEnabledStream;
105
-	}
99
+    /**
100
+     * @return bool True when the option can be changed for the stream
101
+     * @since 11.0.0
102
+     */
103
+    public function isDefaultEnabledStream() {
104
+        return $this->isDefaultEnabledStream;
105
+    }
106 106
 
107
-	/**
108
-	 * @return bool True when the option can be changed for the mail
109
-	 * @since 11.0.0
110
-	 */
111
-	public function canChangeMail() {
112
-		return $this->canChangeMail;
113
-	}
107
+    /**
108
+     * @return bool True when the option can be changed for the mail
109
+     * @since 11.0.0
110
+     */
111
+    public function canChangeMail() {
112
+        return $this->canChangeMail;
113
+    }
114 114
 
115
-	/**
116
-	 * @return bool True when the option can be changed for the stream
117
-	 * @since 11.0.0
118
-	 */
119
-	public function isDefaultEnabledMail() {
120
-		return $this->isDefaultEnabledMail;
121
-	}
115
+    /**
116
+     * @return bool True when the option can be changed for the stream
117
+     * @since 11.0.0
118
+     */
119
+    public function isDefaultEnabledMail() {
120
+        return $this->isDefaultEnabledMail;
121
+    }
122 122
 }
123 123
 
Please login to merge, or discard this patch.
lib/private/Security/CSP/ContentSecurityPolicyNonceManager.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -29,52 +29,52 @@
 block discarded – undo
29 29
  * @package OC\Security\CSP
30 30
  */
31 31
 class ContentSecurityPolicyNonceManager {
32
-	/** @var CsrfTokenManager */
33
-	private $csrfTokenManager;
34
-	/** @var IRequest */
35
-	private $request;
36
-	/** @var string */
37
-	private $nonce = '';
32
+    /** @var CsrfTokenManager */
33
+    private $csrfTokenManager;
34
+    /** @var IRequest */
35
+    private $request;
36
+    /** @var string */
37
+    private $nonce = '';
38 38
 
39
-	/**
40
-	 * @param CsrfTokenManager $csrfTokenManager
41
-	 * @param IRequest $request
42
-	 */
43
-	public function __construct(CsrfTokenManager $csrfTokenManager,
44
-								IRequest $request) {
45
-		$this->csrfTokenManager = $csrfTokenManager;
46
-		$this->request = $request;
47
-	}
39
+    /**
40
+     * @param CsrfTokenManager $csrfTokenManager
41
+     * @param IRequest $request
42
+     */
43
+    public function __construct(CsrfTokenManager $csrfTokenManager,
44
+                                IRequest $request) {
45
+        $this->csrfTokenManager = $csrfTokenManager;
46
+        $this->request = $request;
47
+    }
48 48
 
49
-	/**
50
-	 * Returns the current CSP nounce
51
-	 *
52
-	 * @return string
53
-	 */
54
-	public function getNonce() {
55
-		if($this->nonce === '') {
56
-			$this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue());
57
-		}
49
+    /**
50
+     * Returns the current CSP nounce
51
+     *
52
+     * @return string
53
+     */
54
+    public function getNonce() {
55
+        if($this->nonce === '') {
56
+            $this->nonce = base64_encode($this->csrfTokenManager->getToken()->getEncryptedValue());
57
+        }
58 58
 
59
-		return $this->nonce;
60
-	}
59
+        return $this->nonce;
60
+    }
61 61
 
62
-	/**
63
-	 * Check if the browser supports CSP v3
64
-	 *
65
-	 * @return bool
66
-	 */
67
-	public function browserSupportsCspV3() {
68
-		$browserWhitelist = [
69
-			Request::USER_AGENT_CHROME,
70
-			// Firefox 45+
71
-			'/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/',
72
-		];
62
+    /**
63
+     * Check if the browser supports CSP v3
64
+     *
65
+     * @return bool
66
+     */
67
+    public function browserSupportsCspV3() {
68
+        $browserWhitelist = [
69
+            Request::USER_AGENT_CHROME,
70
+            // Firefox 45+
71
+            '/^Mozilla\/5\.0 \([^)]+\) Gecko\/[0-9.]+ Firefox\/(4[5-9]|[5-9][0-9])\.[0-9.]+$/',
72
+        ];
73 73
 
74
-		if($this->request->isUserAgent($browserWhitelist)) {
75
-			return true;
76
-		}
74
+        if($this->request->isUserAgent($browserWhitelist)) {
75
+            return true;
76
+        }
77 77
 
78
-		return false;
79
-	}
78
+        return false;
79
+    }
80 80
 }
Please login to merge, or discard this patch.
lib/private/Security/CSP/ContentSecurityPolicy.php 1 patch
Indentation   +167 added lines, -167 removed lines patch added patch discarded remove patch
@@ -29,172 +29,172 @@
 block discarded – undo
29 29
  * @package OC\Security\CSP
30 30
  */
31 31
 class ContentSecurityPolicy extends \OCP\AppFramework\Http\ContentSecurityPolicy {
32
-	/**
33
-	 * @return boolean
34
-	 */
35
-	public function isInlineScriptAllowed() {
36
-		return $this->inlineScriptAllowed;
37
-	}
38
-
39
-	/**
40
-	 * @param boolean $inlineScriptAllowed
41
-	 */
42
-	public function setInlineScriptAllowed($inlineScriptAllowed) {
43
-		$this->inlineScriptAllowed = $inlineScriptAllowed;
44
-	}
45
-
46
-	/**
47
-	 * @return boolean
48
-	 */
49
-	public function isEvalScriptAllowed() {
50
-		return $this->evalScriptAllowed;
51
-	}
52
-
53
-	/**
54
-	 * @param boolean $evalScriptAllowed
55
-	 */
56
-	public function setEvalScriptAllowed($evalScriptAllowed) {
57
-		$this->evalScriptAllowed = $evalScriptAllowed;
58
-	}
59
-
60
-	/**
61
-	 * @return array
62
-	 */
63
-	public function getAllowedScriptDomains() {
64
-		return $this->allowedScriptDomains;
65
-	}
66
-
67
-	/**
68
-	 * @param array $allowedScriptDomains
69
-	 */
70
-	public function setAllowedScriptDomains($allowedScriptDomains) {
71
-		$this->allowedScriptDomains = $allowedScriptDomains;
72
-	}
73
-
74
-	/**
75
-	 * @return boolean
76
-	 */
77
-	public function isInlineStyleAllowed() {
78
-		return $this->inlineStyleAllowed;
79
-	}
80
-
81
-	/**
82
-	 * @param boolean $inlineStyleAllowed
83
-	 */
84
-	public function setInlineStyleAllowed($inlineStyleAllowed) {
85
-		$this->inlineStyleAllowed = $inlineStyleAllowed;
86
-	}
87
-
88
-	/**
89
-	 * @return array
90
-	 */
91
-	public function getAllowedStyleDomains() {
92
-		return $this->allowedStyleDomains;
93
-	}
94
-
95
-	/**
96
-	 * @param array $allowedStyleDomains
97
-	 */
98
-	public function setAllowedStyleDomains($allowedStyleDomains) {
99
-		$this->allowedStyleDomains = $allowedStyleDomains;
100
-	}
101
-
102
-	/**
103
-	 * @return array
104
-	 */
105
-	public function getAllowedImageDomains() {
106
-		return $this->allowedImageDomains;
107
-	}
108
-
109
-	/**
110
-	 * @param array $allowedImageDomains
111
-	 */
112
-	public function setAllowedImageDomains($allowedImageDomains) {
113
-		$this->allowedImageDomains = $allowedImageDomains;
114
-	}
115
-
116
-	/**
117
-	 * @return array
118
-	 */
119
-	public function getAllowedConnectDomains() {
120
-		return $this->allowedConnectDomains;
121
-	}
122
-
123
-	/**
124
-	 * @param array $allowedConnectDomains
125
-	 */
126
-	public function setAllowedConnectDomains($allowedConnectDomains) {
127
-		$this->allowedConnectDomains = $allowedConnectDomains;
128
-	}
129
-
130
-	/**
131
-	 * @return array
132
-	 */
133
-	public function getAllowedMediaDomains() {
134
-		return $this->allowedMediaDomains;
135
-	}
136
-
137
-	/**
138
-	 * @param array $allowedMediaDomains
139
-	 */
140
-	public function setAllowedMediaDomains($allowedMediaDomains) {
141
-		$this->allowedMediaDomains = $allowedMediaDomains;
142
-	}
143
-
144
-	/**
145
-	 * @return array
146
-	 */
147
-	public function getAllowedObjectDomains() {
148
-		return $this->allowedObjectDomains;
149
-	}
150
-
151
-	/**
152
-	 * @param array $allowedObjectDomains
153
-	 */
154
-	public function setAllowedObjectDomains($allowedObjectDomains) {
155
-		$this->allowedObjectDomains = $allowedObjectDomains;
156
-	}
157
-
158
-	/**
159
-	 * @return array
160
-	 */
161
-	public function getAllowedFrameDomains() {
162
-		return $this->allowedFrameDomains;
163
-	}
164
-
165
-	/**
166
-	 * @param array $allowedFrameDomains
167
-	 */
168
-	public function setAllowedFrameDomains($allowedFrameDomains) {
169
-		$this->allowedFrameDomains = $allowedFrameDomains;
170
-	}
171
-
172
-	/**
173
-	 * @return array
174
-	 */
175
-	public function getAllowedFontDomains() {
176
-		return $this->allowedFontDomains;
177
-	}
178
-
179
-	/**
180
-	 * @param array $allowedFontDomains
181
-	 */
182
-	public function setAllowedFontDomains($allowedFontDomains) {
183
-		$this->allowedFontDomains = $allowedFontDomains;
184
-	}
185
-
186
-	/**
187
-	 * @return array
188
-	 */
189
-	public function getAllowedChildSrcDomains() {
190
-		return $this->allowedChildSrcDomains;
191
-	}
192
-
193
-	/**
194
-	 * @param array $allowedChildSrcDomains
195
-	 */
196
-	public function setAllowedChildSrcDomains($allowedChildSrcDomains) {
197
-		$this->allowedChildSrcDomains = $allowedChildSrcDomains;
198
-	}
32
+    /**
33
+     * @return boolean
34
+     */
35
+    public function isInlineScriptAllowed() {
36
+        return $this->inlineScriptAllowed;
37
+    }
38
+
39
+    /**
40
+     * @param boolean $inlineScriptAllowed
41
+     */
42
+    public function setInlineScriptAllowed($inlineScriptAllowed) {
43
+        $this->inlineScriptAllowed = $inlineScriptAllowed;
44
+    }
45
+
46
+    /**
47
+     * @return boolean
48
+     */
49
+    public function isEvalScriptAllowed() {
50
+        return $this->evalScriptAllowed;
51
+    }
52
+
53
+    /**
54
+     * @param boolean $evalScriptAllowed
55
+     */
56
+    public function setEvalScriptAllowed($evalScriptAllowed) {
57
+        $this->evalScriptAllowed = $evalScriptAllowed;
58
+    }
59
+
60
+    /**
61
+     * @return array
62
+     */
63
+    public function getAllowedScriptDomains() {
64
+        return $this->allowedScriptDomains;
65
+    }
66
+
67
+    /**
68
+     * @param array $allowedScriptDomains
69
+     */
70
+    public function setAllowedScriptDomains($allowedScriptDomains) {
71
+        $this->allowedScriptDomains = $allowedScriptDomains;
72
+    }
73
+
74
+    /**
75
+     * @return boolean
76
+     */
77
+    public function isInlineStyleAllowed() {
78
+        return $this->inlineStyleAllowed;
79
+    }
80
+
81
+    /**
82
+     * @param boolean $inlineStyleAllowed
83
+     */
84
+    public function setInlineStyleAllowed($inlineStyleAllowed) {
85
+        $this->inlineStyleAllowed = $inlineStyleAllowed;
86
+    }
87
+
88
+    /**
89
+     * @return array
90
+     */
91
+    public function getAllowedStyleDomains() {
92
+        return $this->allowedStyleDomains;
93
+    }
94
+
95
+    /**
96
+     * @param array $allowedStyleDomains
97
+     */
98
+    public function setAllowedStyleDomains($allowedStyleDomains) {
99
+        $this->allowedStyleDomains = $allowedStyleDomains;
100
+    }
101
+
102
+    /**
103
+     * @return array
104
+     */
105
+    public function getAllowedImageDomains() {
106
+        return $this->allowedImageDomains;
107
+    }
108
+
109
+    /**
110
+     * @param array $allowedImageDomains
111
+     */
112
+    public function setAllowedImageDomains($allowedImageDomains) {
113
+        $this->allowedImageDomains = $allowedImageDomains;
114
+    }
115
+
116
+    /**
117
+     * @return array
118
+     */
119
+    public function getAllowedConnectDomains() {
120
+        return $this->allowedConnectDomains;
121
+    }
122
+
123
+    /**
124
+     * @param array $allowedConnectDomains
125
+     */
126
+    public function setAllowedConnectDomains($allowedConnectDomains) {
127
+        $this->allowedConnectDomains = $allowedConnectDomains;
128
+    }
129
+
130
+    /**
131
+     * @return array
132
+     */
133
+    public function getAllowedMediaDomains() {
134
+        return $this->allowedMediaDomains;
135
+    }
136
+
137
+    /**
138
+     * @param array $allowedMediaDomains
139
+     */
140
+    public function setAllowedMediaDomains($allowedMediaDomains) {
141
+        $this->allowedMediaDomains = $allowedMediaDomains;
142
+    }
143
+
144
+    /**
145
+     * @return array
146
+     */
147
+    public function getAllowedObjectDomains() {
148
+        return $this->allowedObjectDomains;
149
+    }
150
+
151
+    /**
152
+     * @param array $allowedObjectDomains
153
+     */
154
+    public function setAllowedObjectDomains($allowedObjectDomains) {
155
+        $this->allowedObjectDomains = $allowedObjectDomains;
156
+    }
157
+
158
+    /**
159
+     * @return array
160
+     */
161
+    public function getAllowedFrameDomains() {
162
+        return $this->allowedFrameDomains;
163
+    }
164
+
165
+    /**
166
+     * @param array $allowedFrameDomains
167
+     */
168
+    public function setAllowedFrameDomains($allowedFrameDomains) {
169
+        $this->allowedFrameDomains = $allowedFrameDomains;
170
+    }
171
+
172
+    /**
173
+     * @return array
174
+     */
175
+    public function getAllowedFontDomains() {
176
+        return $this->allowedFontDomains;
177
+    }
178
+
179
+    /**
180
+     * @param array $allowedFontDomains
181
+     */
182
+    public function setAllowedFontDomains($allowedFontDomains) {
183
+        $this->allowedFontDomains = $allowedFontDomains;
184
+    }
185
+
186
+    /**
187
+     * @return array
188
+     */
189
+    public function getAllowedChildSrcDomains() {
190
+        return $this->allowedChildSrcDomains;
191
+    }
192
+
193
+    /**
194
+     * @param array $allowedChildSrcDomains
195
+     */
196
+    public function setAllowedChildSrcDomains($allowedChildSrcDomains) {
197
+        $this->allowedChildSrcDomains = $allowedChildSrcDomains;
198
+    }
199 199
 
200 200
 }
Please login to merge, or discard this patch.
lib/private/Security/CSP/ContentSecurityPolicyManager.php 1 patch
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -27,48 +27,48 @@
 block discarded – undo
27 27
 use OCP\Security\IContentSecurityPolicyManager;
28 28
 
29 29
 class ContentSecurityPolicyManager implements IContentSecurityPolicyManager {
30
-	/** @var ContentSecurityPolicy[] */
31
-	private $policies = [];
30
+    /** @var ContentSecurityPolicy[] */
31
+    private $policies = [];
32 32
 
33
-	/** {@inheritdoc} */
34
-	public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) {
35
-		$this->policies[] = $policy;
36
-	}
33
+    /** {@inheritdoc} */
34
+    public function addDefaultPolicy(EmptyContentSecurityPolicy $policy) {
35
+        $this->policies[] = $policy;
36
+    }
37 37
 
38
-	/**
39
-	 * Get the configured default policy. This is not in the public namespace
40
-	 * as it is only supposed to be used by core itself.
41
-	 *
42
-	 * @return ContentSecurityPolicy
43
-	 */
44
-	public function getDefaultPolicy() {
45
-		$defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy();
46
-		foreach($this->policies as $policy) {
47
-			$defaultPolicy = $this->mergePolicies($defaultPolicy, $policy);
48
-		}
49
-		return $defaultPolicy;
50
-	}
38
+    /**
39
+     * Get the configured default policy. This is not in the public namespace
40
+     * as it is only supposed to be used by core itself.
41
+     *
42
+     * @return ContentSecurityPolicy
43
+     */
44
+    public function getDefaultPolicy() {
45
+        $defaultPolicy = new \OC\Security\CSP\ContentSecurityPolicy();
46
+        foreach($this->policies as $policy) {
47
+            $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy);
48
+        }
49
+        return $defaultPolicy;
50
+    }
51 51
 
52
-	/**
53
-	 * Merges the first given policy with the second one
54
-	 *
55
-	 * @param ContentSecurityPolicy $defaultPolicy
56
-	 * @param EmptyContentSecurityPolicy $originalPolicy
57
-	 * @return ContentSecurityPolicy
58
-	 */
59
-	public function mergePolicies(ContentSecurityPolicy $defaultPolicy,
60
-								  EmptyContentSecurityPolicy $originalPolicy) {
61
-		foreach((object)(array)$originalPolicy as $name => $value) {
62
-			$setter = 'set'.ucfirst($name);
63
-			if(is_array($value)) {
64
-				$getter = 'get'.ucfirst($name);
65
-				$currentValues = is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : [];
66
-				$defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value))));
67
-			} elseif (is_bool($value)) {
68
-				$defaultPolicy->$setter($value);
69
-			}
70
-		}
52
+    /**
53
+     * Merges the first given policy with the second one
54
+     *
55
+     * @param ContentSecurityPolicy $defaultPolicy
56
+     * @param EmptyContentSecurityPolicy $originalPolicy
57
+     * @return ContentSecurityPolicy
58
+     */
59
+    public function mergePolicies(ContentSecurityPolicy $defaultPolicy,
60
+                                    EmptyContentSecurityPolicy $originalPolicy) {
61
+        foreach((object)(array)$originalPolicy as $name => $value) {
62
+            $setter = 'set'.ucfirst($name);
63
+            if(is_array($value)) {
64
+                $getter = 'get'.ucfirst($name);
65
+                $currentValues = is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : [];
66
+                $defaultPolicy->$setter(array_values(array_unique(array_merge($currentValues, $value))));
67
+            } elseif (is_bool($value)) {
68
+                $defaultPolicy->$setter($value);
69
+            }
70
+        }
71 71
 
72
-		return $defaultPolicy;
73
-	}
72
+        return $defaultPolicy;
73
+    }
74 74
 }
Please login to merge, or discard this patch.
lib/private/Security/CredentialsManager.php 1 patch
Indentation   +78 added lines, -78 removed lines patch added patch discarded remove patch
@@ -34,93 +34,93 @@
 block discarded – undo
34 34
  */
35 35
 class CredentialsManager implements ICredentialsManager {
36 36
 
37
-	const DB_TABLE = 'credentials';
37
+    const DB_TABLE = 'credentials';
38 38
 
39
-	/** @var ICrypto */
40
-	protected $crypto;
39
+    /** @var ICrypto */
40
+    protected $crypto;
41 41
 
42
-	/** @var IDBConnection */
43
-	protected $dbConnection;
42
+    /** @var IDBConnection */
43
+    protected $dbConnection;
44 44
 
45
-	/**
46
-	 * @param ICrypto $crypto
47
-	 * @param IDBConnection $dbConnection
48
-	 */
49
-	public function __construct(ICrypto $crypto, IDBConnection $dbConnection) {
50
-		$this->crypto = $crypto;
51
-		$this->dbConnection = $dbConnection;
52
-	}
45
+    /**
46
+     * @param ICrypto $crypto
47
+     * @param IDBConnection $dbConnection
48
+     */
49
+    public function __construct(ICrypto $crypto, IDBConnection $dbConnection) {
50
+        $this->crypto = $crypto;
51
+        $this->dbConnection = $dbConnection;
52
+    }
53 53
 
54
-	/**
55
-	 * Store a set of credentials
56
-	 *
57
-	 * @param string|null $userId Null for system-wide credentials
58
-	 * @param string $identifier
59
-	 * @param mixed $credentials
60
-	 */
61
-	public function store($userId, $identifier, $credentials) {
62
-		$value = $this->crypto->encrypt(json_encode($credentials));
54
+    /**
55
+     * Store a set of credentials
56
+     *
57
+     * @param string|null $userId Null for system-wide credentials
58
+     * @param string $identifier
59
+     * @param mixed $credentials
60
+     */
61
+    public function store($userId, $identifier, $credentials) {
62
+        $value = $this->crypto->encrypt(json_encode($credentials));
63 63
 
64
-		$this->dbConnection->setValues(self::DB_TABLE, [
65
-			'user' => $userId,
66
-			'identifier' => $identifier,
67
-		], [
68
-			'credentials' => $value,
69
-		]);
70
-	}
64
+        $this->dbConnection->setValues(self::DB_TABLE, [
65
+            'user' => $userId,
66
+            'identifier' => $identifier,
67
+        ], [
68
+            'credentials' => $value,
69
+        ]);
70
+    }
71 71
 
72
-	/**
73
-	 * Retrieve a set of credentials
74
-	 *
75
-	 * @param string|null $userId Null for system-wide credentials
76
-	 * @param string $identifier
77
-	 * @return mixed
78
-	 */
79
-	public function retrieve($userId, $identifier) {
80
-		$qb = $this->dbConnection->getQueryBuilder();
81
-		$qb->select('credentials')
82
-			->from(self::DB_TABLE)
83
-			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
84
-			->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
85
-		;
86
-		$result = $qb->execute()->fetch();
72
+    /**
73
+     * Retrieve a set of credentials
74
+     *
75
+     * @param string|null $userId Null for system-wide credentials
76
+     * @param string $identifier
77
+     * @return mixed
78
+     */
79
+    public function retrieve($userId, $identifier) {
80
+        $qb = $this->dbConnection->getQueryBuilder();
81
+        $qb->select('credentials')
82
+            ->from(self::DB_TABLE)
83
+            ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
84
+            ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
85
+        ;
86
+        $result = $qb->execute()->fetch();
87 87
 
88
-		if (!$result) {
89
-			return null;
90
-		}
91
-		$value = $result['credentials'];
88
+        if (!$result) {
89
+            return null;
90
+        }
91
+        $value = $result['credentials'];
92 92
 
93
-		return json_decode($this->crypto->decrypt($value), true);
94
-	}
93
+        return json_decode($this->crypto->decrypt($value), true);
94
+    }
95 95
 
96
-	/**
97
-	 * Delete a set of credentials
98
-	 *
99
-	 * @param string|null $userId Null for system-wide credentials
100
-	 * @param string $identifier
101
-	 * @return int rows removed
102
-	 */
103
-	public function delete($userId, $identifier) {
104
-		$qb = $this->dbConnection->getQueryBuilder();
105
-		$qb->delete(self::DB_TABLE)
106
-			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
107
-			->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
108
-		;
109
-		return $qb->execute();
110
-	}
96
+    /**
97
+     * Delete a set of credentials
98
+     *
99
+     * @param string|null $userId Null for system-wide credentials
100
+     * @param string $identifier
101
+     * @return int rows removed
102
+     */
103
+    public function delete($userId, $identifier) {
104
+        $qb = $this->dbConnection->getQueryBuilder();
105
+        $qb->delete(self::DB_TABLE)
106
+            ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
107
+            ->andWhere($qb->expr()->eq('identifier', $qb->createNamedParameter($identifier)))
108
+        ;
109
+        return $qb->execute();
110
+    }
111 111
 
112
-	/**
113
-	 * Erase all credentials stored for a user
114
-	 *
115
-	 * @param string $userId
116
-	 * @return int rows removed
117
-	 */
118
-	public function erase($userId) {
119
-		$qb = $this->dbConnection->getQueryBuilder();
120
-		$qb->delete(self::DB_TABLE)
121
-			->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
122
-		;
123
-		return $qb->execute();
124
-	}
112
+    /**
113
+     * Erase all credentials stored for a user
114
+     *
115
+     * @param string $userId
116
+     * @return int rows removed
117
+     */
118
+    public function erase($userId) {
119
+        $qb = $this->dbConnection->getQueryBuilder();
120
+        $qb->delete(self::DB_TABLE)
121
+            ->where($qb->expr()->eq('user', $qb->createNamedParameter($userId)))
122
+        ;
123
+        return $qb->execute();
124
+    }
125 125
 
126 126
 }
Please login to merge, or discard this patch.
lib/private/Security/TrustedDomainHelper.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -32,68 +32,68 @@
 block discarded – undo
32 32
  * @package OC\Security
33 33
  */
34 34
 class TrustedDomainHelper {
35
-	/** @var IConfig */
36
-	private $config;
35
+    /** @var IConfig */
36
+    private $config;
37 37
 
38
-	/**
39
-	 * @param IConfig $config
40
-	 */
41
-	function __construct(IConfig $config) {
42
-		$this->config = $config;
43
-	}
38
+    /**
39
+     * @param IConfig $config
40
+     */
41
+    function __construct(IConfig $config) {
42
+        $this->config = $config;
43
+    }
44 44
 
45
-	/**
46
-	 * Strips a potential port from a domain (in format domain:port)
47
-	 * @param string $host
48
-	 * @return string $host without appended port
49
-	 */
50
-	private function getDomainWithoutPort($host) {
51
-		$pos = strrpos($host, ':');
52
-		if ($pos !== false) {
53
-			$port = substr($host, $pos + 1);
54
-			if (is_numeric($port)) {
55
-				$host = substr($host, 0, $pos);
56
-			}
57
-		}
58
-		return $host;
59
-	}
45
+    /**
46
+     * Strips a potential port from a domain (in format domain:port)
47
+     * @param string $host
48
+     * @return string $host without appended port
49
+     */
50
+    private function getDomainWithoutPort($host) {
51
+        $pos = strrpos($host, ':');
52
+        if ($pos !== false) {
53
+            $port = substr($host, $pos + 1);
54
+            if (is_numeric($port)) {
55
+                $host = substr($host, 0, $pos);
56
+            }
57
+        }
58
+        return $host;
59
+    }
60 60
 
61
-	/**
62
-	 * Checks whether a domain is considered as trusted from the list
63
-	 * of trusted domains. If no trusted domains have been configured, returns
64
-	 * true.
65
-	 * This is used to prevent Host Header Poisoning.
66
-	 * @param string $domainWithPort
67
-	 * @return bool true if the given domain is trusted or if no trusted domains
68
-	 * have been configured
69
-	 */
70
-	public function isTrustedDomain($domainWithPort) {
71
-		$domain = $this->getDomainWithoutPort($domainWithPort);
61
+    /**
62
+     * Checks whether a domain is considered as trusted from the list
63
+     * of trusted domains. If no trusted domains have been configured, returns
64
+     * true.
65
+     * This is used to prevent Host Header Poisoning.
66
+     * @param string $domainWithPort
67
+     * @return bool true if the given domain is trusted or if no trusted domains
68
+     * have been configured
69
+     */
70
+    public function isTrustedDomain($domainWithPort) {
71
+        $domain = $this->getDomainWithoutPort($domainWithPort);
72 72
 
73
-		// Read trusted domains from config
74
-		$trustedList = $this->config->getSystemValue('trusted_domains', []);
75
-		if (!is_array($trustedList)) {
76
-			return false;
77
-		}
73
+        // Read trusted domains from config
74
+        $trustedList = $this->config->getSystemValue('trusted_domains', []);
75
+        if (!is_array($trustedList)) {
76
+            return false;
77
+        }
78 78
 
79
-		// Always allow access from localhost
80
-		if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) {
81
-			return true;
82
-		}
83
-		// Reject misformed domains in any case
84
-		if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
85
-			return false;
86
-		}
87
-		// Match, allowing for * wildcards
88
-		foreach ($trustedList as $trusted) {
89
-			if (gettype($trusted) !== 'string') {
90
-				break;
91
-			}
92
-			$regex = '/^' . join('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
93
-			if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94
- 				return true;
95
- 			}
96
- 		}
97
- 		return false;
98
-	}
79
+        // Always allow access from localhost
80
+        if (preg_match(Request::REGEX_LOCALHOST, $domain) === 1) {
81
+            return true;
82
+        }
83
+        // Reject misformed domains in any case
84
+        if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
85
+            return false;
86
+        }
87
+        // Match, allowing for * wildcards
88
+        foreach ($trustedList as $trusted) {
89
+            if (gettype($trusted) !== 'string') {
90
+                break;
91
+            }
92
+            $regex = '/^' . join('[-\.a-zA-Z0-9]*', array_map(function($v) { return preg_quote($v, '/'); }, explode('*', $trusted))) . '$/';
93
+            if (preg_match($regex, $domain) || preg_match($regex, $domainWithPort)) {
94
+                    return true;
95
+                }
96
+            }
97
+            return false;
98
+    }
99 99
 }
Please login to merge, or discard this patch.
lib/private/Security/Hasher.php 1 patch
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -46,116 +46,116 @@
 block discarded – undo
46 46
  * @package OC\Security
47 47
  */
48 48
 class Hasher implements IHasher {
49
-	/** @var IConfig */
50
-	private $config;
51
-	/** @var array Options passed to password_hash and password_needs_rehash */
52
-	private $options = array();
53
-	/** @var string Salt used for legacy passwords */
54
-	private $legacySalt = null;
55
-	/** @var int Current version of the generated hash */
56
-	private $currentVersion = 1;
57
-
58
-	/**
59
-	 * @param IConfig $config
60
-	 */
61
-	function __construct(IConfig $config) {
62
-		$this->config = $config;
63
-
64
-		$hashingCost = $this->config->getSystemValue('hashingCost', null);
65
-		if(!is_null($hashingCost)) {
66
-			$this->options['cost'] = $hashingCost;
67
-		}
68
-	}
69
-
70
-	/**
71
-	 * Hashes a message using PHP's `password_hash` functionality.
72
-	 * Please note that the size of the returned string is not guaranteed
73
-	 * and can be up to 255 characters.
74
-	 *
75
-	 * @param string $message Message to generate hash from
76
-	 * @return string Hash of the message with appended version parameter
77
-	 */
78
-	public function hash($message) {
79
-		return $this->currentVersion . '|' . password_hash($message, PASSWORD_DEFAULT, $this->options);
80
-	}
81
-
82
-	/**
83
-	 * Get the version and hash from a prefixedHash
84
-	 * @param string $prefixedHash
85
-	 * @return null|array Null if the hash is not prefixed, otherwise array('version' => 1, 'hash' => 'foo')
86
-	 */
87
-	protected function splitHash($prefixedHash) {
88
-		$explodedString = explode('|', $prefixedHash, 2);
89
-		if(sizeof($explodedString) === 2) {
90
-			if((int)$explodedString[0] > 0) {
91
-				return array('version' => (int)$explodedString[0], 'hash' => $explodedString[1]);
92
-			}
93
-		}
94
-
95
-		return null;
96
-	}
97
-
98
-	/**
99
-	 * Verify legacy hashes
100
-	 * @param string $message Message to verify
101
-	 * @param string $hash Assumed hash of the message
102
-	 * @param null|string &$newHash Reference will contain the updated hash
103
-	 * @return bool Whether $hash is a valid hash of $message
104
-	 */
105
-	protected function legacyHashVerify($message, $hash, &$newHash = null) {
106
-		if(empty($this->legacySalt)) {
107
-			$this->legacySalt = $this->config->getSystemValue('passwordsalt', '');
108
-		}
109
-
110
-		// Verify whether it matches a legacy PHPass or SHA1 string
111
-		$hashLength = strlen($hash);
112
-		if($hashLength === 60 && password_verify($message.$this->legacySalt, $hash) ||
113
-			$hashLength === 40 && hash_equals($hash, sha1($message))) {
114
-			$newHash = $this->hash($message);
115
-			return true;
116
-		}
117
-
118
-		return false;
119
-	}
120
-
121
-	/**
122
-	 * Verify V1 hashes
123
-	 * @param string $message Message to verify
124
-	 * @param string $hash Assumed hash of the message
125
-	 * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
126
-	 * @return bool Whether $hash is a valid hash of $message
127
-	 */
128
-	protected function verifyHashV1($message, $hash, &$newHash = null) {
129
-		if(password_verify($message, $hash)) {
130
-			if(password_needs_rehash($hash, PASSWORD_DEFAULT, $this->options)) {
131
-				$newHash = $this->hash($message);
132
-			}
133
-			return true;
134
-		}
135
-
136
-		return false;
137
-	}
138
-
139
-	/**
140
-	 * @param string $message Message to verify
141
-	 * @param string $hash Assumed hash of the message
142
-	 * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
143
-	 * @return bool Whether $hash is a valid hash of $message
144
-	 */
145
-	public function verify($message, $hash, &$newHash = null) {
146
-		$splittedHash = $this->splitHash($hash);
147
-
148
-		if(isset($splittedHash['version'])) {
149
-			switch ($splittedHash['version']) {
150
-				case 1:
151
-					return $this->verifyHashV1($message, $splittedHash['hash'], $newHash);
152
-			}
153
-		} else {
154
-			return $this->legacyHashVerify($message, $hash, $newHash);
155
-		}
156
-
157
-
158
-		return false;
159
-	}
49
+    /** @var IConfig */
50
+    private $config;
51
+    /** @var array Options passed to password_hash and password_needs_rehash */
52
+    private $options = array();
53
+    /** @var string Salt used for legacy passwords */
54
+    private $legacySalt = null;
55
+    /** @var int Current version of the generated hash */
56
+    private $currentVersion = 1;
57
+
58
+    /**
59
+     * @param IConfig $config
60
+     */
61
+    function __construct(IConfig $config) {
62
+        $this->config = $config;
63
+
64
+        $hashingCost = $this->config->getSystemValue('hashingCost', null);
65
+        if(!is_null($hashingCost)) {
66
+            $this->options['cost'] = $hashingCost;
67
+        }
68
+    }
69
+
70
+    /**
71
+     * Hashes a message using PHP's `password_hash` functionality.
72
+     * Please note that the size of the returned string is not guaranteed
73
+     * and can be up to 255 characters.
74
+     *
75
+     * @param string $message Message to generate hash from
76
+     * @return string Hash of the message with appended version parameter
77
+     */
78
+    public function hash($message) {
79
+        return $this->currentVersion . '|' . password_hash($message, PASSWORD_DEFAULT, $this->options);
80
+    }
81
+
82
+    /**
83
+     * Get the version and hash from a prefixedHash
84
+     * @param string $prefixedHash
85
+     * @return null|array Null if the hash is not prefixed, otherwise array('version' => 1, 'hash' => 'foo')
86
+     */
87
+    protected function splitHash($prefixedHash) {
88
+        $explodedString = explode('|', $prefixedHash, 2);
89
+        if(sizeof($explodedString) === 2) {
90
+            if((int)$explodedString[0] > 0) {
91
+                return array('version' => (int)$explodedString[0], 'hash' => $explodedString[1]);
92
+            }
93
+        }
94
+
95
+        return null;
96
+    }
97
+
98
+    /**
99
+     * Verify legacy hashes
100
+     * @param string $message Message to verify
101
+     * @param string $hash Assumed hash of the message
102
+     * @param null|string &$newHash Reference will contain the updated hash
103
+     * @return bool Whether $hash is a valid hash of $message
104
+     */
105
+    protected function legacyHashVerify($message, $hash, &$newHash = null) {
106
+        if(empty($this->legacySalt)) {
107
+            $this->legacySalt = $this->config->getSystemValue('passwordsalt', '');
108
+        }
109
+
110
+        // Verify whether it matches a legacy PHPass or SHA1 string
111
+        $hashLength = strlen($hash);
112
+        if($hashLength === 60 && password_verify($message.$this->legacySalt, $hash) ||
113
+            $hashLength === 40 && hash_equals($hash, sha1($message))) {
114
+            $newHash = $this->hash($message);
115
+            return true;
116
+        }
117
+
118
+        return false;
119
+    }
120
+
121
+    /**
122
+     * Verify V1 hashes
123
+     * @param string $message Message to verify
124
+     * @param string $hash Assumed hash of the message
125
+     * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
126
+     * @return bool Whether $hash is a valid hash of $message
127
+     */
128
+    protected function verifyHashV1($message, $hash, &$newHash = null) {
129
+        if(password_verify($message, $hash)) {
130
+            if(password_needs_rehash($hash, PASSWORD_DEFAULT, $this->options)) {
131
+                $newHash = $this->hash($message);
132
+            }
133
+            return true;
134
+        }
135
+
136
+        return false;
137
+    }
138
+
139
+    /**
140
+     * @param string $message Message to verify
141
+     * @param string $hash Assumed hash of the message
142
+     * @param null|string &$newHash Reference will contain the updated hash if necessary. Update the existing hash with this one.
143
+     * @return bool Whether $hash is a valid hash of $message
144
+     */
145
+    public function verify($message, $hash, &$newHash = null) {
146
+        $splittedHash = $this->splitHash($hash);
147
+
148
+        if(isset($splittedHash['version'])) {
149
+            switch ($splittedHash['version']) {
150
+                case 1:
151
+                    return $this->verifyHashV1($message, $splittedHash['hash'], $newHash);
152
+            }
153
+        } else {
154
+            return $this->legacyHashVerify($message, $hash, $newHash);
155
+        }
156
+
157
+
158
+        return false;
159
+    }
160 160
 
161 161
 }
Please login to merge, or discard this patch.