You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AdminSettingsController.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OC\Settings\Controller;
  25. use OCP\AppFramework\Controller;
  26. use OCP\AppFramework\Http\TemplateResponse;
  27. use OCP\INavigationManager;
  28. use OCP\IRequest;
  29. use OCP\Settings\IManager as ISettingsManager;
  30. use OCP\Template;
  31. /**
  32. * @package OC\Settings\Controller
  33. */
  34. class AdminSettingsController extends Controller {
  35. /** @var INavigationManager */
  36. private $navigationManager;
  37. /** @var ISettingsManager */
  38. private $settingsManager;
  39. /**
  40. * @param string $appName
  41. * @param IRequest $request
  42. * @param INavigationManager $navigationManager
  43. * @param ISettingsManager $settingsManager
  44. */
  45. public function __construct(
  46. $appName,
  47. IRequest $request,
  48. INavigationManager $navigationManager,
  49. ISettingsManager $settingsManager
  50. ) {
  51. parent::__construct($appName, $request);
  52. $this->navigationManager = $navigationManager;
  53. $this->settingsManager = $settingsManager;
  54. }
  55. /**
  56. * @param string $section
  57. * @return TemplateResponse
  58. *
  59. * @NoCSRFRequired
  60. */
  61. public function index($section) {
  62. $this->navigationManager->setActiveEntry('admin');
  63. $templateParams = [];
  64. $templateParams = array_merge($templateParams, $this->getNavigationParameters($section));
  65. $templateParams = array_merge($templateParams, $this->getSettings($section));
  66. return new TemplateResponse('settings', 'admin/frame', $templateParams);
  67. }
  68. /**
  69. * @param string $section
  70. * @return array
  71. */
  72. private function getSettings($section) {
  73. $html = '';
  74. $settings = $this->settingsManager->getAdminSettings($section);
  75. foreach ($settings as $prioritizedSettings) {
  76. foreach ($prioritizedSettings as $setting) {
  77. /** @var \OCP\Settings\ISettings $setting */
  78. $form = $setting->getForm();
  79. $html .= $form->renderAs('')->render();
  80. }
  81. }
  82. if($section === 'additional') {
  83. $html .= $this->getLegacyForms();
  84. }
  85. return ['content' => $html];
  86. }
  87. /**
  88. * @return bool|string
  89. */
  90. private function getLegacyForms() {
  91. $forms = \OC_App::getForms('admin');
  92. $forms = array_map(function ($form) {
  93. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  94. $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
  95. $sectionName = str_replace('</h2>', '', $sectionName);
  96. $anchor = strtolower($sectionName);
  97. $anchor = str_replace(' ', '-', $anchor);
  98. return array(
  99. 'anchor' => $anchor,
  100. 'section-name' => $sectionName,
  101. 'form' => $form
  102. );
  103. }
  104. return array(
  105. 'form' => $form
  106. );
  107. }, $forms);
  108. $out = new Template('settings', 'admin/additional');
  109. $out->assign('forms', $forms);
  110. return $out->fetchPage();
  111. }
  112. /**
  113. * @param string $currentSection
  114. * @return array
  115. */
  116. private function getNavigationParameters($currentSection) {
  117. $sections = $this->settingsManager->getAdminSections();
  118. $templateParameters = [];
  119. /** @var \OC\Settings\Section[] $prioritizedSections */
  120. foreach($sections as $prioritizedSections) {
  121. foreach ($prioritizedSections as $section) {
  122. $templateParameters[] = [
  123. 'anchor' => $section->getID(),
  124. 'section-name' => $section->getName(),
  125. 'active' => $section->getID() === $currentSection,
  126. ];
  127. }
  128. }
  129. return [
  130. 'forms' => $templateParameters
  131. ];
  132. }
  133. }