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