PageRenderTime 52ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/epub/PHPePub/EPub.OPF.php

https://github.com/ldleman/Leed-market
PHP | 1226 lines | 458 code | 153 blank | 615 comment | 47 complexity | 6ecff73e4237c00fc3486d0fa18cb455 MD5 | raw file
  1. <?php
  2. /**
  3. * ePub OPF file structure
  4. *
  5. * @author A. Grandt <php@grandt.com>
  6. * @copyright 2009-2014 A. Grandt
  7. * @license GNU LGPL, Attribution required for commercial implementations, requested for everything else.
  8. * @version 3.20
  9. */
  10. class Opf {
  11. const _VERSION = 3.20;
  12. /* Core Media types.
  13. * These types are the only guaranteed mime types any ePub reader must understand.
  14. * Any other type muse define a fall back whose fallback chain will end in one of these.
  15. */
  16. const TYPE_GIF = "image/gif";
  17. const TYPE_JPEG = "image/jpeg";
  18. const TYPE_PNG = "image/png";
  19. const TYPE_SVG = "image/svg+xml";
  20. const TYPE_XHTML = "application/xhtml+xml";
  21. const TYPE_DTBOOK = "application/x-dtbook+xml";
  22. const TYPE_CSS = "text/css";
  23. const TYPE_XML = "application/xml";
  24. const TYPE_OEB1_DOC = "text/x-oeb1-document"; // Deprecated
  25. const TYPE_OEB1_CSS = "text/x-oeb1-css"; // Deprecated
  26. const TYPE_NCX = "application/x-dtbncx+xml";
  27. private $bookVersion = EPub::BOOK_VERSION_EPUB2;
  28. private $ident = "BookId";
  29. public $date = NULL;
  30. public $metadata = NULL;
  31. public $manifest = NULL;
  32. public $spine = NULL;
  33. public $guide = NULL;
  34. /**
  35. * Class constructor.
  36. *
  37. * @return void
  38. */
  39. function __construct($ident = "BookId", $bookVersion = EPub::BOOK_VERSION_EPUB2) {
  40. $this->setIdent($ident);
  41. $this->setVersion($bookVersion);
  42. $this->metadata = new Metadata();
  43. $this->manifest = new Manifest();
  44. $this->spine = new Spine();
  45. $this->guide = new Guide();
  46. }
  47. /**
  48. * Class destructor
  49. *
  50. * @return void
  51. */
  52. function __destruct() {
  53. unset ($this->bookVersion, $this->ident, $this->date, $this->metadata, $this->manifest, $this->spine, $this->guide);
  54. }
  55. /**
  56. *
  57. * Enter description here ...
  58. *
  59. * @param string $ident
  60. */
  61. function setVersion($bookVersion) {
  62. $this->bookVersion = is_string($bookVersion) ? trim($bookVersion) : EPub::BOOK_VERSION_EPUB2;
  63. }
  64. function isEPubVersion2() {
  65. return $this->bookVersion === EPub::BOOK_VERSION_EPUB2;
  66. }
  67. /**
  68. *
  69. * Enter description here ...
  70. *
  71. * @param string $ident
  72. */
  73. function setIdent($ident = "BookId") {
  74. $this->ident = is_string($ident) ? trim($ident) : "BookId";
  75. }
  76. /**
  77. *
  78. * Enter description here ...
  79. *
  80. * @return string
  81. */
  82. function finalize() {
  83. $opf = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
  84. . "<package xmlns=\"http://www.idpf.org/2007/opf\" unique-identifier=\"" . $this->ident . "\" version=\"" . $this->bookVersion . "\">\n";
  85. $opf .= $this->metadata->finalize($this->bookVersion, $this->date);
  86. $opf .= $this->manifest->finalize($this->bookVersion);
  87. $opf .= $this->spine->finalize();
  88. if ($this->guide->length() > 0) {
  89. $opf .= $this->guide->finalize();
  90. }
  91. return $opf . "</package>\n";
  92. }
  93. // Convenience functions:
  94. /**
  95. *
  96. * Enter description here ...
  97. *
  98. * @param string $title
  99. * @param string $language
  100. * @param string $identifier
  101. * @param string $identifierScheme
  102. */
  103. function initialize($title, $language, $identifier, $identifierScheme) {
  104. $this->metadata->addDublinCore(new DublinCore("title", $title));
  105. $this->metadata->addDublinCore(new DublinCore("language", $language));
  106. $dc = new DublinCore("identifier", $identifier);
  107. $dc->addAttr("id", $this->ident);
  108. $dc->addOpfAttr("scheme", $identifierScheme);
  109. $this->metadata->addDublinCore($dc);
  110. }
  111. /**
  112. *
  113. * Enter description here ...
  114. *
  115. * @param string $id
  116. * @param string $href
  117. * @param string $mediaType
  118. */
  119. function addItem($id, $href, $mediaType, $properties = NULL) {
  120. $this->manifest->addItem(new Item($id, $href, $mediaType, $properties));
  121. }
  122. /**
  123. *
  124. * Enter description here ...
  125. *
  126. * @param string $idref
  127. * @param bool $linear
  128. */
  129. function addItemRef($idref, $linear = TRUE) {
  130. $this->spine->addItemref(new Itemref($idref, $linear));
  131. }
  132. /**
  133. *
  134. * Enter description here ...
  135. *
  136. * @param string $type
  137. * @param string $title
  138. * @param string $href
  139. */
  140. function addReference($type, $title, $href) {
  141. $this->guide->addReference(new Reference($type, $title, $href));
  142. }
  143. /**
  144. *
  145. * Enter description here ...
  146. *
  147. * @param string $name
  148. * @param string $value
  149. */
  150. function addDCMeta($name, $value) {
  151. $this->metadata->addDublinCore(new DublinCore($name, $value));
  152. }
  153. /**
  154. *
  155. * Enter description here ...
  156. *
  157. * @param string $name
  158. * @param string $content
  159. */
  160. function addMeta($name, $content) {
  161. $this->metadata->addMeta($name, $content);
  162. }
  163. /**
  164. *
  165. * Enter description here ...
  166. *
  167. * @param string $name
  168. * @param string $fileAs
  169. * @param string $role Use the MarcCode constants
  170. */
  171. function addCreator($name, $fileAs = NULL, $role = NULL) {
  172. $dc = new DublinCore(DublinCore::CREATOR, trim($name));
  173. if ($fileAs !== NULL) {
  174. $dc->addOpfAttr("file-as", trim($fileAs));
  175. }
  176. if ($role !== NULL) {
  177. $dc->addOpfAttr("role", trim($role));
  178. }
  179. $this->metadata->addDublinCore($dc);
  180. }
  181. /**
  182. *
  183. * Enter description here ...
  184. *
  185. * @param string $name
  186. * @param string $fileAs
  187. * @param string $role Use the MarcCode constants
  188. */
  189. function addColaborator($name, $fileAs = NULL, $role = NULL) {
  190. $dc = new DublinCore(DublinCore::CONTRIBUTOR, trim($name));
  191. if ($fileAs !== NULL) {
  192. $dc->addOpfAttr("file-as", trim($fileAs));
  193. }
  194. if ($role !== NULL) {
  195. $dc->addOpfAttr("role", trim($role));
  196. }
  197. $this->metadata->addDublinCore($dc);
  198. }
  199. }
  200. /**
  201. * ePub OPF Metadata structures
  202. */
  203. class Metadata {
  204. const _VERSION = 3.00;
  205. private $dc = array();
  206. private $meta = array();
  207. /**
  208. * Class constructor.
  209. *
  210. * @return void
  211. */
  212. function __construct() {
  213. }
  214. /**
  215. * Class destructor
  216. *
  217. * @return void
  218. */
  219. function __destruct() {
  220. unset ($this->dc, $this->meta);
  221. }
  222. /**
  223. *
  224. * Enter description here ...
  225. *
  226. * @param DublinCore $dc
  227. */
  228. function addDublinCore($dc) {
  229. if ($dc != NULL && is_object($dc) && get_class($dc) === "DublinCore") {
  230. $this->dc[] = $dc;
  231. }
  232. }
  233. /**
  234. *
  235. * Enter description here ...
  236. *
  237. * @param string $name
  238. * @param string $content
  239. */
  240. function addMeta($name, $content) {
  241. $name = is_string($name) ? trim($name) : NULL;
  242. if (isset($name)) {
  243. $content = is_string($content) ? trim($content) : NULL;
  244. }
  245. if (isset($content)) {
  246. $this->meta[] = array ($name => $content);
  247. }
  248. }
  249. /**
  250. *
  251. * @param string $bookVersion
  252. * @param int $date
  253. * @return string
  254. */
  255. function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2, $date = NULL) {
  256. $metadata = "\t<metadata xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n";
  257. if ($bookVersion === EPub::BOOK_VERSION_EPUB2) {
  258. $metadata .= "\t\txmlns:opf=\"http://www.idpf.org/2007/opf\"\n\t\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
  259. } else {
  260. $metadata .= "\t\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n";
  261. if (!isset($date)) {
  262. $date = time();
  263. }
  264. $metadata .= "\t\t<meta property=\"dcterms:modified\">" . gmdate("Y-m-d\TH:i:s\Z", $date) . "</meta>\n";
  265. }
  266. foreach ($this->dc as $dc) {
  267. $metadata .= $dc->finalize($bookVersion);
  268. }
  269. foreach ($this->meta as $data) {
  270. list($name, $content) = each($data);
  271. $metadata .= "\t\t<meta name=\"" . $name . "\" content=\"" . $content . "\" />\n";
  272. }
  273. return $metadata . "\t</metadata>\n";
  274. }
  275. }
  276. /**
  277. * ePub OPF Dublin Core (dc:) Metadata structures
  278. */
  279. class DublinCore {
  280. const _VERSION = 3.00;
  281. const CONTRIBUTOR = "contributor";
  282. const COVERAGE = "coverage";
  283. const CREATOR = "creator";
  284. const DATE = "date";
  285. const DESCRIPTION = "description";
  286. const FORMAT = "format";
  287. const IDENTIFIER = "identifier";
  288. const LANGUAGE = "language";
  289. const PUBLISHER = "publisher";
  290. const RELATION = "relation";
  291. const RIGHTS = "rights";
  292. const SOURCE = "source";
  293. const SUBJECT = "subject";
  294. const TITLE = "title";
  295. const TYPE = "type";
  296. private $dcName = NULL;
  297. private $dcValue = NULL;
  298. private $attr = array();
  299. private $opfAttr = array();
  300. /**
  301. * Class constructor.
  302. *
  303. * @return void
  304. */
  305. function __construct($name, $value) {
  306. $this->setDc($name, $value);
  307. }
  308. /**
  309. * Class destructor
  310. *
  311. * @return void
  312. */
  313. function __destruct() {
  314. unset ($this->dcName, $this->dcValue, $this->attr, $this->opfAttr);
  315. }
  316. /**
  317. *
  318. * Enter description here ...
  319. *
  320. * @param string $name
  321. * @param string $value
  322. */
  323. function setDc($name, $value) {
  324. $this->dcName = is_string($name) ? trim($name) : NULL;
  325. if (isset($this->dcName)) {
  326. $this->dcValue = isset($value) ? (string)$value : NULL;
  327. }
  328. if (! isset($this->dcValue)) {
  329. $this->dcName = NULL;
  330. }
  331. }
  332. /**
  333. *
  334. * Enter description here ...
  335. *
  336. * @param string $attrName
  337. * @param string $attrValue
  338. */
  339. function addAttr($attrName, $attrValue) {
  340. $attrName = is_string($attrName) ? trim($attrName) : NULL;
  341. if (isset($attrName)) {
  342. $attrValue = is_string($attrValue) ? trim($attrValue) : NULL;
  343. }
  344. if (isset($attrValue)) {
  345. $this->attr[$attrName] = $attrValue;
  346. }
  347. }
  348. /**
  349. *
  350. * Enter description here ...
  351. *
  352. * @param string $opfAttrName
  353. * @param string $opfAttrValue
  354. */
  355. function addOpfAttr($opfAttrName, $opfAttrValue) {
  356. $opfAttrName = is_string($opfAttrName) ? trim($opfAttrName) : NULL;
  357. if (isset($opfAttrName)) {
  358. $opfAttrValue = is_string($opfAttrValue) ? trim($opfAttrValue) : NULL;
  359. }
  360. if (isset($opfAttrValue)) {
  361. $this->opfAttr[$opfAttrName] = $opfAttrValue;
  362. }
  363. }
  364. /**
  365. *
  366. * @param string $bookVersion
  367. * @return string
  368. */
  369. function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2) {
  370. $dc = "\t\t<dc:" . $this->dcName;
  371. if (sizeof($this->attr) > 0) {
  372. while (list($name, $content) = each($this->attr)) {
  373. $dc .= " " . $name . "=\"" . $content . "\"";
  374. }
  375. }
  376. if ($bookVersion === EPub::BOOK_VERSION_EPUB2 && sizeof($this->opfAttr) > 0) {
  377. while (list($name, $content) = each($this->opfAttr)) {
  378. $dc .= " opf:" . $name . "=\"" . $content . "\"";
  379. }
  380. }
  381. return $dc . ">" . $this->dcValue . "</dc:" . $this->dcName . ">\n";
  382. }
  383. }
  384. /**
  385. * ePub OPF Manifest structure
  386. */
  387. class Manifest {
  388. const _VERSION = 3.00;
  389. private $items = array();
  390. /**
  391. * Class constructor.
  392. *
  393. * @return void
  394. */
  395. function __construct() {
  396. }
  397. /**
  398. * Class destructor
  399. *
  400. * @return void
  401. */
  402. function __destruct() {
  403. unset ($this->items);
  404. }
  405. /**
  406. *
  407. * Enter description here ...
  408. *
  409. * @param Item $item
  410. */
  411. function addItem($item) {
  412. if ($item != NULL && is_object($item) && get_class($item) === "Item") {
  413. $this->items[] = $item;
  414. }
  415. }
  416. /**
  417. *
  418. * @param string $bookVersion
  419. * @return string
  420. */
  421. function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2) {
  422. $manifest = "\n\t<manifest>\n";
  423. foreach ($this->items as $item) {
  424. $manifest .= $item->finalize($bookVersion);
  425. }
  426. return $manifest . "\t</manifest>\n";
  427. }
  428. }
  429. /**
  430. * ePub OPF Item structure
  431. */
  432. class Item {
  433. const _VERSION = 3.00;
  434. private $id = NULL;
  435. private $href = NULL;
  436. private $mediaType = NULL;
  437. private $properties = NULL;
  438. private $requiredNamespace = NULL;
  439. private $requiredModules = NULL;
  440. private $fallback = NULL;
  441. private $fallbackStyle = NULL;
  442. /**
  443. * Class constructor.
  444. *
  445. * @return void
  446. */
  447. function __construct($id, $href, $mediaType, $properties = NULL) {
  448. $this->setId($id);
  449. $this->setHref($href);
  450. $this->setMediaType($mediaType);
  451. $this->setProperties($properties);
  452. }
  453. /**
  454. * Class destructor
  455. *
  456. * @return void
  457. */
  458. function __destruct() {
  459. unset ($this->id, $this->href, $this->mediaType);
  460. unset ($this->properties, $this->requiredNamespace, $this->requiredModules, $this->fallback, $this->fallbackStyle);
  461. }
  462. /**
  463. *
  464. * Enter description here ...
  465. *
  466. * @param string $id
  467. */
  468. function setId($id) {
  469. $this->id = is_string($id) ? trim($id) : NULL;
  470. }
  471. /**
  472. *
  473. * Enter description here ...
  474. *
  475. * @param string $href
  476. */
  477. function setHref($href) {
  478. $this->href = is_string($href) ? trim($href) : NULL;
  479. }
  480. /**
  481. *
  482. * Enter description here ...
  483. *
  484. * @param string $mediaType
  485. */
  486. function setMediaType($mediaType) {
  487. $this->mediaType = is_string($mediaType) ? trim($mediaType) : NULL;
  488. }
  489. /**
  490. *
  491. * Enter description here ...
  492. *
  493. * @param string $properties
  494. */
  495. function setProperties($properties) {
  496. $this->properties = is_string($properties) ? trim($properties) : NULL;
  497. }
  498. /**
  499. *
  500. * Enter description here ...
  501. *
  502. * @param string $requiredNamespace
  503. */
  504. function setRequiredNamespace($requiredNamespace) {
  505. $this->requiredNamespace = is_string($requiredNamespace) ? trim($requiredNamespace) : NULL;
  506. }
  507. /**
  508. *
  509. * Enter description here ...
  510. *
  511. * @param string $requiredModules
  512. */
  513. function setRequiredModules($requiredModules) {
  514. $this->requiredModules = is_string($requiredModules) ? trim($requiredModules) : NULL;
  515. }
  516. /**
  517. *
  518. * Enter description here ...
  519. *
  520. * @param string $fallback
  521. */
  522. function setfallback($fallback) {
  523. $this->fallback = is_string($fallback) ? trim($fallback) : NULL;
  524. }
  525. /**
  526. *
  527. * Enter description here ...
  528. *
  529. * @param string $fallbackStyle
  530. */
  531. function setFallbackStyle($fallbackStyle) {
  532. $this->fallbackStyle = is_string($fallbackStyle) ? trim($fallbackStyle) : NULL;
  533. }
  534. /**
  535. *
  536. * @param string $bookVersion
  537. * @return string
  538. */
  539. function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2) {
  540. $item = "\t\t<item id=\"" . $this->id . "\" href=\"" . $this->href . "\" media-type=\"" . $this->mediaType . "\" ";
  541. if ($bookVersion === EPub::BOOK_VERSION_EPUB3 && isset($this->properties)) {
  542. $item .= "properties=\"" . $this->properties . "\" ";
  543. }
  544. if (isset($this->requiredNamespace)) {
  545. $item .= "\n\t\t\trequired-namespace=\"" . $this->requiredNamespace . "\" ";
  546. if (isset($this->requiredModules)) {
  547. $item .= "required-modules=\"" . $this->requiredModules . "\" ";
  548. }
  549. }
  550. if (isset($this->fallback)) {
  551. $item .= "\n\t\t\tfallback=\"" . $this->fallback . "\" ";
  552. }
  553. if (isset($this->fallbackStyle)) {
  554. $item .= "\n\t\t\tfallback-style=\"" . $this->fallbackStyle . "\" ";
  555. }
  556. return $item . "/>\n";
  557. }
  558. }
  559. /**
  560. * ePub OPF Spine structure
  561. */
  562. class Spine {
  563. const _VERSION = 1.00;
  564. private $itemrefs = array();
  565. private $toc = NULL;
  566. /**
  567. * Class constructor.
  568. *
  569. * @return void
  570. */
  571. function __construct($toc = "ncx") {
  572. $this->setToc($toc);
  573. }
  574. /**
  575. * Class destructor
  576. *
  577. * @return void
  578. */
  579. function __destruct() {
  580. unset ($this->itemrefs, $this->toc);
  581. }
  582. /**
  583. *
  584. * Enter description here ...
  585. *
  586. * @param string $toc
  587. */
  588. function setToc($toc) {
  589. $this->toc = is_string($toc) ? trim($toc) : NULL;
  590. }
  591. /**
  592. *
  593. * Enter description here ...
  594. *
  595. * @param Itemref $itemref
  596. */
  597. function addItemref($itemref) {
  598. if ($itemref != NULL
  599. && is_object($itemref)
  600. && get_class($itemref) === "Itemref"
  601. && !isset($this->itemrefs[$itemref->getIdref()])) {
  602. $this->itemrefs[$itemref->getIdref()] = $itemref;
  603. }
  604. }
  605. /**
  606. *
  607. * Enter description here ...
  608. *
  609. * @return string
  610. */
  611. function finalize() {
  612. $spine = "\n\t<spine toc=\"" . $this->toc . "\">\n";
  613. foreach ($this->itemrefs as $itemref) {
  614. $spine .= $itemref->finalize();
  615. }
  616. return $spine . "\t</spine>\n";
  617. }
  618. }
  619. /**
  620. * ePub OPF ItemRef structure
  621. */
  622. class Itemref {
  623. const _VERSION = 3.00;
  624. private $idref = NULL;
  625. private $linear = TRUE;
  626. /**
  627. * Class constructor.
  628. *
  629. * @return void
  630. */
  631. function __construct($idref, $linear = TRUE) {
  632. $this->setIdref($idref);
  633. $this->setLinear($linear);
  634. }
  635. /**
  636. * Class destructor
  637. *
  638. * @return void
  639. */
  640. function __destruct() {
  641. unset ($this->idref, $this->linear);
  642. }
  643. /**
  644. *
  645. * Enter description here ...
  646. *
  647. * @param string $idref
  648. */
  649. function setIdref($idref) {
  650. $this->idref = is_string($idref) ? trim($idref) : NULL;
  651. }
  652. /**
  653. *
  654. * Enter description here ...
  655. *
  656. * @return string $idref
  657. */
  658. function getIdref() {
  659. return $this->idref;
  660. }
  661. /**
  662. *
  663. * Enter description here ...
  664. *
  665. * @param bool $linear
  666. */
  667. function setLinear($linear = TRUE) {
  668. $this->linear = $linear === TRUE;
  669. }
  670. /**
  671. *
  672. * Enter description here ...
  673. *
  674. * @return string
  675. */
  676. function finalize() {
  677. $itemref = "\t\t<itemref idref=\"" . $this->idref . "\"";
  678. if ($this->linear == FALSE) {
  679. return $itemref .= " linear=\"no\" />\n";
  680. }
  681. return $itemref . " />\n";
  682. }
  683. }
  684. /**
  685. * ePub OPF Guide structure
  686. */
  687. class Guide {
  688. const _VERSION = 3.00;
  689. private $references = array();
  690. /**
  691. * Class constructor.
  692. *
  693. * @return void
  694. */
  695. function __construct() {
  696. }
  697. /**
  698. * Class destructor
  699. *
  700. * @return void
  701. */
  702. function __destruct() {
  703. unset ($this->references);
  704. }
  705. /**
  706. *
  707. * Enter description here ...
  708. *
  709. */
  710. function length() {
  711. return sizeof($this->references);
  712. }
  713. /**
  714. *
  715. * Enter description here ...
  716. *
  717. * @param Reference $reference
  718. */
  719. function addReference($reference) {
  720. if ($reference != NULL && is_object($reference) && get_class($reference) === "Reference") {
  721. $this->references[] = $reference;
  722. }
  723. }
  724. /**
  725. *
  726. * Enter description here ...
  727. *
  728. * @return string
  729. */
  730. function finalize() {
  731. $ref = "";
  732. if (sizeof($this->references) > 0) {
  733. $ref = "\n\t<guide>\n";
  734. foreach ($this->references as $reference) {
  735. $ref .= $reference->finalize();
  736. }
  737. $ref .= "\t</guide>\n";
  738. }
  739. return $ref;
  740. }
  741. }
  742. /**
  743. * Reference constants
  744. */
  745. class Reference {
  746. const _VERSION = 1.00;
  747. /* REFERENCE types are derived from the "Chicago Manual of Style"
  748. */
  749. /** Acknowledgements page */
  750. const ACKNOWLEDGEMENTS = "acknowledgements";
  751. /** Bibliography page */
  752. const BIBLIOGRAPHY = "bibliography";
  753. /** Colophon page */
  754. const COLOPHON = "colophon";
  755. /** Copyright page */
  756. const COPYRIGHT_PAGE = "copyright-page";
  757. /** Dedication */
  758. const DEDICATION = "dedication";
  759. /** Epigraph */
  760. const EPIGRAPH = "epigraph";
  761. /** Foreword */
  762. const FOREWORD = "foreword";
  763. /** Glossary page */
  764. const GLOSSARY = "glossary";
  765. /** back-of-book style index */
  766. const INDEX = "index";
  767. /** List of illustrations */
  768. const LIST_OF_ILLUSTRATIONS = "loi";
  769. /** List of tables */
  770. const LIST_OF_TABLES = "lot";
  771. /** Notes page */
  772. const NOTES = "notes";
  773. /** Preface page */
  774. const PREFACE = "preface";
  775. /** Table of contents */
  776. const TABLE_OF_CONTENTS = "toc";
  777. /** Page with possibly title, author, publisher, and other metadata */
  778. const TITLE_PAGE = "titlepage";
  779. /** First page of the book, ie. first page of the first chapter */
  780. const TEXT = "text";
  781. // ******************
  782. // ePub3 constants
  783. // ******************
  784. // Document partitions
  785. /** The publications cover(s), jacket information, etc. This is officially in ePub3, but works for ePub 2 as well */
  786. const COVER = "cover";
  787. /** Preliminary material to the content body, such as tables of contents, dedications, etc. */
  788. const FRONTMATTER = "frontmatter";
  789. /** The main (body) content of a document. */
  790. const BODYMATTER = "bodymatter";
  791. /** Ancillary material occurring after the document body, such as indices, appendices, etc. */
  792. const BACKMATTER = "backmatter";
  793. private $type = NULL;
  794. private $title = NULL;
  795. private $href = NULL;
  796. /**
  797. * Class constructor.
  798. *
  799. * @param string $type
  800. * @param string $title
  801. * @param string $href
  802. */
  803. function __construct($type, $title, $href) {
  804. $this->setType($type);
  805. $this->setTitle($title);
  806. $this->setHref($href);
  807. }
  808. /**
  809. * Class destructor
  810. *
  811. * @return void
  812. */
  813. function __destruct() {
  814. unset ($this->type, $this->title, $this->href);
  815. }
  816. /**
  817. *
  818. * Enter description here ...
  819. *
  820. * @param string $type
  821. */
  822. function setType($type) {
  823. $this->type = is_string($type) ? trim($type) : NULL;
  824. }
  825. /**
  826. *
  827. * Enter description here ...
  828. *
  829. * @param string $title
  830. */
  831. function setTitle($title) {
  832. $this->title = is_string($title) ? trim($title) : NULL;
  833. }
  834. /**
  835. *
  836. * Enter description here ...
  837. *
  838. * @param string $href
  839. */
  840. function setHref($href) {
  841. $this->href = is_string($href) ? trim($href) : NULL;
  842. }
  843. /**
  844. *
  845. * Enter description here ...
  846. *
  847. * @return string
  848. */
  849. function finalize() {
  850. return "\t\t<reference type=\"" . $this->type . "\" title=\"" . $this->title . "\" href=\"" . $this->href . "\" />\n";
  851. }
  852. }
  853. /**
  854. * Common Marc codes.
  855. * Ref: http://www.loc.gov/marc/relators/
  856. */
  857. class MarcCode {
  858. const _VERSION = 3.00;
  859. /**
  860. * Adapter
  861. *
  862. * Use for a person who
  863. * 1) reworks a musical composition, usually for a different medium, or
  864. * 2) rewrites novels or stories for motion pictures or other audiovisual medium.
  865. */
  866. const ADAPTER = "adp";
  867. /**
  868. * Annotator
  869. *
  870. * Use for a person who writes manuscript annotations on a printed item.
  871. */
  872. const ANNOTATOR = "ann";
  873. /**
  874. * Arranger
  875. *
  876. * Use for a person who transcribes a musical composition, usually for a different
  877. * medium from that of the original; in an arrangement the musical substance remains
  878. * essentially unchanged.
  879. */
  880. const ARRANGER = "arr";
  881. /**
  882. * Artist
  883. *
  884. * Use for a person (e.g., a painter) who conceives, and perhaps also implements,
  885. * an original graphic design or work of art, if specific codes (e.g., [egr],
  886. * [etr]) are not desired. For book illustrators, prefer Illustrator [ill].
  887. */
  888. const ARTIST = "art";
  889. /**
  890. * Associated name
  891. *
  892. * Use as a general relator for a name associated with or found in an item or
  893. * collection, or which cannot be determined to be that of a Former owner [fmo]
  894. * or other designated relator indicative of provenance.
  895. */
  896. const ASSOCIATED_NAME = "asn";
  897. /**
  898. * Author
  899. *
  900. * Use for a person or corporate body chiefly responsible for the intellectual
  901. * or artistic content of a work. This term may also be used when more than one
  902. * person or body bears such responsibility.
  903. */
  904. const AUTHOR = "aut";
  905. /**
  906. * Author in quotations or text extracts
  907. *
  908. * Use for a person whose work is largely quoted or extracted in a works to which
  909. * he or she did not contribute directly. Such quotations are found particularly
  910. * in exhibition catalogs, collections of photographs, etc.
  911. */
  912. const AUTHOR_IN_QUOTES = "aqt";
  913. /**
  914. * Author of afterword, colophon, etc.
  915. *
  916. * Use for a person or corporate body responsible for an afterword, postface,
  917. * colophon, etc. but who is not the chief author of a work.
  918. */
  919. const AUTHOR_OF_AFTERWORD = "aft";
  920. /**
  921. * Author of introduction, etc.
  922. *
  923. * Use for a person or corporate body responsible for an introduction, preface,
  924. * foreword, or other critical matter, but who is not the chief author.
  925. */
  926. const AUTHOR_OF_INTRO = "aui";
  927. /**
  928. * Bibliographic antecedent
  929. *
  930. * Use for the author responsible for a work upon which the work represented by
  931. * the catalog record is based. This can be appropriate for adaptations, sequels,
  932. * continuations, indexes, etc.
  933. */
  934. const BIB_ANTECEDENT = "ant";
  935. /**
  936. * Book producer
  937. *
  938. * Use for the person or firm responsible for the production of books and other
  939. * print media, if specific codes (e.g., [bkd], [egr], [tyd], [prt]) are not desired.
  940. */
  941. const BOOK_PRODUCER = "bkp";
  942. /**
  943. * Collaborator
  944. *
  945. * Use for a person or corporate body that takes a limited part in the elaboration
  946. * of a work of another author or that brings complements (e.g., appendices, notes)
  947. * to the work of another author.
  948. */
  949. const COLABORATOR = "clb";
  950. /**
  951. * Commentator
  952. *
  953. * Use for a person who provides interpretation, analysis, or a discussion of the
  954. * subject matter on a recording, motion picture, or other audiovisual medium.
  955. * Compiler [com] Use for a person who produces a work or publication by selecting
  956. * and putting together material from the works of various persons or bodies.
  957. */
  958. const COMMENTATOR = "cmm";
  959. /**
  960. * Designer
  961. *
  962. * Use for a person or organization responsible for design if specific codes (e.g.,
  963. * [bkd], [tyd]) are not desired.
  964. */
  965. const DESIGNER = "dsr";
  966. /**
  967. * Editor
  968. *
  969. * Use for a person who prepares for publication a work not primarily his/her own,
  970. * such as by elucidating text, adding introductory or other critical matter, or
  971. * technically directing an editorial staff.
  972. */
  973. const EDITORT = "edt";
  974. /**
  975. * Illustrator
  976. *
  977. * Use for the person who conceives, and perhaps also implements, a design or
  978. * illustration, usually to accompany a written text.
  979. */
  980. const ILLUSTRATOR = "ill";
  981. /**
  982. * Lyricist
  983. *
  984. * Use for the writer of the text of a song.
  985. */
  986. const LYRICIST = "lyr";
  987. /**
  988. * Metadata contact
  989. *
  990. * Use for the person or organization primarily responsible for compiling and
  991. * maintaining the original description of a metadata set (e.g., geospatial
  992. * metadata set).
  993. */
  994. const METADATA_CONTACT = "mdc";
  995. /**
  996. * Musician
  997. *
  998. * Use for the person who performs music or contributes to the musical content
  999. * of a work when it is not possible or desirable to identify the function more
  1000. * precisely.
  1001. */
  1002. const MUSICIAN = "mus";
  1003. /**
  1004. * Narrator
  1005. *
  1006. * Use for the speaker who relates the particulars of an act, occurrence, or
  1007. * course of events.
  1008. */
  1009. const NARRATOR = "nrt";
  1010. /**
  1011. * Other
  1012. *
  1013. * Use for relator codes from other lists which have no equivalent in the MARC
  1014. * list or for terms which have not been assigned a code.
  1015. */
  1016. const OTHER = "oth";
  1017. /**
  1018. * Photographer
  1019. *
  1020. * Use for the person or organization responsible for taking photographs, whether
  1021. * they are used in their original form or as reproductions.
  1022. */
  1023. const PHOTOGRAPHER = "pht";
  1024. /**
  1025. * Printer
  1026. *
  1027. * Use for the person or organization who prints texts, whether from type or plates.
  1028. */
  1029. const PRINTER = "prt";
  1030. /**
  1031. * Redactor
  1032. *
  1033. * Use for a person who writes or develops the framework for an item without
  1034. * being intellectually responsible for its content.
  1035. */
  1036. const REDACTOR = "red";
  1037. /**
  1038. * Reviewer
  1039. *
  1040. * Use for a person or corporate body responsible for the review of book, motion
  1041. * picture, performance, etc.
  1042. */
  1043. const REVIEWER = "rev";
  1044. /**
  1045. * Sponsor
  1046. *
  1047. * Use for the person or agency that issued a contract, or under whose auspices
  1048. * a work has been written, printed, published, etc.
  1049. */
  1050. const SPONSOR = "spn";
  1051. /**
  1052. * Thesis advisor
  1053. *
  1054. * Use for the person under whose supervision a degree candidate develops and
  1055. * presents a thesis, memoir, or text of a dissertation.
  1056. */
  1057. const THESIS_ADVISOR = "ths";
  1058. /**
  1059. * Transcriber
  1060. *
  1061. * Use for a person who prepares a handwritten or typewritten copy from original
  1062. * material, including from dictated or orally recorded material.
  1063. */
  1064. const TRANSCRIBER = "trc";
  1065. /**
  1066. * Translator
  1067. *
  1068. * Use for a person who renders a text from one language into another, or from
  1069. * an older form of a language into the modern form.
  1070. */
  1071. const TRANSLATOR = "trl";
  1072. }
  1073. ?>