From: Hypolite Petovan Date: Sat, 5 Nov 2022 02:32:46 +0000 (-0400) Subject: Move settings/addons to src/Module X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=33d1df3c6d81de08c4eedf529a36d83d1aad16da;p=friendica.git Move settings/addons to src/Module --- diff --git a/doc/Connectors.md b/doc/Connectors.md index 148352c552..992e83bba9 100644 --- a/doc/Connectors.md +++ b/doc/Connectors.md @@ -9,8 +9,8 @@ There is also a connector for accessing your email INBOX. If the following network connectors are installed on your system, select the following links to visit the appropriate settings page and configure them for your account: -* [Twitter](/settings/addon) -* [GNU Social](/settings/addon) +* [Twitter](/settings/addons) +* [GNU Social](/settings/addons) * [Email](/settings) Instructions For Connecting To People On Specific Services diff --git a/mod/settings.php b/mod/settings.php index 1935c17091..290a2d374c 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -55,14 +55,6 @@ function settings_post(App $a) return; } - if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] == 'addon')) { - BaseModule::checkFormSecurityTokenRedirectOnError(DI::args()->getQueryString(), 'settings_addon'); - - Hook::callAll('addon_settings_post', $_POST); - DI::baseUrl()->redirect(DI::args()->getQueryString()); - return; - } - $user = User::getById($a->getLoggedInUserId()); if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] == 'connectors')) { @@ -157,41 +149,6 @@ function settings_content(App $a) return ''; } - if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'addon')) { - $addon_settings_forms = []; - foreach (DI::dba()->selectToArray('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) { - $data = []; - Hook::callSingle(DI::app(), 'addon_settings', [$hook['file'], $hook['function']], $data); - - if (!empty($data['href'])) { - $tpl = Renderer::getMarkupTemplate('settings/addon/link.tpl'); - $addon_settings_forms[] = Renderer::replaceMacros($tpl, [ - '$addon' => $data['addon'], - '$title' => $data['title'], - '$href' => $data['href'], - ]); - } elseif(!empty($data['addon'])) { - $tpl = Renderer::getMarkupTemplate('settings/addon/panel.tpl'); - $addon_settings_forms[$data['addon']] = Renderer::replaceMacros($tpl, [ - '$addon' => $data['addon'], - '$title' => $data['title'], - '$open' => (DI::args()->getArgv()[2] ?? '') === $data['addon'], - '$html' => $data['html'] ?? '', - '$submit' => $data['submit'] ?? DI::l10n()->t('Save Settings'), - ]); - } - } - - $tpl = Renderer::getMarkupTemplate('settings/addons.tpl'); - $o .= Renderer::replaceMacros($tpl, [ - '$form_security_token' => BaseModule::getFormSecurityToken("settings_addon"), - '$title' => DI::l10n()->t('Addon Settings'), - '$no_addons_settings_configured' => DI::l10n()->t('No Addon settings configured'), - '$addon_settings_forms' => $addon_settings_forms, - ]); - return $o; - } - if ((DI::args()->getArgc() > 1) && (DI::args()->getArgv()[1] === 'features')) { $arr = []; diff --git a/src/Module/BaseSettings.php b/src/Module/BaseSettings.php index 89dc8d8673..142a8941c8 100644 --- a/src/Module/BaseSettings.php +++ b/src/Module/BaseSettings.php @@ -132,7 +132,7 @@ class BaseSettings extends BaseModule $tabs[] = [ 'label' => $this->t('Addons'), - 'url' => 'settings/addon', + 'url' => 'settings/addons', 'selected' => static::class == Settings\Addons::class ? 'active' : '', 'accesskey' => 'l', ]; diff --git a/src/Module/Settings/Addons.php b/src/Module/Settings/Addons.php new file mode 100644 index 0000000000..580d37e611 --- /dev/null +++ b/src/Module/Settings/Addons.php @@ -0,0 +1,94 @@ +. + * + */ + +namespace Friendica\Module\Settings; + +use Friendica\App; +use Friendica\Core\Hook; +use Friendica\Core\L10n; +use Friendica\Core\Renderer; +use Friendica\Core\Session\Capability\IHandleUserSessions; +use Friendica\Database\Database; +use Friendica\Module\BaseSettings; +use Friendica\Module\Response; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; + +class Addons extends BaseSettings +{ + /** @var Database */ + private $database; + /** @var App */ + private $app; + + public function __construct(App $app, Database $database, 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->database = $database; + $this->app = $app; + } + + protected function post(array $request = []) + { + BaseSettings::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings_addon'); + + Hook::callAll('addon_settings_post', $request); + $this->baseUrl->redirect($this->args->getQueryString()); + } + + protected function content(array $request = []): string + { + parent::content($request); // TODO: Change the autogenerated stub + + $addon_settings_forms = []; + foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) { + $data = []; + Hook::callSingle($this->app, 'addon_settings', [$hook['file'], $hook['function']], $data); + + if (!empty($data['href'])) { + $tpl = Renderer::getMarkupTemplate('settings/addons/link.tpl'); + $addon_settings_forms[] = Renderer::replaceMacros($tpl, [ + '$addon' => $data['addon'], + '$title' => $data['title'], + '$href' => $data['href'], + ]); + } elseif (!empty($data['addon'])) { + $tpl = Renderer::getMarkupTemplate('settings/addons/panel.tpl'); + $addon_settings_forms[$data['addon']] = Renderer::replaceMacros($tpl, [ + '$addon' => $data['addon'], + '$title' => $data['title'], + '$open' => ($this->parameters['addon'] ?? '') === $data['addon'], + '$html' => $data['html'] ?? '', + '$submit' => $data['submit'] ?? $this->t('Save Settings'), + ]); + } + } + + $tpl = Renderer::getMarkupTemplate('settings/addons.tpl'); + return Renderer::replaceMacros($tpl, [ + '$form_security_token' => BaseSettings::getFormSecurityToken('settings_addon'), + '$title' => $this->t('Addon Settings'), + '$no_addons_settings_configured' => $this->t('No Addon settings configured'), + '$addon_settings_forms' => $addon_settings_forms, + ]); + } +} diff --git a/static/routes.config.php b/static/routes.config.php index c69a1515af..ef80922e38 100644 --- a/static/routes.config.php +++ b/static/routes.config.php @@ -592,6 +592,7 @@ return [ '[/]' => [Module\Settings\Account::class, [R::GET, R::POST]], '/{open}' => [Module\Settings\Account::class, [R::GET, R::POST]], ], + '/addons[/{addon}]' => [Module\Settings\Addons::class, [R::GET, R::POST]], '/2fa' => [ '[/]' => [Module\Settings\TwoFactor\Index::class, [R::GET, R::POST]], '/recovery' => [Module\Settings\TwoFactor\Recovery::class, [R::GET, R::POST]], diff --git a/view/templates/settings/addon/link.tpl b/view/templates/settings/addon/link.tpl deleted file mode 100644 index 4fb8178ccf..0000000000 --- a/view/templates/settings/addon/link.tpl +++ /dev/null @@ -1 +0,0 @@ -

{{$title}}

\ No newline at end of file diff --git a/view/templates/settings/addon/panel.tpl b/view/templates/settings/addon/panel.tpl deleted file mode 100644 index f401f01231..0000000000 --- a/view/templates/settings/addon/panel.tpl +++ /dev/null @@ -1,33 +0,0 @@ - -

{{$title}}

-
-
- -

{{$title}}

-
- {{$html nofilter}} -{{if $submit}} - -{{/if}} -
diff --git a/view/templates/settings/addons.tpl b/view/templates/settings/addons.tpl index 03313c9244..768a0d6c46 100644 --- a/view/templates/settings/addons.tpl +++ b/view/templates/settings/addons.tpl @@ -2,7 +2,7 @@ {{foreach $addon_settings_forms as $addon => $addon_settings_form}} -
+ {{$addon_settings_form nofilter}}
diff --git a/view/templates/settings/addons/link.tpl b/view/templates/settings/addons/link.tpl new file mode 100644 index 0000000000..4fb8178ccf --- /dev/null +++ b/view/templates/settings/addons/link.tpl @@ -0,0 +1 @@ +

{{$title}}

\ No newline at end of file diff --git a/view/templates/settings/addons/panel.tpl b/view/templates/settings/addons/panel.tpl new file mode 100644 index 0000000000..f401f01231 --- /dev/null +++ b/view/templates/settings/addons/panel.tpl @@ -0,0 +1,33 @@ + +

{{$title}}

+
+
+ +

{{$title}}

+
+ {{$html nofilter}} +{{if $submit}} + +{{/if}} +
diff --git a/view/theme/frio/templates/settings/addon/link.tpl b/view/theme/frio/templates/settings/addon/link.tpl deleted file mode 100644 index bf430db46b..0000000000 --- a/view/theme/frio/templates/settings/addon/link.tpl +++ /dev/null @@ -1 +0,0 @@ -

{{$title}}

diff --git a/view/theme/frio/templates/settings/addon/panel.tpl b/view/theme/frio/templates/settings/addon/panel.tpl deleted file mode 100644 index 561d0fc9f3..0000000000 --- a/view/theme/frio/templates/settings/addon/panel.tpl +++ /dev/null @@ -1,36 +0,0 @@ - -
-
- {{$html nofilter}} -
- -
diff --git a/view/theme/frio/templates/settings/addons.tpl b/view/theme/frio/templates/settings/addons.tpl index f150303eaf..af37f6e0cf 100644 --- a/view/theme/frio/templates/settings/addons.tpl +++ b/view/theme/frio/templates/settings/addons.tpl @@ -4,7 +4,7 @@
{{foreach $addon_settings_forms as $addon => $addon_settings_form}} -
+ {{$addon_settings_form nofilter}}
diff --git a/view/theme/frio/templates/settings/addons/link.tpl b/view/theme/frio/templates/settings/addons/link.tpl new file mode 100644 index 0000000000..bf430db46b --- /dev/null +++ b/view/theme/frio/templates/settings/addons/link.tpl @@ -0,0 +1 @@ + diff --git a/view/theme/frio/templates/settings/addons/panel.tpl b/view/theme/frio/templates/settings/addons/panel.tpl new file mode 100644 index 0000000000..561d0fc9f3 --- /dev/null +++ b/view/theme/frio/templates/settings/addons/panel.tpl @@ -0,0 +1,36 @@ + +
+
+ {{$html nofilter}} +
+ +