]> git.mxchange.org Git - friendica.git/blob - src/Module/Settings/Addons.php
Merge remote-tracking branch 'upstream/develop' into audience
[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
40         public function __construct(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 = [])
41         {
42                 parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
43
44                 $this->database = $database;
45         }
46
47         protected function post(array $request = [])
48         {
49                 BaseSettings::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings_addon');
50
51                 Hook::callAll('addon_settings_post', $request);
52                 $this->baseUrl->redirect($this->args->getQueryString());
53         }
54
55         protected function content(array $request = []): string
56         {
57                 parent::content($request); // TODO: Change the autogenerated stub
58
59                 $addon_settings_forms = [];
60                 foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) {
61                         $data = [];
62                         Hook::callSingle('addon_settings', [$hook['file'], $hook['function']], $data);
63
64                         if (!empty($data['href'])) {
65                                 $tpl                    = Renderer::getMarkupTemplate('settings/addons/link.tpl');
66                                 $addon_settings_forms[] = Renderer::replaceMacros($tpl, [
67                                         '$addon' => $data['addon'],
68                                         '$title' => $data['title'],
69                                         '$href'  => $data['href'],
70                                 ]);
71                         } elseif (!empty($data['addon'])) {
72                                 $tpl                                  = Renderer::getMarkupTemplate('settings/addons/panel.tpl');
73                                 $addon_settings_forms[$data['addon']] = Renderer::replaceMacros($tpl, [
74                                         '$addon'  => $data['addon'],
75                                         '$title'  => $data['title'],
76                                         '$open'   => ($this->parameters['addon'] ?? '') === $data['addon'],
77                                         '$html'   => $data['html'] ?? '',
78                                         '$submit' => $data['submit'] ?? $this->t('Save Settings'),
79                                 ]);
80                         }
81                 }
82
83                 $tpl = Renderer::getMarkupTemplate('settings/addons.tpl');
84                 return Renderer::replaceMacros($tpl, [
85                         '$form_security_token'           => BaseSettings::getFormSecurityToken('settings_addon'),
86                         '$title'                         => $this->t('Addon Settings'),
87                         '$no_addons_settings_configured' => $this->t('No Addon settings configured'),
88                         '$addon_settings_forms'          => $addon_settings_forms,
89                 ]);
90         }
91 }