Completed
Pull Request — master (#8824)
by John
29:18 queued 12:04
created
settings/templates/settings.php 2 patches
Indentation   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -13,7 +13,6 @@  discard block
 block discarded – undo
13 13
  * $tmpl = new OC_Template('settings', 'settings', 'user');
14 14
  * $tmpl->assign('serverData', $serverData);
15 15
  * $tmpl->printPage();
16
-
17 16
  */
18 17
 
19 18
 script('settings', 'main');
@@ -21,7 +20,7 @@  discard block
 block discarded – undo
21 20
 
22 21
 // Did we have some data to inject ?
23 22
 if(is_array($_['serverData'])) {
24
-	$serverData = json_encode($_['serverData']);
23
+    $serverData = json_encode($_['serverData']);
25 24
 ?>
26 25
 <span id="serverData" data-server="<?php p($serverData);?>"></span>
27 26
 <?php } ?>
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,8 +20,8 @@
 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
 	$serverData = json_encode($_['serverData']);
25 25
 ?>
26
-<span id="serverData" data-server="<?php p($serverData);?>"></span>
26
+<span id="serverData" data-server="<?php p($serverData); ?>"></span>
27 27
 <?php } ?>
Please login to merge, or discard this patch.
settings/main.php 1 patch
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,5 +20,5 @@
 block discarded – undo
20 20
  *
21 21
  */
22 22
 
23
- $tmpl = new OC_Template("settings", "settings", "user");
24
- $tmpl->printPage();
23
+    $tmpl = new OC_Template("settings", "settings", "user");
24
+    $tmpl->printPage();
Please login to merge, or discard this patch.
settings/users.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -47,18 +47,18 @@  discard block
 block discarded – undo
47 47
 /* SORT OPTION: SORT_USERCOUNT or SORT_GROUPNAME */
48 48
 $sortGroupsBy = \OC\Group\MetaData::SORT_USERCOUNT;
49 49
 if ($config->getSystemValue('sort_groups_by_name', false)) {
50
-	$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
50
+    $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
51 51
 } else {
52
-	$isLDAPUsed = false;
53
-	if ($appManager->isEnabledForUser('user_ldap')) {
54
-		$isLDAPUsed =
55
-			$groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
56
-			|| $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
57
-		if ($isLDAPUsed) {
58
-			// LDAP user count can be slow, so we sort by group name here
59
-			$sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
60
-		}
61
-	}
52
+    $isLDAPUsed = false;
53
+    if ($appManager->isEnabledForUser('user_ldap')) {
54
+        $isLDAPUsed =
55
+            $groupManager->isBackendUsed('\OCA\User_LDAP\Group_LDAP')
56
+            || $groupManager->isBackendUsed('\OCA\User_LDAP\Group_Proxy');
57
+        if ($isLDAPUsed) {
58
+            // LDAP user count can be slow, so we sort by group name here
59
+            $sortGroupsBy = \OC\Group\MetaData::SORT_GROUPNAME;
60
+        }
61
+    }
62 62
 }
63 63
 
64 64
 /* ENCRYPTION CONFIG */
@@ -73,42 +73,42 @@  discard block
 block discarded – undo
73 73
 $isAdmin = \OC_User::isAdminUser($uid);
74 74
 
75 75
 $groupsInfo = new \OC\Group\MetaData(
76
-	$uid,
77
-	$isAdmin,
78
-	$groupManager,
79
-	\OC::$server->getUserSession()
76
+    $uid,
77
+    $isAdmin,
78
+    $groupManager,
79
+    \OC::$server->getUserSession()
80 80
 );
81 81
 
82 82
 $groupsInfo->setSorting($sortGroupsBy);
83 83
 list($adminGroup, $groups) = $groupsInfo->get();
84 84
 
