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;
9 use Friendica\Module\BaseAdminModule;
10 use Friendica\Util\Strings;
12 class Details extends BaseAdminModule
14 public static function post()
21 // @TODO: Replace with parameter from router
23 $theme = Strings::sanitizeFilePathItem($theme);
24 if (is_file("view/theme/$theme/config.php")) {
25 require_once "view/theme/$theme/config.php";
27 if (function_exists('theme_admin_post')) {
32 info(L10n::t('Theme settings updated.'));
38 $a->internalRedirect('admin/themes/' . $theme);
42 public static function content()
49 // @TODO: Replace with parameter from router
51 $theme = Strings::sanitizeFilePathItem($theme);
52 if (!is_dir("view/theme/$theme")) {
53 notice(L10n::t("Item not found."));
57 $isEnabled = in_array($theme, Theme::getAllowedList());
60 $action = L10n::t("Disable");
63 $action = L10n::t("Enable");
66 if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
67 parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
70 Theme::uninstall($theme);
71 info(L10n::t('Theme %s disabled.', $theme));
72 } elseif (Theme::install($theme)) {
73 info(L10n::t('Theme %s successfully enabled.', $theme));
75 info(L10n::t('Theme %s failed to install.', $theme));
78 $a->internalRedirect('admin/themes/' . $theme);
82 if (is_file("view/theme/$theme/README.md")) {
83 $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
84 } elseif (is_file("view/theme/$theme/README")) {
85 $readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
89 if (is_file("view/theme/$theme/config.php")) {
90 require_once "view/theme/$theme/config.php";
92 if (function_exists('theme_admin')) {
93 $admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
97 $screenshot = [Theme::getScreenshot($theme), L10n::t('Screenshot')];
98 if (!stristr($screenshot[0], $theme)) {
102 $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
103 return Renderer::replaceMacros($t, [
104 '$title' => L10n::t('Administration'),
105 '$page' => L10n::t('Themes'),
106 '$toggle' => L10n::t('Toggle'),
107 '$settings' => L10n::t('Settings'),
108 '$baseurl' => $a->getBaseURL(true),
110 '$status' => $status,
111 '$action' => $action,
112 '$info' => Theme::getInfo($theme),
113 '$function' => 'themes',
114 '$admin_form' => $admin_form,
115 '$str_author' => L10n::t('Author: '),
116 '$str_maintainer' => L10n::t('Maintainer: '),
117 '$screenshot' => $screenshot,
118 '$readme' => $readme,
120 '$form_security_token' => parent::getFormSecurityToken("admin_themes"),
124 $a->internalRedirect('admin/themes');