]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Addons/Details.php
Useless info messages removed
[friendica.git] / src / Module / Admin / Addons / Details.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
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\Admin\Addons;
23
24 use Friendica\Content\Text\Markdown;
25 use Friendica\Core\Addon;
26 use Friendica\Core\Renderer;
27 use Friendica\DI;
28 use Friendica\Module\BaseAdmin;
29 use Friendica\Util\Strings;
30
31 class Details extends BaseAdmin
32 {
33         public static function post(array $parameters = [])
34         {
35                 parent::post($parameters);
36
37                 $a = DI::app();
38
39                 if ($a->argc > 2) {
40                         // @TODO: Replace with parameter from router
41                         $addon = $a->argv[2];
42                         $addon = Strings::sanitizeFilePathItem($addon);
43                         if (is_file('addon/' . $addon . '/' . $addon . '.php')) {
44                                 include_once 'addon/' . $addon . '/' . $addon . '.php';
45                                 if (function_exists($addon . '_addon_admin_post')) {
46                                         $func = $addon . '_addon_admin_post';
47                                         $func($a);
48                                 }
49
50                                 DI::baseUrl()->redirect('admin/addons/' . $addon);
51                         }
52                 }
53
54                 DI::baseUrl()->redirect('admin/addons');
55         }
56
57         public static function content(array $parameters = [])
58         {
59                 parent::content($parameters);
60
61                 $a = DI::app();
62
63                 $addons_admin = Addon::getAdminList();
64
65                 if ($a->argc > 2) {
66                         // @TODO: Replace with parameter from router
67                         $addon = $a->argv[2];
68                         $addon = Strings::sanitizeFilePathItem($addon);
69                         if (!is_file("addon/$addon/$addon.php")) {
70                                 notice(DI::l10n()->t('Addon not found.'));
71                                 Addon::uninstall($addon);
72                                 DI::baseUrl()->redirect('admin/addons');
73                         }
74
75                         if (($_GET['action'] ?? '') == 'toggle') {
76                                 parent::checkFormSecurityTokenRedirectOnError('/admin/addons', 'admin_themes', 't');
77
78                                 // Toggle addon status
79                                 if (Addon::isEnabled($addon)) {
80                                         Addon::uninstall($addon);
81                                         info(DI::l10n()->t('Addon %s disabled.', $addon));
82                                 } else {
83                                         Addon::install($addon);
84                                         info(DI::l10n()->t('Addon %s enabled.', $addon));
85                                 }
86
87                                 DI::baseUrl()->redirect('admin/addons/' . $addon);
88                         }
89
90                         // display addon details
91                         if (Addon::isEnabled($addon)) {
92                                 $status = 'on';
93                                 $action = DI::l10n()->t('Disable');
94                         } else {
95                                 $status = 'off';
96                                 $action = DI::l10n()->t('Enable');
97                         }
98
99                         $readme = null;
100                         if (is_file("addon/$addon/README.md")) {
101                                 $readme = Markdown::convert(file_get_contents("addon/$addon/README.md"), false);
102                         } elseif (is_file("addon/$addon/README")) {
103                                 $readme = '<pre>' . file_get_contents("addon/$addon/README") . '</pre>';
104                         }
105
106                         $admin_form = '';
107                         if (array_key_exists($addon, $addons_admin)) {
108                                 require_once "addon/$addon/$addon.php";
109                                 $func = $addon . '_addon_admin';
110                                 $func($a, $admin_form);
111                         }
112
113                         $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
114
115                         return Renderer::replaceMacros($t, [
116                                 '$title' => DI::l10n()->t('Administration'),
117                                 '$page' => DI::l10n()->t('Addons'),
118                                 '$toggle' => DI::l10n()->t('Toggle'),
119                                 '$settings' => DI::l10n()->t('Settings'),
120                                 '$baseurl' => DI::baseUrl()->get(true),
121
122                                 '$addon' => $addon,
123                                 '$status' => $status,
124                                 '$action' => $action,
125                                 '$info' => Addon::getInfo($addon),
126                                 '$str_author' => DI::l10n()->t('Author: '),
127                                 '$str_maintainer' => DI::l10n()->t('Maintainer: '),
128
129                                 '$admin_form' => $admin_form,
130                                 '$function' => 'addons',
131                                 '$screenshot' => '',
132                                 '$readme' => $readme,
133
134                                 '$form_security_token' => parent::getFormSecurityToken('admin_themes'),
135                         ]);
136                 }
137
138                 DI::baseUrl()->redirect('admin/addons');
139         }
140 }