From abf64e40157dd27253a763203c15755cc9912c21 Mon Sep 17 00:00:00 2001 From: Rico Neitzel Date: Mon, 3 Sep 2012 21:56:25 +0200 Subject: [PATCH] header and footer in separate functions --- EPub.php | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/EPub.php b/EPub.php index d683d79..7ece149 100644 --- a/EPub.php +++ b/EPub.php @@ -76,6 +76,9 @@ class EPub { private $EPubMark = TRUE; private $generator = ""; + private $contentHeader = ""; + private $contentFooter = ""; + /** * Class constructor. * @@ -103,6 +106,20 @@ function __construct() { $this->chapterCount = 0; $this->isGdInstalled = extension_loaded('gd') && function_exists('gd_info'); + + // introduced variable {{BOOKTITLE}} for str_replace the BookTitle in all head sections + $this->contentHeader = "\n" + . "\n" + . "\n" + . "" + . "\n" + . "\n" + . "{{BOOKTITLE}}\n" + . "\n" + . "\n"; + + $this->contentFooter = "\n\n"; } /** @@ -207,7 +224,8 @@ function addChapter($chapterName, $fileName, $chapterData, $autoSplit = FALSE, $ $htmlDir = pathinfo($fileName); $htmlDir = preg_replace('#^[/\.]+#i', "", $htmlDir["dirname"] . "/"); - $chapter = $chapterData; + // Add Header and Footer to Chapter HTML Data + $chapter = $this->wrapChapter($chapterData); if ($autoSplit && is_string($chapterData) && mb_strlen($chapterData) > $this->splitDefaultSize) { $splitter = new EPubChapterSplitter(); @@ -254,6 +272,16 @@ function addChapter($chapterName, $fileName, $chapterData, $autoSplit = FALSE, $ return TRUE; } + /** + * Wrap ChapterContent with Head and Footer + * + * @param $content + * @return string $content + */ + private function wrapChapter($content) { + return $this->contentHeader . "\n" . $content . "\n" . $this->contentFooter; + } + /** * Process external references from a HTML to the book. The chapter itself is not stored. * the HTML is scanned for ,