mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 21:56:25 +02:00
feat(admin-plugin): add themes settings page #296
feat(admin-plugin): add themes imformation page #295
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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."
|
||||
|
@@ -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
|
||||
|
@@ -7,58 +7,35 @@
|
||||
{% for key, theme in themes_list %}
|
||||
<tr>
|
||||
<td style="width: 50px; padding-right: 10px; text-align:center;">
|
||||
<i class="fas fa-palette" aria-hidden="true"></i>
|
||||
<i class="fas fa-palette {% if key == registry.settings.theme %}{% else %}opacity-50{% endif %}" aria-hidden="true"></i>
|
||||
</td>
|
||||
<td style="padding-left:0px;"><a href="{{ path_for('admin.templates.index') }}?theme={{ key }}">{{ theme.name }}</a></td>
|
||||
<td class="text-right" style="width: 50px;">
|
||||
|
||||
<td class="text-right">
|
||||
<div class="btn-group">
|
||||
<button type="button" class="btn dropdown-toggle" data-toggle="dropdown" data-display="static" aria-haspopup="true" aria-expanded="false">
|
||||
<i class="fas fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu dropdown-menu-lg-right">
|
||||
<form id="activate-theme-id-{{ key }}" action="{{ path_for('admin.themes.activateProcess') }}" method="POST" style="display: none;">
|
||||
{{ csrf() }}
|
||||
<input type="hidden" name="theme-id" value="{{ key }}">
|
||||
<input type="hidden" name="theme-status" value="true">
|
||||
</form>
|
||||
{% if key == registry.settings.theme %}
|
||||
{% else %}
|
||||
<a class="dropdown-item" href="javascript:;"
|
||||
onclick="event.preventDefault();
|
||||
document.getElementById('activate-theme-id-{{ key }}').submit();"><i class="far fa-star"></i> {{ tr('admin_activate') }}</a>
|
||||
{% endif %}
|
||||
<a class="dropdown-item" href="{{ path_for('admin.themes.information') }}?id={{ key }}"><i class="fas fa-info-circle"></i> {{ tr('admin_information') }}</a>
|
||||
<a class="dropdown-item" href="{{ path_for('admin.themes.settings') }}?id={{ key }}"><i class="fas fa-cog"></i> {{ tr('admin_settings') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
<!--
|
||||
<div class="card-deck">
|
||||
<div class="col-md-12">
|
||||
<div class="row">
|
||||
{% for key, theme in themes_list %}
|
||||
<div class="col-md-4">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
{{ theme.name }}
|
||||
</div>
|
||||
<div style="padding: 0px;">
|
||||
<img src="{{ base_url() }}/site/themes/{{ key }}/thumbnail.jpg" class="card-img-top" alt="{{ theme.name }}">
|
||||
</div>
|
||||
<div class="card-footer text-center">
|
||||
<div class="btn-group">
|
||||
{% if key == registry.settings.theme %}
|
||||
<a class="btn btn-default" href="javascript:;">{{ tr('admin_active_theme') }}</a>
|
||||
{% else %}
|
||||
<a class="btn btn-default" href="javascript:;"
|
||||
onclick="event.preventDefault();
|
||||
document.getElementById('activate-theme-id-{{ key }}').submit();">{{ tr('admin_activate') }}</a>
|
||||
<form id="activate-theme-id-{{ key }}" action="{{ path_for('admin.themes.activateProcess') }}" method="POST" style="display: none;">
|
||||
{{ csrf() }}
|
||||
<input type="hidden" name="theme-id" value="{{ key }}">
|
||||
<input type="hidden" name="theme-status" value="true">
|
||||
</form>
|
||||
{% endif %}
|
||||
<button type="button" class="btn btn-default dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
<span class="sr-only">Toggle Dropdown</span>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item" href="{{ path_for('admin.templates.index') }}?theme={{ key }}">{{ tr('admin_edit') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
{% else %}
|
||||
<div class="empty-list-message">
|
||||
<i class="fas fa-list"></i>
|
||||
|
@@ -0,0 +1,44 @@
|
||||
{% extends "plugins/admin/views/partials/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<table class="table no-margin">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>{{ tr('admin_name') }}:</td>
|
||||
<td>{{ theme_manifest.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_version') }}:</td>
|
||||
<td>{{ theme_manifest.version }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_description') }}:</td>
|
||||
<td>{{ theme_manifest.description }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_author_name') }}:</td>
|
||||
<td>{{ theme_manifest.author.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_author_email') }}:</td>
|
||||
<td>{{ theme_manifest.author.email }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_author_url') }}:</td>
|
||||
<td>{{ theme_manifest.author.url }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_homepage') }}:</td>
|
||||
<td>{{ theme_manifest.homepage }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_bugs') }}:</td>
|
||||
<td>{{ theme_manifest.bugs }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_license') }}:</td>
|
||||
<td>{{ theme_manifest.license }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
{% endblock %}
|
@@ -0,0 +1,16 @@
|
||||
{% extends "plugins/admin/views/partials/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<form method="post" id="form">
|
||||
{{ csrf() }}
|
||||
<input type="hidden" id="action" name="action" value="save-form">
|
||||
<input type="hidden" id="id" name="id" value="{{ id }}">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<div class="form-group">
|
||||
<textarea name="data" rows="0" cols="0" class="form-control code-editor js-code">{{ theme_settings }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
Reference in New Issue
Block a user