From bf22266a6230be105ec9a91eccf00e489108405c Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 18:38:02 +0100 Subject: EntriesExport/epub: replace epub identifier with unique urn We replace the title used as the unique identifier of the epub file with a urn following the format: urn:wallabag:{sha1("wallabagUrl:listOfEntryIdsSeparatedByComma")} This format is repeatable: it always gives the same uid for the same list of entries. Fixes #3811 Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index cbf1037b..6082f6b9 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -150,8 +150,6 @@ class EntriesExport */ $book->setTitle($this->title); - // Could also be the ISBN number, prefered for published books, or a UUID. - $book->setIdentifier($this->title, EPub::IDENTIFIER_URI); // Not needed, but included for the example, Language is mandatory, but EPub defaults to "en". Use RFC3066 Language codes, such as "en", "da", "fr" etc. $book->setLanguage($this->language); $book->setDescription('Some articles saved on my wallabag'); @@ -174,6 +172,8 @@ class EntriesExport $book->setCoverImage('Cover.png', file_get_contents($this->logoPath), 'image/png'); } + $entryIds = []; + /* * Adding actual entries */ @@ -192,8 +192,14 @@ class EntriesExport $book->addChapter('Title', 'Title.html', $titlepage, true, EPub::EXTERNAL_REF_ADD); $chapter = $content_start . $entry->getContent() . $bookEnd; $book->addChapter($entry->getTitle(), htmlspecialchars($filename) . '.html', $chapter, true, EPub::EXTERNAL_REF_ADD); + + $entryIds[] = $entry->getId(); } + // Could also be the ISBN number, prefered for published books, or a UUID. + $hash = sha1(sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds))); + $book->setIdentifier(sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI); + $book->buildTOC(); return Response::create( -- cgit v1.2.3 From 063d5e7bda58fee5363dcbb1f86cee51d72c4940 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 18:55:39 +0100 Subject: EntriesExport/epub: remove TOC page This change only remove the rendered page of the TOC at the end of the book, the TOC remains available to readers. Fixes #3603 Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 6082f6b9..5658a7d3 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -200,8 +200,6 @@ class EntriesExport $hash = sha1(sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds))); $book->setIdentifier(sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI); - $book->buildTOC(); - return Response::create( $book->getBook(), 200, -- cgit v1.2.3 From edd1825b5832303b714bec37b8796b9077e7ddc0 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 19:13:26 +0100 Subject: EntriesExport/epub: use sha1 sums for filenames, fix and rename title chapters This commit renames entry chapters file using a sha1 sum of their title for simplicity. Also we fix the 'Title' chapter duplicate issue by using the hash of the related entry and the suffix '_title'. Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 5658a7d3..ea5a03cf 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -173,6 +173,8 @@ class EntriesExport } $entryIds = []; + $entryCount = \count($this->entries); + $i = 0; /* * Adding actual entries @@ -180,20 +182,18 @@ class EntriesExport // set tags as subjects foreach ($this->entries as $entry) { + ++$i; foreach ($entry->getTags() as $tag) { $book->setSubject($tag->getLabel()); } - - // the reader in Kobo Devices doesn't likes special caracters - // in filenames, we limit to A-z/0-9 - $filename = preg_replace('/[^A-Za-z0-9\-]/', '', $entry->getTitle()); + $filename = sha1($entry->getTitle()); $titlepage = $content_start . '

' . $entry->getTitle() . '

' . $this->getExportInformation('PHPePub') . $bookEnd; - $book->addChapter('Title', 'Title.html', $titlepage, true, EPub::EXTERNAL_REF_ADD); + $book->addChapter("Entry {$i} of {$entryCount}", "{$filename}_cover.html", $titlepage, true, EPub::EXTERNAL_REF_ADD); $chapter = $content_start . $entry->getContent() . $bookEnd; - $book->addChapter($entry->getTitle(), htmlspecialchars($filename) . '.html', $chapter, true, EPub::EXTERNAL_REF_ADD); $entryIds[] = $entry->getId(); + $book->addChapter($entry->getTitle(), "{$filename}.html", $chapter, true, EPub::EXTERNAL_REF_ADD); } // Could also be the ISBN number, prefered for published books, or a UUID. -- cgit v1.2.3 From 30cf72bf55cdb2130e9096b1f7bcfa2f2ea1df1c Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 19:23:01 +0100 Subject: EntriesExport/epub: revert c779373f, move exportinfo to the end of the book Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index ea5a03cf..92f1779c 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -188,7 +188,7 @@ class EntriesExport } $filename = sha1($entry->getTitle()); - $titlepage = $content_start . '

' . $entry->getTitle() . '

' . $this->getExportInformation('PHPePub') . $bookEnd; + $titlepage = $content_start . '

' . $entry->getTitle() . '

