3 namespace Friendica\Module\Admin\Themes;
5 use Friendica\Core\Config;
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 Index extends BaseAdminModule
15 public static function content(array $parameters = [])
17 parent::content($parameters);
21 $allowed_themes = Theme::getAllowedList();
23 // reload active themes
24 if (!empty($_GET['action'])) {
25 parent::checkFormSecurityTokenRedirectOnError($a->getBaseURL() . '/admin/themes', 'admin_themes', 't');
27 switch ($_GET['action']) {
29 $allowed_themes = array_unique($allowed_themes);
30 foreach ($allowed_themes as $theme) {
31 Theme::uninstall($theme);
32 Theme::install($theme);
34 Theme::setAllowedList($allowed_themes);
36 info('Themes reloaded');
40 $theme = $_GET['addon'] ?? '';
42 $theme = Strings::sanitizeFilePathItem($theme);
43 if (!is_dir("view/theme/$theme")) {
44 notice(L10n::t('Item not found.'));
48 if (in_array($theme, Theme::getAllowedList())) {
49 Theme::uninstall($theme);
50 info(L10n::t('Theme %s disabled.', $theme));
51 } elseif (Theme::install($theme)) {
52 info(L10n::t('Theme %s successfully enabled.', $theme));
54 info(L10n::t('Theme %s failed to install.', $theme));
62 $a->internalRedirect('admin/themes');
66 $files = glob('view/theme/*');
67 if (is_array($files)) {
68 foreach ($files as $file) {
69 $theme = basename($file);
71 // Is there a style file?
72 $theme_files = glob('view/theme/' . $theme . '/style.*');
75 if (count($theme_files) == 0) {
79 $is_experimental = intval(file_exists($file . '/experimental'));
80 $is_supported = 1 - (intval(file_exists($file . '/unsupported')));
81 $is_allowed = intval(in_array($theme, $allowed_themes));
83 if ($is_allowed || $is_supported || Config::get('system', 'show_unsupported_themes')) {
84 $themes[] = ['name' => $theme, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed];
90 foreach ($themes as $theme) {
91 $addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])];
94 $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
95 return Renderer::replaceMacros($t, [
96 '$title' => L10n::t('Administration'),
97 '$page' => L10n::t('Themes'),
98 '$submit' => L10n::t('Save Settings'),
99 '$reload' => L10n::t('Reload active themes'),
100 '$baseurl' => $a->getBaseURL(true),
101 '$function' => 'themes',
102 '$addons' => $addons,
103 '$pcount' => count($themes),
104 '$noplugshint' => L10n::t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
105 '$experimental' => L10n::t('[Experimental]'),
106 '$unsupported' => L10n::t('[Unsupported]'),
107 '$form_security_token' => parent::getFormSecurityToken('admin_themes'),