1
0

PersonalSettingsController.php 2.6 KB

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