From ae1b2a074c3851fd148c05e76b096afa5865617b Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 3 Jan 2016 17:53:04 +0100 Subject: [PATCH] Show any configuration item Grav finds under user/config, if there is an associated blueprint provided Also, organize current system/site/info files under a common config.html.twig. Delete info/site/system twig files. Preserve BC by setting the template of system/site/info to "config", in the pages. --- classes/admin.php | 32 +++++++++ pages/admin/config.md | 0 pages/admin/info.md | 2 +- pages/admin/site.md | 2 +- pages/admin/system.md | 2 +- themes/grav/templates/config.html.twig | 72 ++++++++++++++++++++ themes/grav/templates/info.html.twig | 23 ------- themes/grav/templates/partials/nav.html.twig | 2 +- themes/grav/templates/site.html.twig | 38 ----------- themes/grav/templates/system.html.twig | 38 ----------- 10 files changed, 108 insertions(+), 103 deletions(-) create mode 100644 pages/admin/config.md create mode 100644 themes/grav/templates/config.html.twig delete mode 100644 themes/grav/templates/info.html.twig delete mode 100644 themes/grav/templates/site.html.twig delete mode 100644 themes/grav/templates/system.html.twig diff --git a/classes/admin.php b/classes/admin.php index 39086600..7f8c440a 100644 --- a/classes/admin.php +++ b/classes/admin.php @@ -335,6 +335,15 @@ class Admin $obj = User::load(preg_replace('|users/|', '', $type)); $obj->merge($post); + $data[$type] = $obj; + } elseif (preg_match('|config/|', $type)) { + $type = preg_replace('|config/|', '', $type); + $blueprints = $this->blueprints("config/{$type}"); + $config = $this->grav['config']; + $obj = new Data\Data($config->get($type), $blueprints); + $obj->merge($post); + $file = CompiledYamlFile::instance($this->grav['locator']->findResource("config://{$type}.yaml")); + $obj->file($file); $data[$type] = $obj; } else { throw new \RuntimeException("Data type '{$type}' doesn't exist!"); @@ -706,6 +715,29 @@ class Admin return $languages; } + /** + * Return the configuration files found + * + * @return array + */ + public static function configurations() + { + $configurations = []; + $path = $this->grav['locator']->findResource('user://config'); + + /** @var \DirectoryIterator $directory */ + foreach (new \DirectoryIterator($path) as $file) { + if ($file->isDir() || $file->isDot() || $file->getBasename()[0] == '.') { + continue; + } + + $configurations[] = basename($file->getBasename(), '.yaml'); + + } + + return $configurations; + } + /** * Return the languages available in the site * diff --git a/pages/admin/config.md b/pages/admin/config.md new file mode 100644 index 00000000..e69de29b diff --git a/pages/admin/info.md b/pages/admin/info.md index cd084941..ca950fda 100644 --- a/pages/admin/info.md +++ b/pages/admin/info.md @@ -1,6 +1,6 @@ --- title: PHP Info - +template: config access: admin.settings: true admin.super: true diff --git a/pages/admin/site.md b/pages/admin/site.md index 699bf794..437c2898 100644 --- a/pages/admin/site.md +++ b/pages/admin/site.md @@ -1,6 +1,6 @@ --- title: Site Settings - +template: config access: admin.settings: true admin.super: true diff --git a/pages/admin/system.md b/pages/admin/system.md index f38e9b84..76560180 100644 --- a/pages/admin/system.md +++ b/pages/admin/system.md @@ -1,6 +1,6 @@ --- title: Configuration - +template: config access: admin.configuration: true admin.super: true diff --git a/themes/grav/templates/config.html.twig b/themes/grav/templates/config.html.twig new file mode 100644 index 00000000..5e0d439d --- /dev/null +++ b/themes/grav/templates/config.html.twig @@ -0,0 +1,72 @@ +{% extends 'partials/base.html.twig' %} + +{% set config_slug = uri.basename %} +{% set isInfo = (config_slug == 'info') %} + +{% set title = "PLUGIN_ADMIN.CONFIGURATION"|tu ~ ": " ~ ("PLUGIN_ADMIN." ~ config_slug|upper)|tu %} + +{% if not isInfo %} + {% set data = admin.data('config/' ~ config_slug) %} +{% endif %} + +{% block stylesheets %} + {% do assets.addCss(theme_url~'/css/codemirror/codemirror.css') %} + {{ parent() }} +{% endblock %} + +{% block javascripts %} + {% do assets.addJs(theme_url~'/js/codemirror-compressed.js') %} + {% do assets.addJs(theme_url~'/js/mdeditor.js') %} + {{ parent() }} +{% endblock %} + +{% block titlebar %} +
+ {{ "PLUGIN_ADMIN.BACK"|tu }} + +
+

{{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ ("PLUGIN_ADMIN." ~ config_slug|upper)|tu }}

+{% endblock %} + +{% block content_top %} +
{{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: {{ data.file.filename|replace({(base_path):''}) }}
+ +{% endblock %} + +{% block content %} + {% if isInfo %} +
+ {{ admin.phpinfo }} +
+ {% else %} + {% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %} + {% endif %} +{% endblock %} + diff --git a/themes/grav/templates/info.html.twig b/themes/grav/templates/info.html.twig deleted file mode 100644 index ac30c598..00000000 --- a/themes/grav/templates/info.html.twig +++ /dev/null @@ -1,23 +0,0 @@ -{% extends 'partials/base.html.twig' %} - -{% block titlebar %} -
- {{ "PLUGIN_ADMIN.BACK"|tu }} -
-

{{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ "PLUGIN_ADMIN.PHP_INFO"|tu }}

-{% endblock %} - -{% block content_top %} - -{% endblock %} - -{% block content %} -
- {{ admin.phpinfo }} -
-{% endblock %} - diff --git a/themes/grav/templates/partials/nav.html.twig b/themes/grav/templates/partials/nav.html.twig index a621b0c9..fc93168a 100644 --- a/themes/grav/templates/partials/nav.html.twig +++ b/themes/grav/templates/partials/nav.html.twig @@ -25,7 +25,7 @@ {{ "PLUGIN_ADMIN.DASHBOARD"|tu }} {% if authorize(['admin.configuration', 'admin.super']) %} -
  • +
  • {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }}
  • {% endif %} diff --git a/themes/grav/templates/site.html.twig b/themes/grav/templates/site.html.twig deleted file mode 100644 index 33caeced..00000000 --- a/themes/grav/templates/site.html.twig +++ /dev/null @@ -1,38 +0,0 @@ -{% extends 'partials/base.html.twig' %} - -{% set title = "PLUGIN_ADMIN.CONFIGURATION"|tu ~ ": " ~ "PLUGIN_ADMIN.SITE"|tu %} - -{% set data = admin.data('site') %} - -{% block stylesheets %} - {% do assets.addCss(theme_url~'/css/codemirror/codemirror.css') %} - {{ parent() }} -{% endblock %} - -{% block javascripts %} - {% do assets.addJs(theme_url~'/js/codemirror-compressed.js') %} - {% do assets.addJs(theme_url~'/js/mdeditor.js') %} - {{ parent() }} -{% endblock %} - -{% block titlebar %} -
    - {{ "PLUGIN_ADMIN.BACK"|tu }} - -
    -

    {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ "PLUGIN_ADMIN.SITE"|tu }}

    -{% endblock %} - -{% block content_top %} -
    {{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: {{ data.file.filename|replace({(base_path):''}) }}
    - -{% endblock %} - -{% block content %} - {% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %} -{% endblock %} - diff --git a/themes/grav/templates/system.html.twig b/themes/grav/templates/system.html.twig deleted file mode 100644 index ce19a6f9..00000000 --- a/themes/grav/templates/system.html.twig +++ /dev/null @@ -1,38 +0,0 @@ -{% extends 'partials/base.html.twig' %} - -{% set title = "PLUGIN_ADMIN.CONFIGURATION"|tu ~ ": " ~ "PLUGIN_ADMIN.SYSTEM"|tu %} - -{% set data = admin.data('system') %} - -{% block stylesheets %} - {% do assets.addCss(theme_url~'/css/codemirror/codemirror.css') %} - {{ parent() }} -{% endblock %} - -{% block javascripts %} - {% do assets.addJs(theme_url~'/js/codemirror-compressed.js') %} - {% do assets.addJs(theme_url~'/js/mdeditor.js') %} - {{ parent() }} -{% endblock %} - -{% block titlebar %} -
    - {{ "PLUGIN_ADMIN.BACK"|tu }} - -
    -

    {{ "PLUGIN_ADMIN.CONFIGURATION"|tu }} - {{ "PLUGIN_ADMIN.SYSTEM"|tu }}

    -{% endblock %} - -{% block content_top %} -
    {{ "PLUGIN_ADMIN.SAVE_LOCATION"|tu }}: {{ data.file.filename|replace({(base_path):''}) }}
    - -{% endblock %} - -{% block content %} - {% include 'partials/blueprints.html.twig' with { blueprints: data.blueprints, data: data } %} -{% endblock %} -