diff --git a/site/plugins/admin/app/Controllers/ThemesController.php b/site/plugins/admin/app/Controllers/ThemesController.php index f75a8413..9d037c41 100644 --- a/site/plugins/admin/app/Controllers/ThemesController.php +++ b/site/plugins/admin/app/Controllers/ThemesController.php @@ -99,4 +99,153 @@ class ThemesController extends Controller // Redirect to themes index page return $response->withRedirect($this->router->pathFor('admin.themes.index')); } + + /** + * Theme information + * + * @param Request $request PSR7 request + * @param Response $response PSR7 response + */ + public function information(Request $request, Response $response) : Response + { + // Get Theme ID + $id = $request->getQueryParams()['id']; + + // Init theme configs + $theme = []; + $theme_manifest = []; + $default_theme_manifest = []; + $site_theme_manifest = []; + + $default_theme_manifest_file = PATH['themes'] . '/' . $id . '/theme.yaml'; + $site_theme_manifest_file = PATH['config']['site'] . '/themes/' . $id . '/theme.yaml'; + + if (Filesystem::has($default_theme_manifest_file)) { + $default_theme_manifest_file_content = Filesystem::read($default_theme_manifest_file); + $default_theme_manifest = $this->parser->decode($default_theme_manifest_file_content, 'yaml'); + } + + if (Filesystem::has($site_theme_manifest_file)) { + $site_theme_manifest_file_content = Filesystem::read($site_theme_manifest_file); + $site_theme_manifest = $this->parser->decode($site_theme_manifest_file_content, 'yaml'); + } + + $theme[$id]['manifest'] = array_merge( + array_replace_recursive($default_theme_manifest, $site_theme_manifest) + ); + + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/themes/information.html', + [ + 'menu_item' => 'themes', + 'id' => $id, + 'theme_manifest' => $theme[$id]['manifest'], + 'links' => [ + 'themes' => [ + 'link' => $this->router->pathFor('admin.themes.index'), + 'title' => __('admin_themes'), + 'attributes' => ['class' => 'navbar-item'], + ], + 'themes_information' => [ + 'link' => $this->router->pathFor('admin.themes.information') . '?id=' . $request->getQueryParams()['id'], + 'title' => __('admin_information'), + 'attributes' => ['class' => 'navbar-item active'], + ], + ], + ] + ); + } + + /** + * Theme settings + * + * @param Request $request PSR7 request + * @param Response $response PSR7 response + */ + public function settings(Request $request, Response $response) : Response + { + // Get Theme ID + $id = $request->getQueryParams()['id']; + + // Init theme configs + $theme = []; + $theme_settings = []; + $default_theme_settings = []; + $site_theme_settings = []; + + $default_theme_settings_file = PATH['themes'] . '/' . $id . '/settings.yaml'; + $site_theme_settings_file = PATH['config']['site'] . '/themes/' . $id . '/settings.yaml'; + + if (Filesystem::has($default_theme_settings_file)) { + $default_theme_settings_file_content = Filesystem::read($default_theme_settings_file); + $default_theme_settings = $this->parser->decode($default_theme_settings_file_content, 'yaml'); + } + + if (Filesystem::has($site_theme_settings_file)) { + $site_theme_settings_file_content = Filesystem::read($site_theme_settings_file); + $site_theme_settings = $this->parser->decode($site_theme_settings_file_content, 'yaml'); + } + + $theme[$id]['settings'] = array_merge( + array_replace_recursive($default_theme_settings, $site_theme_settings) + ); + + return $this->view->render( + $response, + 'plugins/admin/views/templates/extends/themes/settings.html', + [ + 'menu_item' => 'themes', + 'id' => $id, + 'theme_settings' => $this->parser->encode($theme[$id]['settings'], 'yaml'), + 'links' => [ + 'themes' => [ + 'link' => $this->router->pathFor('admin.themes.index'), + 'title' => __('admin_themes'), + 'attributes' => ['class' => 'navbar-item'], + ], + 'themes_settings' => [ + 'link' => $this->router->pathFor('admin.themes.settings') . '?id=' . $request->getQueryParams()['id'], + 'title' => __('admin_settings'), + 'attributes' => ['class' => 'navbar-item active'], + ], + ], + 'buttons' => [ + 'save_theme_settings' => [ + 'link' => 'javascript:;', + 'title' => __('admin_save'), + 'attributes' => ['class' => 'js-save-form-submit float-right btn'], + ], + ], + ] + ); + } + + /** + * Theme settings process + * + * @param Request $request PSR7 request + * @param Response $response PSR7 response + */ + public function settingsProcess(Request $request, Response $response) : Response + { + $data = $request->getParsedBody(); + + $id = $data['id']; + $data = $data['data']; + + $site_theme_settings_dir = PATH['config']['site'] . '/themes/' . $id; + $site_theme_settings_file = PATH['config']['site'] . '/themes/' . $id . '/settings.yaml'; + + if (Filesystem::has($site_theme_settings_file)) { + Filesystem::write($site_theme_settings_file, $data); + $this->flash->addMessage('success', __('admin_message_theme_settings_saved')); + } else { + ! Filesystem::has($site_theme_settings_dir) and Filesystem::createDir($site_theme_settings_dir); + Filesystem::write($site_theme_settings_file, $data); + $this->flash->addMessage('success', __('admin_message_theme_settings_saved')); + } + + return $response->withRedirect($this->router->pathFor('admin.themes.settings') . '?id=' . $id); + } } diff --git a/site/plugins/admin/lang/en_US.yaml b/site/plugins/admin/lang/en_US.yaml index 67d685b8..bee44f03 100755 --- a/site/plugins/admin/lang/en_US.yaml +++ b/site/plugins/admin/lang/en_US.yaml @@ -266,6 +266,8 @@ admin_menu: "Menu" admin_seo: "Seo" admin_main: "Main" admin_you_have_no_plugins: "You have no plugins" +admin_you_have_no_themes: "You have no themes" +admin_message_theme_settings_saved: "Theme settings saved" admin_help_text_for_settings_site_title_label: "Title for your site." admin_help_text_for_settings_site_robots_label: "Robots settings for your site." admin_help_text_for_settings_site_keywords_label: "Keywords for your site." diff --git a/site/plugins/admin/routes/web.php b/site/plugins/admin/routes/web.php index a8e58204..0dc60175 100644 --- a/site/plugins/admin/routes/web.php +++ b/site/plugins/admin/routes/web.php @@ -61,6 +61,9 @@ $app->group('/' . $admin_route, function () use ($app) : void { // ThemesController $app->get('/themes', 'ThemesController:index')->setName('admin.themes.index'); + $app->get('/themes/information', 'ThemesController:information')->setName('admin.themes.information'); + $app->get('/themes/settings', 'ThemesController:settings')->setName('admin.themes.settings'); + $app->post('/themes/settings', 'ThemesController:settingsProcess')->setName('admin.themes.settingsProcess'); $app->post('/themes/activateProcess', 'ThemesController:activateProcess')->setName('admin.themes.activateProcess'); // TemplatesController diff --git a/site/plugins/admin/views/templates/extends/themes/index.html b/site/plugins/admin/views/templates/extends/themes/index.html index 3afb1154..dc365015 100644 --- a/site/plugins/admin/views/templates/extends/themes/index.html +++ b/site/plugins/admin/views/templates/extends/themes/index.html @@ -7,58 +7,35 @@ {% for key, theme in themes_list %} - + {{ theme.name }} - - + +
+ + +
{% endfor %} - {% else %}
diff --git a/site/plugins/admin/views/templates/extends/themes/information.html b/site/plugins/admin/views/templates/extends/themes/information.html new file mode 100644 index 00000000..99c09313 --- /dev/null +++ b/site/plugins/admin/views/templates/extends/themes/information.html @@ -0,0 +1,44 @@ +{% extends "plugins/admin/views/partials/base.html" %} + +{% block content %} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{{ tr('admin_name') }}:{{ theme_manifest.name }}
{{ tr('admin_version') }}:{{ theme_manifest.version }}
{{ tr('admin_description') }}:{{ theme_manifest.description }}
{{ tr('admin_author_name') }}:{{ theme_manifest.author.name }}
{{ tr('admin_author_email') }}:{{ theme_manifest.author.email }}
{{ tr('admin_author_url') }}:{{ theme_manifest.author.url }}
{{ tr('admin_homepage') }}:{{ theme_manifest.homepage }}
{{ tr('admin_bugs') }}:{{ theme_manifest.bugs }}
{{ tr('admin_license') }}:{{ theme_manifest.license }}
+{% endblock %} diff --git a/site/plugins/admin/views/templates/extends/themes/settings.html b/site/plugins/admin/views/templates/extends/themes/settings.html new file mode 100644 index 00000000..f0eda96a --- /dev/null +++ b/site/plugins/admin/views/templates/extends/themes/settings.html @@ -0,0 +1,16 @@ +{% extends "plugins/admin/views/partials/base.html" %} + +{% block content %} +
+ {{ csrf() }} + + +
+
+
+ +
+
+
+
+{% endblock %}