1
0

PersonalSettingsController.php 2.8 KB

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