3 * @copyright Copyright (C) 2010-2022, 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
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 = [])
44 parent::__construct($session, $page, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
46 $this->database = $database;
50 protected function post(array $request = [])
52 BaseSettings::checkFormSecurityTokenRedirectOnError($this->args->getQueryString(), 'settings_addon');
54 Hook::callAll('addon_settings_post', $request);
55 $this->baseUrl->redirect($this->args->getQueryString());
58 protected function content(array $request = []): string
60 parent::content($request); // TODO: Change the autogenerated stub
62 $addon_settings_forms = [];
63 foreach ($this->database->selectToArray('hook', ['file', 'function'], ['hook' => 'addon_settings']) as $hook) {
65 Hook::callSingle($this->app, 'addon_settings', [$hook['file'], $hook['function']], $data);
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'],
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'),
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,