]> git.immae.eu Git - github/wallabag/wallabag.git/blobdiff - src/Wallabag/CoreBundle/Helper/EntriesExport.php
EntriesExport/epub: add metadata to each entry's cover
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Helper / EntriesExport.php
index 6082f6b9c47f444a6c5abad61dd167032d8f815b..9cde27c68bc041fa5a6c463456943f67c982ee13 100644 (file)
@@ -85,7 +85,7 @@ class EntriesExport
     public function updateAuthor($method)
     {
         if ('entry' !== $method) {
-            $this->author = $method . ' authors';
+            $this->author = 'Various authors';
 
             return $this;
         }
@@ -173,6 +173,8 @@ class EntriesExport
         }
 
         $entryIds = [];
+        $entryCount = \count($this->entries);
+        $i = 0;
 
         /*
          * Adding actual entries
@@ -180,28 +182,41 @@ class EntriesExport
 
         // set tags as subjects
         foreach ($this->entries as $entry) {
+            ++$i;
             foreach ($entry->getTags() as $tag) {
                 $book->setSubject($tag->getLabel());
             }
+            $filename = sha1($entry->getTitle());
 
-            // 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());
+            $publishedBy = $entry->getPublishedBy();
+            if (!empty($publishedBy)) {
+                $authors = implode(',', $publishedBy);
+            } else {
+                $authors = $this->translator->trans('export.unknown');
+            }
 
-            $titlepage = $content_start . '<h1>' . $entry->getTitle() . '</h1>' . $this->getExportInformation('PHPePub') . $bookEnd;
-            $book->addChapter('Title', 'Title.html', $titlepage, true, EPub::EXTERNAL_REF_ADD);
+            $titlepage = $content_start .
+                '<h1>' . $entry->getTitle() . '</h1>' .
+                '<dl>' .
+                '<dt>' . $this->translator->trans('entry.view.published_by') . '</dt><dd>' . $authors . '</dd>' .
+                '<dt>' . $this->translator->trans('entry.metadata.reading_time') . '</dt><dd>' . $this->translator->trans('entry.metadata.reading_time_minutes_short', ['%readingTime%' => $entry->getReadingTime()]) . '</dd>' .
+                '<dt>' . $this->translator->trans('entry.metadata.added_on') . '</dt><dd>' . $entry->getCreatedAt()->format('Y-m-d') . '</dd>' .
+                '<dt>' . $this->translator->trans('entry.metadata.address') . '</dt><dd><a href="' . $entry->getUrl() . '">' . $entry->getUrl() . '</a></dd>' .
+                '</dl>' .
+                $bookEnd;
+            $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);
         }
 
+        $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);
 
-        $book->buildTOC();
-
         return Response::create(
             $book->getBook(),
             200,