diff --git a/CHANGELOG.md b/CHANGELOG.md index f2d5015..16ef711 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +# v1.2.8 +## mm/dd/2020 + +1. [](#bugfix) + * Fix for PHP 7.4 [#81](https://github.com/getgrav/grav-plugin-comments/issues/81) + * Fix for allowing path in form submission [#86](https://github.com/getgrav/grav-plugin-comments/issues/86) [#80](https://github.com/getgrav/grav-plugin-comments/issues/80) + # v1.2.7 ## 05/12/2017 diff --git a/comments.php b/comments.php index 7a59543..282242e 100644 --- a/comments.php +++ b/comments.php @@ -73,8 +73,17 @@ public function onFormPageHeaderProcessed(Event $event) } public function onTwigSiteVariables() { - $this->grav['twig']->enable_comments_plugin = $this->enable; - $this->grav['twig']->comments = $this->fetchComments(); + // Old way + $enabled = $this->enable; + $comments = $this->fetchComments(); + + $this->grav['twig']->enable_comments_plugin = $enabled; + $this->grav['twig']->comments = $comments; + + // New way + $this->grav['twig']->twig_vars['enable_comments_plugin'] = $enabled; + $this->grav['twig']->twig_vars['comments'] = $comments; + } /** @@ -189,8 +198,9 @@ public function onFormProcessed(Event $event) case 'addComment': $post = isset($_POST['data']) ? $_POST['data'] : []; + $path = $this->grav['uri']->path(); + $lang = filter_var(urldecode($post['lang']), FILTER_SANITIZE_STRING); - $path = filter_var(urldecode($post['path']), FILTER_SANITIZE_STRING); $text = filter_var(urldecode($post['text']), FILTER_SANITIZE_STRING); $name = filter_var(urldecode($post['name']), FILTER_SANITIZE_STRING); $email = filter_var(urldecode($post['email']), FILTER_SANITIZE_STRING); @@ -347,7 +357,8 @@ private function fetchComments() { $filename = $lang ? '/' . $lang : ''; $filename .= $this->grav['uri']->path() . '.yaml'; - $comments = $this->getDataFromFilename($filename)['comments']; + $data = $this->getDataFromFilename($filename); + $comments = $data['comments'] ?? null; //save to cache if enabled $cache->save($this->comments_cache_id, $comments); return $comments; diff --git a/templates/partials/comments.html.twig b/templates/partials/comments.html.twig index 29d79b9..b1ff904 100644 --- a/templates/partials/comments.html.twig +++ b/templates/partials/comments.html.twig @@ -1,4 +1,4 @@ -{% if grav.twig.enable_comments_plugin %} +{% if enable_comments_plugin %} {% set scope = scope ?: 'data.' %}

{{'PLUGIN_COMMENTS.ADD_COMMENT'|t}}

@@ -46,7 +46,7 @@

{{'PLUGIN_COMMENTS.COMMENTS'|t}}

- {% for comment in grav.twig.comments|array_reverse %} + {% for comment in comments|array_reverse %}
{{comment.text}}