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