diff --git a/README.md b/README.md index 616083a..e626769 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,14 @@ # PHP ePub generator +## What changes after fork + +1. Remove `each` function that deprecated in php 7.2. +2. When download epub, let it use utf8filename. + +--- + +## Below is original content + PHPePub allows a php script to generate ePub Electronic books on the fly, and send them to the user as downloads. PHPePub support most of the ePub 2.01 specification, and enough of the new ePub3 specification to make valid ePub 3 books as well. diff --git a/composer.json b/composer.json index 489594e..331a3ce 100644 --- a/composer.json +++ b/composer.json @@ -1,9 +1,9 @@ { - "name": "grandt/phpepub", + "name": "mytory/phpepub", "type": "library", - "description": "Package to create and stream e-books in the ePub 2.0 and 3.0 formats.", + "description": "Package to create and stream e-books in the ePub 2.0 and 3.0 formats. Forked from Grandt", "keywords": ["epub", "e-book"], - "homepage": "https://github.com/Grandt/PHPZip", + "homepage": "https://github.com/mytory/PHPePub", "license": "LGPL-2.1", "minimum-stability": "stable", "authors": [ @@ -12,6 +12,12 @@ "email": "php@grandt.com", "homepage": "http://grandt.com", "role": "Developer" + }, + { + "name": "An, Hyeong-woo", + "email": "mail@mytory.net", + "homepage": "https://mytory.net", + "role": "Contributor" } ], "require": { diff --git a/legacy/EPub.Test.Example.php b/legacy/EPub.Test.Example.php index e873350..51ea8e4 100644 --- a/legacy/EPub.Test.Example.php +++ b/legacy/EPub.Test.Example.php @@ -225,7 +225,7 @@ $log->logLine("Add Chapter 5"); $idx = 0; -while (list($k, $v) = each($html2)) { +foreach ($html2 as $k => $v) { $idx++; // Because we used a string search in the splitter, the returned hits are put in the key part of the array. // The entire HTML tag of the line matching the chapter search. diff --git a/src/PHPePub/Core/EPub.php b/src/PHPePub/Core/EPub.php index bbc6fe0..34240ab 100644 --- a/src/PHPePub/Core/EPub.php +++ b/src/PHPePub/Core/EPub.php @@ -284,10 +284,8 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f $partCount = 0; $this->chapterCount++; - $oneChapter = each($chapter); - while ($oneChapter) { - /** @noinspection PhpUnusedLocalVariableInspection */ - list($k, $v) = $oneChapter; + foreach ($chapter as $oneChapter) { + $v = reset($oneChapter); if ($this->encodeHTML === true) { $v = StringHelper::encodeHtml($v); } @@ -301,8 +299,6 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f $this->extractIdAttributes($partName, $v); $this->opf->addItemRef($partName); - - $oneChapter = each($chapter); } $partName = $name . "_1." . $extension; $navPoint = new NavPoint(StringHelper::decodeHtmlEntities($chapterName), $partName, $partName); @@ -315,10 +311,10 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f //$this->opf->addItemRef("chapter" . $this->chapterCount); $id = preg_split("/[#]/", $fileName); - if (sizeof($id) == 2 && $this->isLogging) { + if (count($id) == 2 && $this->isLogging) { $name = preg_split('/[\.]/', $id[0]); - if (sizeof($name) > 1) { + if (count($name) > 1) { $name = $name[0]; } @@ -2057,8 +2053,9 @@ function finalize() { $this->opf->addMeta("generator", "EPub (Version " . self::VERSION . ") by A. Grandt, http://www.phpclasses.org/package/6115 or https://github.com/Grandt/PHPePub/"); } - reset($this->ncx->chapterList); - list($firstChapterName, $firstChapterNavPoint) = each($this->ncx->chapterList); + $firstChapterNavPoint = reset($this->ncx->chapterList); + $firstChapterName = key($this->ncx->chapterList); + /** @var $firstChapterNavPoint NavPoint */ $firstChapterFileName = $firstChapterNavPoint->getContentSrc(); $this->opf->addReference(Reference::TEXT, StringHelper::decodeHtmlEntities($firstChapterName), $firstChapterFileName); @@ -2100,7 +2097,7 @@ function finalize() { return true; } - + /** * Finalize and build final ePub structures. * @@ -2156,9 +2153,9 @@ private function finalizeTOC() { } $tocData .= ">\n"; - while (list($item, $descriptive) = each($this->referencesOrder)) { + foreach ($this->referencesOrder as $item => $descriptive) { if ($item === "text") { - while (list($chapterName, $navPoint) = each($this->ncx->chapterList)) { + foreach ($this->ncx->chapterList as $chapterName => $navPoint) { /** @var $navPoint NavPoint */ $fileName = $navPoint->getContentSrc(); $level = $navPoint->getLevel() - 2; @@ -2226,7 +2223,7 @@ function buildEPub3TOC($cssFileName = null, $title = "Table of Contents") { return $this->ncx->finalizeEPub3($title, $cssFileName); } - + /** * Return the finalized book. * @@ -2273,13 +2270,13 @@ function sendBook($fileName) { $fileName .= ".epub"; } - if (true === $this->zip->sendZip($fileName, "application/epub+zip")) { + if (true === $this->zip->sendZip($fileName, "application/epub+zip", $fileName)) { return $fileName; } return false; } - + /** * Retrieve an array of file names currently added to the book. * $key is the filename used in the book @@ -2314,7 +2311,7 @@ function setSplitSize($size) { function getSplitSize() { return $this->splitDefaultSize; } - + /** * @return string */ diff --git a/src/PHPePub/Core/EPubChapterSplitter.php b/src/PHPePub/Core/EPubChapterSplitter.php index 41c4823..98c586d 100644 --- a/src/PHPePub/Core/EPubChapterSplitter.php +++ b/src/PHPePub/Core/EPubChapterSplitter.php @@ -142,17 +142,12 @@ function splitChapter($chapter, $splitOnSearchString = false, $searchString = '/ $files[] = $curFile; $curParent = $curFile; if ($domDepth > 0) { - reset($domPath); - reset($domClonedPath); - $oneDomClonedPath = each($domClonedPath); - while ($oneDomClonedPath) { - /** @noinspection PhpUnusedLocalVariableInspection */ - list($k, $v) = $oneDomClonedPath; + foreach ($domClonedPath as $oneDomClonedPath) { /** @var $v \DOMNode */ + $v = reset($oneDomClonedPath); $newParent = $v->cloneNode(false); $curParent->appendChild($newParent); $curParent = $newParent; - $oneDomClonedPath = each($domClonedPath); } } $curSize = strlen($xmlDoc->saveXML($curFile)); diff --git a/src/PHPePub/Core/Structure/NCX/NavMap.php b/src/PHPePub/Core/Structure/NCX/NavMap.php index 6f9ea4c..5f61236 100644 --- a/src/PHPePub/Core/Structure/NCX/NavMap.php +++ b/src/PHPePub/Core/Structure/NCX/NavMap.php @@ -98,7 +98,7 @@ function finalize() { $this->navLevels = 0; $nav = "\t\n"; - if (sizeof($this->navPoints) > 0) { + if (count($this->navPoints) > 0) { $this->navLevels++; foreach ($this->navPoints as $navPoint) { /** @var $navPoint NavPoint */ @@ -123,7 +123,7 @@ function finalizeEPub3() { $nav = "\t\t