3 namespace Friendica\Module\Admin\Themes;
5 use Friendica\Core\Config;
6 use Friendica\Core\Renderer;
7 use Friendica\Core\Theme;
9 use Friendica\Module\BaseAdminModule;
10 use Friendica\Util\Strings;
12 class Index extends BaseAdminModule
14 public static function content(array $parameters = [])
16 parent::content($parameters);
18 $allowed_themes = Theme::getAllowedList();
20 // reload active themes
21 if (!empty($_GET['action'])) {
22 parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
24 switch ($_GET['action']) {
26 $allowed_themes = array_unique($allowed_themes);
27 foreach ($allowed_themes as $theme) {
28 Theme::uninstall($theme);
29 Theme::install($theme);
31 Theme::setAllowedList($allowed_themes);
33 info('Themes reloaded');
37 $theme = $_GET['addon'] ?? '';
39 $theme = Strings::sanitizeFilePathItem($theme);
40 if (!is_dir("view/theme/$theme")) {
41 notice(DI::l10n()->t('Item not found.'));
45 if (in_array($theme, Theme::getAllowedList())) {
46 Theme::uninstall($theme);
47 info(DI::l10n()->t('Theme %s disabled.', $theme));
48 } elseif (Theme::install($theme)) {
49 info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
51 info(DI::l10n()->t('Theme %s failed to install.', $theme));
59 DI::baseUrl()->redirect('admin/themes');
63 $files = glob('view/theme/*');
64 if (is_array($files)) {
65 foreach ($files as $file) {
66 $theme = basename($file);
68 // Is there a style file?
69 $theme_files = glob('view/theme/' . $theme . '/style.*');
72 if (count($theme_files) == 0) {
76 $is_experimental = intval(file_exists($file . '/experimental'));
77 $is_supported = 1 - (intval(file_exists($file . '/unsupported')));
78 $is_allowed = intval(in_array($theme, $allowed_themes));
80 if ($is_allowed || $is_supported || DI::config()->get('system', 'show_unsupported_themes')) {
81 $themes[] = ['name' => $theme, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed];
87 foreach ($themes as $theme) {
88 $addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])];
91 $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
92 return Renderer::replaceMacros($t, [
93 '$title' => DI::l10n()->t('Administration'),
94 '$page' => DI::l10n()->t('Themes'),
95 '$submit' => DI::l10n()->t('Save Settings'),
96 '$reload' => DI::l10n()->t('Reload active themes'),
97 '$baseurl' => DI::baseUrl()->get(true),
98 '$function' => 'themes',
100 '$pcount' => count($themes),
101 '$noplugshint' => DI::l10n()->t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
102 '$experimental' => DI::l10n()->t('[Experimental]'),
103 '$unsupported' => DI::l10n()->t('[Unsupported]'),
104 '$form_security_token' => parent::getFormSecurityToken('admin_themes'),