diff --git a/composer.json b/composer.json index 6b41404..d6986f4 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "keywords": ["epub", "e-book"], "homepage": "https://github.com/Grandt/PHPZip", "license": "LGPL-2.1", - "version": "4.0.5", + "version": "4.0.6", "minimum-stability": "stable", "authors": [ { diff --git a/legacy/EPub.Test.Example.php b/legacy/EPub.Test.Example.php index 9fb3e65..e873350 100644 --- a/legacy/EPub.Test.Example.php +++ b/legacy/EPub.Test.Example.php @@ -3,8 +3,9 @@ use PHPePub\Core\EPub; use PHPePub\Core\EPubChapterSplitter; -use PHPePub\Core\Structure\OPF\DublinCore; use PHPePub\Core\Logger; +use PHPePub\Core\Structure\OPF\DublinCore; +use PHPePub\Helpers\URLHelper; use PHPZip\Zip\File\Zip; error_reporting(E_ALL | E_STRICT); @@ -40,8 +41,8 @@ $log->logLine("new EPub()"); $log->logLine("EPub class version.: " . EPub::VERSION); $log->logLine("Zip version........: " . Zip::VERSION); -$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL()); -$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL()); +$log->logLine("getCurrentServerURL: " . URLHelper::getCurrentServerURL()); +$log->logLine("getCurrentPageURL..: " . URLHelper::getCurrentPageURL()); // Title and Identifier are mandatory! $book->setTitle("Test book"); diff --git a/src/PHPePub/Core/EPub.php b/src/PHPePub/Core/EPub.php index 6cb85f3..dcb1e1c 100644 --- a/src/PHPePub/Core/EPub.php +++ b/src/PHPePub/Core/EPub.php @@ -3,8 +3,6 @@ use com\grandt\BinStringStatic; use DOMDocument; -use DOMNode; -use grandt\ResizeGif\ResizeGif; use PHPePub\Core\Structure\Ncx; use PHPePub\Core\Structure\NCX\NavPoint; use PHPePub\Core\Structure\Opf; @@ -12,9 +10,12 @@ use PHPePub\Core\Structure\OPF\MarcCode; use PHPePub\Core\Structure\OPF\MetaValue; use PHPePub\Core\Structure\OPF\Reference; +use PHPePub\Helpers\FileHelper; +use PHPePub\Helpers\ImageHelper; +use PHPePub\Helpers\StringHelper; +use PHPePub\Helpers\URLHelper; use PHPZip\Zip\File\Zip; use RelativePath; -use SimpleXMLElement; /** @@ -29,12 +30,11 @@ * @author A. Grandt * @copyright 2009- A. Grandt * @license GNU LGPL 2.1 - * @version 4.0.4 * @link http://www.phpclasses.org/package/6115 * @link https://github.com/Grandt/PHPePub */ class EPub { - const VERSION = '4.0.4'; + const VERSION = '4.0.6'; const IDENTIFIER_UUID = 'UUID'; const IDENTIFIER_URI = 'URI'; @@ -54,28 +54,28 @@ class EPub { const BOOK_VERSION_EPUB2 = '2.0'; const BOOK_VERSION_EPUB3 = '3.0'; - public $maxImageWidth = 768; - public $maxImageHeight = 1024; + public $splitDefaultSize = 250000; /** Gifs can crash some early ADE based readers, and are disabled by default. * getImage will convert these if it can, unless this is set to TRUE. */ + + public $maxImageWidth = 768; + public $maxImageHeight = 1024; public $isGifImagesEnabled = false; + public $isReferencesAddedToToc = true; /** * Used for building the TOC. * If this list is overwritten it MUST contain at least "text" as an element. */ public $referencesOrder = null; + public $pluginDir = 'extLib'; + public $isLogging = true; public $encodeHTML = false; - protected $isCurlInstalled; - protected $isGdInstalled; - protected $isExifInstalled; - protected $isFileGetContentsInstalled; - protected $isFileGetContentsExtInstalled; - protected $isAnimatedGifResizeInstalled = false; + private $bookVersion = EPub::BOOK_VERSION_EPUB2; /** @var $Zip Zip */ private $zip; @@ -122,6 +122,9 @@ class EPub { private $htmlContentHeader = "\n\n\n\n\n\n\n"; private $htmlContentFooter = "\n\n"; + /** @var array $viewport */ + private $viewport = null; + private $dangermode = false; /** @@ -169,12 +172,6 @@ private function setUp() { $this->docRoot = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT') . '/'; - $this->isCurlInstalled = extension_loaded('curl') && function_exists('curl_version'); - $this->isGdInstalled = (extension_loaded('gd') || extension_loaded('gd2')) && function_exists('gd_info'); - $this->isExifInstalled = extension_loaded('exif') && function_exists('exif_imagetype'); - $this->isFileGetContentsInstalled = function_exists('file_get_contents'); - $this->isFileGetContentsExtInstalled = $this->isFileGetContentsInstalled && ini_get('allow_url_fopen'); - $this->zip = new Zip(); $this->zip->setExtraField(false); $this->zip->addFile('application/epub+zip', 'mimetype'); @@ -183,6 +180,8 @@ private function setUp() { $this->ncx = new Ncx(null, null, null, $this->languageCode, $this->writingDirection); $this->opf = new Opf(); + + $this->ncx->setBook($this); } /** @@ -200,12 +199,10 @@ function __destruct() { unset($this->sourceURL, $this->chapterCount, $this->opf, $this->ncx, $this->isFinalized); unset($this->isCoverImageSet, $this->fileList, $this->writingDirection, $this->languageCode); unset($this->referencesOrder, $this->dateformat, $this->dateformatShort, $this->headerDateFormat); - unset($this->isCurlInstalled, $this->isGdInstalled, $this->isExifInstalled); - unset($this->isFileGetContentsInstalled, $this->isFileGetContentsExtInstalled, $this->bookRoot); - unset($this->docRoot, $this->EPubMark, $this->generator, $this->log, $this->isLogging); + unset($this->bookRoot, $this->docRoot, $this->EPubMark, $this->generator, $this->log, $this->isLogging); unset($this->encodeHTML, $this->htmlContentHeader, $this->htmlContentFooter); unset($this->buildTOC, $this->tocTitle, $this->tocCSSClass, $this->tocAddReferences); - unset($this->tocFileName, $this->tocCssFileName); + unset($this->tocFileName, $this->tocCssFileName, $this->viewport); } /** @@ -247,14 +244,14 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f } if ($this->encodeHTML === true) { - $chapter = $this->encodeHtml($chapter); + $chapter = StringHelper::encodeHtml($chapter); } $this->chapterCount++; $this->addFile($fileName, "chapter" . $this->chapterCount, $chapter, "application/xhtml+xml"); $this->opf->addItemRef("chapter" . $this->chapterCount); - $navPoint = new NavPoint($this->decodeHtmlEntities($chapterName), $fileName, "chapter" . $this->chapterCount); + $navPoint = new NavPoint(StringHelper::decodeHtmlEntities($chapterName), $fileName, "chapter" . $this->chapterCount); $this->ncx->addNavPoint($navPoint); $this->ncx->chapterList[$chapterName] = $navPoint; } elseif (is_array($chapter)) { @@ -270,7 +267,7 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f /** @noinspection PhpUnusedLocalVariableInspection */ list($k, $v) = $oneChapter; if ($this->encodeHTML === true) { - $v = $this->encodeHtml($v); + $v = StringHelper::encodeHtml($v); } if ($externalReferences !== EPub::EXTERNAL_REF_IGNORE) { @@ -284,7 +281,7 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f $oneChapter = each($chapter); } $partName = $name . "_1." . $extension; - $navPoint = new NavPoint($this->decodeHtmlEntities($chapterName), $partName, $partName); + $navPoint = new NavPoint(StringHelper::decodeHtmlEntities($chapterName), $partName, $partName); $this->ncx->addNavPoint($navPoint); $this->ncx->chapterList[$chapterName] = $navPoint; @@ -292,14 +289,14 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f $this->chapterCount++; //$this->opf->addItemRef("chapter" . $this->chapterCount); - $navPoint = new NavPoint($this->decodeHtmlEntities($chapterName), $fileName, "chapter" . $this->chapterCount); + $navPoint = new NavPoint(StringHelper::decodeHtmlEntities($chapterName), $fileName, "chapter" . $this->chapterCount); $this->ncx->addNavPoint($navPoint); $this->ncx->chapterList[$chapterName] = $navPoint; } elseif (!isset($chapterData) && $fileName == "TOC.xhtml") { $this->chapterCount++; $this->opf->addItemRef("toc"); - $navPoint = new NavPoint($this->decodeHtmlEntities($chapterName), $fileName, "chapter" . $this->chapterCount); + $navPoint = new NavPoint(StringHelper::decodeHtmlEntities($chapterName), $fileName, "chapter" . $this->chapterCount); $this->ncx->addNavPoint($navPoint); $this->ncx->chapterList[$chapterName] = $navPoint; $this->tocNavAdded = true; @@ -342,7 +339,7 @@ protected function processChapterExternalReferences(&$doc, $externalReferences = $xmlDoc = null; if ($isDocAString) { - $doc = self::removeComments($doc); + $doc = StringHelper::removeComments($doc); $xmlDoc = new DOMDocument(); @$xmlDoc->loadHTML($doc); @@ -398,46 +395,6 @@ protected function processChapterExternalReferences(&$doc, $externalReferences = return true; } - /** - * @param $doc - * - * @return string - */ - public static function removeComments($doc) { - $doc = preg_replace('~--\s+>~', '-->', $doc); - $doc = preg_replace('~<\s*!\s*--~', '"); - - $lastCPos = -1; - - while ($cPos !== false && $lastCPos != $cPos) { - $lastCPos = $cPos; - $lastEPos = $cPos; - $ePos = $cPos; - do { - $ePos = BinStringStatic::_strpos($doc, "-->", $ePos + 1); - if ($ePos !== false) { - $lastEPos = $ePos; - $comment = BinStringStatic::_substr($doc, $cPos, ($lastEPos + 3) - $cPos); - $startCount = substr_count($comment, ""); - } elseif ($lastEPos == $cPos) { - $lastEPos = BinStringStatic::_strlen($doc) - 3; - } - } while ($startCount != $endCount && $ePos !== false); - - $doc = substr_replace($doc, "", $cPos, ($lastEPos + 3) - $cPos); - $cPos = BinStringStatic::_strpos($doc, "', $doc); + $doc = preg_replace('~<\s*!\s*--~', '"); + + $lastCPos = -1; + + while ($cPos !== false && $lastCPos != $cPos) { + $lastCPos = $cPos; + $lastEPos = $cPos; + $ePos = $cPos; + do { + $ePos = BinStringStatic::_strpos($doc, "-->", $ePos + 1); + if ($ePos !== false) { + $lastEPos = $ePos; + $comment = BinStringStatic::_substr($doc, $cPos, ($lastEPos + 3) - $cPos); + $startCount = substr_count($comment, ""); + } elseif ($lastEPos == $cPos) { + $lastEPos = BinStringStatic::_strlen($doc) - 3; + } + } while ($startCount != $endCount && $ePos !== false); + + $doc = substr_replace($doc, "", $cPos, ($lastEPos + 3) - $cPos); + $cPos = BinStringStatic::_strpos($doc, "