public function buildEntry(Book $book, DOMDocument $dom) { $wsUrl = wikisourceUrl($book->lang, $book->title); $node = $dom->createElement('entry'); $node->setAttribute('xml:lang', $book->lang); $this->addNode($dom, $node, 'title', $book->name); $this->addNode($dom, $node, 'id', $wsUrl, 'dcterms:URI'); // TODO published? $this->addNode($dom, $node, 'updated', date(DATE_ATOM)); $this->addNode($dom, $node, 'rights', 'http://creativecommons.org/licenses/by-sa/3.0'); $this->addPersonNode($dom, $node, 'author', $book->author); $this->addPersonNode($dom, $node, 'contributor', $book->translator); $this->addPersonNode($dom, $node, 'contributor', $book->illustrator); foreach ($book->categories as $categorie) { $cat = $dom->createElement('category'); $cat->setAttribute('label', $categorie); $cat->setAttribute('term', $categorie); $node->appendChild($cat); } $this->addNode($dom, $node, 'dc:identifier', $wsUrl, 'dcterms:URI'); $this->addNode($dom, $node, 'dc:language', $book->lang, 'dcterms:RFC4646'); $this->addNode($dom, $node, 'dc:source', wikisourceUrl($book->lang, $book->title), 'dcterms:URI'); $this->addNode($dom, $node, 'dcterms:issued', $book->year, 'dcterms:W3CDTF'); $this->addNode($dom, $node, 'dc:publisher', $book->publisher); $this->addLink($dom, $node, 'alternate', $this->buildExportUrl($book, 'atom'), 'application/atom+xml;type=entry;profile=opds-catalog'); $this->addLink($dom, $node, 'alternate', $wsUrl, 'text/html'); $this->addLink($dom, $node, 'http://opds-spec.org/acquisition', $this->buildExportUrl($book, 'epub'), 'application/epub+zip'); $this->addLink($dom, $node, 'http://opds-spec.org/acquisition', $this->buildExportUrl($book, 'mobi'), 'application/x-mobipocket-ebook'); $this->addLink($dom, $node, 'http://opds-spec.org/acquisition', $this->buildExportUrl($book, 'xhtml'), 'application/xhtml+xml'); if ($book->cover !== '') { $this->addLink($dom, $node, 'http://opds-spec.org/image', $book->pictures[$book->cover]->url, $book->pictures[$book->cover]->mimetype); } return $node; }
/** * 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; }
private function buildFromTitles(array $titles, $fromPage = '') { $generator = new AtomGenerator($this->exportBasePath); $dom = new DOMDocument('1.0', 'UTF-8'); $feed = $dom->createElement('feed'); $generator->appendNamespaces($feed); $feed->setAttribute('xml:lang', $this->lang); $this->addNode($dom, $feed, 'title', $fromPage); $this->addNode($dom, $feed, 'updated', date(DATE_ATOM)); if ($fromPage !== '') { $wsUrl = wikisourceUrl($this->lang, $fromPage); $this->addNode($dom, $feed, 'id', $wsUrl, 'dcterms:URI'); $this->addLink($dom, $feed, 'alternate', $wsUrl, 'text/html'); } foreach (array_chunk($titles, 20) as $chunk) { foreach ($this->bookProvider->getMulti($chunk, true) as $book) { $entry = $generator->buildEntry($book, $dom); $feed->appendChild($entry); } } $dom->appendChild($feed); return $dom->saveXML(); }