aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorKevin Decherf <kevin@kdecherf.com>2019-01-06 19:13:26 +0100
committerKevin Decherf <kevin@kdecherf.com>2019-01-07 21:41:12 +0100
commitedd1825b5832303b714bec37b8796b9077e7ddc0 (patch)
tree2f1e22e37ad0a16bbe742c4469cc2f264697170d /src/Wallabag
parent063d5e7bda58fee5363dcbb1f86cee51d72c4940 (diff)
downloadwallabag-edd1825b5832303b714bec37b8796b9077e7ddc0.tar.gz
wallabag-edd1825b5832303b714bec37b8796b9077e7ddc0.tar.zst
wallabag-edd1825b5832303b714bec37b8796b9077e7ddc0.zip
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 <kevin@kdecherf.com>
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Helper/EntriesExport.php12
1 files changed, 6 insertions, 6 deletions
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
173 } 173 }
174 174
175 $entryIds = []; 175 $entryIds = [];
176 $entryCount = \count($this->entries);
177 $i = 0;
176 178
177 /* 179 /*
178 * Adding actual entries 180 * Adding actual entries
@@ -180,20 +182,18 @@ class EntriesExport
180 182
181 // set tags as subjects 183 // set tags as subjects
182 foreach ($this->entries as $entry) { 184 foreach ($this->entries as $entry) {
185 ++$i;
183 foreach ($entry->getTags() as $tag) { 186 foreach ($entry->getTags() as $tag) {
184 $book->setSubject($tag->getLabel()); 187 $book->setSubject($tag->getLabel());
185 } 188 }
186 189 $filename = sha1($entry->getTitle());
187 // the reader in Kobo Devices doesn't likes special caracters
188 // in filenames, we limit to A-z/0-9
189 $filename = preg_replace('/[^A-Za-z0-9\-]/', '', $entry->getTitle());
190 190
191 $titlepage = $content_start . '<h1>' . $entry->getTitle() . '</h1>' . $this->getExportInformation('PHPePub') . $bookEnd; 191 $titlepage = $content_start . '<h1>' . $entry->getTitle() . '</h1>' . $this->getExportInformation('PHPePub') . $bookEnd;
192 $book->addChapter('Title', 'Title.html', $titlepage, true, EPub::EXTERNAL_REF_ADD); 192 $book->addChapter("Entry {$i} of {$entryCount}", "{$filename}_cover.html", $titlepage, true, EPub::EXTERNAL_REF_ADD);
193 $chapter = $content_start . $entry->getContent() . $bookEnd; 193 $chapter = $content_start . $entry->getContent() . $bookEnd;
194 $book->addChapter($entry->getTitle(), htmlspecialchars($filename) . '.html', $chapter, true, EPub::EXTERNAL_REF_ADD);
195 194
196 $entryIds[] = $entry->getId(); 195 $entryIds[] = $entry->getId();
196 $book->addChapter($entry->getTitle(), "{$filename}.html", $chapter, true, EPub::EXTERNAL_REF_ADD);
197 } 197 }
198 198
199 // Could also be the ISBN number, prefered for published books, or a UUID. 199 // Could also be the ISBN number, prefered for published books, or a UUID.