Skip to content

Commit 289b2b0

Browse files
committed
fix: some code cleanup
1 parent 5f8c91b commit 289b2b0

File tree

6 files changed

+53
-41
lines changed

6 files changed

+53
-41
lines changed
File renamed without changes.
File renamed without changes.

components/page-methods.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace mauricerenck\Komments;
4+
5+
use mauricerenck\Komments\KommentBaseUtils;
6+
use mauricerenck\Komments\KommentModeration;
7+
8+
return [
9+
'kommentCount' => function () {
10+
$count = 0;
11+
foreach ($this->kommentsInbox()->yaml() as $komment) {
12+
if ($komment['status'] !== 'false' && $komment['status'] !== false) {
13+
$count++;
14+
}
15+
}
16+
return $count;
17+
},
18+
'hasQueuedKomments' => function ($kommentId, $kommenStatus) {
19+
$kommentModeration = new KommentModeration();
20+
return $kommentModeration->pageHasQueuedKomments($kommentId, $kommenStatus);
21+
},
22+
'kommentsAreEnabled' => function () {
23+
$kommentBaseUtils = new KommentBaseUtils();
24+
25+
if ($kommentBaseUtils->kommentsAreExpired($this)) {
26+
return false;
27+
}
28+
29+
return $this->kommentsEnabledOnpage()->isEmpty() || $this->kommentsEnabledOnpage()->isTrue();
30+
},
31+
];

components/site-methods.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace mauricerenck\Komments;
4+
5+
use mauricerenck\Komments\KommentBaseUtils;
6+
7+
return [
8+
'numberOfPendingComments' => function () {
9+
$kommentBaseUtils = new KommentBaseUtils();
10+
return $kommentBaseUtils->getPendingCommentCount();
11+
},
12+
'numberOfSpamComments' => function () {
13+
$kommentBaseUtils = new KommentBaseUtils();
14+
return $kommentBaseUtils->getSpamCommentCount();
15+
}
16+
];
File renamed without changes.

index.php

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
namespace mauricerenck\Komments;
44

5-
use mauricerenck\Komments\KommentBaseUtils;
65
use mauricerenck\Komments\KommentModeration;
76
use mauricerenck\Komments\KommentReceiver;
8-
use mauricerenck\Komments\MastodonSender;
9-
use mauricerenck\Komments\WebmentionSender;
107
use Kirby;
118
use Kirby\Toolkit\V;
129
use Kirby\Toolkit\F;
@@ -15,62 +12,30 @@
1512
use Kirby\Data\Data;
1613
use Kirby\Data\yaml;
1714
use Kirby\Cms\Structure;
15+
use Kirby\Http\Response;
1816
use StdClass;
1917
use is_null;
2018
use json_encode;
21-
use \Response;
2219
use \Throwable;
2320

2421
@include_once __DIR__ . '/vendor/autoload.php';
2522

2623
Kirby::plugin('mauricerenck/komments', [
2724
'areas' => require_once(__DIR__ . '/components/areas.php'),
2825
'options' => require_once(__DIR__ . '/config/options.php'),
29-
'snippets' => require_once(__DIR__ . '/config/snippets.php'),
26+
'snippets' => require_once(__DIR__ . '/components/snippets.php'),
3027
'templates' => [
3128
'emails/newcomments' => __DIR__ . '/templates/emails/newComments.php'
3229
],
3330
'blueprints' => [
3431
'sections/komments' => __DIR__ . '/blueprints/sections/komments.yml'
3532
],
36-
'pageMethods' => [
37-
'kommentCount' => function () {
38-
$count = 0;
39-
foreach ($this->kommentsInbox()->yaml() as $komment) {
40-
if ($komment['status'] !== 'false' && $komment['status'] !== false) {
41-
$count++;
42-
}
43-
}
44-
return $count;
45-
},
46-
'hasQueuedKomments' => function ($kommentId, $kommenStatus) {
47-
$kommentModeration = new KommentModeration();
48-
return $kommentModeration->pageHasQueuedKomments($kommentId, $kommenStatus);
49-
},
50-
'kommentsAreEnabled' => function () {
51-
$kommentBaseUtils = new KommentBaseUtils();
52-
53-
if ($kommentBaseUtils->kommentsAreExpired($this)) {
54-
return false;
55-
}
56-
57-
return $this->kommentsEnabledOnpage()->isEmpty() || $this->kommentsEnabledOnpage()->isTrue();
58-
},
59-
],
60-
'siteMethods' => [
61-
'numberOfPendingComments' => function () {
62-
$kommentBaseUtils = new KommentBaseUtils();
63-
return $kommentBaseUtils->getPendingCommentCount();
64-
},
65-
'numberOfSpamComments' => function () {
66-
$kommentBaseUtils = new KommentBaseUtils();
67-
return $kommentBaseUtils->getSpamCommentCount();
68-
}
69-
],
33+
'pageMethods' => require_once(__DIR__ . '/components/page-methods.php'),
34+
'siteMethods' => require_once(__DIR__ . '/components/site-methods.php'),
7035
'fields' => require_once(__DIR__ . '/components/fields.php'),
7136
'translations' => require_once(__DIR__ . '/config/translations.php'),
72-
'api' => require_once(__DIR__ . '/config/api.php'),
73-
'hooks' => require_once(__DIR__ . '/config/hooks.php'),
37+
'api' => require_once(__DIR__ . '/components/api.php'),
38+
'hooks' => require_once(__DIR__ . '/components/hooks.php'),
7439
'routes' => [
7540
[
7641
'pattern' => 'komments/send',

0 commit comments

Comments
 (0)