Browse Source

First commit

release/1.1.0
Flavio Copes 7 years ago
commit
b7ce57b541
  1. 1
      .gitignore
  2. 25
      README.md
  3. 7
      admin/pages/comments.md
  4. 58
      admin/templates/comments.html.twig
  5. 51
      admin/templates/partials/item.html.twig
  6. 47
      admin/templates/partials/items.html.twig
  7. 17
      admin/templates/partials/types.html.twig
  8. 63
      comments.php
  9. 1
      comments.yaml
  10. 3
      languages.yaml

1
.gitignore

@ -0,0 +1 @@
.DS_Store

25
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

7
admin/pages/comments.md

@ -0,0 +1,7 @@
---
title: Data Manager
access:
admin.data-manager: true
admin.super: true
---

58
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' %}
<div class="button-bar">
<a class="button" href="{{ base_url }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
</div>
<h1><i class="fa fa-fw fa-file-text-o"></i> {{ "PLUGIN_DATA_MANAGER.DATA_TYPES"|tu }}</h1>
{% elseif mode == 'items' %}
<div class="button-bar">
<a class="button" href="{{ base_url }}/data-manager"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
</div>
<h1><i class="fa fa-fw fa-file-text-o"></i> {{ "PLUGIN_DATA_MANAGER.ITEMS_LIST"|tu }}</h1>
{% elseif mode == 'item' %}
<div class="button-bar">
<a class="button" href="{{ base_url }}/data-manager/{{ type }}"><i class="fa fa-reply"></i> {{ "PLUGIN_ADMIN.BACK"|tu }}</a>
</div>
<h1><i class="fa fa-fw fa-file-text-o"></i> {{ "PLUGIN_DATA_MANAGER.ITEM_DETAILS"|tu }}</h1>
{% endif %}
{% endblock %}
{% block content %}
<style>
.page-data ul { padding-left: 60px; display: block; list-style-type: square; }
.page-data ul li .row { padding-left: 0px }
</style>
<div class="page-data">
{% 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 %}
</div>
{% endblock %}

51
admin/templates/partials/item.html.twig

@ -0,0 +1,51 @@
{% macro loop(elements) %}
<ul>
{% for key, item in elements %}
{% if item is iterable %}
<li><strong>{{key|e|capitalize}}</strong>:</li>
{{ _self.loop(item) }}
{% else %}
<li><strong>{{key|e|capitalize}}</strong>: {{ item|e }}</li>
{% endif %}
{% endfor %}
</ul>
{% endmacro %}
<h1>
{{ config.plugins['data-manager'].types[type].item.title ?: type|e|capitalize ~ " " ~ "PLUGIN_DATA_MANAGER.ITEM_DETAILS"|e|tu }}
</h1>
<ul>
{% if config.plugins['data-manager'].types[type].item.fields %}
{% for key, type in config.plugins['data-manager'].types[type].item.fields %}
<li class="page-item">
<div class="row">
<strong>{{type.name|e|capitalize}}</strong>:
{% set item = grav.twig.itemData[key]|cast_to_array %}
{% if item is iterable %}
{{ _self.loop(item) }}
{% else %}
{{ item|e }}
{% endif %}
</div>
</li>
{% endfor %}
{% else %}
{% for key, type in grav.twig.itemData %}
<li class="page-item">
<div class="row">
<strong>{{key|capitalize}}</strong>:
{% set item = grav.twig.itemData[key]|cast_to_array %}
{% if item is iterable %}
{{ _self.loop(item) }}
{% else %}
{{ item|e }}
{% endif %}
</div>
</li>
{% endfor %}
{% endif %}
</ul>

47
admin/templates/partials/items.html.twig

@ -0,0 +1,47 @@
<h1>
{{ config.plugins['data-manager'].types[type].list.title ?: type|e|capitalize ~ " " ~ "PLUGIN_DATA_MANAGER.ITEMS_LIST"|e|tu }}
</h1>
<div class="row">
{% if config.plugins['data-manager'].types[type].list.columns %}
<table>
<thead>
<tr>
{% for column in config.plugins['data-manager'].types[type].list.columns %}
<th>{{ column.label|e }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for item in grav.twig.items %}
<tr>
{% for column in config.plugins['data-manager'].types[type].list.columns %}
<td>
<a href="{{ type }}/{{ item.route }}">
{% 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 %}
</a>
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<ul class="pages-list depth-0">
{% for item in grav.twig.items %}
<li class="page-item">
<div class="row">
<a href="{{ type }}/{{ item.route }}" class="page-edit">{{ item.route|e }}</a>
</div>
</li>
{% endfor %}
</ul>
{% endif %}
</div>

17
admin/templates/partials/types.html.twig

@ -0,0 +1,17 @@
<div class="gpm gpm-themes">
<h1>
{{"PLUGIN_DATA_MANAGER.DATA_TYPES"|e|tu}}
</h1>
<div class="gpm gpm-themes themes card-row grid fixed-blocks pure-g">
{% for type, count in grav.twig.types %}
<a href="data-manager/{{ type }}" class="pure-u-1-3 card-item">
<div class="theme">
<div class="gpm-name">
{{ config.plugins['data-manager'].types[type].name|e ?: type|capitalize|e }}
</div>
<p>{{ count }} {{"PLUGIN_DATA_MANAGER.ITEMS"|e|tu}}</p>
</div>
</a>
{% endfor %}
</div>
</div>

63
comments.php

@ -0,0 +1,63 @@
<?php
namespace Grav\Plugin;
use Grav\Common\GPM\GPM;
use Grav\Common\Grav;
use Grav\Common\Page\Page;
use Grav\Common\Page\Pages;
use Grav\Common\Plugin;
class CommentsPlugin extends Plugin
{
protected $route = 'comments';
/**
* @return array
*/
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['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';
}
}

1
comments.yaml

@ -0,0 +1 @@
enabled: true

3
languages.yaml

@ -0,0 +1,3 @@
en:
PLUGIN_COMMENTS:
COMMENTS: Comments
Loading…
Cancel
Save