Skip to content

Commit

Permalink
#25 TOC added to the end of the book,
Browse files Browse the repository at this point in the history
  • Loading branch information
Grandt committed Apr 30, 2015
1 parent 9a3af70 commit 86b7389
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 50 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ $RECYCLE.BIN/
tests/screenshots/*
tests/*.lock
tests/*.phar
tests/*.bat
tests/*.epub
tests/vendor
tests/vendor/*
demo
demo/*
tests/demo/georgia-pls-ssml
tests/georgia-pls-ssml/*
tests/tools
tests/tools/*
legacy/*.lock
legacy/vendor
legacy/vendor/*
Expand Down
24 changes: 0 additions & 24 deletions README

This file was deleted.

74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# PHP ePub generator

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.

The projects is also hosted on PHPClasses.org at the addresses:
http://www.phpclasses.org/package/6115

PHPePub is meant to be easy to use for small projects, and still allow for comples and complete e-books should the need arise.

The Zip.php class in this project originates from http://www.phpclasses.org/package/6110

or on Github: git://github.com/Grandt/PHPZip.git

See the examples for example usage. The php files have "some" doumentation in them in the form of Javadoc style function headers.

## Installation

### Import
Add this requirement to your `composer.json` file:
```json
"grandt/phpepub": ">=4.0.0"
```

### Composer
If you already have Composer installed, skip this part.

[Packagist](https://packagist.org/), the main composer repository has a neat and very short guide.
Or you can look at the guide at the [Composer site](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx).

The easiest for first time users, is to have the composer installed in the same directory as your composer.json file, though there are better options.

Run this from the command line:
```
php -r "readfile('https://getcomposer.org/installer');" | php
```

This will check your PHP installation, and download the `composer.phar`, which is the composer binary. This file is not needed on the server though.

Once composer is installed you can create the `composer.json` file to import this package.
```json
{
"require": {
"grandt/phpepub": ">=4.0.0"
"php": ">=5.3.0"
}
}
```

Followed by telling Composer to install the dependencies.
```
php composer.phar install
```

this will download and place all dependencies defined in your `composer.json` file in the `vendor` directory.

Finally, you include the `autoload.php` file in the new `vendor` directory.
```php
<?php
require 'vendor/autoload.php';
.
.
.
```

## TODO:
* The goal being to encompass the majority of the features in the ePub 2.0 and 3.0 specifications, except the Daisy type files.
* Add better handling of Reference structures.
* Improve handling of media types and linked files.
* A/V content is allowed, but definitely not recommended, and MUST have a fallback chain ending in a valid file. If no such chain is provided, the content should not be added.
* Documentation, no one reads it, but everyone complains if it is missing.
* Better examples to fully cover the capabilities of the EPub classes.
* more TODO's.
21 changes: 12 additions & 9 deletions src/PHPePub/Core/EPub.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class EPub {
private $buildTOC = false; // ISO 8601 long
private $tocTitle = null; // short date format to placate ePubChecker.
private $tocFileName = null;
private $tocNavAdded = false;
private $tocCSSClass = null;
private $tocAddReferences = false;
private $tocCssFileName = null;
Expand Down Expand Up @@ -297,6 +298,7 @@ function addChapter($chapterName, $fileName, $chapterData = null, $autoSplit = f
$navPoint = new NavPoint($this->decodeHtmlEntities($chapterName), $fileName, "chapter" . $this->chapterCount);
$this->ncx->addNavPoint($navPoint);
$this->ncx->chapterList[$chapterName] = $navPoint;
$this->tocNavAdded = true;
}

return $navPoint;
Expand Down Expand Up @@ -1489,7 +1491,7 @@ function setCoverImage($fileName, $imageData = null, $mimetype = null) {
$image = $this->getImage($fileName);
$imageData = $image['image'];
$mimetype = $image['mime'];
$fileName = preg_replace("#\.[^\.]+$#", "." . $image['ext'], $fileName);
$fileName = preg_replace('#\.[^\.]+$#', "." . $image['ext'], $fileName);
}

$path = pathinfo($fileName);
Expand Down Expand Up @@ -2171,17 +2173,18 @@ function buildTOC($cssFileName = null, $tocCSSClass = "toc", $title = "Table of
$this->tocCSSClass = $tocCSSClass;
$this->tocAddReferences = $addReferences;

$this->opf->addItemRef("ref_" . Reference::TABLE_OF_CONTENTS, false);
$this->opf->addReference(Reference::TABLE_OF_CONTENTS, $title, $this->tocFileName);
if (!$this->tocNavAdded = true) {
$this->opf->addItemRef("ref_" . Reference::TABLE_OF_CONTENTS, false);

if ($addToIndex) {
$navPoint = new NavPoint($this->decodeHtmlEntities($title), $this->tocFileName, "ref_" . Reference::TABLE_OF_CONTENTS);
$this->ncx->addNavPoint($navPoint);
} else {
$this->ncx->referencesList[Reference::TABLE_OF_CONTENTS] = $this->tocFileName;
$this->ncx->referencesName[Reference::TABLE_OF_CONTENTS] = $title;
if ($addToIndex) {
$navPoint = new NavPoint($this->decodeHtmlEntities($title), $this->tocFileName, "ref_" . Reference::TABLE_OF_CONTENTS);
$this->ncx->addNavPoint($navPoint);
} else {
$this->ncx->referencesList[Reference::TABLE_OF_CONTENTS] = $this->tocFileName;
$this->ncx->referencesName[Reference::TABLE_OF_CONTENTS] = $title;
}
}

return true;
}

Expand Down
3 changes: 3 additions & 0 deletions src/PHPePub/Core/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class Logger {

/**
* Class constructor.
*
* @param string $name
* @param bool $isLogging
*/
function __construct($name = null, $isLogging = false) {
if ($name === null) {
Expand Down
5 changes: 2 additions & 3 deletions tests/EPub.Example1.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@
// Default is EPub::BOOK_VERSION_EPUB2
$book = new EPub();
$log->logLine("new EPub()");
$log->logLine("EPub class version: " . EPub::VERSION);
$log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
$log->logLine("Zip version: " . Zip::VERSION);
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());

Expand Down
5 changes: 2 additions & 3 deletions tests/EPub.Example2.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@

$book = new EPub(); // Default is EPub::BOOK_VERSION_EPUB2
$log->logLine("new EPub()");
$log->logLine("EPub class version: " . EPub::VERSION);
$log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
$log->logLine("Zip version: " . Zip::VERSION);
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());

