2020-06-05 05:37:17 +09:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// {{{ License
|
2020-07-18 11:16:18 +09:00
|
|
|
|
2020-06-05 05:37:17 +09:00
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social 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.
|
|
|
|
//
|
|
|
|
// GNU social 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 GNU social. If not, see <http://www.gnu.org/licenses/>.
|
2020-07-18 11:16:18 +09:00
|
|
|
|
2020-06-05 05:37:17 +09:00
|
|
|
// }}}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle network public feed
|
|
|
|
*
|
|
|
|
* @package GNUsocial
|
|
|
|
* @category Controller
|
|
|
|
*
|
2021-02-20 08:29:43 +09:00
|
|
|
* @author Hugo Sales <hugo@hsal.es>
|
|
|
|
* @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
|
2020-06-05 05:37:17 +09:00
|
|
|
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
2020-07-07 05:51:08 +09:00
|
|
|
use App\Core\Controller;
|
2020-06-24 06:24:14 +09:00
|
|
|
use App\Core\Form;
|
2020-06-05 06:53:34 +09:00
|
|
|
use function App\Core\I18n\_m;
|
2020-07-25 23:43:43 +09:00
|
|
|
use App\Util\Common;
|
2020-09-08 09:12:33 +09:00
|
|
|
use App\Util\Exceptiion\InvalidFormException;
|
2020-07-25 23:43:43 +09:00
|
|
|
use App\Util\Formatting;
|
2020-06-05 05:37:17 +09:00
|
|
|
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
|
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextType;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
2020-07-23 23:08:31 +09:00
|
|
|
class AdminPanel extends Controller
|
2020-06-05 05:37:17 +09:00
|
|
|
{
|
2020-11-07 04:47:15 +09:00
|
|
|
/**
|
|
|
|
* Handler for the site admin panel section. Allows the
|
|
|
|
* administrator to change various configuration options
|
|
|
|
*/
|
2020-07-24 02:55:06 +09:00
|
|
|
public function site(Request $request)
|
2020-06-05 05:37:17 +09:00
|
|
|
{
|
2020-11-07 04:47:15 +09:00
|
|
|
// TODO CHECK PERMISSION
|
2020-10-01 07:57:25 +09:00
|
|
|
$defaults = Common::getConfigDefaults();
|
2020-06-24 06:24:14 +09:00
|
|
|
$options = [];
|
|
|
|
foreach ($defaults as $key => $inner) {
|
2020-06-05 05:37:17 +09:00
|
|
|
$options[$key] = [];
|
|
|
|
foreach (array_keys($inner) as $inner_key) {
|
2020-06-05 06:53:34 +09:00
|
|
|
$options[_m($key)][_m($inner_key)] = "{$key}:{$inner_key}";
|
2020-06-05 05:37:17 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-23 23:08:31 +09:00
|
|
|
$form = Form::create([
|
2020-07-25 23:43:43 +09:00
|
|
|
['setting', ChoiceType::class, ['label' => _m('Setting'), 'choices' => $options]],
|
|
|
|
['value', TextType::class, ['label' => _m('Value')]],
|
|
|
|
['save', SubmitType::class, ['label' => _m('Set site setting')]],
|
2020-07-23 23:08:31 +09:00
|
|
|
]);
|
2020-06-05 05:37:17 +09:00
|
|
|
|
|
|
|
$form->handleRequest($request);
|
2020-06-24 06:24:14 +09:00
|
|
|
if ($form->isSubmitted()) {
|
2020-06-05 05:37:17 +09:00
|
|
|
$data = $form->getData();
|
2020-07-25 23:43:43 +09:00
|
|
|
if ($form->isValid() && array_key_exists('setting', $data)) {
|
|
|
|
list($section, $setting) = explode(':', $data['setting']);
|
|
|
|
$value = $data['value'];
|
|
|
|
if (preg_match('/^[0-9]+$/', $value)) {
|
|
|
|
$value = (int) $value;
|
2020-10-01 07:57:25 +09:00
|
|
|
} elseif (strstr($value, ',') === false) {
|
|
|
|
// empty, string
|
2020-07-25 23:43:43 +09:00
|
|
|
} elseif (Formatting::toArray($value, $value)) {
|
|
|
|
// empty
|
|
|
|
} elseif (preg_match('/true|false/i', $value)) {
|
|
|
|
$value = ($value == 'true');
|
|
|
|
}
|
|
|
|
|
|
|
|
$default = $defaults[$section][$setting];
|
2020-07-23 23:08:31 +09:00
|
|
|
// Sanity check
|
2020-06-24 06:24:14 +09:00
|
|
|
if (gettype($default) === gettype($value)) {
|
2020-07-25 23:43:43 +09:00
|
|
|
$old_value = Common::config($section, $setting);
|
|
|
|
Common::setConfig($section, $setting, $value);
|
2020-07-23 23:08:31 +09:00
|
|
|
return [
|
|
|
|
'_template' => 'config/admin.html.twig',
|
|
|
|
'form' => $form->createView(),
|
2020-07-25 23:43:43 +09:00
|
|
|
'old_value' => Formatting::toString($old_value),
|
|
|
|
'default' => Formatting::toString($default),
|
2020-07-23 23:08:31 +09:00
|
|
|
];
|
2020-06-24 06:24:14 +09:00
|
|
|
}
|
|
|
|
} else {
|
2020-09-08 09:12:33 +09:00
|
|
|
throw new InvalidFormException();
|
2020-06-24 06:24:14 +09:00
|
|
|
}
|
2020-06-05 05:37:17 +09:00
|
|
|
}
|
|
|
|
|
2020-07-07 05:51:08 +09:00
|
|
|
return [
|
|
|
|
'_template' => 'config/admin.html.twig',
|
|
|
|
'form' => $form->createView(),
|
|
|
|
];
|
2020-06-05 05:37:17 +09:00
|
|
|
}
|
|
|
|
}
|