' . $bookEnd; $book->addChapter("Entry {$i} of {$entryCount}", "{$filename}_cover.html", $titlepage, true, EPub::EXTERNAL_REF_ADD); $chapter = $content_start . $entry->getContent() . $bookEnd; @@ -196,6 +196,8 @@ class EntriesExport $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. $hash = sha1(sprintf('%s:%s', $this->wallabagUrl, implode(',', $entryIds))); $book->setIdentifier(sprintf('urn:wallabag:%s', $hash), EPub::IDENTIFIER_URI); -- cgit v1.2.3 From f8108346236e18768c08d6c0d4dc5fb4dfe13b78 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 20:17:35 +0100 Subject: EntriesExport: change authors and title when not single entry export Change '{method} authors' (which gives 'Tag_entries authors' when exporting a tag) to 'Various authors'. When exporting a tag (tag_entries), change the title from 'Tag_entries articles' to 'Tag {tag} articles'. Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 92f1779c..db5340fc 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -85,7 +85,7 @@ class EntriesExport public function updateAuthor($method) { if ('entry' !== $method) { - $this->author = $method . ' authors'; + $this->author = 'Various authors'; return $this; } -- cgit v1.2.3 From 4944703edc7cdd2c8cd645b785603b4405d2a288 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 23:27:13 +0100 Subject: EntriesExport/epub: add metadata to each entry's cover Add metadata to the cover of each entry: - Publishers - Estimated reading time - Date of creation ("Added on") - Address (URL) Related to #2821 Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index db5340fc..9cde27c6 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -188,7 +188,22 @@ class EntriesExport } $filename = sha1($entry->getTitle()); - $titlepage = $content_start . '

' . $entry->getTitle() . '

' . $bookEnd; + $publishedBy = $entry->getPublishedBy(); + if (!empty($publishedBy)) { + $authors = implode(',', $publishedBy); + } else { + $authors = $this->translator->trans('export.unknown'); + } + + $titlepage = $content_start . + '

' . $entry->getTitle() . '

' . + '
' . + '
' . $this->translator->trans('entry.view.published_by') . '
' . $authors . '
' . + '
' . $this->translator->trans('entry.metadata.reading_time') . '
' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $entry->getReadingTime()]) . '
' . + '
' . $this->translator->trans('entry.metadata.added_on') . '
' . $entry->getCreatedAt()->format('Y-m-d') . '
' . + '
' . $this->translator->trans('entry.metadata.address') . '
' . $entry->getUrl() . '
' . + '
' . + $bookEnd; $book->addChapter("Entry {$i} of {$entryCount}", "{$filename}_cover.html", $titlepage, true, EPub::EXTERNAL_REF_ADD); $chapter = $content_start . $entry->getContent() . $bookEnd; -- cgit v1.2.3 From ad5ef8bca0c0321f348dcf402e0a20791eca3f4d Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Mon, 7 Jan 2019 23:36:41 +0100 Subject: EntriesExport/pdf: move notice to the end, add metadata cover Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 33 ++++++++++++++++++------ 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 9cde27c6..1debdf8e 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -299,14 +299,6 @@ class EntriesExport $pdf->SetSubject('Articles via wallabag'); $pdf->SetKeywords('wallabag'); - /* - * Front page - */ - $pdf->AddPage(); - $intro = '

' . $this->title . '

' . $this->getExportInformation('tcpdf'); - - $pdf->writeHTMLCell(0, 0, '', '', $intro, 0, 1, 0, true, '', true); - /* * Adding actual entries */ @@ -315,6 +307,23 @@ class EntriesExport $pdf->SetKeywords($tag->getLabel()); } + $publishedBy = $entry->getPublishedBy(); + if (!empty($publishedBy)) { + $authors = implode(',', $publishedBy); + } else { + $authors = $this->translator->trans('export.unknown'); + } + + $pdf->addPage(); + $html = '

' . $entry->getTitle() . '

' . + '
' . + '
' . $this->translator->trans('entry.view.published_by') . '
' . $authors . '
' . + '
' . $this->translator->trans('entry.metadata.reading_time') . '
' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $entry->getReadingTime()]) . '
' . + '
' . $this->translator->trans('entry.metadata.added_on') . '
' . $entry->getCreatedAt()->format('Y-m-d') . '
' . + '
' . $this->translator->trans('entry.metadata.address') . '
' . $entry->getUrl() . '
' . + '
'; + $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); + $pdf->AddPage(); $html = '

' . $entry->getTitle() . '

