From afd22bea5b8bbf7775518e4f8faea0b6ab7887fc Mon Sep 17 00:00:00 2001 From: Marc-Antoine Thevenet Date: Wed, 16 Mar 2016 15:04:47 -0400 Subject: [PATCH 01/14] :fr: typos :fr: typos --- languages.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/languages.yaml b/languages.yaml index 086dd21..b62c25a 100644 --- a/languages.yaml +++ b/languages.yaml @@ -14,13 +14,13 @@ fr: PLUGIN_COMMENTS: ADD_COMMENT: Ajouter un commentaire COMMENTS: Commentaires - EMAIL_NOT_CONFIGURED: Email non configurée + EMAIL_NOT_CONFIGURED: E-mail non configuré NEW_COMMENT_EMAIL_SUBJECT: 'Nouveau commentaire sur %1$s' NEW_COMMENT_EMAIL_BODY: '

Un nouveau commentaire a été posté sur %1$s par %3$s (%4$s).

Page: %2$s

Texte: %5$s

' EMAIL_FOOTER: '' - NAME: Nom: - EMAIL: Email: - WRITTEN_ON: Ecrit le + NAME: Nom : + EMAIL: E-mail : + WRITTEN_ON: Écrit le BY: par it: PLUGIN_COMMENTS: From 9d38761d44b514d987404c3fb8950f728717f38b Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 24 Mar 2016 09:03:25 +0100 Subject: [PATCH 02/14] Allow translating the comments form --- comments.php | 1 - comments.yaml | 18 +++++++++--------- languages.yaml | 20 ++++++++++++++++++++ templates/partials/comments.html.twig | 20 ++++++++++---------- 4 files changed, 39 insertions(+), 20 deletions(-) diff --git a/comments.php b/comments.php index 49be739..0bc7be9 100644 --- a/comments.php +++ b/comments.php @@ -117,7 +117,6 @@ class CommentsPlugin extends Plugin $this->enable([ 'onTwigTemplatePaths' => ['onTwigAdminTemplatePaths', 0], 'onAdminMenu' => ['onAdminMenu', 0], - 'onAdminTemplateNavPluginHook' => ['onAdminMenu', 0], //DEPRECATED 'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0], ]); diff --git a/comments.yaml b/comments.yaml index a401c97..b3e2a73 100644 --- a/comments.yaml +++ b/comments.yaml @@ -12,23 +12,23 @@ form: name: comments fields: - name: name - label: Name - placeholder: Enter your name + label: PLUGIN_COMMENTS.NAME_LABEL + placeholder: PLUGIN_COMMENTS.NAME_PLACEHOLDER autocomplete: on type: text validate: required: true - name: email - label: Email - placeholder: Enter your email address + label: PLUGIN_COMMENTS.EMAIL_LABEL + placeholder: PLUGIN_COMMENTS.EMAIL_PLACEHOLDER type: email validate: required: true - name: text - label: Message - placeholder: Enter your message + label: PLUGIN_COMMENTS.MESSAGE_LABEL + placeholder: PLUGIN_COMMENTS.MESSAGE_PLACEHOLDER type: textarea validate: required: true @@ -62,15 +62,15 @@ form: buttons: - type: submit - value: Submit + value: PLUGIN_COMMENTS.SUBMIT_COMMENT_BUTTON_TEXT process: - email: - subject: "[New Comment] from {{ form.value.name|e }}" + subject: PLUGIN_COMMENTS.EMAIL_NEW_COMMENT_SUBJECT body: "{% include 'forms/data.html.twig' %}" # - captcha: # recatpcha_secret: ej32oiej23oiej32oijeoi32jeio32je - addComment: - - message: Thank you for writing your comment! + - message: PLUGIN_COMMENTS.THANK_YOU_MESSAGE diff --git a/languages.yaml b/languages.yaml index b62c25a..ef8a18a 100644 --- a/languages.yaml +++ b/languages.yaml @@ -10,6 +10,16 @@ en: EMAIL: Email: WRITTEN_ON: Written on BY: by + NAME_LABEL: "Name" + NAME_PLACEHOLDER: "Enter your name" + EMAIL_LABEL: "Email" + EMAIL_PLACEHOLDER: "Enter your email address" + MESSAGE_LABEL: "Comment" + MESSAGE_PLACEHOLDER: "Enter your comment" + SUBMIT_COMMENT_BUTTON_TEXT: "Submit" + EMAIL_NEW_COMMENT_SUBJECT: "[New Comment] from {{ form.value.name|e }}" + THANK_YOU_MESSAGE: "Thank you for writing your comment!" + fr: PLUGIN_COMMENTS: ADD_COMMENT: Ajouter un commentaire @@ -34,6 +44,16 @@ it: EMAIL: Email: WRITTEN_ON: Scritto il BY: da + NAME_LABEL: "Nome" + NAME_PLACEHOLDER: "Inserisci il tuo nome" + EMAIL_LABEL: "Email" + EMAIL_PLACEHOLDER: "Inserisci il tuo indirizzo email" + MESSAGE_LABEL: "Messaggio" + MESSAGE_PLACEHOLDER: "Inserisci il tuo commento" + SUBMIT_COMMENT_BUTTON_TEXT: "Invia" + EMAIL_NEW_COMMENT_SUBJECT: "[Nuovo commento] da {{ form.value.name|e }}" + THANK_YOU_MESSAGE: "Grazie per il tuo commento!" + ru: PLUGIN_COMMENTS: ADD_COMMENT: Добавить комментарий diff --git a/templates/partials/comments.html.twig b/templates/partials/comments.html.twig index 691dd86..cbb75fa 100644 --- a/templates/partials/comments.html.twig +++ b/templates/partials/comments.html.twig @@ -5,20 +5,20 @@
- {% for field in grav.config.plugins.comments.form.fields %} - {% set value = form.value(field.name) %} - {% if field.evaluateDefault %} - {% set value = evaluate(field.evaluateDefault) %} - {% endif %} -
- {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %} -
- {% endfor %} + {% for field in grav.config.plugins.comments.form.fields %} + {% set value = form.value(field.name) %} + {% if field.evaluateDefault %} + {% set value = evaluate(field.evaluateDefault) %} + {% endif %} +
+ {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %} +
+ {% endfor %}
{% for button in grav.config.plugins.comments.form.buttons %} - + {% endfor %}
From 7014a07879ebaeac1fdc422fef387063bec672dd Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 31 Mar 2016 11:10:16 +0200 Subject: [PATCH 03/14] Drop beta message --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index e1d4eda..b023a5f 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,6 @@ 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 Comments plugin is easy to install with GPM. From 570467430a098ed824374f4228326fc154aa2816 Mon Sep 17 00:00:00 2001 From: Marc-Antoine Thevenet Date: Mon, 11 Apr 2016 11:40:51 -0400 Subject: [PATCH 04/14] :fr: update + arranged alphabetically :fr: update + arranged alphabetically --- languages.yaml | 62 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/languages.yaml b/languages.yaml index ef8a18a..05473d5 100644 --- a/languages.yaml +++ b/languages.yaml @@ -1,3 +1,16 @@ +de: + PLUGIN_COMMENTS: + ADD_COMMENT: Kommentar hinzufügen + COMMENTS: Kommentare + EMAIL_NOT_CONFIGURED: Email nicht konfiguriert + NEW_COMMENT_EMAIL_SUBJECT: 'Neuer Kommentar für %1$s' + NEW_COMMENT_EMAIL_BODY: '

