/** * Use PHPePub to dump a .epub file. * * @return Response */ private function produceEpub() { /* * Start and End of the book */ $content_start = "<?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" . '<head>' . "<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n" . "<title>wallabag articles book</title>\n" . "</head>\n" . "<body>\n"; $bookEnd = "</body>\n</html>\n"; $book = new EPub(EPub::BOOK_VERSION_EPUB3); /* * Book metadata */ $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'); foreach ($this->authors as $author) { $book->setAuthor($author, $author); } // I hope this is a non existant address :) $book->setPublisher('wallabag', 'wallabag'); // Strictly not needed as the book date defaults to time(). $book->setDate(time()); $book->setSourceURL($this->wallabagUrl); $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, 'PHP'); $book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, 'wallabag'); /* * Front page */ if (file_exists($this->logoPath)) { $book->setCoverImage('Cover.png', file_get_contents($this->logoPath), 'image/png'); } $book->addChapter('Notices', 'Cover2.html', $content_start . $this->getExportInformation('PHPePub') . $bookEnd); $book->buildTOC(); /* * Adding actual entries */ // set tags as subjects foreach ($this->entries as $entry) { 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()); $chapter = $content_start . $entry->getContent() . $bookEnd; $book->addChapter($entry->getTitle(), htmlspecialchars($filename) . '.html', $chapter, true, EPub::EXTERNAL_REF_ADD); } return Response::create($book->getBook(), 200, ['Content-Description' => 'File Transfer', 'Content-type' => 'application/epub+zip', 'Content-Disposition' => 'attachment; filename="' . $this->title . '.epub"', 'Content-Transfer-Encoding' => 'binary']); }