Skip to content

Commit

Permalink
Add function addFileToMETAINF for issue Grandt#32
Browse files Browse the repository at this point in the history
---------------------------------------------------------------------
Rev. 4.0.2 - 2015-09-15
* Changed: Added function addFileToMETAINF to enable users to add the
apple ibooks metadata.
*   $book->addFileToMETAINF("com.apple.ibooks.display-options.xml",
$xmldata);
  • Loading branch information
Grandt committed Sep 15, 2015
1 parent b13b5a1 commit 77c6480
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ See the examples for example usage. The php files have "some" doumentation in th
### Import
Add this requirement to your `composer.json` file:
```json
"grandt/phpepub": ">=4.0.1"
"grandt/phpepub": ">=4.0.2"
```

### Composer
Expand All @@ -42,7 +42,7 @@ Once composer is installed you can create the `composer.json` file to import thi
```json
{
"require": {
"grandt/phpepub": ">=4.0.1",
"grandt/phpepub": ">=4.0.2",
"php": ">=5.3.0"
}
}
Expand Down
4 changes: 4 additions & 0 deletions REVISION.TXT
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---------------------------------------------------------------------
Rev. 4.0.2 - 2015-09-15
* Changed: Added function addFileToMETAINF to enable users to add the apple ibooks metadata.
* $book->addFileToMETAINF("com.apple.ibooks.display-options.xml", $xmldata);
---------------------------------------------------------------------
Rev. 4.0.1 - 2015-06-29
* Changed: Included J. King's DrUUID library rather than using composer. The only available package remained in "dev" stability.
* http://jkingweb.ca/code/php/lib.uuid/
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"keywords": ["epub", "e-book"],
"homepage": "https://github.com/Grandt/PHPZip",
"license": "LGPL-2.1",
"version": "4.0.1",
"version": "4.0.2",
"minimum-stability": "stable",
"authors": [
{
Expand Down
23 changes: 23 additions & 0 deletions src/PHPePub/Core/EPub.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,29 @@ function getMimeTypeFromExtension($ext) {
return "application/octet-stream";
}

/**
* Add a file to the META-INF directory.
* Bloody Apple and their bloody proprietary ways of doing things.
*
* @param string $fileName Filename to use for the file, must be unique for the book.
* @param string $fileData File data
*
* @return bool $success
*/
function addFileToMETAINF($fileName, $fileData) {
if ($this->isFinalized) {
return false;
}
if (!$this->isInitialized) {
$this->initialize();
}
$fileName = $this->normalizeFileName($fileName);

$this->zip->addFile($fileData, "META-INF/" . $fileName);

return true;
}

/**
* Add dynamically generated data as a file to the book.
*
Expand Down
1 change: 1 addition & 0 deletions tests/EPub.Example1.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
$book->buildTOC(NULL, "toc", "Table of Contents", TRUE, TRUE);
// function buildTOC($cssFileName = NULL, $tocCSSClass = "toc", $title = "Table of Contents", $addReferences = TRUE, $addToIndex = FALSE, $tocFileName = "TOC.xhtml") {

$book->addFileToMETAINF("com.apple.ibooks.display-options.xml", "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<display_options>\n <platform name=\"*\">\n <option name=\"fixed-layout\">true</option>\n <option name=\"interactive\">true</option>\n <option name=\"specified-fonts\">true</option>\n </platform>\n</display_options>");

$chapter1 = $content_start . "<h1>Chapter 1</h1>\n"
. "<h2>Lorem ipsum</h2>\n"
Expand Down

0 comments on commit 77c6480

Please sign in to comment.