Ein neuer Kommentar am %1$s von %3$s (%4$s).

Seite: %2$s

Text: %5$s

' + EMAIL_FOOTER: '' + NAME: Name: + EMAIL: Email: + WRITTEN_ON: geschrieben am + BY: von + en: PLUGIN_COMMENTS: ADD_COMMENT: Add a comment @@ -26,12 +39,22 @@ fr: COMMENTS: Commentaires EMAIL_NOT_CONFIGURED: E-mail non configuré NEW_COMMENT_EMAIL_SUBJECT: 'Nouveau commentaire sur %1$s' - NEW_COMMENT_EMAIL_BODY: '

Un nouveau commentaire a été posté sur %1$s par %3$s (%4$s).

Page: %2$s

Texte: %5$s

' + NEW_COMMENT_EMAIL_BODY: '

Un nouveau commentaire a été publié sur %1$s par %3$s (%4$s).

Page : %2$s

Texte : %5$s

' EMAIL_FOOTER: '' NAME: Nom : EMAIL: E-mail : WRITTEN_ON: Écrit le BY: par + NAME_LABEL: "Nom" + NAME_PLACEHOLDER: "Indiquez votre nom" + EMAIL_LABEL: "E-mail" + EMAIL_PLACEHOLDER: "Indiquez votre adresse e-mail" + MESSAGE_LABEL: "Commentaire" + MESSAGE_PLACEHOLDER: "Rédigez votre commentaire" + SUBMIT_COMMENT_BUTTON_TEXT: "Envoyer" + EMAIL_NEW_COMMENT_SUBJECT: "[Nouveau commentaire] de {{ form.value.name|e }}" + THANK_YOU_MESSAGE: "Merci d'avoir rédigé votre commentaire !" + it: PLUGIN_COMMENTS: ADD_COMMENT: Aggiungi un commento @@ -53,6 +76,19 @@ it: SUBMIT_COMMENT_BUTTON_TEXT: "Invia" EMAIL_NEW_COMMENT_SUBJECT: "[Nuovo commento] da {{ form.value.name|e }}" THANK_YOU_MESSAGE: "Grazie per il tuo commento!" + +pl: + PLUGIN_COMMENTS: + ADD_COMMENT: Dodaj komentarz + COMMENTS: Komentarzy + EMAIL_NOT_CONFIGURED: Email jest nie skofigurowany + NEW_COMMENT_EMAIL_SUBJECT: 'Nowy komentarz %1$s' + NEW_COMMENT_EMAIL_BODY: '

