Skip to content

Commit

Permalink
fix: add note to author info
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricerenck committed Oct 7, 2024
1 parent 35acf17 commit d37148a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/Microformats.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -149,6 +149,7 @@ public function getAuthor($microformats)
'name' => null,
'url' => null,
'photo' => null,
'note' => null,
];

foreach ($microformats['items'] as $item) {
Expand Down Expand Up @@ -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'])) {
Expand All @@ -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,
];
}

Expand Down
30 changes: 30 additions & 0 deletions tests/lib/MicroformatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -821,6 +826,7 @@ public function testGetAuthorFromHCardMissingValue()
'name' => 'Maurice Renck',
'photo' => null,
'url' => 'https://maurice-renck.de',
'note' => null,
];

$microformats = new Microformats();
Expand Down Expand Up @@ -848,6 +854,7 @@ public function testGetAuthorFromHCardCorruptValue()
'name' => 'Maurice Renck',
'photo' => null,
'url' => 'https://maurice-renck.de',
'note' => null,
];

$microformats = new Microformats();
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/lib/WebmentionReceiverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit d37148a

Please sign in to comment.