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