From 063d5e7bda58fee5363dcbb1f86cee51d72c4940 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 18:55:39 +0100 Subject: [PATCH 1/9] 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(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 6082f6b9c..5658a7d3a 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, From edd1825b5832303b714bec37b8796b9077e7ddc0 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 19:13:26 +0100 Subject: [PATCH 2/9] 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(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 5658a7d3a..ea5a03cf3 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. From 30cf72bf55cdb2130e9096b1f7bcfa2f2ea1df1c Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 19:23:01 +0100 Subject: [PATCH 3/9] 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(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index ea5a03cf3..92f1779c5 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); From f8108346236e18768c08d6c0d4dc5fb4dfe13b78 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 20:17:35 +0100 Subject: [PATCH 4/9] 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/Controller/ExportController.php | 5 ++++- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Wallabag/CoreBundle/Controller/ExportController.php b/src/Wallabag/CoreBundle/Controller/ExportController.php index 7ca892394..9e9dbe49a 100644 --- a/src/Wallabag/CoreBundle/Controller/ExportController.php +++ b/src/Wallabag/CoreBundle/Controller/ExportController.php @@ -58,6 +58,7 @@ class ExportController extends Controller $method = ucfirst($category); $methodBuilder = 'getBuilderFor' . $method . 'ByUser'; $repository = $this->get('wallabag_core.entry_repository'); + $title = $method; if ('tag_entries' === $category) { $tag = $this->get('wallabag_core.tag_repository')->findOneBySlug($request->query->get('tag')); @@ -66,6 +67,8 @@ class ExportController extends Controller $this->getUser()->getId(), $tag->getId() ); + + $title = 'Tag ' . $tag->getLabel(); } else { $entries = $repository ->$methodBuilder($this->getUser()->getId()) @@ -76,7 +79,7 @@ class ExportController extends Controller try { return $this->get('wallabag_core.helper.entries_export') ->setEntries($entries) - ->updateTitle($method) + ->updateTitle($title) ->updateAuthor($method) ->exportAs($format); } catch (\InvalidArgumentException $e) { diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 92f1779c5..db5340fc1 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; } From 4944703edc7cdd2c8cd645b785603b4405d2a288 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 23:27:13 +0100 Subject: [PATCH 5/9] 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 --- .../CoreBundle/Helper/EntriesExport.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index db5340fc1..9cde27c68 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; From af83d05ce2bfda2a00bd764f5717d77824325d33 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Sun, 6 Jan 2019 23:28:39 +0100 Subject: [PATCH 6/9] Add translations Signed-off-by: Kevin Decherf --- .../CoreBundle/Resources/translations/messages.da.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.de.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.en.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.es.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.fa.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.fr.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.it.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.oc.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.pl.yml | 8 +++++++- .../CoreBundle/Resources/translations/messages.pt.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.ro.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.ru.yml | 9 +++++++++ .../CoreBundle/Resources/translations/messages.th.yml | 6 ++++++ .../CoreBundle/Resources/translations/messages.tr.yml | 6 ++++++ 14 files changed, 88 insertions(+), 1 deletion(-) diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml index e3ff21f14..97eb874d2 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.da.yml @@ -253,6 +253,11 @@ entry: confirm: # delete: "Are you sure you want to remove that article?" # delete_tag: "Are you sure you want to remove that tag from that article?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'Om' @@ -402,6 +407,7 @@ tag: # export: # footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' import: # page_title: 'Import' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml index c297ffb5d..0cf3b138e 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.de.yml @@ -253,6 +253,11 @@ entry: confirm: delete: 'Bist du sicher, dass du diesen Artikel löschen möchtest?' delete_tag: 'Bist du sicher, dass du diesen Tag vom Artikel entfernen möchtest?' + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'Über' @@ -402,6 +407,7 @@ tag: export: footer_template: '

Generiert von wallabag mit Hilfe von %method%

Bitte öffne ein Ticket wenn du ein Problem mit der Darstellung von diesem E-Book auf deinem Gerät hast.

' + # unknown: 'Unknown' import: page_title: 'Importieren' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml index 169ae728e..6085be140 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.en.yml @@ -253,6 +253,11 @@ entry: confirm: delete: "Are you sure you want to remove that article?" delete_tag: "Are you sure you want to remove that tag from that article?" + metadata: + reading_time: "Estimated reading time" + reading_time_minutes_short: "%readingTime% min" + address: "Address" + added_on: "Added on" about: page_title: 'About' @@ -402,6 +407,7 @@ tag: export: footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' + unknown: 'Unknown' import: page_title: 'Import' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml index 039a1867c..f2a8fb890 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.es.yml @@ -253,6 +253,11 @@ entry: confirm: # delete: "Are you sure you want to remove that article?" # delete_tag: "Are you sure you want to remove that tag from that article?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'Acerca de' @@ -402,6 +407,7 @@ tag: # export: # footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' import: page_title: 'Importar' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml index b3f2eb584..a5cbd7ecb 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fa.yml @@ -253,6 +253,11 @@ entry: confirm: # delete: "Are you sure you want to remove that article?" # delete_tag: "Are you sure you want to remove that tag from that article?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'درباره' @@ -402,6 +407,7 @@ tag: # export: # footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' import: page_title: 'درون‌ریزی' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 5cdd836ea..a36d84ae1 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -253,6 +253,11 @@ entry: confirm: delete: "Voulez-vous vraiment supprimer cet article ?" delete_tag: "Voulez-vous vraiment supprimer ce tag de cet article ?" + metadata: + reading_time: "Durée de lecture estimée" + reading_time_minutes_short: "%readingTime% min" + address: "Adresse" + added_on: "Ajouté le" about: page_title: "À propos" @@ -402,6 +407,7 @@ tag: export: footer_template: '

Généré par wallabag with %method%

Merci d''ouvrir un ticket si vous rencontrez des soucis d''affichage avec ce document sur votre support.

' + unknown: 'Inconnu' import: page_title: "Importer" diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml index 83b3edcdd..1649c0e4f 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.it.yml @@ -253,6 +253,11 @@ entry: confirm: delete: "Vuoi veramente rimuovere quell'articolo?" delete_tag: "Vuoi veramente rimuovere quell'etichetta da quell'articolo?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'A proposito' @@ -402,6 +407,7 @@ tag: # export: # footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' import: page_title: 'Importa' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml index 95bc9560f..e2298f1f6 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.oc.yml @@ -253,6 +253,11 @@ entry: confirm: delete: "Sètz segur de voler suprimir aqueste article ?" delete_tag: "Sètz segur de voler levar aquesta etiqueta de l'article ?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'A prepaus' @@ -402,6 +407,7 @@ tag: export: footer_template: '

Produch per wallabag amb %method%

Mercés de dobrir una sollicitacion s’avètz de problèmas amb l’afichatge d’aqueste E-Book sus vòstre periferic.

' + # unknown: 'Unknown' import: page_title: 'Importar' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml index a64e60b01..a5712733b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pl.yml @@ -253,6 +253,11 @@ entry: confirm: delete: "Czy jesteś pewien, że chcesz usunąć ten artykuł?" delete_tag: "Czy jesteś pewien, że chcesz usunąć ten tag, z tego artykułu?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'O nas' @@ -401,7 +406,8 @@ tag: placeholder: 'Możesz dodać kilka tagów, oddzielając je przecinkami.' export: - footer_template: '

Stworzone przez wallabag z %method%

Proszę zgłoś sprawę, jeżeli masz problem z wyświetleniem tego e-booka na swoim urządzeniu.

' + footer_template: '

Stworzone przez wallabag z %method%

Proszę zgłoś sprawę, jeżeli masz problem z wyświetleniem tego e-booka na swoim urządzeniu.

' + # unknown: 'Unknown' import: page_title: 'Import' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml index 58d2d0587..1ccf49e1b 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.pt.yml @@ -253,6 +253,11 @@ entry: confirm: # delete: "Are you sure you want to remove that article?" # delete_tag: "Are you sure you want to remove that tag from that article?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'Sobre' @@ -402,6 +407,7 @@ tag: # export: # footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' import: page_title: 'Importar' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml index 564fed945..6c0e18e1c 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ro.yml @@ -253,6 +253,11 @@ entry: confirm: # delete: "Are you sure you want to remove that article?" # delete_tag: "Are you sure you want to remove that tag from that article?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'Despre' @@ -402,6 +407,7 @@ tag: # export: # footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' import: # page_title: 'Import' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml index 5f210c934..48753b555 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.ru.yml @@ -241,6 +241,11 @@ entry: save_label: 'Сохранить' public: shared_by_wallabag: "Запись была опубликована wallabag" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'О' @@ -388,6 +393,10 @@ tag: add: 'Добавить' placeholder: 'Вы можете добавить несколько тегов, разделенных запятой.' +# export: +# footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' + import: page_title: 'Импорт' page_description: 'Добро пожаловать в импортер wallabag. Выберите сервис, из которого вы хотите перенести данные.' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml index 9d22f90d3..5524b1f12 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.th.yml @@ -251,6 +251,11 @@ entry: confirm: delete: "คุณแน่ใจหรือไม่ว่าคุณต้องการลบบทความนี้?" delete_tag: "คุณแน่ใจหรือไม่ว่าคุณต้องการลบแท็กจากบทความนี้?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'เกี่ยวกับ' @@ -400,6 +405,7 @@ tag: export: footer_template: '

ผลิตโดย wallabag กับ %method%

ให้ทำการเปิด ฉบับนี้ ถ้าคุณมีข้อบกพร่องif you have trouble with the display of this E-Book on your device.

' + # unknown: 'Unknown' import: page_title: 'นำข้อมูลเช้า' diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml index 4c71f0b96..e2156d479 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.tr.yml @@ -251,6 +251,11 @@ entry: confirm: # delete: "Are you sure you want to remove that article?" # delete_tag: "Are you sure you want to remove that tag from that article?" + metadata: + # reading_time: "Estimated reading time" + # reading_time_minutes_short: "%readingTime% min" + # address: "Address" + # added_on: "Added on" about: page_title: 'Hakkımızda' @@ -400,6 +405,7 @@ tag: # export: # footer_template: '

Produced by wallabag with %method%

Please open an issue if you have trouble with the display of this E-Book on your device.

' +# unknown: 'Unknown' import: page_title: 'İçe Aktar' From ad5ef8bca0c0321f348dcf402e0a20791eca3f4d Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Mon, 7 Jan 2019 23:36:41 +0100 Subject: [PATCH 7/9] EntriesExport/pdf: move notice to the end, add metadata cover Signed-off-by: Kevin Decherf --- .../CoreBundle/Helper/EntriesExport.php | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 9cde27c68..1debdf8e4 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); From dac93644e8585cc6b2ea1a0409b11ed82bb8169d Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Mon, 7 Jan 2019 23:50:08 +0100 Subject: [PATCH 8/9] 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 --- .../CoreBundle/Helper/EntriesExport.php | 28 ++++++++++++------- .../Controller/ExportControllerTest.php | 11 ++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 1debdf8e4..1a6111994 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)); + } } diff --git a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php index 6f3308e56..0c3d4c83a 100644 --- a/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php +++ b/tests/Wallabag/CoreBundle/Controller/ExportControllerTest.php @@ -98,7 +98,7 @@ class ExportControllerTest extends WallabagCoreTestCase $headers = $client->getResponse()->headers; $this->assertSame('application/x-mobipocket-ebook', $headers->get('content-type')); - $this->assertSame('attachment; filename="' . preg_replace('/[^A-Za-z0-9\-]/', '', $content->getTitle()) . '.mobi"', $headers->get('content-disposition')); + $this->assertSame('attachment; filename="' . $this->getSanitizedFilename($content->getTitle()) . '.mobi"', $headers->get('content-disposition')); $this->assertSame('binary', $headers->get('content-transfer-encoding')); } @@ -126,7 +126,7 @@ class ExportControllerTest extends WallabagCoreTestCase $headers = $client->getResponse()->headers; $this->assertSame('application/pdf', $headers->get('content-type')); - $this->assertSame('attachment; filename="Tag_entries articles.pdf"', $headers->get('content-disposition')); + $this->assertSame('attachment; filename="Tag foo bar articles.pdf"', $headers->get('content-disposition')); $this->assertSame('binary', $headers->get('content-transfer-encoding')); } @@ -212,7 +212,7 @@ class ExportControllerTest extends WallabagCoreTestCase $headers = $client->getResponse()->headers; $this->assertSame('application/json', $headers->get('content-type')); - $this->assertSame('attachment; filename="' . $contentInDB->getTitle() . '.json"', $headers->get('content-disposition')); + $this->assertSame('attachment; filename="' . $this->getSanitizedFilename($contentInDB->getTitle()) . '.json"', $headers->get('content-disposition')); $this->assertSame('UTF-8', $headers->get('content-transfer-encoding')); $content = json_decode($client->getResponse()->getContent(), true); @@ -281,4 +281,9 @@ class ExportControllerTest extends WallabagCoreTestCase $this->assertNotEmpty('created_at', (string) $content->entry[0]->created_at); $this->assertNotEmpty('updated_at', (string) $content->entry[0]->updated_at); } + + private function getSanitizedFilename($title) + { + return preg_replace('/[^A-Za-z0-9\- \']/', '', iconv('utf-8', 'us-ascii//TRANSLIT', $title)); + } } From 5e1f27767bc2dcf0760bc3061544ecbb833ad5e7 Mon Sep 17 00:00:00 2001 From: Kevin Decherf Date: Wed, 9 Jan 2019 16:26:19 +0100 Subject: [PATCH 9/9] EntriesExport: avoid else on $authors Signed-off-by: Kevin Decherf --- src/Wallabag/CoreBundle/Helper/EntriesExport.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Wallabag/CoreBundle/Helper/EntriesExport.php b/src/Wallabag/CoreBundle/Helper/EntriesExport.php index 1a6111994..64591687d 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();