]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Index.php
Added type hints
[friendica.git] / src / Module / Admin / Themes / Index.php
1 <?php
2
3 namespace Friendica\Module\Admin\Themes;
4
5 use Friendica\Core\Config;
6 use Friendica\Core\L10n;
7 use Friendica\Core\Renderer;
8 use Friendica\Core\Theme;
9 use Friendica\DI;
10 use Friendica\Module\BaseAdminModule;
11 use Friendica\Util\Strings;
12
13 class Index extends BaseAdminModule
14 {
15         public static function content(array $parameters = [])
16         {
17                 parent::content($parameters);
18
19                 $allowed_themes = Theme::getAllowedList();
20
21                 // reload active themes
22                 if (!empty($_GET['action'])) {
23                         parent::checkFormSecurityTokenRedirectOnError(DI::baseUrl()->get() . '/admin/themes', 'admin_themes', 't');
24
25                         switch ($_GET['action']) {
26                                 case 'reload':
27                                         $allowed_themes = array_unique($allowed_themes);
28                                         foreach ($allowed_themes as $theme) {
29                                                 Theme::uninstall($theme);
30                                                 Theme::install($theme);
31                                         }
32                                         Theme::setAllowedList($allowed_themes);
33
34                                         info('Themes reloaded');
35                                         break;
36
37                                 case 'toggle' :
38                                         $theme = $_GET['addon'] ?? '';
39                                         if ($theme) {
40                                                 $theme = Strings::sanitizeFilePathItem($theme);
41                                                 if (!is_dir("view/theme/$theme")) {
42                                                         notice(L10n::t('Item not found.'));
43                                                         return '';
44                                                 }
45
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));
51                                                 } else {
52                                                         info(L10n::t('Theme %s failed to install.', $theme));
53                                                 }
54                                         }
55
56                                         break;
57
58                         }
59
60                         DI::baseUrl()->redirect('admin/themes');
61                 }
62
63                 $themes = [];
64                 $files = glob('view/theme/*');
65                 if (is_array($files)) {
66                         foreach ($files as $file) {
67                                 $theme = basename($file);
68
69                                 // Is there a style file?
70                                 $theme_files = glob('view/theme/' . $theme . '/style.*');
71
72                                 // If not then quit
73                                 if (count($theme_files) == 0) {
74                                         continue;
75                                 }
76
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));
80
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];
83                                 }
84                         }
85                 }
86
87                 $addons = [];
88                 foreach ($themes as $theme) {
89                         $addons[] = [$theme['name'], (($theme['allowed']) ? 'on' : 'off'), Theme::getInfo($theme['name'])];
90                 }
91
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'),
106                 ]);
107         }
108 }