@@ -51,6 +51,9 @@ discard block |
||
51 | 51 | ]; |
52 | 52 | } |
53 | 53 | |
54 | + /** |
|
55 | + * @param string $type |
|
56 | + */ |
|
54 | 57 | protected function formatSections($sections, $currentSection, $type) { |
55 | 58 | $templateParameters = []; |
56 | 59 | /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
@@ -81,6 +84,9 @@ discard block |
||
81 | 84 | return $templateParameters; |
82 | 85 | } |
83 | 86 | |
87 | + /** |
|
88 | + * @param string $currentSections |
|
89 | + */ |
|
84 | 90 | protected function formatPersonalSections($currentSections) { |
85 | 91 | $sections = $this->settingsManager->getPersonalSections(); |
86 | 92 | $templateParameters = $this->formatSections($sections, $currentSections, 'personal'); |
@@ -88,6 +94,9 @@ discard block |
||
88 | 94 | return $templateParameters; |
89 | 95 | } |
90 | 96 | |
97 | + /** |
|
98 | + * @param string $currentSections |
|
99 | + */ |
|
91 | 100 | protected function formatAdminSections($currentSections) { |
92 | 101 | $sections = $this->settingsManager->getAdminSections(); |
93 | 102 | $templateParameters = $this->formatSections($sections, $currentSections, 'admin'); |
@@ -111,6 +120,9 @@ discard block |
||
111 | 120 | return ['content' => $html]; |
112 | 121 | } |
113 | 122 | |
123 | + /** |
|
124 | + * @param string $section |
|
125 | + */ |
|
114 | 126 | private function getIndexResponse($section) { |
115 | 127 | $templateParams = []; |
116 | 128 | $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); |
@@ -29,95 +29,95 @@ |
||
29 | 29 | use OCP\Settings\ISettings; |
30 | 30 | |
31 | 31 | trait CommonSettingsTrait { |
32 | - /** @var ISettingsManager */ |
|
33 | - private $settingsManager; |
|
34 | - |
|
35 | - /** |
|
36 | - * @param string $currentSection |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - private function getNavigationParameters($currentSection) { |
|
40 | - $templateParameters = [ |
|
41 | - 'personal' => $this->formatPersonalSections($currentSection), |
|
42 | - 'admin' => [] |
|
43 | - ]; |
|
44 | - |
|
45 | - if(\OC_User::isAdminUser(\OC_User::getUser())) { |
|
46 | - $templateParameters['admin'] = $this->formatAdminSections($currentSection); |
|
47 | - } |
|
48 | - |
|
49 | - return [ |
|
50 | - 'forms' => $templateParameters |
|
51 | - ]; |
|
52 | - } |
|
53 | - |
|
54 | - protected function formatSections($sections, $currentSection, $type) { |
|
55 | - $templateParameters = []; |
|
56 | - /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
|
57 | - foreach($sections as $prioritizedSections) { |
|
58 | - foreach ($prioritizedSections as $section) { |
|
59 | - if($type === 'admin') { |
|
60 | - $settings = $this->settingsManager->getAdminSettings($section->getID()); |
|
61 | - } else if($type === 'personal') { |
|
62 | - $settings = $this->settingsManager->getPersonalSettings($section->getID()); |
|
63 | - } |
|
64 | - if (empty($settings)) { |
|
65 | - continue; |
|
66 | - } |
|
67 | - |
|
68 | - $icon = ''; |
|
69 | - if ($section instanceof IIconSection) { |
|
70 | - $icon = $section->getIcon(); |
|
71 | - } |
|
72 | - |
|
73 | - $templateParameters[] = [ |
|
74 | - 'anchor' => $section->getID(), |
|
75 | - 'section-name' => $section->getName(), |
|
76 | - 'active' => $section->getID() === $currentSection, |
|
77 | - 'icon' => $icon, |
|
78 | - ]; |
|
79 | - } |
|
80 | - } |
|
81 | - return $templateParameters; |
|
82 | - } |
|
83 | - |
|
84 | - protected function formatPersonalSections($currentSections) { |
|
85 | - $sections = $this->settingsManager->getPersonalSections(); |
|
86 | - $templateParameters = $this->formatSections($sections, $currentSections, 'personal'); |
|
87 | - |
|
88 | - return $templateParameters; |
|
89 | - } |
|
90 | - |
|
91 | - protected function formatAdminSections($currentSections) { |
|
92 | - $sections = $this->settingsManager->getAdminSections(); |
|
93 | - $templateParameters = $this->formatSections($sections, $currentSections, 'admin'); |
|
94 | - |
|
95 | - return $templateParameters; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @param ISettings[] $settings |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - private function formatSettings($settings) { |
|
103 | - $html = ''; |
|
104 | - foreach ($settings as $prioritizedSettings) { |
|
105 | - foreach ($prioritizedSettings as $setting) { |
|
106 | - /** @var \OCP\Settings\ISettings $setting */ |
|
107 | - $form = $setting->getForm(); |
|
108 | - $html .= $form->renderAs('')->render(); |
|
109 | - } |
|
110 | - } |
|
111 | - return ['content' => $html]; |
|
112 | - } |
|
113 | - |
|
114 | - private function getIndexResponse($section) { |
|
115 | - $templateParams = []; |
|
116 | - $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); |
|
117 | - $templateParams = array_merge($templateParams, $this->getSettings($section)); |
|
118 | - |
|
119 | - return new TemplateResponse('settings', 'settings/frame', $templateParams); |
|
120 | - } |
|
121 | - |
|
122 | - abstract public function getSettings($section); |
|
32 | + /** @var ISettingsManager */ |
|
33 | + private $settingsManager; |
|
34 | + |
|
35 | + /** |
|
36 | + * @param string $currentSection |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + private function getNavigationParameters($currentSection) { |
|
40 | + $templateParameters = [ |
|
41 | + 'personal' => $this->formatPersonalSections($currentSection), |
|
42 | + 'admin' => [] |
|
43 | + ]; |
|
44 | + |
|
45 | + if(\OC_User::isAdminUser(\OC_User::getUser())) { |
|
46 | + $templateParameters['admin'] = $this->formatAdminSections($currentSection); |
|
47 | + } |
|
48 | + |
|
49 | + return [ |
|
50 | + 'forms' => $templateParameters |
|
51 | + ]; |
|
52 | + } |
|
53 | + |
|
54 | + protected function formatSections($sections, $currentSection, $type) { |
|
55 | + $templateParameters = []; |
|
56 | + /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
|
57 | + foreach($sections as $prioritizedSections) { |
|
58 | + foreach ($prioritizedSections as $section) { |
|
59 | + if($type === 'admin') { |
|
60 | + $settings = $this->settingsManager->getAdminSettings($section->getID()); |
|
61 | + } else if($type === 'personal') { |
|
62 | + $settings = $this->settingsManager->getPersonalSettings($section->getID()); |
|
63 | + } |
|
64 | + if (empty($settings)) { |
|
65 | + continue; |
|
66 | + } |
|
67 | + |
|
68 | + $icon = ''; |
|
69 | + if ($section instanceof IIconSection) { |
|
70 | + $icon = $section->getIcon(); |
|
71 | + } |
|
72 | + |
|
73 | + $templateParameters[] = [ |
|
74 | + 'anchor' => $section->getID(), |
|
75 | + 'section-name' => $section->getName(), |
|
76 | + 'active' => $section->getID() === $currentSection, |
|
77 | + 'icon' => $icon, |
|
78 | + ]; |
|
79 | + } |
|
80 | + } |
|
81 | + return $templateParameters; |
|
82 | + } |
|
83 | + |
|
84 | + protected function formatPersonalSections($currentSections) { |
|
85 | + $sections = $this->settingsManager->getPersonalSections(); |
|
86 | + $templateParameters = $this->formatSections($sections, $currentSections, 'personal'); |
|
87 | + |
|
88 | + return $templateParameters; |
|
89 | + } |
|
90 | + |
|
91 | + protected function formatAdminSections($currentSections) { |
|
92 | + $sections = $this->settingsManager->getAdminSections(); |
|
93 | + $templateParameters = $this->formatSections($sections, $currentSections, 'admin'); |
|
94 | + |
|
95 | + return $templateParameters; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @param ISettings[] $settings |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + private function formatSettings($settings) { |
|
103 | + $html = ''; |
|
104 | + foreach ($settings as $prioritizedSettings) { |
|
105 | + foreach ($prioritizedSettings as $setting) { |
|
106 | + /** @var \OCP\Settings\ISettings $setting */ |
|
107 | + $form = $setting->getForm(); |
|
108 | + $html .= $form->renderAs('')->render(); |
|
109 | + } |
|
110 | + } |
|
111 | + return ['content' => $html]; |
|
112 | + } |
|
113 | + |
|
114 | + private function getIndexResponse($section) { |
|
115 | + $templateParams = []; |
|
116 | + $templateParams = array_merge($templateParams, $this->getNavigationParameters($section)); |
|
117 | + $templateParams = array_merge($templateParams, $this->getSettings($section)); |
|
118 | + |
|
119 | + return new TemplateResponse('settings', 'settings/frame', $templateParams); |
|
120 | + } |
|
121 | + |
|
122 | + abstract public function getSettings($section); |
|
123 | 123 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | use OCP\Settings\IIconSection; |
29 | 29 | use OCP\Settings\ISettings; |
30 | 30 | |
31 | -trait CommonSettingsTrait { |
|
31 | +trait CommonSettingsTrait { |
|
32 | 32 | /** @var ISettingsManager */ |
33 | 33 | private $settingsManager; |
34 | 34 | |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | 'admin' => [] |
43 | 43 | ]; |
44 | 44 | |
45 | - if(\OC_User::isAdminUser(\OC_User::getUser())) { |
|
45 | + if (\OC_User::isAdminUser(\OC_User::getUser())) { |
|
46 | 46 | $templateParameters['admin'] = $this->formatAdminSections($currentSection); |
47 | 47 | } |
48 | 48 | |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | protected function formatSections($sections, $currentSection, $type) { |
55 | 55 | $templateParameters = []; |
56 | 56 | /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
57 | - foreach($sections as $prioritizedSections) { |
|
57 | + foreach ($sections as $prioritizedSections) { |
|
58 | 58 | foreach ($prioritizedSections as $section) { |
59 | - if($type === 'admin') { |
|
59 | + if ($type === 'admin') { |
|
60 | 60 | $settings = $this->settingsManager->getAdminSettings($section->getID()); |
61 | - } else if($type === 'personal') { |
|
61 | + } else if ($type === 'personal') { |
|
62 | 62 | $settings = $this->settingsManager->getPersonalSettings($section->getID()); |
63 | 63 | } |
64 | 64 | if (empty($settings)) { |
@@ -135,7 +135,7 @@ |
||
135 | 135 | $ln = array('code' => $lang, 'name' => $potentialName); |
136 | 136 | } elseif ($lang === 'en') { |
137 | 137 | $ln = ['code' => $lang, 'name' => 'English (US)']; |
138 | - }else{//fallback to language code |
|
138 | + } else{//fallback to language code |
|
139 | 139 | $ln=array('code'=>$lang, 'name'=>$lang); |
140 | 140 | } |
141 | 141 |
@@ -154,16 +154,16 @@ discard block |
||
154 | 154 | $commonLanguages = []; |
155 | 155 | $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
156 | 156 | $languageCodes = $this->l10nFactory->findAvailableLanguages(); |
157 | - foreach($languageCodes as $lang) { |
|
157 | + foreach ($languageCodes as $lang) { |
|
158 | 158 | $l = \OC::$server->getL10N('settings', $lang); |
159 | 159 | // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
160 | 160 | $potentialName = (string) $l->t('__language_name__'); |
161 | - if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
161 | + if ($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
162 | 162 | $ln = array('code' => $lang, 'name' => $potentialName); |
163 | 163 | } elseif ($lang === 'en') { |
164 | 164 | $ln = ['code' => $lang, 'name' => 'English (US)']; |
165 | - }else{//fallback to language code |
|
166 | - $ln=array('code'=>$lang, 'name'=>$lang); |
|
165 | + } else {//fallback to language code |
|
166 | + $ln = array('code'=>$lang, 'name'=>$lang); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | // put appropriate languages into appropriate arrays, to print them sorted |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | if ($lang === $userLang) { |
172 | 172 | $userLang = $ln; |
173 | 173 | } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
174 | - $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
174 | + $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)] = $ln; |
|
175 | 175 | } else { |
176 | - $languages[]=$ln; |
|
176 | + $languages[] = $ln; |
|
177 | 177 | } |
178 | 178 | } |
179 | 179 | |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | ksort($commonLanguages); |
189 | 189 | |
190 | 190 | // sort now by displayed language not the iso-code |
191 | - usort( $languages, function ($a, $b) { |
|
191 | + usort($languages, function($a, $b) { |
|
192 | 192 | if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
193 | 193 | // If a doesn't have a name, but b does, list b before a |
194 | 194 | return 1; |
@@ -37,204 +37,204 @@ |
||
37 | 37 | use OCP\Settings\ISettings; |
38 | 38 | |
39 | 39 | class PersonalInfo implements ISettings { |
40 | - /** @var IConfig */ |
|
41 | - private $config; |
|
42 | - /** @var IUserManager */ |
|
43 | - private $userManager; |
|
44 | - /** @var AccountManager */ |
|
45 | - private $accountManager; |
|
46 | - /** @var IGroupManager */ |
|
47 | - private $groupManager; |
|
48 | - /** @var IFactory */ |
|
49 | - private $l10nFactory; |
|
50 | - |
|
51 | - const COMMON_LANGUAGE_CODES = [ |
|
52 | - 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', |
|
53 | - 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' |
|
54 | - ]; |
|
55 | - |
|
56 | - /** @var IL10N */ |
|
57 | - private $l; |
|
58 | - |
|
59 | - /** |
|
60 | - * @param IConfig $config |
|
61 | - * @param IUserManager $userManager |
|
62 | - * @param IGroupManager $groupManager |
|
63 | - * @param AccountManager $accountManager |
|
64 | - * @param IFactory $l10nFactory |
|
65 | - * @param IL10N $l |
|
66 | - */ |
|
67 | - public function __construct( |
|
68 | - IConfig $config, |
|
69 | - IUserManager $userManager, |
|
70 | - IGroupManager $groupManager, |
|
71 | - AccountManager $accountManager, |
|
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->l10nFactory = $l10nFactory; |
|
80 | - $this->l = $l; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
85 | - * @since 9.1 |
|
86 | - */ |
|
87 | - public function getForm() { |
|
88 | - $lookupServerUploadEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
89 | - $lookupServerUploadEnabled = $lookupServerUploadEnabled === 'yes'; |
|
90 | - |
|
91 | - $uid = \OC_User::getUser(); |
|
92 | - $user = $this->userManager->get($uid); |
|
93 | - $userData = $this->accountManager->getUser($user); |
|
94 | - |
|
95 | - $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
96 | - if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
97 | - $totalSpace = $this->l->t('Unlimited'); |
|
98 | - } else { |
|
99 | - $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
100 | - } |
|
101 | - |
|
102 | - list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user); |
|
103 | - |
|
104 | - $parameters = [ |
|
105 | - 'total_space' => $totalSpace, |
|
106 | - 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
107 | - 'usage_relative' => $storageInfo['relative'], |
|
108 | - 'quota' => $storageInfo['quota'], |
|
109 | - 'avatarChangeSupported' => \OC_User::canUserChangeAvatar($uid), |
|
110 | - 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
111 | - 'avatar_scope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
112 | - 'displayNameChangeSupported' => \OC_User::canUserChangeDisplayName($uid), |
|
113 | - 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
114 | - 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
115 | - 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
116 | - 'emailMesage' => '', |
|
117 | - 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
118 | - 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
119 | - 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
120 | - 'address', $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
121 | - 'addressScope', $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
122 | - 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
123 | - 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
124 | - 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
125 | - 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
126 | - 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
127 | - 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
128 | - 'groups' => $this->getGroups($user), |
|
129 | - 'passwordChangeSupported' => \OC_User::canUserChangePassword($uid), |
|
130 | - 'activelanguage' => $activeLanguage, |
|
131 | - 'commonlanguages' => $commonLanguages, |
|
132 | - 'languages' => $languages, |
|
133 | - ]; |
|
134 | - |
|
135 | - |
|
136 | - return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @return string the section ID, e.g. 'sharing' |
|
141 | - * @since 9.1 |
|
142 | - */ |
|
143 | - public function getSection() { |
|
144 | - return 'personal-info'; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * @return int whether the form should be rather on the top or bottom of |
|
149 | - * the admin section. The forms are arranged in ascending order of the |
|
150 | - * priority values. It is required to return a value between 0 and 100. |
|
151 | - * |
|
152 | - * E.g.: 70 |
|
153 | - * @since 9.1 |
|
154 | - */ |
|
155 | - public function getPriority() { |
|
156 | - return 10; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * returns a sorted list of the user's group GIDs |
|
161 | - * |
|
162 | - * @param IUser $user |
|
163 | - * @return array |
|
164 | - */ |
|
165 | - private function getGroups(IUser $user) { |
|
166 | - $groups = array_map( |
|
167 | - function(IGroup $group) { |
|
168 | - return $group->getGID(); |
|
169 | - }, |
|
170 | - $this->groupManager->getUserGroups($user) |
|
171 | - ); |
|
172 | - sort($groups); |
|
173 | - |
|
174 | - return $groups; |
|
175 | - } |
|
176 | - |
|
177 | - /** |
|
178 | - * returns the user language, common language and other languages in an |
|
179 | - * associative array |
|
180 | - * |
|
181 | - * @param IUser $user |
|
182 | - * @return array |
|
183 | - */ |
|
184 | - private function getLanguages(IUser $user) { |
|
185 | - $uid = $user->getUID(); |
|
186 | - |
|
187 | - $commonLanguages = []; |
|
188 | - $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
189 | - $languageCodes = $this->l10nFactory->findAvailableLanguages(); |
|
190 | - foreach($languageCodes as $lang) { |
|
191 | - $l = \OC::$server->getL10N('settings', $lang); |
|
192 | - // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
|
193 | - $potentialName = (string) $l->t('__language_name__'); |
|
194 | - if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
195 | - $ln = array('code' => $lang, 'name' => $potentialName); |
|
196 | - } elseif ($lang === 'en') { |
|
197 | - $ln = ['code' => $lang, 'name' => 'English (US)']; |
|
198 | - }else{//fallback to language code |
|
199 | - $ln=array('code'=>$lang, 'name'=>$lang); |
|
200 | - } |
|
201 | - |
|
202 | - // put appropriate languages into appropriate arrays, to print them sorted |
|
203 | - // used language -> common languages -> divider -> other languages |
|
204 | - if ($lang === $userLang) { |
|
205 | - $userLang = $ln; |
|
206 | - } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
|
207 | - $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
208 | - } else { |
|
209 | - $languages[]=$ln; |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - // if user language is not available but set somehow: show the actual code as name |
|
214 | - if (!is_array($userLang)) { |
|
215 | - $userLang = [ |
|
216 | - 'code' => $userLang, |
|
217 | - 'name' => $userLang, |
|
218 | - ]; |
|
219 | - } |
|
220 | - |
|
221 | - ksort($commonLanguages); |
|
222 | - |
|
223 | - // sort now by displayed language not the iso-code |
|
224 | - usort( $languages, function ($a, $b) { |
|
225 | - if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
|
226 | - // If a doesn't have a name, but b does, list b before a |
|
227 | - return 1; |
|
228 | - } |
|
229 | - if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { |
|
230 | - // If a does have a name, but b doesn't, list a before b |
|
231 | - return -1; |
|
232 | - } |
|
233 | - // Otherwise compare the names |
|
234 | - return strcmp($a['name'], $b['name']); |
|
235 | - }); |
|
236 | - |
|
237 | - return [$userLang, $commonLanguages, $languages]; |
|
238 | - } |
|
40 | + /** @var IConfig */ |
|
41 | + private $config; |
|
42 | + /** @var IUserManager */ |
|
43 | + private $userManager; |
|
44 | + /** @var AccountManager */ |
|
45 | + private $accountManager; |
|
46 | + /** @var IGroupManager */ |
|
47 | + private $groupManager; |
|
48 | + /** @var IFactory */ |
|
49 | + private $l10nFactory; |
|
50 | + |
|
51 | + const COMMON_LANGUAGE_CODES = [ |
|
52 | + 'en', 'es', 'fr', 'de', 'de_DE', 'ja', 'ar', 'ru', 'nl', 'it', |
|
53 | + 'pt_BR', 'pt_PT', 'da', 'fi_FI', 'nb_NO', 'sv', 'tr', 'zh_CN', 'ko' |
|
54 | + ]; |
|
55 | + |
|
56 | + /** @var IL10N */ |
|
57 | + private $l; |
|
58 | + |
|
59 | + /** |
|
60 | + * @param IConfig $config |
|
61 | + * @param IUserManager $userManager |
|
62 | + * @param IGroupManager $groupManager |
|
63 | + * @param AccountManager $accountManager |
|
64 | + * @param IFactory $l10nFactory |
|
65 | + * @param IL10N $l |
|
66 | + */ |
|
67 | + public function __construct( |
|
68 | + IConfig $config, |
|
69 | + IUserManager $userManager, |
|
70 | + IGroupManager $groupManager, |
|
71 | + AccountManager $accountManager, |
|
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->l10nFactory = $l10nFactory; |
|
80 | + $this->l = $l; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
85 | + * @since 9.1 |
|
86 | + */ |
|
87 | + public function getForm() { |
|
88 | + $lookupServerUploadEnabled = $this->config->getAppValue('files_sharing', 'lookupServerUploadEnabled', 'yes'); |
|
89 | + $lookupServerUploadEnabled = $lookupServerUploadEnabled === 'yes'; |
|
90 | + |
|
91 | + $uid = \OC_User::getUser(); |
|
92 | + $user = $this->userManager->get($uid); |
|
93 | + $userData = $this->accountManager->getUser($user); |
|
94 | + |
|
95 | + $storageInfo = \OC_Helper::getStorageInfo('/'); |
|
96 | + if ($storageInfo['quota'] === FileInfo::SPACE_UNLIMITED) { |
|
97 | + $totalSpace = $this->l->t('Unlimited'); |
|
98 | + } else { |
|
99 | + $totalSpace = \OC_Helper::humanFileSize($storageInfo['total']); |
|
100 | + } |
|
101 | + |
|
102 | + list($activeLanguage, $commonLanguages, $languages) = $this->getLanguages($user); |
|
103 | + |
|
104 | + $parameters = [ |
|
105 | + 'total_space' => $totalSpace, |
|
106 | + 'usage' => \OC_Helper::humanFileSize($storageInfo['used']), |
|
107 | + 'usage_relative' => $storageInfo['relative'], |
|
108 | + 'quota' => $storageInfo['quota'], |
|
109 | + 'avatarChangeSupported' => \OC_User::canUserChangeAvatar($uid), |
|
110 | + 'lookupServerUploadEnabled' => $lookupServerUploadEnabled, |
|
111 | + 'avatar_scope' => $userData[AccountManager::PROPERTY_AVATAR]['scope'], |
|
112 | + 'displayNameChangeSupported' => \OC_User::canUserChangeDisplayName($uid), |
|
113 | + 'displayName' => $userData[AccountManager::PROPERTY_DISPLAYNAME]['value'], |
|
114 | + 'email' => $userData[AccountManager::PROPERTY_EMAIL]['value'], |
|
115 | + 'emailScope' => $userData[AccountManager::PROPERTY_EMAIL]['scope'], |
|
116 | + 'emailMesage' => '', |
|
117 | + 'emailVerification' => $userData[AccountManager::PROPERTY_EMAIL]['verified'], |
|
118 | + 'phone' => $userData[AccountManager::PROPERTY_PHONE]['value'], |
|
119 | + 'phoneScope' => $userData[AccountManager::PROPERTY_PHONE]['scope'], |
|
120 | + 'address', $userData[AccountManager::PROPERTY_ADDRESS]['value'], |
|
121 | + 'addressScope', $userData[AccountManager::PROPERTY_ADDRESS]['scope'], |
|
122 | + 'website' => $userData[AccountManager::PROPERTY_WEBSITE]['value'], |
|
123 | + 'websiteScope' => $userData[AccountManager::PROPERTY_WEBSITE]['scope'], |
|
124 | + 'websiteVerification' => $userData[AccountManager::PROPERTY_WEBSITE]['verified'], |
|
125 | + 'twitter' => $userData[AccountManager::PROPERTY_TWITTER]['value'], |
|
126 | + 'twitterScope' => $userData[AccountManager::PROPERTY_TWITTER]['scope'], |
|
127 | + 'twitterVerification' => $userData[AccountManager::PROPERTY_TWITTER]['verified'], |
|
128 | + 'groups' => $this->getGroups($user), |
|
129 | + 'passwordChangeSupported' => \OC_User::canUserChangePassword($uid), |
|
130 | + 'activelanguage' => $activeLanguage, |
|
131 | + 'commonlanguages' => $commonLanguages, |
|
132 | + 'languages' => $languages, |
|
133 | + ]; |
|
134 | + |
|
135 | + |
|
136 | + return new TemplateResponse('settings', 'settings/personal/personal.info', $parameters, ''); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @return string the section ID, e.g. 'sharing' |
|
141 | + * @since 9.1 |
|
142 | + */ |
|
143 | + public function getSection() { |
|
144 | + return 'personal-info'; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * @return int whether the form should be rather on the top or bottom of |
|
149 | + * the admin section. The forms are arranged in ascending order of the |
|
150 | + * priority values. It is required to return a value between 0 and 100. |
|
151 | + * |
|
152 | + * E.g.: 70 |
|
153 | + * @since 9.1 |
|
154 | + */ |
|
155 | + public function getPriority() { |
|
156 | + return 10; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * returns a sorted list of the user's group GIDs |
|
161 | + * |
|
162 | + * @param IUser $user |
|
163 | + * @return array |
|
164 | + */ |
|
165 | + private function getGroups(IUser $user) { |
|
166 | + $groups = array_map( |
|
167 | + function(IGroup $group) { |
|
168 | + return $group->getGID(); |
|
169 | + }, |
|
170 | + $this->groupManager->getUserGroups($user) |
|
171 | + ); |
|
172 | + sort($groups); |
|
173 | + |
|
174 | + return $groups; |
|
175 | + } |
|
176 | + |
|
177 | + /** |
|
178 | + * returns the user language, common language and other languages in an |
|
179 | + * associative array |
|
180 | + * |
|
181 | + * @param IUser $user |
|
182 | + * @return array |
|
183 | + */ |
|
184 | + private function getLanguages(IUser $user) { |
|
185 | + $uid = $user->getUID(); |
|
186 | + |
|
187 | + $commonLanguages = []; |
|
188 | + $userLang = $this->config->getUserValue($uid, 'core', 'lang', $this->l10nFactory->findLanguage()); |
|
189 | + $languageCodes = $this->l10nFactory->findAvailableLanguages(); |
|
190 | + foreach($languageCodes as $lang) { |
|
191 | + $l = \OC::$server->getL10N('settings', $lang); |
|
192 | + // TRANSLATORS this is the language name for the language switcher in the personal settings and should be the localized version |
|
193 | + $potentialName = (string) $l->t('__language_name__'); |
|
194 | + if($l->getLanguageCode() === $lang && substr($potentialName, 0, 1) !== '_') {//first check if the language name is in the translation file |
|
195 | + $ln = array('code' => $lang, 'name' => $potentialName); |
|
196 | + } elseif ($lang === 'en') { |
|
197 | + $ln = ['code' => $lang, 'name' => 'English (US)']; |
|
198 | + }else{//fallback to language code |
|
199 | + $ln=array('code'=>$lang, 'name'=>$lang); |
|
200 | + } |
|
201 | + |
|
202 | + // put appropriate languages into appropriate arrays, to print them sorted |
|
203 | + // used language -> common languages -> divider -> other languages |
|
204 | + if ($lang === $userLang) { |
|
205 | + $userLang = $ln; |
|
206 | + } elseif (in_array($lang, self::COMMON_LANGUAGE_CODES)) { |
|
207 | + $commonLanguages[array_search($lang, self::COMMON_LANGUAGE_CODES)]=$ln; |
|
208 | + } else { |
|
209 | + $languages[]=$ln; |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + // if user language is not available but set somehow: show the actual code as name |
|
214 | + if (!is_array($userLang)) { |
|
215 | + $userLang = [ |
|
216 | + 'code' => $userLang, |
|
217 | + 'name' => $userLang, |
|
218 | + ]; |
|
219 | + } |
|
220 | + |
|
221 | + ksort($commonLanguages); |
|
222 | + |
|
223 | + // sort now by displayed language not the iso-code |
|
224 | + usort( $languages, function ($a, $b) { |
|
225 | + if ($a['code'] === $a['name'] && $b['code'] !== $b['name']) { |
|
226 | + // If a doesn't have a name, but b does, list b before a |
|
227 | + return 1; |
|
228 | + } |
|
229 | + if ($a['code'] !== $a['name'] && $b['code'] === $b['name']) { |
|
230 | + // If a does have a name, but b doesn't, list a before b |
|
231 | + return -1; |
|
232 | + } |
|
233 | + // Otherwise compare the names |
|
234 | + return strcmp($a['name'], $b['name']); |
|
235 | + }); |
|
236 | + |
|
237 | + return [$userLang, $commonLanguages, $languages]; |
|
238 | + } |
|
239 | 239 | |
240 | 240 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
79 | 79 | $settings = $this->settingsManager->getAdminSettings($section); |
80 | 80 | $formatted = $this->formatSettings($settings); |
81 | - if($section === 'additional') { |
|
81 | + if ($section === 'additional') { |
|
82 | 82 | $formatted['content'] .= $this->getLegacyForms(); |
83 | 83 | } |
84 | 84 | return $formatted; |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | private function getLegacyForms() { |
91 | 91 | $forms = \OC_App::getForms('admin'); |
92 | 92 | |
93 | - $forms = array_map(function ($form) { |
|
93 | + $forms = array_map(function($form) { |
|
94 | 94 | if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
95 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
95 | + $sectionName = str_replace('<h2'.$regs['class'].'>', '', $regs[0]); |
|
96 | 96 | $sectionName = str_replace('</h2>', '', $sectionName); |
97 | 97 | $anchor = strtolower($sectionName); |
98 | 98 | $anchor = str_replace(' ', '-', $anchor); |
@@ -35,84 +35,84 @@ |
||
35 | 35 | * @package OC\Settings\Controller |
36 | 36 | */ |
37 | 37 | class AdminSettingsController extends Controller { |
38 | - use CommonSettingsTrait; |
|
38 | + use CommonSettingsTrait; |
|
39 | 39 | |
40 | - /** @var INavigationManager */ |
|
41 | - private $navigationManager; |
|
42 | - /** @var ISettingsManager */ |
|
43 | - private $settingsManager; |
|
40 | + /** @var INavigationManager */ |
|
41 | + private $navigationManager; |
|
42 | + /** @var ISettingsManager */ |
|
43 | + private $settingsManager; |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param string $appName |
|
47 | - * @param IRequest $request |
|
48 | - * @param INavigationManager $navigationManager |
|
49 | - * @param ISettingsManager $settingsManager |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - $appName, |
|
53 | - IRequest $request, |
|
54 | - INavigationManager $navigationManager, |
|
55 | - ISettingsManager $settingsManager |
|
56 | - ) { |
|
57 | - parent::__construct($appName, $request); |
|
58 | - $this->navigationManager = $navigationManager; |
|
59 | - $this->settingsManager = $settingsManager; |
|
60 | - } |
|
45 | + /** |
|
46 | + * @param string $appName |
|
47 | + * @param IRequest $request |
|
48 | + * @param INavigationManager $navigationManager |
|
49 | + * @param ISettingsManager $settingsManager |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + $appName, |
|
53 | + IRequest $request, |
|
54 | + INavigationManager $navigationManager, |
|
55 | + ISettingsManager $settingsManager |
|
56 | + ) { |
|
57 | + parent::__construct($appName, $request); |
|
58 | + $this->navigationManager = $navigationManager; |
|
59 | + $this->settingsManager = $settingsManager; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @param string $section |
|
64 | - * @return TemplateResponse |
|
65 | - * |
|
66 | - * @NoCSRFRequired |
|
67 | - */ |
|
68 | - public function index($section) { |
|
69 | - $this->navigationManager->setActiveEntry('admin'); |
|
70 | - return $this->getIndexResponse($section); |
|
71 | - } |
|
62 | + /** |
|
63 | + * @param string $section |
|
64 | + * @return TemplateResponse |
|
65 | + * |
|
66 | + * @NoCSRFRequired |
|
67 | + */ |
|
68 | + public function index($section) { |
|
69 | + $this->navigationManager->setActiveEntry('admin'); |
|
70 | + return $this->getIndexResponse($section); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @param string $section |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - private function getSettings($section) { |
|
78 | - // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
79 | - $settings = $this->settingsManager->getAdminSettings($section); |
|
80 | - $formatted = $this->formatSettings($settings); |
|
81 | - if($section === 'additional') { |
|
82 | - $formatted['content'] .= $this->getLegacyForms(); |
|
83 | - } |
|
84 | - return $formatted; |
|
85 | - } |
|
73 | + /** |
|
74 | + * @param string $section |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + private function getSettings($section) { |
|
78 | + // PhpStorm shows this as unused, but is required by CommonSettingsTrait |
|
79 | + $settings = $this->settingsManager->getAdminSettings($section); |
|
80 | + $formatted = $this->formatSettings($settings); |
|
81 | + if($section === 'additional') { |
|
82 | + $formatted['content'] .= $this->getLegacyForms(); |
|
83 | + } |
|
84 | + return $formatted; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @return bool|string |
|
89 | - */ |
|
90 | - private function getLegacyForms() { |
|
91 | - $forms = \OC_App::getForms('admin'); |
|
87 | + /** |
|
88 | + * @return bool|string |
|
89 | + */ |
|
90 | + private function getLegacyForms() { |
|
91 | + $forms = \OC_App::getForms('admin'); |
|
92 | 92 | |
93 | - $forms = array_map(function ($form) { |
|
94 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
95 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
96 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
97 | - $anchor = strtolower($sectionName); |
|
98 | - $anchor = str_replace(' ', '-', $anchor); |
|
93 | + $forms = array_map(function ($form) { |
|
94 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
95 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
96 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
97 | + $anchor = strtolower($sectionName); |
|
98 | + $anchor = str_replace(' ', '-', $anchor); |
|
99 | 99 | |
100 | - return array( |
|
101 | - 'anchor' => $anchor, |
|
102 | - 'section-name' => $sectionName, |
|
103 | - 'form' => $form |
|
104 | - ); |
|
105 | - } |
|
106 | - return array( |
|
107 | - 'form' => $form |
|
108 | - ); |
|
109 | - }, $forms); |
|
100 | + return array( |
|
101 | + 'anchor' => $anchor, |
|
102 | + 'section-name' => $sectionName, |
|
103 | + 'form' => $form |
|
104 | + ); |
|
105 | + } |
|
106 | + return array( |
|
107 | + 'form' => $form |
|
108 | + ); |
|
109 | + }, $forms); |
|
110 | 110 | |
111 | - $out = new Template('settings', 'settings/additional'); |
|
112 | - $out->assign('forms', $forms); |
|
111 | + $out = new Template('settings', 'settings/additional'); |
|
112 | + $out->assign('forms', $forms); |
|
113 | 113 | |
114 | - return $out->fetchPage(); |
|
115 | - } |
|
114 | + return $out->fetchPage(); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | } |
@@ -32,13 +32,13 @@ discard block |
||
32 | 32 | <ul> |
33 | 33 | <li class="settings-caption">Personal</li> |
34 | 34 | <?php |
35 | - foreach($_['forms']['personal'] as $form) { |
|
36 | - if (isset($form['anchor'])) { |
|
37 | - $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]); |
|
38 | - $class = 'nav-icon-' . $form['anchor']; |
|
39 | - $sectionName = $form['section-name']; |
|
40 | - $active = $form['active'] ? ' class="active"' : ''; |
|
41 | - ?> |
|
35 | + foreach($_['forms']['personal'] as $form) { |
|
36 | + if (isset($form['anchor'])) { |
|
37 | + $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]); |
|
38 | + $class = 'nav-icon-' . $form['anchor']; |
|
39 | + $sectionName = $form['section-name']; |
|
40 | + $active = $form['active'] ? ' class="active"' : ''; |
|
41 | + ?> |
|
42 | 42 | <li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?>> |
43 | 43 | <a href="<?php p($anchor); ?>"> |
44 | 44 | <?php if (!empty($form['icon'])) { ?> |
@@ -50,24 +50,24 @@ discard block |
||
50 | 50 | </a> |
51 | 51 | </li> |
52 | 52 | <?php |
53 | - } |
|
54 | - } |
|
55 | - ?> |
|
53 | + } |
|
54 | + } |
|
55 | + ?> |
|
56 | 56 | |
57 | 57 | <?php |
58 | - if(!empty($_['forms']['admin'])) { |
|
59 | - ?> |
|
58 | + if(!empty($_['forms']['admin'])) { |
|
59 | + ?> |
|
60 | 60 | <li class="settings-caption">Administration</li> |
61 | 61 | <?php |
62 | - } |
|
63 | - foreach($_['forms']['admin'] as $form) { |
|
64 | - if (isset($form['anchor'])) { |
|
62 | + } |
|
63 | + foreach($_['forms']['admin'] as $form) { |
|
64 | + if (isset($form['anchor'])) { |
|
65 | 65 | |
66 | - $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); |
|
67 | - $class = 'nav-icon-' . $form['anchor']; |
|
68 | - $sectionName = $form['section-name']; |
|
69 | - $active = $form['active'] ? ' class="active"' : ''; |
|
70 | - ?> |
|
66 | + $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); |
|
67 | + $class = 'nav-icon-' . $form['anchor']; |
|
68 | + $sectionName = $form['section-name']; |
|
69 | + $active = $form['active'] ? ' class="active"' : ''; |
|
70 | + ?> |
|
71 | 71 | <li <?php print_unescaped($form['active'] ? ' class="active"' : ''); ?>> |
72 | 72 | <a href="<?php p($anchor); ?>"> |
73 | 73 | <?php if (!empty($form['icon'])) { ?> |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | </a> |
80 | 80 | </li> |
81 | 81 | <?php |
82 | - } |
|
83 | - } |
|
84 | - ?> |
|
82 | + } |
|
83 | + } |
|
84 | + ?> |
|
85 | 85 | </ul> |
86 | 86 | </div> |
87 | 87 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | */ |
23 | 23 | |
24 | 24 | style('settings', 'settings'); |
25 | -script('settings', [ 'settings', 'admin', 'log', 'certificates'] ); |
|
25 | +script('settings', ['settings', 'admin', 'log', 'certificates']); |
|
26 | 26 | script('core', ['multiselect', 'setupchecks']); |
27 | 27 | script('files', 'jquery.fileupload'); |
28 | 28 | |
@@ -32,10 +32,10 @@ discard block |
||
32 | 32 | <ul> |
33 | 33 | <li class="settings-caption">Personal</li> |
34 | 34 | <?php |
35 | - foreach($_['forms']['personal'] as $form) { |
|
35 | + foreach ($_['forms']['personal'] as $form) { |
|
36 | 36 | if (isset($form['anchor'])) { |
37 | 37 | $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.PersonalSettings.index', ['section' => $form['anchor']]); |
38 | - $class = 'nav-icon-' . $form['anchor']; |
|
38 | + $class = 'nav-icon-'.$form['anchor']; |
|
39 | 39 | $sectionName = $form['section-name']; |
40 | 40 | $active = $form['active'] ? ' class="active"' : ''; |
41 | 41 | ?> |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | ?> |
56 | 56 | |
57 | 57 | <?php |
58 | - if(!empty($_['forms']['admin'])) { |
|
58 | + if (!empty($_['forms']['admin'])) { |
|
59 | 59 | ?> |
60 | 60 | <li class="settings-caption">Administration</li> |
61 | 61 | <?php |
62 | 62 | } |
63 | - foreach($_['forms']['admin'] as $form) { |
|
63 | + foreach ($_['forms']['admin'] as $form) { |
|
64 | 64 | if (isset($form['anchor'])) { |
65 | 65 | |
66 | 66 | $anchor = \OC::$server->getURLGenerator()->linkToRoute('settings.AdminSettings.index', ['section' => $form['anchor']]); |
67 | - $class = 'nav-icon-' . $form['anchor']; |
|
67 | + $class = 'nav-icon-'.$form['anchor']; |
|
68 | 68 | $sectionName = $form['section-name']; |
69 | 69 | $active = $form['active'] ? ' class="active"' : ''; |
70 | 70 | ?> |
@@ -36,77 +36,77 @@ |
||
36 | 36 | |
37 | 37 | $application = new Application(); |
38 | 38 | $application->registerRoutes($this, [ |
39 | - 'resources' => [ |
|
40 | - 'users' => ['url' => '/settings/users/users'], |
|
41 | - 'AuthSettings' => ['url' => '/settings/personal/authtokens'], |
|
42 | - ], |
|
43 | - 'routes' => [ |
|
44 | - ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'], |
|
45 | - ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'], |
|
46 | - ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'], |
|
47 | - ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'], |
|
48 | - ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'], |
|
49 | - ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'], |
|
50 | - ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'], |
|
51 | - ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'], |
|
52 | - ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'], |
|
53 | - ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'], |
|
54 | - ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'], |
|
55 | - ['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'], |
|
56 | - ['name' => 'Users#setEnabled', 'url' => '/settings/users/{id}/setEnabled', 'verb' => 'POST'], |
|
57 | - ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'], |
|
58 | - ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'], |
|
59 | - ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'], |
|
60 | - ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'], |
|
61 | - ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'], |
|
62 | - ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'], |
|
63 | - ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'], |
|
64 | - ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'], |
|
65 | - ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
66 | - ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'], |
|
67 | - ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
68 | - ['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info']], |
|
69 | - ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']], |
|
70 | - ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], |
|
71 | - ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'], |
|
72 | - ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'], |
|
73 | - ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'], |
|
74 | - ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'], |
|
75 | - ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'], |
|
76 | - ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'], |
|
77 | - ['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'], |
|
78 | - ['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'], |
|
79 | - ] |
|
39 | + 'resources' => [ |
|
40 | + 'users' => ['url' => '/settings/users/users'], |
|
41 | + 'AuthSettings' => ['url' => '/settings/personal/authtokens'], |
|
42 | + ], |
|
43 | + 'routes' => [ |
|
44 | + ['name' => 'MailSettings#setMailSettings', 'url' => '/settings/admin/mailsettings', 'verb' => 'POST'], |
|
45 | + ['name' => 'MailSettings#storeCredentials', 'url' => '/settings/admin/mailsettings/credentials', 'verb' => 'POST'], |
|
46 | + ['name' => 'MailSettings#sendTestMail', 'url' => '/settings/admin/mailtest', 'verb' => 'POST'], |
|
47 | + ['name' => 'Encryption#startMigration', 'url' => '/settings/admin/startmigration', 'verb' => 'POST'], |
|
48 | + ['name' => 'AppSettings#listCategories', 'url' => '/settings/apps/categories', 'verb' => 'GET'], |
|
49 | + ['name' => 'AppSettings#viewApps', 'url' => '/settings/apps', 'verb' => 'GET'], |
|
50 | + ['name' => 'AppSettings#listApps', 'url' => '/settings/apps/list', 'verb' => 'GET'], |
|
51 | + ['name' => 'SecuritySettings#trustedDomains', 'url' => '/settings/admin/security/trustedDomains', 'verb' => 'POST'], |
|
52 | + ['name' => 'Users#setDisplayName', 'url' => '/settings/users/{username}/displayName', 'verb' => 'POST'], |
|
53 | + ['name' => 'Users#setEMailAddress', 'url' => '/settings/users/{id}/mailAddress', 'verb' => 'PUT'], |
|
54 | + ['name' => 'Users#setUserSettings', 'url' => '/settings/users/{username}/settings', 'verb' => 'PUT'], |
|
55 | + ['name' => 'Users#getVerificationCode', 'url' => '/settings/users/{account}/verify', 'verb' => 'GET'], |
|
56 | + ['name' => 'Users#setEnabled', 'url' => '/settings/users/{id}/setEnabled', 'verb' => 'POST'], |
|
57 | + ['name' => 'Users#stats', 'url' => '/settings/users/stats', 'verb' => 'GET'], |
|
58 | + ['name' => 'LogSettings#setLogLevel', 'url' => '/settings/admin/log/level', 'verb' => 'POST'], |
|
59 | + ['name' => 'LogSettings#getEntries', 'url' => '/settings/admin/log/entries', 'verb' => 'GET'], |
|
60 | + ['name' => 'LogSettings#download', 'url' => '/settings/admin/log/download', 'verb' => 'GET'], |
|
61 | + ['name' => 'CheckSetup#check', 'url' => '/settings/ajax/checksetup', 'verb' => 'GET'], |
|
62 | + ['name' => 'CheckSetup#getFailedIntegrityCheckFiles', 'url' => '/settings/integrity/failed', 'verb' => 'GET'], |
|
63 | + ['name' => 'CheckSetup#rescanFailedIntegrityCheck', 'url' => '/settings/integrity/rescan', 'verb' => 'GET'], |
|
64 | + ['name' => 'Certificate#addPersonalRootCertificate', 'url' => '/settings/personal/certificate', 'verb' => 'POST'], |
|
65 | + ['name' => 'Certificate#removePersonalRootCertificate', 'url' => '/settings/personal/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
66 | + ['name' => 'Certificate#addSystemRootCertificate', 'url' => '/settings/admin/certificate', 'verb' => 'POST'], |
|
67 | + ['name' => 'Certificate#removeSystemRootCertificate', 'url' => '/settings/admin/certificate/{certificateIdentifier}', 'verb' => 'DELETE'], |
|
68 | + ['name' => 'PersonalSettings#index', 'url' => '/settings/user/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'personal-info']], |
|
69 | + ['name' => 'AdminSettings#index', 'url' => '/settings/admin/{section}', 'verb' => 'GET', 'defaults' => ['section' => 'server']], |
|
70 | + ['name' => 'AdminSettings#form', 'url' => '/settings/admin/{section}', 'verb' => 'GET'], |
|
71 | + ['name' => 'ChangePassword#changePersonalPassword', 'url' => '/settings/personal/changepassword', 'verb' => 'POST'], |
|
72 | + ['name' => 'ChangePassword#changeUserPassword', 'url' => '/settings/users/changepassword', 'verb' => 'POST'], |
|
73 | + ['name' => 'Personal#setLanguage', 'url' => '/settings/ajax/setlanguage.php', 'verb' => 'POST'], |
|
74 | + ['name' => 'Groups#index', 'url' => '/settings/users/groups', 'verb' => 'GET'], |
|
75 | + ['name' => 'Groups#show', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'GET'], |
|
76 | + ['name' => 'Groups#create', 'url' => '/settings/users/groups', 'verb' => 'POST'], |
|
77 | + ['name' => 'Groups#update', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'PUT'], |
|
78 | + ['name' => 'Groups#destroy', 'url' => '/settings/users/groups/{id}', 'requirements' => ['id' => '[^?]*'], 'verb' => 'DELETE'], |
|
79 | + ] |
|
80 | 80 | ]); |
81 | 81 | |
82 | 82 | /** @var $this \OCP\Route\IRouter */ |
83 | 83 | |
84 | 84 | // Settings pages |
85 | 85 | $this->create('settings_help', '/settings/help') |
86 | - ->actionInclude('settings/help.php'); |
|
86 | + ->actionInclude('settings/help.php'); |
|
87 | 87 | $this->create('settings_users', '/settings/users') |
88 | - ->actionInclude('settings/users.php'); |
|
88 | + ->actionInclude('settings/users.php'); |
|
89 | 89 | // Settings ajax actions |
90 | 90 | // users |
91 | 91 | $this->create('settings_ajax_setquota', '/settings/ajax/setquota.php') |
92 | - ->actionInclude('settings/ajax/setquota.php'); |
|
92 | + ->actionInclude('settings/ajax/setquota.php'); |
|
93 | 93 | $this->create('settings_ajax_togglegroups', '/settings/ajax/togglegroups.php') |
94 | - ->actionInclude('settings/ajax/togglegroups.php'); |
|
94 | + ->actionInclude('settings/ajax/togglegroups.php'); |
|
95 | 95 | $this->create('settings_ajax_togglesubadmins', '/settings/ajax/togglesubadmins.php') |
96 | - ->actionInclude('settings/ajax/togglesubadmins.php'); |
|
96 | + ->actionInclude('settings/ajax/togglesubadmins.php'); |
|
97 | 97 | $this->create('settings_ajax_changegorupname', '/settings/ajax/changegroupname.php') |
98 | - ->actionInclude('settings/ajax/changegroupname.php'); |
|
98 | + ->actionInclude('settings/ajax/changegroupname.php'); |
|
99 | 99 | // apps |
100 | 100 | $this->create('settings_ajax_enableapp', '/settings/ajax/enableapp.php') |
101 | - ->actionInclude('settings/ajax/enableapp.php'); |
|
101 | + ->actionInclude('settings/ajax/enableapp.php'); |
|
102 | 102 | $this->create('settings_ajax_disableapp', '/settings/ajax/disableapp.php') |
103 | - ->actionInclude('settings/ajax/disableapp.php'); |
|
103 | + ->actionInclude('settings/ajax/disableapp.php'); |
|
104 | 104 | $this->create('settings_ajax_updateapp', '/settings/ajax/updateapp.php') |
105 | - ->actionInclude('settings/ajax/updateapp.php'); |
|
105 | + ->actionInclude('settings/ajax/updateapp.php'); |
|
106 | 106 | $this->create('settings_ajax_uninstallapp', '/settings/ajax/uninstallapp.php') |
107 | - ->actionInclude('settings/ajax/uninstallapp.php'); |
|
107 | + ->actionInclude('settings/ajax/uninstallapp.php'); |
|
108 | 108 | $this->create('settings_ajax_navigationdetect', '/settings/ajax/navigationdetect.php') |
109 | - ->actionInclude('settings/ajax/navigationdetect.php'); |
|
109 | + ->actionInclude('settings/ajax/navigationdetect.php'); |
|
110 | 110 | // admin |
111 | 111 | $this->create('settings_ajax_excludegroups', '/settings/ajax/excludegroups.php') |
112 | - ->actionInclude('settings/ajax/excludegroups.php'); |
|
112 | + ->actionInclude('settings/ajax/excludegroups.php'); |
@@ -29,31 +29,31 @@ |
||
29 | 29 | |
30 | 30 | class AppPasswords implements ISettings { |
31 | 31 | |
32 | - /** |
|
33 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
34 | - * @since 9.1 |
|
35 | - */ |
|
36 | - public function getForm() { |
|
37 | - return new TemplateResponse('settings', 'settings/personal/app-passwords'); |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
34 | + * @since 9.1 |
|
35 | + */ |
|
36 | + public function getForm() { |
|
37 | + return new TemplateResponse('settings', 'settings/personal/app-passwords'); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string the section ID, e.g. 'sharing' |
|
42 | - * @since 9.1 |
|
43 | - */ |
|
44 | - public function getSection() { |
|
45 | - return 'app-passwords'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return string the section ID, e.g. 'sharing' |
|
42 | + * @since 9.1 |
|
43 | + */ |
|
44 | + public function getSection() { |
|
45 | + return 'app-passwords'; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return int whether the form should be rather on the top or bottom of |
|
50 | - * the admin section. The forms are arranged in ascending order of the |
|
51 | - * priority values. It is required to return a value between 0 and 100. |
|
52 | - * |
|
53 | - * E.g.: 70 |
|
54 | - * @since 9.1 |
|
55 | - */ |
|
56 | - public function getPriority() { |
|
57 | - return 5; |
|
58 | - } |
|
48 | + /** |
|
49 | + * @return int whether the form should be rather on the top or bottom of |
|
50 | + * the admin section. The forms are arranged in ascending order of the |
|
51 | + * priority values. It is required to return a value between 0 and 100. |
|
52 | + * |
|
53 | + * E.g.: 70 |
|
54 | + * @since 9.1 |
|
55 | + */ |
|
56 | + public function getPriority() { |
|
57 | + return 5; |
|
58 | + } |
|
59 | 59 | } |
@@ -29,31 +29,31 @@ |
||
29 | 29 | |
30 | 30 | class Sessions implements ISettings { |
31 | 31 | |
32 | - /** |
|
33 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
34 | - * @since 9.1 |
|
35 | - */ |
|
36 | - public function getForm() { |
|
37 | - return new TemplateResponse('settings', 'settings/personal/sessions'); |
|
38 | - } |
|
32 | + /** |
|
33 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
34 | + * @since 9.1 |
|
35 | + */ |
|
36 | + public function getForm() { |
|
37 | + return new TemplateResponse('settings', 'settings/personal/sessions'); |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return string the section ID, e.g. 'sharing' |
|
42 | - * @since 9.1 |
|
43 | - */ |
|
44 | - public function getSection() { |
|
45 | - return 'sessions'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * @return string the section ID, e.g. 'sharing' |
|
42 | + * @since 9.1 |
|
43 | + */ |
|
44 | + public function getSection() { |
|
45 | + return 'sessions'; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @return int whether the form should be rather on the top or bottom of |
|
50 | - * the admin section. The forms are arranged in ascending order of the |
|
51 | - * priority values. It is required to return a value between 0 and 100. |
|
52 | - * |
|
53 | - * E.g.: 70 |
|
54 | - * @since 9.1 |
|
55 | - */ |
|
56 | - public function getPriority() { |
|
57 | - return 10; |
|
58 | - } |
|
48 | + /** |
|
49 | + * @return int whether the form should be rather on the top or bottom of |
|
50 | + * the admin section. The forms are arranged in ascending order of the |
|
51 | + * priority values. It is required to return a value between 0 and 100. |
|
52 | + * |
|
53 | + * E.g.: 70 |
|
54 | + * @since 9.1 |
|
55 | + */ |
|
56 | + public function getPriority() { |
|
57 | + return 10; |
|
58 | + } |
|
59 | 59 | } |
@@ -30,56 +30,56 @@ |
||
30 | 30 | |
31 | 31 | class SyncClients implements ISettings { |
32 | 32 | |
33 | - /** @var IConfig */ |
|
34 | - private $config; |
|
35 | - /** @var \OC_Defaults */ |
|
36 | - private $defaults; |
|
33 | + /** @var IConfig */ |
|
34 | + private $config; |
|
35 | + /** @var \OC_Defaults */ |
|
36 | + private $defaults; |
|
37 | 37 | |
38 | - public function __construct(IConfig $config, \OC_Defaults $defaults) { |
|
39 | - $this->config = $config; |
|
40 | - $this->defaults = $defaults; |
|
41 | - } |
|
38 | + public function __construct(IConfig $config, \OC_Defaults $defaults) { |
|
39 | + $this->config = $config; |
|
40 | + $this->defaults = $defaults; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
45 | - * @since 9.1 |
|
46 | - */ |
|
47 | - public function getForm() { |
|
48 | - $parameters = [ 'clients' => $this->getClientLinks() ]; |
|
49 | - return new TemplateResponse('settings', 'settings/personal/sync-clients', $parameters); |
|
50 | - } |
|
43 | + /** |
|
44 | + * @return TemplateResponse returns the instance with all parameters set, ready to be rendered |
|
45 | + * @since 9.1 |
|
46 | + */ |
|
47 | + public function getForm() { |
|
48 | + $parameters = [ 'clients' => $this->getClientLinks() ]; |
|
49 | + return new TemplateResponse('settings', 'settings/personal/sync-clients', $parameters); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * @return string the section ID, e.g. 'sharing' |
|
54 | - * @since 9.1 |
|
55 | - */ |
|
56 | - public function getSection() { |
|
57 | - return 'sync-clients'; |
|
58 | - } |
|
52 | + /** |
|
53 | + * @return string the section ID, e.g. 'sharing' |
|
54 | + * @since 9.1 |
|
55 | + */ |
|
56 | + public function getSection() { |
|
57 | + return 'sync-clients'; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * @return int whether the form should be rather on the top or bottom of |
|
62 | - * the admin section. The forms are arranged in ascending order of the |
|
63 | - * priority values. It is required to return a value between 0 and 100. |
|
64 | - * |
|
65 | - * E.g.: 70 |
|
66 | - * @since 9.1 |
|
67 | - */ |
|
68 | - public function getPriority() { |
|
69 | - return 20; |
|
70 | - } |
|
60 | + /** |
|
61 | + * @return int whether the form should be rather on the top or bottom of |
|
62 | + * the admin section. The forms are arranged in ascending order of the |
|
63 | + * priority values. It is required to return a value between 0 and 100. |
|
64 | + * |
|
65 | + * E.g.: 70 |
|
66 | + * @since 9.1 |
|
67 | + */ |
|
68 | + public function getPriority() { |
|
69 | + return 20; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * returns an array containing links to the various clients |
|
74 | - * |
|
75 | - * @return array |
|
76 | - */ |
|
77 | - private function getClientLinks() { |
|
78 | - $clients = [ |
|
79 | - 'desktop' => $this->config->getSystemValue('customclient_desktop', $this->defaults->getSyncClientUrl()), |
|
80 | - 'android' => $this->config->getSystemValue('customclient_android', $this->defaults->getAndroidClientUrl()), |
|
81 | - 'ios' => $this->config->getSystemValue('customclient_ios', $this->defaults->getiOSClientUrl()) |
|
82 | - ]; |
|
83 | - return $clients; |
|
84 | - } |
|
72 | + /** |
|
73 | + * returns an array containing links to the various clients |
|
74 | + * |
|
75 | + * @return array |
|
76 | + */ |
|
77 | + private function getClientLinks() { |
|
78 | + $clients = [ |
|
79 | + 'desktop' => $this->config->getSystemValue('customclient_desktop', $this->defaults->getSyncClientUrl()), |
|
80 | + 'android' => $this->config->getSystemValue('customclient_android', $this->defaults->getAndroidClientUrl()), |
|
81 | + 'ios' => $this->config->getSystemValue('customclient_ios', $this->defaults->getiOSClientUrl()) |
|
82 | + ]; |
|
83 | + return $clients; |
|
84 | + } |
|
85 | 85 | } |
@@ -45,7 +45,7 @@ |
||
45 | 45 | * @since 9.1 |
46 | 46 | */ |
47 | 47 | public function getForm() { |
48 | - $parameters = [ 'clients' => $this->getClientLinks() ]; |
|
48 | + $parameters = ['clients' => $this->getClientLinks()]; |
|
49 | 49 | return new TemplateResponse('settings', 'settings/personal/sync-clients', $parameters); |
50 | 50 | } |
51 | 51 |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | */ |
184 | 184 | private function setupSectionEntry($sectionClassName, $type) { |
185 | 185 | if (!class_exists($sectionClassName)) { |
186 | - $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
186 | + $this->log->debug('Could not find '.ucfirst($type).' section class '.$sectionClassName); |
|
187 | 187 | return; |
188 | 188 | } |
189 | 189 | try { |
@@ -195,13 +195,13 @@ discard block |
||
195 | 195 | |
196 | 196 | if (!$section instanceof ISection) { |
197 | 197 | $this->log->error( |
198 | - ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
198 | + ucfirst($type).' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
199 | 199 | ['class' => $sectionClassName] |
200 | 200 | ); |
201 | 201 | return; |
202 | 202 | } |
203 | 203 | $table = $this->getSectionTableForType($type); |
204 | - if(!$this->hasSection(get_class($section), $table)) { |
|
204 | + if (!$this->hasSection(get_class($section), $table)) { |
|
205 | 205 | $this->addSection($section, $table); |
206 | 206 | } else { |
207 | 207 | $this->updateSection($section, $table); |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | |
268 | 268 | private function setupSettingsEntry($settingsClassName, $type) { |
269 | 269 | if (!class_exists($settingsClassName)) { |
270 | - $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
270 | + $this->log->debug('Could not find '.$type.' section class '.$settingsClassName); |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | |
@@ -281,7 +281,7 @@ discard block |
||
281 | 281 | |
282 | 282 | if (!$settings instanceof ISettings) { |
283 | 283 | $this->log->error( |
284 | - ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
284 | + ucfirst($type).' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
285 | 285 | ['class' => $settingsClassName] |
286 | 286 | ); |
287 | 287 | return; |
@@ -295,18 +295,18 @@ discard block |
||
295 | 295 | } |
296 | 296 | |
297 | 297 | private function getSectionTableForType($type) { |
298 | - if($type === 'admin') { |
|
298 | + if ($type === 'admin') { |
|
299 | 299 | return Mapper::TABLE_ADMIN_SECTIONS; |
300 | - } else if($type === 'personal') { |
|
300 | + } else if ($type === 'personal') { |
|
301 | 301 | return Mapper::TABLE_PERSONAL_SECTIONS; |
302 | 302 | } |
303 | 303 | throw new \InvalidArgumentException('"admin" or "personal" expected'); |
304 | 304 | } |
305 | 305 | |
306 | 306 | private function getSettingsTableForType($type) { |
307 | - if($type === 'admin') { |
|
307 | + if ($type === 'admin') { |
|
308 | 308 | return Mapper::TABLE_ADMIN_SETTINGS; |
309 | - } else if($type === 'personal') { |
|
309 | + } else if ($type === 'personal') { |
|
310 | 310 | return Mapper::TABLE_PERSONAL_SETTINGS; |
311 | 311 | } |
312 | 312 | throw new \InvalidArgumentException('"admin" or "personal" expected'); |
@@ -405,17 +405,17 @@ discard block |
||
405 | 405 | $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->l); |
406 | 406 | $forms[$form->getPriority()] = [$form]; |
407 | 407 | } |
408 | - if($section === 'sessions') { |
|
408 | + if ($section === 'sessions') { |
|
409 | 409 | /** @var ISettings $form */ |
410 | 410 | $form = new Personal\Sessions(); |
411 | 411 | $forms[$form->getPriority()] = [$form]; |
412 | 412 | } |
413 | - if($section === 'app-passwords') { |
|
413 | + if ($section === 'app-passwords') { |
|
414 | 414 | /** @var ISettings $form */ |
415 | 415 | $form = new Personal\AppPasswords(); |
416 | 416 | $forms[$form->getPriority()] = [$form]; |
417 | 417 | } |
418 | - if($section === 'sync-clients') { |
|
418 | + if ($section === 'sync-clients') { |
|
419 | 419 | /** @var ISettings $form */ |
420 | 420 | $form = new Personal\SyncClients($this->config, $this->defaults); |
421 | 421 | $forms[$form->getPriority()] = [$form]; |
@@ -265,6 +265,9 @@ discard block |
||
265 | 265 | return $this->mapper->has($table, $className); |
266 | 266 | } |
267 | 267 | |
268 | + /** |
|
269 | + * @param string $type |
|
270 | + */ |
|
268 | 271 | private function setupSettingsEntry($settingsClassName, $type) { |
269 | 272 | if (!class_exists($settingsClassName)) { |
270 | 273 | $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
@@ -294,6 +297,9 @@ discard block |
||
294 | 297 | } |
295 | 298 | } |
296 | 299 | |
300 | + /** |
|
301 | + * @param string $type |
|
302 | + */ |
|
297 | 303 | private function getSectionTableForType($type) { |
298 | 304 | if($type === 'admin') { |
299 | 305 | return Mapper::TABLE_ADMIN_SECTIONS; |
@@ -41,437 +41,437 @@ |
||
41 | 41 | use OCP\Settings\ISection; |
42 | 42 | |
43 | 43 | class Manager implements IManager { |
44 | - /** @var ILogger */ |
|
45 | - private $log; |
|
46 | - /** @var IDBConnection */ |
|
47 | - private $dbc; |
|
48 | - /** @var Mapper */ |
|
49 | - private $mapper; |
|
50 | - /** @var IL10N */ |
|
51 | - private $l; |
|
52 | - /** @var IConfig */ |
|
53 | - private $config; |
|
54 | - /** @var EncryptionManager */ |
|
55 | - private $encryptionManager; |
|
56 | - /** @var IUserManager */ |
|
57 | - private $userManager; |
|
58 | - /** @var ILockingProvider */ |
|
59 | - private $lockingProvider; |
|
60 | - /** @var IRequest */ |
|
61 | - private $request; |
|
62 | - /** @var IURLGenerator */ |
|
63 | - private $url; |
|
64 | - /** @var AccountManager */ |
|
65 | - private $accountManager; |
|
66 | - /** @var IGroupManager */ |
|
67 | - private $groupManager; |
|
68 | - /** @var IFactory */ |
|
69 | - private $l10nFactory; |
|
70 | - /** @var \OC_Defaults */ |
|
71 | - private $defaults; |
|
72 | - |
|
73 | - /** |
|
74 | - * @param ILogger $log |
|
75 | - * @param IDBConnection $dbc |
|
76 | - * @param IL10N $l |
|
77 | - * @param IConfig $config |
|
78 | - * @param EncryptionManager $encryptionManager |
|
79 | - * @param IUserManager $userManager |
|
80 | - * @param ILockingProvider $lockingProvider |
|
81 | - * @param IRequest $request |
|
82 | - * @param Mapper $mapper |
|
83 | - * @param IURLGenerator $url |
|
84 | - * @param AccountManager $accountManager |
|
85 | - * @param IGroupManager $groupManager |
|
86 | - * @param IFactory $l10nFactory |
|
87 | - * @param \OC_Defaults $defaults |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - ILogger $log, |
|
91 | - IDBConnection $dbc, |
|
92 | - IL10N $l, |
|
93 | - IConfig $config, |
|
94 | - EncryptionManager $encryptionManager, |
|
95 | - IUserManager $userManager, |
|
96 | - ILockingProvider $lockingProvider, |
|
97 | - IRequest $request, |
|
98 | - Mapper $mapper, |
|
99 | - IURLGenerator $url, |
|
100 | - AccountManager $accountManager, |
|
101 | - IGroupManager $groupManager, |
|
102 | - IFactory $l10nFactory, |
|
103 | - \OC_Defaults $defaults |
|
104 | - ) { |
|
105 | - $this->log = $log; |
|
106 | - $this->dbc = $dbc; |
|
107 | - $this->mapper = $mapper; |
|
108 | - $this->l = $l; |
|
109 | - $this->config = $config; |
|
110 | - $this->encryptionManager = $encryptionManager; |
|
111 | - $this->userManager = $userManager; |
|
112 | - $this->lockingProvider = $lockingProvider; |
|
113 | - $this->request = $request; |
|
114 | - $this->url = $url; |
|
115 | - $this->accountManager = $accountManager; |
|
116 | - $this->groupManager = $groupManager; |
|
117 | - $this->l10nFactory = $l10nFactory; |
|
118 | - $this->defaults = $defaults; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @inheritdoc |
|
123 | - */ |
|
124 | - public function setupSettings(array $settings) { |
|
125 | - if (isset($settings[IManager::KEY_ADMIN_SECTION])) { |
|
126 | - $this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin'); |
|
127 | - } |
|
128 | - if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
129 | - $this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin'); |
|
130 | - } |
|
131 | - |
|
132 | - if (isset($settings[IManager::KEY_PERSONAL_SECTION])) { |
|
133 | - $this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal'); |
|
134 | - } |
|
135 | - if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) { |
|
136 | - $this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal'); |
|
137 | - } |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * attempts to remove an apps section and/or settings entry. A listener is |
|
142 | - * added centrally making sure that this method is called ones an app was |
|
143 | - * disabled. |
|
144 | - * |
|
145 | - * @param string $appId |
|
146 | - * @since 9.1.0 |
|
147 | - */ |
|
148 | - public function onAppDisabled($appId) { |
|
149 | - $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
150 | - |
|
151 | - if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
152 | - $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\')); |
|
153 | - } |
|
154 | - if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
155 | - $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\')); |
|
156 | - } |
|
157 | - |
|
158 | - if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) { |
|
159 | - $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\')); |
|
160 | - } |
|
161 | - if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) { |
|
162 | - $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\')); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - public function checkForOrphanedClassNames() { |
|
167 | - $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS]; |
|
168 | - foreach ($tables as $table) { |
|
169 | - $classes = $this->mapper->getClasses($table); |
|
170 | - foreach ($classes as $className) { |
|
171 | - try { |
|
172 | - \OC::$server->query($className); |
|
173 | - } catch (QueryException $e) { |
|
174 | - $this->mapper->remove($table, $className); |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * @param string $sectionClassName |
|
182 | - * @param string $type either 'admin' or 'personal' |
|
183 | - */ |
|
184 | - private function setupSectionEntry($sectionClassName, $type) { |
|
185 | - if (!class_exists($sectionClassName)) { |
|
186 | - $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
187 | - return; |
|
188 | - } |
|
189 | - try { |
|
190 | - $section = $this->query($sectionClassName); |
|
191 | - } catch (QueryException $e) { |
|
192 | - // cancel |
|
193 | - return; |
|
194 | - } |
|
195 | - |
|
196 | - if (!$section instanceof ISection) { |
|
197 | - $this->log->error( |
|
198 | - ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
199 | - ['class' => $sectionClassName] |
|
200 | - ); |
|
201 | - return; |
|
202 | - } |
|
203 | - $table = $this->getSectionTableForType($type); |
|
204 | - if(!$this->hasSection(get_class($section), $table)) { |
|
205 | - $this->addSection($section, $table); |
|
206 | - } else { |
|
207 | - $this->updateSection($section, $table); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - private function addSection(ISection $section, $table) { |
|
212 | - $this->mapper->add($table, [ |
|
213 | - 'id' => $section->getID(), |
|
214 | - 'class' => get_class($section), |
|
215 | - 'priority' => $section->getPriority(), |
|
216 | - ]); |
|
217 | - } |
|
218 | - |
|
219 | - private function addSettings(ISettings $settings, $table) { |
|
220 | - $this->mapper->add($table, [ |
|
221 | - 'class' => get_class($settings), |
|
222 | - 'section' => $settings->getSection(), |
|
223 | - 'priority' => $settings->getPriority(), |
|
224 | - ]); |
|
225 | - } |
|
226 | - |
|
227 | - private function updateSettings(ISettings $settings, $table) { |
|
228 | - $this->mapper->update( |
|
229 | - $table, |
|
230 | - 'class', |
|
231 | - get_class($settings), |
|
232 | - [ |
|
233 | - 'section' => $settings->getSection(), |
|
234 | - 'priority' => $settings->getPriority(), |
|
235 | - ] |
|
236 | - ); |
|
237 | - } |
|
238 | - |
|
239 | - private function updateSection(ISection $section, $table) { |
|
240 | - $this->mapper->update( |
|
241 | - $table, |
|
242 | - 'class', |
|
243 | - get_class($section), |
|
244 | - [ |
|
245 | - 'id' => $section->getID(), |
|
246 | - 'priority' => $section->getPriority(), |
|
247 | - ] |
|
248 | - ); |
|
249 | - } |
|
250 | - |
|
251 | - /** |
|
252 | - * @param string $className |
|
253 | - * @param string $table |
|
254 | - * @return bool |
|
255 | - */ |
|
256 | - private function hasSection($className, $table) { |
|
257 | - return $this->mapper->has($table, $className); |
|
258 | - } |
|
259 | - |
|
260 | - /** |
|
261 | - * @param string $className |
|
262 | - * @return bool |
|
263 | - */ |
|
264 | - private function hasSettings($className, $table) { |
|
265 | - return $this->mapper->has($table, $className); |
|
266 | - } |
|
267 | - |
|
268 | - private function setupSettingsEntry($settingsClassName, $type) { |
|
269 | - if (!class_exists($settingsClassName)) { |
|
270 | - $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
271 | - return; |
|
272 | - } |
|
273 | - |
|
274 | - try { |
|
275 | - /** @var ISettings $settings */ |
|
276 | - $settings = $this->query($settingsClassName); |
|
277 | - } catch (QueryException $e) { |
|
278 | - // cancel |
|
279 | - return; |
|
280 | - } |
|
281 | - |
|
282 | - if (!$settings instanceof ISettings) { |
|
283 | - $this->log->error( |
|
284 | - ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
285 | - ['class' => $settingsClassName] |
|
286 | - ); |
|
287 | - return; |
|
288 | - } |
|
289 | - $table = $this->getSettingsTableForType($type); |
|
290 | - if (!$this->hasSettings(get_class($settings), $table)) { |
|
291 | - $this->addSettings($settings, $table); |
|
292 | - } else { |
|
293 | - $this->updateSettings($settings, $table); |
|
294 | - } |
|
295 | - } |
|
296 | - |
|
297 | - private function getSectionTableForType($type) { |
|
298 | - if($type === 'admin') { |
|
299 | - return Mapper::TABLE_ADMIN_SECTIONS; |
|
300 | - } else if($type === 'personal') { |
|
301 | - return Mapper::TABLE_PERSONAL_SECTIONS; |
|
302 | - } |
|
303 | - throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
304 | - } |
|
305 | - |
|
306 | - private function getSettingsTableForType($type) { |
|
307 | - if($type === 'admin') { |
|
308 | - return Mapper::TABLE_ADMIN_SETTINGS; |
|
309 | - } else if($type === 'personal') { |
|
310 | - return Mapper::TABLE_PERSONAL_SETTINGS; |
|
311 | - } |
|
312 | - throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
313 | - } |
|
314 | - |
|
315 | - private function query($className) { |
|
316 | - try { |
|
317 | - return \OC::$server->query($className); |
|
318 | - } catch (QueryException $e) { |
|
319 | - $this->log->logException($e); |
|
320 | - throw $e; |
|
321 | - } |
|
322 | - } |
|
323 | - |
|
324 | - /** |
|
325 | - * @inheritdoc |
|
326 | - */ |
|
327 | - public function getAdminSections() { |
|
328 | - // built-in sections |
|
329 | - $sections = [ |
|
330 | - 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
331 | - 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
332 | - 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
333 | - 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
334 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
335 | - 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
336 | - ]; |
|
337 | - |
|
338 | - $rows = $this->mapper->getAdminSectionsFromDB(); |
|
339 | - |
|
340 | - foreach ($rows as $row) { |
|
341 | - if (!isset($sections[$row['priority']])) { |
|
342 | - $sections[$row['priority']] = []; |
|
343 | - } |
|
344 | - try { |
|
345 | - $sections[$row['priority']][] = $this->query($row['class']); |
|
346 | - } catch (QueryException $e) { |
|
347 | - // skip |
|
348 | - } |
|
349 | - } |
|
350 | - |
|
351 | - ksort($sections); |
|
352 | - |
|
353 | - return $sections; |
|
354 | - } |
|
355 | - |
|
356 | - /** |
|
357 | - * @param string $section |
|
358 | - * @return ISection[] |
|
359 | - */ |
|
360 | - private function getBuiltInAdminSettings($section) { |
|
361 | - $forms = []; |
|
362 | - try { |
|
363 | - if ($section === 'server') { |
|
364 | - /** @var ISettings $form */ |
|
365 | - $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
366 | - $forms[$form->getPriority()] = [$form]; |
|
367 | - $form = new Admin\ServerDevNotice(); |
|
368 | - $forms[$form->getPriority()] = [$form]; |
|
369 | - } |
|
370 | - if ($section === 'encryption') { |
|
371 | - /** @var ISettings $form */ |
|
372 | - $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
373 | - $forms[$form->getPriority()] = [$form]; |
|
374 | - } |
|
375 | - if ($section === 'sharing') { |
|
376 | - /** @var ISettings $form */ |
|
377 | - $form = new Admin\Sharing($this->config); |
|
378 | - $forms[$form->getPriority()] = [$form]; |
|
379 | - } |
|
380 | - if ($section === 'additional') { |
|
381 | - /** @var ISettings $form */ |
|
382 | - $form = new Admin\Additional($this->config); |
|
383 | - $forms[$form->getPriority()] = [$form]; |
|
384 | - } |
|
385 | - if ($section === 'tips-tricks') { |
|
386 | - /** @var ISettings $form */ |
|
387 | - $form = new Admin\TipsTricks($this->config); |
|
388 | - $forms[$form->getPriority()] = [$form]; |
|
389 | - } |
|
390 | - } catch (QueryException $e) { |
|
391 | - // skip |
|
392 | - } |
|
393 | - return $forms; |
|
394 | - } |
|
395 | - |
|
396 | - /** |
|
397 | - * @param string $section |
|
398 | - * @return ISection[] |
|
399 | - */ |
|
400 | - private function getBuiltInPersonalSettings($section) { |
|
401 | - $forms = []; |
|
402 | - try { |
|
403 | - if ($section === 'personal-info') { |
|
404 | - /** @var ISettings $form */ |
|
405 | - $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->l); |
|
406 | - $forms[$form->getPriority()] = [$form]; |
|
407 | - } |
|
408 | - if($section === 'sessions') { |
|
409 | - /** @var ISettings $form */ |
|
410 | - $form = new Personal\Sessions(); |
|
411 | - $forms[$form->getPriority()] = [$form]; |
|
412 | - } |
|
413 | - if($section === 'app-passwords') { |
|
414 | - /** @var ISettings $form */ |
|
415 | - $form = new Personal\AppPasswords(); |
|
416 | - $forms[$form->getPriority()] = [$form]; |
|
417 | - } |
|
418 | - if($section === 'sync-clients') { |
|
419 | - /** @var ISettings $form */ |
|
420 | - $form = new Personal\SyncClients($this->config, $this->defaults); |
|
421 | - $forms[$form->getPriority()] = [$form]; |
|
422 | - } |
|
423 | - if ($section === 'additional') { |
|
424 | - /** @var ISettings $form */ |
|
425 | - $form = new Personal\Additional($this->config); |
|
426 | - $forms[$form->getPriority()] = [$form]; |
|
427 | - } |
|
428 | - } catch (QueryException $e) { |
|
429 | - // skip |
|
430 | - } |
|
431 | - return $forms; |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * @inheritdoc |
|
436 | - */ |
|
437 | - public function getAdminSettings($section) { |
|
438 | - $settings = $this->getBuiltInAdminSettings($section); |
|
439 | - $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
440 | - |
|
441 | - foreach ($dbRows as $row) { |
|
442 | - if (!isset($settings[$row['priority']])) { |
|
443 | - $settings[$row['priority']] = []; |
|
444 | - } |
|
445 | - try { |
|
446 | - $settings[$row['priority']][] = $this->query($row['class']); |
|
447 | - } catch (QueryException $e) { |
|
448 | - // skip |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - ksort($settings); |
|
453 | - return $settings; |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * @inheritdoc |
|
458 | - */ |
|
459 | - public function getPersonalSections() { |
|
460 | - $sections = [ |
|
461 | - 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
462 | - 5 => [new Section('sessions', $this->l->t('Sessions'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
463 | - 10 => [new Section('app-passwords', $this->l->t('App passwords'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
464 | - 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
465 | - 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
466 | - ]; |
|
467 | - return $sections; |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * @inheritdoc |
|
472 | - */ |
|
473 | - public function getPersonalSettings($section) { |
|
474 | - $settings = $this->getBuiltInPersonalSettings($section); |
|
475 | - return $settings; |
|
476 | - } |
|
44 | + /** @var ILogger */ |
|
45 | + private $log; |
|
46 | + /** @var IDBConnection */ |
|
47 | + private $dbc; |
|
48 | + /** @var Mapper */ |
|
49 | + private $mapper; |
|
50 | + /** @var IL10N */ |
|
51 | + private $l; |
|
52 | + /** @var IConfig */ |
|
53 | + private $config; |
|
54 | + /** @var EncryptionManager */ |
|
55 | + private $encryptionManager; |
|
56 | + /** @var IUserManager */ |
|
57 | + private $userManager; |
|
58 | + /** @var ILockingProvider */ |
|
59 | + private $lockingProvider; |
|
60 | + /** @var IRequest */ |
|
61 | + private $request; |
|
62 | + /** @var IURLGenerator */ |
|
63 | + private $url; |
|
64 | + /** @var AccountManager */ |
|
65 | + private $accountManager; |
|
66 | + /** @var IGroupManager */ |
|
67 | + private $groupManager; |
|
68 | + /** @var IFactory */ |
|
69 | + private $l10nFactory; |
|
70 | + /** @var \OC_Defaults */ |
|
71 | + private $defaults; |
|
72 | + |
|
73 | + /** |
|
74 | + * @param ILogger $log |
|
75 | + * @param IDBConnection $dbc |
|
76 | + * @param IL10N $l |
|
77 | + * @param IConfig $config |
|
78 | + * @param EncryptionManager $encryptionManager |
|
79 | + * @param IUserManager $userManager |
|
80 | + * @param ILockingProvider $lockingProvider |
|
81 | + * @param IRequest $request |
|
82 | + * @param Mapper $mapper |
|
83 | + * @param IURLGenerator $url |
|
84 | + * @param AccountManager $accountManager |
|
85 | + * @param IGroupManager $groupManager |
|
86 | + * @param IFactory $l10nFactory |
|
87 | + * @param \OC_Defaults $defaults |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + ILogger $log, |
|
91 | + IDBConnection $dbc, |
|
92 | + IL10N $l, |
|
93 | + IConfig $config, |
|
94 | + EncryptionManager $encryptionManager, |
|
95 | + IUserManager $userManager, |
|
96 | + ILockingProvider $lockingProvider, |
|
97 | + IRequest $request, |
|
98 | + Mapper $mapper, |
|
99 | + IURLGenerator $url, |
|
100 | + AccountManager $accountManager, |
|
101 | + IGroupManager $groupManager, |
|
102 | + IFactory $l10nFactory, |
|
103 | + \OC_Defaults $defaults |
|
104 | + ) { |
|
105 | + $this->log = $log; |
|
106 | + $this->dbc = $dbc; |
|
107 | + $this->mapper = $mapper; |
|
108 | + $this->l = $l; |
|
109 | + $this->config = $config; |
|
110 | + $this->encryptionManager = $encryptionManager; |
|
111 | + $this->userManager = $userManager; |
|
112 | + $this->lockingProvider = $lockingProvider; |
|
113 | + $this->request = $request; |
|
114 | + $this->url = $url; |
|
115 | + $this->accountManager = $accountManager; |
|
116 | + $this->groupManager = $groupManager; |
|
117 | + $this->l10nFactory = $l10nFactory; |
|
118 | + $this->defaults = $defaults; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @inheritdoc |
|
123 | + */ |
|
124 | + public function setupSettings(array $settings) { |
|
125 | + if (isset($settings[IManager::KEY_ADMIN_SECTION])) { |
|
126 | + $this->setupSectionEntry($settings[IManager::KEY_ADMIN_SECTION], 'admin'); |
|
127 | + } |
|
128 | + if (isset($settings[IManager::KEY_ADMIN_SETTINGS])) { |
|
129 | + $this->setupSettingsEntry($settings[IManager::KEY_ADMIN_SETTINGS], 'admin'); |
|
130 | + } |
|
131 | + |
|
132 | + if (isset($settings[IManager::KEY_PERSONAL_SECTION])) { |
|
133 | + $this->setupSectionEntry($settings[IManager::KEY_PERSONAL_SECTION], 'personal'); |
|
134 | + } |
|
135 | + if (isset($settings[IManager::KEY_PERSONAL_SETTINGS])) { |
|
136 | + $this->setupSettingsEntry($settings[IManager::KEY_PERSONAL_SETTINGS], 'personal'); |
|
137 | + } |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * attempts to remove an apps section and/or settings entry. A listener is |
|
142 | + * added centrally making sure that this method is called ones an app was |
|
143 | + * disabled. |
|
144 | + * |
|
145 | + * @param string $appId |
|
146 | + * @since 9.1.0 |
|
147 | + */ |
|
148 | + public function onAppDisabled($appId) { |
|
149 | + $appInfo = \OC_App::getAppInfo($appId); // hello static legacy |
|
150 | + |
|
151 | + if (isset($appInfo['settings'][IManager::KEY_ADMIN_SECTION])) { |
|
152 | + $this->mapper->remove(Mapper::TABLE_ADMIN_SECTIONS, trim($appInfo['settings'][IManager::KEY_ADMIN_SECTION], '\\')); |
|
153 | + } |
|
154 | + if (isset($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS])) { |
|
155 | + $this->mapper->remove(Mapper::TABLE_ADMIN_SETTINGS, trim($appInfo['settings'][IManager::KEY_ADMIN_SETTINGS], '\\')); |
|
156 | + } |
|
157 | + |
|
158 | + if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SECTION])) { |
|
159 | + $this->mapper->remove(Mapper::TABLE_PERSONAL_SECTIONS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SECTION], '\\')); |
|
160 | + } |
|
161 | + if (isset($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS])) { |
|
162 | + $this->mapper->remove(Mapper::TABLE_PERSONAL_SETTINGS, trim($appInfo['settings'][IManager::KEY_PERSONAL_SETTINGS], '\\')); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + public function checkForOrphanedClassNames() { |
|
167 | + $tables = [Mapper::TABLE_ADMIN_SECTIONS, Mapper::TABLE_ADMIN_SETTINGS, Mapper::TABLE_PERSONAL_SECTIONS, Mapper::TABLE_PERSONAL_SETTINGS]; |
|
168 | + foreach ($tables as $table) { |
|
169 | + $classes = $this->mapper->getClasses($table); |
|
170 | + foreach ($classes as $className) { |
|
171 | + try { |
|
172 | + \OC::$server->query($className); |
|
173 | + } catch (QueryException $e) { |
|
174 | + $this->mapper->remove($table, $className); |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * @param string $sectionClassName |
|
182 | + * @param string $type either 'admin' or 'personal' |
|
183 | + */ |
|
184 | + private function setupSectionEntry($sectionClassName, $type) { |
|
185 | + if (!class_exists($sectionClassName)) { |
|
186 | + $this->log->debug('Could not find ' . ucfirst($type) . ' section class ' . $sectionClassName); |
|
187 | + return; |
|
188 | + } |
|
189 | + try { |
|
190 | + $section = $this->query($sectionClassName); |
|
191 | + } catch (QueryException $e) { |
|
192 | + // cancel |
|
193 | + return; |
|
194 | + } |
|
195 | + |
|
196 | + if (!$section instanceof ISection) { |
|
197 | + $this->log->error( |
|
198 | + ucfirst($type) .' section instance must implement \OCP\ISection. Invalid class: {class}', |
|
199 | + ['class' => $sectionClassName] |
|
200 | + ); |
|
201 | + return; |
|
202 | + } |
|
203 | + $table = $this->getSectionTableForType($type); |
|
204 | + if(!$this->hasSection(get_class($section), $table)) { |
|
205 | + $this->addSection($section, $table); |
|
206 | + } else { |
|
207 | + $this->updateSection($section, $table); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + private function addSection(ISection $section, $table) { |
|
212 | + $this->mapper->add($table, [ |
|
213 | + 'id' => $section->getID(), |
|
214 | + 'class' => get_class($section), |
|
215 | + 'priority' => $section->getPriority(), |
|
216 | + ]); |
|
217 | + } |
|
218 | + |
|
219 | + private function addSettings(ISettings $settings, $table) { |
|
220 | + $this->mapper->add($table, [ |
|
221 | + 'class' => get_class($settings), |
|
222 | + 'section' => $settings->getSection(), |
|
223 | + 'priority' => $settings->getPriority(), |
|
224 | + ]); |
|
225 | + } |
|
226 | + |
|
227 | + private function updateSettings(ISettings $settings, $table) { |
|
228 | + $this->mapper->update( |
|
229 | + $table, |
|
230 | + 'class', |
|
231 | + get_class($settings), |
|
232 | + [ |
|
233 | + 'section' => $settings->getSection(), |
|
234 | + 'priority' => $settings->getPriority(), |
|
235 | + ] |
|
236 | + ); |
|
237 | + } |
|
238 | + |
|
239 | + private function updateSection(ISection $section, $table) { |
|
240 | + $this->mapper->update( |
|
241 | + $table, |
|
242 | + 'class', |
|
243 | + get_class($section), |
|
244 | + [ |
|
245 | + 'id' => $section->getID(), |
|
246 | + 'priority' => $section->getPriority(), |
|
247 | + ] |
|
248 | + ); |
|
249 | + } |
|
250 | + |
|
251 | + /** |
|
252 | + * @param string $className |
|
253 | + * @param string $table |
|
254 | + * @return bool |
|
255 | + */ |
|
256 | + private function hasSection($className, $table) { |
|
257 | + return $this->mapper->has($table, $className); |
|
258 | + } |
|
259 | + |
|
260 | + /** |
|
261 | + * @param string $className |
|
262 | + * @return bool |
|
263 | + */ |
|
264 | + private function hasSettings($className, $table) { |
|
265 | + return $this->mapper->has($table, $className); |
|
266 | + } |
|
267 | + |
|
268 | + private function setupSettingsEntry($settingsClassName, $type) { |
|
269 | + if (!class_exists($settingsClassName)) { |
|
270 | + $this->log->debug('Could not find ' . $type . ' section class ' . $settingsClassName); |
|
271 | + return; |
|
272 | + } |
|
273 | + |
|
274 | + try { |
|
275 | + /** @var ISettings $settings */ |
|
276 | + $settings = $this->query($settingsClassName); |
|
277 | + } catch (QueryException $e) { |
|
278 | + // cancel |
|
279 | + return; |
|
280 | + } |
|
281 | + |
|
282 | + if (!$settings instanceof ISettings) { |
|
283 | + $this->log->error( |
|
284 | + ucfirst($type) . ' section instance must implement \OCP\Settings\ISettings. Invalid class: {class}', |
|
285 | + ['class' => $settingsClassName] |
|
286 | + ); |
|
287 | + return; |
|
288 | + } |
|
289 | + $table = $this->getSettingsTableForType($type); |
|
290 | + if (!$this->hasSettings(get_class($settings), $table)) { |
|
291 | + $this->addSettings($settings, $table); |
|
292 | + } else { |
|
293 | + $this->updateSettings($settings, $table); |
|
294 | + } |
|
295 | + } |
|
296 | + |
|
297 | + private function getSectionTableForType($type) { |
|
298 | + if($type === 'admin') { |
|
299 | + return Mapper::TABLE_ADMIN_SECTIONS; |
|
300 | + } else if($type === 'personal') { |
|
301 | + return Mapper::TABLE_PERSONAL_SECTIONS; |
|
302 | + } |
|
303 | + throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
304 | + } |
|
305 | + |
|
306 | + private function getSettingsTableForType($type) { |
|
307 | + if($type === 'admin') { |
|
308 | + return Mapper::TABLE_ADMIN_SETTINGS; |
|
309 | + } else if($type === 'personal') { |
|
310 | + return Mapper::TABLE_PERSONAL_SETTINGS; |
|
311 | + } |
|
312 | + throw new \InvalidArgumentException('"admin" or "personal" expected'); |
|
313 | + } |
|
314 | + |
|
315 | + private function query($className) { |
|
316 | + try { |
|
317 | + return \OC::$server->query($className); |
|
318 | + } catch (QueryException $e) { |
|
319 | + $this->log->logException($e); |
|
320 | + throw $e; |
|
321 | + } |
|
322 | + } |
|
323 | + |
|
324 | + /** |
|
325 | + * @inheritdoc |
|
326 | + */ |
|
327 | + public function getAdminSections() { |
|
328 | + // built-in sections |
|
329 | + $sections = [ |
|
330 | + 0 => [new Section('server', $this->l->t('Basic settings'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
331 | + 5 => [new Section('sharing', $this->l->t('Sharing'), 0, $this->url->imagePath('core', 'actions/share.svg'))], |
|
332 | + 10 => [new Section('security', $this->l->t('Security'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
333 | + 45 => [new Section('encryption', $this->l->t('Encryption'), 0, $this->url->imagePath('core', 'actions/password.svg'))], |
|
334 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
335 | + 99 => [new Section('tips-tricks', $this->l->t('Tips & tricks'), 0, $this->url->imagePath('settings', 'help.svg'))], |
|
336 | + ]; |
|
337 | + |
|
338 | + $rows = $this->mapper->getAdminSectionsFromDB(); |
|
339 | + |
|
340 | + foreach ($rows as $row) { |
|
341 | + if (!isset($sections[$row['priority']])) { |
|
342 | + $sections[$row['priority']] = []; |
|
343 | + } |
|
344 | + try { |
|
345 | + $sections[$row['priority']][] = $this->query($row['class']); |
|
346 | + } catch (QueryException $e) { |
|
347 | + // skip |
|
348 | + } |
|
349 | + } |
|
350 | + |
|
351 | + ksort($sections); |
|
352 | + |
|
353 | + return $sections; |
|
354 | + } |
|
355 | + |
|
356 | + /** |
|
357 | + * @param string $section |
|
358 | + * @return ISection[] |
|
359 | + */ |
|
360 | + private function getBuiltInAdminSettings($section) { |
|
361 | + $forms = []; |
|
362 | + try { |
|
363 | + if ($section === 'server') { |
|
364 | + /** @var ISettings $form */ |
|
365 | + $form = new Admin\Server($this->dbc, $this->request, $this->config, $this->lockingProvider, $this->l); |
|
366 | + $forms[$form->getPriority()] = [$form]; |
|
367 | + $form = new Admin\ServerDevNotice(); |
|
368 | + $forms[$form->getPriority()] = [$form]; |
|
369 | + } |
|
370 | + if ($section === 'encryption') { |
|
371 | + /** @var ISettings $form */ |
|
372 | + $form = new Admin\Encryption($this->encryptionManager, $this->userManager); |
|
373 | + $forms[$form->getPriority()] = [$form]; |
|
374 | + } |
|
375 | + if ($section === 'sharing') { |
|
376 | + /** @var ISettings $form */ |
|
377 | + $form = new Admin\Sharing($this->config); |
|
378 | + $forms[$form->getPriority()] = [$form]; |
|
379 | + } |
|
380 | + if ($section === 'additional') { |
|
381 | + /** @var ISettings $form */ |
|
382 | + $form = new Admin\Additional($this->config); |
|
383 | + $forms[$form->getPriority()] = [$form]; |
|
384 | + } |
|
385 | + if ($section === 'tips-tricks') { |
|
386 | + /** @var ISettings $form */ |
|
387 | + $form = new Admin\TipsTricks($this->config); |
|
388 | + $forms[$form->getPriority()] = [$form]; |
|
389 | + } |
|
390 | + } catch (QueryException $e) { |
|
391 | + // skip |
|
392 | + } |
|
393 | + return $forms; |
|
394 | + } |
|
395 | + |
|
396 | + /** |
|
397 | + * @param string $section |
|
398 | + * @return ISection[] |
|
399 | + */ |
|
400 | + private function getBuiltInPersonalSettings($section) { |
|
401 | + $forms = []; |
|
402 | + try { |
|
403 | + if ($section === 'personal-info') { |
|
404 | + /** @var ISettings $form */ |
|
405 | + $form = new Personal\PersonalInfo($this->config, $this->userManager, $this->groupManager, $this->accountManager, $this->l10nFactory, $this->l); |
|
406 | + $forms[$form->getPriority()] = [$form]; |
|
407 | + } |
|
408 | + if($section === 'sessions') { |
|
409 | + /** @var ISettings $form */ |
|
410 | + $form = new Personal\Sessions(); |
|
411 | + $forms[$form->getPriority()] = [$form]; |
|
412 | + } |
|
413 | + if($section === 'app-passwords') { |
|
414 | + /** @var ISettings $form */ |
|
415 | + $form = new Personal\AppPasswords(); |
|
416 | + $forms[$form->getPriority()] = [$form]; |
|
417 | + } |
|
418 | + if($section === 'sync-clients') { |
|
419 | + /** @var ISettings $form */ |
|
420 | + $form = new Personal\SyncClients($this->config, $this->defaults); |
|
421 | + $forms[$form->getPriority()] = [$form]; |
|
422 | + } |
|
423 | + if ($section === 'additional') { |
|
424 | + /** @var ISettings $form */ |
|
425 | + $form = new Personal\Additional($this->config); |
|
426 | + $forms[$form->getPriority()] = [$form]; |
|
427 | + } |
|
428 | + } catch (QueryException $e) { |
|
429 | + // skip |
|
430 | + } |
|
431 | + return $forms; |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * @inheritdoc |
|
436 | + */ |
|
437 | + public function getAdminSettings($section) { |
|
438 | + $settings = $this->getBuiltInAdminSettings($section); |
|
439 | + $dbRows = $this->mapper->getAdminSettingsFromDB($section); |
|
440 | + |
|
441 | + foreach ($dbRows as $row) { |
|
442 | + if (!isset($settings[$row['priority']])) { |
|
443 | + $settings[$row['priority']] = []; |
|
444 | + } |
|
445 | + try { |
|
446 | + $settings[$row['priority']][] = $this->query($row['class']); |
|
447 | + } catch (QueryException $e) { |
|
448 | + // skip |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + ksort($settings); |
|
453 | + return $settings; |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * @inheritdoc |
|
458 | + */ |
|
459 | + public function getPersonalSections() { |
|
460 | + $sections = [ |
|
461 | + 0 => [new Section('personal-info', $this->l->t('Personal info'), 0, $this->url->imagePath('core', 'actions/info.svg'))], |
|
462 | + 5 => [new Section('sessions', $this->l->t('Sessions'), 0, $this->url->imagePath('settings', 'admin.svg'))], |
|
463 | + 10 => [new Section('app-passwords', $this->l->t('App passwords'), 0, $this->url->imagePath('settings', 'password.svg'))], |
|
464 | + 15 => [new Section('sync-clients', $this->l->t('Sync clients'), 0, $this->url->imagePath('settings', 'change.svg'))], |
|
465 | + 98 => [new Section('additional', $this->l->t('Additional settings'), 0, $this->url->imagePath('core', 'actions/settings-dark.svg'))], |
|
466 | + ]; |
|
467 | + return $sections; |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * @inheritdoc |
|
472 | + */ |
|
473 | + public function getPersonalSettings($section) { |
|
474 | + $settings = $this->getBuiltInPersonalSettings($section); |
|
475 | + return $settings; |
|
476 | + } |
|
477 | 477 | } |