3 * @copyright Copyright (C) 2020, Friendica
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\Admin\Addons;
24 use Friendica\Content\Text\Markdown;
25 use Friendica\Core\Addon;
26 use Friendica\Core\Renderer;
28 use Friendica\Module\BaseAdmin;
29 use Friendica\Util\Strings;
31 class Details extends BaseAdmin
33 public static function post(array $parameters = [])
35 parent::post($parameters);
37 $addon = Strings::sanitizeFilePathItem($parameters['addon']);
39 $redirect = 'admin/addons/' . $addon;
41 if (is_file('addon/' . $addon . '/' . $addon . '.php')) {
42 include_once 'addon/' . $addon . '/' . $addon . '.php';
44 if (function_exists($addon . '_addon_admin_post')) {
45 $func = $addon . '_addon_admin_post';
50 DI::baseUrl()->redirect($redirect);
53 public static function content(array $parameters = [])
55 parent::content($parameters);
59 $addons_admin = Addon::getAdminList();
61 $addon = Strings::sanitizeFilePathItem($parameters['addon']);
62 if (!is_file("addon/$addon/$addon.php")) {
63 notice(DI::l10n()->t('Addon not found.'));
64 Addon::uninstall($addon);
65 DI::baseUrl()->redirect('admin/addons');
68 if (($_GET['action'] ?? '') == 'toggle') {
69 self::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_addons', 't');
71 // Toggle addon status
72 if (Addon::isEnabled($addon)) {
73 Addon::uninstall($addon);
74 info(DI::l10n()->t('Addon %s disabled.', $addon));
76 Addon::install($addon);
77 info(DI::l10n()->t('Addon %s enabled.', $addon));
80 DI::baseUrl()->redirect('admin/addons/' . $addon);
83 // display addon details
84 if (Addon::isEnabled($addon)) {
86 $action = DI::l10n()->t('Disable');
89 $action = DI::l10n()->t('Enable');
93 if (is_file("addon/$addon/README.md")) {
94 $readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false);
95 } elseif (is_file("addon/$addon/README")) {
96 $readme = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
100 if (array_key_exists($addon, $addons_admin)) {
101 require_once "addon/$addon/$addon.php";
102 $func = $addon . '_addon_admin';
103 $func($a, $admin_form);
106 $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
108 return Renderer::replaceMacros($t, [
109 '$title' => DI::l10n()->t('Administration'),
110 '$page' => DI::l10n()->t('Addons'),
111 '$toggle' => DI::l10n()->t('Toggle'),
112 '$settings' => DI::l10n()->t('Settings'),
113 '$baseurl' => DI::baseUrl()->get(true),
116 '$status' => $status,
117 '$action' => $action,
118 '$info' => Addon::getInfo($addon),
119 '$str_author' => DI::l10n()->t('Author: '),
120 '$str_maintainer' => DI::l10n()->t('Maintainer: '),
122 '$admin_form' => $admin_form,
123 '$function' => 'addons',
125 '$readme' => $readme,
127 '$form_security_token' => self::getFormSecurityToken('admin_addons'),