Passed
Push — master ( 96e892...5b0e70 )
by Roeland
13:09
created
lib/public/Settings/IManager.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -28,72 +28,72 @@
 block discarded – undo
28 28
  * @since 9.1
29 29
  */
30 30
 interface IManager {
31
-	/**
32
-	 * @since 9.1.0
33
-	 */
34
-	const KEY_ADMIN_SETTINGS = 'admin';
31
+    /**
32
+     * @since 9.1.0
33
+     */
34
+    const KEY_ADMIN_SETTINGS = 'admin';
35 35
 
36
-	/**
37
-	 * @since 9.1.0
38
-	 */
39
-	const KEY_ADMIN_SECTION  = 'admin-section';
36
+    /**
37
+     * @since 9.1.0
38
+     */
39
+    const KEY_ADMIN_SECTION  = 'admin-section';
40 40
 
41
-	/**
42
-	 * @since 13.0.0
43
-	 */
44
-	const KEY_PERSONAL_SETTINGS = 'personal';
41
+    /**
42
+     * @since 13.0.0
43
+     */
44
+    const KEY_PERSONAL_SETTINGS = 'personal';
45 45
 
46
-	/**
47
-	 * @since 13.0.0
48
-	 */
49
-	const KEY_PERSONAL_SECTION  = 'personal-section';
46
+    /**
47
+     * @since 13.0.0
48
+     */
49
+    const KEY_PERSONAL_SECTION  = 'personal-section';
50 50
 
51
-	/**
52
-	 * @param string $type 'admin' or 'personal'
53
-	 * @param string $section Class must implement OCP\Settings\ISection
54
-	 * @since 14.0.0
55
-	 */
56
-	public function registerSection(string $type, string $section);
51
+    /**
52
+     * @param string $type 'admin' or 'personal'
53
+     * @param string $section Class must implement OCP\Settings\ISection
54
+     * @since 14.0.0
55
+     */
56
+    public function registerSection(string $type, string $section);
57 57
 
58
-	/**
59
-	 * @param string $type 'admin' or 'personal'
60
-	 * @param string $setting Class must implement OCP\Settings\ISetting
61
-	 * @since 14.0.0
62
-	 */
63
-	public function registerSetting(string $type, string $setting);
58
+    /**
59
+     * @param string $type 'admin' or 'personal'
60
+     * @param string $setting Class must implement OCP\Settings\ISetting
61
+     * @since 14.0.0
62
+     */
63
+    public function registerSetting(string $type, string $setting);
64 64
 
65
-	/**
66
-	 * returns a list of the admin sections
67
-	 *
68
-	 * @return array array of ISection[] where key is the priority
69
-	 * @since 9.1.0
70
-	 */
71
-	public function getAdminSections(): array;
65
+    /**
66
+     * returns a list of the admin sections
67
+     *
68
+     * @return array array of ISection[] where key is the priority
69
+     * @since 9.1.0
70
+     */
71
+    public function getAdminSections(): array;
72 72
 
73
-	/**
74
-	 * returns a list of the personal sections
75
-	 *
76
-	 * @return array array of ISection[] where key is the priority
77
-	 * @since 13.0.0
78
-	 */
79
-	public function getPersonalSections(): array;
73
+    /**
74
+     * returns a list of the personal sections
75
+     *
76
+     * @return array array of ISection[] where key is the priority
77
+     * @since 13.0.0
78
+     */
79
+    public function getPersonalSections(): array;
80 80
 
81
-	/**
82
-	 * returns a list of the admin settings
83
-	 *
84
-	 * @param string $section the section id for which to load the settings
85
-	 * @param bool $subAdminOnly only return settings sub admins are supposed to see (since 17.0.0)
86
-	 * @return array array of IAdmin[] where key is the priority
87
-	 * @since 9.1.0
88
-	 */
89
-	public function getAdminSettings($section, bool $subAdminOnly = false): array;
81
+    /**
82
+     * returns a list of the admin settings
83
+     *
84
+     * @param string $section the section id for which to load the settings
85
+     * @param bool $subAdminOnly only return settings sub admins are supposed to see (since 17.0.0)
86
+     * @return array array of IAdmin[] where key is the priority
87
+     * @since 9.1.0
88
+     */
89
+    public function getAdminSettings($section, bool $subAdminOnly = false): array;
90 90
 
91
-	/**
92
-	 * returns a list of the personal  settings
93
-	 *
94
-	 * @param string $section the section id for which to load the settings
95
-	 * @return array array of IPersonal[] where key is the priority
96
-	 * @since 13.0.0
97
-	 */
98
-	public function getPersonalSettings($section): array;
91
+    /**
92
+     * returns a list of the personal  settings
93
+     *
94
+     * @param string $section the section id for which to load the settings
95
+     * @return array array of IPersonal[] where key is the priority
96
+     * @since 13.0.0
97
+     */
98
+    public function getPersonalSettings($section): array;
99 99
 }
Please login to merge, or discard this patch.
lib/private/Settings/Manager.php 1 patch
Indentation   +357 added lines, -357 removed lines patch added patch discarded remove patch
@@ -43,361 +43,361 @@
 block discarded – undo
43 43
 
