PHPePub\Core\EPub::finalizeTOC PHP Method

finalizeTOC() private method

Finalize and build final ePub structures.
private finalizeTOC ( ) : boolean
return boolean
    private function finalizeTOC()
    {
        if (!$this->buildTOC) {
            return false;
        }
        if (empty($this->tocTitle)) {
            $this->tocTitle = "Table of Contents";
        }
        $tocCssCls = "";
        if (!empty($this->tocCSSClass)) {
            $tocCssCls = $this->tocCSSClass . " ";
        }
        $tocData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
        if ($this->isEPubVersion2()) {
            $tocData .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n" . "    \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n" . "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n" . "\t<head>\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n";
        } else {
            $tocData .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" xmlns:epub=\"http://www.idpf.org/2007/ops\">\n" . "<head>\n<meta http-equiv=\"Default-Style\" content=\"text/html; charset=utf-8\" />\n";
        }
        $tocData .= $this->getViewportMetaLine();
        $tocData .= "<style type=\"text/css\">\n" . $tocCssCls . ".level1 {text-indent:  0em;}\n" . $tocCssCls . ".level2 {text-indent:  2em;}\n" . $tocCssCls . ".level3 {text-indent:  4em;}\n" . $tocCssCls . ".level4 {text-indent:  6em;}\n" . $tocCssCls . ".level5 {text-indent:  8em;}\n" . $tocCssCls . ".level6 {text-indent: 10em;}\n" . $tocCssCls . ".level7 {text-indent: 12em;}\n" . $tocCssCls . ".reference {}\n" . "</style>\n";
        if (!empty($this->tocCssFileName)) {
            $tocData .= "<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $this->tocCssFileName . "\" />\n";
        }
        $tocData .= "<title>" . $this->tocTitle . "</title>\n" . "</head>\n" . "<body>\n" . "<h3>" . $this->tocTitle . "</h3>\n<div";
        if (!empty($this->tocCSSClass)) {
            $tocData .= " class=\"" . $this->tocCSSClass . "\"";
        }
        $tocData .= ">\n";
        while (list($item, $descriptive) = each($this->referencesOrder)) {
            if ($item === "text") {
                while (list($chapterName, $navPoint) = each($this->ncx->chapterList)) {
                    /** @var $navPoint NavPoint */
                    $fileName = $navPoint->getContentSrc();
                    $level = $navPoint->getLevel() - 2;
                    $tocData .= "\t<p class='level" . ($level + 1) . "'>" . "<a href=\"" . $fileName . "\">" . $chapterName . "</a></p>\n";
                }
            } else {
                if ($this->tocAddReferences === true) {
                    if (array_key_exists($item, $this->ncx->referencesList)) {
                        $tocData .= "\t<p class='level1 reference'><a href=\"" . $this->ncx->referencesList[$item] . "\">" . $descriptive . "</a></p>\n";
                    } else {
                        if ($item === "toc") {
                            $tocData .= "\t<p class='level1 reference'><a href=\"TOC.xhtml\">" . $this->tocTitle . "</a></p>\n";
                        } else {
                            if ($item === "cover" && $this->isCoverImageSet) {
                                $tocData .= "\t<p class='level1 reference'><a href=\"CoverPage.xhtml\">" . $descriptive . "</a></p>\n";
                            }
                        }
                    }
                }
            }
        }
        $tocData .= "</div>\n</body>\n</html>\n";
        $this->addReferencePage($this->tocTitle, $this->tocFileName, $tocData, Reference::TABLE_OF_CONTENTS);
        return true;
    }