PersonalSettingsController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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\Group\ISubAdmin;
  32. use OCP\IGroupManager;
  33. use OCP\INavigationManager;
  34. use OCP\IRequest;
  35. use OCP\IUserSession;
  36. use OCP\Settings\IManager as ISettingsManager;
  37. use OCP\Template;
  38. #[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
  39. class PersonalSettingsController extends Controller {
  40. use CommonSettingsTrait;
  41. public function __construct(
  42. $appName,
  43. IRequest $request,
  44. INavigationManager $navigationManager,
  45. ISettingsManager $settingsManager,
  46. IUserSession $userSession,
  47. IGroupManager $groupManager,
  48. ISubAdmin $subAdmin
  49. ) {
  50. parent::__construct($appName, $request);
  51. $this->navigationManager = $navigationManager;
  52. $this->settingsManager = $settingsManager;
  53. $this->userSession = $userSession;
  54. $this->subAdmin = $subAdmin;
  55. $this->groupManager = $groupManager;
  56. }
  57. /**
  58. * @NoCSRFRequired
  59. * @NoAdminRequired
  60. * @NoSubAdminRequired
  61. */
  62. public function index(string $section): TemplateResponse {
  63. return $this->getIndexResponse('personal', $section);
  64. }
  65. /**
  66. * @param string $section
  67. * @return array
  68. */
  69. protected function getSettings($section) {
  70. $settings = $this->settingsManager->getPersonalSettings($section);
  71. $formatted = $this->formatSettings($settings);
  72. if ($section === 'additional') {
  73. $formatted['content'] .= $this->getLegacyForms();
  74. }
  75. return $formatted;
  76. }
  77. /**
  78. * @return bool|string
  79. */
  80. private function getLegacyForms() {
  81. $forms = \OC_App::getForms('personal');
  82. $forms = array_map(function ($form) {
  83. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  84. $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
  85. $sectionName = str_replace('</h2>', '', $sectionName);
  86. $anchor = strtolower($sectionName);
  87. $anchor = str_replace(' ', '-', $anchor);
  88. return [
  89. 'anchor' => $anchor,
  90. 'section-name' => $sectionName,
  91. 'form' => $form
  92. ];
  93. }
  94. return [
  95. 'form' => $form
  96. ];
  97. }, $forms);
  98. $out = new Template('settings', 'settings/additional');
  99. $out->assign('forms', $forms);
  100. return $out->fetchPage();
  101. }
  102. }