mirror of
https://github.com/flextype/flextype.git
synced 2025-08-24 13:52:56 +02:00
feat(admin-plugin): YAML parsing will be cached in production #263
feat(admin-plugin): add plugins settings page #258 feat(admin-plugin): add plugins information page #257
This commit is contained in:
@@ -127,7 +127,7 @@ class EntriesController extends Controller
|
||||
if (count($fieldsets_list) > 0) {
|
||||
foreach ($fieldsets_list as $fieldset) {
|
||||
if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') {
|
||||
$fieldset_content = Parser::decode(Filesystem::read($fieldset['path']), 'yaml');
|
||||
$fieldset_content = $this->parser->decode(Filesystem::read($fieldset['path']), 'yaml');
|
||||
if (isset($fieldset_content['sections']) && isset($fieldset_content['sections']['main']) && isset($fieldset_content['sections']['main']['fields'])) {
|
||||
$fieldsets[$fieldset['basename']] = $fieldset_content['title'];
|
||||
}
|
||||
@@ -281,7 +281,7 @@ class EntriesController extends Controller
|
||||
if (count($_fieldsets) > 0) {
|
||||
foreach ($_fieldsets as $fieldset) {
|
||||
if ($fieldset['type'] == 'file' && $fieldset['extension'] == 'yaml') {
|
||||
$fieldset_content = Parser::decode(Filesystem::read($fieldset['path']), 'yaml');
|
||||
$fieldset_content = $this->parser->decode(Filesystem::read($fieldset['path']), 'yaml');
|
||||
if (isset($fieldset_content['sections']) && isset($fieldset_content['sections']['main']) && isset($fieldset_content['sections']['main']['fields'])) {
|
||||
$fieldsets[$fieldset['basename']] = $fieldset_content['title'];
|
||||
}
|
||||
@@ -598,7 +598,7 @@ class EntriesController extends Controller
|
||||
|
||||
// Fieldsets for current entry template
|
||||
$fieldsets_path = PATH['site'] . '/fieldsets/' . (isset($entry['fieldset']) ? $entry['fieldset'] : 'default') . '.yaml';
|
||||
$fieldsets = Parser::decode(Filesystem::read($fieldsets_path), 'yaml');
|
||||
$fieldsets = $this->parser->decode(Filesystem::read($fieldsets_path), 'yaml');
|
||||
is_null($fieldsets) and $fieldsets = [];
|
||||
|
||||
if ($type == 'source') {
|
||||
@@ -610,7 +610,7 @@ class EntriesController extends Controller
|
||||
'i' => count($parts),
|
||||
'last' => Arr::last($parts),
|
||||
'id' => $this->getEntryID($query),
|
||||
'data' => Parser::encode($entry, 'frontmatter'),
|
||||
'data' => $this->parser->encode($entry, 'frontmatter'),
|
||||
'type' => $type,
|
||||
'menu_item' => 'entries',
|
||||
'links' => [
|
||||
@@ -752,12 +752,12 @@ class EntriesController extends Controller
|
||||
// Data from POST
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
$entry = Parser::decode($data['data'], 'frontmatter');
|
||||
$entry = $this->parser->decode($data['data'], 'frontmatter');
|
||||
|
||||
$entry['published_by'] = Session::get('uuid');
|
||||
|
||||
// Update entry
|
||||
if (Filesystem::write(PATH['entries'] . '/' . $id . '/entry.md', Parser::encode($entry, 'frontmatter'))) {
|
||||
if (Filesystem::write(PATH['entries'] . '/' . $id . '/entry.md', $this->parser->encode($entry, 'frontmatter'))) {
|
||||
$this->flash->addMessage('success', __('admin_message_entry_changes_saved'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_entry_changes_not_saved'));
|
||||
|
@@ -95,7 +95,7 @@ class FieldsetsController extends Controller
|
||||
[
|
||||
'menu_item' => 'fieldsets',
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'data' => Parser::encode($this->fieldsets->fetch($request->getQueryParams()['id']), 'yaml'),
|
||||
'data' => $this->parser->encode($this->fieldsets->fetch($request->getQueryParams()['id']), 'yaml'),
|
||||
'links' => [
|
||||
'fieldsets' => [
|
||||
'link' => $this->router->pathFor('admin.fieldsets.index'),
|
||||
@@ -124,7 +124,7 @@ class FieldsetsController extends Controller
|
||||
$id = $request->getParsedBody()['id'];
|
||||
$data = $request->getParsedBody()['data'];
|
||||
|
||||
if ($this->fieldsets->update($request->getParsedBody()['id'], Parser::decode($data, 'yaml'))) {
|
||||
if ($this->fieldsets->update($request->getParsedBody()['id'], $this->parser->decode($data, 'yaml'))) {
|
||||
$this->flash->addMessage('success', __('admin_message_fieldset_saved'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_fieldset_was_not_saved'));
|
||||
|
@@ -62,9 +62,9 @@ class PluginsController extends Controller
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
// Update settings
|
||||
$plugin_settings = Parser::decode(Filesystem::read(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml'), 'yaml');
|
||||
$plugin_settings = $this->parser->decode(Filesystem::read(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml'), 'yaml');
|
||||
Arr::set($plugin_settings, 'enabled', ($data['plugin-status'] === 'true'));
|
||||
Filesystem::write(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml', Parser::encode($plugin_settings, 'yaml'));
|
||||
Filesystem::write(PATH['plugins'] . '/' . $data['plugin-key'] . '/' . 'settings.yaml', $this->parser->encode($plugin_settings, 'yaml'));
|
||||
|
||||
// Clear doctrine cache
|
||||
$this->cache->clear('doctrine');
|
||||
@@ -72,4 +72,43 @@ class PluginsController extends Controller
|
||||
// Redirect to plugins index page
|
||||
return $response->withRedirect($this->router->pathFor('admin.plugins.index'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit plugin
|
||||
*
|
||||
* @param Request $request PSR7 request
|
||||
* @param Response $response PSR7 response
|
||||
*/
|
||||
public function edit(Request $request, Response $response) : Response
|
||||
{
|
||||
return $this->view->render(
|
||||
$response,
|
||||
'plugins/admin/views/templates/extends/plugins/edit.html',
|
||||
[
|
||||
'menu_item' => 'plugins',
|
||||
'id' => $request->getQueryParams()['id'],
|
||||
'plugin_manifest' => $this->parser->decode(Filesystem::read(PATH['plugins'] . '/' . $request->getQueryParams()['id'] . '/plugin.yaml'), 'yaml'),
|
||||
'plugin_settings' => Filesystem::read(PATH['plugins'] . '/' . $request->getQueryParams()['id'] . '/settings.yaml'),
|
||||
'links' => [
|
||||
'plugins' => [
|
||||
'link' => $this->router->pathFor('admin.plugins.index'),
|
||||
'title' => __('admin_plugins'),
|
||||
'attributes' => ['class' => 'navbar-item'],
|
||||
],
|
||||
'fieldsets_editor' => [
|
||||
'link' => $this->router->pathFor('admin.plugins.edit') . '?id=' . $request->getQueryParams()['id'],
|
||||
'title' => __('admin_plugin'),
|
||||
'attributes' => ['class' => 'navbar-item active'],
|
||||
],
|
||||
],
|
||||
'buttons' => [
|
||||
'save_entry' => [
|
||||
'link' => 'javascript:;',
|
||||
'title' => __('admin_save'),
|
||||
'attributes' => ['class' => 'js-save-form-submit float-right btn'],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -143,7 +143,7 @@ class SettingsController extends Controller
|
||||
Arr::set($data, 'entries.media.upload_images_width', (int) $data['entries']['media']['upload_images_width']);
|
||||
Arr::set($data, 'entries.media.upload_images_height', (int) $data['entries']['media']['upload_images_height']);
|
||||
|
||||
if (Filesystem::write(PATH['config']['site'] . '/settings.yaml', Parser::encode(array_merge($this->registry->get('settings'), $data), 'yaml'))) {
|
||||
if (Filesystem::write(PATH['config']['site'] . '/settings.yaml', $this->parser->encode(array_merge($this->registry->get('settings'), $data), 'yaml'))) {
|
||||
$this->flash->addMessage('success', __('admin_message_settings_saved'));
|
||||
} else {
|
||||
$this->flash->addMessage('error', __('admin_message_settings_was_not_saved'));
|
||||
|
@@ -64,9 +64,9 @@ class ThemesController extends Controller
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
// Update current theme settings
|
||||
$theme_settings = Parser::decode(Filesystem::read(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml'), 'yaml');
|
||||
$theme_settings = $this->parser->decode(Filesystem::read(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml'), 'yaml');
|
||||
Arr::set($theme_settings, 'enabled', ($data['theme-status'] === 'true'));
|
||||
Filesystem::write(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml', Parser::encode($theme_settings, 'yaml'));
|
||||
Filesystem::write(PATH['themes'] . '/' . $data['theme-id'] . '/' . 'settings.yaml', $this->parser->encode($theme_settings, 'yaml'));
|
||||
|
||||
// Get themes list
|
||||
$themes_list = $this->themes->getThemes();
|
||||
@@ -82,16 +82,16 @@ class ThemesController extends Controller
|
||||
continue;
|
||||
}
|
||||
|
||||
$theme_settings = Parser::decode(Filesystem::read($theme_settings_file), 'yaml');
|
||||
$theme_settings = $this->parser->decode(Filesystem::read($theme_settings_file), 'yaml');
|
||||
Arr::set($theme_settings, 'enabled', false);
|
||||
Filesystem::write($theme_settings_file, Parser::encode($theme_settings, 'yaml'));
|
||||
Filesystem::write($theme_settings_file, $this->parser->encode($theme_settings, 'yaml'));
|
||||
}
|
||||
}
|
||||
|
||||
// Update theme in the site settings
|
||||
$settings = Parser::decode(Filesystem::read(PATH['config']['site'] . '/settings.yaml'), 'yaml');
|
||||
$settings = $this->parser->decode(Filesystem::read(PATH['config']['site'] . '/settings.yaml'), 'yaml');
|
||||
Arr::set($settings, 'theme', $data['theme-id']);
|
||||
Filesystem::write(PATH['config']['site'] . '/settings.yaml', Parser::encode($settings, 'yaml'));
|
||||
Filesystem::write(PATH['config']['site'] . '/settings.yaml', $this->parser->encode($settings, 'yaml'));
|
||||
|
||||
// clear cache
|
||||
$this->cache->clear('doctrine');
|
||||
|
@@ -67,7 +67,7 @@ class UsersController extends Controller
|
||||
$data = $request->getParsedBody();
|
||||
|
||||
if (Filesystem::has($_user_file = PATH['site'] . '/accounts/' . $data['username'] . '.yaml')) {
|
||||
$user_file = Parser::decode(Filesystem::read($_user_file), 'yaml');
|
||||
$user_file = $this->parser->decode(Filesystem::read($_user_file), 'yaml', false);
|
||||
if (password_verify(trim($data['password']), $user_file['hashed_password'])) {
|
||||
Session::set('username', $user_file['username']);
|
||||
Session::set('role', $user_file['role']);
|
||||
@@ -135,7 +135,7 @@ class UsersController extends Controller
|
||||
// Create admin account
|
||||
if (Filesystem::write(
|
||||
PATH['site'] . '/accounts/' . $data['username'] . '.yaml',
|
||||
Parser::encode([
|
||||
$this->parser->encode([
|
||||
'username' => $this->slugify->slugify($data['username']),
|
||||
'hashed_password' => password_hash($data['password'], PASSWORD_BCRYPT),
|
||||
'email' => $data['email'],
|
||||
|
@@ -252,3 +252,5 @@ admin_twig_charset: "Charset"
|
||||
admin_twig_cache: "Cache"
|
||||
admin_published_at: "Published at"
|
||||
admin_licence: "Licence"
|
||||
admin_plugin: "Plugin"
|
||||
admin_icon: "Icon"
|
||||
|
@@ -43,6 +43,7 @@ $app->group('/' . $admin_route, function () use ($app) : void {
|
||||
|
||||
// Plugins Controller
|
||||
$app->get('/plugins', 'PluginsController:index')->setName('admin.plugins.index');
|
||||
$app->get('/plugins/edit', 'PluginsController:edit')->setName('admin.plugins.edit');
|
||||
$app->post('/plugins/update-status', 'PluginsController:pluginStatusProcess')->setName('admin.plugins.update-status');
|
||||
|
||||
// FieldsetsController
|
||||
|
@@ -216,6 +216,13 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if is_current_path('admin.plugins.index') or
|
||||
is_current_path('admin.plugins.edit') %}
|
||||
<div class="entry-editor-heading">
|
||||
/ {{ id }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<div class="content entry-editor">
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
|
@@ -12,7 +12,7 @@
|
||||
{% if entry.fieldset %}
|
||||
{% set fieldset_path = PATH_FIELDSETS ~ '/' ~ entry.fieldset ~ '.yaml' %}
|
||||
{% if filesystem_has(fieldset_path) %}
|
||||
{% set fieldset = yaml_decode(filesystem_read(fieldset_path)) %}
|
||||
{% set fieldset = parser_decode(filesystem_read(fieldset_path), 'yaml') %}
|
||||
{% if fieldset.icon %}
|
||||
<i class="{{ fieldset.icon }}"></i>
|
||||
{% else %}
|
||||
|
@@ -9,7 +9,7 @@
|
||||
<td style="width: 50px; padding-right: 10px; text-align:center;">
|
||||
{% set fieldset_path = PATH_FIELDSETS ~ '/' ~ id ~ '.yaml' %}
|
||||
{% if filesystem_has(fieldset_path) %}
|
||||
{% set fieldset = yaml_decode(filesystem_read(fieldset_path)) %}
|
||||
{% set fieldset = parser_decode(filesystem_read(fieldset_path), 'yaml') %}
|
||||
{% if fieldset.icon %}
|
||||
<i class="{{ fieldset.icon }}"></i>
|
||||
{% else %}
|
||||
|
71
site/plugins/admin/views/templates/extends/plugins/edit.html
Normal file
71
site/plugins/admin/views/templates/extends/plugins/edit.html
Normal file
@@ -0,0 +1,71 @@
|
||||
{% extends "plugins/admin/views/partials/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
<table class="table no-margin">
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="width: 200px;">{{ tr('admin_name') }}:</td>
|
||||
<td>{{ plugin_manifest.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_version') }}:</td>
|
||||
<td>{{ plugin_manifest.version }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_description') }}:</td>
|
||||
<td>{{ plugin_manifest.description }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_icon') }}:</td>
|
||||
<td>{{ plugin_manifest.icon }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_author_name') }}:</td>
|
||||
<td>{{ plugin_manifest.author.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_author_email') }}:</td>
|
||||
<td>{{ plugin_manifest.author.email }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_author_url') }}:</td>
|
||||
<td>{{ plugin_manifest.author.url }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_homepage') }}:</td>
|
||||
<td>{{ plugin_manifest.homepage }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_bugs') }}:</td>
|
||||
<td>{{ plugin_manifest.bugs }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ tr('admin_license') }}:</td>
|
||||
<td>{{ plugin_manifest.license }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<h3 class="h3 margin-top-none">{{ tr('admin_settings') }}</h3>
|
||||
<hr>
|
||||
|
||||
<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 style="min-height:500px;" name="data" rows="8" cols="80" class="form-control js-code">{{ plugin_settings }}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
<br>
|
||||
|
||||
{% endblock %}
|
@@ -12,20 +12,7 @@
|
||||
<i class="fas fa-plug"></i>
|
||||
{% endif %}
|
||||
</td>
|
||||
<td style="padding-left:0px;">{{ plugin.name }}</td>
|
||||
<td class="text-right">
|
||||
<a href="javascript:;" class="btn js-plugins-info" data-toggle="modal" data-target="#pluginInfoModal"
|
||||
data-name="{{ plugin.name }}"
|
||||
data-version="{{ plugin.version }}"
|
||||
data-description="{{ plugin.description }}"
|
||||
data-author-name="{{ plugin.author.name }}"
|
||||
data-author-email="{{ plugin.author.email }}"
|
||||
data-author-url="{{ plugin.author.url }}"
|
||||
data-homepage="{{ plugin.homepage }}"
|
||||
data-bugs="{{ plugin.bugs }}"
|
||||
data-license="{{ plugin.license }}"
|
||||
>{{ tr('admin_info') }}</a>
|
||||
</td>
|
||||
<td style="padding-left:0px;"><a href="{{ path_for('admin.plugins.edit') }}?id={{ key }}">{{ plugin.name }}</a></td>
|
||||
<td class="text-right" style="width: 50px;">
|
||||
<div class="form-group no-margin">
|
||||
<span class="switch switch-sm">
|
||||
|
Reference in New Issue
Block a user