]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Embed.php
675e33c8465cfc77930cc5fb0d3584f0e461a50c
[friendica.git] / src / Module / Admin / Themes / Embed.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2020, Friendica
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module\Admin\Themes;
23
24 use Friendica\Core\Renderer;
25 use Friendica\DI;
26 use Friendica\Module\BaseAdmin;
27 use Friendica\Util\Strings;
28
29 class Embed extends BaseAdmin
30 {
31         public static function init(array $parameters = [])
32         {
33                 $a = DI::app();
34
35                 if ($a->argc > 2) {
36                         // @TODO: Replace with parameter from router
37                         $theme = $a->argv[2];
38                         $theme = Strings::sanitizeFilePathItem($theme);
39                         if (is_file("view/theme/$theme/config.php")) {
40                                 $a->setCurrentTheme($theme);
41                         }
42                 }
43         }
44
45         public static function post(array $parameters = [])
46         {
47                 parent::post($parameters);
48
49                 $a = DI::app();
50
51                 if ($a->argc > 2) {
52                         // @TODO: Replace with parameter from router
53                         $theme = $a->argv[2];
54                         $theme = Strings::sanitizeFilePathItem($theme);
55                         if (is_file("view/theme/$theme/config.php")) {
56                                 self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
57
58                                 require_once "view/theme/$theme/config.php";
59
60                                 if (function_exists('theme_admin_post')) {
61                                         theme_admin_post($a);
62                                 }
63                         }
64
65                         info(DI::l10n()->t('Theme settings updated.'));
66
67                         if (DI::mode()->isAjax()) {
68                                 return;
69                         }
70
71                         DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
72                 }
73         }
74
75         public static function content(array $parameters = [])
76         {
77                 parent::content($parameters);
78
79                 $a = DI::app();
80
81                 if ($a->argc > 2) {
82                         // @TODO: Replace with parameter from router
83                         $theme = $a->argv[2];
84                         $theme = Strings::sanitizeFilePathItem($theme);
85                         if (!is_dir("view/theme/$theme")) {
86                                 notice(DI::l10n()->t('Unknown theme.'));
87                                 return '';
88                         }
89
90                         $admin_form = '';
91                         if (is_file("view/theme/$theme/config.php")) {
92                                 require_once "view/theme/$theme/config.php";
93
94                                 if (function_exists('theme_admin')) {
95                                         $admin_form = theme_admin($a);
96                                 }
97                         }
98
99                         // Overrides normal theme style include to strip user param to show embedded theme settings
100                         Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
101
102                         $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
103                         return Renderer::replaceMacros($t, [
104                                 '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
105                                 '$form' => $admin_form,
106                                 '$form_security_token' => parent::getFormSecurityToken("admin_theme_settings"),
107                         ]);
108                 }
109
110                 return '';
111         }
112 }