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