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\Themes;
24 use Friendica\Content\Text\Markdown;
25 use Friendica\Core\Renderer;
26 use Friendica\Core\Theme;
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);
40 // @TODO: Replace with parameter from router
42 $theme = Strings::sanitizeFilePathItem($theme);
43 if (is_file("view/theme/$theme/config.php")) {
44 require_once "view/theme/$theme/config.php";
46 if (function_exists('theme_admin_post')) {
51 if (DI::mode()->isAjax()) {
55 DI::baseUrl()->redirect('admin/themes/' . $theme);
59 public static function content(array $parameters = [])
61 parent::content($parameters);
66 // @TODO: Replace with parameter from router
68 $theme = Strings::sanitizeFilePathItem($theme);
69 if (!is_dir("view/theme/$theme")) {
70 notice(DI::l10n()->t("Item not found."));
74 $isEnabled = in_array($theme, Theme::getAllowedList());
77 $action = DI::l10n()->t("Disable");
80 $action = DI::l10n()->t("Enable");
83 if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
84 parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
87 Theme::uninstall($theme);
88 info(DI::l10n()->t('Theme %s disabled.', $theme));
89 } elseif (Theme::install($theme)) {
90 info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
92 notice(DI::l10n()->t('Theme %s failed to install.', $theme));
95 DI::baseUrl()->redirect('admin/themes/' . $theme);
99 if (is_file("view/theme/$theme/README.md")) {
100 $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
101 } elseif (is_file("view/theme/$theme/README")) {
102 $readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
106 if (is_file("view/theme/$theme/config.php")) {
107 require_once "view/theme/$theme/config.php";
109 if (function_exists('theme_admin')) {
110 $admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
114 $screenshot = [Theme::getScreenshot($theme), DI::l10n()->t('Screenshot')];
115 if (!stristr($screenshot[0], $theme)) {
119 $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
120 return Renderer::replaceMacros($t, [
121 '$title' => DI::l10n()->t('Administration'),
122 '$page' => DI::l10n()->t('Themes'),
123 '$toggle' => DI::l10n()->t('Toggle'),
124 '$settings' => DI::l10n()->t('Settings'),
125 '$baseurl' => DI::baseUrl()->get(true),
127 '$status' => $status,
128 '$action' => $action,
129 '$info' => Theme::getInfo($theme),
130 '$function' => 'themes',
131 '$admin_form' => $admin_form,
132 '$str_author' => DI::l10n()->t('Author: '),
133 '$str_maintainer' => DI::l10n()->t('Maintainer: '),
134 '$screenshot' => $screenshot,
135 '$readme' => $readme,
137 '$form_security_token' => parent::getFormSecurityToken("admin_themes"),
141 DI::baseUrl()->redirect('admin/themes');