]> git.mxchange.org Git - friendica.git/commitdiff
Move settings/addons to src/Module
authorHypolite Petovan <hypolite@mrpetovan.com>
Sat, 5 Nov 2022 02:32:46 +0000 (22:32 -0400)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 9 Nov 2022 11:25:41 +0000 (06:25 -0500)
15 files changed:
doc/Connectors.md
mod/settings.php
src/Module/BaseSettings.php
src/Module/Settings/Addons.php [new file with mode: 0644]
static/routes.config.php
view/templates/settings/addon/link.tpl [deleted file]
view/templates/settings/addon/panel.tpl [deleted file]
view/templates/settings/addons.tpl
view/templates/settings/addons/link.tpl [new file with mode: 0644]
view/templates/settings/addons/panel.tpl [new file with mode: 0644]
view/theme/frio/templates/settings/addon/link.tpl [deleted file]
view/theme/frio/templates/settings/addon/panel.tpl [deleted file]
view/theme/frio/templates/settings/addons.tpl
view/theme/frio/templates/settings/addons/link.tpl [new file with mode: 0644]
view/theme/frio/templates/settings/addons/panel.tpl [new file with mode: 0644]

index 148352c552b2a028c9cf42bd9b184b2fb784aafa..992e83bba9d986c242ebd2089b6f8491c9bf1dc0 100644 (file)
@@ -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
index 1935c17091ce01610428734087eb9fa81a6aa986..290a2d374ccf30a7fac232173d05e371cbbcfb9c 100644 (file)
@@ -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 = [];
index 89dc8d86730ef7004f18f5599bfa938b0b47c52e..142a8941c8bd308b1318bf5cff0a6b85a70a718a 100644 (file)
@@ -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 (file)
index 0000000..580d37e
--- /dev/null
@@ -0,0 +1,94 @@
+<?php
+/**
+ * @copyright Copyright (C) 2010-2022, the Friendica project
+ *
+ * @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 <https://www.gnu.org/licenses/>.
+ *
+ */
+
+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,
+               ]);
+       }
+}
index c69a1515af3faab60bccaebb15feeb7525e112fc..ef80922e387bc4e47a6de92df718837bc5a15d5c 100644 (file)
@@ -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 (file)
index 4fb8178..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<span class="settings-block fakelink" style="display: block;"><h3><a href="{{$href}}">{{$title}} <i class="glyphicon glyphicon-share"></i></a></h3></span>
\ 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 (file)
index f401f01..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-<span id="settings_{{$addon}}_inflated" class="settings-block fakelink" style="display: {{if $open}}none{{else}}block{{/if}};" onclick="openClose('settings_{{$addon}}_expanded'); openClose('settings_{{$addon}}_inflated');">
-       <h3>{{$title}}</h3>
-</span>
-<div id="settings_{{$addon}}_expanded" class="settings-block" style="display: {{if $open}}block{{else}}none{{/if}};">
-       <span class="fakelink" onclick="openClose('settings_{{$addon}}_expanded'); openClose('settings_{{$addon}}_inflated');">
-               <h3>{{$title}}</h3>
-       </span>
-       {{$html nofilter}}
-{{if $submit}}
-       <div class="settings-submit-wrapper panel-footer">
-    {{if $submit|is_string}}
-               <button type="submit" name="{{$addon}}-submit" class="btn btn-primary settings-submit" value="{{$submit}}">{{$submit}}</button>
-    {{else}}
-        {{$count = 1}}
-               {{foreach $submit as $name => $label}}{{if $label}}
-                       {{if $count == 1}}
-               <button type="submit" name="{{$name}}" class="btn btn-primary settings-submit" value="{{$label}}">{{$label}}</button>
-            {{/if}}
-            {{if $count == 2}}
-               <div class="btn-group" role="group" aria-label="...">
-                       {{/if}}
-            {{if $count != 1}}
-                       <button type="submit" name="{{$name}}" class="btn btn-default settings-submit" value="{{$label}}">{{$label}}</button>
-            {{/if}}
-            {{$count = $count + 1}}
-        {{/if}}{{/foreach}}
-               {{if $submit|count > 1}}
-               </div>
-               {{/if}}
-    {{/if}}
-       </div>
-{{/if}}
-</div>
index 03313c92446f5bebe415399ad056324a1777eaed..768a0d6c46e7527a54642319d1bf9eaeb457be09 100644 (file)
@@ -2,7 +2,7 @@
 
 {{foreach $addon_settings_forms as $addon => $addon_settings_form}}
 