Pojawił się nowy komentarz, napisany %1$s przez %3$s (%4$s).

Strona: %2$s

Treść: %5$s

' + EMAIL_FOOTER: '' + NAME: Imię: + EMAIL: Email: + WRITTEN_ON: Napisany przez + BY: przez ru: PLUGIN_COMMENTS: @@ -66,27 +102,3 @@ ru: EMAIL: Email: WRITTEN_ON: Написан в BY: от -pl: - PLUGIN_COMMENTS: - ADD_COMMENT: Dodaj komentarz - COMMENTS: Komentarzy - EMAIL_NOT_CONFIGURED: Email jest nie skofigurowany - NEW_COMMENT_EMAIL_SUBJECT: 'Nowy komentarz %1$s' - NEW_COMMENT_EMAIL_BODY: '

Pojawił się nowy komentarz, napisany %1$s przez %3$s (%4$s).

Strona: %2$s

Treść: %5$s

' - EMAIL_FOOTER: '' - NAME: Imię: - EMAIL: Email: - WRITTEN_ON: Napisany przez - BY: przez -de: - PLUGIN_COMMENTS: - ADD_COMMENT: Kommentar hinzufügen - COMMENTS: Kommentare - EMAIL_NOT_CONFIGURED: Email nicht konfiguriert - NEW_COMMENT_EMAIL_SUBJECT: 'Neuer Kommentar für %1$s' - NEW_COMMENT_EMAIL_BODY: '

Ein neuer Kommentar am %1$s von %3$s (%4$s).

Seite: %2$s

Text: %5$s

