Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #116

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# v1.2.9
## 13/05/2024

1. [](#improved)
* Changed icon to ["text bubble"](https://fontawesome.com/icons/comment?f=classic&s=solid) in grav admin menu
* The "Load more" button under the "Comments in the last 7 days" table was fixed
* The styling of comments is improved
1. [](#bugfix)
* Fix for escaping problem [#107](https://github.com/getgrav/grav-plugin-comments/issues/107)

# v1.2.8
## 09/10/2020

Expand Down
11 changes: 6 additions & 5 deletions admin/templates/comments.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% endif %}

{% block titlebar %}
<h1><i class="fa fa-fw fa-file-text-o"></i> {{ "PLUGIN_COMMENTS.COMMENTS"|tu }}</h1>
<h1><i class="fa fa-fw fa-comment"></i> {{ "PLUGIN_COMMENTS.COMMENTS"|tu }}</h1>
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -42,12 +42,13 @@
</style>

<script>
let totalRetrieved = 30;
$(function() {
var currentPage = 0;

$(document).on('click tap', '.js__load-more', function(event) {
$.getJSON(window.location + '/page:' + (currentPage + 1))
.success(function(response) {
.done(function(response) {
currentPage = parseInt(response.page);

response.comments.forEach(function(comment) {
Expand All @@ -59,7 +60,7 @@
'</tr>');
})

var totalRetrieved = response.totalRetrieved * (parseInt(response.page) + 1);
totalRetrieved += response.comments.length;

$('.totalRetrieved').html(totalRetrieved);
$('.totalAvailable').html(response.totalAvailable);
Expand All @@ -68,7 +69,7 @@
$('.js__load-more').hide();
}
})
.error(function() {
.fail(function() {
alert('Unexpected error');
});
});
Expand All @@ -88,7 +89,7 @@
{% for comment in grav.twig.comments.comments %}
<tr>
<td class="author">{{comment.author}}</td>
<td class="comment">{{comment.text}}</td>
<td class="comment">{{comment.text|raw}}</td>
<td class="details"><strong>Page</strong>: {{comment.pageTitle}}<br>
<strong>Date</strong>: {{comment.date}}</td>
</tr>
Expand Down
23 changes: 17 additions & 6 deletions comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,11 @@ public function onFormProcessed(Event $event)

$path = $this->grav['uri']->path();

$lang = filter_var(urldecode($post['lang']), 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);
$title = filter_var(urldecode($post['title']), FILTER_SANITIZE_STRING);
$lang = htmlspecialchars(urldecode($post['lang']), ENT_QUOTES);
$text = htmlspecialchars(urldecode($post['text']), ENT_QUOTES);
$name = htmlspecialchars(urldecode($post['name']), ENT_QUOTES);
$email = filter_var(urldecode($post['email']), FILTER_SANITIZE_EMAIL);
$title = htmlspecialchars(urldecode($post['title']), ENT_QUOTES);

if (isset($this->grav['user'])) {
$user = $this->grav['user'];
Expand Down Expand Up @@ -361,6 +361,17 @@ private function fetchComments() {
$comments = isset($data['comments']) ? $data['comments'] : null;
//save to cache if enabled
$cache->save($this->comments_cache_id, $comments);

$pattern = '/\r\n/i';
$replacement = '<br>';

// Iterate through each element of the array and apply preg_replace
if ($comments != null) {
foreach ($comments as &$value) {
$value = preg_replace($pattern, $replacement, $value);
}
}

return $comments;
}

Expand Down Expand Up @@ -422,7 +433,7 @@ public function onTwigAdminTemplatePaths()
*/
public function onAdminMenu()
{
$this->grav['twig']->plugins_hooked_nav['PLUGIN_COMMENTS.COMMENTS'] = ['route' => $this->route, 'icon' => 'fa-file-text'];
$this->grav['twig']->plugins_hooked_nav['PLUGIN_COMMENTS.COMMENTS'] = ['route' => $this->route, 'icon' => 'fa-comment'];
}

/**
Expand Down
20 changes: 18 additions & 2 deletions templates/partials/comments.html.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
{% if enable_comments_plugin %}
{% set scope = scope ?: 'data.' %}

<style>
table {
border-collapse:separate;
border-spacing: 0 10px;
}

td {
padding: 10px;
border: solid 1px #caced7;
border-radius: 5px;
}
</style>

<h3>{{'PLUGIN_COMMENTS.ADD_COMMENT'|t}}</h3>

<form name="{{ grav.config.plugins.comments.form.name }}"
Expand Down Expand Up @@ -29,6 +42,8 @@
{% endif %}
{% endfor %}
{% include "forms/fields/formname/formname.html.twig" %}

<br />

<div class="buttons">
{% for button in grav.config.plugins.comments.form.buttons %}
Expand All @@ -49,9 +64,10 @@
{% for comment in comments|array_reverse %}
<tr>
<td>
{{comment.text}}
{{comment.text|raw}}
<br />
<br />
{{'PLUGIN_COMMENTS.WRITTEN_ON'|t}} {{comment.date|e}} {{'PLUGIN_COMMENTS.BY'|t}} {{comment.author}}
<small>{{'PLUGIN_COMMENTS.WRITTEN_ON'|t}} {{comment.date|e}} {{'PLUGIN_COMMENTS.BY'|t}} {{comment.author}}</small>
</td>
</tr>
{% endfor %}
Expand Down