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.

115 lines
3.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Lukas Reschke <lukas@statuscode.ch>
  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. /**
  32. * @package OC\Settings\Controller
  33. */
  34. class AdminSettingsController extends Controller {
  35. use CommonSettingsTrait;
  36. /** @var INavigationManager */
  37. private $navigationManager;
  38. /**
  39. * @param string $appName
  40. * @param IRequest $request
  41. * @param INavigationManager $navigationManager
  42. * @param ISettingsManager $settingsManager
  43. */
  44. public function __construct(
  45. $appName,
  46. IRequest $request,
  47. INavigationManager $navigationManager,
  48. ISettingsManager $settingsManager
  49. ) {
  50. parent::__construct($appName, $request);
  51. $this->navigationManager = $navigationManager;
  52. $this->settingsManager = $settingsManager;
  53. }
  54. /**
  55. * @param string $section
  56. * @return TemplateResponse
  57. *
  58. * @NoCSRFRequired
  59. */
  60. public function index($section) {
  61. $this->navigationManager->setActiveEntry('admin');
  62. return $this->getIndexResponse('admin', $section);
  63. }
  64. /**
  65. * @param string $section
  66. * @return array
  67. */
  68. protected function getSettings($section) {
  69. $settings = $this->settingsManager->getAdminSettings($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('admin');
  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 array(
  88. 'anchor' => $anchor,
  89. 'section-name' => $sectionName,
  90. 'form' => $form
  91. );
  92. }
  93. return array(
  94. 'form' => $form
  95. );
  96. }, $forms);
  97. $out = new Template('settings', 'settings/additional');
  98. $out->assign('forms', $forms);
  99. return $out->fetchPage();
  100. }
  101. }