]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Embed.php
Merge pull request #8919 from annando/notice-info
[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                         if (DI::mode()->isAjax()) {
66                                 return;
67                         }
68
69                         DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
70                 }
71         }
72
73         public static function content(array $parameters = [])
74         {
75                 parent::content($parameters);
76
77                 $a = DI::app();
78
79                 if ($a->argc > 2) {
80                         // @TODO: Replace with parameter from router
81                         $theme = $a->argv[2];
82                         $theme = Strings::sanitizeFilePathItem($theme);
83                         if (!is_dir("view/theme/$theme")) {
84                                 notice(DI::l10n()->t('Unknown theme.'));
85                                 return '';
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 = theme_admin($a);
94                                 }
95                         }
96
97                         // Overrides normal theme style include to strip user param to show embedded theme settings
98                         Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
99
100                         $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
101                         return Renderer::replaceMacros($t, [
102                                 '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
103                                 '$form' => $admin_form,
104                                 '$form_security_token' => parent::getFormSecurityToken("admin_theme_settings"),
105                         ]);
106                 }
107
108                 return '';
109         }
110 }