addDublinCoreMetadata() public method

Use the DublinCore constants included in EPub, ie DublinCore::DATE
public addDublinCoreMetadata ( string $dublinCoreConstant, string $value )
$dublinCoreConstant string name
$value string
 /**
  * @inheritdoc
  */
 public function initialization(Config $config)
 {
     $this->epub = new EPub();
     $this->epub->setTitle($config->get('title', 'untitled'));
     if ($isbn = $config->get('ISBN')) {
         $this->epub->setIdentifier($isbn, EPub::IDENTIFIER_ISBN);
     } else {
         $this->epub->setIdentifier($config->get('uri'), EPub::IDENTIFIER_URI);
     }
     $this->epub->setLanguage($config->get('language', 'zh-cn'));
     // 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.
     $this->epub->setDescription($config->get('description'));
     $this->epub->setAuthor($config->get('author'), $config->get('author'));
     $this->epub->setPublisher($config->get('publisher.name'), $config->get('publisher.url'));
     // I hope this is a non existent address :)
     $this->epub->setDate(time());
     // Strictly not needed as the book date defaults to time().
     $this->epub->setRights($config->get('copyright'));
     // As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book.
     $this->epub->setSourceURL($config->get('publisher.url'));
     $this->epub->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
     $this->epub->buildTOC(NULL, "toc", "目录", TRUE, TRUE);
 }
Beispiel #2
0
// Title and Identifier are mandatory!
$book->setTitle("Test book");
$book->setIdentifier("http://JohnJaneDoePublications.com/books/TestBook.html", EPub::IDENTIFIER_URI);
// Could also be the ISBN number, preferred for published books, or a UUID.
$book->setLanguage("en");
// 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->setDescription("This is a brief description\nA test ePub book as an example of building a book in PHP");
$book->setAuthor("John Doe Johnson", "Johnson, John Doe");
$book->setPublisher("John and Jane Doe Publications", "http://JohnJaneDoePublications.com/");
// I hope this is a non existent address :)
$book->setDate(time());
// Strictly not needed as the book date defaults to time().
$book->setRights("Copyright and licence information specific for the book.");
// As this is generated, this _could_ contain the name or licence information of the user who purchased the book, if needed. If this is used that way, the identifier must also be made unique for the book.
$book->setSourceURL("http://JohnJaneDoePublications.com/books/TestBook.html");
$book->addDublinCoreMetadata(DublinCore::CONTRIBUTOR, "PHP");
$book->setSubject("Test book");
$book->setSubject("keywords");
$book->setSubject("Chapter levels");
// Insert custom meta data to the book, in this cvase, Calibre series index information.
$book->addCustomMetadata("calibre:series", "PHPePub Test books");
$book->addCustomMetadata("calibre:series_index", "1");
$log->logLine("Set up parameters");
$cssData = "body {\n  margin-left: .5em;\n  margin-right: .5em;\n  text-align: justify;\n}\n\np {\n  font-family: serif;\n  font-size: 10pt;\n  text-align: justify;\n  text-indent: 1em;\n  margin-top: 0px;\n  margin-bottom: 1ex;\n}\n\nh1, h2 {\n  font-family: sans-serif;\n  font-style: italic;\n  text-align: center;\n  background-color: #6b879c;\n  color: white;\n  width: 100%;\n}\n\nh1 {\n    margin-bottom: 2px;\n}\n\nh2 {\n    margin-top: -2px;\n    margin-bottom: 2px;\n}\n";
$log->logLine("Add css");
$book->addCSSFile("styles.css", "css1", $cssData);
// This test requires you have an image, change "demo/cover-image.jpg" to match your location.
$log->logLine("Add Cover Image");
$book->setCoverImage("Cover.jpg", file_get_contents("demo/cover-image.jpg"), "image/jpeg");
// A better way is to let EPub handle the image itself, as it may need resizing. Most e-books are only about 600x800
//  pixels, adding mega-pixel images is a waste of place and spends bandwidth. setCoverImage can resize the image.
Beispiel #3
0
 /**
  * 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']);
 }