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.

106 lines
2.8 KiB

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