PageRenderTime 56ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/epub/PHPePub/EPub.NCX.php

https://github.com/ldleman/Leed-market
PHP | 782 lines | 412 code | 85 blank | 285 comment | 67 complexity | 5d0f3ddee2b54109b4f91f63fe5211a8 MD5 | raw file
  1. <?php
  2. /**
  3. * ePub NCX 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 Ncx {
  11. const _VERSION = 3.20;
  12. const MIMETYPE = "application/x-dtbncx+xml";
  13. private $bookVersion = EPub::BOOK_VERSION_EPUB2;
  14. private $navMap = NULL;
  15. private $uid = NULL;
  16. private $meta = array();
  17. private $docTitle = NULL;
  18. private $docAuthor = NULL;
  19. private $currentLevel = NULL;
  20. private $lastLevel = NULL;
  21. private $languageCode = "en";
  22. private $writingDirection = EPub::DIRECTION_LEFT_TO_RIGHT;
  23. public $chapterList = array();
  24. public $referencesTitle = "Guide";
  25. public $referencesClass = "references";
  26. public $referencesId = "references";
  27. public $referencesList = array();
  28. public $referencesName = array();
  29. public $referencesOrder = NULL;
  30. /**
  31. * Class constructor.
  32. *
  33. * @param string $uid
  34. * @param string $docTitle
  35. * @param string $docAuthor
  36. * @param string $languageCode
  37. * @param string $writingDirection
  38. */
  39. function __construct($uid = NULL, $docTitle = NULL, $docAuthor = NULL, $languageCode = "en", $writingDirection = EPub::DIRECTION_LEFT_TO_RIGHT) {
  40. $this->navMap = new NavMap($writingDirection);
  41. $this->currentLevel = $this->navMap;
  42. $this->setUid($uid);
  43. $this->setDocTitle($docTitle);
  44. $this->setDocAuthor($docAuthor);
  45. $this->setLanguageCode($languageCode);
  46. $this->setWritingDirection($writingDirection);
  47. }
  48. /**
  49. * Class destructor
  50. *
  51. * @return void
  52. */
  53. function __destruct() {
  54. unset($this->bookVersion, $this->navMap, $this->uid, $this->meta);
  55. unset($this->docTitle, $this->docAuthor, $this->currentLevel, $this->lastLevel);
  56. unset($this->languageCode, $this->writingDirection, $this->chapterList, $this->referencesTitle);
  57. unset($this->referencesClass, $this->referencesId, $this->referencesList, $this->referencesName);
  58. unset($this->referencesOrder);
  59. }
  60. /**
  61. *
  62. * Enter description here ...
  63. *
  64. * @param string $bookVersion
  65. */
  66. function setVersion($bookVersion) {
  67. $this->bookVersion = is_string($bookVersion) ? trim($bookVersion) : EPub::BOOK_VERSION_EPUB2;
  68. }
  69. /**
  70. *
  71. * @return bool TRUE if the book is set to type ePub 2
  72. */
  73. function isEPubVersion2() {
  74. return $this->bookVersion === EPub::BOOK_VERSION_EPUB2;
  75. }
  76. /**
  77. *
  78. * Enter description here ...
  79. *
  80. * @param string $uid
  81. */
  82. function setUid($uid) {
  83. $this->uid = is_string($uid) ? trim($uid) : NULL;
  84. }
  85. /**
  86. *
  87. * Enter description here ...
  88. *
  89. * @param string $docTitle
  90. */
  91. function setDocTitle($docTitle) {
  92. $this->docTitle = is_string($docTitle) ? trim($docTitle) : NULL;
  93. }
  94. /**
  95. *
  96. * Enter description here ...
  97. *
  98. * @param string $docAuthor
  99. */
  100. function setDocAuthor($docAuthor) {
  101. $this->docAuthor = is_string($docAuthor) ? trim($docAuthor) : NULL;
  102. }
  103. /**
  104. *
  105. * Enter description here ...
  106. *
  107. * @param string $languageCode
  108. */
  109. function setLanguageCode($languageCode) {
  110. $this->languageCode = is_string($languageCode) ? trim($languageCode) : "en";
  111. }
  112. /**
  113. *
  114. * Enter description here ...
  115. *
  116. * @param string $writingDirection
  117. */
  118. function setWritingDirection($writingDirection) {
  119. $this->writingDirection = is_string($writingDirection) ? trim($writingDirection) : EPub::DIRECTION_LEFT_TO_RIGHT;
  120. }
  121. /**
  122. *
  123. * Enter description here ...
  124. *
  125. * @param NavMap $navMap
  126. */
  127. function setNavMap($navMap) {
  128. if ($navMap != NULL && is_object($navMap) && get_class($navMap) === "NavMap") {
  129. $this->navMap = $navMap;
  130. }
  131. }
  132. /**
  133. * Add one chapter level.
  134. *
  135. * Subsequent chapters will be added to this level.
  136. *
  137. * @param string $navTitle
  138. * @param string $navId
  139. * @param string $navClass
  140. * @param string $isNavHidden
  141. * @param string $writingDirection
  142. * @return NavPoint
  143. */
  144. function subLevel($navTitle = NULL, $navId = NULL, $navClass = NULL, $isNavHidden = FALSE, $writingDirection = NULL) {
  145. $navPoint = FALSE;
  146. if (isset($navTitle) && isset($navClass)) {
  147. $navPoint = new NavPoint($navTitle, NULL, $navId, $navClass, $isNavHidden, $writingDirection);
  148. $this->addNavPoint($navPoint);
  149. }
  150. if ($this->lastLevel !== NULL) {
  151. $this->currentLevel = $this->lastLevel;
  152. }
  153. return $navPoint;
  154. }
  155. /**
  156. * Step back one chapter level.
  157. *
  158. * Subsequent chapters will be added to this chapters parent level.
  159. */
  160. function backLevel() {
  161. $this->lastLevel = $this->currentLevel;
  162. $this->currentLevel = $this->currentLevel->getParent();
  163. }
  164. /**
  165. * Step back to the root level.
  166. *
  167. * Subsequent chapters will be added to the rooot NavMap.
  168. */
  169. function rootLevel() {
  170. $this->lastLevel = $this->currentLevel;
  171. $this->currentLevel = $this->navMap;
  172. }
  173. /**
  174. * Step back to the given level.
  175. * Useful for returning to a previous level from deep within the structure.
  176. * Values below 2 will have the same effect as rootLevel()
  177. *
  178. * @param int $newLevel
  179. */
  180. function setCurrentLevel($newLevel) {
  181. if ($newLevel <= 1) {
  182. $this->rootLevel();
  183. } else {
  184. while ($this->currentLevel->getLevel() > $newLevel) {
  185. $this->backLevel();
  186. }
  187. }
  188. }
  189. /**
  190. * Get current level count.
  191. * The indentation of the current structure point.
  192. *
  193. * @return current level count;
  194. */
  195. function getCurrentLevel() {
  196. return $this->currentLevel->getLevel();
  197. }
  198. /**
  199. * Add child NavPoints to current level.
  200. *
  201. * @param NavPoint $navPoint
  202. */
  203. function addNavPoint($navPoint) {
  204. $this->lastLevel = $this->currentLevel->addNavPoint($navPoint);
  205. }
  206. /**
  207. *
  208. * Enter description here ...
  209. *
  210. * @return NavMap
  211. */
  212. function getNavMap() {
  213. return $this->navMap;
  214. }
  215. /**
  216. *
  217. * Enter description here ...
  218. *
  219. * @param string $name
  220. * @param string $content
  221. */
  222. function addMetaEntry($name, $content) {
  223. $name = is_string($name) ? trim($name) : NULL;
  224. $content = is_string($content) ? trim($content) : NULL;
  225. if ($name != NULL && $content != NULL) {
  226. $this->meta[] = array($name => $content);
  227. }
  228. }
  229. /**
  230. *
  231. * Enter description here ...
  232. *
  233. * @return string
  234. */
  235. function finalize() {
  236. $nav = $this->navMap->finalize();
  237. $ncx = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  238. if ($this->isEPubVersion2()) {
  239. $ncx .= "<!DOCTYPE ncx PUBLIC \"-//NISO//DTD ncx 2005-1//EN\"\n"
  240. . " \"http://www.daisy.org/z3986/2005/ncx-2005-1.dtd\">\n";
  241. }
  242. $ncx .= "<ncx xmlns=\"http://www.daisy.org/z3986/2005/ncx/\" version=\"2005-1\" xml:lang=\"" . $this->languageCode . "\" dir=\"" . $this->writingDirection . "\">\n"
  243. . "\t<head>\n"
  244. . "\t\t<meta name=\"dtb:uid\" content=\"" . $this->uid . "\" />\n"
  245. . "\t\t<meta name=\"dtb:depth\" content=\"" . $this->navMap->getNavLevels() . "\" />\n"
  246. . "\t\t<meta name=\"dtb:totalPageCount\" content=\"0\" />\n"
  247. . "\t\t<meta name=\"dtb:maxPageNumber\" content=\"0\" />\n";
  248. if (sizeof($this->meta)) {
  249. foreach ($this->meta as $metaEntry) {
  250. list($name, $content) = each($metaEntry);
  251. $ncx .= "\t\t<meta name=\"" . $name . "\" content=\"" . $content . "\" />\n";
  252. }
  253. }
  254. $ncx .= "\t</head>\n\n\t<docTitle>\n\t\t<text>"
  255. . $this->docTitle
  256. . "</text>\n\t</docTitle>\n\n\t<docAuthor>\n\t\t<text>"
  257. . $this->docAuthor
  258. . "</text>\n\t</docAuthor>\n\n"
  259. . $nav;
  260. return $ncx . "</ncx>\n";
  261. }
  262. /**
  263. *
  264. * @param string $title
  265. * @param string $cssFileName
  266. * @return string
  267. */
  268. function finalizeEPub3($title = "Table of Contents", $cssFileName = NULL) {
  269. $end = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  270. . "<html xmlns=\"http://www.w3.org/1999/xhtml\"\n"
  271. . " xmlns:epub=\"http://www.idpf.org/2007/ops\"\n"
  272. . " xml:lang=\"" . $this->languageCode . "\" lang=\"" . $this->languageCode . "\" dir=\"" . $this->writingDirection . "\">\n"
  273. . "\t<head>\n"
  274. . "\t\t<title>" . $this->docTitle . "</title>\n"
  275. . "\t\t<meta http-equiv=\"default-style\" content=\"text/html; charset=utf-8\"/>\n";
  276. if ($cssFileName !== NULL) {
  277. $end .= "\t\t<link rel=\"stylesheet\" href=\"" . $cssFileName . "\" type=\"text/css\"/>\n";
  278. }
  279. $end .= "\t</head>\n"
  280. . "\t<body epub:type=\"frontmatter toc\">\n"
  281. . "\t\t<header>\n"
  282. . "\t\t\t<h1>" . $title . "</h1>\n"
  283. . "\t\t</header>\n"
  284. . $this->navMap->finalizeEPub3()
  285. . $this->finalizeEPub3Landmarks()
  286. . "\t</body>\n"
  287. . "</html>\n";
  288. return $end;
  289. }
  290. /**
  291. * Build the references for the ePub 2 toc.
  292. * These are merely reference pages added to the end of the navMap though.
  293. *
  294. * @return string
  295. */
  296. function finalizeReferences() {
  297. if (isset($this->referencesList) && sizeof($this->referencesList) > 0) {
  298. $this->rootLevel();
  299. $this->subLevel($this->referencesTitle, $this->referencesId, $this->referencesClass);
  300. $refId = 1;
  301. while (list($item, $descriptive) = each($this->referencesOrder)) {
  302. if (array_key_exists($item, $this->referencesList)) {
  303. $name = (empty($this->referencesName[$item]) ? $descriptive : $this->referencesName[$item]);
  304. $navPoint = new NavPoint($name, $this->referencesList[$item], "ref-" . $refId++);
  305. $this->addNavPoint($navPoint);
  306. }
  307. }
  308. }
  309. }
  310. /**
  311. * Build the landmarks for the ePub 3 toc.
  312. * @return string
  313. */
  314. function finalizeEPub3Landmarks() {
  315. $lm = "";
  316. if (isset($this->referencesList) && sizeof($this->referencesList) > 0) {
  317. $lm = "\t\t\t<nav epub:type=\"landmarks\">\n"
  318. . "\t\t\t\t<h2"
  319. . ($this->writingDirection === EPub::DIRECTION_RIGHT_TO_LEFT ? " dir=\"rtl\"" : "")
  320. . ">" . $this->referencesTitle . "</h2>\n"
  321. . "\t\t\t\t<ol>\n";
  322. $li = "";
  323. while (list($item, $descriptive) = each($this->referencesOrder)) {
  324. if (array_key_exists($item, $this->referencesList)) {
  325. $li .= "\t\t\t\t\t<li><a epub:type=\""
  326. . $item
  327. . "\" href=\"" . $this->referencesList[$item] . "\">"
  328. . (empty($this->referencesName[$item]) ? $descriptive : $this->referencesName[$item])
  329. . "</a></li>\n";
  330. }
  331. }
  332. if (empty($li)) {
  333. return "";
  334. }
  335. $lm .= $li
  336. . "\t\t\t\t</ol>\n"
  337. . "\t\t\t</nav>\n";
  338. }
  339. return $lm;
  340. }
  341. }
  342. /**
  343. * ePub NavMap class
  344. */
  345. class NavMap {
  346. const _VERSION = 3.00;
  347. private $navPoints = array();
  348. private $navLevels = 0;
  349. private $writingDirection = NULL;
  350. /**
  351. * Class constructor.
  352. *
  353. * @return void
  354. */
  355. function __construct($writingDirection = NULL) {
  356. $this->setWritingDirection($writingDirection);
  357. }
  358. /**
  359. * Class destructor
  360. *
  361. * @return void
  362. */
  363. function __destruct() {
  364. unset($this->navPoints, $this->navLevels, $this->writingDirection);
  365. }
  366. /**
  367. * Set the writing direction to be used for this NavPoint.
  368. *
  369. * @param string $writingDirection
  370. */
  371. function setWritingDirection($writingDirection) {
  372. $this->writingDirection = isset($writingDirection) && is_string($writingDirection) ? trim($writingDirection) : NULL;
  373. }
  374. function getWritingDirection() {
  375. return $this->writingDirection;
  376. }
  377. /**
  378. * Add a navPoint to the root of the NavMap.
  379. *
  380. * @param NavPoint $navPoint
  381. * @return NavMap
  382. */
  383. function addNavPoint($navPoint) {
  384. if ($navPoint != NULL && is_object($navPoint) && get_class($navPoint) === "NavPoint") {
  385. $navPoint->setParent($this);
  386. if ($navPoint->getWritingDirection() == NULL) {
  387. $navPoint->setWritingDirection($this->writingDirection);
  388. }
  389. $this->navPoints[] = $navPoint;
  390. return $navPoint;
  391. }
  392. return $this;
  393. }
  394. /**
  395. * The final max depth for the "dtb:depth" meta attribute
  396. * Only available after finalize have been called.
  397. *
  398. * @return number
  399. */
  400. function getNavLevels() {
  401. return $this->navLevels+1;
  402. }
  403. function getLevel() {
  404. return 1;
  405. }
  406. function getParent() {
  407. return $this;
  408. }
  409. /**
  410. * Finalize the navMap, the final max depth for the "dtb:depth" meta attribute can be retrieved with getNavLevels after finalization
  411. *
  412. */
  413. function finalize() {
  414. $playOrder = 0;
  415. $this->navLevels = 0;
  416. $nav = "\t<navMap>\n";
  417. if (sizeof($this->navPoints) > 0) {
  418. $this->navLevels++;
  419. foreach ($this->navPoints as $navPoint) {
  420. $retLevel = $navPoint->finalize($nav, $playOrder, 0);
  421. if ($retLevel > $this->navLevels) {
  422. $this->navLevels = $retLevel;
  423. }
  424. }
  425. }
  426. return $nav . "\t</navMap>\n";
  427. }
  428. /**
  429. * Finalize the navMap, the final max depth for the "dtb:depth" meta attribute can be retrieved with getNavLevels after finalization
  430. *
  431. */
  432. function finalizeEPub3() {
  433. $playOrder = 0;
  434. $level = 0;
  435. $this->navLevels = 0;
  436. $nav = "\t\t<nav epub:type=\"toc\" id=\"toc\">\n";
  437. if (sizeof($this->navPoints) > 0) {
  438. $this->navLevels++;
  439. $nav .= str_repeat("\t", $level) . "\t\t\t<ol epub:type=\"list\">\n";
  440. foreach ($this->navPoints as $navPoint) {
  441. $retLevel = $navPoint->finalizeEPub3($nav, $playOrder, 0);
  442. if ($retLevel > $this->navLevels) {
  443. $this->navLevels = $retLevel;
  444. }
  445. }
  446. $nav .= str_repeat("\t", $level) . "\t\t\t</ol>\n";
  447. }
  448. return $nav . "\t\t</nav>\n";
  449. }
  450. }
  451. /**
  452. * ePub NavPoint class
  453. */
  454. class NavPoint {
  455. const _VERSION = 3.00;
  456. private $label = NULL;
  457. private $contentSrc = NULL;
  458. private $id = NULL;
  459. private $navClass = NULL;
  460. private $isNavHidden = FALSE;
  461. private $navPoints = array();
  462. private $parent = NULL;
  463. /**
  464. * Class constructor.
  465. *
  466. * All three attributes are mandatory, though if ID is set to null (default) the value will be generated.
  467. *
  468. * @param string $label
  469. * @param string $contentSrc
  470. * @param string $id
  471. * @param string $navClass
  472. * @param bool $isNavHidden
  473. * @param string $writingDirection
  474. */
  475. function __construct($label, $contentSrc = NULL, $id = NULL, $navClass = NULL, $isNavHidden = FALSE, $writingDirection = NULL) {
  476. $this->setLabel($label);
  477. $this->setContentSrc($contentSrc);
  478. $this->setId($id);
  479. $this->setNavClass($navClass);
  480. $this->setNavHidden($isNavHidden);
  481. $this->setWritingDirection($writingDirection);
  482. }
  483. /**
  484. * Class destructor
  485. *
  486. * @return void
  487. */
  488. function __destruct() {
  489. unset($this->label, $this->contentSrc, $this->id, $this->navClass);
  490. unset($this->isNavHidden, $this->navPoints, $this->parent);
  491. }
  492. /**
  493. * Set the Text label for the NavPoint.
  494. *
  495. * The label is mandatory.
  496. *
  497. * @param string $label
  498. */
  499. function setLabel($label) {
  500. $this->label = is_string($label) ? trim($label) : NULL;
  501. }
  502. /**
  503. * Get the Text label for the NavPoint.
  504. *
  505. * @return string Label
  506. */
  507. function getLabel() {
  508. return $this->label;
  509. }
  510. /**
  511. * Set the src reference for the NavPoint.
  512. *
  513. * The src is mandatory for ePub 2.
  514. *
  515. * @param string $contentSrc
  516. */
  517. function setContentSrc($contentSrc) {
  518. $this->contentSrc = isset($contentSrc) && is_string($contentSrc) ? trim($contentSrc) : NULL;
  519. }
  520. /**
  521. * Get the src reference for the NavPoint.
  522. *
  523. * @return string content src url.
  524. */
  525. function getContentSrc() {
  526. return $this->contentSrc;
  527. }
  528. /**
  529. * Set the parent for this NavPoint.
  530. *
  531. * @param NavPoint or NavMap $parent
  532. */
  533. function setParent($parent) {
  534. if ($parent != NULL && is_object($parent) &&
  535. (get_class($parent) === "NavPoint" || get_class($parent) === "NavMap") ) {
  536. $this->parent = $parent;
  537. }
  538. }
  539. /**
  540. * Get the parent to this NavPoint.
  541. *
  542. * @return NavPoint, or NavMap if the parent is the root.
  543. */
  544. function getParent() {
  545. return $this->parent;
  546. }
  547. /**
  548. * Get the current level. 1 = document root.
  549. *
  550. * @return int level
  551. */
  552. function getLevel() {
  553. return $this->parent === NULL ? 1 : $this->parent->getLevel()+1;
  554. }
  555. /**
  556. * Set the id for the NavPoint.
  557. *
  558. * The id must be unique, and is mandatory.
  559. *
  560. * @param string $id
  561. */
  562. function setId($id) {
  563. $this->id = is_string($id) ? trim($id) : NULL;
  564. }
  565. /**
  566. * Set the class to be used for this NavPoint.
  567. *
  568. * @param string $navClass
  569. */
  570. function setNavClass($navClass) {
  571. $this->navClass = isset($navClass) && is_string($navClass) ? trim($navClass) : NULL;
  572. }
  573. /**
  574. * Set the class to be used for this NavPoint.
  575. *
  576. * @param string $navClass
  577. */
  578. function setNavHidden($isNavHidden) {
  579. $this->isNavHidden = $isNavHidden === TRUE;
  580. }
  581. /**
  582. * Set the writing direction to be used for this NavPoint.
  583. *
  584. * @param string $writingDirection
  585. */
  586. function setWritingDirection($writingDirection) {
  587. $this->writingDirection = isset($writingDirection) && is_string($writingDirection) ? trim($writingDirection) : NULL;
  588. }
  589. function getWritingDirection() {
  590. return $this->writingDirection;
  591. }
  592. /**
  593. * Add child NavPoints for multi level NavMaps.
  594. *
  595. * @param NavPoint $navPoint
  596. */
  597. function addNavPoint($navPoint) {
  598. if ($navPoint != NULL && is_object($navPoint) && get_class($navPoint) === "NavPoint") {
  599. $navPoint->setParent($this);
  600. if ($navPoint->getWritingDirection() == NULL) {
  601. $navPoint->setWritingDirection($this->writingDirection);
  602. }
  603. $this->navPoints[] = $navPoint;
  604. return $navPoint;
  605. }
  606. return $this;
  607. }
  608. /**
  609. *
  610. * Enter description here ...
  611. *
  612. * @param string $nav
  613. * @param int $playOrder
  614. * @param int $level
  615. * @return int
  616. */
  617. function finalize(&$nav = "", &$playOrder = 0, $level = 0) {
  618. $maxLevel = $level;
  619. $levelAdjust = 0;
  620. if ($this->isNavHidden) {
  621. return $maxLevel;
  622. }
  623. if (isset($this->contentSrc)) {
  624. $playOrder++;
  625. if ($this->id == NULL) {
  626. $this->id = "navpoint-" . $playOrder;
  627. }
  628. $nav .= str_repeat("\t", $level) . "\t\t<navPoint id=\"" . $this->id . "\" playOrder=\"" . $playOrder . "\">\n"
  629. . str_repeat("\t", $level) . "\t\t\t<navLabel>\n"
  630. . str_repeat("\t", $level) . "\t\t\t\t<text>" . $this->label . "</text>\n"
  631. . str_repeat("\t", $level) . "\t\t\t</navLabel>\n"
  632. . str_repeat("\t", $level) . "\t\t\t<content src=\"" . $this->contentSrc . "\" />\n";
  633. } else {
  634. $levelAdjust++;
  635. }
  636. if (sizeof($this->navPoints) > 0) {
  637. $maxLevel++;
  638. foreach ($this->navPoints as $navPoint) {
  639. $retLevel = $navPoint->finalize($nav, $playOrder, ($level+1+$levelAdjust));
  640. if ($retLevel > $maxLevel) {
  641. $maxLevel = $retLevel;
  642. }
  643. }
  644. }
  645. if (isset($this->contentSrc)) {
  646. $nav .= str_repeat("\t", $level) . "\t\t</navPoint>\n";
  647. }
  648. return $maxLevel;
  649. }
  650. /**
  651. *
  652. * Enter description here ...
  653. *
  654. * @param string $nav
  655. * @param int $playOrder
  656. * @param int $level
  657. * @return int
  658. */
  659. function finalizeEPub3(&$nav = "", &$playOrder = 0, $level = 0, $subLevelClass = NULL, $subLevelHidden = FALSE) {
  660. $maxLevel = $level;
  661. if ($this->id == NULL) {
  662. $this->id = "navpoint-" . $playOrder;
  663. }
  664. $indent = str_repeat("\t", $level) . "\t\t\t\t";
  665. $nav .= $indent . "<li id=\"" . $this->id . "\"";
  666. if (isset($this->writingDirection)) {
  667. $nav .= " dir=\"" . $this->writingDirection . "\"";
  668. }
  669. $nav .= ">\n";
  670. if (isset($this->contentSrc)) {
  671. $nav .= $indent . "\t<a href=\"" . $this->contentSrc . "\">" . $this->label . "</a>\n";
  672. } else {
  673. $nav .= $indent . "\t<span>" . $this->label . "</span>\n";
  674. }
  675. if (sizeof($this->navPoints) > 0) {
  676. $maxLevel++;
  677. $nav .= $indent . "\t<ol epub:type=\"list\"";
  678. if (isset($subLevelClass)) {
  679. $nav .= " class=\"" . $subLevelClass . "\"";
  680. }
  681. if ($subLevelHidden) {
  682. $nav .= " hidden=\"hidden\"";
  683. }
  684. $nav .= ">\n";
  685. foreach ($this->navPoints as $navPoint) {
  686. $retLevel = $navPoint->finalizeEPub3($nav, $playOrder, ($level+2), $subLevelClass, $subLevelHidden);
  687. if ($retLevel > $maxLevel) {
  688. $maxLevel = $retLevel;
  689. }
  690. }
  691. $nav .= $indent . "\t</ol>\n";
  692. }
  693. $nav .= $indent . "</li>\n";
  694. return $maxLevel;
  695. }
  696. }
  697. ?>