This repository has been archived by the owner on Nov 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
52 lines (42 loc) · 2.12 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace mauricerenck\Traschtante;
use Kirby;
@include_once __DIR__ . '/vendor/autoload.php';
Kirby::plugin('mauricerenck/tratschtante', [
'options' => require_once(__DIR__ . '/config/options.php'),
'routes' => [
[
'pattern' => 'tratschtante/webhook/webmentionio',
'method' => 'POST',
'action' => function () {
$response = json_decode(file_get_contents('php://input'));
$receiver = new WebmentionReceiver();
$hookHelper = new HookHelper();
$webmention = [];
if ($response->secret !== option('mauricerenck.tratschtante.secret')) {
return 'PAGE NOT FOUND';
}
$targetPage = $receiver->getPageFromUrl($response->post->{'wm-target'});
if (is_null($targetPage)) {
return 'PAGE NOT FOUND';
}
$webmention['type'] = $receiver->getWebmentionType($response->post->{'wm-property'});
$webmention['target'] = $response->post->{'wm-target'};
$webmention['source'] = $response->post->{'wm-source'};
$webmention['published'] = (!is_null($response->post->published)) ? $response->post->published : $response->post->{'wm-received'};
$webmention['content'] = (isset($response->post->content) && isset($response->post->content->text)) ? $response->post->content->text : '';
$webmention['author'] = $receiver->getAuthor($response);
if ($webmention['type'] === 'MENTION') {
if (is_null($webmention['author']['name'])) {
$webmention['author']['name'] = $webmention['source'];
}
if (is_null($webmention['author']['url'])) {
$webmention['author']['url'] = $webmention['source'];
}
}
$hookHelper->triggerHook('tratschtante.webhook.received', ['webmention' => $webmention, 'targetPage' => $targetPage]);
return $webmention;
}
],
]
]);