mirror of
https://github.com/wallabag/wallabag.git
synced 2025-09-30 19:22:12 +00:00
Merge ec82e56fac
into f458fb1c9b
This commit is contained in:
commit
c737faea16
3 changed files with 64 additions and 34 deletions
|
@ -92,11 +92,14 @@ class EntriesExport
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->author = $this->entries[0]->getDomainName();
|
|
||||||
|
|
||||||
$publishedBy = $this->entries[0]->getPublishedBy();
|
$publishedBy = $this->entries[0]->getPublishedBy();
|
||||||
if (!empty($publishedBy)) {
|
$domainName = $this->entries[0]->getDomainName();
|
||||||
|
if (!empty($publishedBy) && !empty($publishedBy[0])) {
|
||||||
$this->author = implode(', ', $publishedBy);
|
$this->author = implode(', ', $publishedBy);
|
||||||
|
} elseif (!empty($domainName)) {
|
||||||
|
$this->author = $domainName;
|
||||||
|
} else {
|
||||||
|
$this->author = $this->translator->trans('export.unknown');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -135,16 +138,16 @@ class EntriesExport
|
||||||
/*
|
/*
|
||||||
* Start and End of the book
|
* Start and End of the book
|
||||||
*/
|
*/
|
||||||
$content_start =
|
$chapterStart =
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||||
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
|
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n"
|
||||||
. '<head>'
|
. '<head>'
|
||||||
. "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n"
|
. "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n"
|
||||||
. "<title>wallabag articles book</title>\n"
|
. "<title>{$this->title}</title>\n"
|
||||||
. "</head>\n"
|
. "</head>\n"
|
||||||
. "<body>\n";
|
. "<body>\n";
|
||||||
|
|
||||||
$bookEnd = "</body>\n</html>\n";
|
$chapterEnd = "</body>\n</html>\n";
|
||||||
|
|
||||||
$book = new EPub(EPub::BOOK_VERSION_EPUB3);
|
$book = new EPub(EPub::BOOK_VERSION_EPUB3);
|
||||||
|
|
||||||
|
@ -155,13 +158,8 @@ class EntriesExport
|
||||||
$book->setTitle($this->title);
|
$book->setTitle($this->title);
|
||||||
// EPub specification requires BCP47-compliant languages, thus we replace _ with -
|
// EPub specification requires BCP47-compliant languages, thus we replace _ with -
|
||||||
$book->setLanguage(str_replace('_', '-', $this->language));
|
$book->setLanguage(str_replace('_', '-', $this->language));
|
||||||
$book->setDescription('Some articles saved on my wallabag');
|
|
||||||
|
|
||||||
$book->setAuthor($this->author, $this->author);
|
$book->setAuthor($this->author, $this->author);
|
||||||
|
$book->setPublisher('wallabag', $this->wallabagUrl);
|
||||||
// I hope this is a non-existent address :)
|
|
||||||
$book->setPublisher('wallabag', 'wallabag');
|
|
||||||
// Strictly not needed as the book date defaults to time().
|
|
||||||
$book->setDate(time());
|
$book->setDate(time());
|
||||||
$book->setSourceURL($this->wallabagUrl);
|
$book->setSourceURL($this->wallabagUrl);
|
||||||
|
|
||||||
|
@ -170,6 +168,10 @@ class EntriesExport
|
||||||
|
|
||||||
$entryIds = [];
|
$entryIds = [];
|
||||||
$entryCount = \count($this->entries);
|
$entryCount = \count($this->entries);
|
||||||
|
|
||||||
|
if ($entryCount > 1) {
|
||||||
|
$book->setDescription("{$entryCount} articles saved on my wallabag");
|
||||||
|
}
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -180,23 +182,23 @@ class EntriesExport
|
||||||
foreach ($this->entries as $entry) {
|
foreach ($this->entries as $entry) {
|
||||||
++$i;
|
++$i;
|
||||||
|
|
||||||
/*
|
$internalLink = $this->wallabagUrl . '/view/' . $entry->getId();
|
||||||
* Front page
|
|
||||||
* Set if there's only one entry in the given set
|
|
||||||
*/
|
|
||||||
if (1 === $entryCount && null !== $entry->getPreviewPicture()) {
|
|
||||||
$book->setCoverImage($entry->getPreviewPicture());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($entry->getTags() as $tag) {
|
foreach ($entry->getTags() as $tag) {
|
||||||
$book->setSubject($tag->getLabel());
|
$book->setSubject($tag->getLabel());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use a hash of the original URL plus title as chapter filename inside the Epub
|
||||||
$filename = sha1(\sprintf('%s:%s', $entry->getUrl(), $entry->getTitle()));
|
$filename = sha1(\sprintf('%s:%s', $entry->getUrl(), $entry->getTitle()));
|
||||||
|
|
||||||
$publishedBy = $entry->getPublishedBy();
|
$publishedBy = $entry->getPublishedBy();
|
||||||
|
$domainName = $entry->getDomainName();
|
||||||
|
if (!empty($publishedBy) && !empty($publishedBy[0])) {
|
||||||
|
$authors = implode(', ', $publishedBy);
|
||||||
|
} elseif (!empty($domainName)) {
|
||||||
|
$authors = $domainName;
|
||||||
|
} else {
|
||||||
$authors = $this->translator->trans('export.unknown');
|
$authors = $this->translator->trans('export.unknown');
|
||||||
if (!empty($publishedBy)) {
|
|
||||||
$authors = implode(',', $publishedBy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$publishedAt = $entry->getPublishedAt();
|
$publishedAt = $entry->getPublishedAt();
|
||||||
|
@ -207,29 +209,53 @@ class EntriesExport
|
||||||
|
|
||||||
$readingTime = round($entry->getReadingTime() / $user->getConfig()->getReadingSpeed() * 200);
|
$readingTime = round($entry->getReadingTime() / $user->getConfig()->getReadingSpeed() * 200);
|
||||||
|
|
||||||
$titlepage = $content_start .
|
if ($entryCount > 1) {
|
||||||
'<h1>' . $entry->getTitle() . '</h1>' .
|
$chapterName = "{$i}. {$entry->getTitle()}";
|
||||||
'<dl>' .
|
$chapter = $chapterStart . "<h1>({$i}/{$entryCount}) {$entry->getTitle()}</h1>";
|
||||||
'<dt>' . $this->translator->trans('entry.view.published_by') . '</dt><dd>' . $authors . '</dd>' .
|
if (null !== $entry->getPreviewPicture()) {
|
||||||
'<dt>' . $this->translator->trans('entry.metadata.published_on') . '</dt><dd>' . $publishedDate . '</dd>' .
|
$chapter .= "<img src=\"{$entry->getPreviewPicture()}\">";
|
||||||
'<dt>' . $this->translator->trans('entry.metadata.reading_time') . '</dt><dd>' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $readingTime]) . '</dd>' .
|
}
|
||||||
'<dt>' . $this->translator->trans('entry.metadata.added_on') . '</dt><dd>' . $entry->getCreatedAt()->format('Y-m-d') . '</dd>' .
|
} else {
|
||||||
'<dt>' . $this->translator->trans('entry.metadata.address') . '</dt><dd><a href="' . $entry->getUrl() . '">' . $entry->getUrl() . '</a></dd>' .
|
$book->setDescription($entry->getUrl());
|
||||||
'</dl>' .
|
if (null !== $entry->getPreviewPicture()) {
|
||||||
$bookEnd;
|
$book->setCoverImage($entry->getPreviewPicture());
|
||||||
$book->addChapter("Entry {$i} of {$entryCount}", "{$filename}_cover.html", $titlepage, true, EPub::EXTERNAL_REF_ADD);
|
}
|
||||||
$chapter = $content_start . $entry->getContent() . $bookEnd;
|
$chapterName = $entry->getTitle();
|
||||||
|
$chapter = $chapterStart . "<h1>{$entry->getTitle()}</h1>";
|
||||||
$entryIds[] = $entry->getId();
|
|
||||||
$book->addChapter($entry->getTitle(), "{$filename}.html", $chapter, true, EPub::EXTERNAL_REF_ADD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$book->addChapter('Notices', 'Cover2.html', $content_start . $this->getExportInformation('PHPePub') . $bookEnd);
|
|
||||||
|
|
||||||
// Could also be the ISBN number, prefered for published books, or a UUID.
|
$chapter .= '<dl>' .
|
||||||
|
'<dt>' . $this->translator->trans('entry.view.published_by') . '</dt><dd>' . $authors . '</dd>' .
|
||||||
|
'<dt>' . $this->translator->trans('entry.metadata.published_on') . '</dt><dd>' . $publishedDate . '</dd>' .
|
||||||
|
'<dt>' . $this->translator->trans('entry.metadata.added_on') . '</dt><dd>' . $entry->getCreatedAt()->format('Y-m-d') . '</dd>' .
|
||||||
|
'<dt>' . $this->translator->trans('entry.metadata.reading_time') . '</dt><dd>' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $readingTime]) . '</dd>' .
|
||||||
|
'<dt>' . $this->translator->trans('entry.metadata.address') . '</dt><dd><a href="' . $entry->getUrl() . '">' . $entry->getUrl() . '</a></dd>' .
|
||||||
|
'<dt>' . $this->translator->trans('entry.metadata.internal_link') . '</dt><dd><a href="' . $internalLink . '">' . $internalLink . '</a></dd>';
|
||||||
|
|
||||||
|
if ($entry->isPublic()) {
|
||||||
|
$publicLink = $this->wallabagUrl . '/share/' . $entry->getUid();
|
||||||
|
$chapter .= '<dt>' . $this->translator->trans('entry.metadata.public_link') . '</dt><dd><a href="' . $publicLink . '">' . $publicLink . '</a></dd>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$chapter .= '</dl>' .
|
||||||
|
"<h2>{$entry->getTitle()}</h2>" .
|
||||||
|
$entry->getContent() .
|
||||||
|
$chapterEnd;
|
||||||
|
|
||||||
|
$entryIds[] = $entry->getId();
|
||||||
|
$book->addChapter($chapterName, "{$filename}.xhtml", $chapter, true, EPub::EXTERNAL_REF_ADD);
|
||||||
|
}
|
||||||
|
|
||||||
|
$book->addChapter('Notices', 'CoverBack.xhtml', $chapterStart . $this->getExportInformation('PHPePub') . $chapterEnd);
|
||||||
|
|
||||||
|
// Set identifier to a hash of the wallabag server URL plus comma-separated entry IDs
|
||||||
$hash = sha1(\sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds)));
|
$hash = sha1(\sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds)));
|
||||||
$book->setIdentifier(\sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI);
|
$book->setIdentifier(\sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI);
|
||||||
|
|
||||||
|
// Do not add "Guide" chapter for "CoverPage"
|
||||||
|
$book->setisReferencesAddedToToc(false);
|
||||||
|
|
||||||
return new Response(
|
return new Response(
|
||||||
$book->getBook(),
|
$book->getBook(),
|
||||||
200,
|
200,
|
||||||
|
@ -271,7 +297,7 @@ class EntriesExport
|
||||||
|
|
||||||
$publishedBy = $entry->getPublishedBy();
|
$publishedBy = $entry->getPublishedBy();
|
||||||
$authors = $this->translator->trans('export.unknown');
|
$authors = $this->translator->trans('export.unknown');
|
||||||
if (!empty($publishedBy)) {
|
if (!empty($publishedBy) && !empty($publishedBy[0])) {
|
||||||
$authors = implode(',', $publishedBy);
|
$authors = implode(',', $publishedBy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -336,6 +336,8 @@ entry:
|
||||||
reading_time: Estimated reading time
|
reading_time: Estimated reading time
|
||||||
reading_time_minutes_short: '%readingTime% min'
|
reading_time_minutes_short: '%readingTime% min'
|
||||||
address: Address
|
address: Address
|
||||||
|
internal_link: Internal link
|
||||||
|
public_link: Public link
|
||||||
added_on: Added on
|
added_on: Added on
|
||||||
published_on: "Published on"
|
published_on: "Published on"
|
||||||
about:
|
about:
|
||||||
|
|
|
@ -336,6 +336,8 @@ entry:
|
||||||
reading_time: Durée de lecture estimée
|
reading_time: Durée de lecture estimée
|
||||||
reading_time_minutes_short: '%readingTime% min'
|
reading_time_minutes_short: '%readingTime% min'
|
||||||
address: Adresse
|
address: Adresse
|
||||||
|
internal_link: Lien interne
|
||||||
|
public_link: Lien public
|
||||||
added_on: Ajouté le
|
added_on: Ajouté le
|
||||||
published_on: Publié le
|
published_on: Publié le
|
||||||
about:
|
about:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue