Grandt / PHPePub

PHP Classes for dynamically generating EPub files.
http://www.phpclasses.org/package/6115
241 stars 83 forks source link

Two first chapters having the same id #36

Closed tcitworld closed 8 years ago

tcitworld commented 8 years ago

Hi,

wallabag uses PHPePub to produce epubs from articles.

We first add a custom cover as a chapter, then we're looping around our entries to produce a chapter for each entry. However, it seems the produced epub has it's first two chapters with the same id (1) in the book.opf file. Therefore, our first entry isn't shown since it has the same id as our cover.

A workaround is to set $this->chapterCount to 1, but I can't get to understand why this happens.

Grandt commented 8 years ago

How are you adding chapters?

Because, at a glance I don't see a way addChapter can do that, meaning you are obviously doing something I didn't anticipate (or overlooked). :P I'm not saying you are wrong, as you obviously have the problem.

tcitworld commented 8 years ago

The cover is added by this line :

$book->addChapter('Notices', 'Cover2.html', $content_start.$this->getExportInformation('PHPePub').$bookEnd);

and the chapters are added through a loop :

foreach ($this->entries as $entry) {
    foreach ($this->tags as $tag) {
        $book->setSubject($tag['value']);
     }
     $chapter = $content_start.$entry->getContent().$bookEnd;
     $book->addChapter($entry->getTitle(), htmlspecialchars($entry->getTitle()).'.html', $chapter, true, EPub::EXTERNAL_REF_ADD);
}
Grandt commented 8 years ago

Can I get you to send me an example of a defective book to php@grandt.com?

Grandt commented 8 years ago

Boy, does that bug make me look "stoopid"

In addChapter I increase chapterCount. That function calls a few others of course, in the course of which the code checks if the book has been initialized yet, if it haven't is does so. Initialize Sets up the zip file and adding the preliminary metadata depending on the setup of the book. For instance the ePub version. And that initialization sets chapterCount to 0, AFTER I just increased it to 1...

I need more coffee.

Grandt commented 8 years ago

P.S.: For a minimum impact of your current code, at least until I'm ready to release 4.0.6, you can just uncomment the $this->chapterCount = 0; line in the initialize function.

tcitworld commented 8 years ago

No worries. Thanks for your time.

For a minimum impact of your current code, at least until I'm ready to release 4.0.6

If we can get it through composer before end of March, it's perfectly fine. :)

Grandt commented 8 years ago

I need to test 4.0.6 a little more, it's on github master branch now, but I expect to release it before the end of February.

On 21-02-2016 15:44, Thomas Citharel wrote:

No worries. Thanks for your time.

For a minimum impact of your current code, at least until I'm
ready to release 4.0.6

If we can get it through composer before end of March, it's perfectly fine. :)

— Reply to this email directly or view it on GitHub https://github.com/Grandt/PHPePub/issues/36#issuecomment-186834027.

tcitworld commented 8 years ago

Perfect !

nicosomb commented 8 years ago

Hello @Grandt!

Do you plan to release a new version in next days?