PersonalSettingsController.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. /**
  3. * SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
  4. * SPDX-License-Identifier: AGPL-3.0-or-later
  5. */
  6. namespace OCA\Settings\Controller;
  7. use OCP\AppFramework\Controller;
  8. use OCP\AppFramework\Http\Attribute\OpenAPI;
  9. use OCP\AppFramework\Http\TemplateResponse;
  10. use OCP\AppFramework\Services\IInitialState;
  11. use OCP\Group\ISubAdmin;
  12. use OCP\IGroupManager;
  13. use OCP\INavigationManager;
  14. use OCP\IRequest;
  15. use OCP\IUserSession;
  16. use OCP\Settings\IDeclarativeManager;
  17. use OCP\Settings\IManager as ISettingsManager;
  18. use OCP\Template;
  19. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  20. class PersonalSettingsController extends Controller {
  21. use CommonSettingsTrait;
  22. public function __construct(
  23. $appName,
  24. IRequest $request,
  25. INavigationManager $navigationManager,
  26. ISettingsManager $settingsManager,
  27. IUserSession $userSession,
  28. IGroupManager $groupManager,
  29. ISubAdmin $subAdmin,
  30. IDeclarativeManager $declarativeSettingsManager,
  31. IInitialState $initialState,
  32. ) {
  33. parent::__construct($appName, $request);
  34. $this->navigationManager = $navigationManager;
  35. $this->settingsManager = $settingsManager;
  36. $this->userSession = $userSession;
  37. $this->subAdmin = $subAdmin;
  38. $this->groupManager = $groupManager;
  39. $this->declarativeSettingsManager = $declarativeSettingsManager;
  40. $this->initialState = $initialState;
  41. }
  42. /**
  43. * @NoCSRFRequired
  44. * @NoAdminRequired
  45. * @NoSubAdminRequired
  46. */
  47. public function index(string $section): TemplateResponse {
  48. return $this->getIndexResponse('personal', $section);
  49. }
  50. /**
  51. * @param string $section
  52. * @return array
  53. */
  54. protected function getSettings($section) {
  55. $settings = $this->settingsManager->getPersonalSettings($section);
  56. $formatted = $this->formatSettings($settings);
  57. if ($section === 'additional') {
  58. $formatted['content'] .= $this->getLegacyForms();
  59. }
  60. return $formatted;
  61. }
  62. /**
  63. * @return bool|string
  64. */
  65. private function getLegacyForms() {
  66. $forms = \OC_App::getForms('personal');
  67. $forms = array_map(function ($form) {
  68. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  69. $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
  70. $sectionName = str_replace('</h2>', '', $sectionName);
  71. $anchor = strtolower($sectionName);
  72. $anchor = str_replace(' ', '-', $anchor);
  73. return [
  74. 'anchor' => $anchor,
  75. 'section-name' => $sectionName,
  76. 'form' => $form
  77. ];
  78. }
  79. return [
  80. 'form' => $form
  81. ];
  82. }, $forms);
  83. $out = new Template('settings', 'settings/additional');
  84. $out->assign('forms', $forms);
  85. return $out->fetchPage();
  86. }
  87. }