AdminSettingsController.php 2.9 KB

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