]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Details.php
Added parameters
[friendica.git] / src / Module / Admin / Themes / Details.php
1 <?php
2
3 namespace Friendica\Module\Admin\Themes;
4
5 use Friendica\Content\Text\Markdown;
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 Details extends BaseAdminModule
13 {
14         public static function post($parameters)
15         {
16                 parent::post($parameters);
17
18                 $a = self::getApp();
19
20                 if ($a->argc > 2) {
21                         // @TODO: Replace with parameter from router
22                         $theme = $a->argv[2];
23                         $theme = Strings::sanitizeFilePathItem($theme);
24                         if (is_file("view/theme/$theme/config.php")) {
25                                 require_once "view/theme/$theme/config.php";
26
27                                 if (function_exists('theme_admin_post')) {
28                                         theme_admin_post($a);
29                                 }
30                         }
31
32                         info(L10n::t('Theme settings updated.'));
33
34                         if ($a->isAjax()) {
35                                 return;
36                         }
37
38                         $a->internalRedirect('admin/themes/' . $theme);
39                 }
40         }
41
42         public static function content($parameters)
43         {
44                 parent::content($parameters);
45
46                 $a = self::getApp();
47
48                 if ($a->argc > 2) {
49                         // @TODO: Replace with parameter from router
50                         $theme = $a->argv[2];
51                         $theme = Strings::sanitizeFilePathItem($theme);
52                         if (!is_dir("view/theme/$theme")) {
53                                 notice(L10n::t("Item not found."));
54                                 return '';
55                         }
56
57                         $isEnabled = in_array($theme, Theme::getAllowedList());
58                         if ($isEnabled) {
59                                 $status = "on";
60                                 $action = L10n::t("Disable");
61                         } else {
62                                 $status = "off";
63                                 $action = L10n::t("Enable");
64                         }
65
66                         if (!empty($_GET['action']) && $_GET['action'] == 'toggle') {
67                                 parent::checkFormSecurityTokenRedirectOnError('/admin/themes', 'admin_themes', 't');
68
69                                 if ($isEnabled) {
70                                         Theme::uninstall($theme);
71                                         info(L10n::t('Theme %s disabled.', $theme));
72                                 } elseif (Theme::install($theme)) {
73                                         info(L10n::t('Theme %s successfully enabled.', $theme));
74                                 } else {
75                                         info(L10n::t('Theme %s failed to install.', $theme));
76                                 }
77
78                                 $a->internalRedirect('admin/themes/' . $theme);
79                         }
80
81                         $readme = null;
82                         if (is_file("view/theme/$theme/README.md")) {
83                                 $readme = Markdown::convert(file_get_contents("view/theme/$theme/README.md"), false);
84                         } elseif (is_file("view/theme/$theme/README")) {
85                                 $readme = "<pre>" . file_get_contents("view/theme/$theme/README") . "</pre>";
86                         }
87
88                         $admin_form = '';
89                         if (is_file("view/theme/$theme/config.php")) {
90                                 require_once "view/theme/$theme/config.php";
91
92                                 if (function_exists('theme_admin')) {
93                                         $admin_form = '<iframe onload="resizeIframe(this);" src="/admin/themes/' . $theme . '/embed?mode=minimal" width="100%" height="600px" frameborder="no"></iframe>';
94                                 }
95                         }
96
97                         $screenshot = [Theme::getScreenshot($theme), L10n::t('Screenshot')];
98                         if (!stristr($screenshot[0], $theme)) {
99                                 $screenshot = null;
100                         }
101
102                         $t = Renderer::getMarkupTemplate('admin/addons/details.tpl');
103                         return Renderer::replaceMacros($t, [
104                                 '$title' => L10n::t('Administration'),
105                                 '$page' => L10n::t('Themes'),
106                                 '$toggle' => L10n::t('Toggle'),
107                                 '$settings' => L10n::t('Settings'),
108                                 '$baseurl' => $a->getBaseURL(true),
109                                 '$addon' => $theme,
110                                 '$status' => $status,
111                                 '$action' => $action,
112                                 '$info' => Theme::getInfo($theme),
113                                 '$function' => 'themes',
114                                 '$admin_form' => $admin_form,
115                                 '$str_author' => L10n::t('Author: '),
116                                 '$str_maintainer' => L10n::t('Maintainer: '),
117                                 '$screenshot' => $screenshot,
118                                 '$readme' => $readme,
119
120                                 '$form_security_token' => parent::getFormSecurityToken("admin_themes"),
121                         ]);
122                 }
123
124                 $a->internalRedirect('admin/themes');
125         }
126 }