1
0

PersonalSettingsController.php 3.1 KB

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