From d37148abed02a55dc7a31d243d78cd2298786d9b Mon Sep 17 00:00:00 2001 From: Maurice Renck Date: Mon, 7 Oct 2024 10:51:33 +0200 Subject: [PATCH] fix: add note to author info --- lib/Microformats.php | 16 ++++++++++++++- tests/lib/MicroformatsTest.php | 30 ++++++++++++++++++++++++++++ tests/lib/WebmentionReceiverTest.php | 1 + 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/Microformats.php b/lib/Microformats.php index 64dc2de..38c3f05 100644 --- a/lib/Microformats.php +++ b/lib/Microformats.php @@ -52,7 +52,7 @@ public function includesBaseUrl(array|string $urls) return false; } - public function getTypes(array $microformats): array + public function getTypes(array $microformats): array | null { if (empty($microformats['items'])) { return null; @@ -149,6 +149,7 @@ public function getAuthor($microformats) 'name' => null, 'url' => null, 'photo' => null, + 'note' => null, ]; foreach ($microformats['items'] as $item) { @@ -220,6 +221,17 @@ public function getAuthorPhoto(array $hCard): string|null return !isset($photo[0]['value']) ? null : $photo[0]['value']; } + public function getAuthorNote(array $hCard): string|null + { + if (!isset($hCard['properties']['note'])) { + return null; + } + + $note = $this->returnArraySave($hCard['properties']['note']); + + return !isset($note[0]) ? null : $note[0]; + } + public function getAuthorFromHCard(array $hCard) { if (!isset($hCard['properties'])) { @@ -229,11 +241,13 @@ public function getAuthorFromHCard(array $hCard) $name = $this->getAuthorName($hCard); $url = $this->getAuthorUrl($hCard); $photo = $this->getAuthorPhoto($hCard); + $note = $this->getAuthorNote($hCard); return [ 'name' => $name, 'url' => $url, 'photo' => $photo, + 'note' => $note, ]; } diff --git a/tests/lib/MicroformatsTest.php b/tests/lib/MicroformatsTest.php index 75814ad..a58c13b 100644 --- a/tests/lib/MicroformatsTest.php +++ b/tests/lib/MicroformatsTest.php @@ -622,6 +622,7 @@ public function testGetAuthorDataHCard() 'name' => 'Maurice Renck', 'photo' => 'https://example.org/photo.png', 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $microformats = new Microformats(); @@ -665,6 +666,7 @@ public function testGetAuthorDataHEntryAuthor() 'name' => 'Maurice Renck', 'photo' => 'https://example.org/photo.png', 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $microformats = new Microformats(); @@ -702,6 +704,7 @@ public function testGetAuthorDataHEntryChildHcard() 'name' => 'Maurice Renck', 'photo' => 'https://example.org/photo.png', 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $microformats = new Microformats(); @@ -765,6 +768,7 @@ public function testGetAuthorDataMixed() 'name' => 'Maurice Renck', 'photo' => 'https://example.org/photo.png', 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $microformats = new Microformats(); @@ -793,6 +797,7 @@ public function testGetAuthorFromHCard() 'name' => 'Maurice Renck', 'photo' => 'https://example.org/photo.png', 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $microformats = new Microformats(); @@ -821,6 +826,7 @@ public function testGetAuthorFromHCardMissingValue() 'name' => 'Maurice Renck', 'photo' => null, 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $microformats = new Microformats(); @@ -848,6 +854,7 @@ public function testGetAuthorFromHCardCorruptValue() 'name' => 'Maurice Renck', 'photo' => null, 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $microformats = new Microformats(); @@ -922,6 +929,29 @@ public function testGetAuthorPhotoFromHCard() $this->assertEquals('https://example.org/photo.png', $result); } + /** + * @group microformats + * @testdox getAuthorNote - get author note from h-card + */ + public function testGetAuthorNoteFromHCard() + { + $hCard = [ + 'type' => ['h-card'], + 'properties' => [ + 'name' => ['Maurice Renck'], + 'url' => ['https://maurice-renck.de'], + 'photo' => [['value' => 'https://example.org/photo.png', 'alt' => '']], + 'note' => ['This is a note'], + ], + 'value' => 'Maurice Renck', + ]; + + $microformats = new Microformats(); + $result = $microformats->getAuthorNote($hCard); + + $this->assertEquals('This is a note', $result); + } + /** * @group microformats * @testdox getSummaryOrContent - get summary from h-entry diff --git a/tests/lib/WebmentionReceiverTest.php b/tests/lib/WebmentionReceiverTest.php index 75ccf93..4b6841d 100644 --- a/tests/lib/WebmentionReceiverTest.php +++ b/tests/lib/WebmentionReceiverTest.php @@ -211,6 +211,7 @@ public function testGetWebmentionData() 'name' => 'Maurice Renck', 'photo' => null, 'url' => 'https://maurice-renck.de', + 'note' => null, ]; $webmentionReceiver = new WebmentionReceiver('https://sender.tld', 'https://indie-connector.tld');