Skip to content

Commit

Permalink
Fixes for #86 #81 #80
Browse files Browse the repository at this point in the history
  • Loading branch information
rhukster committed Sep 10, 2020
1 parent 563d7af commit 0683d93
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
19 changes: 15 additions & 4 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}

/**
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions templates/partials/comments.html.twig
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% if grav.twig.enable_comments_plugin %}
{% if enable_comments_plugin %}
{% set scope = scope ?: 'data.' %}

<h3>{{'PLUGIN_COMMENTS.ADD_COMMENT'|t}}</h3>
Expand Down Expand Up @@ -46,7 +46,7 @@
<h3>{{'PLUGIN_COMMENTS.COMMENTS'|t}}</h3>

<table>
{% for comment in grav.twig.comments|array_reverse %}
{% for comment in comments|array_reverse %}
<tr>
<td>
{{comment.text}}
Expand Down

2 comments on commit 0683d93

@NicoHood
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path inside the form config is not required anymore I guess?

- name: path
type: hidden
evaluateDefault: grav.uri.path

@rhukster
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that is till needed for the email to notify you which page the comment was on. Someone could still change that but it will not cause any damage,

Please sign in to comment.