@@ -32,72 +32,72 @@ |
||
32 | 32 | use OCP\Template; |
33 | 33 | |
34 | 34 | class PersonalSettingsController extends Controller { |
35 | - use CommonSettingsTrait; |
|
35 | + use CommonSettingsTrait; |
|
36 | 36 | |
37 | - public function __construct( |
|
38 | - $appName, |
|
39 | - IRequest $request, |
|
40 | - INavigationManager $navigationManager, |
|
41 | - ISettingsManager $settingsManager |
|
42 | - ) { |
|
43 | - parent::__construct($appName, $request); |
|
44 | - $this->navigationManager = $navigationManager; |
|
45 | - $this->settingsManager = $settingsManager; |
|
46 | - } |
|
37 | + public function __construct( |
|
38 | + $appName, |
|
39 | + IRequest $request, |
|
40 | + INavigationManager $navigationManager, |
|
41 | + ISettingsManager $settingsManager |
|
42 | + ) { |
|
43 | + parent::__construct($appName, $request); |
|
44 | + $this->navigationManager = $navigationManager; |
|
45 | + $this->settingsManager = $settingsManager; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string $section |
|
50 | - * @return TemplateResponse |
|
51 | - * |
|
52 | - * @NoCSRFRequired |
|
53 | - * @NoAdminRequired |
|
54 | - * @NoSubadminRequired |
|
55 | - */ |
|
56 | - public function index($section) { |
|
57 | - return $this->getIndexResponse('personal', $section); |
|
48 | + /** |
|
49 | + * @param string $section |
|
50 | + * @return TemplateResponse |
|
51 | + * |
|
52 | + * @NoCSRFRequired |
|
53 | + * @NoAdminRequired |
|
54 | + * @NoSubadminRequired |
|
55 | + */ |
|
56 | + public function index($section) { |
|
57 | + return $this->getIndexResponse('personal', $section); |
|
58 | 58 | |
59 | - } |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @param string $section |
|
63 | - * @return array |
|
64 | - */ |
|
65 | - protected function getSettings($section) { |
|
66 | - $settings = $this->settingsManager->getPersonalSettings($section); |
|
67 | - $formatted = $this->formatSettings($settings); |
|
68 | - if($section === 'additional') { |
|
69 | - $formatted['content'] .= $this->getLegacyForms(); |
|
70 | - } |
|
71 | - return $formatted; |
|
72 | - } |
|
61 | + /** |
|
62 | + * @param string $section |
|
63 | + * @return array |
|
64 | + */ |
|
65 | + protected function getSettings($section) { |
|
66 | + $settings = $this->settingsManager->getPersonalSettings($section); |
|
67 | + $formatted = $this->formatSettings($settings); |
|
68 | + if($section === 'additional') { |
|
69 | + $formatted['content'] .= $this->getLegacyForms(); |
|
70 | + } |
|
71 | + return $formatted; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return bool|string |
|
76 | - */ |
|
77 | - private function getLegacyForms() { |
|
78 | - $forms = \OC_App::getForms('personal'); |
|
74 | + /** |
|
75 | + * @return bool|string |
|
76 | + */ |
|
77 | + private function getLegacyForms() { |
|
78 | + $forms = \OC_App::getForms('personal'); |
|
79 | 79 | |
80 | - $forms = array_map(function ($form) { |
|
81 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
82 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
83 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
84 | - $anchor = strtolower($sectionName); |
|
85 | - $anchor = str_replace(' ', '-', $anchor); |
|
80 | + $forms = array_map(function ($form) { |
|
81 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
82 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
83 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
84 | + $anchor = strtolower($sectionName); |
|
85 | + $anchor = str_replace(' ', '-', $anchor); |
|
86 | 86 | |
87 | - return array( |
|
88 | - 'anchor' => $anchor, |
|
89 | - 'section-name' => $sectionName, |
|
90 | - 'form' => $form |
|
91 | - ); |
|
92 | - } |
|
93 | - return array( |
|
94 | - 'form' => $form |
|
95 | - ); |
|
96 | - }, $forms); |
|
87 | + return array( |
|
88 | + 'anchor' => $anchor, |
|
89 | + 'section-name' => $sectionName, |
|
90 | + 'form' => $form |
|
91 | + ); |
|
92 | + } |
|
93 | + return array( |
|
94 | + 'form' => $form |
|
95 | + ); |
|
96 | + }, $forms); |
|
97 | 97 | |
98 | - $out = new Template('settings', 'settings/additional'); |
|
99 | - $out->assign('forms', $forms); |
|
98 | + $out = new Template('settings', 'settings/additional'); |
|
99 | + $out->assign('forms', $forms); |
|
100 | 100 | |
101 | - return $out->fetchPage(); |
|
102 | - } |
|
101 | + return $out->fetchPage(); |
|
102 | + } |
|
103 | 103 | } |
@@ -31,102 +31,102 @@ |
||
31 | 31 | use OCP\Settings\ISettings; |
32 | 32 | |
33 | 33 | trait CommonSettingsTrait { |
34 | - /** @var ISettingsManager */ |
|
35 | - private $settingsManager; |
|
36 | - |
|
37 | - /** @var INavigationManager */ |
|
38 | - private $navigationManager; |
|
39 | - |
|
40 | - /** |
|
41 | - * @param string $currentSection |
|
42 | - * @return array |
|
43 | - */ |
|
44 | - private function getNavigationParameters($currentType, $currentSection) { |
|
45 | - $templateParameters = [ |
|
46 | - 'personal' => $this->formatPersonalSections($currentType, $currentSection), |
|
47 | - 'admin' => [] |
|
48 | - ]; |
|
49 | - |
|
50 | - if(\OC_User::isAdminUser(\OC_User::getUser())) { |
|
51 | - $templateParameters['admin'] = $this->formatAdminSections($currentType, $currentSection); |
|
52 | - } |
|
53 | - |
|
54 | - return [ |
|
55 | - 'forms' => $templateParameters |
|
56 | - ]; |
|
57 | - } |
|
58 | - |
|
59 | - protected function formatSections($sections, $currentSection, $type, $currentType) { |
|
60 | - $templateParameters = []; |
|
61 | - /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
|
62 | - foreach($sections as $prioritizedSections) { |
|
63 | - foreach ($prioritizedSections as $section) { |
|
64 | - if($type === 'admin') { |
|
65 | - $settings = $this->settingsManager->getAdminSettings($section->getID()); |
|
66 | - } else if($type === 'personal') { |
|
67 | - $settings = $this->settingsManager->getPersonalSettings($section->getID()); |
|
68 | - } |
|
69 | - if (empty($settings)) { |
|
70 | - continue; |
|
71 | - } |
|
72 | - |
|
73 | - $icon = ''; |
|
74 | - if ($section instanceof IIconSection) { |
|
75 | - $icon = $section->getIcon(); |
|
76 | - } |
|
77 | - |
|
78 | - $active = $section->getID() === $currentSection |
|
79 | - && $type === $currentType; |
|
80 | - |
|
81 | - $templateParameters[] = [ |
|
82 | - 'anchor' => $section->getID(), |
|
83 | - 'section-name' => $section->getName(), |
|
84 | - 'active' => $active, |
|
85 | - 'icon' => $icon, |
|
86 | - ]; |
|
87 | - } |
|
88 | - } |
|
89 | - return $templateParameters; |
|
90 | - } |
|
91 | - |
|
92 | - protected function formatPersonalSections($currentType, $currentSections) { |
|
93 | - $sections = $this->settingsManager->getPersonalSections(); |
|
94 | - $templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType); |
|
95 | - |
|
96 | - return $templateParameters; |
|
97 | - } |
|
98 | - |
|
99 | - protected function formatAdminSections($currentType, $currentSections) { |
|
100 | - $sections = $this->settingsManager->getAdminSections(); |
|
101 | - $templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType); |
|
102 | - |
|
103 | - return $templateParameters; |
|
104 | - } |
|
105 | - |
|
106 | - /** |
|
107 | - * @param ISettings[] $settings |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - private function formatSettings($settings) { |
|
111 | - $html = ''; |
|
112 | - foreach ($settings as $prioritizedSettings) { |
|
113 | - foreach ($prioritizedSettings as $setting) { |
|
114 | - /** @var \OCP\Settings\ISettings $setting */ |
|
115 | - $form = $setting->getForm(); |
|
116 | - $html .= $form->renderAs('')->render(); |
|
117 | - } |
|
118 | - } |
|
119 | - return ['content' => $html]; |
|
120 | - } |
|
121 | - |
|
122 | - private function getIndexResponse($type, $section) { |
|
123 | - $this->navigationManager->setActiveEntry('settings'); |
|
124 | - $templateParams = []; |
|
125 | - $templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section)); |
|
126 | - $templateParams = array_merge($templateParams, $this->getSettings($section)); |
|
127 | - |
|
128 | - return new TemplateResponse('settings', 'settings/frame', $templateParams); |
|
129 | - } |
|
130 | - |
|
131 | - abstract protected function getSettings($section); |
|
34 | + /** @var ISettingsManager */ |
|
35 | + private $settingsManager; |
|
36 | + |
|
37 | + /** @var INavigationManager */ |
|
38 | + private $navigationManager; |
|
39 | + |
|
40 | + /** |
|
41 | + * @param string $currentSection |
|
42 | + * @return array |
|
43 | + */ |
|
44 | + private function getNavigationParameters($currentType, $currentSection) { |
|
45 | + $templateParameters = [ |
|
46 | + 'personal' => $this->formatPersonalSections($currentType, $currentSection), |
|
47 | + 'admin' => [] |
|
48 | + ]; |
|
49 | + |
|
50 | + if(\OC_User::isAdminUser(\OC_User::getUser())) { |
|
51 | + $templateParameters['admin'] = $this->formatAdminSections($currentType, $currentSection); |
|
52 | + } |
|
53 | + |
|
54 | + return [ |
|
55 | + 'forms' => $templateParameters |
|
56 | + ]; |
|
57 | + } |
|
58 | + |
|
59 | + protected function formatSections($sections, $currentSection, $type, $currentType) { |
|
60 | + $templateParameters = []; |
|
61 | + /** @var \OCP\Settings\ISection[] $prioritizedSections */ |
|
62 | + foreach($sections as $prioritizedSections) { |
|
63 | + foreach ($prioritizedSections as $section) { |
|
64 | + if($type === 'admin') { |
|
65 | + $settings = $this->settingsManager->getAdminSettings($section->getID()); |
|
66 | + } else if($type === 'personal') { |
|
67 | + $settings = $this->settingsManager->getPersonalSettings($section->getID()); |
|
68 | + } |
|
69 | + if (empty($settings)) { |
|
70 | + continue; |
|
71 | + } |
|
72 | + |
|
73 | + $icon = ''; |
|
74 | + if ($section instanceof IIconSection) { |
|
75 | + $icon = $section->getIcon(); |
|
76 | + } |
|
77 | + |
|
78 | + $active = $section->getID() === $currentSection |
|
79 | + && $type === $currentType; |
|
80 | + |
|
81 | + $templateParameters[] = [ |
|
82 | + 'anchor' => $section->getID(), |
|
83 | + 'section-name' => $section->getName(), |
|
84 | + 'active' => $active, |
|
85 | + 'icon' => $icon, |
|
86 | + ]; |
|
87 | + } |
|
88 | + } |
|
89 | + return $templateParameters; |
|
90 | + } |
|
91 | + |
|
92 | + protected function formatPersonalSections($currentType, $currentSections) { |
|
93 | + $sections = $this->settingsManager->getPersonalSections(); |
|
94 | + $templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType); |
|
95 | + |
|
96 | + return $templateParameters; |
|
97 | + } |
|
98 | + |
|
99 | + protected function formatAdminSections($currentType, $currentSections) { |
|
100 | + $sections = $this->settingsManager->getAdminSections(); |
|
101 | + $templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType); |
|
102 | + |
|
103 | + return $templateParameters; |
|
104 | + } |
|
105 | + |
|
106 | + /** |
|
107 | + * @param ISettings[] $settings |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + private function formatSettings($settings) { |
|
111 | + $html = ''; |
|
112 | + foreach ($settings as $prioritizedSettings) { |
|
113 | + foreach ($prioritizedSettings as $setting) { |
|
114 | + /** @var \OCP\Settings\ISettings $setting */ |
|
115 | + $form = $setting->getForm(); |
|
116 | + $html .= $form->renderAs('')->render(); |
|
117 | + } |
|
118 | + } |
|
119 | + return ['content' => $html]; |
|
120 | + } |
|
121 | + |
|
122 | + private function getIndexResponse($type, $section) { |
|
123 | + $this->navigationManager->setActiveEntry('settings'); |
|
124 | + $templateParams = []; |
|
125 | + $templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section)); |
|
126 | + $templateParams = array_merge($templateParams, $this->getSettings($section)); |
|
127 | + |
|
128 | + return new TemplateResponse('settings', 'settings/frame', $templateParams); |
|
129 | + } |
|
130 | + |
|
131 | + abstract protected function getSettings($section); |
|
132 | 132 | } |
@@ -36,77 +36,77 @@ |
||
36 | 36 | * @package OC\Settings\Controller |
37 | 37 | */ |
38 | 38 | class AdminSettingsController extends Controller { |
39 | - use CommonSettingsTrait; |
|
39 | + use CommonSettingsTrait; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @param string $appName |
|
43 | - * @param IRequest $request |
|
44 | - * @param INavigationManager $navigationManager |
|
45 | - * @param ISettingsManager $settingsManager |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - $appName, |
|
49 | - IRequest $request, |
|
50 | - INavigationManager $navigationManager, |
|
51 | - ISettingsManager $settingsManager |
|
52 | - ) { |
|
53 | - parent::__construct($appName, $request); |
|
54 | - $this->navigationManager = $navigationManager; |
|
55 | - $this->settingsManager = $settingsManager; |
|
56 | - } |
|
41 | + /** |
|
42 | + * @param string $appName |
|
43 | + * @param IRequest $request |
|
44 | + * @param INavigationManager $navigationManager |
|
45 | + * @param ISettingsManager $settingsManager |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + $appName, |
|
49 | + IRequest $request, |
|
50 | + INavigationManager $navigationManager, |
|
51 | + ISettingsManager $settingsManager |
|
52 | + ) { |
|
53 | + parent::__construct($appName, $request); |
|
54 | + $this->navigationManager = $navigationManager; |
|
55 | + $this->settingsManager = $settingsManager; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param string $section |
|
60 | - * @return TemplateResponse |
|
61 | - * |
|
62 | - * @NoCSRFRequired |
|
63 | - */ |
|
64 | - public function index($section) { |
|
65 | - return $this->getIndexResponse('admin', $section); |
|
66 | - } |
|
58 | + /** |
|
59 | + * @param string $section |
|
60 | + * @return TemplateResponse |
|
61 | + * |
|
62 | + * @NoCSRFRequired |
|
63 | + */ |
|
64 | + public function index($section) { |
|
65 | + return $this->getIndexResponse('admin', $section); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @param string $section |
|
70 | - * @return array |
|
71 | - */ |
|
72 | - protected function getSettings($section) { |
|
73 | - $settings = $this->settingsManager->getAdminSettings($section); |
|
74 | - $formatted = $this->formatSettings($settings); |
|
75 | - if($section === 'additional') { |
|
76 | - $formatted['content'] .= $this->getLegacyForms(); |
|
77 | - } |
|
78 | - return $formatted; |
|
79 | - } |
|
68 | + /** |
|
69 | + * @param string $section |
|
70 | + * @return array |
|
71 | + */ |
|
72 | + protected function getSettings($section) { |
|
73 | + $settings = $this->settingsManager->getAdminSettings($section); |
|
74 | + $formatted = $this->formatSettings($settings); |
|
75 | + if($section === 'additional') { |
|
76 | + $formatted['content'] .= $this->getLegacyForms(); |
|
77 | + } |
|
78 | + return $formatted; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return bool|string |
|
83 | - */ |
|
84 | - private function getLegacyForms() { |
|
85 | - $forms = \OC_App::getForms('admin'); |
|
81 | + /** |
|
82 | + * @return bool|string |
|
83 | + */ |
|
84 | + private function getLegacyForms() { |
|
85 | + $forms = \OC_App::getForms('admin'); |
|
86 | 86 | |
87 | - $forms = array_map(function ($form) { |
|
88 | - if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
89 | - $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
90 | - $sectionName = str_replace('</h2>', '', $sectionName); |
|
91 | - $anchor = strtolower($sectionName); |
|
92 | - $anchor = str_replace(' ', '-', $anchor); |
|
87 | + $forms = array_map(function ($form) { |
|
88 | + if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) { |
|
89 | + $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]); |
|
90 | + $sectionName = str_replace('</h2>', '', $sectionName); |
|
91 | + $anchor = strtolower($sectionName); |
|
92 | + $anchor = str_replace(' ', '-', $anchor); |
|
93 | 93 | |
94 | - return array( |
|
95 | - 'anchor' => $anchor, |
|
96 | - 'section-name' => $sectionName, |
|
97 | - 'form' => $form |
|
98 | - ); |
|
99 | - } |
|
100 | - return array( |
|
101 | - 'form' => $form |
|
102 | - ); |
|
103 | - }, $forms); |
|
94 | + return array( |
|
95 | + 'anchor' => $anchor, |
|
96 | + 'section-name' => $sectionName, |
|
97 | + 'form' => $form |
|
98 | + ); |
|
99 | + } |
|
100 | + return array( |
|
101 | + 'form' => $form |
|
102 | + ); |
|
103 | + }, $forms); |
|
104 | 104 | |
105 | - $out = new Template('settings', 'settings/additional'); |
|
106 | - $out->assign('forms', $forms); |
|
105 | + $out = new Template('settings', 'settings/additional'); |
|
106 | + $out->assign('forms', $forms); |
|
107 | 107 | |
108 | - return $out->fetchPage(); |
|
109 | - } |
|
108 | + return $out->fetchPage(); |
|
109 | + } |
|
110 | 110 | |
111 | 111 | |
112 | 112 | } |