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