]> git.mxchange.org Git - friendica.git/blob - src/Module/Admin/Themes/Embed.php
Make `BaseModule` a real entity
[friendica.git] / src / Module / Admin / Themes / Embed.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2021, the Friendica project
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\App;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Renderer;
27 use Friendica\Module\BaseAdmin;
28 use Friendica\Util\Profiler;
29 use Friendica\Util\Strings;
30 use Psr\Log\LoggerInterface;
31
32 class Embed extends BaseAdmin
33 {
34         /** @var App */
35         protected $app;
36         /** @var App\Mode */
37         protected $mode;
38
39         public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, App\Mode $mode, array $server, array $parameters = [])
40         {
41                 parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $server, $parameters);
42
43                 $this->app  = $app;
44                 $this->mode = $mode;
45
46                 $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
47                 if (is_file("view/theme/$theme/config.php")) {
48                         $this->app->setCurrentTheme($theme);
49                 }
50         }
51
52         protected function post(array $request = [], array $post = [])
53         {
54                 self::checkAdminAccess();
55
56                 $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
57                 if (is_file("view/theme/$theme/config.php")) {
58                         require_once "view/theme/$theme/config.php";
59                         if (function_exists('theme_admin_post')) {
60                                 self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
61                                 theme_admin_post($this->app);
62                         }
63                 }
64
65                 if ($this->mode->isAjax()) {
66                         return;
67                 }
68
69                 $this->baseUrl->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
70         }
71
72         protected function content(array $request = []): string
73         {
74                 parent::content();
75
76                 $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
77                 if (!is_dir("view/theme/$theme")) {
78                         notice($this->t('Unknown theme.'));
79                         return '';
80                 }
81
82                 $admin_form = '';
83                 if (is_file("view/theme/$theme/config.php")) {
84                         require_once "view/theme/$theme/config.php";
85
86                         if (function_exists('theme_admin')) {
87                                 $admin_form = theme_admin($this->app);
88                         }
89                 }
90
91                 // Overrides normal theme style include to strip user param to show embedded theme settings
92                 Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
93
94                 $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
95                 return Renderer::replaceMacros($t, [
96                         '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
97                         '$form' => $admin_form,
98                         '$form_security_token' => self::getFormSecurityToken("admin_theme_settings"),
99                 ]);
100         }
101 }