]> git.mxchange.org Git - friendica.git/blob - src/Module/Settings/Addons.php
ac2d188c0a5bae2bb0cbebdf10e9455b6ca0cae9
[friendica.git] / src / Module / Settings / Addons.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Settings;
23
24 use Friendica\App;
25 use Friendica\Core\Hook;
26 use Friendica\Core\L10n;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\Session\Capability\IHandleUserSessions;
29 use Friendica\Database\Database;
30 use Friendica\Module\BaseSettings;
31 use Friendica\Module\Response;
32 use Friendica\Util\Profiler;
33 use Psr\Log\LoggerInterface;
34
35 class Addons extends BaseSettings
36 {
37         /** @var Database */
38         private $database;
39         /** @var App */
40         private $app;
41
42         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 = [])
43         {
44                 parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
45
46                 $this->database = $database;
47                 $this->app      = $app;
48         }
49
50         protected function post(array $request = [])
51         {
52                 BaseSettings::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings_addon');
53
54                 Hook::callAll('addon_settings_post', $request);
55                 $this->baseUrl->redirect($this->args->getQueryString());
56         }
57
58         protected function content(array $request = []): string
59         {
60                 parent::content($request); // TODO: Change the autogenerated stub
61
62                 $addon_settings_forms = [];
63                 foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) {
64                         $data = [];
65                         Hook::callSingle($this->app, 'addon_settings', [$hook['file'], $hook['function']], $data);
66
67                         if (!empty($data['href'])) {
68                                 $tpl                    = Renderer::getMarkupTemplate('settings/addons/link.tpl');
69                                 $addon_settings_forms[] = Renderer::replaceMacros($tpl, [
70                                         '$addon' => $data['addon'],
71                                         '$title' => $data['title'],
72                                         '$href'  => $data['href'],
73                                 ]);
74                         } elseif (!empty($data['addon'])) {
75                                 $tpl                                  = Renderer::getMarkupTemplate('settings/addons/panel.tpl');
76                                 $addon_settings_forms[$data['addon']] = Renderer::replaceMacros($tpl, [
77                                         '$addon'  => $data['addon'],
78                                         '$title'  => $data['title'],
79                                         '$open'   => ($this->parameters['addon'] ?? '') === $data['addon'],
80                                         '$html'   => $data['html'] ?? '',
81                                         '$submit' => $data['submit'] ?? $this->t('Save Settings'),
82                                 ]);
83                         }
84                 }
85
86                 $tpl = Renderer::getMarkupTemplate('settings/addons.tpl');
87                 return Renderer::replaceMacros($tpl, [
88                         '$form_security_token'           => BaseSettings::getFormSecurityToken('settings_addon'),
89                         '$title'                         => $this->t('Addon Settings'),
90                         '$no_addons_settings_configured' => $this->t('No Addon settings configured'),
91                         '$addon_settings_forms'          => $addon_settings_forms,
92                 ]);
93         }
94 }