44 44
 class Manager implements IManager {
45 45
 
46
-	/** @var ILogger */
47
-	private $log;
48
-
49
-	/** @var IL10N */
50
-	private $l;
51
-
52
-	/** @var IFactory */
53
-	private $l10nFactory;
54
-
55
-	/** @var IURLGenerator */
56
-	private $url;
57
-
58
-	/** @var IServerContainer */
59
-	private $container;
60
-
61
-	public function __construct(
62
-		ILogger $log,
63
-		IFactory $l10nFactory,
64
-		IURLGenerator $url,
65
-		IServerContainer $container
66
-	) {
67
-		$this->log = $log;
68
-		$this->l10nFactory = $l10nFactory;
69
-		$this->url = $url;
70
-		$this->container = $container;
71
-	}
72
-
73
-	/** @var array */
74
-	protected $sectionClasses = [];
75
-
76
-	/** @var array */
77
-	protected $sections = [];
78
-
79
-	/**
80
-	 * @param string $type 'admin' or 'personal'
81
-	 * @param string $section Class must implement OCP\Settings\ISection
82
-	 *
83
-	 * @return void
84
-	 */
85
-	public function registerSection(string $type, string $section) {
86
-		if (!isset($this->sectionClasses[$type])) {
87
-			$this->sectionClasses[$type] = [];
88
-		}
89
-
90
-		$this->sectionClasses[$type][] = $section;
91
-	}
92
-
93
-	/**
94
-	 * @param string $type 'admin' or 'personal'
95
-	 *
96
-	 * @return ISection[]
97
-	 */
98
-	protected function getSections(string $type): array {
99
-		if (!isset($this->sections[$type])) {
100
-			$this->sections[$type] = [];
101
-		}
102
-
103
-		if (!isset($this->sectionClasses[$type])) {
104
-			return $this->sections[$type];
105
-		}
106
-
107
-		foreach ($this->sectionClasses[$type] as $index => $class) {
108
-			try {
109
-				/** @var ISection $section */
110
-				$section = \OC::$server->query($class);
111
-			} catch (QueryException $e) {
112
-				$this->log->logException($e, ['level' => ILogger::INFO]);
113
-				continue;
114
-			}
115
-
116
-			if (!$section instanceof ISection) {
117
-				$this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]);
118
-				continue;
119
-			}
120
-
121
-			$sectionID = $section->getID();
122
-
123
-			if (isset($this->sections[$type][$sectionID])) {
124
-				$this->log->logException(new \InvalidArgumentException('Section with the same ID already registered'), ['level' => ILogger::INFO]);
125
-				continue;
126
-			}
127
-
128
-			$this->sections[$type][$sectionID] = $section;
129
-
130
-			unset($this->sectionClasses[$type][$index]);
131
-		}
132
-
133
-		return $this->sections[$type];
134
-	}
135
-
136
-	/** @var array */
137
-	protected $settingClasses = [];
138
-
139
-	/** @var array */
140
-	protected $settings = [];
141
-
142
-	/**
143
-	 * @param string $type 'admin' or 'personal'
144
-	 * @param string $setting Class must implement OCP\Settings\ISetting
145
-	 *
146
-	 * @return void
147
-	 */
148
-	public function registerSetting(string $type, string $setting) {
149
-		$this->settingClasses[$setting] = $type;
150
-	}
151
-
152
-	/**
153
-	 * @param string $type 'admin' or 'personal'
154
-	 * @param string $section
155
-	 * @param Closure $filter optional filter to apply on all loaded ISettings
156
-	 *
157
-	 * @return ISettings[]
158
-	 */
159
-	protected function getSettings(string $type, string $section, Closure $filter = null): array {
160
-		if (!isset($this->settings[$type])) {
161
-			$this->settings[$type] = [];
162
-		}
163
-		if (!isset($this->settings[$type][$section])) {
164
-			$this->settings[$type][$section] = [];
165
-		}
166
-
167
-		foreach ($this->settingClasses as $class => $settingsType) {
168
-			if ($type !== $settingsType) {
169
-				continue;
170
-			}
171
-
172
-			try {
173
-				/** @var ISettings $setting */
174
-				$setting = \OC::$server->query($class);
175
-			} catch (QueryException $e) {
176
-				$this->log->logException($e, ['level' => ILogger::INFO]);
177
-				continue;
178
-			}
179
-
180
-			if (!$setting instanceof ISettings) {
181
-				$this->log->logException(new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'), ['level' => ILogger::INFO]);
182
-				continue;
183
-			}
184
-
185
-			if ($filter !== null && !$filter($setting)) {
186
-				continue;
187
-			}
188
-			if ($setting->getSection() === null) {
189
-				continue;
190
-			}
191
-
192
-			if (!isset($this->settings[$settingsType][$setting->getSection()])) {
193
-				$this->settings[$settingsType][$setting->getSection()] = [];
194
-			}
195
-			$this->settings[$settingsType][$setting->getSection()][] = $setting;
196
-
197
-			unset($this->settingClasses[$class]);
198
-		}
199
-
200
-		return $this->settings[$type][$section];
201
-	}
202
-
203
-	/**
204
-	 * @inheritdoc
205
-	 */
206
-	public function getAdminSections(): array {
207
-		if ($this->l === null) {
208
-			$this->l = $this->l10nFactory->get('lib');
209
-		}
210
-
211
-		// built-in sections
212
-		$sections = [
213
-			0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))],
214
-			1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
215
-			5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
216
-			10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
217
-			50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))],
218
-			98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
219
-		];
220
-
221
-		$appSections = $this->getSections('admin');
222
-
223
-		foreach ($appSections as $section) {
224
-			/** @var ISection $section */
225
-			if (!isset($sections[$section->getPriority()])) {
226
-				$sections[$section->getPriority()] = [];
227
-			}
228
-
229
-			$sections[$section->getPriority()][] = $section;
230
-		}
231
-
232
-		ksort($sections);
233
-
234
-		return $sections;
235
-	}
236
-
237
-	/**
238
-	 * @param string $section
239
-	 * @param Closure $filter
240
-	 *
241
-	 * @return ISection[]
242
-	 */
243
-	private function getBuiltInAdminSettings($section, Closure $filter = null): array {
244
-		$forms = [];
245
-
246
-		if ($section === 'overview') {
247
-			/** @var ISettings $form */
248
-			$form = $this->container->query(Admin\Overview::class);
249
-			if ($filter === null || $filter($form)) {
250
-				$forms[$form->getPriority()] = [$form];
251
-			}
252
-		}
253
-		if ($section === 'server') {
254
-			/** @var ISettings $form */
255
-			$form = $this->container->query(Admin\Server::class);
256
-			if ($filter === null || $filter($form)) {
257
-				$forms[$form->getPriority()] = [$form];
258
-			}
259
-			$form = $this->container->query(Admin\Mail::class);
260
-			if ($filter === null || $filter($form)) {
261
-				$forms[$form->getPriority()] = [$form];
262
-			}
263
-		}
264
-		if ($section === 'security') {
265
-			/** @var ISettings $form */
266
-			$form = $this->container->query(Admin\Security::class);
267
-			if ($filter === null || $filter($form)) {
268
-				$forms[$form->getPriority()] = [$form];
269
-			}
270
-		}
271
-		if ($section === 'sharing') {
272
-			/** @var ISettings $form */
273
-			$form = $this->container->query(Admin\Sharing::class);
274
-			if ($filter === null || $filter($form)) {
275
-				$forms[$form->getPriority()] = [$form];
276
-			}
277
-		}
278
-
279
-		return $forms;
280
-	}
281
-
282
-	/**
283
-	 * @param string $section
284
-	 *
285
-	 * @return ISection[]
286
-	 */
287
-	private function getBuiltInPersonalSettings($section): array {
288
-		$forms = [];
289
-
290
-		if ($section === 'personal-info') {
291
-			/** @var ISettings $form */
292
-			$form = $this->container->query(Personal\PersonalInfo::class);
293
-			$forms[$form->getPriority()] = [$form];
294
-			$form = new Personal\ServerDevNotice();
295
-			$forms[$form->getPriority()] = [$form];
296
-		}
297
-		if ($section === 'security') {
298
-			/** @var ISettings $form */
299
-			$form = $this->container->query(Personal\Security::class);
300
-			$forms[$form->getPriority()] = [$form];
301
-		}
302
-		if ($section === 'additional') {
303
-			/** @var ISettings $form */
304
-			$form = $this->container->query(Personal\Additional::class);
305
-			$forms[$form->getPriority()] = [$form];
306
-		}
307
-
308
-		return $forms;
309
-	}
310
-
311
-	/**
312
-	 * @inheritdoc
313
-	 */
314
-	public function getAdminSettings($section, bool $subAdminOnly = false): array {
315
-		if ($subAdminOnly) {
316
-			$subAdminSettingsFilter = function(ISettings $settings) {
317
-				return $settings instanceof ISubAdminSettings;
318
-			};
319
-			$settings = $this->getBuiltInAdminSettings($section, $subAdminSettingsFilter);
320
-			$appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter);
321
-		} else {
322
-			$settings = $this->getBuiltInAdminSettings($section);
323
-			$appSettings = $this->getSettings('admin', $section);
324
-		}
325
-
326
-		foreach ($appSettings as $setting) {
327
-			if (!isset($settings[$setting->getPriority()])) {
328
-				$settings[$setting->getPriority()] = [];
329
-			}
330
-			$settings[$setting->getPriority()][] = $setting;
331
-		}
332
-
333
-		ksort($settings);
334
-		return $settings;
335
-	}
336
-
337
-	/**
338
-	 * @inheritdoc
339
-	 */
340
-	public function getPersonalSections(): array {
341
-		if ($this->l === null) {
342
-			$this->l = $this->l10nFactory->get('lib');
343
-		}
344
-
345
-		$sections = [
346
-			0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
347
-			5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
348
-			15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))],
349
-		];
350
-
351
-		$legacyForms = \OC_App::getForms('personal');
352
-		if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
353
-			$sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
354
-		}
355
-
356
-		$appSections = $this->getSections('personal');
357
-
358
-		foreach ($appSections as $section) {
359
-			/** @var ISection $section */
360
-			if (!isset($sections[$section->getPriority()])) {
361
-				$sections[$section->getPriority()] = [];
362
-			}
363
-
364
-			$sections[$section->getPriority()][] = $section;
365
-		}
366
-
367
-		ksort($sections);
368
-
369
-		return $sections;
370
-	}
371
-
372
-	/**
373
-	 * @param string[] $forms
374
-	 *
375
-	 * @return bool
376
-	 */
377
-	private function hasLegacyPersonalSettingsToRender(array $forms): bool {
378
-		foreach ($forms as $form) {
379
-			if (trim($form) !== '') {
380
-				return true;
381
-			}
382
-		}
383
-		return false;
384
-	}
385
-
386
-	/**
387
-	 * @inheritdoc
388
-	 */
389
-	public function getPersonalSettings($section): array {
390
-		$settings = $this->getBuiltInPersonalSettings($section);
391
-		$appSettings = $this->getSettings('personal', $section);
392
-
393
-		foreach ($appSettings as $setting) {
394
-			if (!isset($settings[$setting->getPriority()])) {
395
-				$settings[$setting->getPriority()] = [];
396
-			}
397
-			$settings[$setting->getPriority()][] = $setting;
398
-		}
399
-
400
-		ksort($settings);
401
-		return $settings;
402
-	}
46
+    /** @var ILogger */
47
+    private $log;
48
+
49
+    /** @var IL10N */
50
+    private $l;
51
+
52
+    /** @var IFactory */
53
+    private $l10nFactory;
54
+
55
+    /** @var IURLGenerator */
56
+    private $url;
57
+
58
+    /** @var IServerContainer */
59
+    private $container;
60
+
61
+    public function __construct(
62
+        ILogger $log,
63
+        IFactory $l10nFactory,
64
+        IURLGenerator $url,
65
+        IServerContainer $container
66
+    ) {
67
+        $this->log = $log;
68
+        $this->l10nFactory = $l10nFactory;
69
+        $this->url = $url;
70
+        $this->container = $container;
71
+    }
72
+
73
+    /** @var array */
74
+    protected $sectionClasses = [];
75
+
76
+    /** @var array */
77
+    protected $sections = [];
78
+
79
+    /**
80
+     * @param string $type 'admin' or 'personal'
81
+     * @param string $section Class must implement OCP\Settings\ISection
82
+     *
83
+     * @return void
84
+     */
85
+    public function registerSection(string $type, string $section) {
86
+        if (!isset($this->sectionClasses[$type])) {
87
+            $this->sectionClasses[$type] = [];
88
+        }
89
+
90
+        $this->sectionClasses[$type][] = $section;
91
+    }
92
+
93
+    /**
94
+     * @param string $type 'admin' or 'personal'
95
+     *
96
+     * @return ISection[]
97
+     */
98
+    protected function getSections(string $type): array {
99
+        if (!isset($this->sections[$type])) {
100
+            $this->sections[$type] = [];
101
+        }
102
+
103
+        if (!isset($this->sectionClasses[$type])) {
104
+            return $this->sections[$type];
105
+        }
106
+
107
+        foreach ($this->sectionClasses[$type] as $index => $class) {
108
+            try {
109
+                /** @var ISection $section */
110
+                $section = \OC::$server->query($class);
111
+            } catch (QueryException $e) {
112
+                $this->log->logException($e, ['level' => ILogger::INFO]);
113
+                continue;
114
+            }
115
+
116
+            if (!$section instanceof ISection) {
117
+                $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]);
118
+                continue;
119
+            }
120
+
121
+            $sectionID = $section->getID();
122
+
123
+            if (isset($this->sections[$type][$sectionID])) {
124
+                $this->log->logException(new \InvalidArgumentException('Section with the same ID already registered'), ['level' => ILogger::INFO]);
125
+                continue;
126
+            }
127
+
128
+            $this->sections[$type][$sectionID] = $section;
129
+
130
+            unset($this->sectionClasses[$type][$index]);
131
+        }
132
+
133
+        return $this->sections[$type];
134
+    }
135
+
136
+    /** @var array */
137
+    protected $settingClasses = [];
138
+
139
+    /** @var array */
140
+    protected $settings = [];
141
+
142
+    /**
143
+     * @param string $type 'admin' or 'personal'
144
+     * @param string $setting Class must implement OCP\Settings\ISetting
145
+     *
146
+     * @return void
147
+     */
148
+    public function registerSetting(string $type, string $setting) {
149
+        $this->settingClasses[$setting] = $type;
150
+    }
151
+
152
+    /**
153
+     * @param string $type 'admin' or 'personal'
154
+     * @param string $section
155
+     * @param Closure $filter optional filter to apply on all loaded ISettings
156
+     *
157
+     * @return ISettings[]
158
+     */
159
+    protected function getSettings(string $type, string $section, Closure $filter = null): array {
160
+        if (!isset($this->settings[$type])) {
161
+            $this->settings[$type] = [];
162
+        }
163
+        if (!isset($this->settings[$type][$section])) {
164
+            $this->settings[$type][$section] = [];
165
+        }
166
+
167
+        foreach ($this->settingClasses as $class => $settingsType) {
168
+            if ($type !== $settingsType) {
169
+                continue;
170
+            }
171
+
172
+            try {
173
+                /** @var ISettings $setting */
174
+                $setting = \OC::$server->query($class);
175
+            } catch (QueryException $e) {
176
+                $this->log->logException($e, ['level' => ILogger::INFO]);
177
+                continue;
178
+            }
179
+
180
+            if (!$setting instanceof ISettings) {
181
+                $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered (' . $class . ')'), ['level' => ILogger::INFO]);
182
+                continue;
183
+            }
184
+
185
+            if ($filter !== null && !$filter($setting)) {
186
+                continue;
187
+            }
188
+            if ($setting->getSection() === null) {
189
+                continue;
190
+            }
191
+
192
+            if (!isset($this->settings[$settingsType][$setting->getSection()])) {
193
+                $this->settings[$settingsType][$setting->getSection()] = [];
194
+            }
195
+            $this->settings[$settingsType][$setting->getSection()][] = $setting;
196
+
197
+            unset($this->settingClasses[$class]);
198
+        }
199
+
200
+        return $this->settings[$type][$section];
201
+    }
202
+
203
+    /**
204
+     * @inheritdoc
205
+     */
206
+    public function getAdminSections(): array {
207
+        if ($this->l === null) {
208
+            $this->l = $this->l10nFactory->get('lib');
209
+        }
210
+
211
+        // built-in sections
212
+        $sections = [
213
+            0 => [new Section('overview', $this->l->t('Overview'), 0, $this->url->imagePath('settings', 'admin.svg'))],
214
+            1 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
215
+            5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))],
216
+            10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))],
217
+            50 => [new Section('groupware', $this->l->t('Groupware'), 0, $this->url->imagePath('core', 'places/contacts.svg'))],
218
+            98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))],
219
+        ];
220
+
221
+        $appSections = $this->getSections('admin');
222
+
223
+        foreach ($appSections as $section) {
224
+            /** @var ISection $section */
225
+            if (!isset($sections[$section->getPriority()])) {
226
+                $sections[$section->getPriority()] = [];
227
+            }
228
+
229
+            $sections[$section->getPriority()][] = $section;
230
+        }
231
+
232
+        ksort($sections);
233
+
234
+        return $sections;
235
+    }
236
+
237
+    /**
238
+     * @param string $section
239
+     * @param Closure $filter
240
+     *
241
+     * @return ISection[]
242
+     */
243
+    private function getBuiltInAdminSettings($section, Closure $filter = null): array {
244
+        $forms = [];
245
+
246
+        if ($section === 'overview') {
247
+            /** @var ISettings $form */
248
+            $form = $this->container->query(Admin\Overview::class);
249
+            if ($filter === null || $filter($form)) {
250
+                $forms[$form->getPriority()] = [$form];
251
+            }
252
+        }
253
+        if ($section === 'server') {
254
+            /** @var ISettings $form */
255
+            $form = $this->container->query(Admin\Server::class);
256
+            if ($filter === null || $filter($form)) {
257
+                $forms[$form->getPriority()] = [$form];
258
+            }
259
+            $form = $this->container->query(Admin\Mail::class);
260
+            if ($filter === null || $filter($form)) {
261
+                $forms[$form->getPriority()] = [$form];
262
+            }
263
+        }
264
+        if ($section === 'security') {
265
+            /** @var ISettings $form */
266
+            $form = $this->container->query(Admin\Security::class);
267
+            if ($filter === null || $filter($form)) {
268
+                $forms[$form->getPriority()] = [$form];
269
+            }
270
+        }
271
+        if ($section === 'sharing') {
272
+            /** @var ISettings $form */
273
+            $form = $this->container->query(Admin\Sharing::class);
274
+            if ($filter === null || $filter($form)) {
275
+                $forms[$form->getPriority()] = [$form];
276
+            }
277
+        }
278
+
279
+        return $forms;
280
+    }
281
+
282
+    /**
283
+     * @param string $section
284
+     *
285
+     * @return ISection[]
286
+     */
287
+    private function getBuiltInPersonalSettings($section): array {
288
+        $forms = [];
289
+
290
+        if ($section === 'personal-info') {
291
+            /** @var ISettings $form */
292
+            $form = $this->container->query(Personal\PersonalInfo::class);
293
+            $forms[$form->getPriority()] = [$form];
294
+            $form = new Personal\ServerDevNotice();
295
+            $forms[$form->getPriority()] = [$form];
296
+        }
297
+        if ($section === 'security') {
298
+            /** @var ISettings $form */
299
+            $form = $this->container->query(Personal\Security::class);
300
+            $forms[$form->getPriority()] = [$form];
301
+        }
302
+        if ($section === 'additional') {
303
+            /** @var ISettings $form */
304
+            $form = $this->container->query(Personal\Additional::class);
305
+            $forms[$form->getPriority()] = [$form];
306
+        }
307
+
308
+        return $forms;
309
+    }
310
+
311
+    /**
312
+     * @inheritdoc
313
+     */
314
+    public function getAdminSettings($section, bool $subAdminOnly = false): array {
315
+        if ($subAdminOnly) {
316
+            $subAdminSettingsFilter = function(ISettings $settings) {
317
+                return $settings instanceof ISubAdminSettings;
318
+            };
319
+            $settings = $this->getBuiltInAdminSettings($section, $subAdminSettingsFilter);
320
+            $appSettings = $this->getSettings('admin', $section, $subAdminSettingsFilter);
321
+        } else {
322
+            $settings = $this->getBuiltInAdminSettings($section);
323
+            $appSettings = $this->getSettings('admin', $section);
324
+        }
325
+
326
+        foreach ($appSettings as $setting) {
327
+            if (!isset($settings[$setting->getPriority()])) {
328
+                $settings[$setting->getPriority()] = [];
329
+            }
330
+            $settings[$setting->getPriority()][] = $setting;
331
+        }
332
+
333
+        ksort($settings);
334
+        return $settings;
335
+    }
336
+
337
+    /**
338
+     * @inheritdoc
339
+     */
340
+    public function getPersonalSections(): array {
341
+        if ($this->l === null) {
342
+            $this->l = $this->l10nFactory->get('lib');
343
+        }
344
+
345
+        $sections = [
346
+            0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))],
347
+            5 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('settings', 'password.svg'))],
348
+            15 => [new Section('sync-clients', $this->l->t('Mobile & desktop'), 0, $this->url->imagePath('core', 'clients/phone.svg'))],
349
+        ];
350
+
351
+        $legacyForms = \OC_App::getForms('personal');
352
+        if (!empty($legacyForms) && $this->hasLegacyPersonalSettingsToRender($legacyForms)) {
353
+            $sections[98] = [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))];
354
+        }
355
+
356
+        $appSections = $this->getSections('personal');
357
+
358
+        foreach ($appSections as $section) {
359
+            /** @var ISection $section */
360
+            if (!isset($sections[$section->getPriority()])) {
361
+                $sections[$section->getPriority()] = [];
362
+            }
363
+
364
+            $sections[$section->getPriority()][] = $section;
365
+        }
366
+
367
+        ksort($sections);
368
+
369
+        return $sections;
370
+    }
371
+
372
+    /**
373
+     * @param string[] $forms
374
+     *
375
+     * @return bool
376
+     */
377
+    private function hasLegacyPersonalSettingsToRender(array $forms): bool {
378
+        foreach ($forms as $form) {
379
+            if (trim($form) !== '') {
380
+                return true;
381
+            }
382
+        }
383
+        return false;
384
+    }
385
+
386
+    /**
387
+     * @inheritdoc
388
+     */
389
+    public function getPersonalSettings($section): array {
390
+        $settings = $this->getBuiltInPersonalSettings($section);
391
+        $appSettings = $this->getSettings('personal', $section);
392
+
393
+        foreach ($appSettings as $setting) {
394
+            if (!isset($settings[$setting->getPriority()])) {
395
+                $settings[$setting->getPriority()] = [];
396
+            }
397
+            $settings[$setting->getPriority()][] = $setting;
398
+        }
399
+
400
+        ksort($settings);
401
+        return $settings;
402
+    }
403 403
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/Security/SecurityMiddleware.php 2 patches
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -66,109 +66,109 @@  discard block
 block discarded – undo