-<form action="settings/addon/{{$addon}}" method="post" autocomplete="off">
+<form action="settings/addons/{{$addon}}" method="post" autocomplete="off">
        <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
        {{$addon_settings_form nofilter}}
 </form>
diff --git a/view/templates/settings/addons/link.tpl b/view/templates/settings/addons/link.tpl
new file mode 100644 (file)
index 0000000..4fb8178
--- /dev/null
@@ -0,0 +1 @@
+<span class="settings-block fakelink" style="display: block;"><h3><a href="{{$href}}">{{$title}} <i class="glyphicon glyphicon-share"></i></a></h3></span>
\ 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 (file)
index 0000000..f401f01
--- /dev/null
@@ -0,0 +1,33 @@
+<span id="settings_{{$addon}}_inflated" class="settings-block fakelink" style="display: {{if $open}}none{{else}}block{{/if}};" onclick="openClose('settings_{{$addon}}_expanded'); openClose('settings_{{$addon}}_inflated');">
+       <h3>{{$title}}</h3>
+</span>
+<div id="settings_{{$addon}}_expanded" class="settings-block" style="display: {{if $open}}block{{else}}none{{/if}};">
+       <span class="fakelink" onclick="openClose('settings_{{$addon}}_expanded'); openClose('settings_{{$addon}}_inflated');">
+               <h3>{{$title}}</h3>
+       </span>
+       {{$html nofilter}}
+{{if $submit}}
+       <div class="settings-submit-wrapper panel-footer">
+    {{if $submit|is_string}}
+               <button type="submit" name="{{$addon}}-submit" class="btn btn-primary settings-submit" value="{{$submit}}">{{$submit}}</button>
+    {{else}}
+        {{$count = 1}}
+               {{foreach $submit as $name => $label}}{{if $label}}
+                       {{if $count == 1}}
+               <button type="submit" name="{{$name}}" class="btn btn-primary settings-submit" value="{{$label}}">{{$label}}</button>
+            {{/if}}
+            {{if $count == 2}}
+               <div class="btn-group" role="group" aria-label="...">
+                       {{/if}}
+            {{if $count != 1}}
+                       <button type="submit" name="{{$name}}" class="btn btn-default settings-submit" value="{{$label}}">{{$label}}</button>
+            {{/if}}
+            {{$count = $count + 1}}
+        {{/if}}{{/foreach}}
+               {{if $submit|count > 1}}
+               </div>
+               {{/if}}
+    {{/if}}
+       </div>
+{{/if}}
+</div>
diff --git a/view/theme/frio/templates/settings/addon/link.tpl b/view/theme/frio/templates/settings/addon/link.tpl
deleted file mode 100644 (file)
index bf430db..0000000
+++ /dev/null
@@ -1 +0,0 @@
-<div class="settings-block"><h3><a href="{{$href}}">{{$title}} <i class="glyphicon glyphicon-share"></i></a></h3></div>
diff --git a/view/theme/frio/templates/settings/addon/panel.tpl b/view/theme/frio/templates/settings/addon/panel.tpl
deleted file mode 100644 (file)
index 561d0fc..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-       <div class="section-subtitle-wrapper panel-heading" role="tab" id="{{$addon}}-settings-title">
-               <h2>
-                       <button class="btn-link accordion-toggle{{if !$open}} collapsed{{/if}}" data-toggle="collapse" data-parent="#settings-addons" href="#{{$addon}}-settings-content" aria-expanded="false" aria-controls="{{$addon}}-settings-content">
-                               {{$title}}
-                       </button>
-               </h2>
-       </div>
-       <div id="{{$addon}}-settings-content" class="panel-collapse collapse{{if $open}} in{{/if}}" role="tabpanel" aria-labelledby="{{$addon}}-settings-title">
-               <div class="panel-body">
-            {{$html nofilter}}
-               </div>
-               <div class="panel-footer">
-{{if $submit}}
-    {{if $submit|is_string}}
-                       <button type="submit" name="{{$addon}}-submit" class="btn btn-primary settings-submit" value="{{$submit}}">{{$submit}}</button>
-    {{else}}
-        {{$count = 1}}
-        {{foreach $submit as $name => $label}}{{if $label}}
-            {{if $count == 1}}
-                       <button type="submit" name="{{$name}}" class="btn btn-primary settings-submit" value="{{$label}}">{{$label}}</button>
-            {{/if}}
-            {{if $count == 2}}
-                       <div class="btn-group" role="group" aria-label="...">
-            {{/if}}
-            {{if $count != 1}}
-                               <button type="submit" name="{{$name}}" class="btn btn-default settings-submit" value="{{$label}}">{{$label}}</button>
-            {{/if}}
-            {{$count = $count + 1}}
-        {{/if}}{{/foreach}}
-        {{if $submit|count > 1}}
-                       </div>
-        {{/if}}
-    {{/if}}
-{{/if}}
-               </div>
-       </div>
index f150303eaf8b844ee921ffd64cbced8d4e3de6fb..af37f6e0cf89bb62e8d904423a5cf78960ec33ec 100644 (file)
@@ -4,7 +4,7 @@
 
        <div class="panel-group panel-group-settings" id="settings-addons" role="tablist" aria-multiselectable="true">
 {{foreach $addon_settings_forms as $addon => $addon_settings_form}}
