3 * @copyright Copyright (C) 2010-2021, the Friendica project
5 * @license GNU AGPL version 3 or any later version
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.
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.
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/>.
22 namespace Friendica\Module\Admin\Themes;
25 use Friendica\Core\L10n;
26 use Friendica\Core\Renderer;
27 use Friendica\Module\BaseAdmin;
28 use Friendica\Util\Strings;
30 class Embed extends BaseAdmin
34 /** @var App\BaseURL */
39 public function __construct(App $app, App\BaseURL $baseUrl, App\Mode $mode, L10n $l10n, array $parameters = [])
41 parent::__construct($l10n, $parameters);
44 $this->baseUrl = $baseUrl;
47 $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
48 if (is_file("view/theme/$theme/config.php")) {
49 $this->app->setCurrentTheme($theme);
53 public function post()
55 self::checkAdminAccess();
57 $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
58 if (is_file("view/theme/$theme/config.php")) {
59 require_once "view/theme/$theme/config.php";
60 if (function_exists('theme_admin_post')) {
61 self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
62 theme_admin_post($this->app);
66 if ($this->mode->isAjax()) {
70 $this->baseUrl->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
73 public function content(): string
77 $theme = Strings::sanitizeFilePathItem($this->parameters['theme']);
78 if (!is_dir("view/theme/$theme")) {
79 notice($this->t('Unknown theme.'));
84 if (is_file("view/theme/$theme/config.php")) {
85 require_once "view/theme/$theme/config.php";
87 if (function_exists('theme_admin')) {
88 $admin_form = theme_admin($this->app);
92 // Overrides normal theme style include to strip user param to show embedded theme settings
93 Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
95 $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
96 return Renderer::replaceMacros($t, [
97 '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
98 '$form' => $admin_form,
99 '$form_security_token' => self::getFormSecurityToken("admin_theme_settings"),