85 85
 if ($isAdmin) {
86
-	$subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
87
-	// New class returns IUser[] so convert back
88
-	$result = [];
89
-	foreach ($subAdmins as $subAdmin) {
90
-		$result[] = [
91
-			'gid' => $subAdmin['group']->getGID(),
92
-			'uid' => $subAdmin['user']->getUID(),
93
-		];
94
-	}
95
-	$subAdmins = $result;
86
+    $subAdmins = \OC::$server->getGroupManager()->getSubAdmin()->getAllSubAdmins();
87
+    // New class returns IUser[] so convert back
88
+    $result = [];
89
+    foreach ($subAdmins as $subAdmin) {
90
+        $result[] = [
91
+            'gid' => $subAdmin['group']->getGID(),
92
+            'uid' => $subAdmin['user']->getUID(),
93
+        ];
94
+    }
95
+    $subAdmins = $result;
96 96
 } else {
97
-	/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
98
-	$gids = array();
99
-	foreach($groups as $group) {
100
-		if (isset($group['id'])) {
101
-			$gids[] = $group['id'];
102
-		}
103
-	}
104
-	$subAdmins = false;
97
+    /* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
98
+    $gids = array();
99
+    foreach($groups as $group) {
100
+        if (isset($group['id'])) {
101
+            $gids[] = $group['id'];
102
+        }
103
+    }
104
+    $subAdmins = false;
105 105
 }
106 106
 
107 107
 $disabledUsers = $isLDAPUsed ? 0 : $userManager->countDisabledUsers();
108 108
 $disabledUsersGroup = [
109
-	'id' => '_disabled',
110
-	'name' => 'Disabled users',
111
-	'usercount' => $disabledUsers
109
+    'id' => '_disabled',
110
+    'name' => 'Disabled users',
111
+    'usercount' => $disabledUsers
112 112
 ];
113 113
 $allGroups = array_merge_recursive($adminGroup, $groups);
114 114
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 $quotaPreset = $config->getAppValue('files', 'quota_preset', '1 GB, 5 GB, 10 GB');
117 117
 $quotaPreset = explode(',', $quotaPreset);
118 118
 foreach ($quotaPreset as &$preset) {
119
-	$preset = trim($preset);
119
+    $preset = trim($preset);
120 120
 }
121 121
 $quotaPreset = array_diff($quotaPreset, array('default', 'none'));
122 122
 $defaultQuota = $config->getAppValue('files', 'default_quota', 'none');
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 
126 126
 /* TOTAL USERS COUNT */
127 127
 function addition($v, $w) {
128
-	return $v+$w;
128
+    return $v+$w;
129 129
 }
130 130
 $userCount = array_reduce($userManager->countUsers(), 'addition', 0);
131 131
 
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 } else {
98 98
 	/* Retrieve group IDs from $groups array, so we can pass that information into OC_Group::displayNamesInGroups() */
99 99
 	$gids = array();
100
-	foreach($groups as $group) {
100
+	foreach ($groups as $group) {
101 101
 		if (isset($group['id'])) {
102 102
 			$gids[] = $group['id'];
103 103
 		}
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 
127 127
 /* TOTAL USERS COUNT */
128 128
 function addition($v, $w) {
129
-	return $v+$w;
129
+	return $v + $w;
130 130
 }
131 131
 $userCount = array_reduce($userManager->countUsers(), 'addition', 0);
132 132
 
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 $serverData['subadmins'] = $subAdmins;
143 143
 $serverData['sortGroups'] = $sortGroupsBy;
144 144
 $serverData['quotaPreset'] = $quotaPreset;
145
-$serverData['userCount'] = $userCount-$disabledUsers;
145
+$serverData['userCount'] = $userCount - $disabledUsers;
146 146
 $serverData['languages'] = $languages;
147 147
 $serverData['defaultLanguage'] = $config->getSystemValue('default_language', 'en');
148 148
 // Settings
Please login to merge, or discard this patch.
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/routes.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -38,74 +38,74 @@
 block discarded – undo
38 38
 
39 39
 $application = new Application();
40 40
 $application->registerRoutes($this, [
41
-	'resources' => [
42
-		'users' => ['url' => '/settings/users/users'],
43
-		'AuthSettings' => ['url' => '/settings/personal/authtokens'],
44
-	],
45
-	'routes' => [
46
-		['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
47
-		['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
48
-		['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
49
-		['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
50
-		['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
51
-		['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
52
-		['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
53
-		['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'],
54
-		['name' => 'Users#setDisplayName', 'url' => '/settings/users/{id}/displayName', 'verb' => 'PUT'],
55
-		['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'],
56
-		['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
57
-		['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
58
-		['name' => 'Users#setEnabled', 'url' => '/settings/users/{id}/setEnabled', 'verb' => 'POST'],
59
-		['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'],
60
-		['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
61
-		['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
62
-		['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'],
63
-		['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'],
64
-		['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'],
65
-		['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'],
66
-		['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'],
67
-		['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
68
-		['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'],
69
-		['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
70
-		['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info']],
71
-		['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']],
72
-		['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'],
73
-		['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'],
74
-		['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'],
75
-		['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'],
76
-		['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'],
77
-		['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'],
78
-		['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'],
79
-		['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'],
80
-	]
41
+    'resources' => [
42
+        'users' => ['url' => '/settings/users/users'],
43
+        'AuthSettings' => ['url' => '/settings/personal/authtokens'],
44
+    ],
45
+    'routes' => [
46
+        ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'],
47
+        ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'],
48
+        ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'],
49
+        ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'],
50
+        ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'],
51
+        ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'],
52
+        ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'],
53
+        ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'],
54
+        ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{id}/displayName', 'verb' => 'PUT'],
55
+        ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'],
56
+        ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'],
57
+        ['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'],
58
+        ['name' => 'Users#setEnabled', 'url' => '/settings/users/{id}/setEnabled', 'verb' => 'POST'],
59
+        ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'],
60
+        ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'],
61
+        ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'],
62
+        ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'],
63
+        ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'],
64
+        ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'],
65
+        ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'],
66
+        ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'],
67
+        ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
68
+        ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'],
69
+        ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'],
70
+        ['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info']],
71
+        ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']],
72
+        ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'],
73
+        ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'],
74
+        ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'],
75
+        ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'],
76
+        ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'],
77
+        ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'],
78
+        ['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'],
79
+        ['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'],
80
+    ]
81 81
 ]);
82 82
 
83 83
 /** @var $this \OCP\Route\IRouter */
84 84
 
85 85
 // Settings pages
86 86
 $this->create('settings_help', '/settings/help')
87
-	->actionInclude('settings/help.php');
87
+    ->actionInclude('settings/help.php');
88 88
 $this->create('settings_users', '/settings/users')
89
-	->actionInclude('settings/users.php');
89
+    ->actionInclude('settings/users.php');
90 90
 // Settings ajax actions
91 91
 // users
92 92
 $this->create('settings_ajax_setquota', '/settings/ajax/setquota.php')
93
-	->actionInclude('settings/ajax/setquota.php');
93
+    ->actionInclude('settings/ajax/setquota.php');
94 94
 $this->create('settings_ajax_togglegroups', '/settings/ajax/togglegroups.php')
95
-	->actionInclude('settings/ajax/togglegroups.php');
95
+    ->actionInclude('settings/ajax/togglegroups.php');
96 96
 $this->create('settings_ajax_togglesubadmins', '/settings/ajax/togglesubadmins.php')
97
-	->actionInclude('settings/ajax/togglesubadmins.php');
97
+    ->actionInclude('settings/ajax/togglesubadmins.php');
98 98
 $this->create('settings_ajax_changegorupname', '/settings/ajax/changegroupname.php')
99
-	->actionInclude('settings/ajax/changegroupname.php');
99
+    ->actionInclude('settings/ajax/changegroupname.php');
100 100
 // apps
101 101
 $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php')
102
-	->actionInclude('settings/ajax/enableapp.php');
102
+    ->actionInclude('settings/ajax/enableapp.php');
103 103
 $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php')
104
-	->actionInclude('settings/ajax/disableapp.php');
104
+    ->actionInclude('settings/ajax/disableapp.php');
105 105
 $this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php')
106
-	->actionInclude('settings/ajax/updateapp.php');
106
+    ->actionInclude('settings/ajax/updateapp.php');
107 107
 $this->create('settings_ajax_uninstallapp', '/settings/ajax/uninstallapp.php')
108
-	->actionInclude('settings/ajax/uninstallapp.php');
108
+    ->actionInclude('settings/ajax/uninstallapp.php');
109 109
 // admin
110 110
 $this->create('settings_ajax_excludegroups', '/settings/ajax/excludegroups.php')
111
-	->actionInclude('settings/ajax/excludegroups.php');
111
+    ->actionInclude('settings/ajax/excludegroups.php');
Please login to merge, or discard this patch.