2016-08-09 00:31:26 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2016 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
2016-08-15 17:24:56 +03:00
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-08-09 00:31:26 +03:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\Settings\Controller;
|
|
|
|
|
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\INavigationManager;
|
|
|
|
use OCP\IRequest;
|
2017-01-19 12:34:17 +03:00
|
|
|
use OCP\Settings\IIconSection;
|
2016-08-09 00:31:26 +03:00
|
|
|
use OCP\Settings\IManager as ISettingsManager;
|
2017-01-19 12:34:17 +03:00
|
|
|
use OCP\Settings\ISection;
|
2016-08-13 01:59:04 +03:00
|
|
|
use OCP\Template;
|
2016-08-09 00:31:26 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @package OC\Settings\Controller
|
|
|
|
*/
|
|
|
|
class AdminSettingsController extends Controller {
|
|
|
|
/** @var INavigationManager */
|
|
|
|
private $navigationManager;
|
|
|
|
/** @var ISettingsManager */
|
|
|
|
private $settingsManager;
|
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IRequest $request
|
|
|
|
* @param INavigationManager $navigationManager
|
|
|
|
* @param ISettingsManager $settingsManager
|
|
|
|
*/
|
2016-08-09 00:31:26 +03:00
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IRequest $request,
|
|
|
|
INavigationManager $navigationManager,
|
|
|
|
ISettingsManager $settingsManager
|
|
|
|
) {
|
|
|
|
parent::__construct($appName, $request);
|
|
|
|
$this->navigationManager = $navigationManager;
|
|
|
|
$this->settingsManager = $settingsManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $section
|
|
|
|
* @return TemplateResponse
|
|
|
|
*
|
|
|
|
* @NoCSRFRequired
|
|
|
|
*/
|
|
|
|
public function index($section) {
|
|
|
|
$this->navigationManager->setActiveEntry('admin');
|
|
|
|
|
|
|
|
$templateParams = [];
|
2016-08-12 18:08:32 +03:00
|
|
|
$templateParams = array_merge($templateParams, $this->getNavigationParameters($section));
|
2016-08-09 00:31:26 +03:00
|
|
|
$templateParams = array_merge($templateParams, $this->getSettings($section));
|
|
|
|
|
|
|
|
return new TemplateResponse('settings', 'admin/frame', $templateParams);
|
|
|
|
}
|
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
/**
|
|
|
|
* @param string $section
|
|
|
|
* @return array
|
|
|
|
*/
|
2016-08-09 00:31:26 +03:00
|
|
|
private function getSettings($section) {
|
|
|
|
$html = '';
|
2016-08-13 01:59:04 +03:00
|
|
|
$settings = $this->settingsManager->getAdminSettings($section);
|
2016-08-09 00:31:26 +03:00
|
|
|
foreach ($settings as $prioritizedSettings) {
|
|
|
|
foreach ($prioritizedSettings as $setting) {
|
2016-08-11 15:48:21 +03:00
|
|
|
/** @var \OCP\Settings\ISettings $setting */
|
2016-08-10 16:21:25 +03:00
|
|
|
$form = $setting->getForm();
|
|
|
|
$html .= $form->renderAs('')->render();
|
2016-08-09 00:31:26 +03:00
|
|
|
}
|
|
|
|
}
|
2016-08-13 01:59:04 +03:00
|
|
|
if($section === 'additional') {
|
|
|
|
$html .= $this->getLegacyForms();
|
|
|
|
}
|
2016-08-09 00:31:26 +03:00
|
|
|
return ['content' => $html];
|
|
|
|
}
|
|
|
|
|
2016-08-15 17:24:56 +03:00
|
|
|
/**
|
|
|
|
* @return bool|string
|
|
|
|
*/
|
2016-08-10 00:30:07 +03:00
|
|
|
private function getLegacyForms() {
|
|
|
|
$forms = \OC_App::getForms('admin');
|
|
|
|
|
|
|
|
$forms = array_map(function ($form) {
|
|
|
|
if (preg_match('%(<h2(?P<class>[^>]*)>.*?</h2>)%i', $form, $regs)) {
|
|
|
|
$sectionName = str_replace('<h2' . $regs['class'] . '>', '', $regs[0]);
|
|
|
|
$sectionName = str_replace('</h2>', '', $sectionName);
|
|
|
|
$anchor = strtolower($sectionName);
|
|
|
|
$anchor = str_replace(' ', '-', $anchor);
|
|
|
|
|
|
|
|
return array(
|
|
|
|
'anchor' => $anchor,
|
|
|
|
'section-name' => $sectionName,
|
|
|
|
'form' => $form
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return array(
|
|
|
|
'form' => $form
|
|
|
|
);
|
|
|
|
}, $forms);
|
|
|
|
|
2016-08-13 01:59:04 +03:00
|
|
|
$out = new Template('settings', 'admin/additional');
|
2016-08-10 00:30:07 +03:00
|
|
|
$out->assign('forms', $forms);
|
|
|
|
|
2016-08-13 01:59:04 +03:00
|
|
|
return $out->fetchPage();
|
2016-08-10 00:30:07 +03:00
|
|
|
}
|
|
|
|
|
2016-08-12 18:08:32 +03:00
|
|
|
/**
|
|
|
|
* @param string $currentSection
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
private function getNavigationParameters($currentSection) {
|
2016-08-09 00:31:26 +03:00
|
|
|
$sections = $this->settingsManager->getAdminSections();
|
|
|
|
$templateParameters = [];
|
2016-08-15 17:24:56 +03:00
|
|
|
/** @var \OC\Settings\Section[] $prioritizedSections */
|
2016-08-09 00:31:26 +03:00
|
|
|
foreach($sections as $prioritizedSections) {
|
|
|
|
foreach ($prioritizedSections as $section) {
|
2017-04-19 14:11:19 +03:00
|
|
|
if (empty($this->settingsManager->getAdminSettings($section->getID()))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-01-19 12:34:17 +03:00
|
|
|
$icon = '';
|
|
|
|
if ($section instanceof IIconSection) {
|
|
|
|
$icon = $section->getIcon();
|
|
|
|
}
|
|
|
|
|
2016-08-12 18:08:32 +03:00
|
|
|
$templateParameters[] = [
|
|
|
|
'anchor' => $section->getID(),
|
|
|
|
'section-name' => $section->getName(),
|
|
|
|
'active' => $section->getID() === $currentSection,
|
2017-01-19 12:34:17 +03:00
|
|
|
'icon' => $icon,
|
2016-08-12 18:08:32 +03:00
|
|
|
];
|
2016-08-09 00:31:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [
|
|
|
|
'forms' => $templateParameters
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|