/** * create the file * @var $data Book the content of the book * @return string */ public function create(Book $book) { $oldBookTitle = $book->title; $css = $this->getCss($book); $this->i18n = getI18n($book->lang); setlocale(LC_TIME, $book->lang . '_' . strtoupper($book->lang) . '.utf8'); $wsUrl = wikisourceUrl($book->lang, $book->title); $cleaner = new BookCleanerEpub($this->getVersion()); $cleaner->clean($book, wikisourceUrl($book->lang)); $fileName = buildTemporaryFileName($book->title, 'epub'); $zip = $this->createZipFile($fileName); $zip->addFromString('META-INF/container.xml', $this->getXmlContainer()); $zip->addFromString('OPS/content.opf', $this->getOpfContent($book, $wsUrl)); $zip->addFromString('OPS/toc.ncx', $this->getNcxToc($book, $wsUrl)); if ($book->cover != '') { $zip->addFromString('OPS/cover.xhtml', $this->getXhtmlCover($book)); } $zip->addFromString('OPS/title.xhtml', $this->getXhtmlTitle($book)); $zip->addFromString('OPS/about.xhtml', $this->getXhtmlAbout($book, $wsUrl)); $dir = __DIR__; $zip->addFile($dir . '/images/Accueil_scribe.png', 'OPS/images/Accueil_scribe.png'); $font = FontProvider::getData($book->options['fonts']); if ($font !== null) { foreach ($font['otf'] as $name => $path) { $zip->addFile($dir . '/fonts/' . $font['name'] . '/' . $path, 'OPS/fonts/' . $font['name'] . $name . '.otf'); } } if ($book->content) { $zip->addFromString('OPS/' . $book->title . '.xhtml', $book->content->saveXML()); } if (!empty($book->chapters)) { foreach ($book->chapters as $chapter) { $zip->addFromString('OPS/' . $chapter->title . '.xhtml', $chapter->content->saveXML()); foreach ($chapter->chapters as $subpage) { $zip->addFromString('OPS/' . $subpage->title . '.xhtml', $subpage->content->saveXML()); } } } foreach ($book->pictures as $picture) { $zip->addFromString('OPS/images/' . $picture->title, $picture->content); } $zip->addFromString('OPS/main.css', $css); $this->addContent($book, $zip); $book->title = $oldBookTitle; $zip->close(); return $fileName; }
protected function getOpfContent(Book $book, $wsUrl) { $content = '<?xml version="1.0" encoding="UTF-8" ?> <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uid" version="3.0" xml:lang="' . $book->lang . '" prefix="cc: http://creativecommons.org/ns#"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:identifier id="uid">' . $wsUrl . '</dc:identifier> <meta property="dcterms:modified">' . date('Y-m-d\\TH:i:s') . 'Z</meta> <dc:language>' . $book->lang . '</dc:language> <dc:title id="meta-title">' . htmlspecialchars($book->name, ENT_QUOTES) . '</dc:title> <meta refines="#meta-title" property="title-type">main</meta> <dc:source>' . $wsUrl . '</dc:source> <dc:rights xml:lang="en">Creative Commons BY-SA 3.0</dc:rights> <link rel="cc:license" href="http://creativecommons.org/licenses/by-sa/3.0/" /> <dc:rights xml:lang="en">GNU Free Documentation License</dc:rights> <link rel="cc:license" href="http://www.gnu.org/copyleft/fdl.html" /> <dc:contributor id="meta-bkp">Wikisource</dc:contributor> <meta refines="#meta-bkp" property="role" scheme="marc:relators">bkp</meta>'; if ($book->author != '') { $content .= '<dc:creator id="meta-aut">' . htmlspecialchars($book->author, ENT_QUOTES) . '</dc:creator> <meta refines="#meta-aut" property="role" scheme="marc:relators">aut</meta>'; } if ($book->translator != '') { $content .= '<dc:contributor id="meta-trl">' . htmlspecialchars($book->translator, ENT_QUOTES) . '</dc:contributor> <meta refines="#meta-trl" property="role" scheme="marc:relators">trl</meta>'; } if ($book->illustrator != '') { $content .= '<dc:contributor id="meta-ill">' . htmlspecialchars($book->illustrator, ENT_QUOTES) . '</dc:contributor> <meta refines="#meta-ill" property="role" scheme="marc:relators">ill</meta>'; } if ($book->publisher != '') { $content .= '<dc:publisher>' . htmlspecialchars($book->publisher, ENT_QUOTES) . '</dc:publisher>'; } if ($book->year != '') { $content .= '<dc:date>' . htmlspecialchars($book->year, ENT_QUOTES) . '</dc:date>'; } if ($book->cover != '') { $content .= '<meta name="cover" content="cover" />'; } else { $content .= '<meta name="cover" content="title" />'; } $content .= '</metadata> <manifest> <item href="nav.xhtml" id="nav" media-type="application/xhtml+xml" properties="nav" /> <item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>'; // deprecated if ($book->cover != '') { // TODO use image ? $content .= '<item id="cover" href="cover.xhtml" media-type="application/xhtml+xml" />'; } $content .= '<item id="title" href="title.xhtml" media-type="application/xhtml+xml" /> <item id="mainCss" href="main.css" media-type="text/css" /> <item id="Accueil_scribe.png" href="images/Accueil_scribe.png" media-type="image/png" />'; $font = FontProvider::getData($book->options['fonts']); if ($font !== null) { foreach ($font['otf'] as $name => $path) { $content .= '<item id="' . $font['name'] . $name . '" href="fonts/' . $font['name'] . $name . '.otf" media-type="font/opentype" />' . "\n"; } } if ($book->content) { $content .= '<item id="' . $book->title . '" href="' . $book->title . '.xhtml" media-type="application/xhtml+xml" />' . "\n"; } foreach ($book->chapters as $chapter) { $content .= '<item id="' . $chapter->title . '" href="' . $chapter->title . '.xhtml" media-type="application/xhtml+xml" />' . "\n"; foreach ($chapter->chapters as $subpage) { $content .= '<item id="' . $subpage->title . '" href="' . $subpage->title . '.xhtml" media-type="application/xhtml+xml" />' . "\n"; } } foreach ($book->pictures as $pictureId => $picture) { $content .= '<item id="' . $picture->title . '" href="images/' . $picture->title . '" media-type="' . $picture->mimetype . '"'; if ($book->cover === $pictureId) { $content .= ' properties="cover-image"'; } $content .= ' />' . "\n"; } $content .= '<item id="about" href="about.xhtml" media-type="application/xhtml+xml" /> </manifest> <spine toc="ncx">'; if ($book->cover != '') { $content .= '<itemref idref="cover" linear="no" />'; } $content .= '<itemref idref="title" linear="yes" />'; if ($book->content) { $content .= '<itemref idref="' . $book->title . '" linear="yes" />'; } if (!empty($book->chapters)) { foreach ($book->chapters as $chapter) { $content .= '<itemref idref="' . $chapter->title . '" linear="yes" />'; foreach ($chapter->chapters as $subpage) { $content .= '<itemref idref="' . $subpage->title . '" linear="yes" />'; } } } $content .= '<itemref idref="about" linear="yes" /> </spine> </package>'; return $content; }
protected function getOpfContent(Book $book, $wsUrl) { $content = '<?xml version="1.0" encoding="UTF-8" ?> <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="uid" version="2.0"> <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:dcterms="http://purl.org/dc/terms/"> <dc:identifier id="uid" opf:scheme="URI">' . $wsUrl . '</dc:identifier> <dc:language xsi:type="dcterms:RFC4646">' . $book->lang . '</dc:language> <dc:title>' . htmlspecialchars($book->name, ENT_QUOTES) . '</dc:title> <dc:source>' . $wsUrl . '</dc:source> <dc:date opf:event="ops-publication" xsi:type="dcterms:W3CDTF">' . date(DATE_W3C) . '</dc:date> <dc:rights>http://creativecommons.org/licenses/by-sa/3.0/</dc:rights> <dc:rights>http://www.gnu.org/copyleft/fdl.html</dc:rights> <dc:contributor opf:role="bkp">Wikisource</dc:contributor>'; if ($book->author != '') { $content .= '<dc:creator opf:role="aut">' . htmlspecialchars($book->author, ENT_QUOTES) . '</dc:creator>'; } if ($book->translator != '') { $content .= '<dc:contributor opf:role="trl">' . htmlspecialchars($book->translator, ENT_QUOTES) . '</dc:contributor>'; } if ($book->illustrator != '') { $content .= '<dc:contributor opf:role="ill">' . htmlspecialchars($book->illustrator, ENT_QUOTES) . '</dc:contributor>'; } if ($book->publisher != '') { $content .= '<dc:publisher>' . htmlspecialchars($book->publisher, ENT_QUOTES) . '</dc:publisher>'; } if ($book->year != '') { $content .= '<dc:date opf:event="original-publication">' . htmlspecialchars($book->year, ENT_QUOTES) . '</dc:date>'; } if ($book->cover != '') { $content .= '<meta name="cover" content="cover" />'; } else { $content .= '<meta name="cover" content="title" />'; } $content .= '</metadata> <manifest> <item href="toc.ncx" id="ncx" media-type="application/x-dtbncx+xml"/>'; if ($book->cover != '') { $content .= '<item id="cover" href="cover.xhtml" media-type="application/xhtml+xml" />'; } $content .= '<item id="title" href="title.xhtml" media-type="application/xhtml+xml" /> <item id="mainCss" href="main.css" media-type="text/css" /> <item id="Accueil_scribe.png" href="images/Accueil_scribe.png" media-type="image/png" />'; $font = FontProvider::getData($book->options['fonts']); if ($font !== null) { foreach ($font['otf'] as $name => $path) { $content .= '<item id="' . $font['name'] . $name . '" href="fonts/' . $font['name'] . $name . '.otf" media-type="font/opentype" />' . "\n"; } } if ($book->content) { $content .= '<item id="' . $book->title . '" href="' . $book->title . '.xhtml" media-type="application/xhtml+xml" />' . "\n"; } foreach ($book->chapters as $chapter) { $content .= '<item id="' . $chapter->title . '" href="' . $chapter->title . '.xhtml" media-type="application/xhtml+xml" />' . "\n"; foreach ($chapter->chapters as $subpage) { $content .= '<item id="' . $subpage->title . '" href="' . $subpage->title . '.xhtml" media-type="application/xhtml+xml" />' . "\n"; } } foreach ($book->pictures as $picture) { $content .= '<item id="' . $picture->title . '" href="images/' . $picture->title . '" media-type="' . $picture->mimetype . '" />' . "\n"; } $content .= '<item id="about" href="about.xhtml" media-type="application/xhtml+xml" /> </manifest> <spine toc="ncx">'; if ($book->cover != '') { $content .= '<itemref idref="cover" linear="no" />'; } $content .= '<itemref idref="title" linear="yes" />'; if ($book->content) { $content .= '<itemref idref="' . $book->title . '" linear="yes" />'; } if (!empty($book->chapters)) { foreach ($book->chapters as $chapter) { $content .= '<itemref idref="' . $chapter->title . '" linear="yes" />'; foreach ($chapter->chapters as $subpage) { $content .= '<itemref idref="' . $subpage->title . '" linear="yes" />'; } } } $content .= '<itemref idref="about" linear="yes" /> </spine> <guide>'; if ($book->cover != '') { $content .= '<reference type="cover" title="' . htmlspecialchars($this->i18n['cover'], ENT_QUOTES) . '" href="cover.xhtml" />'; } else { $content .= '<reference type="cover" title="' . htmlspecialchars($this->i18n['cover'], ENT_QUOTES) . '" href="title.xhtml" />'; } $content .= '<reference type="title-page" title="' . htmlspecialchars($this->i18n['title_page'], ENT_QUOTES) . '" href="title.xhtml" />'; if ($book->content) { $content .= '<reference type="text" title="' . htmlspecialchars($book->name, ENT_QUOTES) . '" href="' . $book->title . '.xhtml" />'; } $content .= '<reference type="copyright-page" title="' . htmlspecialchars($this->i18n['about'], ENT_QUOTES) . '" href="about.xhtml" /> </guide> </package>'; return $content; }