3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module\Settings;
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;
35 class Addons extends BaseSettings
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 = [])
42 parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
44 $this->database = $database;
47 protected function post(array $request = [])
49 BaseSettings::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings_addon');
51 Hook::callAll('addon_settings_post', $request);
52 $this->baseUrl->redirect($this->args->getQueryString());
55 protected function content(array $request = []): string
57 parent::content($request); // TODO: Change the autogenerated stub
59 $addon_settings_forms = [];
60 foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) {
62 Hook::callSingle('addon_settings', [$hook['file'], $hook['function']], $data);
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'],
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'),
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,