@@ -54,282 +54,282 @@ |
||
54 | 54 | |
55 | 55 | class PersonalInfo implements ISettings { |
56 | 56 | |
57 | - /** @var IConfig */ |
|
58 | - private $config; |
|
59 | - /** @var IUserManager */ |
|
60 | - private $userManager; |
|
61 | - /** @var IAccountManager */ |
|
62 | - private $accountManager; |
|
63 | - /** @var IGroupManager */ |
|
64 | - private $groupManager; |
|
65 | - /** @var IAppManager */ |
|
66 | - private $appManager; |
|
67 | - /** @var IFactory */ |
|
68 | - private $l10nFactory; |
|
69 | - /** @var IL10N */ |
|
70 | - private $l; |
|
71 | - /** @var IInitialState */ |
|
72 | - private $initialStateService; |
|
73 | - |
|
74 | - public function __construct( |
|
75 | - IConfig $config, |
|
76 | - IUserManager $userManager, |
|
77 | - IGroupManager $groupManager, |
|
78 | - IAccountManager $accountManager, |
|
79 | - IAppManager $appManager, |
|
80 | - IFactory $l10nFactory, |
|
81 | - IL10N $l, |
|
82 | - IInitialState $initialStateService |
|
83 | - ) { |
|
84 | - $this->config = $config; |
|
85 | - $this->userManager = $userManager; |
|
86 | - $this->accountManager = $accountManager; |
|
87 | - $this->groupManager = $groupManager; |
|
88 | - $this->appManager = $appManager; |
|
89 | - $this->l10nFactory = $l10nFactory; |
|
90 | - $this->l = $l; |
|
91 | - $this->initialStateService = $initialStateService; |
|
92 | - } |
|
93 | - |
|
94 | - public function getForm(): TemplateResponse { |
|
95 | - $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
96 | - $lookupServerUploadEnabled = false; |
|
97 | - if ($federatedFileSharingEnabled) { |
|
98 | - /** @var FederatedShareProvider $shareProvider */ |
|
99 | - $shareProvider = \OC::$server->query(FederatedShareProvider::class); |
|
100 | - $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
101 | - } |
|
102 | - |
|
103 | - $uid = \OC_User::getUser(); |
|
104 | - $user = $this->userManager->get($uid); |
|
105 | - $account = $this->accountManager->getAccount($user); |
|
106 | - |
|
107 | - // make sure FS is setup before querying storage related stuff... |
|
108 | - \OC_Util::setupFS($user->getUID()); |
|
109 | - |
|
110 | - $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
111 | - if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
112 | - $totalSpace = $this->l->t('Unlimited'); |
|
113 | - } else { |
|
114 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
115 | - } |
|
116 | - |
|
117 | - $languageParameters = $this->getLanguages($user); |
|
118 | - $localeParameters = $this->getLocales($user); |
|
119 | - $messageParameters = $this->getMessageParameters($account); |
|
120 | - |
|
121 | - $parameters = [ |
|
122 | - 'total_space' => $totalSpace, |
|
123 | - 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
124 | - 'usage_relative' => round($storageInfo['relative']), |
|
125 | - 'quota' => $storageInfo['quota'], |
|
126 | - 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
127 | - 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
128 | - 'avatarScope' => $account->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(), |
|
129 | - 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
130 | - 'displayName' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getValue(), |
|
131 | - 'displayNameScope' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(), |
|
132 | - 'email' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(), |
|
133 | - 'emailScope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(), |
|
134 | - 'emailVerification' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(), |
|
135 | - 'phone' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(), |
|
136 | - 'phoneScope' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getScope(), |
|
137 | - 'address' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getValue(), |
|
138 | - 'addressScope' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getScope(), |
|
139 | - 'website' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getValue(), |
|
140 | - 'websiteScope' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getScope(), |
|
141 | - 'websiteVerification' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getVerified(), |
|
142 | - 'twitter' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getValue(), |
|
143 | - 'twitterScope' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getScope(), |
|
144 | - 'twitterVerification' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getVerified(), |
|
145 | - 'groups' => $this->getGroups($user), |
|
146 | - ] + $messageParameters + $languageParameters + $localeParameters; |
|
147 | - |
|
148 | - $emails = $this->getEmails($account); |
|
149 | - |
|
150 | - $accountParameters = [ |
|
151 | - 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
152 | - 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
153 | - ]; |
|
154 | - |
|
155 | - $this->initialStateService->provideInitialState('emails', $emails); |
|
156 | - $this->initialStateService->provideInitialState('accountParameters', $accountParameters); |
|
157 | - |
|
158 | - return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * @return string the section ID, e.g. 'sharing' |
|
163 | - * @since 9.1 |
|
164 | - */ |
|
165 | - public function getSection(): string { |
|
166 | - return 'personal-info'; |
|
167 | - } |
|
168 | - |
|
169 | - /** |
|
170 | - * @return int whether the form should be rather on the top or bottom of |
|
171 | - * the admin section. The forms are arranged in ascending order of the |
|
172 | - * priority values. It is required to return a value between 0 and 100. |
|
173 | - * |
|
174 | - * E.g.: 70 |
|
175 | - * @since 9.1 |
|
176 | - */ |
|
177 | - public function getPriority(): int { |
|
178 | - return 10; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * returns a sorted list of the user's group GIDs |
|
183 | - * |
|
184 | - * @param IUser $user |
|
185 | - * @return array |
|
186 | - */ |
|
187 | - private function getGroups(IUser $user): array { |
|
188 | - $groups = array_map( |
|
189 | - static function (IGroup $group) { |
|
190 | - return $group->getDisplayName(); |
|
191 | - }, |
|
192 | - $this->groupManager->getUserGroups($user) |
|
193 | - ); |
|
194 | - sort($groups); |
|
195 | - |
|
196 | - return $groups; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * returns the primary email and additional emails in an |
|
201 | - * associative array |
|
202 | - * |
|
203 | - * @param IAccount $account |
|
204 | - * @return array |
|
205 | - */ |
|
206 | - private function getEmails(IAccount $account): array { |
|
207 | - $primaryEmail = [ |
|
208 | - 'value' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(), |
|
209 | - 'scope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(), |
|
210 | - 'verified' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(), |
|
211 | - ]; |
|
212 | - |
|
213 | - $additionalEmails = array_map( |
|
214 | - function (IAccountProperty $property) { |
|
215 | - return [ |
|
216 | - 'value' => $property->getValue(), |
|
217 | - 'scope' => $property->getScope(), |
|
218 | - 'verified' => $property->getVerified(), |
|
219 | - ]; |
|
220 | - }, |
|
221 | - $account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties() |
|
222 | - ); |
|
223 | - |
|
224 | - $emails = [ |
|
225 | - 'primaryEmail' => $primaryEmail, |
|
226 | - 'additionalEmails' => $additionalEmails, |
|
227 | - ]; |
|
228 | - |
|
229 | - return $emails; |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * returns the user language, common language and other languages in an |
|
234 | - * associative array |
|
235 | - * |
|
236 | - * @param IUser $user |
|
237 | - * @return array |
|
238 | - */ |
|
239 | - private function getLanguages(IUser $user): array { |
|
240 | - $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
241 | - if ($forceLanguage !== false) { |
|
242 | - return []; |
|
243 | - } |
|
244 | - |
|
245 | - $uid = $user->getUID(); |
|
246 | - |
|
247 | - $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
248 | - $languages = $this->l10nFactory->getLanguages(); |
|
249 | - |
|
250 | - // associate the user language with the proper array |
|
251 | - $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code')); |
|
252 | - $userLang = $languages['commonlanguages'][$userLangIndex]; |
|
253 | - // search in the other languages |
|
254 | - if ($userLangIndex === false) { |
|
255 | - $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code')); |
|
256 | - $userLang = $languages['languages'][$userLangIndex]; |
|
257 | - } |
|
258 | - // if user language is not available but set somehow: show the actual code as name |
|
259 | - if (!is_array($userLang)) { |
|
260 | - $userLang = [ |
|
261 | - 'code' => $userConfLang, |
|
262 | - 'name' => $userConfLang, |
|
263 | - ]; |
|
264 | - } |
|
265 | - |
|
266 | - return array_merge( |
|
267 | - ['activelanguage' => $userLang], |
|
268 | - $languages |
|
269 | - ); |
|
270 | - } |
|
271 | - |
|
272 | - private function getLocales(IUser $user): array { |
|
273 | - $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
274 | - if ($forceLanguage !== false) { |
|
275 | - return []; |
|
276 | - } |
|
277 | - |
|
278 | - $uid = $user->getUID(); |
|
279 | - |
|
280 | - $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale()); |
|
281 | - |
|
282 | - $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
283 | - |
|
284 | - $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
285 | - |
|
286 | - $userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) { |
|
287 | - return $userLocaleString === $value['code']; |
|
288 | - }); |
|
289 | - |
|
290 | - if (!empty($userLocale)) { |
|
291 | - $userLocale = reset($userLocale); |
|
292 | - } |
|
293 | - |
|
294 | - $localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) { |
|
295 | - return 0 === strpos($localeCode['code'], $userLang); |
|
296 | - }); |
|
297 | - |
|
298 | - if (!$userLocale) { |
|
299 | - $userLocale = [ |
|
300 | - 'code' => 'en', |
|
301 | - 'name' => 'English' |
|
302 | - ]; |
|
303 | - } |
|
304 | - |
|
305 | - return [ |
|
306 | - 'activelocaleLang' => $userLocaleString, |
|
307 | - 'activelocale' => $userLocale, |
|
308 | - 'locales' => $localeCodes, |
|
309 | - 'localesForLanguage' => $localesForLanguage, |
|
310 | - ]; |
|
311 | - } |
|
312 | - |
|
313 | - /** |
|
314 | - * @param IAccount $account |
|
315 | - * @return array |
|
316 | - */ |
|
317 | - private function getMessageParameters(IAccount $account): array { |
|
318 | - $needVerifyMessage = [IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_WEBSITE, IAccountManager::PROPERTY_TWITTER]; |
|
319 | - $messageParameters = []; |
|
320 | - foreach ($needVerifyMessage as $property) { |
|
321 | - switch ($account->getProperty($property)->getVerified()) { |
|
322 | - case IAccountManager::VERIFIED: |
|
323 | - $message = $this->l->t('Verifying'); |
|
324 | - break; |
|
325 | - case IAccountManager::VERIFICATION_IN_PROGRESS: |
|
326 | - $message = $this->l->t('Verifying …'); |
|
327 | - break; |
|
328 | - default: |
|
329 | - $message = $this->l->t('Verify'); |
|
330 | - } |
|
331 | - $messageParameters[$property . 'Message'] = $message; |
|
332 | - } |
|
333 | - return $messageParameters; |
|
334 | - } |
|
57 | + /** @var IConfig */ |
|
58 | + private $config; |
|
59 | + /** @var IUserManager */ |
|
60 | + private $userManager; |
|
61 | + /** @var IAccountManager */ |
|
62 | + private $accountManager; |
|
63 | + /** @var IGroupManager */ |
|
64 | + private $groupManager; |
|
65 | + /** @var IAppManager */ |
|
66 | + private $appManager; |
|
67 | + /** @var IFactory */ |
|
68 | + private $l10nFactory; |
|
69 | + /** @var IL10N */ |
|
70 | + private $l; |
|
71 | + /** @var IInitialState */ |
|
72 | + private $initialStateService; |
|
73 | + |
|
74 | + public function __construct( |
|
75 | + IConfig $config, |
|
76 | + IUserManager $userManager, |
|
77 | + IGroupManager $groupManager, |
|
78 | + IAccountManager $accountManager, |
|
79 | + IAppManager $appManager, |
|
80 | + IFactory $l10nFactory, |
|
81 | + IL10N $l, |
|
82 | + IInitialState $initialStateService |
|
83 | + ) { |
|
84 | + $this->config = $config; |
|
85 | + $this->userManager = $userManager; |
|
86 | + $this->accountManager = $accountManager; |
|
87 | + $this->groupManager = $groupManager; |
|
88 | + $this->appManager = $appManager; |
|
89 | + $this->l10nFactory = $l10nFactory; |
|
90 | + $this->l = $l; |
|
91 | + $this->initialStateService = $initialStateService; |
|
92 | + } |
|
93 | + |
|
94 | + public function getForm(): TemplateResponse { |
|
95 | + $federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing'); |
|
96 | + $lookupServerUploadEnabled = false; |
|
97 | + if ($federatedFileSharingEnabled) { |
|
98 | + /** @var FederatedShareProvider $shareProvider */ |
|
99 | + $shareProvider = \OC::$server->query(FederatedShareProvider::class); |
|
100 | + $lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled(); |
|
101 | + } |
|
102 | + |
|
103 | + $uid = \OC_User::getUser(); |
|
104 | + $user = $this->userManager->get($uid); |
|
105 | + $account = $this->accountManager->getAccount($user); |
|
106 | + |
|
107 | + // make sure FS is setup before querying storage related stuff... |
|
108 | + \OC_Util::setupFS($user->getUID()); |
|
109 | + |
|
110 | + $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
111 | + if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
112 | + $totalSpace = $this->l->t('Unlimited'); |
|
113 | + } else { |
|
114 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
115 | + } |
|
116 | + |
|
117 | + $languageParameters = $this->getLanguages($user); |
|
118 | + $localeParameters = $this->getLocales($user); |
|
119 | + $messageParameters = $this->getMessageParameters($account); |
|
120 | + |
|
121 | + $parameters = [ |
|
122 | + 'total_space' => $totalSpace, |
|
123 | + 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
124 | + 'usage_relative' => round($storageInfo['relative']), |
|
125 | + 'quota' => $storageInfo['quota'], |
|
126 | + 'avatarChangeSupported' => $user->canChangeAvatar(), |
|
127 | + 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
128 | + 'avatarScope' => $account->getProperty(IAccountManager::PROPERTY_AVATAR)->getScope(), |
|
129 | + 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
130 | + 'displayName' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getValue(), |
|
131 | + 'displayNameScope' => $account->getProperty(IAccountManager::PROPERTY_DISPLAYNAME)->getScope(), |
|
132 | + 'email' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(), |
|
133 | + 'emailScope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(), |
|
134 | + 'emailVerification' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(), |
|
135 | + 'phone' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getValue(), |
|
136 | + 'phoneScope' => $account->getProperty(IAccountManager::PROPERTY_PHONE)->getScope(), |
|
137 | + 'address' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getValue(), |
|
138 | + 'addressScope' => $account->getProperty(IAccountManager::PROPERTY_ADDRESS)->getScope(), |
|
139 | + 'website' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getValue(), |
|
140 | + 'websiteScope' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getScope(), |
|
141 | + 'websiteVerification' => $account->getProperty(IAccountManager::PROPERTY_WEBSITE)->getVerified(), |
|
142 | + 'twitter' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getValue(), |
|
143 | + 'twitterScope' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getScope(), |
|
144 | + 'twitterVerification' => $account->getProperty(IAccountManager::PROPERTY_TWITTER)->getVerified(), |
|
145 | + 'groups' => $this->getGroups($user), |
|
146 | + ] + $messageParameters + $languageParameters + $localeParameters; |
|
147 | + |
|
148 | + $emails = $this->getEmails($account); |
|
149 | + |
|
150 | + $accountParameters = [ |
|
151 | + 'displayNameChangeSupported' => $user->canChangeDisplayName(), |
|
152 | + 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
153 | + ]; |
|
154 | + |
|
155 | + $this->initialStateService->provideInitialState('emails', $emails); |
|
156 | + $this->initialStateService->provideInitialState('accountParameters', $accountParameters); |
|
157 | + |
|
158 | + return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * @return string the section ID, e.g. 'sharing' |
|
163 | + * @since 9.1 |
|
164 | + */ |
|
165 | + public function getSection(): string { |
|
166 | + return 'personal-info'; |
|
167 | + } |
|
168 | + |
|
169 | + /** |
|
170 | + * @return int whether the form should be rather on the top or bottom of |
|
171 | + * the admin section. The forms are arranged in ascending order of the |
|
172 | + * priority values. It is required to return a value between 0 and 100. |
|
173 | + * |
|
174 | + * E.g.: 70 |
|
175 | + * @since 9.1 |
|
176 | + */ |
|
177 | + public function getPriority(): int { |
|
178 | + return 10; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * returns a sorted list of the user's group GIDs |
|
183 | + * |
|
184 | + * @param IUser $user |
|
185 | + * @return array |
|
186 | + */ |
|
187 | + private function getGroups(IUser $user): array { |
|
188 | + $groups = array_map( |
|
189 | + static function (IGroup $group) { |
|
190 | + return $group->getDisplayName(); |
|
191 | + }, |
|
192 | + $this->groupManager->getUserGroups($user) |
|
193 | + ); |
|
194 | + sort($groups); |
|
195 | + |
|
196 | + return $groups; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * returns the primary email and additional emails in an |
|
201 | + * associative array |
|
202 | + * |
|
203 | + * @param IAccount $account |
|
204 | + * @return array |
|
205 | + */ |
|
206 | + private function getEmails(IAccount $account): array { |
|
207 | + $primaryEmail = [ |
|
208 | + 'value' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getValue(), |
|
209 | + 'scope' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getScope(), |
|
210 | + 'verified' => $account->getProperty(IAccountManager::PROPERTY_EMAIL)->getVerified(), |
|
211 | + ]; |
|
212 | + |
|
213 | + $additionalEmails = array_map( |
|
214 | + function (IAccountProperty $property) { |
|
215 | + return [ |
|
216 | + 'value' => $property->getValue(), |
|
217 | + 'scope' => $property->getScope(), |
|
218 | + 'verified' => $property->getVerified(), |
|
219 | + ]; |
|
220 | + }, |
|
221 | + $account->getPropertyCollection(IAccountManager::COLLECTION_EMAIL)->getProperties() |
|
222 | + ); |
|
223 | + |
|
224 | + $emails = [ |
|
225 | + 'primaryEmail' => $primaryEmail, |
|
226 | + 'additionalEmails' => $additionalEmails, |
|
227 | + ]; |
|
228 | + |
|
229 | + return $emails; |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * returns the user language, common language and other languages in an |
|
234 | + * associative array |
|
235 | + * |
|
236 | + * @param IUser $user |
|
237 | + * @return array |
|
238 | + */ |
|
239 | + private function getLanguages(IUser $user): array { |
|
240 | + $forceLanguage = $this->config->getSystemValue('force_language', false); |
|
241 | + if ($forceLanguage !== false) { |
|
242 | + return []; |
|
243 | + } |
|
244 | + |
|
245 | + $uid = $user->getUID(); |
|
246 | + |
|
247 | + $userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
248 | + $languages = $this->l10nFactory->getLanguages(); |
|
249 | + |
|
250 | + // associate the user language with the proper array |
|
251 | + $userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code')); |
|
252 | + $userLang = $languages['commonlanguages'][$userLangIndex]; |
|
253 | + // search in the other languages |
|
254 | + if ($userLangIndex === false) { |
|
255 | + $userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code')); |
|
256 | + $userLang = $languages['languages'][$userLangIndex]; |
|
257 | + } |
|
258 | + // if user language is not available but set somehow: show the actual code as name |
|
259 | + if (!is_array($userLang)) { |
|
260 | + $userLang = [ |
|
261 | + 'code' => $userConfLang, |
|
262 | + 'name' => $userConfLang, |
|
263 | + ]; |
|
264 | + } |
|
265 | + |
|
266 | + return array_merge( |
|
267 | + ['activelanguage' => $userLang], |
|
268 | + $languages |
|
269 | + ); |
|
270 | + } |
|
271 | + |
|
272 | + private function getLocales(IUser $user): array { |
|
273 | + $forceLanguage = $this->config->getSystemValue('force_locale', false); |
|
274 | + if ($forceLanguage !== false) { |
|
275 | + return []; |
|
276 | + } |
|
277 | + |
|
278 | + $uid = $user->getUID(); |
|
279 | + |
|
280 | + $userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale()); |
|
281 | + |
|
282 | + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
283 | + |
|
284 | + $localeCodes = $this->l10nFactory->findAvailableLocales(); |
|
285 | + |
|
286 | + $userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) { |
|
287 | + return $userLocaleString === $value['code']; |
|
288 | + }); |
|
289 | + |
|
290 | + if (!empty($userLocale)) { |
|
291 | + $userLocale = reset($userLocale); |
|
292 | + } |
|
293 | + |
|
294 | + $localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) { |
|
295 | + return 0 === strpos($localeCode['code'], $userLang); |
|
296 | + }); |
|
297 | + |
|
298 | + if (!$userLocale) { |
|
299 | + $userLocale = [ |
|
300 | + 'code' => 'en', |
|
301 | + 'name' => 'English' |
|
302 | + ]; |
|
303 | + } |
|
304 | + |
|
305 | + return [ |
|
306 | + 'activelocaleLang' => $userLocaleString, |
|
307 | + 'activelocale' => $userLocale, |
|
308 | + 'locales' => $localeCodes, |
|
309 | + 'localesForLanguage' => $localesForLanguage, |
|
310 | + ]; |
|
311 | + } |
|
312 | + |
|
313 | + /** |
|
314 | + * @param IAccount $account |
|
315 | + * @return array |
|
316 | + */ |
|
317 | + private function getMessageParameters(IAccount $account): array { |
|
318 | + $needVerifyMessage = [IAccountManager::PROPERTY_EMAIL, IAccountManager::PROPERTY_WEBSITE, IAccountManager::PROPERTY_TWITTER]; |
|
319 | + $messageParameters = []; |
|
320 | + foreach ($needVerifyMessage as $property) { |
|
321 | + switch ($account->getProperty($property)->getVerified()) { |
|
322 | + case IAccountManager::VERIFIED: |
|
323 | + $message = $this->l->t('Verifying'); |
|
324 | + break; |
|
325 | + case IAccountManager::VERIFICATION_IN_PROGRESS: |
|
326 | + $message = $this->l->t('Verifying …'); |
|
327 | + break; |
|
328 | + default: |
|
329 | + $message = $this->l->t('Verify'); |
|
330 | + } |
|
331 | + $messageParameters[$property . 'Message'] = $message; |
|
332 | + } |
|
333 | + return $messageParameters; |
|
334 | + } |
|
335 | 335 | } |