Skip to content

Commit

Permalink
0.3.10
Browse files Browse the repository at this point in the history
- `OpdsEntryBook` add `content` property with HTML
  • Loading branch information
ewilan-riviere committed May 9, 2023
1 parent addbbe2 commit 0588b74
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kiwilan/php-opds",
"description": "PHP package to create OPDS feed for eBooks.",
"version": "0.3.0",
"version": "0.3.10",
"keywords": [
"php",
"ebook",
Expand Down
22 changes: 17 additions & 5 deletions src/Converters/OpdsXmlConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,27 @@ public function entryBook(OpdsEntryBook $entry): array
];
}

$media = $entry->media();
$mediaThumbnail = $entry->mediaThumbnail();

$mediaMimeType = mime_content_type($media);
$mediaThumbnailMimeType = mime_content_type($mediaThumbnail);

return [
'title' => $entry->title(),
'updated' => $entry->updated()?->format('Y-m-d H:i:s'),
'id' => $id,
'summary' => [
'_attributes' => [
'type' => 'text',
],
'_value' => $entry->summary(),
],
'content' => [
'_attributes' => [
'type' => 'text/html',
],
'_value' => $entry->summary(),
'_value' => $entry->content(),
],
'__custom:link:1' => [
'_attributes' => [
Expand All @@ -380,15 +392,15 @@ public function entryBook(OpdsEntryBook $entry): array
],
'__custom:link:2' => [
'_attributes' => [
'href' => $entry->media(),
'type' => 'image/png',
'href' => $media,
'type' => $mediaMimeType,
'rel' => 'http://opds-spec.org/image',
],
],
'__custom:link:3' => [
'_attributes' => [
'href' => $entry->mediaThumbnail(),
'type' => 'image/png',
'href' => $mediaThumbnail,
'type' => $mediaThumbnailMimeType,
'rel' => 'http://opds-spec.org/image/thumbnail',
],
],
Expand Down
20 changes: 16 additions & 4 deletions src/Entries/OpdsEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ public function __construct(
protected ?string $media = null,
protected DateTime|string|null $updated = null,
) {
if ($summary) {
$this->summary = strip_tags($summary);
$this->summary = strlen($this->summary) > 200 ? substr($this->summary, 0, 200).'...' : $this->summary;
}
$this->summary = OpdsEntry::handleContent($this->summary);
}

public function id(): string
Expand Down Expand Up @@ -61,4 +58,19 @@ public function toArray(): array
'updated' => $this->updated(),
];
}

public static function handleContent(?string $content, bool $stripTags = true): string
{
if (! $content) {
return '';
}

$content = strlen($content) > 200 ? substr($content, 0, 200).'...' : $content;

if ($stripTags) {
$content = strip_tags($content);
}

return $content;
}
}
8 changes: 8 additions & 0 deletions src/Entries/OpdsEntryBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function __construct(
protected string $title,
protected string $route,
protected ?string $summary = null,
protected ?string $content = null,
protected ?string $media = null,
protected DateTime|string|null $updated = null,
protected ?string $download = null,
Expand All @@ -34,6 +35,13 @@ public function __construct(
media: $media,
updated: $updated,
);

$this->content = OpdsEntry::handleContent($this->content, false);
}

public function content(): ?string
{
return $this->content;
}

public function download(): ?string
Expand Down

0 comments on commit 0588b74

Please sign in to comment.