' - EMAIL_FOOTER: '' - NAME: Name: - EMAIL: Email: - WRITTEN_ON: geschrieben am - BY: von From 6b64dcf8007f20b3b5a043c8be97021a257f5642 Mon Sep 17 00:00:00 2001 From: janklostermann Date: Mon, 25 Apr 2016 16:12:30 +0200 Subject: [PATCH 05/14] Enhanced German translation --- languages.yaml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/languages.yaml b/languages.yaml index 05473d5..8040738 100644 --- a/languages.yaml +++ b/languages.yaml @@ -10,7 +10,15 @@ de: EMAIL: Email: WRITTEN_ON: geschrieben am BY: von - + NAME_LABEL: "Name" + NAME_PLACEHOLDER: "Namen eingeben" + EMAIL_LABEL: "Email" + EMAIL_PLACEHOLDER: "Email-Adresse eingeben" + MESSAGE_LABEL: "Kommentar" + MESSAGE_PLACEHOLDER: "Kommentar eingeben" + SUBMIT_COMMENT_BUTTON_TEXT: "Absenden" + EMAIL_NEW_COMMENT_SUBJECT: "[Neuer Kommentar] von {{ form.value.name|e }}" + THANK_YOU_MESSAGE: "Vielen Dank für den Kommentar!" en: PLUGIN_COMMENTS: ADD_COMMENT: Add a comment From fd106be103d197c175d8f031edee73c12ae40821 Mon Sep 17 00:00:00 2001 From: Renata Date: Thu, 5 May 2016 07:56:44 -0300 Subject: [PATCH 06/14] Add Brazilian Portuguese (pt-br) translation (#23) --- languages.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/languages.yaml b/languages.yaml index 8040738..ae6a2f1 100644 --- a/languages.yaml +++ b/languages.yaml @@ -110,3 +110,25 @@ ru: EMAIL: Email: WRITTEN_ON: Написан в BY: от + +pt-br: + PLUGIN_COMMENTS: + ADD_COMMENT: Escreva um comentário + COMMENTS: Comentários + EMAIL_NOT_CONFIGURED: E-mail não configurado + NEW_COMMENT_EMAIL_SUBJECT: 'Novo comentário em %1$s' + NEW_COMMENT_EMAIL_BODY: '

Um novo comentário foi feito em %1$s por %3$s (%4$s).

Página: %2$s

Texto: %5$s

' + EMAIL_FOOTER: '' + NAME: Name: + EMAIL: Email: + WRITTEN_ON: Publicado em + BY: por + NAME_LABEL: "Nome" + NAME_PLACEHOLDER: "Escreva seu nome" + EMAIL_LABEL: "E-mail" + EMAIL_PLACEHOLDER: "Escreva seu e-mail. Ex.: seunome@provedor.com.br" + MESSAGE_LABEL: "Comentário" + MESSAGE_PLACEHOLDER: "Escreva seu comentário" + SUBMIT_COMMENT_BUTTON_TEXT: "Enviar" + EMAIL_NEW_COMMENT_SUBJECT: "[Novo comentário] de {{ form.value.name|e }}" + THANK_YOU_MESSAGE: "Obrigada por enviar seu comentário!" \ No newline at end of file From 6a70718fc98e7854f2c0ed5530ca87dbbe41f8ce Mon Sep 17 00:00:00 2001 From: Raul E Watson Date: Mon, 30 May 2016 10:18:16 +0200 Subject: [PATCH 07/14] Add Spanish (es) translation (#25) --- languages.yaml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/languages.yaml b/languages.yaml index ae6a2f1..490ebf0 100644 --- a/languages.yaml +++ b/languages.yaml @@ -41,6 +41,28 @@ en: EMAIL_NEW_COMMENT_SUBJECT: "[New Comment] from {{ form.value.name|e }}" THANK_YOU_MESSAGE: "Thank you for writing your comment!" +es: + PLUGIN_COMMENTS: + ADD_COMMENT: Agregar un comentario + COMMENTS: Comentarios + EMAIL_NOT_CONFIGURED: El Email no está configurado + NEW_COMMENT_EMAIL_SUBJECT: 'Nuevo comentario en %1$s' + NEW_COMMENT_EMAIL_BODY: '

Un nuevo comentario se hizo en %1$s por %3$s (%4$s).

Page: %2$s

Text: %5$s

