3 namespace Friendica\Module\Admin\Addons;
5 use Friendica\Content\Text\Markdown;
6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Renderer;
10 use Friendica\Module\BaseAdminModule;
11 use Friendica\Util\Strings;
13 class Details extends BaseAdminModule
15 public static function post(array $parameters = [])
17 parent::post($parameters);
22 // @TODO: Replace with parameter from router
24 $addon = Strings::sanitizeFilePathItem($addon);
25 if (is_file('addon/' . $addon . '/' . $addon . '.php')) {
26 include_once 'addon/' . $addon . '/' . $addon . '.php';
27 if (function_exists($addon . '_addon_admin_post')) {
28 $func = $addon . '_addon_admin_post';
32 DI::baseUrl()->redirect('admin/addons/' . $addon);
36 DI::baseUrl()->redirect('admin/addons');
39 public static function content(array $parameters = [])
41 parent::content($parameters);
45 $addons_admin = Addon::getAdminList();
48 // @TODO: Replace with parameter from router
50 $addon = Strings::sanitizeFilePathItem($addon);
51 if (!is_file("addon/$addon/$addon.php")) {
52 notice(L10n::t('Addon not found.'));
53 Addon::uninstall($addon);
54 DI::baseUrl()->redirect('admin/addons');
57 if (($_GET['action'] ?? '') == 'toggle') {
58 parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't');
60 // Toggle addon status
61 if (Addon::isEnabled($addon)) {
62 Addon::uninstall($addon);
63 info(L10n::t('Addon %s disabled.', $addon));
65 Addon::install($addon);
66 info(L10n::t('Addon %s enabled.', $addon));
69 Addon::saveEnabledList();
71 DI::baseUrl()->redirect('admin/addons/' . $addon);
74 // display addon details
75 if (Addon::isEnabled($addon)) {
77 $action = L10n::t('Disable');
80 $action = L10n::t('Enable');
84 if (is_file("addon/$addon/README.md")) {
85 $readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false);
86 } elseif (is_file("addon/$addon/README")) {
87 $readme = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
91 if (array_key_exists($addon, $addons_admin)) {
92 require_once "addon/$addon/$addon.php";
93 $func = $addon . '_addon_admin';
94 $func($a, $admin_form);
97 $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
99 return Renderer::replaceMacros($t, [
100 '$title' => L10n::t('Administration'),
101 '$page' => L10n::t('Addons'),
102 '$toggle' => L10n::t('Toggle'),
103 '$settings' => L10n::t('Settings'),
104 '$baseurl' => $a->getBaseURL(true),
107 '$status' => $status,
108 '$action' => $action,
109 '$info' => Addon::getInfo($addon),
110 '$str_author' => L10n::t('Author: '),
111 '$str_maintainer' => L10n::t('Maintainer: '),
113 '$admin_form' => $admin_form,
114 '$function' => 'addons',
116 '$readme' => $readme,
118 '$form_security_token' => parent::getFormSecurityToken('admin_themes'),
122 DI::baseUrl()->redirect('admin/addons');