]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Details.php
Merge pull request #8277 from MrPetovan/task/8251-use-about-for-pdesc
[friendica.git] / src / Module / Admin / Themes / 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\Themes;
23
24 use Friendica\Content\Text\Markdown;
25 use Friendica\Core\Renderer;
26 use Friendica\Core\Theme;
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                         $theme = $a->argv[2];
42                         $theme = Strings::sanitizeFilePathItem($theme);
43                         if (is_file("view/theme/$theme/config.php")) {
44                                 require_once "view/theme/$theme/config.php";
45
46                                 if (function_exists('theme_admin_post')) {
47                                         theme_admin_post($a);
48                                 }
49                         }
50
51                         info(DI::l10n()->t('Theme settings updated.'));
52
53                         if (DI::mode()->isAjax()) {
54                                 return;
55                         }
56
57                         DI::baseUrl()->redirect('admin/themes/' . $theme);
58                 }
59         }
60
61         public static function content(array $parameters = [])
62         {
63                 parent::content($parameters);
64
65                 $a = DI::app();
66
67                 if ($a->argc > 2) {
68                         // @TODO: Replace with parameter from router
69                         $theme = $a->argv[2];
70                         $theme = Strings::sanitizeFilePathItem($theme);
71                         if (!is_dir("view/theme/$theme")) {
72                                 notice(DI::l10n()->t("Item not found."));
73                                 return '';
74                         }
75
76                         $isEnabled = in_array($theme, Theme::getAllowedList());
77                         if ($isEnabled) {
78                                 $status = "on";
79                                 $action = DI::l10n()->t("Disable");
80                         } else {
81                                 $status = "off";
82                                 $action = DI::l10n()->t("Enable");
83                         }
84
85                         if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
86                                 parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
87
88                                 if ($isEnabled) {
89                                         Theme::uninstall($theme);
90                                         info(DI::l10n()->t('Theme %s disabled.', $theme));
91                                 } elseif (Theme::install($theme)) {
92                                         info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
93                                 } else {
94                                         info(DI::l10n()->t('Theme %s failed to install.', $theme));
95                                 }
96
97                                 DI::baseUrl()->redirect('admin/themes/' . $theme);
98                         }
99
100                         $readme = null;
101                         if (is_file("view/theme/$theme/README.md")) {
102                                 $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
103                         } elseif (is_file("view/theme/$theme/README")) {
104                                 $readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
105                         }
106
107                         $admin_form = '';
108                         if (is_file("view/theme/$theme/config.php")) {
109                                 require_once "view/theme/$theme/config.php";
110
111                                 if (function_exists('theme_admin')) {
112                                         $admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
113                                 }
114                         }
115
116                         $screenshot = [Theme::getScreenshot($theme), DI::l10n()->t('Screenshot')];
117                         if (!stristr($screenshot[0], $theme)) {
118                                 $screenshot = null;
119                         }
120
121                         $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
122                         return Renderer::replaceMacros($t, [
123                                 '$title' => DI::l10n()->t('Administration'),
124                                 '$page' => DI::l10n()->t('Themes'),
125                                 '$toggle' => DI::l10n()->t('Toggle'),
126                                 '$settings' => DI::l10n()->t('Settings'),
127                                 '$baseurl' => DI::baseUrl()->get(true),
128                                 '$addon' => $theme,
129                                 '$status' => $status,
130                                 '$action' => $action,
131                                 '$info' => Theme::getInfo($theme),
132                                 '$function' => 'themes',
133                                 '$admin_form' => $admin_form,
134                                 '$str_author' => DI::l10n()->t('Author: '),
135                                 '$str_maintainer' => DI::l10n()->t('Maintainer: '),
136                                 '$screenshot' => $screenshot,
137                                 '$readme' => $readme,
138
139                                 '$form_security_token' => parent::getFormSecurityToken("admin_themes"),
140                         ]);
141                 }
142
143                 DI::baseUrl()->redirect('admin/themes');
144         }
145 }