66 66
  * check fails
67 67
  */
68 68
 class SecurityMiddleware extends Middleware {
69
-	/** @var INavigationManager */
70
-	private $navigationManager;
71
-	/** @var IRequest */
72
-	private $request;
73
-	/** @var ControllerMethodReflector */
74
-	private $reflector;
75
-	/** @var string */
76
-	private $appName;
77
-	/** @var IURLGenerator */
78
-	private $urlGenerator;
79
-	/** @var ILogger */
80
-	private $logger;
81
-	/** @var bool */
82
-	private $isLoggedIn;
83
-	/** @var bool */
84
-	private $isAdminUser;
85
-	/** @var bool */
86
-	private $isSubAdmin;
87
-	/** @var ContentSecurityPolicyManager */
88
-	private $contentSecurityPolicyManager;
89
-	/** @var CsrfTokenManager */
90
-	private $csrfTokenManager;
91
-	/** @var ContentSecurityPolicyNonceManager */
92
-	private $cspNonceManager;
93
-	/** @var IAppManager */
94
-	private $appManager;
95
-	/** @var IL10N */
96
-	private $l10n;
69
+    /** @var INavigationManager */
70
+    private $navigationManager;
71
+    /** @var IRequest */
72
+    private $request;
73
+    /** @var ControllerMethodReflector */
74
+    private $reflector;
75
+    /** @var string */
76
+    private $appName;
77
+    /** @var IURLGenerator */
78
+    private $urlGenerator;
79
+    /** @var ILogger */
80
+    private $logger;
81
+    /** @var bool */
82
+    private $isLoggedIn;
83
+    /** @var bool */
84
+    private $isAdminUser;
85
+    /** @var bool */
86
+    private $isSubAdmin;
87
+    /** @var ContentSecurityPolicyManager */
88
+    private $contentSecurityPolicyManager;
89
+    /** @var CsrfTokenManager */
90
+    private $csrfTokenManager;
91
+    /** @var ContentSecurityPolicyNonceManager */
92
+    private $cspNonceManager;
93
+    /** @var IAppManager */
94
+    private $appManager;
95
+    /** @var IL10N */
96
+    private $l10n;
97 97
 
98
-	public function __construct(IRequest $request,
99
-								ControllerMethodReflector $reflector,
100
-								INavigationManager $navigationManager,
101
-								IURLGenerator $urlGenerator,
102
-								ILogger $logger,
103
-								string $appName,
104
-								bool $isLoggedIn,
105
-								bool $isAdminUser,
106
-								bool $isSubAdmin,
107
-								ContentSecurityPolicyManager $contentSecurityPolicyManager,
108
-								CsrfTokenManager $csrfTokenManager,
109
-								ContentSecurityPolicyNonceManager $cspNonceManager,
110
-								IAppManager $appManager,
111
-								IL10N $l10n
112
-	) {
113
-		$this->navigationManager = $navigationManager;
114
-		$this->request = $request;
115
-		$this->reflector = $reflector;
116
-		$this->appName = $appName;
117
-		$this->urlGenerator = $urlGenerator;
118
-		$this->logger = $logger;
119
-		$this->isLoggedIn = $isLoggedIn;
120
-		$this->isAdminUser = $isAdminUser;
121
-		$this->isSubAdmin = $isSubAdmin;
122
-		$this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
123
-		$this->csrfTokenManager = $csrfTokenManager;
124
-		$this->cspNonceManager = $cspNonceManager;
125
-		$this->appManager = $appManager;
126
-		$this->l10n = $l10n;
127
-	}
98
+    public function __construct(IRequest $request,
99
+                                ControllerMethodReflector $reflector,
100
+                                INavigationManager $navigationManager,
101
+                                IURLGenerator $urlGenerator,
102
+                                ILogger $logger,
103
+                                string $appName,
104
+                                bool $isLoggedIn,
105
+                                bool $isAdminUser,
106
+                                bool $isSubAdmin,
107
+                                ContentSecurityPolicyManager $contentSecurityPolicyManager,
108
+                                CsrfTokenManager $csrfTokenManager,
109
+                                ContentSecurityPolicyNonceManager $cspNonceManager,
110
+                                IAppManager $appManager,
111
+                                IL10N $l10n
112
+    ) {
113
+        $this->navigationManager = $navigationManager;
114
+        $this->request = $request;
115
+        $this->reflector = $reflector;
116
+        $this->appName = $appName;
117
+        $this->urlGenerator = $urlGenerator;
118
+        $this->logger = $logger;
119
+        $this->isLoggedIn = $isLoggedIn;
120
+        $this->isAdminUser = $isAdminUser;
121
+        $this->isSubAdmin = $isSubAdmin;
122
+        $this->contentSecurityPolicyManager = $contentSecurityPolicyManager;
123
+        $this->csrfTokenManager = $csrfTokenManager;
124
+        $this->cspNonceManager = $cspNonceManager;
125
+        $this->appManager = $appManager;
126
+        $this->l10n = $l10n;
127
+    }
128 128
 
129
-	/**
130
-	 * This runs all the security checks before a method call. The
131
-	 * security checks are determined by inspecting the controller method
132
-	 * annotations
133
-	 * @param Controller $controller the controller
134
-	 * @param string $methodName the name of the method
135
-	 * @throws SecurityException when a security check fails
136
-	 */
137
-	public function beforeController($controller, $methodName) {
129
+    /**
130
+     * This runs all the security checks before a method call. The
131
+     * security checks are determined by inspecting the controller method
132
+     * annotations
133
+     * @param Controller $controller the controller
134
+     * @param string $methodName the name of the method
135
+     * @throws SecurityException when a security check fails
136
+     */
137
+    public function beforeController($controller, $methodName) {
138 138
 
139
-		// this will set the current navigation entry of the app, use this only
140
-		// for normal HTML requests and not for AJAX requests
141
-		$this->navigationManager->setActiveEntry($this->appName);
139
+        // this will set the current navigation entry of the app, use this only
140
+        // for normal HTML requests and not for AJAX requests
141
+        $this->navigationManager->setActiveEntry($this->appName);
142 142
 
143
-		// security checks
144
-		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
145
-		if(!$isPublicPage) {
146
-			if(!$this->isLoggedIn) {
147
-				throw new NotLoggedInException();
148
-			}
143
+        // security checks
144
+        $isPublicPage = $this->reflector->hasAnnotation('PublicPage');
145
+        if(!$isPublicPage) {
146
+            if(!$this->isLoggedIn) {
147
+                throw new NotLoggedInException();
148
+            }
149 149
 
150
-			if($this->reflector->hasAnnotation('SubAdminRequired')
151
-				&& !$this->isSubAdmin
152
-				&& !$this->isAdminUser) {
153
-				throw new NotAdminException($this->l10n->t('Logged in user must be an admin or sub admin'));
154
-			}
155
-			if(!$this->reflector->hasAnnotation('SubAdminRequired')
156
-				&& !$this->reflector->hasAnnotation('NoAdminRequired')
157
-				&& !$this->isAdminUser) {
158
-				throw new NotAdminException($this->l10n->t('Logged in user must be an admin'));
159
-			}
160
-		}
150
+            if($this->reflector->hasAnnotation('SubAdminRequired')
151
+                && !$this->isSubAdmin
152
+                && !$this->isAdminUser) {
153
+                throw new NotAdminException($this->l10n->t('Logged in user must be an admin or sub admin'));
154
+            }
155
+            if(!$this->reflector->hasAnnotation('SubAdminRequired')
156
+                && !$this->reflector->hasAnnotation('NoAdminRequired')
157
+                && !$this->isAdminUser) {
158
+                throw new NotAdminException($this->l10n->t('Logged in user must be an admin'));
159
+            }
160
+        }
161 161
 
162
-		// Check for strict cookie requirement
163
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
164
-			if(!$this->request->passesStrictCookieCheck()) {
165
-				throw new StrictCookieMissingException();
166
-			}
167
-		}
168
-		// CSRF check - also registers the CSRF token since the session may be closed later
169
-		Util::callRegister();
170
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
171
-			/*
162
+        // Check for strict cookie requirement
163
+        if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
164
+            if(!$this->request->passesStrictCookieCheck()) {
165
+                throw new StrictCookieMissingException();
166
+            }
167
+        }
168
+        // CSRF check - also registers the CSRF token since the session may be closed later
169
+        Util::callRegister();
170
+        if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
171
+            /*
172 172
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
173 173
 			 * hacks around that we have no full token auth in place yet and we
174 174
 			 * do want to offer CSRF checks for web requests.
@@ -176,103 +176,103 @@  discard block
 block discarded – undo
176 176
 			 * Additionally we allow Bearer authenticated requests to pass on OCS routes.
177 177
 			 * This allows oauth apps (e.g. moodle) to use the OCS endpoints
178 178
 			 */
179
-			if(!$this->request->passesCSRFCheck() && !(
180
-					$controller instanceof OCSController && (
181
-						$this->request->getHeader('OCS-APIREQUEST') === 'true' ||
182
-						strpos($this->request->getHeader('Authorization'), 'Bearer ') === 0
183
-					)
184
-				)) {
185
-				throw new CrossSiteRequestForgeryException();
186
-			}
187
-		}
179
+            if(!$this->request->passesCSRFCheck() && !(
180
+                    $controller instanceof OCSController && (
181
+                        $this->request->getHeader('OCS-APIREQUEST') === 'true' ||
182
+                        strpos($this->request->getHeader('Authorization'), 'Bearer ') === 0
183
+                    )
184
+                )) {
185
+                throw new CrossSiteRequestForgeryException();
186
+            }
187
+        }
188 188
 
