diff --git a/src/App/Router.php b/src/App/Router.php index 0fbb78b8b..649d347bb 100644 --- a/src/App/Router.php +++ b/src/App/Router.php @@ -133,6 +133,7 @@ class Router $collector->addRoute(['GET'] , '/queue[/deferred]' , Module\Admin\Queue::class); $collector->addRoute(['GET', 'POST'], '/themes' , Module\Admin\Themes\Index::class); + $collector->addRoute(['GET', 'POST'], '/themes/{theme}/embed' , Module\Admin\Themes\Embed::class); $collector->addRoute(['GET', 'POST'], '/tos' , Module\Admin\Tos::class); diff --git a/src/Module/Admin/Themes/Embed.php b/src/Module/Admin/Themes/Embed.php new file mode 100644 index 000000000..0a309e23c --- /dev/null +++ b/src/Module/Admin/Themes/Embed.php @@ -0,0 +1,92 @@ +argc > 2) { + // @TODO: Replace with parameter from router + $theme = $a->argv[2]; + $theme = Strings::sanitizeFilePathItem($theme); + if (is_file("view/theme/$theme/config.php")) { + $a->setCurrentTheme($theme); + } + } + } + + public static function post() + { + parent::post(); + + $a = self::getApp(); + + if ($a->argc > 2) { + // @TODO: Replace with parameter from router + $theme = $a->argv[2]; + $theme = Strings::sanitizeFilePathItem($theme); + if (is_file("view/theme/$theme/config.php")) { + self::checkFormSecurityTokenRedirectOnError('/admin/themes/' . $theme . '/embed?mode=minimal', 'admin_theme_settings'); + + require_once "view/theme/$theme/config.php"; + + if (function_exists('theme_admin_post')) { + theme_admin_post($a); + } + } + + info(L10n::t('Theme settings updated.')); + + if ($a->isAjax()) { + return; + } + + $a->internalRedirect('admin/themes/' . $theme . '/embed?mode=minimal'); + } + } + + public static function content() + { + parent::content(); + + $a = self::getApp(); + + if ($a->argc > 2) { + // @TODO: Replace with parameter from router + $theme = $a->argv[2]; + $theme = Strings::sanitizeFilePathItem($theme); + if (!is_dir("view/theme/$theme")) { + notice(L10n::t('Unknown theme.')); + return ''; + } + + $admin_form = ''; + if (is_file("view/theme/$theme/config.php")) { + require_once "view/theme/$theme/config.php"; + + if (function_exists('theme_admin')) { + $admin_form = theme_admin($a); + } + } + + $t = Renderer::getMarkupTemplate('admin/addons/embed.tpl'); + return Renderer::replaceMacros($t, [ + '$action' => '/admin/themes/' . $theme . '/embed?mode=minimal', + '$form' => $admin_form, + '$form_security_token' => parent::getFormSecurityToken("admin_theme_settings"), + ]); + } + + return ''; + } +} \ No newline at end of file diff --git a/view/templates/admin/addons/embed.tpl b/view/templates/admin/addons/embed.tpl new file mode 100644 index 000000000..71fb12d43 --- /dev/null +++ b/view/templates/admin/addons/embed.tpl @@ -0,0 +1,5 @@ + +