From b7ce57b54103e34361dab517870320034b2c53b3 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 13 Sep 2015 20:32:44 +0200 Subject: [PATCH] First commit --- .gitignore | 1 + README.md | 25 ++++++++++ admin/pages/comments.md | 7 +++ admin/templates/comments.html.twig | 58 ++++++++++++++++++++++ admin/templates/partials/item.html.twig | 51 +++++++++++++++++++ admin/templates/partials/items.html.twig | 47 ++++++++++++++++++ admin/templates/partials/types.html.twig | 17 +++++++ comments.php | 63 ++++++++++++++++++++++++ comments.yaml | 1 + languages.yaml | 3 ++ 10 files changed, 273 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 admin/pages/comments.md create mode 100644 admin/templates/comments.html.twig create mode 100644 admin/templates/partials/item.html.twig create mode 100644 admin/templates/partials/items.html.twig create mode 100644 admin/templates/partials/types.html.twig create mode 100644 comments.php create mode 100644 comments.yaml create mode 100644 languages.yaml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e43b0f9 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/README.md b/README.md new file mode 100644 index 0000000..87286df --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Grav Data Manager Plugin + +The **Comments Plugin** for [Grav](http://github.com/getgrav/grav) adds the ability to add comments to pages, and moderate them. + +| IMPORTANT!!! This plugin is currently in development as is to be considered a **beta release**. As such, use this in a production environment **at your own risk!**. More features will be added in the future. + +# Installation + +The Data plugin is easy to install with GPM. + +``` +$ bin/gpm install comments +``` + +Or clone from GitHub and put in the `user/plugins/comments` folder. + +# TODO + +- Create inferface (with Form?) to allow people to submit a comment to a Page +- Store and email the comment to the emails configured (default to all with admin.super) +- Enable by default on all Pages +- Allow to enable on some taxonomies or page types only +- Allow some pages to disable comments +- Admin interface to moderate comments +- Add ACL permissions so users can moderate comments in admin diff --git a/admin/pages/comments.md b/admin/pages/comments.md new file mode 100644 index 0000000..5996684 --- /dev/null +++ b/admin/pages/comments.md @@ -0,0 +1,7 @@ +--- +title: Data Manager + +access: + admin.data-manager: true + admin.super: true +--- diff --git a/admin/templates/comments.html.twig b/admin/templates/comments.html.twig new file mode 100644 index 0000000..b72ab52 --- /dev/null +++ b/admin/templates/comments.html.twig @@ -0,0 +1,58 @@ +{% extends 'partials/base.html.twig' %} +{% set mode = 'types' %} + +{% if uri.paths[1] == 'data-manager' and uri.paths[2] %} + {% set mode = 'items' %} + {% set type = uri.paths[2] %} + + {% if uri.paths[3] %} + {% set mode = 'item' %} + {% set item = uri.paths[3] %} + {% endif %} + +{% endif %} + +{% if admin.route %} + {% set context = admin.page(true) %} +{% endif %} + +{% block titlebar %} + {% if mode == 'types' %} +
+ {{ "PLUGIN_ADMIN.BACK"|tu }} +
+

{{ "PLUGIN_DATA_MANAGER.DATA_TYPES"|tu }}

+ {% elseif mode == 'items' %} +
+ {{ "PLUGIN_ADMIN.BACK"|tu }} +
+

{{ "PLUGIN_DATA_MANAGER.ITEMS_LIST"|tu }}

+ {% elseif mode == 'item' %} +
+ {{ "PLUGIN_ADMIN.BACK"|tu }} +
+

{{ "PLUGIN_DATA_MANAGER.ITEM_DETAILS"|tu }}

+ {% endif %} +{% endblock %} + +{% block content %} + + + +
+ {% if mode == 'types' %} + {% include "partials/types.html.twig" %} + {% endif %} + + {% if mode == 'items' %} + {% include ['partials/data-manager/' ~ type ~ '/items.html.twig', 'partials/items.html.twig'] %} + {% endif %} + + {% if mode == 'item' %} + {% include ['partials/data-manager/' ~ type ~ '/item.html.twig', 'partials/item.html.twig'] %} + {% endif %} +
+{% endblock %} diff --git a/admin/templates/partials/item.html.twig b/admin/templates/partials/item.html.twig new file mode 100644 index 0000000..fd5eef5 --- /dev/null +++ b/admin/templates/partials/item.html.twig @@ -0,0 +1,51 @@ +{% macro loop(elements) %} + +{% endmacro %} + +

+ {{ config.plugins['data-manager'].types[type].item.title ?: type|e|capitalize ~ " " ~ "PLUGIN_DATA_MANAGER.ITEM_DETAILS"|e|tu }} +

+ diff --git a/admin/templates/partials/items.html.twig b/admin/templates/partials/items.html.twig new file mode 100644 index 0000000..b8edc20 --- /dev/null +++ b/admin/templates/partials/items.html.twig @@ -0,0 +1,47 @@ +

+ {{ config.plugins['data-manager'].types[type].list.title ?: type|e|capitalize ~ " " ~ "PLUGIN_DATA_MANAGER.ITEMS_LIST"|e|tu }} +

+
+ {% if config.plugins['data-manager'].types[type].list.columns %} + + + + {% for column in config.plugins['data-manager'].types[type].list.columns %} + + {% endfor %} + + + + {% for item in grav.twig.items %} + + {% for column in config.plugins['data-manager'].types[type].list.columns %} + + {% endfor %} + + {% endfor %} + +
{{ column.label|e }}
+ + {% if column.field is iterable %} + {% set value = item.content %} + {% for field in column.field %} + {% set value = value[field] %} + {% endfor %} + {{ value|e }} + {% else %} + {{ item.content[column.field]|e }} + {% endif %} + +
+ {% else %} + + {% endif %} +
diff --git a/admin/templates/partials/types.html.twig b/admin/templates/partials/types.html.twig new file mode 100644 index 0000000..d69ac6e --- /dev/null +++ b/admin/templates/partials/types.html.twig @@ -0,0 +1,17 @@ +
+

+ {{"PLUGIN_DATA_MANAGER.DATA_TYPES"|e|tu}} +

+ +
diff --git a/comments.php b/comments.php new file mode 100644 index 0000000..41f2e73 --- /dev/null +++ b/comments.php @@ -0,0 +1,63 @@ + ['onPluginsInitialized', 0], + ]; + } + + /** + * Enable search only if url matches to the configuration. + */ + public function onPluginsInitialized() + { + if (!$this->isAdmin()) { + return; + } + + $this->enable([ + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], + 'onAdminTemplateNavPluginHook' => ['onAdminTemplateNavPluginHook', 0], + 'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0], + ]); + } + + /** + * Add plugin templates path + */ + public function onTwigTemplatePaths() + { + $this->grav['twig']->twig_paths[] = __DIR__ . '/admin/templates'; + } + + /** + * Add navigation item to the admin plugin + */ + public function onAdminTemplateNavPluginHook() + { + $this->grav['twig']->plugins_hooked_nav['PLUGIN_COMMENTS.COMMENTS'] = ['route' => $this->route, 'icon' => 'fa-file-text']; + } + + /** + * Exclude comments from the Data Manager plugin + */ + public function onDataTypeExcludeFromDataManagerPluginHook() + { + $this->grav['admin']->dataTypesExcludedFromDataManagerPlugin[] = 'comments'; + } +} diff --git a/comments.yaml b/comments.yaml new file mode 100644 index 0000000..d4ca941 --- /dev/null +++ b/comments.yaml @@ -0,0 +1 @@ +enabled: true diff --git a/languages.yaml b/languages.yaml new file mode 100644 index 0000000..7235528 --- /dev/null +++ b/languages.yaml @@ -0,0 +1,3 @@ +en: + PLUGIN_COMMENTS: + COMMENTS: Comments