setIdentifier() public method

Use the URI, or ISBN if available. An unambiguous reference to the resource within a given context. Recommended best practice is to identify the resource by means of a string conforming to a formal identification system. Used for the dc:identifier metadata parameter in the OPF file, as well as dtb:uid in the NCX file. Identifier type should only be: EPub::IDENTIFIER_URI EPub::IDENTIFIER_ISBN EPub::IDENTIFIER_UUID
public setIdentifier ( string $identifier, string $identifierType ) : boolean
$identifier string
$identifierType string
return boolean $success
 /**
  * @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
$content_start = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" . "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" . "    \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" . "<head>" . "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" . "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\" />\n" . "<title>Test Book</title>\n" . "</head>\n" . "<body>\n";
$bookEnd = "</body>\n</html>\n";
// setting timezone for time functions used for logging to work properly
date_default_timezone_set('Europe/Berlin');
$log = new Logger("Example", TRUE);
$fileDir = './PHPePub';
// Default is EPub::BOOK_VERSION_EPUB2
$book = new EPub();
$log->logLine("new EPub()");
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());
// 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");
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']);
 }