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.

145 lines
3.8 KiB

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