Expand Down
5 changes: 2 additions & 3 deletions tests/EPub.Example3.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
// ePub 3 uses HTML5, formatted strictly as if it was XHTML but still using just the HTML5 doctype (aka XHTML5)
$book = new EPub(EPub::BOOK_VERSION_EPUB3, "en", EPub::DIRECTION_LEFT_TO_RIGHT); // Default is ePub 2
$log->logLine("new EPub()");
$log->logLine("EPub class version: " . EPub::VERSION);
$log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
$log->logLine("Zip version: " . Zip::VERSION);
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());

Expand Down
5 changes: 2 additions & 3 deletions tests/EPub.Example3_1.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
// ePub 3 uses HTML5, formatted strictly as if it was XHTML but still using just the HTML5 doctype (aka XHTML5)
$book = new EPub(EPub::BOOK_VERSION_EPUB3, "en", EPub::DIRECTION_LEFT_TO_RIGHT); // Default is ePub 2
$log->logLine("new EPub()");
$log->logLine("EPub class version: " . EPub::VERSION);
$log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
$log->logLine("Zip version: " . Zip::VERSION);
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());

Expand Down
5 changes: 2 additions & 3 deletions tests/EPub.Example3_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
// ePub 3 uses HTML5, formatted strictly as if it was XHTML but still using just the HTML5 doctype (aka XHTML5)
$book = new EPub(EPub::BOOK_VERSION_EPUB3, "en", EPub::DIRECTION_LEFT_TO_RIGHT); // Default is ePub 2
$log->logLine("new EPub()");
$log->logLine("EPub class version: " . EPub::VERSION);
$log->logLine("EPub Req. Zip version: " . EPub::REQ_ZIP_VERSION);
$log->logLine("Zip version: " . Zip::VERSION);
$log->logLine("EPub class version.: " . EPub::VERSION);
$log->logLine("Zip version........: " . Zip::VERSION);
$log->logLine("getCurrentServerURL: " . $book->getCurrentServerURL());
$log->logLine("getCurrentPageURL..: " . $book->getCurrentPageURL());

Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

0 comments on commit 86b7389

Please sign in to comment.