2017-05-16 02:41:17 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2019-12-03 21:57:53 +03:00
|
|
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
|
|
|
* @author Georg Ehrke <oc.list@georgehrke.com>
|
|
|
|
* @author Joas Schilling <coding@schilljs.com>
|
|
|
|
* @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
|
2017-11-06 17:56:42 +03:00
|
|
|
* @author Morris Jobke <hey@morrisjobke.de>
|
2019-12-19 15:16:31 +03:00
|
|
|
* @author Robin Appelman <robin@icewind.nl>
|
|
|
|
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
2020-03-31 11:49:10 +03:00
|
|
|
* @author Thomas Citharel <nextcloud@tcit.fr>
|
2017-05-16 02:41:17 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
2019-12-03 21:57:53 +03:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2017-05-16 02:41:17 +03:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-01-30 15:30:45 +03:00
|
|
|
namespace OCA\Settings\Settings\Personal;
|
2017-05-16 02:41:17 +03:00
|
|
|
|
2017-05-16 03:46:42 +03:00
|
|
|
use OC\Accounts\AccountManager;
|
2020-07-13 17:23:59 +03:00
|
|
|
use OCA\FederatedFileSharing\FederatedShareProvider;
|
2017-06-16 16:00:15 +03:00
|
|
|
use OCP\App\IAppManager;
|
2017-05-16 02:41:17 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2017-05-17 13:06:51 +03:00
|
|
|
use OCP\Files\FileInfo;
|
2017-05-16 03:46:42 +03:00
|
|
|
use OCP\IConfig;
|
2017-05-17 12:51:22 +03:00
|
|
|
use OCP\IGroup;
|
2017-05-16 03:46:42 +03:00
|
|
|
use OCP\IGroupManager;
|
2017-05-17 13:06:51 +03:00
|
|
|
use OCP\IL10N;
|
2017-05-16 03:46:42 +03:00
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
|
|
|
use OCP\L10N\IFactory;
|
2017-05-16 02:41:17 +03:00
|
|
|
use OCP\Settings\ISettings;
|
|
|
|
|
|
|
|
class PersonalInfo implements ISettings {
|
2018-04-07 13:39:11 +03:00
|
|
|
|
2017-05-16 03:46:42 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
/** @var IUserManager */
|
|
|
|
private $userManager;
|
|
|
|
/** @var AccountManager */
|
|
|
|
private $accountManager;
|
|
|
|
/** @var IGroupManager */
|
|
|
|
private $groupManager;
|
2017-06-16 16:00:15 +03:00
|
|
|
/** @var IAppManager */
|
|
|
|
private $appManager;
|
2017-05-16 03:46:42 +03:00
|
|
|
/** @var IFactory */
|
|
|
|
private $l10nFactory;
|
2017-05-17 13:06:51 +03:00
|
|
|
/** @var IL10N */
|
|
|
|
private $l;
|
2017-05-16 03:46:42 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param IConfig $config
|
|
|
|
* @param IUserManager $userManager
|
|
|
|
* @param IGroupManager $groupManager
|
|
|
|
* @param AccountManager $accountManager
|
|
|
|
* @param IFactory $l10nFactory
|
2017-05-17 13:06:51 +03:00
|
|
|
* @param IL10N $l
|
2017-05-16 03:46:42 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
IConfig $config,
|
|
|
|
IUserManager $userManager,
|
|
|
|
IGroupManager $groupManager,
|
|
|
|
AccountManager $accountManager,
|
2017-06-16 16:00:15 +03:00
|
|
|
IAppManager $appManager,
|
2017-05-16 03:46:42 +03:00
|
|
|
IFactory $l10nFactory,
|
2019-03-20 00:24:16 +03:00
|
|
|
IL10N $l
|
2017-05-16 03:46:42 +03:00
|
|
|
) {
|
|
|
|
$this->config = $config;
|
|
|
|
$this->userManager = $userManager;
|
|
|
|
$this->accountManager = $accountManager;
|
|
|
|
$this->groupManager = $groupManager;
|
2017-06-16 16:00:15 +03:00
|
|
|
$this->appManager = $appManager;
|
2017-05-16 03:46:42 +03:00
|
|
|
$this->l10nFactory = $l10nFactory;
|
2017-05-17 13:06:51 +03:00
|
|
|
$this->l = $l;
|
2017-05-16 03:46:42 +03:00
|
|
|
}
|
2017-05-16 02:41:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return TemplateResponse returns the instance with all parameters set, ready to be rendered
|
|
|
|
* @since 9.1
|
|
|
|
*/
|
|
|
|
public function getForm() {
|
2017-06-16 16:00:15 +03:00
|
|
|
$federatedFileSharingEnabled = $this->appManager->isEnabledForUser('federatedfilesharing');
|
|
|
|
$lookupServerUploadEnabled = false;
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($federatedFileSharingEnabled) {
|
2020-07-13 17:23:59 +03:00
|
|
|
/** @var FederatedShareProvider $shareProvider */
|
|
|
|
$shareProvider = \OC::$server->query(FederatedShareProvider::class);
|
2017-06-16 16:00:15 +03:00
|
|
|
$lookupServerUploadEnabled = $shareProvider->isLookupServerUploadEnabled();
|
|
|
|
}
|
2017-05-16 03:46:42 +03:00
|
|
|
|
|
|
|
$uid = \OC_User::getUser();
|
|
|
|
$user = $this->userManager->get($uid);
|
|
|
|
$userData = $this->accountManager->getUser($user);
|
|
|
|
|
2017-05-17 13:06:51 +03:00
|
|
|
$storageInfo = \OC_Helper::getStorageInfo('/');
|
|
|
|
if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) {
|
|
|
|
$totalSpace = $this->l->t('Unlimited');
|
|
|
|
} else {
|
|
|
|
$totalSpace = \OC_Helper::humanFileSize($storageInfo['total']);
|
|
|
|
}
|
|
|
|
|
2017-06-23 14:15:08 +03:00
|
|
|
$languageParameters = $this->getLanguages($user);
|
2017-07-05 18:36:43 +03:00
|
|
|
$localeParameters = $this->getLocales($user);
|
2017-06-16 16:00:15 +03:00
|
|
|
$messageParameters = $this->getMessageParameters($userData);
|
2017-05-16 03:46:42 +03:00
|
|
|
|
|
|
|
$parameters = [
|
2017-05-17 13:06:51 +03:00
|
|
|
'total_space' => $totalSpace,
|
|
|
|
'usage' => \OC_Helper::humanFileSize($storageInfo['used']),
|
2017-09-28 18:58:49 +03:00
|
|
|
'usage_relative' => round($storageInfo['relative']),
|
2017-05-17 13:06:51 +03:00
|
|
|
'quota' => $storageInfo['quota'],
|
2017-07-24 13:11:22 +03:00
|
|
|
'avatarChangeSupported' => $user->canChangeAvatar(),
|
2017-05-16 03:46:42 +03:00
|
|
|
'lookupServerUploadEnabled' => $lookupServerUploadEnabled,
|
2017-06-16 16:00:15 +03:00
|
|
|
'avatarScope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'],
|
2017-07-24 13:11:22 +03:00
|
|
|
'displayNameChangeSupported' => $user->canChangeDisplayName(),
|
2017-05-16 03:46:42 +03:00
|
|
|
'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'],
|
2017-06-16 16:00:15 +03:00
|
|
|
'displayNameScope' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['scope'],
|
2017-05-16 03:46:42 +03:00
|
|
|
'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'],
|
|
|
|
'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'],
|
|
|
|
'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'],
|
|
|
|
'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'],
|
|
|
|
'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'],
|
2017-06-16 16:00:15 +03:00
|
|
|
'address' => $userData[AccountManager::PROPERTY_ADDRESS]['value'],
|
|
|
|
'addressScope' => $userData[AccountManager::PROPERTY_ADDRESS]['scope'],
|
2017-05-16 03:46:42 +03:00
|
|
|
'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'],
|
|
|
|
'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'],
|
|
|
|
'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'],
|
|
|
|
'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'],
|
|
|
|
'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'],
|
|
|
|
'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'],
|
2017-05-17 12:51:22 +03:00
|
|
|
'groups' => $this->getGroups($user),
|
2019-03-20 00:24:16 +03:00
|
|
|
] + $messageParameters + $languageParameters + $localeParameters;
|
2017-05-16 03:46:42 +03:00
|
|
|
|
|
|
|
|
2019-03-20 00:24:16 +03:00
|
|
|
return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, '');
|
2017-05-16 02:41:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string the section ID, e.g. 'sharing'
|
|
|
|
* @since 9.1
|
|
|
|
*/
|
|
|
|
public function getSection() {
|
|
|
|
return 'personal-info';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return int whether the form should be rather on the top or bottom of
|
|
|
|
* the admin section. The forms are arranged in ascending order of the
|
|
|
|
* priority values. It is required to return a value between 0 and 100.
|
|
|
|
*
|
|
|
|
* E.g.: 70
|
|
|
|
* @since 9.1
|
|
|
|
*/
|
|
|
|
public function getPriority() {
|
|
|
|
return 10;
|
|
|
|
}
|
2017-05-16 03:46:42 +03:00
|
|
|
|
2017-05-17 12:51:22 +03:00
|
|
|
/**
|
|
|
|
* returns a sorted list of the user's group GIDs
|
|
|
|
*
|
|
|
|
* @param IUser $user
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getGroups(IUser $user) {
|
|
|
|
$groups = array_map(
|
2020-04-09 14:53:40 +03:00
|
|
|
function (IGroup $group) {
|
2018-01-24 15:07:47 +03:00
|
|
|
return $group->getDisplayName();
|
2017-05-17 12:51:22 +03:00
|
|
|
},
|
|
|
|
$this->groupManager->getUserGroups($user)
|
|
|
|
);
|
|
|
|
sort($groups);
|
|
|
|
|
|
|
|
return $groups;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns the user language, common language and other languages in an
|
|
|
|
* associative array
|
|
|
|
*
|
|
|
|
* @param IUser $user
|
|
|
|
* @return array
|
|
|
|
*/
|
2017-05-16 03:46:42 +03:00
|
|
|
private function getLanguages(IUser $user) {
|
2017-06-23 14:15:08 +03:00
|
|
|
$forceLanguage = $this->config->getSystemValue('force_language', false);
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($forceLanguage !== false) {
|
2017-06-23 14:15:08 +03:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2017-05-16 03:46:42 +03:00
|
|
|
$uid = $user->getUID();
|
|
|
|
|
2018-04-07 13:39:11 +03:00
|
|
|
$userConfLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
|
|
|
|
$languages = $this->l10nFactory->getLanguages();
|
2017-06-23 14:15:08 +03:00
|
|
|
|
2018-04-07 13:39:11 +03:00
|
|
|
// associate the user language with the proper array
|
|
|
|
$userLangIndex = array_search($userConfLang, array_column($languages['commonlanguages'], 'code'));
|
|
|
|
$userLang = $languages['commonlanguages'][$userLangIndex];
|
|
|
|
// search in the other languages
|
|
|
|
if ($userLangIndex === false) {
|
2019-09-17 17:33:27 +03:00
|
|
|
$userLangIndex = array_search($userConfLang, array_column($languages['languages'], 'code'));
|
2018-04-07 13:39:11 +03:00
|
|
|
$userLang = $languages['languages'][$userLangIndex];
|
2017-05-16 03:46:42 +03:00
|
|
|
}
|
|
|
|
// if user language is not available but set somehow: show the actual code as name
|
|
|
|
if (!is_array($userLang)) {
|
|
|
|
$userLang = [
|
2018-04-07 13:39:11 +03:00
|
|
|
'code' => $userConfLang,
|
|
|
|
'name' => $userConfLang,
|
2017-05-16 03:46:42 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-04-07 13:39:11 +03:00
|
|
|
return array_merge(
|
2020-03-26 11:30:18 +03:00
|
|
|
['activelanguage' => $userLang],
|
2018-04-07 13:39:11 +03:00
|
|
|
$languages
|
|
|
|
);
|
2017-05-16 03:46:42 +03:00
|
|
|
}
|
2017-05-17 12:51:22 +03:00
|
|
|
|
2017-07-05 18:36:43 +03:00
|
|
|
private function getLocales(IUser $user) {
|
|
|
|
$forceLanguage = $this->config->getSystemValue('force_locale', false);
|
2020-04-10 15:19:56 +03:00
|
|
|
if ($forceLanguage !== false) {
|
2017-07-05 18:36:43 +03:00
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
$uid = $user->getUID();
|
|
|
|
|
2019-01-24 01:17:44 +03:00
|
|
|
$userLocaleString = $this->config->getUserValue($uid, 'core', 'locale', $this->l10nFactory->findLocale());
|
2017-07-05 18:36:43 +03:00
|
|
|
|
|
|
|
$userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage());
|
|
|
|
|
2017-07-07 12:17:54 +03:00
|
|
|
$localeCodes = $this->l10nFactory->findAvailableLocales();
|
2017-07-05 18:36:43 +03:00
|
|
|
|
2020-04-09 14:53:40 +03:00
|
|
|
$userLocale = array_filter($localeCodes, function ($value) use ($userLocaleString) {
|
2017-07-05 18:36:43 +03:00
|
|
|
return $userLocaleString === $value['code'];
|
|
|
|
});
|
|
|
|
|
2020-04-10 15:19:56 +03:00
|
|
|
if (!empty($userLocale)) {
|
2017-07-05 18:36:43 +03:00
|
|
|
$userLocale = reset($userLocale);
|
|
|
|
}
|
|
|
|
|
2020-04-09 14:53:40 +03:00
|
|
|
$localesForLanguage = array_filter($localeCodes, function ($localeCode) use ($userLang) {
|
2017-07-05 18:36:43 +03:00
|
|
|
return 0 === strpos($localeCode['code'], $userLang);
|
|
|
|
});
|
|
|
|
|
2019-12-16 17:27:08 +03:00
|
|
|
if (!$userLocale) {
|
|
|
|
$userLocale = [
|
|
|
|
'code' => 'en',
|
|
|
|
'name' => 'English'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-07-05 18:36:43 +03:00
|
|
|
return [
|
|
|
|
'activelocaleLang' => $userLocaleString,
|
|
|
|
'activelocale' => $userLocale,
|
|
|
|
'locales' => $localeCodes,
|
2018-06-27 20:40:06 +03:00
|
|
|
'localesForLanguage' => $localesForLanguage,
|
2017-07-05 18:36:43 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2017-06-16 16:00:15 +03:00
|
|
|
/**
|
|
|
|
* @param array $userData
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getMessageParameters(array $userData) {
|
|
|
|
$needVerifyMessage = [AccountManager::PROPERTY_EMAIL, AccountManager::PROPERTY_WEBSITE, AccountManager::PROPERTY_TWITTER];
|
|
|
|
$messageParameters = [];
|
|
|
|
foreach ($needVerifyMessage as $property) {
|
|
|
|
switch ($userData[$property]['verified']) {
|
|
|
|
case AccountManager::VERIFIED:
|
|
|
|
$message = $this->l->t('Verifying');
|
|
|
|
break;
|
|
|
|
case AccountManager::VERIFICATION_IN_PROGRESS:
|
|
|
|
$message = $this->l->t('Verifying …');
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$message = $this->l->t('Verify');
|
|
|
|
}
|
|
|
|
$messageParameters[$property . 'Message'] = $message;
|
|
|
|
}
|
|
|
|
return $messageParameters;
|
|
|
|
}
|
2017-05-16 02:41:17 +03:00
|
|
|
}
|