From 5916544bc8eae14746ee8207ff72d484a0777176 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Fri, 4 Nov 2022 23:59:40 -0400 Subject: [PATCH] Move settings/features to src/Module --- src/Module/Settings/Features.php | 79 ++++++++++++++++++++++++++++++++ static/routes.config.php | 1 + 2 files changed, 80 insertions(+) create mode 100644 src/Module/Settings/Features.php diff --git a/src/Module/Settings/Features.php b/src/Module/Settings/Features.php new file mode 100644 index 0000000000..5bee4427b8 --- /dev/null +++ b/src/Module/Settings/Features.php @@ -0,0 +1,79 @@ +. + * + */ + +namespace Friendica\Module\Settings; + +use Friendica\App; +use Friendica\Content\Feature; +use Friendica\Core\L10n; +use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; +use Friendica\Core\Renderer; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Module\BaseSettings; +use Friendica\Module\Response; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; + +class Features extends BaseSettings +{ + /** @var IManagePersonalConfigValues */ + private $pConfig; + + public function __construct(IManagePersonalConfigValues $pConfig, IHandleUserSessions $session, App\Page $page, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = []) + { + parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->pConfig = $pConfig; + } + + protected function post(array $request = []) + { + BaseSettings::checkFormSecurityTokenRedirectOnError('/settings/features', 'settings_features'); + foreach ($request as $k => $v) { + if (strpos($k, 'feature_') === 0) { + $this->pConfig->set($this->session->getLocalUserId(), 'feature', substr($k, 8), ((intval($v)) ? 1 : 0)); + } + } + } + + protected function content(array $request = []): string + { + parent::content($request); + + $arr = []; + $features = Feature::get(); + foreach ($features as $name => $feature) { + $arr[$name] = []; + $arr[$name][0] = $feature[0]; + foreach (array_slice($feature, 1) as $f) { + $arr[$name][1][] = ['feature_' . $f[0], $f[1], Feature::isEnabled($this->session->getLocalUserId(), $f[0]), $f[2]]; + } + } + + $tpl = Renderer::getMarkupTemplate('settings/features.tpl'); + return Renderer::replaceMacros($tpl, [ + '$form_security_token' => BaseSettings::getFormSecurityToken('settings_features'), + '$title' => $this->t('Additional Features'), + '$features' => $arr, + '$submit' => $this->t('Save Settings'), + ]); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index d2d430a8c2..01415fb260 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -596,6 +596,7 @@ return [ '/connectors[/{connector}]' => [Module\Settings\Connectors::class, [R::GET, R::POST]], '/delegation[/{action}/{user_id}]' => [Module\Settings\Delegation::class, [R::GET, R::POST]], '/display' => [Module\Settings\Display::class, [R::GET, R::POST]], + '/features' => [Module\Settings\Features::class, [R::GET, R::POST]], '/oauth' => [Module\Settings\OAuth::class, [R::GET, R::POST]], '/profile' => [ '[/]' => [Module\Settings\Profile\Index::class, [R::GET, R::POST]], -- 2.39.5