3 namespace Friendica\Module\Admin\Themes;
5 use Friendica\Content\Text\Markdown;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Theme;
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 $theme = Strings::sanitizeFilePathItem($theme);
25 if (is_file("view/theme/$theme/config.php")) {
26 require_once "view/theme/$theme/config.php";
28 if (function_exists('theme_admin_post')) {
33 info(L10n::t('Theme settings updated.'));
35 if (DI::mode()->isAjax()) {
39 DI::baseUrl()->redirect('admin/themes/' . $theme);
43 public static function content(array $parameters = [])
45 parent::content($parameters);
50 // @TODO: Replace with parameter from router
52 $theme = Strings::sanitizeFilePathItem($theme);
53 if (!is_dir("view/theme/$theme")) {
54 notice(L10n::t("Item not found."));
58 $isEnabled = in_array($theme, Theme::getAllowedList());
61 $action = L10n::t("Disable");
64 $action = L10n::t("Enable");
67 if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
68 parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
71 Theme::uninstall($theme);
72 info(L10n::t('Theme %s disabled.', $theme));
73 } elseif (Theme::install($theme)) {
74 info(L10n::t('Theme %s successfully enabled.', $theme));
76 info(L10n::t('Theme %s failed to install.', $theme));
79 DI::baseUrl()->redirect('admin/themes/' . $theme);
83 if (is_file("view/theme/$theme/README.md")) {
84 $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
85 } elseif (is_file("view/theme/$theme/README")) {
86 $readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
90 if (is_file("view/theme/$theme/config.php")) {
91 require_once "view/theme/$theme/config.php";
93 if (function_exists('theme_admin')) {
94 $admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
98 $screenshot = [Theme::getScreenshot($theme), L10n::t('Screenshot')];
99 if (!stristr($screenshot[0], $theme)) {
103 $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
104 return Renderer::replaceMacros($t, [
105 '$title' => L10n::t('Administration'),
106 '$page' => L10n::t('Themes'),
107 '$toggle' => L10n::t('Toggle'),
108 '$settings' => L10n::t('Settings'),
109 '$baseurl' => DI::baseUrl()->get(true),
111 '$status' => $status,
112 '$action' => $action,
113 '$info' => Theme::getInfo($theme),
114 '$function' => 'themes',
115 '$admin_form' => $admin_form,
116 '$str_author' => L10n::t('Author: '),
117 '$str_maintainer' => L10n::t('Maintainer: '),
118 '$screenshot' => $screenshot,
119 '$readme' => $readme,
121 '$form_security_token' => parent::getFormSecurityToken("admin_themes"),
125 DI::baseUrl()->redirect('admin/themes');