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);
19 $allowed_themes = Theme::getAllowedList();
21 // reload active themes
22 if (!empty($_GET['action'])) {
23 parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
25 switch ($_GET['action']) {
27 $allowed_themes = array_unique($allowed_themes);
28 foreach ($allowed_themes as $theme) {
29 Theme::uninstall($theme);
30 Theme::install($theme);
32 Theme::setAllowedList($allowed_themes);
34 info('Themes reloaded');
38 $theme = $_GET['addon'] ?? '';
40 $theme = Strings::sanitizeFilePathItem($theme);
41 if (!is_dir("view/theme/$theme")) {
42 notice(L10n::t('Item not found.'));
46 if (in_array($theme, Theme::getAllowedList())) {
47 Theme::uninstall($theme);
48 info(L10n::t('Theme %s disabled.', $theme));
49 } elseif (Theme::install($theme)) {
50 info(L10n::t('Theme %s successfully enabled.', $theme));
52 info(L10n::t('Theme %s failed to install.', $theme));
60 DI::baseUrl()->redirect('admin/themes');
64 $files = glob('view/theme/*');
65 if (is_array($files)) {
66 foreach ($files as $file) {
67 $theme = basename($file);
69 // Is there a style file?
70 $theme_files = glob('view/theme/' . $theme . '/style.*');
73 if (count($theme_files) == 0) {
77 $is_experimental = intval(file_exists($file . '/experimental'));
78 $is_supported = 1 - (intval(file_exists($file . '/unsupported')));
79 $is_allowed = intval(in_array($theme, $allowed_themes));
81 if ($is_allowed || $is_supported || Config::get('system', 'show_unsupported_themes')) {
82 $themes[] = ['name' => $theme, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed];
88 foreach ($themes as $theme) {
89 $addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])];
92 $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
93 return Renderer::replaceMacros($t, [
94 '$title' => L10n::t('Administration'),
95 '$page' => L10n::t('Themes'),
96 '$submit' => L10n::t('Save Settings'),
97 '$reload' => L10n::t('Reload active themes'),
98 '$baseurl' => DI::baseUrl()->get(true),
99 '$function' => 'themes',
100 '$addons' => $addons,
101 '$pcount' => count($themes),
102 '$noplugshint' => L10n::t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
103 '$experimental' => L10n::t('[Experimental]'),
104 '$unsupported' => L10n::t('[Unsupported]'),
105 '$form_security_token' => parent::getFormSecurityToken('admin_themes'),