AdminSettingsController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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\Group\ISubAdmin;
  29. use OCP\IGroupManager;
  30. use OCP\INavigationManager;
  31. use OCP\IRequest;
  32. use OCP\IUser;
  33. use OCP\IUserSession;
  34. use OCP\Settings\IManager as ISettingsManager;
  35. use OCP\Template;
  36. /**
  37. * @package OC\Settings\Controller
  38. */
  39. class AdminSettingsController extends Controller {
  40. use CommonSettingsTrait;
  41. public function __construct(
  42. $appName,
  43. IRequest $request,
  44. INavigationManager $navigationManager,
  45. ISettingsManager $settingsManager,
  46. IUserSession $userSession,
  47. IGroupManager $groupManager,
  48. ISubAdmin $subAdmin
  49. ) {
  50. parent::__construct($appName, $request);
  51. $this->navigationManager = $navigationManager;
  52. $this->settingsManager = $settingsManager;
  53. $this->userSession = $userSession;
  54. $this->groupManager = $groupManager;
  55. $this->subAdmin = $subAdmin;
  56. }
  57. /**
  58. * @param string $section
  59. * @return TemplateResponse
  60. *
  61. * @NoCSRFRequired
  62. * @SubAdminRequired
  63. */
  64. public function index($section) {
  65. return $this->getIndexResponse('admin', $section);
  66. }
  67. /**
  68. * @param string $section
  69. * @return array
  70. */
  71. protected function getSettings($section) {
  72. /** @var IUser $user */
  73. $user = $this->userSession->getUser();
  74. $isSubAdmin = !$this->groupManager->isAdmin($user->getUID()) && $this->subAdmin->isSubAdmin($user);
  75. $settings = $this->settingsManager->getAdminSettings(
  76. $section,
  77. $isSubAdmin
  78. );
  79. $formatted = $this->formatSettings($settings);
  80. // Do not show legacy forms for sub admins
  81. if($section === 'additional' && !$isSubAdmin) {
  82. $formatted['content'] .= $this->getLegacyForms();
  83. }
  84. return $formatted;
  85. }
  86. /**
  87. * @return bool|string
  88. */
  89. private function getLegacyForms() {
  90. $forms = \OC_App::getForms('admin');
  91. $forms = array_map(function ($form) {
  92. if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
  93. $sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
  94. $sectionName = str_replace('</h2>', '', $sectionName);
  95. $anchor = strtolower($sectionName);
  96. $anchor = str_replace(' ', '-', $anchor);
  97. return array(
  98. 'anchor' => $anchor,
  99. 'section-name' => $sectionName,
  100. 'form' => $form
  101. );
  102. }
  103. return array(
  104. 'form' => $form
  105. );
  106. }, $forms);
  107. $out = new Template('settings', 'settings/additional');
  108. $out->assign('forms', $forms);
  109. return $out->fetchPage();
  110. }
  111. }