'; $html .= $entry->getContent(); @@ -322,6 +331,14 @@ class EntriesExport $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); } + /* + * Last page + */ + $pdf->AddPage(); + $html = $this->getExportInformation('tcpdf'); + + $pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true); + // set image scale factor $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO); -- cgit v1.2.3 From dac93644e8585cc6b2ea1a0409b11ed82bb8169d Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Mon, 7 Jan 2019 23:50:08 +0100 Subject: EntriesExport: sanitize filename and fix tests Filename will now only use a-zA-Z0-9-' and space. Fixes remaining filename issue on #3811 Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 1debdf8e..1a611199 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -223,7 +223,7 @@ class EntriesExport [ 'Content-Description' => 'File Transfer', 'Content-type' => 'application/epub+zip', - 'Content-Disposition' => 'attachment; filename="' . $this->title . '.epub"', + 'Content-Disposition' => 'attachment; filename="' . $this->getSanitizedFilename() . '.epub"', 'Content-Transfer-Encoding' => 'binary', ] ); @@ -265,9 +265,6 @@ class EntriesExport } $mobi->setContentProvider($content); - // the browser inside Kindle Devices doesn't likes special caracters either, we limit to A-z/0-9 - $this->title = preg_replace('/[^A-Za-z0-9\-]/', '', $this->title); - return Response::create( $mobi->toString(), 200, @@ -275,7 +272,7 @@ class EntriesExport 'Accept-Ranges' => 'bytes', 'Content-Description' => 'File Transfer', 'Content-type' => 'application/x-mobipocket-ebook', - 'Content-Disposition' => 'attachment; filename="' . $this->title . '.mobi"', + 'Content-Disposition' => 'attachment; filename="' . $this->getSanitizedFilename() . '.mobi"', 'Content-Transfer-Encoding' => 'binary', ] ); @@ -348,7 +345,7 @@ class EntriesExport [ 'Content-Description' => 'File Transfer', 'Content-type' => 'application/pdf', - 'Content-Disposition' => 'attachment; filename="' . $this->title . '.pdf"', + 'Content-Disposition' => 'attachment; filename="' . $this->getSanitizedFilename() . '.pdf"', 'Content-Transfer-Encoding' => 'binary', ] ); @@ -394,7 +391,7 @@ class EntriesExport 200, [ 'Content-type' => 'application/csv', - 'Content-Disposition' => 'attachment; filename="' . $this->title . '.csv"', + 'Content-Disposition' => 'attachment; filename="' . $this->getSanitizedFilename() . '.csv"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -412,7 +409,7 @@ class EntriesExport 200, [ 'Content-type' => 'application/json', - 'Content-Disposition' => 'attachment; filename="' . $this->title . '.json"', + 'Content-Disposition' => 'attachment; filename="' . $this->getSanitizedFilename() . '.json"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -430,7 +427,7 @@ class EntriesExport 200, [ 'Content-type' => 'application/xml', - 'Content-Disposition' => 'attachment; filename="' . $this->title . '.xml"', + 'Content-Disposition' => 'attachment; filename="' . $this->getSanitizedFilename() . '.xml"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -456,7 +453,7 @@ class EntriesExport 200, [ 'Content-type' => 'text/plain', - 'Content-Disposition' => 'attachment; filename="' . $this->title . '.txt"', + 'Content-Disposition' => 'attachment; filename="' . $this->getSanitizedFilename() . '.txt"', 'Content-Transfer-Encoding' => 'UTF-8', ] ); @@ -499,4 +496,15 @@ class EntriesExport return str_replace('%IMAGE%', '', $info); } + + /** + * Return a sanitized version of the title by applying translit iconv + * and removing non alphanumeric characters, - and space. + * + * @return string Sanitized filename + */ + private function getSanitizedFilename() + { + return preg_replace('/[^A-Za-z0-9\- \']/', '', iconv('utf-8', 'us-ascii//TRANSLIT', $this->title)); + } } -- cgit v1.2.3 From 5e1f27767bc2dcf0760bc3061544ecbb833ad5e7 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Wed, 9 Jan 2019 16:26:19 +0100 Subject: EntriesExport: avoid else on $authors Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src/Wallabag/CoreBundle/Helper/EntriesExport.php') diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 1a611199..64591687 100644 --- a/src/Wallabag/CoreBundle/Helper/EntriesExport.php +++ b/src/Wallabag/CoreBundle/Helper/EntriesExport.php @@ -189,10 +189,9 @@ class EntriesExport $filename = sha1($entry->getTitle()); $publishedBy = $entry->getPublishedBy(); + $authors = $this->translator->trans('export.unknown'); if (!empty($publishedBy)) { $authors = implode(',', $publishedBy); - } else { - $authors = $this->translator->trans('export.unknown'); } $titlepage = $content_start . @@ -305,10 +304,9 @@ class EntriesExport } $publishedBy = $entry->getPublishedBy(); + $authors = $this->translator->trans('export.unknown'); if (!empty($publishedBy)) { $authors = implode(',', $publishedBy); - } else { - $authors = $this->translator->trans('export.unknown'); } $pdf->addPage(); -- cgit v1.2.3