' + EMAIL_FOOTER: '' + NAME: Nombre: + EMAIL: Email: + WRITTEN_ON: Escrito en + BY: por + NAME_LABEL: "Nombre" + NAME_PLACEHOLDER: "Escriba su nombre" + EMAIL_LABEL: "Email" + EMAIL_PLACEHOLDER: "Escriba su email" + MESSAGE_LABEL: "Comentario" + MESSAGE_PLACEHOLDER: "Escriba su comentario" + SUBMIT_COMMENT_BUTTON_TEXT: "Enviar" + EMAIL_NEW_COMMENT_SUBJECT: "[Nuevo comentario] de {{ form.value.name|e }}" + THANK_YOU_MESSAGE: "Gracias por escribir su comentario!" + fr: PLUGIN_COMMENTS: ADD_COMMENT: Ajouter un commentaire @@ -131,4 +153,4 @@ pt-br: MESSAGE_PLACEHOLDER: "Escreva seu comentário" SUBMIT_COMMENT_BUTTON_TEXT: "Enviar" EMAIL_NEW_COMMENT_SUBJECT: "[Novo comentário] de {{ form.value.name|e }}" - THANK_YOU_MESSAGE: "Obrigada por enviar seu comentário!" \ No newline at end of file + THANK_YOU_MESSAGE: "Obrigada por enviar seu comentário!" From a95d0abd849ca77f21d9d19063219c0c5a0abe78 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 30 May 2016 11:16:08 +0200 Subject: [PATCH 08/14] Prevent a missing template problem on ignored routes --- comments.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/comments.php b/comments.php index 0bc7be9..662a77d 100644 --- a/comments.php +++ b/comments.php @@ -102,12 +102,9 @@ class CommentsPlugin extends Plugin if (!$this->isAdmin()) { $this->calculateEnable(); - - if ($this->enable) { - $this->enable([ - 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], - ]); - } + $this->enable([ + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], + ]); } else { /** @var Uri $uri */ From c0265d5524441098452537f946fc50a4ae55d53f Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Mon, 30 May 2016 11:19:22 +0200 Subject: [PATCH 09/14] Fill changelog --- CHANGELOG.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 316afe8..c74669e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v1.1.5 +## xx/xx/2016 + +1. [](#improved) + * Prevent a missing template problem on ignored routes + * Allow to translate the comments form + * Added spanish and brazilian portuguese translations + * Enhanced german, russian and french translations + # v1.1.4 ## 02/05/2016 @@ -25,7 +34,7 @@ 1. [](#improved) * Drop the autofocus on the comment form 1. [](#bugfix) - * Fix double encoding (#12) + * Fix double encoding (#12) # v1.1.0 ## 11/24/2015 @@ -36,7 +45,7 @@ 1. [](#improved) * Use date instead of gmdate to respect the server local time (thanks @bovisp) * Now works with multilang (thanks @bovisp) - + # v1.0.2 ## 11/13/2015 From 04078ba7e0b90d33e62028629ca830d44ab16495 Mon Sep 17 00:00:00 2001 From: gitname Date: Fri, 3 Jun 2016 01:26:16 -0700 Subject: [PATCH 10/14] Fix typos (#26) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b023a5f..a403d84 100644 --- a/README.md +++ b/README.md @@ -49,12 +49,12 @@ To set the enabled routes, create a `user/config/plugins/comments.yaml` file, co # Enabling Recaptcha -The plugin comes with Recaptcha integration. To make it work, create a `user/config/plugins/comments.yaml` file, copy in it the contents of `user/plugins/comments/comments.yaml` and uncomment the capthca form field and the captcha validation process. +The plugin comes with Recaptcha integration. To make it work, create a `user/config/plugins/comments.yaml` file, copy in it the contents of `user/plugins/comments/comments.yaml` and uncomment the captcha form field and the captcha validation process. Make sure you add your own Recaptcha `site` and `secret` keys too. # Where are the comments stored? -In the `user/data/comments` folder. They're organized by page route, so every page with a comment has a corresponding file. This enabled a quick load of all the page comments. +In the `user/data/comments` folder. They're organized by page route, so every page with a comment has a corresponding file. This enables a quick load of all the page comments. # Visualize comments From 60c8d091e62534e3f63818ca3000bd0416267df6 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 29 Jun 2016 18:56:06 +0200 Subject: [PATCH 11/14] Rework a bit the organization of the code. Added cache for comments --- comments.php | 139 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 56 deletions(-) diff --git a/comments.php b/comments.php index 662a77d..b486662 100644 --- a/comments.php +++ b/comments.php @@ -17,17 +17,15 @@ class CommentsPlugin extends Plugin { protected $route = 'comments'; protected $enable = false; - + protected $comments_cache_id; + /** * @return array */ public static function getSubscribedEvents() { return [ - 'onPluginsInitialized' => ['onPluginsInitialized', 0], - 'onFormProcessed' => ['onFormProcessed', 0], - 'onPageInitialized' => ['onPageInitialized', 10], - 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] + 'onPluginsInitialized' => ['onPluginsInitialized', 0] ]; } @@ -36,31 +34,24 @@ class CommentsPlugin extends Plugin */ public function onPageInitialized() { - if (!$this->isAdmin()) { - /** @var Page $page */ - $page = $this->grav['page']; - if (!$page) { - return; - } + /** @var Page $page */ + $page = $this->grav['page']; + if (!$page) { + return; + } - if ($this->enable) { - $header = $page->header(); - if (!isset($header->form)) { - $header->form = $this->grav['config']->get('plugins.comments.form'); - $page->header($header); - } + if ($this->enable) { + $header = $page->header(); + if (!isset($header->form)) { + $header->form = $this->grav['config']->get('plugins.comments.form'); + $page->header($header); } } } public function onTwigSiteVariables() { - if (!$this->isAdmin()) { - $this->grav['twig']->enable = $this->enable; - - if ($this->enable) { - $this->grav['twig']->comments = $this->fetchComments(); - } - } + $this->grav['twig']->enable = $this->enable; + $this->grav['twig']->comments = $this->fetchComments(); } /** @@ -95,42 +86,65 @@ class CommentsPlugin extends Plugin } } + /** + * Frontend side initialization + */ + public function initializeFrontend() + { + $this->calculateEnable(); + + if ($this->enable) { + $this->enable([ + 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], + 'onFormProcessed' => ['onFormProcessed', 0], + 'onPageInitialized' => ['onPageInitialized', 10], + 'onTwigSiteVariables' => ['onTwigSiteVariables', 0] + ]); + } + + $cache = $this->grav['cache']; + //init cache id + $this->comments_cache_id = md5('comments-data' . $cache->getKey()); + } + + /** + * Admin side initialization + */ + public function initializeAdmin() + { + /** @var Uri $uri */ + $uri = $this->grav['uri']; + + $this->enable([ + 'onTwigTemplatePaths' => ['onTwigAdminTemplatePaths', 0], + 'onAdminMenu' => ['onAdminMenu', 0], + 'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0], + ]); + + if (strpos($uri->path(), $this->config->get('plugins.admin.route') . '/' . $this->route) === false) { + return; + } + + $page = $this->grav['uri']->param('page'); + $comments = $this->getLastComments($page); + + if ($page > 0) { + echo json_encode($comments); + exit(); + } + + $this->grav['twig']->comments = $comments; + $this->grav['twig']->pages = $this->fetchPages(); + } + /** */ public function onPluginsInitialized() { - if (!$this->isAdmin()) { - - $this->calculateEnable(); - $this->enable([ - 'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0], - ]); - + if ($this->isAdmin()) { + $this->initializeAdmin(); } else { - /** @var Uri $uri */ - $uri = $this->grav['uri']; - - //Admin - $this->enable([ - 'onTwigTemplatePaths' => ['onTwigAdminTemplatePaths', 0], - 'onAdminMenu' => ['onAdminMenu', 0], - 'onDataTypeExcludeFromDataManagerPluginHook' => ['onDataTypeExcludeFromDataManagerPluginHook', 0], - ]); - - if (strpos($uri->path(), $this->config->get('plugins.admin.route') . '/' . $this->route) === false) { - return; - } - - $page = $this->grav['uri']->param('page'); - $comments = $this->getLastComments($page); - - if ($page > 0) { - echo json_encode($comments); - exit(); - } - - $this->grav['twig']->comments = $comments; - $this->grav['twig']->pages = $this->fetchPages(); + $this->initializeFrontend(); } } @@ -192,6 +206,10 @@ class CommentsPlugin extends Plugin } $file->save(Yaml::dump($data)); + + //clear cache + $this->grav['cache']->delete($this->comments_cache_id); + break; } } @@ -294,11 +312,20 @@ class CommentsPlugin extends Plugin * Return the comments associated to the current route */ private function fetchComments() { + $cache = $this->grav['cache']; + //search in cache + if ($comments = $cache->fetch($this->comments_cache_id)) { + return $comments; + } + $lang = $this->grav['language']->getLanguage(); $filename = $lang ? '/' . $lang : ''; $filename .= $this->grav['uri']->path() . '.yaml'; - return $this->getDataFromFilename($filename)['comments']; + $comments = $this->getDataFromFilename($filename)['comments']; + //save to cache if enabled + $cache->save($this->comments_cache_id, $comments); + return $comments; } /** From 0cf90a74d7c9d8270aa81ca592865d73f57d42b9 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 30 Jun 2016 11:41:12 +0200 Subject: [PATCH 12/14] Reset comments form after submit --- comments.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/comments.yaml b/comments.yaml index b3e2a73..05a16eb 100644 --- a/comments.yaml +++ b/comments.yaml @@ -72,5 +72,6 @@ form: # recatpcha_secret: ej32oiej23oiej32oijeoi32jeio32je - addComment: - message: PLUGIN_COMMENTS.THANK_YOU_MESSAGE + - reset: true From ee608539d469a814f0b13844d4bc9fcefea9401b Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 30 Jun 2016 14:08:59 +0200 Subject: [PATCH 13/14] Handle logged in users by not requiring username/email Still post them as hidden to overcome validation, but still overwrite the values in backend to avoid manipulation --- comments.php | 6 ++++++ templates/partials/comments.html.twig | 18 +++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/comments.php b/comments.php index b486662..00b9790 100644 --- a/comments.php +++ b/comments.php @@ -174,6 +174,12 @@ class CommentsPlugin extends Plugin $email = filter_var(urldecode($post['email']), FILTER_SANITIZE_STRING); $title = filter_var(urldecode($post['title']), FILTER_SANITIZE_STRING); + $user = $this->grav['user']; + if ($user->authenticated) { + $name = $user->fullname; + $email = $user->email; + } + /** @var Language $language */ $language = $this->grav['language']; $lang = $language->getLanguage(); diff --git a/templates/partials/comments.html.twig b/templates/partials/comments.html.twig index cbb75fa..4a161ed 100644 --- a/templates/partials/comments.html.twig +++ b/templates/partials/comments.html.twig @@ -11,9 +11,21 @@ {% if field.evaluateDefault %} {% set value = evaluate(field.evaluateDefault) %} {% endif %} -
- {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %} -
+ {% if grav.user.authenticated %} + {% if field.name == 'name' %} + + {% elseif field.name == 'email' %} + + {% else %} +
+ {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %} +
+ {% endif %} + {% else %} +
+ {% include "forms/fields/#{field.type}/#{field.type}.html.twig" %} +
+ {% endif %} {% endfor %}
From ee89137f81b29cbe4d2cf178a59945bfc2205182 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Thu, 14 Jul 2016 21:52:54 +0200 Subject: [PATCH 14/14] Prepare release --- CHANGELOG.md | 7 +++++-- blueprints.yaml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c74669e..177e4e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,14 @@ -# v1.1.5 -## xx/xx/2016 +# v1.2.0 +## 07/14/2016 1. [](#improved) * Prevent a missing template problem on ignored routes * Allow to translate the comments form * Added spanish and brazilian portuguese translations * Enhanced german, russian and french translations + * Added cache for comments + * Handle logged in users by not requiring username/email + * Reset the comments form after a comment is submitted # v1.1.4 ## 02/05/2016 diff --git a/blueprints.yaml b/blueprints.yaml index bd800f5..947edd0 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,5 +1,5 @@ name: Comments -version: 1.1.4 +version: 1.2.0 description: Adds a commenting functionality to your site icon: comment author: