1
0

PersonalSettingsController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author Robin Appelman <robin@icewind.nl>
  9. * @author Kate Döen <kate.doeen@nextcloud.com>
  10. *
  11. * @license GNU AGPL version 3 or any later version
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License as
  15. * published by the Free Software Foundation, either version 3 of the
  16. * License, or (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU Affero General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU Affero General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. *
  26. */
  27. namespace OCA\Settings\Controller;
  28. use OCP\AppFramework\Controller;
  29. use OCP\AppFramework\Http\Attribute\OpenAPI;
  30. use OCP\AppFramework\Http\TemplateResponse;
  31. use OCP\AppFramework\Services\IInitialState;
  32. use OCP\Group\ISubAdmin;
  33. use OCP\IGroupManager;
  34. use OCP\INavigationManager;
  35. use OCP\IRequest;
  36. use OCP\IUserSession;
  37. use OCP\Settings\IDeclarativeManager;
  38. use OCP\Settings\IManager as ISettingsManager;
  39. use OCP\Template;
  40. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  41. class PersonalSettingsController extends Controller {
  42. use CommonSettingsTrait;
  43. public function __construct(
  44. $appName,
  45. IRequest $request,
  46. INavigationManager $navigationManager,
  47. ISettingsManager $settingsManager,
  48. IUserSession $userSession,
  49. IGroupManager $groupManager,
  50. ISubAdmin $subAdmin,
  51. IDeclarativeManager $declarativeSettingsManager,
  52. IInitialState $initialState,
  53. ) {
  54. parent::__construct($appName, $request);
  55. $this->navigationManager = $navigationManager;
  56. $this->settingsManager = $settingsManager;
  57. $this->userSession = $userSession;
  58. $this->subAdmin = $subAdmin;
  59. $this->groupManager = $groupManager;
  60. $this->declarativeSettingsManager = $declarativeSettingsManager;
  61. $this->initialState = $initialState;
  62. }
  63. /**
  64. * @NoCSRFRequired
  65. * @NoAdminRequired
  66. * @NoSubAdminRequired
  67. */
  68. public function index(string $section): TemplateResponse {
  69. return $this->getIndexResponse('personal', $section);
  70. }
  71. /**
  72. * @param string $section
  73. * @return array
  74. */
  75. protected function getSettings($section) {
  76. $settings = $this->settingsManager->getPersonalSettings($section);
  77. $formatted = $this->formatSettings($settings);
  78. if ($section === 'additional') {
  79. $formatted['content'] .= $this->getLegacyForms();
  80. }
  81. return $formatted;
  82. }
  83. /**
  84. * @return bool|string
  85. */
  86. private function getLegacyForms() {
  87. $forms = \OC_App::getForms('personal');
  88. $forms = array_map(function ($form) {
  89. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  90. $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
  91. $sectionName = str_replace('</h2>', '', $sectionName);
  92. $anchor = strtolower($sectionName);
  93. $anchor = str_replace(' ', '-', $anchor);
  94. return [
  95. 'anchor' => $anchor,
  96. 'section-name' => $sectionName,
  97. 'form' => $form
  98. ];
  99. }
  100. return [
  101. 'form' => $form
  102. ];
  103. }, $forms);
  104. $out = new Template('settings', 'settings/additional');
  105. $out->assign('forms', $forms);
  106. return $out->fetchPage();
  107. }
  108. }