Skip to content

Commit

Permalink
feat: handle new indieconnector types
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricerenck committed Jul 23, 2024
1 parent 553d0b2 commit d6696b5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
6 changes: 1 addition & 5 deletions components/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
$kommentReceiver->storeData($newEntry, $targetPage);
},
'indieConnector.webmention.received' => function ($webmention, $targetPage) {
if (!option('mauricerenck.komments.enable-webmention-support')) {
return;
}

if (!option('mauricerenck.komments.debug')) {
if (!option('mauricerenck.komments.debug', false)) {
$time = time();
file_put_contents('webmentionhook.' . $time . '.json', json_encode($webmention));
}
Expand Down
2 changes: 1 addition & 1 deletion index.js

Large diffs are not rendered by default.

34 changes: 30 additions & 4 deletions utils/receiveKomment.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,39 @@ public function createKomment($webmention, $spamlevel = 0, $isVerified = false,
'published' => $webmention['published'],
'komment' => $this->setKomment($webmention['content']),
'quote' => (isset($webmention['quote'])) ? $this->setKomment($webmention['quote']) : null,
'kommentType' => $webmention['type'],
'kommentType' => $this->convertWebmentionTypes($webmention['type']),
'status' => $this->setStatus($webmention['type'], $publishComments),
'spamlevel' => $spamlevel,
'verified' => $isVerified
];
}

public function convertWebmentionTypes($type) {

$oldTypes = ['LIKE', 'REPOST', 'BOOKMARK', 'REPLY', 'RSVP', 'MENTION', 'INVITE', 'KOMMENT'];

if(in_array($type, $oldTypes)) { return $type; }

switch($type) {
case 'like-of':
return 'LIKE';
case 'repost-of':
return 'REPOST';
case 'bookmark-of':
return 'BOOKMARK';
case 'in-reply-to':
return 'REPLY';
case 'rsvp':
return 'RSVP';
case 'mention-of':
return 'MENTION';
case 'invite':
return 'INVITE';
default:
return 'KOMMENT';
}
}

public function getAuthorData(array $author) {
return [
'name' => $author['name'] ?? null,
Expand All @@ -87,16 +113,16 @@ public function getPageFromUrl(string $url)
$targetPage = page(site()->homePageId());
} elseif (!$targetPage = page($path)) {
$targetPage = page(kirby()->router()->call($path));

if ($targetPage->isErrorPage()) {
return null;
}
}

if (is_null($targetPage)) {
return null;
}

return $targetPage;
}

Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php return array(
'root' => array(
'name' => 'mauricerenck/komments',
'pretty_version' => '2.0.3',
'version' => '2.0.3.0',
'pretty_version' => '2.0.5',
'version' => '2.0.5.0',
'reference' => NULL,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand All @@ -29,8 +29,8 @@
'dev_requirement' => false,
),
'mauricerenck/komments' => array(
'pretty_version' => '2.0.3',
'version' => '2.0.3.0',
'pretty_version' => '2.0.5',
'version' => '2.0.5.0',
'reference' => NULL,
'type' => 'kirby-plugin',
'install_path' => __DIR__ . '/../../',
Expand Down

0 comments on commit d6696b5

Please sign in to comment.