From 8c670838daf688d743b399275dad93add76bc190 Mon Sep 17 00:00:00 2001 From: mytory Date: Wed, 19 Sep 2018 19:19:28 +0900 Subject: [PATCH 1/4] php72, download utf8 filename --- src/PHPePub/Core/EPub.php | 19 +++++++++++++++---- src/PHPePub/Core/Structure/Ncx.php | 6 ++++-- src/PHPePub/Core/Structure/OPF/MetaValue.php | 3 ++- src/PHPePub/Core/Structure/OPF/Metadata.php | 10 ++++++++-- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/src/PHPePub/Core/EPub.php b/src/PHPePub/Core/EPub.php index bbc6fe0..74c09b1 100644 --- a/src/PHPePub/Core/EPub.php +++ b/src/PHPePub/Core/EPub.php @@ -2058,7 +2058,14 @@ function finalize() { } reset($this->ncx->chapterList); - list($firstChapterName, $firstChapterNavPoint) = each($this->ncx->chapterList); + + + + // list($firstChapterName, $firstChapterNavPoint) = each($this->ncx->chapterList); + foreach ($this->ncx->chapterList as $firstChapterName => $firstChapterNavPoint) { + break; + } + /** @var $firstChapterNavPoint NavPoint */ $firstChapterFileName = $firstChapterNavPoint->getContentSrc(); $this->opf->addReference(Reference::TEXT, StringHelper::decodeHtmlEntities($firstChapterName), $firstChapterFileName); @@ -2156,9 +2163,13 @@ private function finalizeTOC() { } $tocData .= ">\n"; - while (list($item, $descriptive) = each($this->referencesOrder)) { + + + // 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) { + // while (list($chapterName, $navPoint) = each($this->ncx->chapterList)) { /** @var $navPoint NavPoint */ $fileName = $navPoint->getContentSrc(); $level = $navPoint->getLevel() - 2; @@ -2273,7 +2284,7 @@ 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; } diff --git a/src/PHPePub/Core/Structure/Ncx.php b/src/PHPePub/Core/Structure/Ncx.php index c410faa..ec547cb 100644 --- a/src/PHPePub/Core/Structure/Ncx.php +++ b/src/PHPePub/Core/Structure/Ncx.php @@ -355,7 +355,8 @@ function finalizeReferences() { $this->rootLevel(); $this->subLevel($this->referencesTitle, $this->referencesId, $this->referencesClass); $refId = 1; - while (list($item, $descriptive) = each($this->referencesOrder)) { + // while (list($item, $descriptive) = each($this->referencesOrder)) { + foreach ($this->referencesOrder as $item => $descriptive) { if (array_key_exists($item, $this->referencesList)) { $name = (empty($this->referencesName[$item]) ? $descriptive : $this->referencesName[$item]); $navPoint = new NavPoint($name, $this->referencesList[$item], "ref-" . $refId++); @@ -380,7 +381,8 @@ function finalizeEPub3Landmarks() { . "\t\t\t\t
    \n"; $li = ""; - while (list($item, $descriptive) = each($this->referencesOrder)) { + foreach ($this->referencesOrder as $item => $descriptive) { + // while (list($item, $descriptive) = each($this->referencesOrder)) { if (array_key_exists($item, $this->referencesList)) { $li .= "\t\t\t\t\t
  1. tagName; if (sizeof($this->attr) > 0) { - while (list($name, $content) = each($this->attr)) { + // while (list($name, $content) = each($this->attr)) { + foreach ($this->attr as $name => $content) { $dc .= " " . $name . "=\"" . $content . "\""; } } diff --git a/src/PHPePub/Core/Structure/OPF/Metadata.php b/src/PHPePub/Core/Structure/OPF/Metadata.php index d182563..90f16ea 100644 --- a/src/PHPePub/Core/Structure/OPF/Metadata.php +++ b/src/PHPePub/Core/Structure/OPF/Metadata.php @@ -123,12 +123,18 @@ function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2, $date = null) { } foreach ($this->metaProperties as $data) { - list($name, $content) = each($data); + // list($name, $content) = each($data); + foreach ($data as $name => $content) { + break; + } $metadata .= "\t\t" . $content . "\n"; } foreach ($this->meta as $data) { - list($name, $content) = each($data); + // list($name, $content) = each($data); + foreach ($data as $name => $content) { + break; + } $metadata .= "\t\t\n"; } From 8ef7ca83fc8fe7d924b4f67df6cae69f745aa401 Mon Sep 17 00:00:00 2001 From: mytory Date: Wed, 19 Sep 2018 19:46:38 +0900 Subject: [PATCH 2/4] update composer and readme --- README.md | 9 +++++++++ composer.json | 12 +++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) 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": { From 1066f149fa0d12dc50e23bae7cb9bbe05100081f Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 1 Oct 2018 00:00:00 +0200 Subject: [PATCH 3/4] Fixed more deprecated each(). --- legacy/EPub.Test.Example.php | 2 +- src/PHPePub/Core/EPub.php | 30 ++++++-------------- src/PHPePub/Core/EPubChapterSplitter.php | 9 ++---- src/PHPePub/Core/Structure/Ncx.php | 5 ++-- src/PHPePub/Core/Structure/OPF/MetaValue.php | 3 +- src/PHPePub/Core/Structure/OPF/Metadata.php | 12 +++----- tests/EPub.Example1.php | 2 +- tests/EPub.Example2.php | 2 +- tests/EPub.Example2b.php | 2 +- 9 files changed, 21 insertions(+), 46 deletions(-) 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 74c09b1..0b7f6ac 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); @@ -2057,14 +2053,8 @@ 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); - foreach ($this->ncx->chapterList as $firstChapterName => $firstChapterNavPoint) { - break; - } + $firstChapterNavPoint = reset($this->ncx->chapterList); + $firstChapterName = key($this->ncx->chapterList); /** @var $firstChapterNavPoint NavPoint */ $firstChapterFileName = $firstChapterNavPoint->getContentSrc(); @@ -2107,7 +2097,7 @@ function finalize() { return true; } - + /** * Finalize and build final ePub structures. * @@ -2163,13 +2153,9 @@ private function finalizeTOC() { } $tocData .= ">\n"; - - - // while (list($item, $descriptive) = each($this->referencesOrder)) { foreach ($this->referencesOrder as $item => $descriptive) { if ($item === "text") { foreach ($this->ncx->chapterList as $chapterName => $navPoint) { - // while (list($chapterName, $navPoint) = each($this->ncx->chapterList)) { /** @var $navPoint NavPoint */ $fileName = $navPoint->getContentSrc(); $level = $navPoint->getLevel() - 2; @@ -2237,7 +2223,7 @@ function buildEPub3TOC($cssFileName = null, $title = "Table of Contents") { return $this->ncx->finalizeEPub3($title, $cssFileName); } - + /** * Return the finalized book. * @@ -2290,7 +2276,7 @@ function sendBook($fileName) { return false; } - + /** * Retrieve an array of file names currently added to the book. * $key is the filename used in the book @@ -2325,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.php b/src/PHPePub/Core/Structure/Ncx.php index ec547cb..4588fb3 100644 --- a/src/PHPePub/Core/Structure/Ncx.php +++ b/src/PHPePub/Core/Structure/Ncx.php @@ -292,7 +292,8 @@ function finalize() { if (sizeof($this->meta)) { foreach ($this->meta as $metaEntry) { - list($name, $content) = each($metaEntry); + $content = reset($metaEntry); + $name = key($metaEntry); $ncx .= "\t\t\n"; } } @@ -355,7 +356,6 @@ function finalizeReferences() { $this->rootLevel(); $this->subLevel($this->referencesTitle, $this->referencesId, $this->referencesClass); $refId = 1; - // while (list($item, $descriptive) = each($this->referencesOrder)) { foreach ($this->referencesOrder as $item => $descriptive) { if (array_key_exists($item, $this->referencesList)) { $name = (empty($this->referencesName[$item]) ? $descriptive : $this->referencesName[$item]); @@ -382,7 +382,6 @@ function finalizeEPub3Landmarks() { $li = ""; foreach ($this->referencesOrder as $item => $descriptive) { - // while (list($item, $descriptive) = each($this->referencesOrder)) { if (array_key_exists($item, $this->referencesList)) { $li .= "\t\t\t\t\t
  2. tagName; if (sizeof($this->attr) > 0) { - // while (list($name, $content) = each($this->attr)) { foreach ($this->attr as $name => $content) { $dc .= " " . $name . "=\"" . $content . "\""; } } if ($bookVersion === EPub::BOOK_VERSION_EPUB2 && sizeof($this->opfAttr) > 0) { - while (list($name, $content) = each($this->opfAttr)) { + foreach ($this->opfAttr as $name => $content) { $dc .= " opf:" . $name . "=\"" . $content . "\""; } } diff --git a/src/PHPePub/Core/Structure/OPF/Metadata.php b/src/PHPePub/Core/Structure/OPF/Metadata.php index 90f16ea..63d9ed1 100644 --- a/src/PHPePub/Core/Structure/OPF/Metadata.php +++ b/src/PHPePub/Core/Structure/OPF/Metadata.php @@ -123,18 +123,14 @@ function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2, $date = null) { } foreach ($this->metaProperties as $data) { - // list($name, $content) = each($data); - foreach ($data as $name => $content) { - break; - } + $content = reset($data); + $name = key($data); $metadata .= "\t\t" . $content . "\n"; } foreach ($this->meta as $data) { - // list($name, $content) = each($data); - foreach ($data as $name => $content) { - break; - } + $content = reset($data); + $name = key($data); $metadata .= "\t\t\n"; } diff --git a/tests/EPub.Example1.php b/tests/EPub.Example1.php index 675e937..8046e0c 100644 --- a/tests/EPub.Example1.php +++ b/tests/EPub.Example1.php @@ -243,7 +243,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/tests/EPub.Example2.php b/tests/EPub.Example2.php index 8c01c40..9240ed6 100644 --- a/tests/EPub.Example2.php +++ b/tests/EPub.Example2.php @@ -216,7 +216,7 @@ $log->logLine("Split 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/tests/EPub.Example2b.php b/tests/EPub.Example2b.php index 01be6b1..73a2cd7 100644 --- a/tests/EPub.Example2b.php +++ b/tests/EPub.Example2b.php @@ -233,7 +233,7 @@ $log->logLine("Split 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. From b6f97d589fe7bd3800d61ad7983e74e5f83c6571 Mon Sep 17 00:00:00 2001 From: Daniel Berthereau Date: Mon, 1 Oct 2018 00:00:00 +0200 Subject: [PATCH 4/4] Replaced sizeof() by count(). --- src/PHPePub/Core/EPub.php | 4 ++-- src/PHPePub/Core/Structure/NCX/NavMap.php | 4 ++-- src/PHPePub/Core/Structure/NCX/NavPoint.php | 4 ++-- src/PHPePub/Core/Structure/Ncx.php | 6 +++--- src/PHPePub/Core/Structure/OPF/Guide.php | 4 ++-- src/PHPePub/Core/Structure/OPF/MetaValue.php | 4 ++-- src/PHPePub/Core/Structure/OPF/Metadata.php | 2 +- src/PHPePub/Core/Structure/Opf.php | 4 ++-- src/lib.uuid.php | 8 ++++---- 9 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/PHPePub/Core/EPub.php b/src/PHPePub/Core/EPub.php index 0b7f6ac..34240ab 100644 --- a/src/PHPePub/Core/EPub.php +++ b/src/PHPePub/Core/EPub.php @@ -311,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]; } 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