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