Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand All @@ -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": {
Expand Down
2 changes: 1 addition & 1 deletion legacy/EPub.Test.Example.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
31 changes: 14 additions & 17 deletions src/PHPePub/Core/EPub.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
Expand All @@ -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];
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2100,7 +2097,7 @@ function finalize() {

return true;
}

/**
* Finalize and build final ePub structures.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -2226,7 +2223,7 @@ function buildEPub3TOC($cssFileName = null, $title = "Table of Contents") {

return $this->ncx->finalizeEPub3($title, $cssFileName);
}

/**
* Return the finalized book.
*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2314,7 +2311,7 @@ function setSplitSize($size) {
function getSplitSize() {
return $this->splitDefaultSize;
}

/**
* @return string
*/
Expand Down
9 changes: 2 additions & 7 deletions src/PHPePub/Core/EPubChapterSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
4 changes: 2 additions & 2 deletions src/PHPePub/Core/Structure/NCX/NavMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ function finalize() {
$this->navLevels = 0;

$nav = "\t<navMap>\n";
if (sizeof($this->navPoints) > 0) {
if (count($this->navPoints) > 0) {
$this->navLevels++;
foreach ($this->navPoints as $navPoint) {
/** @var $navPoint NavPoint */
Expand All @@ -123,7 +123,7 @@ function finalizeEPub3() {

$nav = "\t\t<nav epub:type=\"toc\" id=\"toc\">\n";

if (sizeof($this->navPoints) > 0) {
if (count($this->navPoints) > 0) {
$this->navLevels++;

$nav .= str_repeat("\t", $level) . "\t\t\t<ol epub:type=\"list\">\n";
Expand Down
4 changes: 2 additions & 2 deletions src/PHPePub/Core/Structure/NCX/NavPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ function finalize(&$nav = "", &$playOrder = 0, $level = 0) {
$levelAdjust++;
}

if (sizeof($this->navPoints) > 0) {
if (count($this->navPoints) > 0) {
$maxLevel++;
foreach ($this->navPoints as $navPoint) {
/** @var $navPoint NavPoint */
Expand Down Expand Up @@ -272,7 +272,7 @@ function finalizeEPub3(&$nav = "", &$playOrder = 0, $level = 0, $subLevelClass =
$nav .= $indent . "\t<span" . $dir . ">" . $this->label . "</span>\n";
}

if (sizeof($this->navPoints) > 0) {
if (count($this->navPoints) > 0) {
$maxLevel++;

$nav .= $indent . "\t<ol epub:type=\"list\"" . $dir;
Expand Down
13 changes: 7 additions & 6 deletions src/PHPePub/Core/Structure/Ncx.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,10 @@ function finalize() {
. "\t\t<meta name=\"dtb:totalPageCount\" content=\"0\" />\n"
. "\t\t<meta name=\"dtb:maxPageNumber\" content=\"0\" />\n";

if (sizeof($this->meta)) {
if (count($this->meta)) {
foreach ($this->meta as $metaEntry) {
list($name, $content) = each($metaEntry);
$content = reset($metaEntry);
$name = key($metaEntry);
$ncx .= "\t\t<meta name=\"" . $name . "\" content=\"" . $content . "\" />\n";
}
}
Expand Down Expand Up @@ -351,11 +352,11 @@ function finalizeEPub3($title = "Table of Contents", $cssFileName = null) {
* @return string
*/
function finalizeReferences() {
if (isset($this->referencesList) && sizeof($this->referencesList) > 0) {
if (isset($this->referencesList) && count($this->referencesList) > 0) {
$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]);
$navPoint = new NavPoint($name, $this->referencesList[$item], "ref-" . $refId++);
Expand All @@ -372,15 +373,15 @@ function finalizeReferences() {
*/
function finalizeEPub3Landmarks() {
$lm = "";
if (isset($this->referencesList) && sizeof($this->referencesList) > 0) {
if (isset($this->referencesList) && count($this->referencesList) > 0) {
$lm = "\t\t\t<nav epub:type=\"landmarks\">\n"
. "\t\t\t\t<h2"
. ($this->writingDirection === EPub::DIRECTION_RIGHT_TO_LEFT ? " dir=\"rtl\"" : "") . ">"
. $this->referencesTitle . "</h2>\n"
. "\t\t\t\t<ol>\n";

$li = "";
while (list($item, $descriptive) = each($this->referencesOrder)) {
foreach ($this->referencesOrder as $item => $descriptive) {
if (array_key_exists($item, $this->referencesList)) {
$li .= "\t\t\t\t\t<li><a epub:type=\""
. $item
Expand Down
4 changes: 2 additions & 2 deletions src/PHPePub/Core/Structure/OPF/Guide.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function __destruct() {
*
*/
function length() {
return sizeof($this->references);
return count($this->references);
}

/**
Expand All @@ -56,7 +56,7 @@ function addReference($reference) {
*/
function finalize() {
$ref = "";
if (sizeof($this->references) > 0) {
if (count($this->references) > 0) {
$ref = "\n\t<guide>\n";
foreach ($this->references as $reference) {
/** @var $reference Reference */
Expand Down
8 changes: 4 additions & 4 deletions src/PHPePub/Core/Structure/OPF/MetaValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ function addOpfAttr($opfAttrName, $opfAttrValue) {
function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2) {
$dc = "\t\t<" . $this->tagName;

if (sizeof($this->attr) > 0) {
while (list($name, $content) = each($this->attr)) {
if (count($this->attr) > 0) {
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)) {
if ($bookVersion === EPub::BOOK_VERSION_EPUB2 && count($this->opfAttr) > 0) {
foreach ($this->opfAttr as $name => $content) {
$dc .= " opf:" . $name . "=\"" . $content . "\"";
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/PHPePub/Core/Structure/OPF/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2, $date = null) {
$this->addMetaProperty("dcterms:modified", gmdate('Y-m-d\TH:i:s\Z', $date));
}

if (sizeof($this->dc) > 0) {
if (count($this->dc) > 0) {
$this->addNamespace("dc", StaticData::$namespaces["dc"]);
}

Expand All @@ -123,12 +123,14 @@ function finalize($bookVersion = EPub::BOOK_VERSION_EPUB2, $date = null) {
}

foreach ($this->metaProperties as $data) {
list($name, $content) = each($data);
$content = reset($data);
$name = key($data);
$metadata .= "\t\t<meta property=\"" . $name . "\">" . $content . "</meta>\n";
}

foreach ($this->meta as $data) {
list($name, $content) = each($data);
$content = reset($data);
$name = key($data);
$metadata .= "\t\t<meta name=\"" . $name . "\" content=\"" . $content . "\" />\n";
}

Expand Down
4 changes: 2 additions & 2 deletions src/PHPePub/Core/Structure/Opf.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function finalize() {
$opf .= "\txmlns:$ns=\"$uri\"\n";
}

if ($this->bookVersion === EPub::BOOK_VERSION_EPUB3 && sizeof($this->prefixes) > 0) {
if ($this->bookVersion === EPub::BOOK_VERSION_EPUB3 && count($this->prefixes) > 0) {
$opf .= "\tprefix=\"";
$addSpace = false;
foreach ($this->prefixes as $name => $uri) {
Expand Down Expand Up @@ -234,7 +234,7 @@ function getItemByHref($href, $startsWith = false) {
$rv[] = $item;
}
}
if (sizeof($rv) > 0) {
if (count($rv) > 0) {
return $rv;
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions src/lib.uuid.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

See http://jkingweb.ca/code/php/lib.uuid/
for documentation

Last revised 2014-09-06
*/

Expand Down Expand Up @@ -324,7 +324,7 @@ protected static function normalizeTime($time, $expected = FALSE) {
switch(gettype($time)) {
case "string":
$time = explode(" ", $time);
if(sizeof($time) != 2) throw new UUIDException("Time input was of an unexpected format.",103);
if(count($time) != 2) throw new UUIDException("Time input was of an unexpected format.",103);
return $time[1].substr(str_pad($time[0], 9, "0", STR_PAD_RIGHT),2,7);
case "integer": // assume a second-precision timestamp
return $time."0000000";
Expand Down Expand Up @@ -405,7 +405,7 @@ protected static function decodeTimestamp($hex) {
$chunk = hexdec(array_pop($hex));
$time = bcadd($time, bcmul($chunk, $mul));
$mul = bcmul($max, $mul);
} while (sizeof($hex));
} while (count($hex));
// And finally subtract the magic number to get the correct timestamp
$time = bcsub($time, self::interval);
break;
Expand Down Expand Up @@ -736,7 +736,7 @@ protected function readState() {
if (!$data) // an empty file is not an error
return;
$data = @unserialize($data);
if (!is_array($data) || sizeof($data) < 3)
if (!is_array($data) || count($data) < 3)
throw new UUIDStorageException("Stable storage data is invalid or corrupted.", 1203);
list($this->node, $this->sequence, $this->timestamp) = $data;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/EPub.Example1.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/EPub.Example2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion tests/EPub.Example2b.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down