-               <form action="settings/addon/{{$addon}}" method="post" autocomplete="off" class="panel">
+               <form action="settings/addons/{{$addon}}" method="post" autocomplete="off" class="panel">
                        <input type="hidden" name="form_security_token" value="{{$form_security_token}}">
                        {{$addon_settings_form nofilter}}
                </form>
diff --git a/view/theme/frio/templates/settings/addons/link.tpl b/view/theme/frio/templates/settings/addons/link.tpl
new file mode 100644 (file)
index 0000000..bf430db
--- /dev/null
@@ -0,0 +1 @@
+<div class="settings-block"><h3><a href="{{$href}}">{{$title}} <i class="glyphicon glyphicon-share"></i></a></h3></div>
diff --git a/view/theme/frio/templates/settings/addons/panel.tpl b/view/theme/frio/templates/settings/addons/panel.tpl
new file mode 100644 (file)
index 0000000..561d0fc
--- /dev/null
@@ -0,0 +1,36 @@
+       <div class="section-subtitle-wrapper panel-heading" role="tab" id="{{$addon}}-settings-title">
+               <h2>
+                       <button class="btn-link accordion-toggle{{if !$open}} collapsed{{/if}}" data-toggle="collapse" data-parent="#settings-addons" href="#{{$addon}}-settings-content" aria-expanded="false" aria-controls="{{$addon}}-settings-content">
+                               {{$title}}
+                       </button>
+               </h2>
+       </div>
+       <div id="{{$addon}}-settings-content" class="panel-collapse collapse{{if $open}} in{{/if}}" role="tabpanel" aria-labelledby="{{$addon}}-settings-title">
+               <div class="panel-body">
+            {{$html nofilter}}
+               </div>
+               <div class="panel-footer">
+{{if $submit}}
+    {{if $submit|is_string}}
+                       <button type="submit" name="{{$addon}}-submit" class="btn btn-primary settings-submit" value="{{$submit}}">{{$submit}}</button>
+    {{else}}
+        {{$count = 1}}
+        {{foreach $submit as $name => $label}}{{if $label}}
+            {{if $count == 1}}
+                       <button type="submit" name="{{$name}}" class="btn btn-primary settings-submit" value="{{$label}}">{{$label}}</button>
+            {{/if}}
+            {{if $count == 2}}
+                       <div class="btn-group" role="group" aria-label="...">
+            {{/if}}
+            {{if $count != 1}}
+                               <button type="submit" name="{{$name}}" class="btn btn-default settings-submit" value="{{$label}}">{{$label}}</button>
+            {{/if}}
+            {{$count = $count + 1}}
+        {{/if}}{{/foreach}}
+        {{if $submit|count > 1}}
+                       </div>
+        {{/if}}
+    {{/if}}
+{{/if}}
+               </div>
+       </div>