189
-		/**
190
-		 * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
191
-		 * The getAppPath() check is here since components such as settings also use the AppFramework and
192
-		 * therefore won't pass this check.
193
-		 * If page is public, app does not need to be enabled for current user/visitor
194
-		 */
195
-		try {
196
-			$appPath = $this->appManager->getAppPath($this->appName);
197
-		} catch (AppPathNotFoundException $e) {
198
-			$appPath = false;
199
-		}
189
+        /**
190
+         * Checks if app is enabled (also includes a check whether user is allowed to access the resource)
191
+         * The getAppPath() check is here since components such as settings also use the AppFramework and
192
+         * therefore won't pass this check.
193
+         * If page is public, app does not need to be enabled for current user/visitor
194
+         */
195
+        try {
196
+            $appPath = $this->appManager->getAppPath($this->appName);
197
+        } catch (AppPathNotFoundException $e) {
198
+            $appPath = false;
199
+        }
200 200
 
201
-		if ($appPath !== false && !$isPublicPage && !$this->appManager->isEnabledForUser($this->appName)) {
202
-			throw new AppNotEnabledException();
203
-		}
204
-	}
201
+        if ($appPath !== false && !$isPublicPage && !$this->appManager->isEnabledForUser($this->appName)) {
202
+            throw new AppNotEnabledException();
203
+        }
204
+    }
205 205
 
206
-	/**
207
-	 * Performs the default CSP modifications that may be injected by other
208
-	 * applications
209
-	 *
210
-	 * @param Controller $controller
211
-	 * @param string $methodName
212
-	 * @param Response $response
213
-	 * @return Response
214
-	 */
215
-	public function afterController($controller, $methodName, Response $response): Response {
216
-		$policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
206
+    /**
207
+     * Performs the default CSP modifications that may be injected by other
208
+     * applications
209
+     *
210
+     * @param Controller $controller
211
+     * @param string $methodName
212
+     * @param Response $response
213
+     * @return Response
214
+     */
215
+    public function afterController($controller, $methodName, Response $response): Response {
216
+        $policy = !is_null($response->getContentSecurityPolicy()) ? $response->getContentSecurityPolicy() : new ContentSecurityPolicy();
217 217
 
218
-		if (get_class($policy) === EmptyContentSecurityPolicy::class) {
219
-			return $response;
220
-		}
218
+        if (get_class($policy) === EmptyContentSecurityPolicy::class) {
219
+            return $response;
220
+        }
221 221
 
222
-		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
223
-		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
222
+        $defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
223
+        $defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
224 224
 
225
-		if($this->cspNonceManager->browserSupportsCspV3()) {
226
-			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
227
-		}
225
+        if($this->cspNonceManager->browserSupportsCspV3()) {
226
+            $defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
227
+        }
228 228
 
229
-		$response->setContentSecurityPolicy($defaultPolicy);
229
+        $response->setContentSecurityPolicy($defaultPolicy);
230 230
 
231
-		return $response;
232
-	}
231
+        return $response;
232
+    }
233 233
 
234
-	/**
235
-	 * If an SecurityException is being caught, ajax requests return a JSON error
236
-	 * response and non ajax requests redirect to the index
237
-	 * @param Controller $controller the controller that is being called
238
-	 * @param string $methodName the name of the method that will be called on
239
-	 *                           the controller
240
-	 * @param \Exception $exception the thrown exception
241
-	 * @throws \Exception the passed in exception if it can't handle it
242
-	 * @return Response a Response object or null in case that the exception could not be handled
243
-	 */
244
-	public function afterException($controller, $methodName, \Exception $exception): Response {
245
-		if($exception instanceof SecurityException) {
246
-			if($exception instanceof StrictCookieMissingException) {
247
-				return new RedirectResponse(\OC::$WEBROOT);
248
- 			}
249
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
250
-				$response = new JSONResponse(
251
-					['message' => $exception->getMessage()],
252
-					$exception->getCode()
253
-				);
254
-			} else {
255
-				if($exception instanceof NotLoggedInException) {
256
-					$params = [];
257
-					if (isset($this->request->server['REQUEST_URI'])) {
258
-						$params['redirect_url'] = $this->request->server['REQUEST_URI'];
259
-					}
260
-					$url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
261
-					$response = new RedirectResponse($url);
262
-				} else {
263
-					$response = new TemplateResponse('core', '403', ['message' => $exception->getMessage()], 'guest');
264
-					$response->setStatus($exception->getCode());
265
-				}
266
-			}
234
+    /**
235
+     * If an SecurityException is being caught, ajax requests return a JSON error
236
+     * response and non ajax requests redirect to the index
237
+     * @param Controller $controller the controller that is being called
238
+     * @param string $methodName the name of the method that will be called on
239
+     *                           the controller
240
+     * @param \Exception $exception the thrown exception
241
+     * @throws \Exception the passed in exception if it can't handle it
242
+     * @return Response a Response object or null in case that the exception could not be handled
243
+     */
244
+    public function afterException($controller, $methodName, \Exception $exception): Response {
245
+        if($exception instanceof SecurityException) {
246
+            if($exception instanceof StrictCookieMissingException) {
247
+                return new RedirectResponse(\OC::$WEBROOT);
248
+                }
249
+            if (stripos($this->request->getHeader('Accept'),'html') === false) {
250
+                $response = new JSONResponse(
251
+                    ['message' => $exception->getMessage()],
252
+                    $exception->getCode()
253
+                );
254
+            } else {
255
+                if($exception instanceof NotLoggedInException) {
256
+                    $params = [];
257
+                    if (isset($this->request->server['REQUEST_URI'])) {
258
+                        $params['redirect_url'] = $this->request->server['REQUEST_URI'];
259
+                    }
260
+                    $url = $this->urlGenerator->linkToRoute('core.login.showLoginForm', $params);
261
+                    $response = new RedirectResponse($url);
262
+                } else {
263
+                    $response = new TemplateResponse('core', '403', ['message' => $exception->getMessage()], 'guest');
264
+                    $response->setStatus($exception->getCode());
265
+                }
266
+            }
267 267
 
268
-			$this->logger->logException($exception, [
269
-				'level' => ILogger::DEBUG,
270
-				'app' => 'core',
271
-			]);
272
-			return $response;
273
-		}
268
+            $this->logger->logException($exception, [
269
+                'level' => ILogger::DEBUG,
270
+                'app' => 'core',
271
+            ]);
272
+            return $response;
273
+        }
274 274
 
275
-		throw $exception;
276
-	}
275
+        throw $exception;
276
+    }
277 277
 
278 278
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -142,17 +142,17 @@  discard block
 block discarded – undo
142 142
 
143 143
 		// security checks
144 144
 		$isPublicPage = $this->reflector->hasAnnotation('PublicPage');
