Completed
Push — master ( b40bae...a2c518 )
by Morris
16:08
created
lib/private/Settings/Personal/PersonalInfo.php 2 patches
Indentation   +200 added lines, -200 removed lines patch added patch discarded remove patch
@@ -40,205 +40,205 @@
 block discarded – undo
40 40
 
41 41
 class PersonalInfo implements ISettings {
42 42
 
43
-	/** @var IConfig */
44
-	private $config;
45
-	/** @var IUserManager */
46
-	private $userManager;
47
-	/** @var AccountManager */
48
-	private $accountManager;
49
-	/** @var IGroupManager */
50
-	private $groupManager;
51
-	/** @var IAppManager */
52
-	private $appManager;
53
-	/** @var IFactory */
54
-	private $l10nFactory;
55
-	/** @var IL10N */
56
-	private $l;
57
-
58
-	/**
59
-	 * @param IConfig $config
60
-	 * @param IUserManager $userManager
61
-	 * @param IGroupManager $groupManager
62
-	 * @param AccountManager $accountManager
63
-	 * @param IFactory $l10nFactory
64
-	 * @param IL10N $l
65
-	 */
66
-	public function __construct(
67
-		IConfig $config,
68
-		IUserManager $userManager,
69
-		IGroupManager $groupManager,
70
-		AccountManager $accountManager,
71
-		IAppManager $appManager,
72
-		IFactory $l10nFactory,
73
-		IL10N $l
74
-	) {
75
-		$this->config = $config;
76
-		$this->userManager = $userManager;
77
-		$this->accountManager = $accountManager;
78
-		$this->groupManager = $groupManager;
79
-		$this->appManager = $appManager;
80
-		$this->l10nFactory = $l10nFactory;
81
-		$this->l = $l;
82
-	}
83
-
84
-	/**
85
-	 * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
86
-	 * @since 9.1
87
-	 */
88
-	public function getForm() {
89
-		$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
90
-		$lookupServerUploadEnabled = false;
91
-		if($federatedFileSharingEnabled) {
92
-			$federatedFileSharing = new Application();
93
-			$shareProvider = $federatedFileSharing->getFederatedShareProvider();
94
-			$lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
95
-		}
96
-
97
-		$uid = \OC_User::getUser();
98
-		$user = $this->userManager->get($uid);
99
-		$userData = $this->accountManager->getUser($user);
100
-
101
-		$storageInfo = \OC_Helper::getStorageInfo('/');
102
-		if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) {
103
-			$totalSpace = $this->l->t('Unlimited');
104
-		} else {
105
-			$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
106
-		}
107
-
108
-		$languageParameters = $this->getLanguages($user);
109
-		$messageParameters = $this->getMessageParameters($userData);
110
-
111
-		$parameters = [
112
-			'total_space' => $totalSpace,
113
-			'usage' => \OC_Helper::humanFileSize($storageInfo['used']),
114
-			'usage_relative' => round($storageInfo['relative']),
115
-			'quota' => $storageInfo['quota'],
116
-			'avatarChangeSupported' => $user->canChangeAvatar(),
117
-			'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
118
-			'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'],
119
-			'displayNameChangeSupported' => $user->canChangeDisplayName(),
120
-			'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'],
121
-			'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
122
-			'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'],
123
-			'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'],
124
-			'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'],
125
-			'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'],
126
-			'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'],
127
-			'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'],
128
-			'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'],
129
-			'website' =>  $userData[AccountManager::PROPERTY_WEBSITE]['value'],
130
-			'websiteScope' =>  $userData[AccountManager::PROPERTY_WEBSITE]['scope'],
131
-			'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'],
132
-			'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'],
133
-			'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
134
-			'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
135
-			'groups' => $this->getGroups($user),
136
-			'passwordChangeSupported' => $user->canChangePassword(),
137
-		] + $messageParameters + $languageParameters;
138
-
139
-
140
-		return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
141
-	}
142
-
143
-	/**
144
-	 * @return string the section ID, e.g. 'sharing'
145
-	 * @since 9.1
146
-	 */
147
-	public function getSection() {
148
-		return 'personal-info';
149
-	}
150
-
151
-	/**
152
-	 * @return int whether the form should be rather on the top or bottom of
153
-	 * the admin section. The forms are arranged in ascending order of the
154
-	 * priority values. It is required to return a value between 0 and 100.
155
-	 *
156
-	 * E.g.: 70
157
-	 * @since 9.1
158
-	 */
159
-	public function getPriority() {
160
-		return 10;
161
-	}
162
-
163
-	/**
164
-	 * returns a sorted list of the user's group GIDs
165
-	 *
166
-	 * @param IUser $user
167
-	 * @return array
168
-	 */
169
-	private function getGroups(IUser $user) {
170
-		$groups = array_map(
171
-			function(IGroup $group) {
172
-				return $group->getDisplayName();
173
-			},
174
-			$this->groupManager->getUserGroups($user)
175
-		);
176
-		sort($groups);
177
-
178
-		return $groups;
179
-	}
180
-
181
-	/**
182
-	 * returns the user language, common language and other languages in an
183
-	 * associative array
184
-	 *
185
-	 * @param IUser $user
186
-	 * @return array
187
-	 */
188
-	private function getLanguages(IUser $user) {
189
-		$forceLanguage = $this->config->getSystemValue('force_language', false);
190
-		if($forceLanguage !== false) {
191
-			return [];
192
-		}
193
-
194
-		$uid = $user->getUID();
195
-
196
-		$userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
197
-		$languages = $this->l10nFactory->getLanguages();
198
-
199
-		// associate the user language with the proper array
200
-		$userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code'));
201
-		$userLang = $languages['commonlanguages'][$userLangIndex];
202
-		// search in the other languages
203
-		if ($userLangIndex === false) {
204
-			$userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code'));		
205
-			$userLang = $languages['languages'][$userLangIndex];
206
-		}
207
-		// if user language is not available but set somehow: show the actual code as name
208
-		if (!is_array($userLang)) {
209
-			$userLang = [
210
-				'code' => $userConfLang,
211
-				'name' => $userConfLang,
212
-			];
213
-		}
214
-
215
-		return array_merge(
216
-			array('activelanguage' => $userLang),
217
-			$languages
218
-		);
219
-	}
220
-
221
-	/**
222
-	 * @param array $userData
223
-	 * @return array
224
-	 */
225
-	private function getMessageParameters(array $userData) {
226
-		$needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER];
227
-		$messageParameters = [];
228
-		foreach ($needVerifyMessage as $property) {
229
-			switch ($userData[$property]['verified']) {
230
-				case AccountManager::VERIFIED:
231
-					$message = $this->l->t('Verifying');
232
-					break;
233
-				case AccountManager::VERIFICATION_IN_PROGRESS:
234
-					$message = $this->l->t('Verifying …');
235
-					break;
236
-				default:
237
-					$message = $this->l->t('Verify');
238
-			}
239
-			$messageParameters[$property . 'Message'] = $message;
240
-		}
241
-		return $messageParameters;
242
-	}
43
+    /** @var IConfig */
44
+    private $config;
45
+    /** @var IUserManager */
46
+    private $userManager;
47
+    /** @var AccountManager */
48
+    private $accountManager;
49
+    /** @var IGroupManager */
50
+    private $groupManager;
51
+    /** @var IAppManager */
52
+    private $appManager;
53
+    /** @var IFactory */
54
+    private $l10nFactory;
55
+    /** @var IL10N */
56
+    private $l;
57
+
58
+    /**
59
+     * @param IConfig $config
60
+     * @param IUserManager $userManager
61
+     * @param IGroupManager $groupManager
62
+     * @param AccountManager $accountManager
63
+     * @param IFactory $l10nFactory
64
+     * @param IL10N $l
65
+     */
66
+    public function __construct(
67
+        IConfig $config,
68
+        IUserManager $userManager,
69
+        IGroupManager $groupManager,
70
+        AccountManager $accountManager,
71
+        IAppManager $appManager,
72
+        IFactory $l10nFactory,
73
+        IL10N $l
74
+    ) {
75
+        $this->config = $config;
76
+        $this->userManager = $userManager;
77
+        $this->accountManager = $accountManager;
78
+        $this->groupManager = $groupManager;
79
+        $this->appManager = $appManager;
80
+        $this->l10nFactory = $l10nFactory;
81
+        $this->l = $l;
82
+    }
83
+
84
+    /**
85
+     * @return TemplateResponse returns the instance with all parameters set, ready to be rendered
86
+     * @since 9.1
87
+     */
88
+    public function getForm() {
89
+        $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
90
+        $lookupServerUploadEnabled = false;
91
+        if($federatedFileSharingEnabled) {
92
+            $federatedFileSharing = new Application();
93
+            $shareProvider = $federatedFileSharing->getFederatedShareProvider();
94
+            $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
95
+        }
96
+
97
+        $uid = \OC_User::getUser();
98
+        $user = $this->userManager->get($uid);
99
+        $userData = $this->accountManager->getUser($user);
100
+
101
+        $storageInfo = \OC_Helper::getStorageInfo('/');
102
+        if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) {
103
+            $totalSpace = $this->l->t('Unlimited');
104
+        } else {
105
+            $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
106
+        }
107
+
108
+        $languageParameters = $this->getLanguages($user);
109
+        $messageParameters = $this->getMessageParameters($userData);
110
+
111
+        $parameters = [
112
+            'total_space' => $totalSpace,
113
+            'usage' => \OC_Helper::humanFileSize($storageInfo['used']),
114
+            'usage_relative' => round($storageInfo['relative']),
115
+            'quota' => $storageInfo['quota'],
116
+            'avatarChangeSupported' => $user->canChangeAvatar(),
117
+            'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
118
+            'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'],
119
+            'displayNameChangeSupported' => $user->canChangeDisplayName(),
120
+            'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'],
121
+            'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
122
+            'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'],
123
+            'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'],
124
+            'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'],
125
+            'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'],
126
+            'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'],
127
+            'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'],
128
+            'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'],
129
+            'website' =>  $userData[AccountManager::PROPERTY_WEBSITE]['value'],
130
+            'websiteScope' =>  $userData[AccountManager::PROPERTY_WEBSITE]['scope'],
131
+            'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'],
132
+            'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'],
133
+            'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
134
+            'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
135
+            'groups' => $this->getGroups($user),
136
+            'passwordChangeSupported' => $user->canChangePassword(),
137
+        ] + $messageParameters + $languageParameters;
138
+
139
+
140
+        return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
141
+    }
142
+
143
+    /**
144
+     * @return string the section ID, e.g. 'sharing'
145
+     * @since 9.1
146
+     */
147
+    public function getSection() {
148
+        return 'personal-info';
149
+    }
150
+
151
+    /**
152
+     * @return int whether the form should be rather on the top or bottom of
153
+     * the admin section. The forms are arranged in ascending order of the
154
+     * priority values. It is required to return a value between 0 and 100.
155
+     *
156
+     * E.g.: 70
157
+     * @since 9.1
158
+     */
159
+    public function getPriority() {
160
+        return 10;
161
+    }
162
+
163
+    /**
164
+     * returns a sorted list of the user's group GIDs
165
+     *
166
+     * @param IUser $user
167
+     * @return array
168
+     */
169
+    private function getGroups(IUser $user) {
170
+        $groups = array_map(
171
+            function(IGroup $group) {
172
+                return $group->getDisplayName();
173
+            },
174
+            $this->groupManager->getUserGroups($user)
175
+        );
176
+        sort($groups);
177
+
178
+        return $groups;
179
+    }
180
+
181
+    /**
182
+     * returns the user language, common language and other languages in an
183
+     * associative array
184
+     *
185
+     * @param IUser $user
186
+     * @return array
187
+     */
188
+    private function getLanguages(IUser $user) {
189
+        $forceLanguage = $this->config->getSystemValue('force_language', false);
190
+        if($forceLanguage !== false) {
191
+            return [];
192
+        }
193
+
194
+        $uid = $user->getUID();
195
+
196
+        $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
197
+        $languages = $this->l10nFactory->getLanguages();
198
+
199
+        // associate the user language with the proper array
200
+        $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code'));
201
+        $userLang = $languages['commonlanguages'][$userLangIndex];
202
+        // search in the other languages
203
+        if ($userLangIndex === false) {
204
+            $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code'));		
205
+            $userLang = $languages['languages'][$userLangIndex];
206
+        }
207
+        // if user language is not available but set somehow: show the actual code as name
208
+        if (!is_array($userLang)) {
209
+            $userLang = [
210
+                'code' => $userConfLang,
211
+                'name' => $userConfLang,
212
+            ];
213
+        }
214
+
215
+        return array_merge(
216
+            array('activelanguage' => $userLang),
217
+            $languages
218
+        );
219
+    }
220
+
221
+    /**
222
+     * @param array $userData
223
+     * @return array
224
+     */
225
+    private function getMessageParameters(array $userData) {
226
+        $needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER];
227
+        $messageParameters = [];
228
+        foreach ($needVerifyMessage as $property) {
229
+            switch ($userData[$property]['verified']) {
230
+                case AccountManager::VERIFIED:
231
+                    $message = $this->l->t('Verifying');
232
+                    break;
233
+                case AccountManager::VERIFICATION_IN_PROGRESS:
234
+                    $message = $this->l->t('Verifying …');
235
+                    break;
236
+                default:
237
+                    $message = $this->l->t('Verify');
238
+            }
239
+            $messageParameters[$property . 'Message'] = $message;
240
+        }
241
+        return $messageParameters;
242
+    }
243 243
 
