3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Admin\Themes;
24 use Friendica\Core\Renderer;
25 use Friendica\Core\Theme;
27 use Friendica\Module\BaseAdmin;
28 use Friendica\Util\Strings;
30 class Index extends BaseAdmin
32 public static function content(array $parameters = [])
34 parent::content($parameters);
36 $allowed_themes = Theme::getAllowedList();
38 // reload active themes
39 if (!empty($_GET['action'])) {
40 parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
42 switch ($_GET['action']) {
44 $allowed_themes = array_unique($allowed_themes);
45 foreach ($allowed_themes as $theme) {
46 Theme::uninstall($theme);
47 Theme::install($theme);
49 Theme::setAllowedList($allowed_themes);
51 info('Themes reloaded');
55 $theme = $_GET['addon'] ?? '';
57 $theme = Strings::sanitizeFilePathItem($theme);
58 if (!is_dir("view/theme/$theme")) {
59 notice(DI::l10n()->t('Item not found.'));
63 if (in_array($theme, Theme::getAllowedList())) {
64 Theme::uninstall($theme);
65 info(DI::l10n()->t('Theme %s disabled.', $theme));
66 } elseif (Theme::install($theme)) {
67 info(DI::l10n()->t('Theme %s successfully enabled.', $theme));
69 notice(DI::l10n()->t('Theme %s failed to install.', $theme));
77 DI::baseUrl()->redirect('admin/themes');
81 $files = glob('view/theme/*');
82 if (is_array($files)) {
83 foreach ($files as $file) {
84 $theme = basename($file);
86 // Is there a style file?
87 $theme_files = glob('view/theme/' . $theme . '/style.*');
90 if (count($theme_files) == 0) {
94 $is_experimental = intval(file_exists($file . '/experimental'));
95 $is_supported = 1 - (intval(file_exists($file . '/unsupported')));
96 $is_allowed = intval(in_array($theme, $allowed_themes));
98 if ($is_allowed || $is_supported || DI::config()->get('system', 'show_unsupported_themes')) {
99 $themes[] = ['name' => $theme, 'experimental' => $is_experimental, 'supported' => $is_supported, 'allowed' => $is_allowed];
105 foreach ($themes as $theme) {
106 $addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])];
109 $t = Renderer::getMarkupTemplate('admin/addons/index.tpl');
110 return Renderer::replaceMacros($t, [
111 '$title' => DI::l10n()->t('Administration'),
112 '$page' => DI::l10n()->t('Themes'),
113 '$submit' => DI::l10n()->t('Save Settings'),
114 '$reload' => DI::l10n()->t('Reload active themes'),
115 '$baseurl' => DI::baseUrl()->get(true),
116 '$function' => 'themes',
117 '$addons' => $addons,
118 '$pcount' => count($themes),
119 '$noplugshint' => DI::l10n()->t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
120 '$experimental' => DI::l10n()->t('[Experimental]'),
121 '$unsupported' => DI::l10n()->t('[Unsupported]'),
122 '$form_security_token' => parent::getFormSecurityToken('admin_themes'),