/** * * Enter description here ... * * @param string $name * @param string $fileAs * @param string $role Use the MarcCode constants */ function addColaborator($name, $fileAs = null, $role = null) { $dc = new DublinCore(DublinCore::CONTRIBUTOR, trim($name)); if ($fileAs !== null) { $dc->addOpfAttr("file-as", trim($fileAs)); } if ($role !== null) { $dc->addOpfAttr("role", trim($role)); } $this->metadata->addDublinCore($dc); }
/** * Check for mandatory parameters and finalize the e-book. * Once finalized, the book is locked for further additions. * * @return bool $success */ function finalize() { if ($this->isFinalized || $this->chapterCount == 0 || empty($this->title) || empty($this->language)) { return false; } if (empty($this->identifier) || empty($this->identifierType)) { $this->setIdentifier($this->createUUID(4), EPub::IDENTIFIER_UUID); } if ($this->date == 0) { $this->date = time(); } if (empty($this->sourceURL)) { $this->sourceURL = $this->getCurrentPageURL(); } if (empty($this->publisherURL)) { $this->sourceURL = $this->getCurrentServerURL(); } // Generate OPF data: $this->opf->setIdent("BookId"); $this->opf->initialize($this->title, $this->language, $this->identifier, $this->identifierType); $DCdate = new DublinCore(DublinCore::DATE, gmdate($this->dateformat, $this->date)); $DCdate->addOpfAttr("event", "publication"); $this->opf->metadata->addDublinCore($DCdate); if (!empty($this->description)) { $this->opf->addDCMeta(DublinCore::DESCRIPTION, $this->decodeHtmlEntities($this->description)); } if (!empty($this->publisherName)) { $this->opf->addDCMeta(DublinCore::PUBLISHER, $this->decodeHtmlEntities($this->publisherName)); } if (!empty($this->publisherURL)) { $this->opf->addDCMeta(DublinCore::RELATION, $this->decodeHtmlEntities($this->publisherURL)); } if (!empty($this->author)) { $author = $this->decodeHtmlEntities($this->author); $this->opf->addCreator($author, $this->decodeHtmlEntities($this->authorSortKey), MarcCode::AUTHOR); $this->ncx->setDocAuthor($author); } if (!empty($this->rights)) { $this->opf->addDCMeta(DublinCore::RIGHTS, $this->decodeHtmlEntities($this->rights)); } if (!empty($this->coverage)) { $this->opf->addDCMeta(DublinCore::COVERAGE, $this->decodeHtmlEntities($this->coverage)); } if (!empty($this->sourceURL)) { $this->opf->addDCMeta(DublinCore::SOURCE, $this->sourceURL); } if (!empty($this->relation)) { $this->opf->addDCMeta(DublinCore::RELATION, $this->decodeHtmlEntities($this->relation)); } if ($this->isCoverImageSet) { $this->opf->addMeta("cover", "CoverImage"); } if (!empty($this->generator)) { $gen = $this->decodeHtmlEntities($this->generator); $this->opf->addMeta("generator", $gen); $this->ncx->addMetaEntry("dtb:generator", $gen); } if ($this->EPubMark) { $this->opf->addMeta("generator", "EPub (Version " . self::VERSION . ") by A. Grandt, http://www.phpclasses.org/package/6115 or https://github.com/Grandt/PHPePub/"); } reset($this->ncx->chapterList); list($firstChapterName, $firstChapterNavPoint) = each($this->ncx->chapterList); /** @var $firstChapterNavPoint NavPoint */ $firstChapterFileName = $firstChapterNavPoint->getContentSrc(); $this->opf->addReference(Reference::TEXT, $this->decodeHtmlEntities($firstChapterName), $firstChapterFileName); $this->ncx->setUid($this->identifier); $this->ncx->setDocTitle($this->decodeHtmlEntities($this->title)); $this->ncx->referencesOrder = $this->referencesOrder; if ($this->isReferencesAddedToToc) { $this->ncx->finalizeReferences(); } $this->finalizeTOC(); if (!$this->isEPubVersion2()) { $this->addEPub3TOC("epub3toc.xhtml", $this->buildEPub3TOC()); } $opfFinal = $this->fixEncoding($this->opf->finalize()); $ncxFinal = $this->fixEncoding($this->ncx->finalize()); if (mb_detect_encoding($opfFinal, 'UTF-8', true) === "UTF-8") { $this->zip->addFile($opfFinal, $this->bookRoot . "book.opf"); } else { $this->zip->addFile(mb_convert_encoding($opfFinal, "UTF-8"), $this->bookRoot . "book.opf"); } if (mb_detect_encoding($ncxFinal, 'UTF-8', true) === "UTF-8") { $this->zip->addFile($ncxFinal, $this->bookRoot . "book.ncx"); } else { $this->zip->addFile(mb_convert_encoding($ncxFinal, "UTF-8"), $this->bookRoot . "book.ncx"); } $this->opf = null; $this->ncx = null; $this->isFinalized = true; return true; }