3 * @copyright Copyright (C) 2020, Friendica
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;
24 use Friendica\Core\Renderer;
26 use Friendica\Module\BaseAdmin;
27 use Friendica\Util\Strings;
29 class Embed extends BaseAdmin
31 public static function init(array $parameters = [])
33 $theme = Strings::sanitizeFilePathItem($parameters['theme']);
34 if (is_file("view/theme/$theme/config.php")) {
35 DI::app()->setCurrentTheme($theme);
39 public static function post(array $parameters = [])
41 parent::post($parameters);
43 $theme = Strings::sanitizeFilePathItem($parameters['theme']);
44 if (is_file("view/theme/$theme/config.php")) {
45 require_once "view/theme/$theme/config.php";
46 if (function_exists('theme_admin_post')) {
47 self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings');
48 theme_admin_post(DI::app());
52 if (DI::mode()->isAjax()) {
56 DI::baseUrl()->redirect('admin/themes/' . $theme . '/embed?mode=minimal');
59 public static function content(array $parameters = [])
61 parent::content($parameters);
63 $theme = Strings::sanitizeFilePathItem($parameters['theme']);
64 if (!is_dir("view/theme/$theme")) {
65 notice(DI::l10n()->t('Unknown theme.'));
70 if (is_file("view/theme/$theme/config.php")) {
71 require_once "view/theme/$theme/config.php";
73 if (function_exists('theme_admin')) {
74 $admin_form = theme_admin(DI::app());
78 // Overrides normal theme style include to strip user param to show embedded theme settings
79 Renderer::$theme['stylesheet'] = 'view/theme/' . $theme . '/style.pcss';
81 $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl');
82 return Renderer::replaceMacros($t, [
83 '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal',
84 '$form' => $admin_form,
85 '$form_security_token' => self::getFormSecurityToken("admin_theme_settings"),