]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Embed.php
fc0d3301bff06a89062dd3260569cb9d115b8e97
[friendica.git] / src / Module / Admin / Themes / Embed.php
1 <?php
2
3 namespace Friendica\Module\Admin\Themes;
4
5 use Friendica\Core\L10n;
6 use Friendica\Core\Renderer;
7 use Friendica\DI;
8 use Friendica\Module\BaseAdminModule;
9 use Friendica\Util\Strings;
10
11 class Embed extends BaseAdminModule
12 {
13         public static function init(array $parameters = [])
14         {
15                 $a = DI::app();
16
17                 if ($a->argc > 2) {
18                         // @TODO: Replace with parameter from router
19                         $theme = $a->argv[2];
20                         $theme = Strings::sanitizeFilePathItem($theme);
21                         if (is_file("view/theme/$theme/config.php")) {
22                                 $a->setCurrentTheme($theme);
23                         }
24                 }
25         }
26
27         public static function post(array $parameters = [])
28         {
29                 parent::post($parameters);
30
31                 $a = DI::app();
32
33                 if ($a->argc > 2) {
34                         // @TODO: Replace with parameter from router
35                         $theme = $a->argv[2];
36                         $theme = Strings::sanitizeFilePathItem($theme);
37                         if (is_file("view/theme/$theme/config.php")) {
38                                 self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
39
40                                 require_once "view/theme/$theme/config.php";
41
42                                 if (function_exists('theme_admin_post')) {
43                                         theme_admin_post($a);
44                                 }
45                         }
46
47                         info(L10n::t('Theme settings updated.'));
48
49                         if (DI::mode()->isAjax()) {
50                                 return;
51                         }
52
53                         DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
54                 }
55         }
56
57         public static function content(array $parameters = [])
58         {
59                 parent::content($parameters);
60
61                 $a = DI::app();
62
63                 if ($a->argc > 2) {
64                         // @TODO: Replace with parameter from router
65                         $theme = $a->argv[2];
66                         $theme = Strings::sanitizeFilePathItem($theme);
67                         if (!is_dir("view/theme/$theme")) {
68                                 notice(L10n::t('Unknown theme.'));
69                                 return '';
70                         }
71
72                         $admin_form = '';
73                         if (is_file("view/theme/$theme/config.php")) {
74                                 require_once "view/theme/$theme/config.php";
75
76                                 if (function_exists('theme_admin')) {
77                                         $admin_form = theme_admin($a);
78                                 }
79                         }
80
81                         // Overrides normal theme style include to strip user param to show embedded theme settings
82                         Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
83
84                         $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
85                         return Renderer::replaceMacros($t, [
86                                 '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
87                                 '$form' => $admin_form,
88                                 '$form_security_token' => parent::getFormSecurityToken("admin_theme_settings"),
89                         ]);
90                 }
91
92                 return '';
93         }
94 }