3 namespace Friendica\Module\Admin\Themes;
5 use Friendica\Core\Renderer;
6 use Friendica\Core\Theme;
8 use Friendica\Module\BaseAdmin;
9 use Friendica\Util\Strings;
11 class Index extends BaseAdmin
13 public static function content(array $parameters = [])
15 parent::content($parameters);
17 $allowed_themes = Theme::getAllowedList();
19 // reload active themes
20 if (!empty($_GET['action'])) {
21 parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
23 switch ($_GET['action']) {
25 $allowed_themes = array_unique($allowed_themes);
26 foreach ($allowed_themes as $theme) {
27 Theme::uninstall($theme);
28 Theme::install($theme);
30 Theme::setAllowedList($allowed_themes);
32 info('Themes reloaded');
36 $theme = $_GET['addon'] ?? '';
38 $theme = Strings::sanitizeFilePathItem($theme);
39 if (!is_dir("view/theme/$theme")) {
40 notice(DI::l10n()->t('Item not found.'));
44 if (in_array($theme, Theme::getAllowedList())) {
45 Theme::uninstall($theme);
46 info(DI::l10n()->t('Theme %s disabled.', $theme));
47 } elseif (Theme::install($theme)) {
48 info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
50 info(DI::l10n()->t('Theme %s failed to install.', $theme));
58 DI::baseUrl()->redirect('admin/themes');
62 $files = glob('view/theme/*');
63 if (is_array($files)) {
64 foreach ($files as $file) {
65 $theme = basename($file);
67 // Is there a style file?
68 $theme_files = glob('view/theme/' . $theme . '/style.*');
71 if (count($theme_files) == 0) {
75 $is_experimental = intval(file_exists($file . '/experimental'));
76 $is_supported = 1 - (intval(file_exists($file . '/unsupported')));
77 $is_allowed = intval(in_array($theme, $allowed_themes));
79 if ($is_allowed || $is_supported || DI::config()->get('system', 'show_unsupported_themes')) {
80 $themes[] = ['name' => $theme, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed];
86 foreach ($themes as $theme) {
87 $addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])];
90 $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
91 return Renderer::replaceMacros($t, [
92 '$title' => DI::l10n()->t('Administration'),
93 '$page' => DI::l10n()->t('Themes'),
94 '$submit' => DI::l10n()->t('Save Settings'),
95 '$reload' => DI::l10n()->t('Reload active themes'),
96 '$baseurl' => DI::baseUrl()->get(true),
97 '$function' => 'themes',
99 '$pcount' => count($themes),
100 '$noplugshint' => DI::l10n()->t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
101 '$experimental' => DI::l10n()->t('[Experimental]'),
102 '$unsupported' => DI::l10n()->t('[Unsupported]'),
103 '$form_security_token' => parent::getFormSecurityToken('admin_themes'),