Skip to content

Commit

Permalink
Code and compatibility improvements (#66)
Browse files Browse the repository at this point in the history
* chore: show author action

* chore: removed console log

* improvement: added mockery

* feat: removed moderation cookies

BREAKING CHANGE: Komments plugin will not use cookies anymore

* improvement: use structures in snippets no more arrays

BREAKING CHANGE: comments and replies are splitted, strcutures are used now

* chore: add deprecation warning

* improvement: base utils optimization

* feat: added frontend class (wip)

* feat: removed unused quote feature

BRAKING CHANGE: Quotes are getting removed

* improvement: moved kommentsAreExpired to frontend class

* feat: multilang page mock

* improvement: tests

* chore: ignore tilde folder

* chore: remove dump

* chore: class loader

* improvement: refactored classes and tests

* improvement: remove needless api calls

* fix: better backwards compatibility with Kirby 3

* chore: added translations

* fix: show all language comments in panel

* improvement: reduced css

BREAKING CHANGE: CSS has been reduced to a minimum
  • Loading branch information
mauricerenck authored Mar 4, 2024
1 parent d1e2fd9 commit 51e4ccf
Show file tree
Hide file tree
Showing 43 changed files with 2,017 additions and 926 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
/media
/kirby
/site/cache
/~
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v16.3.0
v20.11.1
7 changes: 7 additions & 0 deletions BREAKING_CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Moderation Cookies entfernt
- Snippets angepasst
- Comments und Replies getrennt
- Alles jetzt als Object, keine Arrays mehr
- hasQueuedKomments DEPRECATED
- Quote ist weg, wurde sowieso nicht aktiv genutzt
-
93 changes: 62 additions & 31 deletions assets/komments.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/komments.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/komments.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ docReady(function () {
link.addEventListener('click', (event) => {
const kommentId = event.target.dataset.id;
const kommentHandle = event.target.dataset.handle;
console.log(kommentId, kommentHandle);

kommentForm.querySelector('input[name=replyTo]').value = kommentId;
kommentForm.querySelector('input[name=replyHandle]').value = kommentHandle;
replyHandleDisplay.innerHTML = `<a href="#komment_${kommentId}">@${kommentHandle}</a>`;
Expand Down
5 changes: 0 additions & 5 deletions blueprints/sections/komments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ fields:
MENTION: Mention
KOMMENT: Komment
SPAM: Spam

quote:
type: textarea
label: Quote
width: 1/1
komment:
type: textarea
label: Komment
Expand Down
74 changes: 10 additions & 64 deletions components/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,68 +2,10 @@

namespace mauricerenck\Komments;

use Structure;
use Kirby\Http\Response;

return [
'routes' => [
[
'pattern' => 'komments/queued',
'action' => function () {

$pendingKomments = [];
$collection = site()->index();

foreach ($collection as $item) {
if ($item->kommentsInbox()->isNotEmpty()) {
foreach ($item->kommentsInbox()->yaml() as $komment) {
$komment['spamlevel'] = (isset($komment['spamlevel'])) ? $komment['spamlevel'] : 0; // backward compatiblity

if (($komment['status'] === 'false' || $komment['status'] === false) && (integer)$komment['spamlevel'] === 0) {
$pendingKomments[] = [
'author' => $komment['author'],
'komment' => $komment['komment'],
'kommentType' => (isset($komment['kommenttype'])) ? $komment['kommenttype'] : 'komment', // backward compatiblity
'image' => $komment['avatar'],
'title' => (string) $item->title(),
'url' => $item->panel()->url(),
];
}
}
}
}

return new Response(json_encode($pendingKomments), 'application/json');
}
],
[
'pattern' => 'komments/spam',
'action' => function () {
$spamKomments = [];
$collection = site()->index();


foreach ($collection as $item) {
if ($item->kommentsInbox()->isNotEmpty()) {
foreach ($item->kommentsInbox()->yaml() as $komment) {
$komment['spamlevel'] = (isset($komment['spamlevel'])) ? $komment['spamlevel'] : 0; // backward compatiblity
if ((integer)$komment['spamlevel'] > 0) {
$spamKomments[] = [
'author' => $komment['author'],
'komment' => $komment['komment'],
'kommentType' => (isset($komment['kommenttype'])) ? $komment['kommenttype'] : 'komment', // backward compatiblity
'image' => $komment['avatar'],
'title' => (string) $item->title(),
'url' => $item->panel()->url(),
];
}
}
}
}

return new Response(json_encode($spamKomments), 'application/json');
}
],
[
'pattern' => 'komments/spam',
'method' => 'POST',
Expand All @@ -74,7 +16,7 @@
$kommentModeration->markAsSpam($formData['pageSlug'], $formData['kommentId'], $formData['isSpam']);

return new Response(json_encode(['message' => 'okay']), 'application/json');
}
},
],
[
'pattern' => 'komments/verify',
Expand All @@ -83,10 +25,14 @@
$formData = kirby()->request()->data();

$kommentModeration = new KommentModeration();
$kommentModeration->markAsVerified($formData['pageSlug'], $formData['kommentId'], $formData['isVerified']);
$kommentModeration->markAsVerified(
$formData['pageSlug'],
$formData['kommentId'],
$formData['isVerified']
);

return new Response(json_encode(['message' => 'okay']), 'application/json');
}
},
],
[
'pattern' => 'komments/publish',
Expand All @@ -98,7 +44,7 @@
$kommentModeration->publish($formData['pageSlug'], $formData['kommentId'], $formData['isPublished']);

return new Response(json_encode(['message' => 'okay']), 'application/json');
}
},
],
[
'pattern' => 'komments/delete',
Expand All @@ -110,7 +56,7 @@
$kommentModeration->delete($formData['pageSlug'], $formData['kommentId']);

return new Response(json_encode(['message' => 'okay']), 'application/json');
}
},
],
]
],
];
15 changes: 8 additions & 7 deletions components/areas.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace mauricerenck\Komments;

