]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Index.php
Merge pull request #7095 from annando/ap-connect
[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\Module\BaseAdminModule;
10 use Friendica\Util\Strings;
11
12 class Index extends BaseAdminModule
13 {
14         public static function content()
15         {
16                 parent::content();
17
18                 $a = self::getApp();
19
20                 $allowed_themes = Theme::getAllowedList();
21
22                 // reload active themes
23                 if (!empty($_GET['action'])) {
24                         parent::checkFormSecurityTokenRedirectOnError($a->getBaseURL() . '/admin/themes', 'admin_themes', 't');
25
26                         switch ($_GET['action']) {
27                                 case 'reload':
28                                         foreach ($allowed_themes as $theme) {
29                                                 Theme::uninstall($theme['name']);
30                                                 Theme::install($theme['name']);
31                                         }
32
33                                         info('Themes reloaded');
34                                         break;
35
36                                 case 'toggle' :
37                                         $theme = defaults($_GET, 'addon', '');
38                                         if ($theme) {
39                                                 $theme = Strings::sanitizeFilePathItem($theme);
40                                                 if (!is_dir("view/theme/$theme")) {
41                                                         notice(L10n::t('Item not found.'));
42                                                         return '';
43                                                 }
44
45                                                 if (in_array($theme, Theme::getAllowedList())) {
46                                                         Theme::uninstall($theme);
47                                                         info(L10n::t('Theme %s disabled.', $theme));
48                                                 } elseif (Theme::install($theme)) {
49                                                         info(L10n::t('Theme %s successfully enabled.', $theme));
50                                                 } else {
51                                                         info(L10n::t('Theme %s failed to install.', $theme));
52                                                 }
53                                         }
54
55                                         break;
56
57                         }
58
59                         $a->internalRedirect('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'               => L10n::t('Administration'),
94                         '$page'                => L10n::t('Themes'),
95                         '$submit'              => L10n::t('Save Settings'),
96                         '$reload'              => L10n::t('Reload active themes'),
97                         '$baseurl'             => $a->getBaseURL(true),
98                         '$function'            => 'themes',
99                         '$addons'              => $addons,
100                         '$pcount'              => count($themes),
101                         '$noplugshint'         => L10n::t('No themes found on the system. They should be placed in %1$s', '<code>/view/themes</code>'),
102                         '$experimental'        => L10n::t('[Experimental]'),
103                         '$unsupported'         => L10n::t('[Unsupported]'),
104                         '$form_security_token' => parent::getFormSecurityToken('admin_themes'),
105                 ]);
106         }
107 }