244 244
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 	public function getForm() {
89 89
 		$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
90 90
 		$lookupServerUploadEnabled = false;
91
-		if($federatedFileSharingEnabled) {
91
+		if ($federatedFileSharingEnabled) {
92 92
 			$federatedFileSharing = new Application();
93 93
 			$shareProvider = $federatedFileSharing->getFederatedShareProvider();
94 94
 			$lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 	 */
188 188
 	private function getLanguages(IUser $user) {
189 189
 		$forceLanguage = $this->config->getSystemValue('force_language', false);
190
-		if($forceLanguage !== false) {
190
+		if ($forceLanguage !== false) {
191 191
 			return [];
192 192
 		}
193 193
 
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
 				default:
237 237
 					$message = $this->l->t('Verify');
238 238
 			}
239
-			$messageParameters[$property . 'Message'] = $message;
239
+			$messageParameters[$property.'Message'] = $message;
240 240
 		}
241 241
 		return $messageParameters;
242 242
 	}
Please login to merge, or discard this patch.
lib/private/L10N/Factory.php 2 patches
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -40,480 +40,480 @@
 block discarded – undo
40 40
  */
41 41
 class Factory implements IFactory {
42 42
 
43
-	/** @var string */
44
-	protected $requestLanguage = '';
45
-
46
-	/**
47
-	 * cached instances
48
-	 * @var array Structure: Lang => App => \OCP\IL10N
49
-	 */
50
-	protected $instances = [];
51
-
52
-	/**
53
-	 * @var array Structure: App => string[]
54
-	 */
55
-	protected $availableLanguages = [];
56
-
57
-	/**
58
-	 * @var array Structure: string => callable
59
-	 */
60
-	protected $pluralFunctions = [];
61
-
62
-	const COMMON_LANGUAGE_CODES = [
63
-		'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it',
64
-		'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
65
-	];
66
-
67
-	/** @var IConfig */
68
-	protected $config;
69
-
70
-	/** @var IRequest */
71
-	protected $request;
72
-
73
-	/** @var IUserSession */
74
-	protected $userSession;
75
-
76
-	/** @var string */
77
-	protected $serverRoot;
78
-
79
-	/**
80
-	 * @param IConfig $config
81
-	 * @param IRequest $request
82
-	 * @param IUserSession $userSession
83
-	 * @param string $serverRoot
84
-	 */
85
-	public function __construct(IConfig $config,
86
-								IRequest $request,
87
-								IUserSession $userSession,
88
-								$serverRoot) {
89
-		$this->config = $config;
90
-		$this->request = $request;
91
-		$this->userSession = $userSession;
92
-		$this->serverRoot = $serverRoot;
93
-	}
94
-
95
-	/**
96
-	 * Get a language instance
97
-	 *
98
-	 * @param string $app
99
-	 * @param string|null $lang
100
-	 * @return \OCP\IL10N
101
-	 */
102
-	public function get($app, $lang = null) {
103
-		$app = \OC_App::cleanAppId($app);
104
-		if ($lang !== null) {
105
-			$lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang);
106
-		}
107
-
108
-		$forceLang = $this->config->getSystemValue('force_language', false);
109
-		if (is_string($forceLang)) {
110
-			$lang = $forceLang;
111
-		}
112
-
113
-		if ($lang === null || !$this->languageExists($app, $lang)) {
114
-			$lang = $this->findLanguage($app);
115
-		}
116
-
117
-		if (!isset($this->instances[$lang][$app])) {
118
-			$this->instances[$lang][$app] = new L10N(
119
-				$this, $app, $lang,
120
-				$this->getL10nFilesForApp($app, $lang)
121
-			);
122
-		}
123
-
124
-		return $this->instances[$lang][$app];
125
-	}
126
-
127
-	/**
128
-	 * Find the best language
129
-	 *
130
-	 * @param string|null $app App id or null for core
131
-	 * @return string language If nothing works it returns 'en'
132
-	 */
133
-	public function findLanguage($app = null) {
134
-		if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) {
135
-			return $this->requestLanguage;
136
-		}
137
-
138
-		/**
139
-		 * At this point Nextcloud might not yet be installed and thus the lookup
140
-		 * in the preferences table might fail. For this reason we need to check
141
-		 * whether the instance has already been installed
142
-		 *
143
-		 * @link https://github.com/owncloud/core/issues/21955
144
-		 */
145
-		if ($this->config->getSystemValue('installed', false)) {
146
-			$userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() :  null;
147
-			if (!is_null($userId)) {
148
-				$userLang = $this->config->getUserValue($userId, 'core', 'lang', null);
149
-			} else {
150
-				$userLang = null;
151
-			}
152
-		} else {
153
-			$userId = null;
154
-			$userLang = null;
155
-		}
156
-
157
-		if ($userLang) {
158
-			$this->requestLanguage = $userLang;
159
-			if ($this->languageExists($app, $userLang)) {
160
-				return $userLang;
161
-			}
162
-		}
163
-
164
-		try {
165
-			// Try to get the language from the Request
166
-			$lang = $this->getLanguageFromRequest($app);
167
-			if ($userId !== null && $app === null && !$userLang) {
168
-				$this->config->setUserValue($userId, 'core', 'lang', $lang);
169
-			}
170
-			return $lang;
171
-		} catch (LanguageNotFoundException $e) {
172
-			// Finding language from request failed fall back to default language
173
-			$defaultLanguage = $this->config->getSystemValue('default_language', false);
174
-			if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) {
175
-				return $defaultLanguage;
176
-			}
177
-		}
178
-
179
-		// We could not find any language so fall back to english
180
-		return 'en';
181
-	}
182
-
183
-	/**
184
-	 * Find all available languages for an app
185
-	 *
186
-	 * @param string|null $app App id or null for core
187
-	 * @return array an array of available languages
188
-	 */
189
-	public function findAvailableLanguages($app = null) {
190
-		$key = $app;
191
-		if ($key === null) {
192
-			$key = 'null';
193
-		}
194
-
195
-		// also works with null as key
196
-		if (!empty($this->availableLanguages[$key])) {
197
-			return $this->availableLanguages[$key];
198
-		}
199
-
200
-		$available = ['en']; //english is always available
201
-		$dir = $this->findL10nDir($app);
202
-		if (is_dir($dir)) {
203
-			$files = scandir($dir);
204
-			if ($files !== false) {
205
-				foreach ($files as $file) {
206
-					if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
207
-						$available[] = substr($file, 0, -5);
208
-					}
209
-				}
210
-			}
211
-		}
212
-
213
-		// merge with translations from theme
214
-		$theme = $this->config->getSystemValue('theme');
215
-		if (!empty($theme)) {
216
-			$themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot));
217
-
218
-			if (is_dir($themeDir)) {
219
-				$files = scandir($themeDir);
220
-				if ($files !== false) {
221
-					foreach ($files as $file) {
222
-						if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
223
-							$available[] = substr($file, 0, -5);
224
-						}
225
-					}
226
-				}
227
-			}
228
-		}
229
-
230
-		$this->availableLanguages[$key] = $available;
231
-		return $available;
232
-	}
233
-
234
-	/**
235
-	 * @param string|null $app App id or null for core
236
-	 * @param string $lang
237
-	 * @return bool
238
-	 */
239
-	public function languageExists($app, $lang) {
240
-		if ($lang === 'en') {//english is always available
241
-			return true;
242
-		}
243
-
244
-		$languages = $this->findAvailableLanguages($app);
245
-		return array_search($lang, $languages) !== false;
246
-	}
247
-
248
-	/**
249
-	 * @param string|null $app
250
-	 * @return string
251
-	 * @throws LanguageNotFoundException
252
-	 */
253
-	private function getLanguageFromRequest($app) {
254
-		$header = $this->request->getHeader('ACCEPT_LANGUAGE');
255
-		if ($header !== '') {
256
-			$available = $this->findAvailableLanguages($app);
257
-
258
-			// E.g. make sure that 'de' is before 'de_DE'.
259
-			sort($available);
260
-
261
-			$preferences = preg_split('/,\s*/', strtolower($header));
262
-			foreach ($preferences as $preference) {
263
-				list($preferred_language) = explode(';', $preference);
264
-				$preferred_language = str_replace('-', '_', $preferred_language);
265
-
266
-				foreach ($available as $available_language) {
267
-					if ($preferred_language === strtolower($available_language)) {
268
-						return $this->respectDefaultLanguage($app, $available_language);
269
-					}
270
-				}
271
-
272
-				// Fallback from de_De to de
273
-				foreach ($available as $available_language) {
274
-					if (substr($preferred_language, 0, 2) === $available_language) {
275
-						return $available_language;
276
-					}
277
-				}
278
-			}
279
-		}
280
-
281
-		throw new LanguageNotFoundException();
282
-	}
283
-
284
-	/**
285
-	 * if default language is set to de_DE (formal German) this should be
286
-	 * preferred to 'de' (non-formal German) if possible
287
-	 *
288
-	 * @param string|null $app
289
-	 * @param string $lang
290
-	 * @return string
291
-	 */
292
-	protected function respectDefaultLanguage($app, $lang) {
293
-		$result = $lang;
294
-		$defaultLanguage = $this->config->getSystemValue('default_language', false);
295
-
296
-		// use formal version of german ("Sie" instead of "Du") if the default
297
-		// language is set to 'de_DE' if possible
298
-		if (is_string($defaultLanguage) &&
299
-			strtolower($lang) === 'de' &&
300
-			strtolower($defaultLanguage) === 'de_de' &&
301
-			$this->languageExists($app, 'de_DE')
302
-		) {
303
-			$result = 'de_DE';
304
-		}
305
-
306
-		return $result;
307
-	}
308
-
309
-	/**
310
-	 * Checks if $sub is a subdirectory of $parent
311
-	 *
312
-	 * @param string $sub
313
-	 * @param string $parent
314
-	 * @return bool
315
-	 */
316
-	private function isSubDirectory($sub, $parent) {
317
-		// Check whether $sub contains no ".."
318
-		if (strpos($sub, '..') !== false) {
319
-			return false;
320
-		}
321
-
322
-		// Check whether $sub is a subdirectory of $parent
323
-		if (strpos($sub, $parent) === 0) {
324
-			return true;
325
-		}
326
-
327
-		return false;
328
-	}
329
-
330
-	/**
331
-	 * Get a list of language files that should be loaded
332
-	 *
333
-	 * @param string $app
334
-	 * @param string $lang
335
-	 * @return string[]
336
-	 */
337
-	// FIXME This method is only public, until OC_L10N does not need it anymore,
338
-	// FIXME This is also the reason, why it is not in the public interface
339
-	public function getL10nFilesForApp($app, $lang) {
340
-		$languageFiles = [];
341
-
342
-		$i18nDir = $this->findL10nDir($app);
343
-		$transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
344
-
345
-		if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
346
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
347
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/')
348
-				|| $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')
349
-			)
350
-			&& file_exists($transFile)) {
351
-			// load the translations file
352
-			$languageFiles[] = $transFile;
353
-		}
354
-
355
-		// merge with translations from theme
356
-		$theme = $this->config->getSystemValue('theme');
357
-		if (!empty($theme)) {
358
-			$transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot));
359
-			if (file_exists($transFile)) {
360
-				$languageFiles[] = $transFile;
361
-			}
362
-		}
363
-
364
-		return $languageFiles;
365
-	}
366
-
367
-	/**
368
-	 * find the l10n directory
369
-	 *
370
-	 * @param string $app App id or empty string for core
371
-	 * @return string directory
372
-	 */
373
-	protected function findL10nDir($app = null) {
374
-		if (in_array($app, ['core', 'lib', 'settings'])) {
375
-			if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
376
-				return $this->serverRoot . '/' . $app . '/l10n/';
377
-			}
378
-		} else if ($app && \OC_App::getAppPath($app) !== false) {
379
-			// Check if the app is in the app folder
380
-			return \OC_App::getAppPath($app) . '/l10n/';
381
-		}
382
-		return $this->serverRoot . '/core/l10n/';
383
-	}
384
-
385
-
386
-	/**
387
-	 * Creates a function from the plural string
388
-	 *
389
-	 * Parts of the code is copied from Habari:
390
-	 * https://github.com/habari/system/blob/master/classes/locale.php
391
-	 * @param string $string
392
-	 * @return string
393
-	 */
394
-	public function createPluralFunction($string) {
395
-		if (isset($this->pluralFunctions[$string])) {
396
-			return $this->pluralFunctions[$string];
397
-		}
398
-
399
-		if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
400
-			// sanitize
401
-			$nplurals = preg_replace( '/[^0-9]/', '', $matches[1] );
402
-			$plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] );
403
-
404
-			$body = str_replace(
405
-				array( 'plural', 'n', '$n$plurals', ),
406
-				array( '$plural', '$n', '$nplurals', ),
407
-				'nplurals='. $nplurals . '; plural=' . $plural
408
-			);
409
-
410
-			// add parents
411
-			// important since PHP's ternary evaluates from left to right
412
-			$body .= ';';
413
-			$res = '';
414
-			$p = 0;
415
-			$length = strlen($body);
416
-			for($i = 0; $i < $length; $i++) {
417
-				$ch = $body[$i];
418
-				switch ( $ch ) {
419
-					case '?':
420
-						$res .= ' ? (';
421
-						$p++;
422
-						break;
423
-					case ':':
424
-						$res .= ') : (';
425
-						break;
426
-					case ';':
427
-						$res .= str_repeat( ')', $p ) . ';';
428
-						$p = 0;
429
-						break;
430
-					default:
431
-						$res .= $ch;
432
-				}
433
-			}
434
-
435
-			$body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);';
436
-			$function = create_function('$n', $body);
437
-			$this->pluralFunctions[$string] = $function;
438
-			return $function;
439
-		} else {
440
-			// default: one plural form for all cases but n==1 (english)
441
-			$function = create_function(
442
-				'$n',
443
-				'$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);'
444
-			);
445
-			$this->pluralFunctions[$string] = $function;
446
-			return $function;
447
-		}
448
-	}
449
-
450
-	/**
451
-	 * returns the common language and other languages in an
452
-	 * associative array
453
-	 *
454
-	 * @return array
455
-	 */
456
-	public function getLanguages() {
457
-		$forceLanguage = $this->config->getSystemValue('force_language', false);
458
-		if ($forceLanguage !== false) {
459
-			return [];
460
-		}
461
-
462
-		$languageCodes = $this->findAvailableLanguages();
463
-
464
-		$commonLanguages = [];
465
-		$languages = [];
466
-
467
-		foreach($languageCodes as $lang) {
468
-			$l = $this->get('lib', $lang);
469
-			// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
470
-			$potentialName = (string) $l->t('__language_name__');
471
-			if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
472
-				$ln = array(
473
-					'code' => $lang,
474
-					'name' => $potentialName
475
-				);
476
-			} else if ($lang === 'en') {
477
-				$ln = array(
478
-					'code' => $lang,
479
-					'name' => 'English (US)'
480
-				);
481
-			} else {//fallback to language code
482
-				$ln = array(
483
-					'code' => $lang,
484
-					'name' => $lang
485
-				);
486
-			}
487
-
488
-			// put appropriate languages into appropriate arrays, to print them sorted
489
-			// common languages -> divider -> other languages
490
-			if (in_array($lang, self::COMMON_LANGUAGE_CODES)) {
491
-				$commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)] = $ln;
492
-			} else {
493
-				$languages[] = $ln;
494
-			}
495
-		}
496
-
497
-		ksort($commonLanguages);
498
-
499
-		// sort now by displayed language not the iso-code
500
-		usort( $languages, function ($a, $b) {
501
-			if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
502
-				// If a doesn't have a name, but b does, list b before a
503
-				return 1;
504
-			}
505
-			if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
506
-				// If a does have a name, but b doesn't, list a before b
507
-				return -1;
508
-			}
509
-			// Otherwise compare the names
510
-			return strcmp($a['name'], $b['name']);
511
-		});
512
-
513
-		return [
514
-			// reset indexes
515
-			'commonlanguages' => array_values($commonLanguages),
516
-			'languages' => $languages
517
-		];
518
-	}
43
+    /** @var string */
44
+    protected $requestLanguage = '';
45
+
46
+    /**
47
+     * cached instances
48
+     * @var array Structure: Lang => App => \OCP\IL10N
49
+     */
50
+    protected $instances = [];
51
+
52
+    /**
53
+     * @var array Structure: App => string[]
54
+     */
55
+    protected $availableLanguages = [];
56
+
57
+    /**
58
+     * @var array Structure: string => callable
59
+     */
60
+    protected $pluralFunctions = [];
61
+
62
+    const COMMON_LANGUAGE_CODES = [
63
+        'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it',
64
+        'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko'
65
+    ];
66
+
67
+    /** @var IConfig */
68
+    protected $config;
69
+
70
+    /** @var IRequest */
71
+    protected $request;
72
+
73
+    /** @var IUserSession */
74
+    protected $userSession;
75
+
76
+    /** @var string */
77
+    protected $serverRoot;
78
+
79
+    /**
80
+     * @param IConfig $config
81
+     * @param IRequest $request
82
+     * @param IUserSession $userSession
83
+     * @param string $serverRoot
84
+     */
85
+    public function __construct(IConfig $config,
86
+                                IRequest $request,
87
+                                IUserSession $userSession,
88
+                                $serverRoot) {
89
+        $this->config = $config;
90
+        $this->request = $request;
91
+        $this->userSession = $userSession;
92
+        $this->serverRoot = $serverRoot;
93
+    }
94
+
95
+    /**
96
+     * Get a language instance
97
+     *
98
+     * @param string $app
99
+     * @param string|null $lang
100
+     * @return \OCP\IL10N
101
+     */
102
+    public function get($app, $lang = null) {
103
+        $app = \OC_App::cleanAppId($app);
104
+        if ($lang !== null) {
105
+            $lang = str_replace(array('\0', '/', '\\', '..'), '', (string) $lang);
106
+        }
107
+
108
+        $forceLang = $this->config->getSystemValue('force_language', false);
109
+        if (is_string($forceLang)) {
110
+            $lang = $forceLang;
111
+        }
112
+
113
+        if ($lang === null || !$this->languageExists($app, $lang)) {
114
+            $lang = $this->findLanguage($app);
115
+        }
116
+
117
+        if (!isset($this->instances[$lang][$app])) {
118
+            $this->instances[$lang][$app] = new L10N(
119
+                $this, $app, $lang,
120
+                $this->getL10nFilesForApp($app, $lang)
121
+            );
122
+        }
123
+
124
+        return $this->instances[$lang][$app];
125
+    }
126
+
127
+    /**
128
+     * Find the best language
129
+     *
130
+     * @param string|null $app App id or null for core
131
+     * @return string language If nothing works it returns 'en'
132
+     */
133
+    public function findLanguage($app = null) {
134
+        if ($this->requestLanguage !== '' && $this->languageExists($app, $this->requestLanguage)) {
135
+            return $this->requestLanguage;
136
+        }
137
+
138
+        /**
139
+         * At this point Nextcloud might not yet be installed and thus the lookup
140
+         * in the preferences table might fail. For this reason we need to check
141
+         * whether the instance has already been installed
142
+         *
143
+         * @link https://github.com/owncloud/core/issues/21955
144
+         */
145
+        if ($this->config->getSystemValue('installed', false)) {
146
+            $userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() :  null;
147
+            if (!is_null($userId)) {
148
+                $userLang = $this->config->getUserValue($userId, 'core', 'lang', null);
149
+            } else {
150
+                $userLang = null;
151
+            }
152
+        } else {
153
+            $userId = null;
154
+            $userLang = null;
155
+        }
156
+
157
+        if ($userLang) {
158
+            $this->requestLanguage = $userLang;
159
+            if ($this->languageExists($app, $userLang)) {
160
+                return $userLang;
161
+            }
162
+        }
163
+
164
+        try {
165
+            // Try to get the language from the Request
166
+            $lang = $this->getLanguageFromRequest($app);
167
+            if ($userId !== null && $app === null && !$userLang) {
168
+                $this->config->setUserValue($userId, 'core', 'lang', $lang);
169
+            }
170
+            return $lang;
171
+        } catch (LanguageNotFoundException $e) {
172
+            // Finding language from request failed fall back to default language
173
+            $defaultLanguage = $this->config->getSystemValue('default_language', false);
174
+            if ($defaultLanguage !== false && $this->languageExists($app, $defaultLanguage)) {
175
+                return $defaultLanguage;
176
+            }
177
+        }
178
+
179
+        // We could not find any language so fall back to english
180
+        return 'en';
181
+    }
182
+
183
+    /**
184
+     * Find all available languages for an app
185
+     *
186
+     * @param string|null $app App id or null for core
187
+     * @return array an array of available languages
188
+     */
189
+    public function findAvailableLanguages($app = null) {
190
+        $key = $app;
191
+        if ($key === null) {
192
+            $key = 'null';
193
+        }
194
+
195
+        // also works with null as key
196
+        if (!empty($this->availableLanguages[$key])) {
197
+            return $this->availableLanguages[$key];
198
+        }
199
+
200
+        $available = ['en']; //english is always available
201
+        $dir = $this->findL10nDir($app);
202
+        if (is_dir($dir)) {
203
+            $files = scandir($dir);
204
+            if ($files !== false) {
205
+                foreach ($files as $file) {
206
+                    if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
207
+                        $available[] = substr($file, 0, -5);
208
+                    }
209
+                }
210
+            }
211
+        }
212
+
213
+        // merge with translations from theme
214
+        $theme = $this->config->getSystemValue('theme');
215
+        if (!empty($theme)) {
216
+            $themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot));
217
+
218
+            if (is_dir($themeDir)) {
219
+                $files = scandir($themeDir);
220
+                if ($files !== false) {
221
+                    foreach ($files as $file) {
222
+                        if (substr($file, -5) === '.json' && substr($file, 0, 4) !== 'l10n') {
223
+                            $available[] = substr($file, 0, -5);
224
+                        }
225
+                    }
226
+                }
227
+            }
228
+        }
229
+
230
+        $this->availableLanguages[$key] = $available;
231
+        return $available;
232
+    }
233
+
234
+    /**
235
+     * @param string|null $app App id or null for core
236
+     * @param string $lang
237
+     * @return bool
238
+     */
239
+    public function languageExists($app, $lang) {
240
+        if ($lang === 'en') {//english is always available
241
+            return true;
242
+        }
243
+
244
+        $languages = $this->findAvailableLanguages($app);
245
+        return array_search($lang, $languages) !== false;
246
+    }
247
+
248
+    /**
249
+     * @param string|null $app
250
+     * @return string
251
+     * @throws LanguageNotFoundException
252
+     */
253
+    private function getLanguageFromRequest($app) {
254
+        $header = $this->request->getHeader('ACCEPT_LANGUAGE');
255
+        if ($header !== '') {
256
+            $available = $this->findAvailableLanguages($app);
257
+
258
+            // E.g. make sure that 'de' is before 'de_DE'.
259
+            sort($available);
260
+
261
+            $preferences = preg_split('/,\s*/', strtolower($header));
262
+            foreach ($preferences as $preference) {
263
+                list($preferred_language) = explode(';', $preference);
264
+                $preferred_language = str_replace('-', '_', $preferred_language);
265
+
266
+                foreach ($available as $available_language) {
267
+                    if ($preferred_language === strtolower($available_language)) {
268
+                        return $this->respectDefaultLanguage($app, $available_language);
269
+                    }
270
+                }
271
+
272
+                // Fallback from de_De to de
273
+                foreach ($available as $available_language) {
274
+                    if (substr($preferred_language, 0, 2) === $available_language) {
275
+                        return $available_language;
276
+                    }
277
+                }
278
+            }
279
+        }
280
+
281
+        throw new LanguageNotFoundException();
282
+    }
283
+
284
+    /**
285
+     * if default language is set to de_DE (formal German) this should be
286
+     * preferred to 'de' (non-formal German) if possible
287
+     *
288
+     * @param string|null $app
289
+     * @param string $lang
290
+     * @return string
291
+     */
292
+    protected function respectDefaultLanguage($app, $lang) {
293
+        $result = $lang;
294
+        $defaultLanguage = $this->config->getSystemValue('default_language', false);
295
+
296
+        // use formal version of german ("Sie" instead of "Du") if the default
297
+        // language is set to 'de_DE' if possible
298
+        if (is_string($defaultLanguage) &&
299
+            strtolower($lang) === 'de' &&
300
+            strtolower($defaultLanguage) === 'de_de' &&
301
+            $this->languageExists($app, 'de_DE')
302
+        ) {
303
+            $result = 'de_DE';
304
+        }
305
+
306
+        return $result;
307
+    }
308
+
309
+    /**
310
+     * Checks if $sub is a subdirectory of $parent
311
+     *
312
+     * @param string $sub
313
+     * @param string $parent
314
+     * @return bool
315
+     */
316
+    private function isSubDirectory($sub, $parent) {
317
+        // Check whether $sub contains no ".."
318
+        if (strpos($sub, '..') !== false) {
319
+            return false;
320
+        }
321
+
322
+        // Check whether $sub is a subdirectory of $parent
323
+        if (strpos($sub, $parent) === 0) {
324
+            return true;
325
+        }
326
+
327
+        return false;
328
+    }
329
+
330
+    /**
331
+     * Get a list of language files that should be loaded
332
+     *
333
+     * @param string $app
334
+     * @param string $lang
335
+     * @return string[]
336
+     */
337
+    // FIXME This method is only public, until OC_L10N does not need it anymore,
338
+    // FIXME This is also the reason, why it is not in the public interface
339
+    public function getL10nFilesForApp($app, $lang) {
340
+        $languageFiles = [];
341
+
342
+        $i18nDir = $this->findL10nDir($app);
343
+        $transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
344
+
345
+        if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
346
+                || $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
347
+                || $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/')
348
+                || $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')
349
+            )
350
+            && file_exists($transFile)) {
351
+            // load the translations file
352
+            $languageFiles[] = $transFile;
353
+        }
354
+
355
+        // merge with translations from theme
356
+        $theme = $this->config->getSystemValue('theme');
357
+        if (!empty($theme)) {
358
+            $transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot));
359
+            if (file_exists($transFile)) {
360
+                $languageFiles[] = $transFile;
361
+            }
362
+        }
363
+
364
+        return $languageFiles;
365
+    }
366
+
367
+    /**
368
+     * find the l10n directory
369
+     *
370
+     * @param string $app App id or empty string for core
371
+     * @return string directory
372
+     */
373
+    protected function findL10nDir($app = null) {
374
+        if (in_array($app, ['core', 'lib', 'settings'])) {
375
+            if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
376
+                return $this->serverRoot . '/' . $app . '/l10n/';
377
+            }
378
+        } else if ($app && \OC_App::getAppPath($app) !== false) {
379
+            // Check if the app is in the app folder
380
+            return \OC_App::getAppPath($app) . '/l10n/';
381
+        }
382
+        return $this->serverRoot . '/core/l10n/';
383
+    }
384
+
385
+
386
+    /**
387
+     * Creates a function from the plural string
388
+     *
389
+     * Parts of the code is copied from Habari:
390
+     * https://github.com/habari/system/blob/master/classes/locale.php
391
+     * @param string $string
392
+     * @return string
393
+     */
394
+    public function createPluralFunction($string) {
395
+        if (isset($this->pluralFunctions[$string])) {
396
+            return $this->pluralFunctions[$string];
397
+        }
398
+
399
+        if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
400
+            // sanitize
401
+            $nplurals = preg_replace( '/[^0-9]/', '', $matches[1] );
402
+            $plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] );
403
+
404
+            $body = str_replace(
405
+                array( 'plural', 'n', '$n$plurals', ),
406
+                array( '$plural', '$n', '$nplurals', ),
407
+                'nplurals='. $nplurals . '; plural=' . $plural
408
+            );
409
+
410
+            // add parents
411
+            // important since PHP's ternary evaluates from left to right
412
+            $body .= ';';
413
+            $res = '';
414
+            $p = 0;
415
+            $length = strlen($body);
416
+            for($i = 0; $i < $length; $i++) {
417
+                $ch = $body[$i];
418
+                switch ( $ch ) {
419
+                    case '?':
420
+                        $res .= ' ? (';
421
+                        $p++;
422
+                        break;
423
+                    case ':':
424
+                        $res .= ') : (';
425
+                        break;
426
+                    case ';':
427
+                        $res .= str_repeat( ')', $p ) . ';';
428
+                        $p = 0;
429
+                        break;
430
+                    default:
431
+                        $res .= $ch;
432
+                }
433
+            }
434
+
435
+            $body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);';
436
+            $function = create_function('$n', $body);
437
+            $this->pluralFunctions[$string] = $function;
438
+            return $function;
439
+        } else {
440
+            // default: one plural form for all cases but n==1 (english)
441
+            $function = create_function(
442
+                '$n',
443
+                '$nplurals=2;$plural=($n==1?0:1);return ($plural>=$nplurals?$nplurals-1:$plural);'
444
+            );
445
+            $this->pluralFunctions[$string] = $function;
446
+            return $function;
447
+        }
448
+    }
449
+
450
+    /**
451
+     * returns the common language and other languages in an
452
+     * associative array
453
+     *
454
+     * @return array
455
+     */
456
+    public function getLanguages() {
457
+        $forceLanguage = $this->config->getSystemValue('force_language', false);
458
+        if ($forceLanguage !== false) {
459
+            return [];
460
+        }
461
+
462
+        $languageCodes = $this->findAvailableLanguages();
463
+
464
+        $commonLanguages = [];
465
+        $languages = [];
466
+
467
+        foreach($languageCodes as $lang) {
468
+            $l = $this->get('lib', $lang);
469
+            // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
470
+            $potentialName = (string) $l->t('__language_name__');
471
+            if ($l->getLanguageCode() === $lang && $potentialName[0] !== '_') {//first check if the language name is in the translation file
472
+                $ln = array(
473
+                    'code' => $lang,
474
+                    'name' => $potentialName
475
+                );
476
+            } else if ($lang === 'en') {
477
+                $ln = array(
478
+                    'code' => $lang,
479
+                    'name' => 'English (US)'
480
+                );
481
+            } else {//fallback to language code
482
+                $ln = array(
483
+                    'code' => $lang,
484
+                    'name' => $lang
485
+                );
486
+            }
487
+
488
+            // put appropriate languages into appropriate arrays, to print them sorted
489
+            // common languages -> divider -> other languages
490
+            if (in_array($lang, self::COMMON_LANGUAGE_CODES)) {
491
+                $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)] = $ln;
492
+            } else {
493
+                $languages[] = $ln;
494
+            }
495
+        }
496
+
497
+        ksort($commonLanguages);
498
+
499
+        // sort now by displayed language not the iso-code
500
+        usort( $languages, function ($a, $b) {
501
+            if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
502
+                // If a doesn't have a name, but b does, list b before a
503
+                return 1;
504
+            }
505
+            if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) {
506
+                // If a does have a name, but b doesn't, list a before b
507
+                return -1;
508
+            }
509
+            // Otherwise compare the names
510
+            return strcmp($a['name'], $b['name']);
511
+        });
512
+
513
+        return [
514
+            // reset indexes
515
+            'commonlanguages' => array_values($commonLanguages),
516
+            'languages' => $languages
517
+        ];
518
+    }
519 519
 }
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		 * @link https://github.com/owncloud/core/issues/21955
144 144
 		 */
