You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PersonalSettingsController.php 3.1KB

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