From a5da0fd98fb53ebf54b2898ce82c11ff4f6fb7e7 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 25 Apr 2019 22:20:20 -0400 Subject: [PATCH] Add admin/themes/{theme}/embed module - This module allows editing the site settings for a theme with a different user theme --- src/App/Router.php | 1 + src/Module/Admin/Themes/Embed.php | 92 +++++++++++++++++++++++++++ view/templates/admin/addons/embed.tpl | 5 ++ 3 files changed, 98 insertions(+) create mode 100644 src/Module/Admin/Themes/Embed.php create mode 100644 view/templates/admin/addons/embed.tpl diff --git a/src/App/Router.php b/src/App/Router.php index 0fbb78b8bc..649d347bb9 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 0000000000..0a309e23ce --- /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 0000000000..71fb12d43c --- /dev/null +++ b/view/templates/admin/addons/embed.tpl @@ -0,0 +1,5 @@ + +
+ + {{$form nofilter}} +