145 145
 		if ($this->config->getSystemValue('installed', false)) {
146
-			$userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() :  null;
146
+			$userId = !is_null($this->userSession->getUser()) ? $this->userSession->getUser()->getUID() : null;
147 147
 			if (!is_null($userId)) {
148 148
 				$userLang = $this->config->getUserValue($userId, 'core', 'lang', null);
149 149
 			} else {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 		// merge with translations from theme
214 214
 		$theme = $this->config->getSystemValue('theme');
215 215
 		if (!empty($theme)) {
216
-			$themeDir = $this->serverRoot . '/themes/' . $theme . substr($dir, strlen($this->serverRoot));
216
+			$themeDir = $this->serverRoot.'/themes/'.$theme.substr($dir, strlen($this->serverRoot));
217 217
 
218 218
 			if (is_dir($themeDir)) {
219 219
 				$files = scandir($themeDir);
@@ -340,12 +340,12 @@  discard block
 block discarded – undo
340 340
 		$languageFiles = [];
341 341
 
342 342
 		$i18nDir = $this->findL10nDir($app);
343
-		$transFile = strip_tags($i18nDir) . strip_tags($lang) . '.json';
343
+		$transFile = strip_tags($i18nDir).strip_tags($lang).'.json';
344 344
 
345
-		if (($this->isSubDirectory($transFile, $this->serverRoot . '/core/l10n/')
346
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/lib/l10n/')
347
-				|| $this->isSubDirectory($transFile, $this->serverRoot . '/settings/l10n/')
348
-				|| $this->isSubDirectory($transFile, \OC_App::getAppPath($app) . '/l10n/')
345
+		if (($this->isSubDirectory($transFile, $this->serverRoot.'/core/l10n/')
346
+				|| $this->isSubDirectory($transFile, $this->serverRoot.'/lib/l10n/')
347
+				|| $this->isSubDirectory($transFile, $this->serverRoot.'/settings/l10n/')
348
+				|| $this->isSubDirectory($transFile, \OC_App::getAppPath($app).'/l10n/')
349 349
 			)
350 350
 			&& file_exists($transFile)) {
351 351
 			// load the translations file
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 		// merge with translations from theme
356 356
 		$theme = $this->config->getSystemValue('theme');
357 357
 		if (!empty($theme)) {
358
-			$transFile = $this->serverRoot . '/themes/' . $theme . substr($transFile, strlen($this->serverRoot));
358
+			$transFile = $this->serverRoot.'/themes/'.$theme.substr($transFile, strlen($this->serverRoot));
359 359
 			if (file_exists($transFile)) {
360 360
 				$languageFiles[] = $transFile;
361 361
 			}
@@ -372,14 +372,14 @@  discard block
 block discarded – undo
372 372
 	 */
373 373
 	protected function findL10nDir($app = null) {
374 374
 		if (in_array($app, ['core', 'lib', 'settings'])) {
375
-			if (file_exists($this->serverRoot . '/' . $app . '/l10n/')) {
376
-				return $this->serverRoot . '/' . $app . '/l10n/';
375
+			if (file_exists($this->serverRoot.'/'.$app.'/l10n/')) {
376
+				return $this->serverRoot.'/'.$app.'/l10n/';
377 377
 			}
378 378
 		} else if ($app && \OC_App::getAppPath($app) !== false) {
379 379
 			// Check if the app is in the app folder
380
-			return \OC_App::getAppPath($app) . '/l10n/';
380
+			return \OC_App::getAppPath($app).'/l10n/';
381 381
 		}
382
-		return $this->serverRoot . '/core/l10n/';
382
+		return $this->serverRoot.'/core/l10n/';
383 383
 	}
384 384
 
385 385
 
@@ -396,15 +396,15 @@  discard block
 block discarded – undo
396 396
 			return $this->pluralFunctions[$string];
397 397
 		}
398 398
 
399
-		if (preg_match( '/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
399
+		if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s*plural=(.*)$/u', $string, $matches)) {
400 400
 			// sanitize
401
-			$nplurals = preg_replace( '/[^0-9]/', '', $matches[1] );
402
-			$plural = preg_replace( '#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2] );
401
+			$nplurals = preg_replace('/[^0-9]/', '', $matches[1]);
402
+			$plural = preg_replace('#[^n0-9:\(\)\?\|\&=!<>+*/\%-]#', '', $matches[2]);
403 403
 
404 404
 			$body = str_replace(
405
-				array( 'plural', 'n', '$n$plurals', ),
406
-				array( '$plural', '$n', '$nplurals', ),
407
-				'nplurals='. $nplurals . '; plural=' . $plural
405
+				array('plural', 'n', '$n$plurals',),
406
+				array('$plural', '$n', '$nplurals',),
407
+				'nplurals='.$nplurals.'; plural='.$plural
408 408
 			);
409 409
 
410 410
 			// add parents
@@ -413,9 +413,9 @@  discard block
 block discarded – undo
413 413
 			$res = '';
414 414
 			$p = 0;
415 415
 			$length = strlen($body);
416
-			for($i = 0; $i < $length; $i++) {
416
+			for ($i = 0; $i < $length; $i++) {
417 417
 				$ch = $body[$i];
418
-				switch ( $ch ) {
418
+				switch ($ch) {
419 419
 					case '?':
420 420
 						$res .= ' ? (';
421 421
 						$p++;
@@ -424,7 +424,7 @@  discard block
 block discarded – undo
424 424
 						$res .= ') : (';
425 425
 						break;
426 426
 					case ';':
427
-						$res .= str_repeat( ')', $p ) . ';';
427
+						$res .= str_repeat(')', $p).';';
428 428
 						$p = 0;
429 429
 						break;
430 430
 					default:
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
 				}
433 433
 			}
434 434
 
435
-			$body = $res . 'return ($plural>=$nplurals?$nplurals-1:$plural);';
435
+			$body = $res.'return ($plural>=$nplurals?$nplurals-1:$plural);';
436 436
 			$function = create_function('$n', $body);
437 437
 			$this->pluralFunctions[$string] = $function;
438 438
 			return $function;
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 		$commonLanguages = [];
465 465
 		$languages = [];
466 466
 
467
-		foreach($languageCodes as $lang) {
467
+		foreach ($languageCodes as $lang) {
468 468
 			$l = $this->get('lib', $lang);
469 469
 			// TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version
470 470
 			$potentialName = (string) $l->t('__language_name__');
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 		ksort($commonLanguages);
498 498
 
499 499
 		// sort now by displayed language not the iso-code
500
-		usort( $languages, function ($a, $b) {
500
+		usort($languages, function($a, $b) {
501 501
 			if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) {
502 502
 				// If a doesn't have a name, but b does, list b before a
503 503
 				return 1;
Please login to merge, or discard this patch.
settings/templates/settings.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 style('settings', 'settings');
21 21
 
22 22
 // Did we have some data to inject ?
23
-if(is_array($_['serverData'])) {
23
+if (is_array($_['serverData'])) {
24 24
 ?>
25
-<span id="serverData" data-server="<?php p(json_encode($_['serverData']));?>"></span>
25
+<span id="serverData" data-server="<?php p(json_encode($_['serverData'])); ?>"></span>
26 26
 <?php } ?>
Please login to merge, or discard this patch.
settings/Controller/UsersController.php 3 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
 		} else {
235 235
 			/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
236 236
 			$gids = array();
237
-			foreach($groups as $group) {
237
+			foreach ($groups as $group) {
238 238
 				if (isset($group['id'])) {
239 239
 					$gids[] = $group['id'];
240 240
 				}
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
 		
264 264
 		/* TOTAL USERS COUNT */
265 265
 		$userCount = array_reduce($this->userManager->countUsers(), function($v, $w) {
266
-			return $v + (int)$w;
266
+			return $v + (int) $w;
267 267
 		}, 0);
268 268
 		
269 269
 		/* LANGUAGES */
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		$serverData['subadmins'] = $subAdmins;
279 279
 		$serverData['sortGroups'] = $sortGroupsBy;
280 280
 		$serverData['quotaPreset'] = $quotaPreset;
281
-		$serverData['userCount'] = $userCount-$disabledUsers;
281
+		$serverData['userCount'] = $userCount - $disabledUsers;
282 282
 		$serverData['languages'] = $languages;
283 283
 		$serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
284 284
 		// Settings
@@ -436,11 +436,11 @@  discard block
 block discarded – undo
436 436
 
437 437
 		$accountData = $this->accountManager->getUser($user);
438 438
 		$cloudId = $user->getCloudId();
439
-		$message = 'Use my Federated Cloud ID to share with me: ' . $cloudId;
439
+		$message = 'Use my Federated Cloud ID to share with me: '.$cloudId;
440 440
 		$signature = $this->signMessage($user, $message);
441 441
 
442
-		$code = $message . ' ' . $signature;
443
-		$codeMd5 = $message . ' ' . md5($signature);
442
+		$code = $message.' '.$signature;
443
+		$codeMd5 = $message.' '.md5($signature);
444 444
 
445 445
 		switch ($account) {
446 446
 			case 'verify-twitter':
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -52,7 +52,6 @@
 block discarded – undo
52 52
 use OCP\IGroupManager;
53 53
 use OCP\IL10N;
54 54
 use OCP\IRequest;
55
-use OCP\IURLGenerator;
56 55
 use OCP\IUser;
57 56
 use OCP\IUserManager;
58 57
 use OCP\IUserSession;
Please login to merge, or discard this patch.
Indentation   +373 added lines, -373 removed lines patch added patch discarded remove patch
@@ -65,408 +65,408 @@
 block discarded – undo
65 65
  * @package OC\Settings\Controller
66 66
  */
67 67
 class UsersController extends Controller {
68
-	/** @var IUserManager */
69
-	private $userManager;
70
-	/** @var IGroupManager */
71
-	private $groupManager;
72
-	/** @var IUserSession */
73
-	private $userSession;
74
-	/** @var IConfig */
75
-	private $config;
76
-	/** @var bool */
77
-	private $isAdmin;
78
-	/** @var IL10N */
79
-	private $l10n;
80
-	/** @var IMailer */
81
-	private $mailer;
82
-	/** @var IFactory */
83
-	private $l10nFactory;
84
-	/** @var IAppManager */
85
-	private $appManager;
86
-	/** @var AccountManager */
87
-	private $accountManager;
88
-	/** @var Manager */
89
-	private $keyManager;
90
-	/** @var IJobList */
91
-	private $jobList;
92
-	/** @var IManager */
93
-	private $encryptionManager;
68
+    /** @var IUserManager */
69
+    private $userManager;
70
+    /** @var IGroupManager */
71
+    private $groupManager;
72
+    /** @var IUserSession */
73
+    private $userSession;
74
+    /** @var IConfig */
75
+    private $config;
76
+    /** @var bool */
77
+    private $isAdmin;
78
+    /** @var IL10N */
79
+    private $l10n;
80
+    /** @var IMailer */
81
+    private $mailer;
82
+    /** @var IFactory */
83
+    private $l10nFactory;
84
+    /** @var IAppManager */
85
+    private $appManager;
86
+    /** @var AccountManager */
87
+    private $accountManager;
88
+    /** @var Manager */
89
+    private $keyManager;
90
+    /** @var IJobList */
91
+    private $jobList;
92
+    /** @var IManager */
93
+    private $encryptionManager;
94 94
 
95 95
 
96
-	public function __construct(string $appName,
97
-								IRequest $request,
98
-								IUserManager $userManager,
99
-								IGroupManager $groupManager,
100
-								IUserSession $userSession,
101
-								IConfig $config,
102
-								bool $isAdmin,
103
-								IL10N $l10n,
104
-								IMailer $mailer,
105
-								IFactory $l10nFactory,
106
-								IAppManager $appManager,
107
-								AccountManager $accountManager,
108
-								Manager $keyManager,
109
-								IJobList $jobList,
110
-								IManager $encryptionManager) {
111
-		parent::__construct($appName, $request);
112
-		$this->userManager = $userManager;
113
-		$this->groupManager = $groupManager;
114
-		$this->userSession = $userSession;
115
-		$this->config = $config;
116
-		$this->isAdmin = $isAdmin;
117
-		$this->l10n = $l10n;
118
-		$this->mailer = $mailer;
119
-		$this->l10nFactory = $l10nFactory;
120
-		$this->appManager = $appManager;
121
-		$this->accountManager = $accountManager;
122
-		$this->keyManager = $keyManager;
123
-		$this->jobList = $jobList;
124
-		$this->encryptionManager = $encryptionManager;
125
-	}
96
+    public function __construct(string $appName,
97
+                                IRequest $request,
98
+                                IUserManager $userManager,
99
+                                IGroupManager $groupManager,
100
+                                IUserSession $userSession,
101
+                                IConfig $config,
102
+                                bool $isAdmin,
103
+                                IL10N $l10n,
104
+                                IMailer $mailer,
105
+                                IFactory $l10nFactory,
106
+                                IAppManager $appManager,
107
+                                AccountManager $accountManager,
108
+                                Manager $keyManager,
109
+                                IJobList $jobList,
110
+                                IManager $encryptionManager) {
111
+        parent::__construct($appName, $request);
112
+        $this->userManager = $userManager;
113
+        $this->groupManager = $groupManager;
114
+        $this->userSession = $userSession;
115
+        $this->config = $config;
116
+        $this->isAdmin = $isAdmin;
117
+        $this->l10n = $l10n;
118
+        $this->mailer = $mailer;
119
+        $this->l10nFactory = $l10nFactory;
120
+        $this->appManager = $appManager;
121
+        $this->accountManager = $accountManager;
122
+        $this->keyManager = $keyManager;
123
+        $this->jobList = $jobList;
124
+        $this->encryptionManager = $encryptionManager;
125
+    }
126 126
 
127 127
 
128
-	/**
129
-	 * @NoCSRFRequired
130
-	 * @NoAdminRequired
131
-	 * 
132
-	 * Display users list template
133
-	 * 
134
-	 * @return TemplateResponse
135
-	 */
136
-	public function usersListByGroup() {
137
-		return $this->usersList();
138
-	}
128
+    /**
129
+     * @NoCSRFRequired
130
+     * @NoAdminRequired
131
+     * 
132
+     * Display users list template
133
+     * 
134
+     * @return TemplateResponse
135
+     */
136
+    public function usersListByGroup() {
137
+        return $this->usersList();
138
+    }
139 139
 
140
-	/**
141
-	 * @NoCSRFRequired
142
-	 * @NoAdminRequired
143
-	 * 
144
-	 * Display users list template
145
-	 * 
146
-	 * @return TemplateResponse
147
-	 */
148
-	public function usersList() {
149
-		$user = $this->userSession->getUser();
150
-		$uid = $user->getUID();
140
+    /**
141
+     * @NoCSRFRequired
142
+     * @NoAdminRequired
143
+     * 
144
+     * Display users list template
145
+     * 
146
+     * @return TemplateResponse
147
+     */
148
+    public function usersList() {
149
+        $user = $this->userSession->getUser();
150
+        $uid = $user->getUID();
151 151
 
152
-		\OC::$server->getNavigationManager()->setActiveEntry('core_users');
152
+        \OC::$server->getNavigationManager()->setActiveEntry('core_users');
153 153
 				
154
-		/* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */
155
-		$sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
156
-		if ($this->config->getSystemValue('sort_groups_by_name', false)) {
157
-			$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
158
-		} else {
159
-			$isLDAPUsed = false;
160
-			if ($this->appManager->isEnabledForUser('user_ldap')) {
161
-				$isLDAPUsed =
162
-					$this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
163
-					|| $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
164
-				if ($isLDAPUsed) {
165
-					// LDAP user count can be slow, so we sort by group name here
166
-					$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
167
-				}
168
-			}
169
-		}
154
+        /* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */
155
+        $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
156
+        if ($this->config->getSystemValue('sort_groups_by_name', false)) {
157
+            $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
158
+        } else {
159
+            $isLDAPUsed = false;
160
+            if ($this->appManager->isEnabledForUser('user_ldap')) {
161
+                $isLDAPUsed =
162
+                    $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
163
+                    || $this->groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
164
+                if ($isLDAPUsed) {
165
+                    // LDAP user count can be slow, so we sort by group name here
166
+                    $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
167
+                }
168
+            }
169
+        }
170 170
 		
171
-		/* ENCRYPTION CONFIG */
172
-		$isEncryptionEnabled = $this->encryptionManager->isEnabled();
173
-		$useMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', true);
174
-		// If masterKey enabled, then you can change password. This is to avoid data loss!
175
-		$canChangePassword = ($isEncryptionEnabled && $useMasterKey) || $useMasterKey;
171
+        /* ENCRYPTION CONFIG */
172
+        $isEncryptionEnabled = $this->encryptionManager->isEnabled();
173
+        $useMasterKey = $this->config->getAppValue('encryption', 'useMasterKey', true);
174
+        // If masterKey enabled, then you can change password. This is to avoid data loss!
175
+        $canChangePassword = ($isEncryptionEnabled && $useMasterKey) || $useMasterKey;
176 176
 		
177 177
 		
178
-		/* GROUPS */		
179
-		$groupsInfo = new \OC\Group\MetaData(
180
-			$uid,
181
-			$this->isAdmin,
182
-			$this->groupManager,
183
-			$this->userSession
184
-		);
178
+        /* GROUPS */		
179
+        $groupsInfo = new \OC\Group\MetaData(
180
+            $uid,
181
+            $this->isAdmin,
182
+            $this->groupManager,
183
+            $this->userSession
184
+        );
185 185
 		
186
-		$groupsInfo->setSorting($sortGroupsBy);
187
-		list($adminGroup, $groups) = $groupsInfo->get();
186
+        $groupsInfo->setSorting($sortGroupsBy);
187
+        list($adminGroup, $groups) = $groupsInfo->get();
188 188
 		
189
-		if ($this->isAdmin) {
190
-			$subAdmins = $this->groupManager->getSubAdmin()->getAllSubAdmins();
191
-			// New class returns IUser[] so convert back
192
-			$result = [];
193
-			foreach ($subAdmins as $subAdmin) {
194
-				$result[] = [
195
-					'gid' => $subAdmin['group']->getGID(),
196
-					'uid' => $subAdmin['user']->getUID(),
197
-				];
198
-			}
199
-			$subAdmins = $result;
200
-		} else {
201
-			/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
202
-			$gids = array();
203
-			foreach($groups as $group) {
204
-				if (isset($group['id'])) {
205
-					$gids[] = $group['id'];
206
-				}
207
-			}
208
-			$subAdmins = false;
209
-		}
189
+        if ($this->isAdmin) {
190
+            $subAdmins = $this->groupManager->getSubAdmin()->getAllSubAdmins();
191
+            // New class returns IUser[] so convert back
192
+            $result = [];
193
+            foreach ($subAdmins as $subAdmin) {
194
+                $result[] = [
195
+                    'gid' => $subAdmin['group']->getGID(),
196
+                    'uid' => $subAdmin['user']->getUID(),
197
+                ];
198
+            }
199
+            $subAdmins = $result;
200
+        } else {
201
+            /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
202
+            $gids = array();
203
+            foreach($groups as $group) {
204
+                if (isset($group['id'])) {
205
+                    $gids[] = $group['id'];
206
+                }
207
+            }
208
+            $subAdmins = false;
209
+        }
210 210
 		
211
-		$disabledUsers = $isLDAPUsed ? 0 : $this->userManager->countDisabledUsers();
212
-		$disabledUsersGroup = [
213
-			'id' => 'disabled',
214
-			'name' => 'Disabled users',
215
-			'usercount' => $disabledUsers
216
-		];
217
-		$allGroups = array_merge_recursive($adminGroup, $groups);
211
+        $disabledUsers = $isLDAPUsed ? 0 : $this->userManager->countDisabledUsers();
212
+        $disabledUsersGroup = [
213
+            'id' => 'disabled',
214
+            'name' => 'Disabled users',
215
+            'usercount' => $disabledUsers
216
+        ];
217
+        $allGroups = array_merge_recursive($adminGroup, $groups);
218 218
 		
219
-		/* QUOTAS PRESETS */
220
-		$quotaPreset = $this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
221
-		$quotaPreset = explode(',', $quotaPreset);
222
-		foreach ($quotaPreset as &$preset) {
223
-			$preset = trim($preset);
224
-		}
225
-		$quotaPreset = array_diff($quotaPreset, array('default', 'none'));
226
-		$defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none');
219
+        /* QUOTAS PRESETS */
220
+        $quotaPreset = $this->config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
221
+        $quotaPreset = explode(',', $quotaPreset);
222
+        foreach ($quotaPreset as &$preset) {
223
+            $preset = trim($preset);
224
+        }
225
+        $quotaPreset = array_diff($quotaPreset, array('default', 'none'));
226
+        $defaultQuota = $this->config->getAppValue('files', 'default_quota', 'none');
227 227
 		
228
-		\OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
228
+        \OC::$server->getEventDispatcher()->dispatch('OC\Settings\Users::loadAdditionalScripts');
229 229
 		
230
-		/* TOTAL USERS COUNT */
231
-		$userCount = array_reduce($this->userManager->countUsers(), function($v, $w) {
232
-			return $v + (int)$w;
233
-		}, 0);
230
+        /* TOTAL USERS COUNT */
231
+        $userCount = array_reduce($this->userManager->countUsers(), function($v, $w) {
232
+            return $v + (int)$w;
233
+        }, 0);
234 234
 		
235
-		/* LANGUAGES */
236
-		$languages = $this->l10nFactory->getLanguages();
235
+        /* LANGUAGES */
236
+        $languages = $this->l10nFactory->getLanguages();
237 237
 		
238
-		/* FINAL DATA */
239
-		$serverData = array();
240
-		// groups
241
-		$serverData['groups'] = array_merge_recursive($adminGroup, [$disabledUsersGroup], $groups);
242
-		$serverData['subadmingroups'] = $groups;
243
-		// Various data
244
-		$serverData['isAdmin'] = $this->isAdmin;
245
-		$serverData['subadmins'] = $subAdmins;
246
-		$serverData['sortGroups'] = $sortGroupsBy;
247
-		$serverData['quotaPreset'] = $quotaPreset;
248
-		$serverData['userCount'] = $userCount-$disabledUsers;
249
-		$serverData['languages'] = $languages;
250
-		$serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
251
-		// Settings
252
-		$serverData['defaultQuota'] = $defaultQuota;
253
-		$serverData['canChangePassword'] = $canChangePassword;
238
+        /* FINAL DATA */
239
+        $serverData = array();
240
+        // groups
241
+        $serverData['groups'] = array_merge_recursive($adminGroup, [$disabledUsersGroup], $groups);
242
+        $serverData['subadmingroups'] = $groups;
243
+        // Various data
244
+        $serverData['isAdmin'] = $this->isAdmin;
245
+        $serverData['subadmins'] = $subAdmins;
246
+        $serverData['sortGroups'] = $sortGroupsBy;
247
+        $serverData['quotaPreset'] = $quotaPreset;
248
+        $serverData['userCount'] = $userCount-$disabledUsers;
249
+        $serverData['languages'] = $languages;
250
+        $serverData['defaultLanguage'] = $this->config->getSystemValue('default_language', 'en');
251
+        // Settings
252
+        $serverData['defaultQuota'] = $defaultQuota;
253
+        $serverData['canChangePassword'] = $canChangePassword;
254 254
 
255
-		return new TemplateResponse('settings', 'settings', ['serverData' => $serverData]);
256
-	}
255
+        return new TemplateResponse('settings', 'settings', ['serverData' => $serverData]);
256
+    }
257 257
 
258
-	/**
259
-	 * @NoAdminRequired
260
-	 * @NoSubadminRequired
261
-	 * @PasswordConfirmationRequired
262
-	 *
263
-	 * @param string $avatarScope
264
-	 * @param string $displayname
265
-	 * @param string $displaynameScope
266
-	 * @param string $phone
267
-	 * @param string $phoneScope
268
-	 * @param string $email
269
-	 * @param string $emailScope
270
-	 * @param string $website
271
-	 * @param string $websiteScope
272
-	 * @param string $address
273
-	 * @param string $addressScope
274
-	 * @param string $twitter
275
-	 * @param string $twitterScope
276
-	 * @return DataResponse
277
-	 */
278
-	public function setUserSettings($avatarScope,
279
-									$displayname,
280
-									$displaynameScope,
281
-									$phone,
282
-									$phoneScope,
283
-									$email,
284
-									$emailScope,
285
-									$website,
286
-									$websiteScope,
287
-									$address,
288
-									$addressScope,
289
-									$twitter,
290
-									$twitterScope
291
-	) {
292
-		if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
293
-			return new DataResponse(
294
-				[
295
-					'status' => 'error',
296
-					'data' => [
297
-						'message' => $this->l10n->t('Invalid mail address')
298
-					]
299
-				],
300
-				Http::STATUS_UNPROCESSABLE_ENTITY
301
-			);
302
-		}
303
-		$user = $this->userSession->getUser();
304
-		$data = $this->accountManager->getUser($user);
305
-		$data[AccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
306
-		if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
307
-			$data[AccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
308
-			$data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope];
309
-		}
310
-		if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
311
-			$federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
312
-			$shareProvider = $federatedFileSharing->getFederatedShareProvider();
313
-			if ($shareProvider->isLookupServerUploadEnabled()) {
314
-				$data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope];
315
-				$data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope];
316
-				$data[AccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope];
317
-				$data[AccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope];
318
-			}
319
-		}
320
-		try {
321
-			$this->saveUserSettings($user, $data);
322
-			return new DataResponse(
323
-				[
324
-					'status' => 'success',
325
-					'data' => [
326
-						'userId' => $user->getUID(),
327
-						'avatarScope' => $data[AccountManager::PROPERTY_AVATAR]['scope'],
328
-						'displayname' => $data[AccountManager::PROPERTY_DISPLAYNAME]['value'],
329
-						'displaynameScope' => $data[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
330
-						'email' => $data[AccountManager::PROPERTY_EMAIL]['value'],
331
-						'emailScope' => $data[AccountManager::PROPERTY_EMAIL]['scope'],
332
-						'website' => $data[AccountManager::PROPERTY_WEBSITE]['value'],
333
-						'websiteScope' => $data[AccountManager::PROPERTY_WEBSITE]['scope'],
334
-						'address' => $data[AccountManager::PROPERTY_ADDRESS]['value'],
335
-						'addressScope' => $data[AccountManager::PROPERTY_ADDRESS]['scope'],
336
-						'message' => $this->l10n->t('Settings saved')
337
-					]
338
-				],
339
-				Http::STATUS_OK
340
-			);
341
-		} catch (ForbiddenException $e) {
342
-			return new DataResponse([
343
-				'status' => 'error',
344
-				'data' => [
345
-					'message' => $e->getMessage()
346
-				],
347
-			]);
348
-		}
349
-	}
350
-	/**
351
-	 * update account manager with new user data
352
-	 *
353
-	 * @param IUser $user
354
-	 * @param array $data
355
-	 * @throws ForbiddenException
356
-	 */
357
-	protected function saveUserSettings(IUser $user, array $data) {
358
-		// keep the user back-end up-to-date with the latest display name and email
359
-		// address
360
-		$oldDisplayName = $user->getDisplayName();
361
-		$oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
362
-		if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
363
-			&& $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
364
-		) {
365
-			$result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
366
-			if ($result === false) {
367
-				throw new ForbiddenException($this->l10n->t('Unable to change full name'));
368
-			}
369
-		}
370
-		$oldEmailAddress = $user->getEMailAddress();
371
-		$oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
372
-		if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
373
-			&& $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
374
-		) {
375
-			// this is the only permission a backend provides and is also used
376
-			// for the permission of setting a email address
377
-			if (!$user->canChangeDisplayName()) {
378
-				throw new ForbiddenException($this->l10n->t('Unable to change email address'));
379
-			}
380
-			$user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
381
-		}
382
-		$this->accountManager->updateUser($user, $data);
383
-	}
258
+    /**
259
+     * @NoAdminRequired
260
+     * @NoSubadminRequired
261
+     * @PasswordConfirmationRequired
262
+     *
263
+     * @param string $avatarScope
264
+     * @param string $displayname
265
+     * @param string $displaynameScope
266
+     * @param string $phone
267
+     * @param string $phoneScope
268
+     * @param string $email
269
+     * @param string $emailScope
270
+     * @param string $website
271
+     * @param string $websiteScope
272
+     * @param string $address
273
+     * @param string $addressScope
274
+     * @param string $twitter
275
+     * @param string $twitterScope
276
+     * @return DataResponse
277
+     */
278
+    public function setUserSettings($avatarScope,
279
+                                    $displayname,
280
+                                    $displaynameScope,
281
+                                    $phone,
282
+                                    $phoneScope,
283
+                                    $email,
284
+                                    $emailScope,
285
+                                    $website,
286
+                                    $websiteScope,
287
+                                    $address,
288
+                                    $addressScope,
289
+                                    $twitter,
290
+                                    $twitterScope
291
+    ) {
292
+        if (!empty($email) && !$this->mailer->validateMailAddress($email)) {
293
+            return new DataResponse(
294
+                [
295
+                    'status' => 'error',
296
+                    'data' => [
297
+                        'message' => $this->l10n->t('Invalid mail address')
298
+                    ]
299
+                ],
300
+                Http::STATUS_UNPROCESSABLE_ENTITY
301
+            );
302
+        }
303
+        $user = $this->userSession->getUser();
304
+        $data = $this->accountManager->getUser($user);
305
+        $data[AccountManager::PROPERTY_AVATAR] = ['scope' => $avatarScope];
306
+        if ($this->config->getSystemValue('allow_user_to_change_display_name', true) !== false) {
307
+            $data[AccountManager::PROPERTY_DISPLAYNAME] = ['value' => $displayname, 'scope' => $displaynameScope];
308
+            $data[AccountManager::PROPERTY_EMAIL] = ['value' => $email, 'scope' => $emailScope];
309
+        }
310
+        if ($this->appManager->isEnabledForUser('federatedfilesharing')) {
311
+            $federatedFileSharing = new \OCA\FederatedFileSharing\AppInfo\Application();
312
+            $shareProvider = $federatedFileSharing->getFederatedShareProvider();
313
+            if ($shareProvider->isLookupServerUploadEnabled()) {
314
+                $data[AccountManager::PROPERTY_WEBSITE] = ['value' => $website, 'scope' => $websiteScope];
315
+                $data[AccountManager::PROPERTY_ADDRESS] = ['value' => $address, 'scope' => $addressScope];
316
+                $data[AccountManager::PROPERTY_PHONE] = ['value' => $phone, 'scope' => $phoneScope];
317
+                $data[AccountManager::PROPERTY_TWITTER] = ['value' => $twitter, 'scope' => $twitterScope];
318
+            }
319
+        }
320
+        try {
321
+            $this->saveUserSettings($user, $data);
322
+            return new DataResponse(
323
+                [
324
+                    'status' => 'success',
325
+                    'data' => [
326
+                        'userId' => $user->getUID(),
327
+                        'avatarScope' => $data[AccountManager::PROPERTY_AVATAR]['scope'],
328
+                        'displayname' => $data[AccountManager::PROPERTY_DISPLAYNAME]['value'],
329
+                        'displaynameScope' => $data[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
330
+                        'email' => $data[AccountManager::PROPERTY_EMAIL]['value'],
331
+                        'emailScope' => $data[AccountManager::PROPERTY_EMAIL]['scope'],
332
+                        'website' => $data[AccountManager::PROPERTY_WEBSITE]['value'],
333
+                        'websiteScope' => $data[AccountManager::PROPERTY_WEBSITE]['scope'],
334
+                        'address' => $data[AccountManager::PROPERTY_ADDRESS]['value'],
335
+                        'addressScope' => $data[AccountManager::PROPERTY_ADDRESS]['scope'],
336
+                        'message' => $this->l10n->t('Settings saved')
337
+                    ]
338
+                ],
339
+                Http::STATUS_OK
340
+            );
341
+        } catch (ForbiddenException $e) {
342
+            return new DataResponse([
343
+                'status' => 'error',
344
+                'data' => [
345
+                    'message' => $e->getMessage()
346
+                ],
347
+            ]);
348
+        }
349
+    }
350
+    /**
351
+     * update account manager with new user data
352
+     *
353
+     * @param IUser $user
354
+     * @param array $data
355
+     * @throws ForbiddenException
356
+     */
357
+    protected function saveUserSettings(IUser $user, array $data) {
358
+        // keep the user back-end up-to-date with the latest display name and email
359
+        // address
360
+        $oldDisplayName = $user->getDisplayName();
361
+        $oldDisplayName = is_null($oldDisplayName) ? '' : $oldDisplayName;
362
+        if (isset($data[AccountManager::PROPERTY_DISPLAYNAME]['value'])
363
+            && $oldDisplayName !== $data[AccountManager::PROPERTY_DISPLAYNAME]['value']
364
+        ) {
365
+            $result = $user->setDisplayName($data[AccountManager::PROPERTY_DISPLAYNAME]['value']);
366
+            if ($result === false) {
367
+                throw new ForbiddenException($this->l10n->t('Unable to change full name'));
368
+            }
369
+        }
370
+        $oldEmailAddress = $user->getEMailAddress();
371
+        $oldEmailAddress = is_null($oldEmailAddress) ? '' : $oldEmailAddress;
372
+        if (isset($data[AccountManager::PROPERTY_EMAIL]['value'])
373
+            && $oldEmailAddress !== $data[AccountManager::PROPERTY_EMAIL]['value']
374
+        ) {
375
+            // this is the only permission a backend provides and is also used
376
+            // for the permission of setting a email address
377
+            if (!$user->canChangeDisplayName()) {
378
+                throw new ForbiddenException($this->l10n->t('Unable to change email address'));
379
+            }
380
+            $user->setEMailAddress($data[AccountManager::PROPERTY_EMAIL]['value']);
381
+        }
382
+        $this->accountManager->updateUser($user, $data);
383
+    }
384 384
 
385
-	/**
386
-	 * Set the mail address of a user
387
-	 *
388
-	 * @NoAdminRequired
389
-	 * @NoSubadminRequired
390
-	 * @PasswordConfirmationRequired
391
-	 *
392
-	 * @param string $account
393
-	 * @param bool $onlyVerificationCode only return verification code without updating the data
394
-	 * @return DataResponse
395
-	 */
396
-	public function getVerificationCode(string $account, bool $onlyVerificationCode): DataResponse {
385
+    /**
386
+     * Set the mail address of a user
387
+     *
388
+     * @NoAdminRequired
389
+     * @NoSubadminRequired
390
+     * @PasswordConfirmationRequired
391
+     *
392
+     * @param string $account
393
+     * @param bool $onlyVerificationCode only return verification code without updating the data
394
+     * @return DataResponse
395
+     */
396
+    public function getVerificationCode(string $account, bool $onlyVerificationCode): DataResponse {
397 397
 
398
-		$user = $this->userSession->getUser();
398
+        $user = $this->userSession->getUser();
399 399
 
400
-		if ($user === null) {
401
-			return new DataResponse([], Http::STATUS_BAD_REQUEST);
402
-		}
400
+        if ($user === null) {
401
+            return new DataResponse([], Http::STATUS_BAD_REQUEST);
402
+        }
403 403
 
404
-		$accountData = $this->accountManager->getUser($user);
405
-		$cloudId = $user->getCloudId();
406
-		$message = 'Use my Federated Cloud ID to share with me: ' . $cloudId;
407
-		$signature = $this->signMessage($user, $message);
404
+        $accountData = $this->accountManager->getUser($user);
405
+        $cloudId = $user->getCloudId();
406
+        $message = 'Use my Federated Cloud ID to share with me: ' . $cloudId;
407
+        $signature = $this->signMessage($user, $message);
408 408
 
409
-		$code = $message . ' ' . $signature;
410
-		$codeMd5 = $message . ' ' . md5($signature);
409
+        $code = $message . ' ' . $signature;
410
+        $codeMd5 = $message . ' ' . md5($signature);
411 411
 
412
-		switch ($account) {
413
-			case 'verify-twitter':
414
-				$accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
415
-				$msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):');
416
-				$code = $codeMd5;
417
-				$type = AccountManager::PROPERTY_TWITTER;
418
-				$data = $accountData[AccountManager::PROPERTY_TWITTER]['value'];
419
-				$accountData[AccountManager::PROPERTY_TWITTER]['signature'] = $signature;
420
-				break;
421
-			case 'verify-website':
422
-				$accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
423
-				$msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):');
424
-				$type = AccountManager::PROPERTY_WEBSITE;
425
-				$data = $accountData[AccountManager::PROPERTY_WEBSITE]['value'];
426
-				$accountData[AccountManager::PROPERTY_WEBSITE]['signature'] = $signature;
427
-				break;
428
-			default:
429
-				return new DataResponse([], Http::STATUS_BAD_REQUEST);
430
-		}
412
+        switch ($account) {
413
+            case 'verify-twitter':
414
+                $accountData[AccountManager::PROPERTY_TWITTER]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
415
+                $msg = $this->l10n->t('In order to verify your Twitter account, post the following tweet on Twitter (please make sure to post it without any line breaks):');
416
+                $code = $codeMd5;
417
+                $type = AccountManager::PROPERTY_TWITTER;
418
+                $data = $accountData[AccountManager::PROPERTY_TWITTER]['value'];
419
+                $accountData[AccountManager::PROPERTY_TWITTER]['signature'] = $signature;
420
+                break;
421
+            case 'verify-website':
422
+                $accountData[AccountManager::PROPERTY_WEBSITE]['verified'] = AccountManager::VERIFICATION_IN_PROGRESS;
423
+                $msg = $this->l10n->t('In order to verify your Website, store the following content in your web-root at \'.well-known/CloudIdVerificationCode.txt\' (please make sure that the complete text is in one line):');
424
+                $type = AccountManager::PROPERTY_WEBSITE;
425
+                $data = $accountData[AccountManager::PROPERTY_WEBSITE]['value'];
426
+                $accountData[AccountManager::PROPERTY_WEBSITE]['signature'] = $signature;
427
+                break;
428
+            default:
429
+                return new DataResponse([], Http::STATUS_BAD_REQUEST);
430
+        }
431 431
 
432
-		if ($onlyVerificationCode === false) {
433
-			$this->accountManager->updateUser($user, $accountData);
432
+        if ($onlyVerificationCode === false) {
433
+            $this->accountManager->updateUser($user, $accountData);
434 434
 
435
-			$this->jobList->add(VerifyUserData::class,
436
-				[
437
-					'verificationCode' => $code,
438
-					'data' => $data,
439
-					'type' => $type,
440
-					'uid' => $user->getUID(),
441
-					'try' => 0,
442
-					'lastRun' => $this->getCurrentTime()
443
-				]
444
-			);
445
-		}
435
+            $this->jobList->add(VerifyUserData::class,
436
+                [
437
+                    'verificationCode' => $code,
438
+                    'data' => $data,
439
+                    'type' => $type,
440
+                    'uid' => $user->getUID(),
441
+                    'try' => 0,
442
+                    'lastRun' => $this->getCurrentTime()
443
+                ]
444
+            );
445
+        }
446 446
 
447
-		return new DataResponse(['msg' => $msg, 'code' => $code]);
448
-	}
447
+        return new DataResponse(['msg' => $msg, 'code' => $code]);
448
+    }
449 449
 
450
-	/**
451
-	 * get current timestamp
452
-	 *
453
-	 * @return int
454
-	 */
455
-	protected function getCurrentTime(): int {
456
-		return time();
457
-	}
450
+    /**
451
+     * get current timestamp
452
+     *
453
+     * @return int
454
+     */
455
+    protected function getCurrentTime(): int {
456
+        return time();
457
+    }
458 458
 
459
-	/**
460
-	 * sign message with users private key
461
-	 *
462
-	 * @param IUser $user
463
-	 * @param string $message
464
-	 *
465
-	 * @return string base64 encoded signature
466
-	 */
467
-	protected function signMessage(IUser $user, string $message): string {
468
-		$privateKey = $this->keyManager->getKey($user)->getPrivate();
469
-		openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
470
-		return base64_encode($signature);
471
-	}
459
+    /**
460
+     * sign message with users private key
461
+     *
462
+     * @param IUser $user
463
+     * @param string $message
464
+     *
465
+     * @return string base64 encoded signature
466
+     */
467
+    protected function signMessage(IUser $user, string $message): string {
468
+        $privateKey = $this->keyManager->getKey($user)->getPrivate();
469
+        openssl_sign(json_encode($message), $signature, $privateKey, OPENSSL_ALGO_SHA512);
470
+        return base64_encode($signature);
471
+    }
472 472
 }
Please login to merge, or discard this patch.
lib/private/NavigationManager.php 1 patch
Indentation   +260 added lines, -260 removed lines patch added patch discarded remove patch
@@ -44,290 +44,290 @@
 block discarded – undo
44 44
  */
45 45
 
46 46
 class NavigationManager implements INavigationManager {
47
-	protected $entries = [];
48
-	protected $closureEntries = [];
49
-	protected $activeEntry;
50
-	/** @var bool */
51
-	protected $init = false;
52
-	/** @var IAppManager|AppManager */
53
-	protected $appManager;
54
-	/** @var IURLGenerator */
55
-	private $urlGenerator;
56
-	/** @var IFactory */
57
-	private $l10nFac;
58
-	/** @var IUserSession */
59
-	private $userSession;
60
-	/** @var IGroupManager|Manager */
61
-	private $groupManager;
62
-	/** @var IConfig */
63
-	private $config;
47
+    protected $entries = [];
48
+    protected $closureEntries = [];
49
+    protected $activeEntry;
50
+    /** @var bool */
51
+    protected $init = false;
52
+    /** @var IAppManager|AppManager */
53
+    protected $appManager;
54
+    /** @var IURLGenerator */
55
+    private $urlGenerator;
56
+    /** @var IFactory */
57
+    private $l10nFac;
58
+    /** @var IUserSession */
59
+    private $userSession;
60
+    /** @var IGroupManager|Manager */
61
+    private $groupManager;
62
+    /** @var IConfig */
63
+    private $config;
64 64
 
65
-	public function __construct(IAppManager $appManager,
66
-						 IURLGenerator $urlGenerator,
67
-						 IFactory $l10nFac,
68
-						 IUserSession $userSession,
69
-						 IGroupManager $groupManager,
70
-						 IConfig $config) {
71
-		$this->appManager = $appManager;
72
-		$this->urlGenerator = $urlGenerator;
73
-		$this->l10nFac = $l10nFac;
74
-		$this->userSession = $userSession;
75
-		$this->groupManager = $groupManager;
76
-		$this->config = $config;
77
-	}
65
+    public function __construct(IAppManager $appManager,
66
+                            IURLGenerator $urlGenerator,
67
+                            IFactory $l10nFac,
68
+                            IUserSession $userSession,
69
+                            IGroupManager $groupManager,
70
+                            IConfig $config) {
71
+        $this->appManager = $appManager;
72
+        $this->urlGenerator = $urlGenerator;
73
+        $this->l10nFac = $l10nFac;
74
+        $this->userSession = $userSession;
75
+        $this->groupManager = $groupManager;
76
+        $this->config = $config;
77
+    }
78 78
 
79
-	/**
80
-	 * Creates a new navigation entry
81
-	 *
82
-	 * @param array|\Closure $entry Array containing: id, name, order, icon and href key
83
-	 *					The use of a closure is preferred, because it will avoid
84
-	 * 					loading the routing of your app, unless required.
85
-	 * @return void
86
-	 */
87
-	public function add($entry) {
88
-		if ($entry instanceof \Closure) {
89
-			$this->closureEntries[] = $entry;
90
-			return;
91
-		}
79
+    /**
80
+     * Creates a new navigation entry
81
+     *
82
+     * @param array|\Closure $entry Array containing: id, name, order, icon and href key
83
+     *					The use of a closure is preferred, because it will avoid
84
+     * 					loading the routing of your app, unless required.
85
+     * @return void
86
+     */
87
+    public function add($entry) {
88
+        if ($entry instanceof \Closure) {
89
+            $this->closureEntries[] = $entry;
90
+            return;
91
+        }
92 92
 
93
-		$entry['active'] = false;
94
-		if(!isset($entry['icon'])) {
95
-			$entry['icon'] = '';
96
-		}
97
-		if(!isset($entry['classes'])) {
98
-			$entry['classes'] = '';
99
-		}
100
-		if(!isset($entry['type'])) {
101
-			$entry['type'] = 'link';
102
-		}
103
-		$this->entries[] = $entry;
104
-	}
93
+        $entry['active'] = false;
94
+        if(!isset($entry['icon'])) {
95
+            $entry['icon'] = '';
96
+        }
97
+        if(!isset($entry['classes'])) {
98
+            $entry['classes'] = '';
99
+        }
100
+        if(!isset($entry['type'])) {
101
+            $entry['type'] = 'link';
102
+        }
103
+        $this->entries[] = $entry;
104
+    }
105 105
 
106
-	/**
107
-	 * Get a list of navigation entries
108
-	 *
109
-	 * @param string $type type of the navigation entries
110
-	 * @return array
111
-	 */
112
-	public function getAll(string $type = 'link'): array {
113
-		$this->init();
114
-		foreach ($this->closureEntries as $c) {
115
-			$this->add($c());
116
-		}
117
-		$this->closureEntries = array();
106
+    /**
107
+     * Get a list of navigation entries
108
+     *
109
+     * @param string $type type of the navigation entries
110
+     * @return array
111
+     */
112
+    public function getAll(string $type = 'link'): array {
113
+        $this->init();
114
+        foreach ($this->closureEntries as $c) {
115
+            $this->add($c());
116
+        }
117
+        $this->closureEntries = array();
118 118
 
119
-		$result = $this->entries;
120
-		if ($type !== 'all') {
121
-			$result = array_filter($this->entries, function($entry) use ($type) {
122
-				return $entry['type'] === $type;
123
-			});
124
-		}
119
+        $result = $this->entries;
120
+        if ($type !== 'all') {
121
+            $result = array_filter($this->entries, function($entry) use ($type) {
122
+                return $entry['type'] === $type;
123
+            });
124
+        }
125 125
 
126
-		return $this->proceedNavigation($result);
127
-	}
126
+        return $this->proceedNavigation($result);
127
+    }
128 128
 
129
-	/**
130
-	 * Sort navigation entries by order, name and set active flag
131
-	 *
132
-	 * @param array $list
133
-	 * @return array
134
-	 */
135
-	private function proceedNavigation(array $list): array {
136
-		usort($list, function($a, $b) {
137
-			if (isset($a['order']) && isset($b['order'])) {
138
-				return ($a['order'] < $b['order']) ? -1 : 1;
139
-			} else if (isset($a['order']) || isset($b['order'])) {
140
-				return isset($a['order']) ? -1 : 1;
141
-			} else {
142
-				return ($a['name'] < $b['name']) ? -1 : 1;
143
-			}
144
-		});
129
+    /**
130
+     * Sort navigation entries by order, name and set active flag
131
+     *
132
+     * @param array $list
133
+     * @return array
134
+     */
135
+    private function proceedNavigation(array $list): array {
136
+        usort($list, function($a, $b) {
137
+            if (isset($a['order']) && isset($b['order'])) {
138
+                return ($a['order'] < $b['order']) ? -1 : 1;
139
+            } else if (isset($a['order']) || isset($b['order'])) {
140
+                return isset($a['order']) ? -1 : 1;
141
+            } else {
142
+                return ($a['name'] < $b['name']) ? -1 : 1;
143
+            }
144
+        });
145 145
 
146
-		$activeApp = $this->getActiveEntry();
147
-		if ($activeApp !== null) {
148
-			foreach ($list as $index => &$navEntry) {
149
-				if ($navEntry['id'] == $activeApp) {
150
-					$navEntry['active'] = true;
151
-				} else {
152
-					$navEntry['active'] = false;
153
-				}
154
-			}
155
-			unset($navEntry);
156
-		}
146
+        $activeApp = $this->getActiveEntry();
147
+        if ($activeApp !== null) {
148
+            foreach ($list as $index => &$navEntry) {
149
+                if ($navEntry['id'] == $activeApp) {
150
+                    $navEntry['active'] = true;
151
+                } else {
152
+                    $navEntry['active'] = false;
153
+                }
154
+            }
155
+            unset($navEntry);
156
+        }
157 157
 
158
-		return $list;
159
-	}
158
+        return $list;
159
+    }
160 160
 
161 161
 
162
-	/**
163
-	 * removes all the entries
164
-	 */
165
-	public function clear($loadDefaultLinks = true) {
166
-		$this->entries = [];
167
-		$this->closureEntries = [];
168
-		$this->init = !$loadDefaultLinks;
169
-	}
162
+    /**
163
+     * removes all the entries
164
+     */
165
+    public function clear($loadDefaultLinks = true) {
166
+        $this->entries = [];
167
+        $this->closureEntries = [];
168
+        $this->init = !$loadDefaultLinks;
169
+    }
170 170
 
171
-	/**
172
-	 * Sets the current navigation entry of the currently running app
173
-	 * @param string $id of the app entry to activate (from added $entry)
174
-	 */
175
-	public function setActiveEntry($id) {
176
-		$this->activeEntry = $id;
177
-	}
171
+    /**
172
+     * Sets the current navigation entry of the currently running app
173
+     * @param string $id of the app entry to activate (from added $entry)
174
+     */
175
+    public function setActiveEntry($id) {
176
+        $this->activeEntry = $id;
177
+    }
178 178
 
179
-	/**
180
-	 * gets the active Menu entry
181
-	 * @return string id or empty string
182
-	 *
183
-	 * This function returns the id of the active navigation entry (set by
184
-	 * setActiveEntry
185
-	 */
186
-	public function getActiveEntry() {
187
-		return $this->activeEntry;
188
-	}
179
+    /**
180
+     * gets the active Menu entry
181
+     * @return string id or empty string
182
+     *
183
+     * This function returns the id of the active navigation entry (set by
184
+     * setActiveEntry
185
+     */
186
+    public function getActiveEntry() {
187
+        return $this->activeEntry;
188
+    }
189 189
 
190
-	private function init() {
191
-		if ($this->init) {
192
-			return;
193
-		}
194
-		$this->init = true;
190
+    private function init() {
191
+        if ($this->init) {
192
+            return;
193
+        }
194
+        $this->init = true;
195 195
 
196
-		$l = $this->l10nFac->get('lib');
197
-		if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
198
-			$this->add([
199
-				'type' => 'settings',
200
-				'id' => 'help',
201
-				'order' => 5,
202
-				'href' => $this->urlGenerator->linkToRoute('settings_help'),
203
-				'name' => $l->t('Help'),
204
-				'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
205
-			]);
206
-		}
196
+        $l = $this->l10nFac->get('lib');
197
+        if ($this->config->getSystemValue('knowledgebaseenabled', true)) {
198
+            $this->add([
199
+                'type' => 'settings',
200
+                'id' => 'help',
201
+                'order' => 5,
202
+                'href' => $this->urlGenerator->linkToRoute('settings_help'),
203
+                'name' => $l->t('Help'),
204
+                'icon' => $this->urlGenerator->imagePath('settings', 'help.svg'),
205
+            ]);
206
+        }
207 207
 
208
-		if ($this->userSession->isLoggedIn()) {
209
-			if ($this->isAdmin()) {
210
-				// App management
211
-				$this->add([
212
-					'type' => 'settings',
213
-					'id' => 'core_apps',
214
-					'order' => 3,
215
-					'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
216
-					'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
217
-					'name' => $l->t('Apps'),
218
-				]);
219
-			}
208
+        if ($this->userSession->isLoggedIn()) {
209
+            if ($this->isAdmin()) {
210
+                // App management
211
+                $this->add([
212
+                    'type' => 'settings',
213
+                    'id' => 'core_apps',
214
+                    'order' => 3,
215
+                    'href' => $this->urlGenerator->linkToRoute('settings.AppSettings.viewApps'),
216
+                    'icon' => $this->urlGenerator->imagePath('settings', 'apps.svg'),
217
+                    'name' => $l->t('Apps'),
218
+                ]);
219
+            }
220 220
 
221
-			// Personal and (if applicable) admin settings
222
-			$this->add([
223
-				'type' => 'settings',
224
-				'id' => 'settings',
225
-				'order' => 1,
226
-				'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
227
-				'name' => $l->t('Settings'),
228
-				'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
229
-			]);
221
+            // Personal and (if applicable) admin settings
222
+            $this->add([
223
+                'type' => 'settings',
224
+                'id' => 'settings',
225
+                'order' => 1,
226
+                'href' => $this->urlGenerator->linkToRoute('settings.PersonalSettings.index'),
227
+                'name' => $l->t('Settings'),
228
+                'icon' => $this->urlGenerator->imagePath('settings', 'admin.svg'),
229
+            ]);
230 230
 
231
-			$logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
232
-			if($logoutUrl !== '') {
233
-				// Logout
234
-				$this->add([
235
-					'type' => 'settings',
236
-					'id' => 'logout',
237
-					'order' => 99999,
238
-					'href' => $logoutUrl,
239
-					'name' => $l->t('Log out'),
240
-					'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
241
-				]);
242
-			}
231
+            $logoutUrl = \OC_User::getLogoutUrl($this->urlGenerator);
232
+            if($logoutUrl !== '') {
233
+                // Logout
234
+                $this->add([
235
+                    'type' => 'settings',
236
+                    'id' => 'logout',
237
+                    'order' => 99999,
238
+                    'href' => $logoutUrl,
239
+                    'name' => $l->t('Log out'),
240
+                    'icon' => $this->urlGenerator->imagePath('core', 'actions/logout.svg'),
241
+                ]);
242
+            }
243 243
 
244
-			if ($this->isSubadmin()) {
245
-				// User management
246
-				$this->add([
247
-					'type' => 'settings',
248
-					'id' => 'core_users',
249
-					'order' => 4,
250
-					'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
251
-					'name' => $l->t('Users'),
252
-					'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
253
-				]);
254
-			}
255
-		}
244
+            if ($this->isSubadmin()) {
245
+                // User management
246
+                $this->add([
247
+                    'type' => 'settings',
248
+                    'id' => 'core_users',
249
+                    'order' => 4,
250
+                    'href' => $this->urlGenerator->linkToRoute('settings.Users.usersList'),
251
+                    'name' => $l->t('Users'),
252
+                    'icon' => $this->urlGenerator->imagePath('settings', 'users.svg'),
253
+                ]);
254
+            }
255
+        }
256 256
 
257
-		if ($this->appManager === 'null') {
258
-			return;
259
-		}
257
+        if ($this->appManager === 'null') {
258
+            return;
259
+        }
260 260
 
261
-		if ($this->userSession->isLoggedIn()) {
262
-			$apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
263
-		} else {
264
-			$apps = $this->appManager->getInstalledApps();
265
-		}
261
+        if ($this->userSession->isLoggedIn()) {
262
+            $apps = $this->appManager->getEnabledAppsForUser($this->userSession->getUser());
263
+        } else {
264
+            $apps = $this->appManager->getInstalledApps();
265
+        }
266 266
 
267
-		foreach ($apps as $app) {
268
-			if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
269
-				continue;
270
-			}
267
+        foreach ($apps as $app) {
268
+            if (!$this->userSession->isLoggedIn() && !$this->appManager->isEnabledForUser($app, $this->userSession->getUser())) {
269
+                continue;
270
+            }
271 271
 
272
-			// load plugins and collections from info.xml
273
-			$info = $this->appManager->getAppInfo($app);
274
-			if (empty($info['navigations'])) {
275
-				continue;
276
-			}
277
-			foreach ($info['navigations'] as $nav) {
278
-				if (!isset($nav['name'])) {
279
-					continue;
280
-				}
281
-				if (!isset($nav['route'])) {
282
-					continue;
283
-				}
284
-				$role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
285
-				if ($role === 'admin' && !$this->isAdmin()) {
286
-					continue;
287
-				}
288
-				$l = $this->l10nFac->get($app);
289
-				$id = isset($nav['id']) ? $nav['id'] : $app;
290
-				$order = isset($nav['order']) ? $nav['order'] : 100;
291
-				$type = isset($nav['type']) ? $nav['type'] : 'link';
292
-				$route = $this->urlGenerator->linkToRoute($nav['route']);
293
-				$icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
294
-				foreach ([$icon, "$app.svg"] as $i) {
295
-					try {
296
-						$icon = $this->urlGenerator->imagePath($app, $i);
297
-						break;
298
-					} catch (\RuntimeException $ex) {
299
-						// no icon? - ignore it then
300
-					}
301
-				}
302
-				if ($icon === null) {
303
-					$icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
304
-				}
272
+            // load plugins and collections from info.xml
273
+            $info = $this->appManager->getAppInfo($app);
274
+            if (empty($info['navigations'])) {
275
+                continue;
276
+            }
277
+            foreach ($info['navigations'] as $nav) {
278
+                if (!isset($nav['name'])) {
279
+                    continue;
280
+                }
281
+                if (!isset($nav['route'])) {
282
+                    continue;
283
+                }
284
+                $role = isset($nav['@attributes']['role']) ? $nav['@attributes']['role'] : 'all';
285
+                if ($role === 'admin' && !$this->isAdmin()) {
286
+                    continue;
287
+                }
288
+                $l = $this->l10nFac->get($app);
289
+                $id = isset($nav['id']) ? $nav['id'] : $app;
290
+                $order = isset($nav['order']) ? $nav['order'] : 100;
291
+                $type = isset($nav['type']) ? $nav['type'] : 'link';
292
+                $route = $this->urlGenerator->linkToRoute($nav['route']);
293
+                $icon = isset($nav['icon']) ? $nav['icon'] : 'app.svg';
294
+                foreach ([$icon, "$app.svg"] as $i) {
295
+                    try {
296
+                        $icon = $this->urlGenerator->imagePath($app, $i);
297
+                        break;
298
+                    } catch (\RuntimeException $ex) {
299
+                        // no icon? - ignore it then
300
+                    }
301
+                }
302
+                if ($icon === null) {
303
+                    $icon = $this->urlGenerator->imagePath('core', 'default-app-icon');
304
+                }
305 305
 
306
-				$this->add([
307
-					'id' => $id,
308
-					'order' => $order,
309
-					'href' => $route,
310
-					'icon' => $icon,
311
-					'type' => $type,
312
-					'name' => $l->t($nav['name']),
313
-				]);
314
-			}
315
-		}
316
-	}
306
+                $this->add([
307
+                    'id' => $id,
308
+                    'order' => $order,
309
+                    'href' => $route,
310
+                    'icon' => $icon,
311
+                    'type' => $type,
312
+                    'name' => $l->t($nav['name']),
313
+                ]);
314
+            }
315
+        }
316
+    }
317 317
 
318
-	private function isAdmin() {
319
-		$user = $this->userSession->getUser();
320
-		if ($user !== null) {
321
-			return $this->groupManager->isAdmin($user->getUID());
322
-		}
323
-		return false;
324
-	}
318
+    private function isAdmin() {
319
+        $user = $this->userSession->getUser();
320
+        if ($user !== null) {
321
+            return $this->groupManager->isAdmin($user->getUID());
322
+        }
323
+        return false;
324
+    }
325 325
 
326
-	private function isSubadmin() {
327
-		$user = $this->userSession->getUser();
328
-		if ($user !== null) {
329
-			return $this->groupManager->getSubAdmin()->isSubAdmin($user);
330
-		}
331
-		return false;
332
-	}
326
+    private function isSubadmin() {
327
+        $user = $this->userSession->getUser();
328
+        if ($user !== null) {
329
+            return $this->groupManager->getSubAdmin()->isSubAdmin($user);
330
+        }
331
+        return false;
332
+    }
333 333
 }
Please login to merge, or discard this patch.
settings/routes.php 1 patch
Indentation   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -38,51 +38,51 @@
 block discarded – undo
38 38
 
39 39
 $application = new Application();
40 40
 $application->registerRoutes($this, [
41
-	'resources' => [
42
-		'AuthSettings' => ['url' => '/settings/personal/authtokens'],
43
-	],
44
-	'routes' => [
45
-		['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
46
-		['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
47
-		['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
48
-		['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
49
-		['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
50
-		['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
51
-		['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
52
-		['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
53
-		['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
54
-		['name' => 'Users#usersList', 'url' => '/settings/users', 'verb' => 'GET'],
55
-		['name' => 'Users#usersListByGroup', 'url' => '/settings/users/{group}', 'verb' => 'GET'],
56
-		['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
57
-		['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
58
-		['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'],
59
-		['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'],
60
-		['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'],
61
-		['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'],
62
-		['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'],
63
-		['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
64
-		['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'],
65
-		['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
66
-		['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info']],
67
-		['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']],
68
-		['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'],
69
-		['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'],
70
-		['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST']
71
-	]
41
+    'resources' => [
42
+        'AuthSettings' => ['url' => '/settings/personal/authtokens'],
43
+    ],
44
+    'routes' => [
45
+        ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
46
+        ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
47
+        ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
48
+        ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
49
+        ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
50
+        ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
51
+        ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
52
+        ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
53
+        ['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
54
+        ['name' => 'Users#usersList', 'url' => '/settings/users', 'verb' => 'GET'],
55
+        ['name' => 'Users#usersListByGroup', 'url' => '/settings/users/{group}', 'verb' => 'GET'],
56
+        ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
57
+        ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
58
+        ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'],
59
+        ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'],
60
+        ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'],
61
+        ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'],
62
+        ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'],
63
+        ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
64
+        ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'],
65
+        ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
66
+        ['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info']],
67
+        ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']],
68
+        ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'],
69
+        ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'],
70
+        ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST']
71
+    ]
72 72
 ]);
73 73
 
74 74
 /** @var $this \OCP\Route\IRouter */
75 75
 
76 76
 // Settings pages
77 77
 $this->create('settings_help', '/settings/help')
78
-	->actionInclude('settings/help.php');
78
+    ->actionInclude('settings/help.php');
79 79
 // Settings ajax actions
80 80
 // apps
81 81
 $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php')
82
-	->actionInclude('settings/ajax/enableapp.php');
82
+    ->actionInclude('settings/ajax/enableapp.php');
83 83
 $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php')
84
-	->actionInclude('settings/ajax/disableapp.php');
84
+    ->actionInclude('settings/ajax/disableapp.php');
85 85
 $this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php')
86
-	->actionInclude('settings/ajax/updateapp.php');
86
+    ->actionInclude('settings/ajax/updateapp.php');
87 87
 $this->create('settings_ajax_uninstallapp', '/settings/ajax/uninstallapp.php')
88
-	->actionInclude('settings/ajax/uninstallapp.php');
88
+    ->actionInclude('settings/ajax/uninstallapp.php');
Please login to merge, or discard this patch.