145
-		if(!$isPublicPage) {
146
-			if(!$this->isLoggedIn) {
145
+		if (!$isPublicPage) {
146
+			if (!$this->isLoggedIn) {
147 147
 				throw new NotLoggedInException();
148 148
 			}
149 149
 
150
-			if($this->reflector->hasAnnotation('SubAdminRequired')
150
+			if ($this->reflector->hasAnnotation('SubAdminRequired')
151 151
 				&& !$this->isSubAdmin
152 152
 				&& !$this->isAdminUser) {
153 153
 				throw new NotAdminException($this->l10n->t('Logged in user must be an admin or sub admin'));
154 154
 			}
155
-			if(!$this->reflector->hasAnnotation('SubAdminRequired')
155
+			if (!$this->reflector->hasAnnotation('SubAdminRequired')
156 156
 				&& !$this->reflector->hasAnnotation('NoAdminRequired')
157 157
 				&& !$this->isAdminUser) {
158 158
 				throw new NotAdminException($this->l10n->t('Logged in user must be an admin'));
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
 		}
161 161
 
162 162
 		// Check for strict cookie requirement
163
-		if($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
164
-			if(!$this->request->passesStrictCookieCheck()) {
163
+		if ($this->reflector->hasAnnotation('StrictCookieRequired') || !$this->reflector->hasAnnotation('NoCSRFRequired')) {
164
+			if (!$this->request->passesStrictCookieCheck()) {
165 165
 				throw new StrictCookieMissingException();
166 166
 			}
167 167
 		}
168 168
 		// CSRF check - also registers the CSRF token since the session may be closed later
169 169
 		Util::callRegister();
170
-		if(!$this->reflector->hasAnnotation('NoCSRFRequired')) {
170
+		if (!$this->reflector->hasAnnotation('NoCSRFRequired')) {
171 171
 			/*
172 172
 			 * Only allow the CSRF check to fail on OCS Requests. This kind of
173 173
 			 * hacks around that we have no full token auth in place yet and we
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
 			 * Additionally we allow Bearer authenticated requests to pass on OCS routes.
177 177
 			 * This allows oauth apps (e.g. moodle) to use the OCS endpoints
178 178
 			 */
179
-			if(!$this->request->passesCSRFCheck() && !(
179
+			if (!$this->request->passesCSRFCheck() && !(
180 180
 					$controller instanceof OCSController && (
181 181
 						$this->request->getHeader('OCS-APIREQUEST') === 'true' ||
182 182
 						strpos($this->request->getHeader('Authorization'), 'Bearer ') === 0
@@ -222,7 +222,7 @@  discard block
 block discarded – undo
222 222
 		$defaultPolicy = $this->contentSecurityPolicyManager->getDefaultPolicy();
223 223
 		$defaultPolicy = $this->contentSecurityPolicyManager->mergePolicies($defaultPolicy, $policy);
224 224
 
225
-		if($this->cspNonceManager->browserSupportsCspV3()) {
225
+		if ($this->cspNonceManager->browserSupportsCspV3()) {
226 226
 			$defaultPolicy->useJsNonce($this->csrfTokenManager->getToken()->getEncryptedValue());
227 227
 		}
228 228
 
@@ -242,17 +242,17 @@  discard block
 block discarded – undo
242 242
 	 * @return Response a Response object or null in case that the exception could not be handled
243 243
 	 */
244 244
 	public function afterException($controller, $methodName, \Exception $exception): Response {
245
-		if($exception instanceof SecurityException) {
246
-			if($exception instanceof StrictCookieMissingException) {
245
+		if ($exception instanceof SecurityException) {
246
+			if ($exception instanceof StrictCookieMissingException) {
247 247
 				return new RedirectResponse(\OC::$WEBROOT);
248 248
  			}
249
-			if (stripos($this->request->getHeader('Accept'),'html') === false) {
249
+			if (stripos($this->request->getHeader('Accept'), 'html') === false) {
250 250
 				$response = new JSONResponse(
251 251
 					['message' => $exception->getMessage()],
252 252
 					$exception->getCode()
253 253
 				);
254 254
 			} else {
255
-				if($exception instanceof NotLoggedInException) {
255
+				if ($exception instanceof NotLoggedInException) {
256 256
 					$params = [];
257 257
 					if (isset($this->request->server['REQUEST_URI'])) {
258 258
 						$params['redirect_url'] = $this->request->server['REQUEST_URI'];
Please login to merge, or discard this patch.
lib/private/AppFramework/DependencyInjection/DIContainer.php 1 patch
Indentation   +348 added lines, -348 removed lines patch added patch discarded remove patch
@@ -69,352 +69,352 @@
 block discarded – undo
69 69
 
70 70
 class DIContainer extends SimpleContainer implements IAppContainer {
71 71
 
72
-	/**
73
-	 * @var array
74
-	 */
75
-	private $middleWares = [];
76
-
77
-	/** @var ServerContainer */
78
-	private $server;
79
-
80
-	/**
81
-	 * Put your class dependencies in here
82
-	 * @param string $appName the name of the app
83
-	 * @param array $urlParams
84
-	 * @param ServerContainer|null $server
85
-	 */
86
-	public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
87
-		parent::__construct();
88
-		$this['AppName'] = $appName;
89
-		$this['urlParams'] = $urlParams;
90
-
91
-		$this->registerAlias('Request', IRequest::class);
92
-
93
-		/** @var \OC\ServerContainer $server */
94
-		if ($server === null) {
95
-			$server = \OC::$server;
96
-		}
97
-		$this->server = $server;
98
-		$this->server->registerAppContainer($appName, $this);
99
-
100
-		// aliases
101
-		$this->registerAlias('appName', 'AppName');
102
-		$this->registerAlias('webRoot', 'WebRoot');
103
-		$this->registerAlias('userId', 'UserId');
104
-
105
-		/**
106
-		 * Core services
107
-		 */
108
-		$this->registerService(IOutput::class, function(){
109
-			return new Output($this->getServer()->getWebRoot());
110
-		});
111
-
112
-		$this->registerService(Folder::class, function() {
113
-			return $this->getServer()->getUserFolder();
114
-		});
115
-
116
-		$this->registerService(IAppData::class, function (SimpleContainer $c) {
117
-			return $this->getServer()->getAppDataDir($c->query('AppName'));
118
-		});
119
-
120
-		$this->registerService(IL10N::class, function($c) {
121
-			return $this->getServer()->getL10N($c->query('AppName'));
122
-		});
123
-
124
-		// Log wrapper
125
-		$this->registerService(ILogger::class, function ($c) {
126
-			return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName'));
127
-		});
128
-
129
-		$this->registerService(IServerContainer::class, function () {
130
-			return $this->getServer();
131
-		});
132
-		$this->registerAlias('ServerContainer', IServerContainer::class);
133
-
134
-		$this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
135
-			return $c->query(Manager::class);
136
-		});
137
-
138
-		$this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
139
-			return $c;
140
-		});
141
-
142
-		// commonly used attributes
143
-		$this->registerService('UserId', function ($c) {
144
-			return $c->query(IUserSession::class)->getSession()->get('user_id');
145
-		});
146
-
147
-		$this->registerService('WebRoot', function ($c) {
148
-			return $c->query('ServerContainer')->getWebRoot();
149
-		});
150
-
151
-		$this->registerService('OC_Defaults', function ($c) {
152
-			return $c->getServer()->getThemingDefaults();
153
-		});
154
-
155
-		$this->registerService(IConfig::class, function ($c) {
156
-			return $c->query(OC\GlobalScale\Config::class);
157
-		});
158
-
159
-		$this->registerService('Protocol', function($c){
160
-			/** @var \OC\Server $server */
161
-			$server = $c->query('ServerContainer');
162
-			$protocol = $server->getRequest()->getHttpProtocol();
163
-			return new Http($_SERVER, $protocol);
164
-		});
165
-
166
-		$this->registerService('Dispatcher', function($c) {
167
-			return new Dispatcher(
168
-				$c['Protocol'],
169
-				$c['MiddlewareDispatcher'],
170
-				$c->query(IControllerMethodReflector::class),
171
-				$c['Request']
172
-			);
173
-		});
174
-
175
-		/**
176
-		 * App Framework default arguments
177
-		 */
178
-		$this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
179
-		$this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
180
-		$this->registerParameter('corsMaxAge', 1728000);
181
-
182
-		/**
183
-		 * Middleware
184
-		 */
185
-		$this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) {
186
-			$server =  $this->getServer();
187
-
188
-			$dispatcher = new MiddlewareDispatcher();
189
-			$dispatcher->registerMiddleware(
190
-				$c->query(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class)
191
-			);
192
-
193
-			$dispatcher->registerMiddleware(
194
-				new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
195
-					$c->query(IRequest::class),
196
-					$c->query(IControllerMethodReflector::class)
197
-				)
198
-			);
199
-			$dispatcher->registerMiddleware(
200
-				new CORSMiddleware(
201
-					$c->query(IRequest::class),
202
-					$c->query(IControllerMethodReflector::class),
203
-					$c->query(IUserSession::class),
204
-					$c->query(OC\Security\Bruteforce\Throttler::class)
205
-				)
206
-			);
207
-			$dispatcher->registerMiddleware(
208
-				new OCSMiddleware(
209
-					$c->query(IRequest::class)
210
-				)
211
-			);
212
-
213
-			$securityMiddleware = new SecurityMiddleware(
214
-				$c->query(IRequest::class),
215
-				$c->query(IControllerMethodReflector::class),
216
-				$c->query(INavigationManager::class),
217
-				$c->query(IURLGenerator::class),
218
-				$server->getLogger(),
219
-				$c['AppName'],
220
-				$server->getUserSession()->isLoggedIn(),
221
-				$server->getGroupManager()->isAdmin($this->getUserId()),
222
-				$server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
223
-				$server->getContentSecurityPolicyManager(),
224
-				$server->getCsrfTokenManager(),
225
-				$server->getContentSecurityPolicyNonceManager(),
226
-				$server->getAppManager(),
227
-				$server->getL10N('lib')
228
-			);
229
-			$dispatcher->registerMiddleware($securityMiddleware);
230
-			$dispatcher->registerMiddleware(
231
-				new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware(
232
-					$c->query(IControllerMethodReflector::class),
233
-					$c->query(ISession::class),
234
-					$c->query(IUserSession::class),
235
-					$c->query(ITimeFactory::class)
236
-				)
237
-			);
238
-			$dispatcher->registerMiddleware(
239
-				new TwoFactorMiddleware(
240
-					$c->query(OC\Authentication\TwoFactorAuth\Manager::class),
241
-					$c->query(IUserSession::class),
242
-					$c->query(ISession::class),
243
-					$c->query(IURLGenerator::class),
244
-					$c->query(IControllerMethodReflector::class),
245
-					$c->query(IRequest::class)
246
-				)
247
-			);
248
-			$dispatcher->registerMiddleware(
249
-				new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
250
-					$c->query(IControllerMethodReflector::class),
251
-					$c->query(OC\Security\Bruteforce\Throttler::class),
252
-					$c->query(IRequest::class)
253
-				)
254
-			);
255
-			$dispatcher->registerMiddleware(
256
-				new RateLimitingMiddleware(
257
-					$c->query(IRequest::class),
258
-					$c->query(IUserSession::class),
259
-					$c->query(IControllerMethodReflector::class),
260
-					$c->query(OC\Security\RateLimiting\Limiter::class)
261
-				)
262
-			);
263
-			$dispatcher->registerMiddleware(
264
-				new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware(
265
-					$c->query(IRequest::class),
266
-					$c->query(ISession::class),
267
-					$c->query(\OCP\IConfig::class)
268
-				)
269
-			);
270
-			$dispatcher->registerMiddleware(
271
-				$c->query(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class)
272
-			);
273
-
274
-			foreach($this->middleWares as $middleWare) {
275
-				$dispatcher->registerMiddleware($c[$middleWare]);
276
-			}
277
-
278
-			$dispatcher->registerMiddleware(
279
-				new SessionMiddleware(
280
-					$c->query(IRequest::class),
281
-					$c->query(IControllerMethodReflector::class),
282
-					$c->query(ISession::class)
283
-				)
284
-			);
285
-			return $dispatcher;
286
-		});
287
-
288
-		$this->registerAlias(\OCP\Collaboration\Resources\IManager::class, OC\Collaboration\Resources\Manager::class);
289
-	}
290
-
291
-	/**
292
-	 * @return \OCP\IServerContainer
293
-	 */
294
-	public function getServer()
295
-	{
296
-		return $this->server;
297
-	}
298
-
299
-	/**
300
-	 * @param string $middleWare
301
-	 * @return boolean|null
302
-	 */
303
-	public function registerMiddleWare($middleWare) {
304
-		if (in_array($middleWare, $this->middleWares, true) !== false) {
305
-			return false;
306
-		}
307
-		$this->middleWares[] = $middleWare;
308
-	}
309
-
310
-	/**
311
-	 * used to return the appname of the set application
312
-	 * @return string the name of your application
313
-	 */
314
-	public function getAppName() {
315
-		return $this->query('AppName');
316
-	}
317
-
318
-	/**
319
-	 * @deprecated use IUserSession->isLoggedIn()
320
-	 * @return boolean
321
-	 */
322
-	public function isLoggedIn() {
323
-		return \OC::$server->getUserSession()->isLoggedIn();
324
-	}
325
-
326
-	/**
327
-	 * @deprecated use IGroupManager->isAdmin($userId)
328
-	 * @return boolean
329
-	 */
330
-	public function isAdminUser() {
331
-		$uid = $this->getUserId();
332
-		return \OC_User::isAdminUser($uid);
333
-	}
334
-
335
-	private function getUserId() {
336
-		return $this->getServer()->getSession()->get('user_id');
337
-	}
338
-
339
-	/**
340
-	 * @deprecated use the ILogger instead
341
-	 * @param string $message
342
-	 * @param string $level
343
-	 * @return mixed
344
-	 */
345
-	public function log($message, $level) {
346
-		switch($level){
347
-			case 'debug':
348
-				$level = ILogger::DEBUG;
349
-				break;
350
-			case 'info':
351
-				$level = ILogger::INFO;
352
-				break;
353
-			case 'warn':
354
-				$level = ILogger::WARN;
355
-				break;
356
-			case 'fatal':
357
-				$level = ILogger::FATAL;
358
-				break;
359
-			default:
360
-				$level = ILogger::ERROR;
361
-				break;
362
-		}
363
-		\OCP\Util::writeLog($this->getAppName(), $message, $level);
364
-	}
365
-
366
-	/**
367
-	 * Register a capability
368
-	 *
369
-	 * @param string $serviceName e.g. 'OCA\Files\Capabilities'
370
-	 */
371
-	public function registerCapability($serviceName) {
372
-		$this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
373
-			return $this->query($serviceName);
374
-		});
375
-	}
376
-
377
-	/**
378
-	 * @param string $name
379
-	 * @return mixed
380
-	 * @throws QueryException if the query could not be resolved
381
-	 */
382
-	public function query($name) {
383
-		try {
384
-			return $this->queryNoFallback($name);
385
-		} catch (QueryException $firstException) {
386
-			try {
387
-				return $this->getServer()->query($name);
388
-			} catch (QueryException $secondException) {
389
-				if ($firstException->getCode() === 1) {
390
-					throw $secondException;
391
-				}
392
-				throw $firstException;
393
-			}
394
-		}
395
-	}
396
-
397
-	/**
398
-	 * @param string $name
399
-	 * @return mixed
400
-	 * @throws QueryException if the query could not be resolved
401
-	 */
402
-	public function queryNoFallback($name) {
403
-		$name = $this->sanitizeName($name);
404
-
405
-		if ($this->offsetExists($name)) {
406
-			return parent::query($name);
407
-		} else {
408
-			if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
409
-				return parent::query($name);
410
-			} else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
411
-				return parent::query($name);
412
-			} else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
413
-				return parent::query($name);
414
-			}
415
-		}
416
-
417
-		throw new QueryException('Could not resolve ' . $name . '!' .
418
-			' Class can not be instantiated', 1);
419
-	}
72
+    /**
73
+     * @var array
74
+     */
75
+    private $middleWares = [];
76
+
77
+    /** @var ServerContainer */
78
+    private $server;
79
+
80
+    /**
81
+     * Put your class dependencies in here
82
+     * @param string $appName the name of the app
83
+     * @param array $urlParams
84
+     * @param ServerContainer|null $server
85
+     */
86
+    public function __construct($appName, $urlParams = array(), ServerContainer $server = null){
87
+        parent::__construct();
88
+        $this['AppName'] = $appName;
89
+        $this['urlParams'] = $urlParams;
90
+
91
+        $this->registerAlias('Request', IRequest::class);
92
+
93
+        /** @var \OC\ServerContainer $server */
94
+        if ($server === null) {
95
+            $server = \OC::$server;
96
+        }
97
+        $this->server = $server;
98
+        $this->server->registerAppContainer($appName, $this);
99
+
100
+        // aliases
101
+        $this->registerAlias('appName', 'AppName');
102
+        $this->registerAlias('webRoot', 'WebRoot');
103
+        $this->registerAlias('userId', 'UserId');
104
+
105
+        /**
106
+         * Core services
107
+         */
108
+        $this->registerService(IOutput::class, function(){
109
+            return new Output($this->getServer()->getWebRoot());
110
+        });
111
+
112
+        $this->registerService(Folder::class, function() {
113
+            return $this->getServer()->getUserFolder();
114
+        });
115
+
116
+        $this->registerService(IAppData::class, function (SimpleContainer $c) {
117
+            return $this->getServer()->getAppDataDir($c->query('AppName'));
118
+        });
119
+
120
+        $this->registerService(IL10N::class, function($c) {
121
+            return $this->getServer()->getL10N($c->query('AppName'));
122
+        });
123
+
124
+        // Log wrapper
125
+        $this->registerService(ILogger::class, function ($c) {
126
+            return new OC\AppFramework\Logger($this->server->query(ILogger::class), $c->query('AppName'));
127
+        });
128
+
129
+        $this->registerService(IServerContainer::class, function () {
130
+            return $this->getServer();
131
+        });
132
+        $this->registerAlias('ServerContainer', IServerContainer::class);
133
+
134
+        $this->registerService(\OCP\WorkflowEngine\IManager::class, function ($c) {
135
+            return $c->query(Manager::class);
136
+        });
137
+
138
+        $this->registerService(\OCP\AppFramework\IAppContainer::class, function ($c) {
139
+            return $c;
140
+        });
141
+
142
+        // commonly used attributes
143
+        $this->registerService('UserId', function ($c) {
144
+            return $c->query(IUserSession::class)->getSession()->get('user_id');
145
+        });
146
+
147
+        $this->registerService('WebRoot', function ($c) {
148
+            return $c->query('ServerContainer')->getWebRoot();
149
+        });
150
+
151
+        $this->registerService('OC_Defaults', function ($c) {
152
+            return $c->getServer()->getThemingDefaults();
153
+        });
154
+
155
+        $this->registerService(IConfig::class, function ($c) {
156
+            return $c->query(OC\GlobalScale\Config::class);
157
+        });
158
+
159
+        $this->registerService('Protocol', function($c){
160
+            /** @var \OC\Server $server */
161
+            $server = $c->query('ServerContainer');
162
+            $protocol = $server->getRequest()->getHttpProtocol();
163
+            return new Http($_SERVER, $protocol);
164
+        });
165
+
166
+        $this->registerService('Dispatcher', function($c) {
167
+            return new Dispatcher(
168
+                $c['Protocol'],
169
+                $c['MiddlewareDispatcher'],
170
+                $c->query(IControllerMethodReflector::class),
171
+                $c['Request']
172
+            );
173
+        });
174
+
175
+        /**
176
+         * App Framework default arguments
177
+         */
178
+        $this->registerParameter('corsMethods', 'PUT, POST, GET, DELETE, PATCH');
179
+        $this->registerParameter('corsAllowedHeaders', 'Authorization, Content-Type, Accept');
180
+        $this->registerParameter('corsMaxAge', 1728000);
181
+
182
+        /**
183
+         * Middleware
184
+         */
185
+        $this->registerService('MiddlewareDispatcher', function(SimpleContainer $c) {
186
+            $server =  $this->getServer();
187
+
188
+            $dispatcher = new MiddlewareDispatcher();
189
+            $dispatcher->registerMiddleware(
190
+                $c->query(OC\AppFramework\Middleware\Security\ReloadExecutionMiddleware::class)
191
+            );
192
+
193
+            $dispatcher->registerMiddleware(
194
+                new OC\AppFramework\Middleware\Security\SameSiteCookieMiddleware(
195
+                    $c->query(IRequest::class),
196
+                    $c->query(IControllerMethodReflector::class)
197
+                )
198
+            );
199
+            $dispatcher->registerMiddleware(
200
+                new CORSMiddleware(
201
+                    $c->query(IRequest::class),
202
+                    $c->query(IControllerMethodReflector::class),
203
+                    $c->query(IUserSession::class),
204
+                    $c->query(OC\Security\Bruteforce\Throttler::class)
205
+                )
206
+            );
207
+            $dispatcher->registerMiddleware(
208
+                new OCSMiddleware(
209
+                    $c->query(IRequest::class)
210
+                )
211
+            );
212
+
213
+            $securityMiddleware = new SecurityMiddleware(
214
+                $c->query(IRequest::class),
215
+                $c->query(IControllerMethodReflector::class),
216
+                $c->query(INavigationManager::class),
217
+                $c->query(IURLGenerator::class),
218
+                $server->getLogger(),
219
+                $c['AppName'],
220
+                $server->getUserSession()->isLoggedIn(),
221
+                $server->getGroupManager()->isAdmin($this->getUserId()),
222
+                $server->getUserSession()->getUser() !== null && $server->query(ISubAdmin::class)->isSubAdmin($server->getUserSession()->getUser()),
223
+                $server->getContentSecurityPolicyManager(),
224
+                $server->getCsrfTokenManager(),
225
+                $server->getContentSecurityPolicyNonceManager(),
226
+                $server->getAppManager(),
227
+                $server->getL10N('lib')
228
+            );
229
+            $dispatcher->registerMiddleware($securityMiddleware);
230
+            $dispatcher->registerMiddleware(
231
+                new OC\AppFramework\Middleware\Security\PasswordConfirmationMiddleware(
232
+                    $c->query(IControllerMethodReflector::class),
233
+                    $c->query(ISession::class),
234
+                    $c->query(IUserSession::class),
235
+                    $c->query(ITimeFactory::class)
236
+                )
237
+            );
238
+            $dispatcher->registerMiddleware(
239
+                new TwoFactorMiddleware(
240
+                    $c->query(OC\Authentication\TwoFactorAuth\Manager::class),
241
+                    $c->query(IUserSession::class),
242
+                    $c->query(ISession::class),
243
+                    $c->query(IURLGenerator::class),
244
+                    $c->query(IControllerMethodReflector::class),
245
+                    $c->query(IRequest::class)
246
+                )
247
+            );
248
+            $dispatcher->registerMiddleware(
249
+                new OC\AppFramework\Middleware\Security\BruteForceMiddleware(
250
+                    $c->query(IControllerMethodReflector::class),
251
+                    $c->query(OC\Security\Bruteforce\Throttler::class),
252
+                    $c->query(IRequest::class)
253
+                )
254
+            );
255
+            $dispatcher->registerMiddleware(
256
+                new RateLimitingMiddleware(
257
+                    $c->query(IRequest::class),
258
+                    $c->query(IUserSession::class),
259
+                    $c->query(IControllerMethodReflector::class),
260
+                    $c->query(OC\Security\RateLimiting\Limiter::class)
261
+                )
262
+            );
263
+            $dispatcher->registerMiddleware(
264
+                new OC\AppFramework\Middleware\PublicShare\PublicShareMiddleware(
265
+                    $c->query(IRequest::class),
266
+                    $c->query(ISession::class),
267
+                    $c->query(\OCP\IConfig::class)
268
+                )
269
+            );
270
+            $dispatcher->registerMiddleware(
271
+                $c->query(\OC\AppFramework\Middleware\AdditionalScriptsMiddleware::class)
272
+            );
273
+
274
+            foreach($this->middleWares as $middleWare) {
275
+                $dispatcher->registerMiddleware($c[$middleWare]);
276
+            }
277
+
278
+            $dispatcher->registerMiddleware(
279
+                new SessionMiddleware(
280
+                    $c->query(IRequest::class),
281
+                    $c->query(IControllerMethodReflector::class),
282
+                    $c->query(ISession::class)
283
+                )
284
+            );
285
+            return $dispatcher;
286
+        });
287
+
288
+        $this->registerAlias(\OCP\Collaboration\Resources\IManager::class, OC\Collaboration\Resources\Manager::class);
289
+    }
290
+
291
+    /**
292
+     * @return \OCP\IServerContainer
293
+     */
294
+    public function getServer()
295
+    {
296
+        return $this->server;
297
+    }
298
+
299
+    /**
300
+     * @param string $middleWare
301
+     * @return boolean|null
302
+     */
303
+    public function registerMiddleWare($middleWare) {
304
+        if (in_array($middleWare, $this->middleWares, true) !== false) {
305
+            return false;
306
+        }
307
+        $this->middleWares[] = $middleWare;
308
+    }
309
+
310
+    /**
311
+     * used to return the appname of the set application
312
+     * @return string the name of your application
313
+     */
314
+    public function getAppName() {
315
+        return $this->query('AppName');
316
+    }
317
+
318
+    /**
319
+     * @deprecated use IUserSession->isLoggedIn()
320
+     * @return boolean
321
+     */
322
+    public function isLoggedIn() {
323
+        return \OC::$server->getUserSession()->isLoggedIn();
324
+    }
325
+
326
+    /**
327
+     * @deprecated use IGroupManager->isAdmin($userId)
328
+     * @return boolean
329
+     */
330
+    public function isAdminUser() {
331
+        $uid = $this->getUserId();
332
+        return \OC_User::isAdminUser($uid);
333
+    }
334
+
335
+    private function getUserId() {
336
+        return $this->getServer()->getSession()->get('user_id');
337
+    }
338
+
339
+    /**
340
+     * @deprecated use the ILogger instead
341
+     * @param string $message
342
+     * @param string $level
343
+     * @return mixed
344
+     */
345
+    public function log($message, $level) {
346
+        switch($level){
347
+            case 'debug':
348
+                $level = ILogger::DEBUG;
349
+                break;
350
+            case 'info':
351
+                $level = ILogger::INFO;
352
+                break;
353
+            case 'warn':
354
+                $level = ILogger::WARN;
355
+                break;
356
+            case 'fatal':
357
+                $level = ILogger::FATAL;
358
+                break;
359
+            default:
360
+                $level = ILogger::ERROR;
361
+                break;
362
+        }
363
+        \OCP\Util::writeLog($this->getAppName(), $message, $level);
364
+    }
365
+
366
+    /**
367
+     * Register a capability
368
+     *
369
+     * @param string $serviceName e.g. 'OCA\Files\Capabilities'
370
+     */
371
+    public function registerCapability($serviceName) {
372
+        $this->query('OC\CapabilitiesManager')->registerCapability(function() use ($serviceName) {
373
+            return $this->query($serviceName);
374
+        });
375
+    }
376
+
377
+    /**
378
+     * @param string $name
379
+     * @return mixed
380
+     * @throws QueryException if the query could not be resolved
381
+     */
382
+    public function query($name) {
383
+        try {
384
+            return $this->queryNoFallback($name);
385
+        } catch (QueryException $firstException) {
386
+            try {
387
+                return $this->getServer()->query($name);
388
+            } catch (QueryException $secondException) {
389
+                if ($firstException->getCode() === 1) {
390
+                    throw $secondException;
391
+                }
392
+                throw $firstException;
393
+            }
394
+        }
395
+    }
396
+
397
+    /**
398
+     * @param string $name
399
+     * @return mixed
400
+     * @throws QueryException if the query could not be resolved
401
+     */
402
+    public function queryNoFallback($name) {
403
+        $name = $this->sanitizeName($name);
404
+
405
+        if ($this->offsetExists($name)) {
406
+            return parent::query($name);
407
+        } else {
408
+            if ($this['AppName'] === 'settings' && strpos($name, 'OC\\Settings\\') === 0) {
409
+                return parent::query($name);
410
+            } else if ($this['AppName'] === 'core' && strpos($name, 'OC\\Core\\') === 0) {
411
+                return parent::query($name);
412
+            } else if (strpos($name, \OC\AppFramework\App::buildAppNamespace($this['AppName']) . '\\') === 0) {
413
+                return parent::query($name);
414
+            }
415
+        }
416
+
417
+        throw new QueryException('Could not resolve ' . $name . '!' .
418
+            ' Class can not be instantiated', 1);
419
+    }
420 420
 }
Please login to merge, or discard this patch.
settings/Controller/PersonalSettingsController.php 1 patch
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -35,78 +35,78 @@
 block discarded – undo
35 35
 use OCP\Template;
36 36
 
37 37
 class PersonalSettingsController extends Controller {
38
-	use CommonSettingsTrait;
38
+    use CommonSettingsTrait;
39 39
 
40
-	public function __construct(
41
-		$appName,
42
-		IRequest $request,
43
-		INavigationManager $navigationManager,
44
-		ISettingsManager $settingsManager,
45
-		IUserSession $userSession,
46
-		IGroupManager $groupManager,
47
-		ISubAdmin $subAdmin
48
-	) {
49
-		parent::__construct($appName, $request);
50
-		$this->navigationManager = $navigationManager;
51
-		$this->settingsManager = $settingsManager;
52
-		$this->userSession = $userSession;
53
-		$this->subAdmin = $subAdmin;
54
-		$this->groupManager = $groupManager;
55
-	}
40
+    public function __construct(
41
+        $appName,
42
+        IRequest $request,
43
+        INavigationManager $navigationManager,
44
+        ISettingsManager $settingsManager,
45
+        IUserSession $userSession,
46
+        IGroupManager $groupManager,
47
+        ISubAdmin $subAdmin
48
+    ) {
49
+        parent::__construct($appName, $request);
50
+        $this->navigationManager = $navigationManager;
51
+        $this->settingsManager = $settingsManager;
52
+        $this->userSession = $userSession;
53
+        $this->subAdmin = $subAdmin;
54
+        $this->groupManager = $groupManager;
55
+    }
56 56
 
57
-	/**
58
-	 * @param string $section
59
-	 * @return TemplateResponse
60
-	 *
61
-	 * @NoCSRFRequired
62
-	 * @NoAdminRequired
63
-	 * @NoSubadminRequired
64
-	 */
65
-	public function index($section) {
66
-		return $this->getIndexResponse('personal', $section);
57
+    /**
58
+     * @param string $section
59
+     * @return TemplateResponse
60
+     *
61
+     * @NoCSRFRequired
62
+     * @NoAdminRequired
63
+     * @NoSubadminRequired
64
+     */
65
+    public function index($section) {
66
+        return $this->getIndexResponse('personal', $section);
67 67
 
68
-	}
68
+    }
69 69
 
70
-	/**
71
-	 * @param string $section
72
-	 * @return array
73
-	 */
74
-	protected function getSettings($section) {
75
-		$settings = $this->settingsManager->getPersonalSettings($section);
76
-		$formatted = $this->formatSettings($settings);
77
-		if($section === 'additional') {
78
-			$formatted['content'] .= $this->getLegacyForms();
79
-		}
80
-		return $formatted;
81
-	}
70
+    /**
71
+     * @param string $section
72
+     * @return array
73
+     */
74
+    protected function getSettings($section) {
75
+        $settings = $this->settingsManager->getPersonalSettings($section);
76
+        $formatted = $this->formatSettings($settings);
77
+        if($section === 'additional') {
78
+            $formatted['content'] .= $this->getLegacyForms();
79
+        }
80
+        return $formatted;
81
+    }
82 82
 
83
-	/**
84
-	 * @return bool|string
85
-	 */
86
-	private function getLegacyForms() {
87
-		$forms = \OC_App::getForms('personal');
83
+    /**
84
+     * @return bool|string
85
+     */
86
+    private function getLegacyForms() {
87
+        $forms = \OC_App::getForms('personal');
88 88
 
89
-		$forms = array_map(function ($form) {
90
-			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
91
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
92
-				$sectionName = str_replace('</h2>', '', $sectionName);
93
-				$anchor = strtolower($sectionName);
94
-				$anchor = str_replace(' ', '-', $anchor);
89
+        $forms = array_map(function ($form) {
90
+            if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
91
+                $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
92
+                $sectionName = str_replace('</h2>', '', $sectionName);
93
+                $anchor = strtolower($sectionName);
94
+                $anchor = str_replace(' ', '-', $anchor);
95 95
 
96
-				return array(
97
-					'anchor' => $anchor,
98
-					'section-name' => $sectionName,
99
-					'form' => $form
100
-				);
101
-			}
102
-			return array(
103
-				'form' => $form
104
-			);
105
-		}, $forms);
96
+                return array(
97
+                    'anchor' => $anchor,
98
+                    'section-name' => $sectionName,
99
+                    'form' => $form
100
+                );
101
+            }
102
+            return array(
103
+                'form' => $form
104
+            );
105
+        }, $forms);
106 106
 
107
-		$out = new Template('settings', 'settings/additional');
108
-		$out->assign('forms', $forms);
107
+        $out = new Template('settings', 'settings/additional');
108
+        $out->assign('forms', $forms);
109 109
 
110
-		return $out->fetchPage();
111
-	}
110
+        return $out->fetchPage();
111
+    }
112 112
 }
Please login to merge, or discard this patch.
settings/Controller/CommonSettingsTrait.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -36,119 +36,119 @@
 block discarded – undo
36 36
 
37 37
 trait CommonSettingsTrait  {
38 38
 
39
-	/** @var ISettingsManager */
40
-	private $settingsManager;
41
-
42
-	/** @var INavigationManager */
43
-	private $navigationManager;
44
-
45
-	/** @var IUserSession */
46
-	private $userSession;
47
-
48
-	/** @var IGroupManager */
49
-	private $groupManager;
50
-
51
-	/** @var ISubAdmin */
52
-	private $subAdmin;
53
-
54
-	/**
55
-	 * @param string $currentSection
56
-	 * @return array
57
-	 */
58
-	private function getNavigationParameters($currentType, $currentSection) {
59
-		$templateParameters = [
60
-			'personal' => $this->formatPersonalSections($currentType, $currentSection),
61
-			'admin' => []
62
-		];
63
-
64
-		/** @var IUser $user */
65
-		$user = $this->userSession->getUser();
66
-		$isAdmin = $this->groupManager->isAdmin($user->getUID());
67
-		$isSubAdmin = $this->subAdmin->isSubAdmin($user);
68
-		if ($isAdmin || $isSubAdmin) {
69
-			$templateParameters['admin'] = $this->formatAdminSections(
70
-				$currentType,
71
-				$currentSection,
72
-				!$isAdmin && $isSubAdmin
73
-			);
74
-		}
75
-
76
-		return [
77
-			'forms' => $templateParameters
78
-		];
79
-	}
80
-
81
-	protected function formatSections($sections, $currentSection, $type, $currentType, bool $subAdminOnly = false) {
82
-		$templateParameters = [];
83
-		/** @var \OCP\Settings\ISection[] $prioritizedSections */
84
-		foreach($sections as $prioritizedSections) {
85
-			foreach ($prioritizedSections as $section) {
86
-				if($type === 'admin') {
87
-					$settings = $this->settingsManager->getAdminSettings($section->getID(), $subAdminOnly);
88
-				} else if($type === 'personal') {
89
-					$settings = $this->settingsManager->getPersonalSettings($section->getID());
90
-				}
91
-				if (empty($settings) && !($section->getID() === 'additional' && count(\OC_App::getForms('admin')) > 0)) {
92
-					continue;
93
-				}
94
-
95
-				$icon = '';
96
-				if ($section instanceof IIconSection) {
97
-					$icon = $section->getIcon();
98
-				}
99
-
100
-				$active = $section->getID() === $currentSection
101
-					&& $type === $currentType;
102
-
103
-				$templateParameters[] = [
104
-					'anchor'       => $section->getID(),
105
-					'section-name' => $section->getName(),
106
-					'active'       => $active,
107
-					'icon'         => $icon,
108
-				];
109
-			}
110
-		}
111
-		return $templateParameters;
112
-	}
113
-
114
-	protected function formatPersonalSections($currentType, $currentSections) {
115
-		$sections = $this->settingsManager->getPersonalSections();
116
-		$templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType);
117
-
118
-		return $templateParameters;
119
-	}
120
-
121
-	protected function formatAdminSections($currentType, $currentSections, bool $subAdminOnly) {
122
-		$sections = $this->settingsManager->getAdminSections();
123
-		$templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType, $subAdminOnly);
124
-
125
-		return $templateParameters;
126
-	}
127
-
128
-	/**
129
-	 * @param ISettings[] $settings
130
-	 * @return array
131
-	 */
132
-	private function formatSettings($settings) {
133
-		$html = '';
134
-		foreach ($settings as $prioritizedSettings) {
135
-			foreach ($prioritizedSettings as $setting) {
136
-				/** @var \OCP\Settings\ISettings $setting */
137
-				$form = $setting->getForm();
138
-				$html .= $form->renderAs('')->render();
139
-			}
140
-		}
141
-		return ['content' => $html];
142
-	}
143
-
144
-	private function getIndexResponse($type, $section) {
145
-		$this->navigationManager->setActiveEntry('settings');
146
-		$templateParams = [];
147
-		$templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section));
148
-		$templateParams = array_merge($templateParams, $this->getSettings($section));
149
-
150
-		return new TemplateResponse('settings', 'settings/frame', $templateParams);
151
-	}
152
-
153
-	abstract protected function getSettings($section);
39
+    /** @var ISettingsManager */
40
+    private $settingsManager;
41
+
42
+    /** @var INavigationManager */
43
+    private $navigationManager;
44
+
45
+    /** @var IUserSession */
46
+    private $userSession;
47
+
48
+    /** @var IGroupManager */
49
+    private $groupManager;
50
+
51
+    /** @var ISubAdmin */
52
+    private $subAdmin;
53
+
54
+    /**
55
+     * @param string $currentSection
56
+     * @return array
57
+     */
58
+    private function getNavigationParameters($currentType, $currentSection) {
59
+        $templateParameters = [
60
+            'personal' => $this->formatPersonalSections($currentType, $currentSection),
61
+            'admin' => []
62
+        ];
63
+
64
+        /** @var IUser $user */
65
+        $user = $this->userSession->getUser();
66
+        $isAdmin = $this->groupManager->isAdmin($user->getUID());
67
+        $isSubAdmin = $this->subAdmin->isSubAdmin($user);
68
+        if ($isAdmin || $isSubAdmin) {
69
+            $templateParameters['admin'] = $this->formatAdminSections(
70
+                $currentType,
71
+                $currentSection,
72
+                !$isAdmin && $isSubAdmin
73
+            );
74
+        }
75
+
76
+        return [
77
+            'forms' => $templateParameters
78
+        ];
79
+    }
80
+
81
+    protected function formatSections($sections, $currentSection, $type, $currentType, bool $subAdminOnly = false) {
82
+        $templateParameters = [];
83
+        /** @var \OCP\Settings\ISection[] $prioritizedSections */
84
+        foreach($sections as $prioritizedSections) {
85
+            foreach ($prioritizedSections as $section) {
86
+                if($type === 'admin') {
87
+                    $settings = $this->settingsManager->getAdminSettings($section->getID(), $subAdminOnly);
88
+                } else if($type === 'personal') {
89
+                    $settings = $this->settingsManager->getPersonalSettings($section->getID());
90
+                }
91
+                if (empty($settings) && !($section->getID() === 'additional' && count(\OC_App::getForms('admin')) > 0)) {
92
+                    continue;
93
+                }
94
+
95
+                $icon = '';
96
+                if ($section instanceof IIconSection) {
97
+                    $icon = $section->getIcon();
98
+                }
99
+
100
+                $active = $section->getID() === $currentSection
101
+                    && $type === $currentType;
102
+
103
+                $templateParameters[] = [
104
+                    'anchor'       => $section->getID(),
105
+                    'section-name' => $section->getName(),
106
+                    'active'       => $active,
107
+                    'icon'         => $icon,
108
+                ];
109
+            }
110
+        }
111
+        return $templateParameters;
112
+    }
113
+
114
+    protected function formatPersonalSections($currentType, $currentSections) {
115
+        $sections = $this->settingsManager->getPersonalSections();
116
+        $templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType);
117
+
118
+        return $templateParameters;
119
+    }
120
+
121
+    protected function formatAdminSections($currentType, $currentSections, bool $subAdminOnly) {
122
+        $sections = $this->settingsManager->getAdminSections();
123
+        $templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType, $subAdminOnly);
124
+
125
+        return $templateParameters;
126
+    }
127
+
128
+    /**
129
+     * @param ISettings[] $settings
130
+     * @return array
131
+     */
132
+    private function formatSettings($settings) {
133
+        $html = '';
134
+        foreach ($settings as $prioritizedSettings) {
135
+            foreach ($prioritizedSettings as $setting) {
136
+                /** @var \OCP\Settings\ISettings $setting */
137
+                $form = $setting->getForm();
138
+                $html .= $form->renderAs('')->render();
139
+            }
140
+        }
141
+        return ['content' => $html];
142
+    }
143
+
144
+    private function getIndexResponse($type, $section) {
145
+        $this->navigationManager->setActiveEntry('settings');
146
+        $templateParams = [];
147
+        $templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section));
148
+        $templateParams = array_merge($templateParams, $this->getSettings($section));
149
+
150
+        return new TemplateResponse('settings', 'settings/frame', $templateParams);
151
+    }
152
+
153
+    abstract protected function getSettings($section);
154 154
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 use OCP\Settings\IIconSection;
35 35
 use OCP\Settings\ISettings;
36 36
 
37
-trait CommonSettingsTrait  {
37
+trait CommonSettingsTrait {
38 38
 
39 39
 	/** @var ISettingsManager */
40 40
 	private $settingsManager;
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
 	protected function formatSections($sections, $currentSection, $type, $currentType, bool $subAdminOnly = false) {
82 82
 		$templateParameters = [];
83 83
 		/** @var \OCP\Settings\ISection[] $prioritizedSections */
84
-		foreach($sections as $prioritizedSections) {
84
+		foreach ($sections as $prioritizedSections) {
85 85
 			foreach ($prioritizedSections as $section) {
86
-				if($type === 'admin') {
86
+				if ($type === 'admin') {
87 87
 					$settings = $this->settingsManager->getAdminSettings($section->getID(), $subAdminOnly);
88
-				} else if($type === 'personal') {
88
+				} else if ($type === 'personal') {
89 89
 					$settings = $this->settingsManager->getPersonalSettings($section->getID());
90 90
 				}
91 91
 				if (empty($settings) && !($section->getID() === 'additional' && count(\OC_App::getForms('admin')) > 0)) {
Please login to merge, or discard this patch.
settings/Controller/AdminSettingsController.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -40,85 +40,85 @@
 block discarded – undo
40 40
  * @package OC\Settings\Controller
41 41
  */
42 42
 class AdminSettingsController extends Controller {
43
-	use CommonSettingsTrait;
43
+    use CommonSettingsTrait;
44 44
 
45
-	public function __construct(
46
-		$appName,
47
-		IRequest $request,
48
-		INavigationManager $navigationManager,
49
-		ISettingsManager $settingsManager,
50
-		IUserSession $userSession,
51
-		IGroupManager $groupManager,
52
-		ISubAdmin $subAdmin
53
-	) {
54
-		parent::__construct($appName, $request);
55
-		$this->navigationManager = $navigationManager;
56
-		$this->settingsManager = $settingsManager;
57
-		$this->userSession = $userSession;
58
-		$this->groupManager = $groupManager;
59
-		$this->subAdmin = $subAdmin;
60
-	}
45
+    public function __construct(
46
+        $appName,
47
+        IRequest $request,
48
+        INavigationManager $navigationManager,
49
+        ISettingsManager $settingsManager,
50
+        IUserSession $userSession,
51
+        IGroupManager $groupManager,
52
+        ISubAdmin $subAdmin
53
+    ) {
54
+        parent::__construct($appName, $request);
55
+        $this->navigationManager = $navigationManager;
56
+        $this->settingsManager = $settingsManager;
57
+        $this->userSession = $userSession;
58
+        $this->groupManager = $groupManager;
59
+        $this->subAdmin = $subAdmin;
60
+    }
61 61
 
62
-	/**
63
-	 * @param string $section
64
-	 * @return TemplateResponse
65
-	 *
66
-	 * @NoCSRFRequired
67
-	 * @SubAdminRequired
68
-	 */
69
-	public function index($section) {
70
-		return $this->getIndexResponse('admin', $section);
71
-	}
62
+    /**
63
+     * @param string $section
64
+     * @return TemplateResponse
65
+     *
66
+     * @NoCSRFRequired
67
+     * @SubAdminRequired
68
+     */
69
+    public function index($section) {
70
+        return $this->getIndexResponse('admin', $section);
71
+    }
72 72
 
73
-	/**
74
-	 * @param string $section
75
-	 * @return array
76
-	 */
77
-	protected function getSettings($section) {
78
-		/** @var IUser $user */
79
-		$user = $this->userSession->getUser();
80
-		$isSubAdmin = !$this->groupManager->isAdmin($user->getUID()) && $this->subAdmin->isSubAdmin($user);
81
-		$settings = $this->settingsManager->getAdminSettings(
82
-			$section,
83
-			$isSubAdmin
84
-		);
85
-		$formatted = $this->formatSettings($settings);
86
-		// Do not show legacy forms for sub admins
87
-		if($section === 'additional' && !$isSubAdmin) {
88
-			$formatted['content'] .= $this->getLegacyForms();
89
-		}
90
-		return $formatted;
91
-	}
73
+    /**
74
+     * @param string $section
75
+     * @return array
76
+     */
77
+    protected function getSettings($section) {
78
+        /** @var IUser $user */
79
+        $user = $this->userSession->getUser();
80
+        $isSubAdmin = !$this->groupManager->isAdmin($user->getUID()) && $this->subAdmin->isSubAdmin($user);
81
+        $settings = $this->settingsManager->getAdminSettings(
82
+            $section,
83
+            $isSubAdmin
84
+        );
85
+        $formatted = $this->formatSettings($settings);
86
+        // Do not show legacy forms for sub admins
87
+        if($section === 'additional' && !$isSubAdmin) {
88
+            $formatted['content'] .= $this->getLegacyForms();
89
+        }
90
+        return $formatted;
91
+    }
92 92
 
93
-	/**
94
-	 * @return bool|string
95
-	 */
96
-	private function getLegacyForms() {
97
-		$forms = \OC_App::getForms('admin');
93
+    /**
94
+     * @return bool|string
95
+     */
96
+    private function getLegacyForms() {
97
+        $forms = \OC_App::getForms('admin');
98 98
 
99
-		$forms = array_map(function ($form) {
100
-			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
101
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
102
-				$sectionName = str_replace('</h2>', '', $sectionName);
103
-				$anchor = strtolower($sectionName);
104
-				$anchor = str_replace(' ', '-', $anchor);
99
+        $forms = array_map(function ($form) {
100
+            if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
101
+                $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
102
+                $sectionName = str_replace('</h2>', '', $sectionName);
103
+                $anchor = strtolower($sectionName);
104
+                $anchor = str_replace(' ', '-', $anchor);
105 105
 
106
-				return array(
107
-					'anchor' => $anchor,
108
-					'section-name' => $sectionName,
109
-					'form' => $form
110
-				);
111
-			}
112
-			return array(
113
-				'form' => $form
114
-			);
115
-		}, $forms);
106
+                return array(
107
+                    'anchor' => $anchor,
108
+                    'section-name' => $sectionName,
109
+                    'form' => $form
110
+                );
111
+            }
112
+            return array(
113
+                'form' => $form
114
+            );
115
+        }, $forms);
116 116
 
117
-		$out = new Template('settings', 'settings/additional');
118
-		$out->assign('forms', $forms);
117
+        $out = new Template('settings', 'settings/additional');
118
+        $out->assign('forms', $forms);
119 119
 
120
-		return $out->fetchPage();
121
-	}
120
+        return $out->fetchPage();
121
+    }
122 122
 
123 123
 
124 124
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
 		);
85 85
 		$formatted = $this->formatSettings($settings);
86 86
 		// Do not show legacy forms for sub admins
87
-		if($section === 'additional' && !$isSubAdmin) {
87
+		if ($section === 'additional' && !$isSubAdmin) {
88 88
 			$formatted['content'] .= $this->getLegacyForms();
89 89
 		}
90 90
 		return $formatted;
@@ -96,9 +96,9 @@  discard block
 block discarded – undo
96 96
 	private function getLegacyForms() {
97 97
 		$forms = \OC_App::getForms('admin');
98 98
 
99
-		$forms = array_map(function ($form) {
99
+		$forms = array_map(function($form) {
100 100
 			if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
101
-				$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
101
+				$sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]);
102 102
 				$sectionName = str_replace('</h2>', '', $sectionName);
103 103
 				$anchor = strtolower($sectionName);
104 104
 				$anchor = str_replace(' ', '-', $anchor);
Please login to merge, or discard this patch.