return [
'komments' => function ($kirby) {
'komments' => function () {
return [
'label' => 'Komments',
'icon' => 'chat',
Expand All @@ -18,14 +18,15 @@
'title' => 'Komments',
'props' => [
'queuedKomments' => function () {
$kommentUtils = new KommentBaseUtils();
return $kommentUtils->getPendingKomments();
$kommentModeration = new KommentModeration();
return $kommentModeration->getSiteWideComments('pending');
},
'kirbyVersion' => kirby()->version(),
],
];
}
]
]
},
],
],
];
}
},
];
15 changes: 7 additions & 8 deletions components/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@

return [
'kommentType' => [
'props' => [
]
'props' => [],
],
'kommentsPending' => [
'props' => [
'queuedComments' => function () {
$kommentUtils = new KommentBaseUtils();
$pendingComments = $kommentUtils->getPendingCommentCount();
$pendingComments = $kommentUtils->getSiteWideCommentCount('pending');
return $pendingComments;
},
]
],
],
'komments' => [
'props' => [
'queuedComments' => function () {
$kommentUtils = new KommentBaseUtils();
return $kommentUtils->getPendingKomments();
$kommentModeration = new KommentModeration();
return $kommentModeration->getSiteWideComments('pending');
},
]
]
],
],
];
22 changes: 7 additions & 15 deletions components/page-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,19 @@

namespace mauricerenck\Komments;

use mauricerenck\Komments\KommentBaseUtils;
use mauricerenck\Komments\KommentModeration;

return [
'kommentCount' => function () {
$count = 0;
foreach ($this->kommentsInbox()->yaml() as $komment) {
if ($komment['status'] !== 'false' && $komment['status'] !== false) {
$count++;
}
}
return $count;
'kommentCount' => function ($language = null) {
$baseUtils = new KommentBaseUtils();
return $baseUtils->getCommentsCountOfPage($this, 'published');
},
'hasQueuedKomments' => function ($kommentId, $kommenStatus) {
$kommentModeration = new KommentModeration();
return $kommentModeration->pageHasQueuedKomments($kommentId, $kommenStatus);
deprecated('`hasQueuedKomments()` is deprecated, queued comment cookies habe been removed, this is no more needed. `hasQueuedKomments()` will be removed in future versions.');
return 0;
},
'kommentsAreEnabled' => function () {
$kommentBaseUtils = new KommentBaseUtils();
$kommentsFrontend = new KommentsFrontend();

if ($kommentBaseUtils->kommentsAreExpired($this)) {
if ($kommentsFrontend->kommentsAreExpired($this)) {
return false;
}

Expand Down
6 changes: 3 additions & 3 deletions components/site-methods.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
return [
'numberOfPendingComments' => function () {
$kommentBaseUtils = new KommentBaseUtils();
return $kommentBaseUtils->getPendingCommentCount();
return $kommentBaseUtils->getSiteWideCommentCount('pending');
},
'numberOfSpamComments' => function () {
$kommentBaseUtils = new KommentBaseUtils();
return $kommentBaseUtils->getSpamCommentCount();
}
return $kommentBaseUtils->getSiteWideCommentCount('spam');
},
];
Loading

0 comments on commit 51e4ccf

Please sign in to comment.