View Single Post
Old 04-15-2009, 10:34 AM   #8
Junior Member
DigitalFeonix began at the beginning.
DigitalFeonix's Avatar
Posts: 8
Karma: 10
Join Date: Dec 2008
Device: Sony PRS-505
Essentially the script takes three arguments; a site, a story id and an output format. I slurp the whole story into an associative array - using htmlpurifier as it's brought in - and output using the desired format.

For epub the .opf is created using this

PHP Code:

// create info for XML
$manifest   '';
$spine      '';

for (
$id sprintf('%03d'$i);

$manifest  .= '        <item id="chapter-' $id '" href="chapter-' $id '.xhtml" media-type="application/xhtml+xml"/>' "\n";
$spine     .= '        <itemref idref="chapter-' $id '"/>' "\n";

$story_title $story['title'];

// add the OPF info
$opf = <<<EOM
<{$qm}xml version="1.0"{$qm}>
<package xmlns="" unique-identifier="bookid" version="2.0">
    <metadata xmlns:dc="">
        <dc:identifier id="bookid">urn:uuid:
        <dc:rights>Public Domain</dc:rights> 
        <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/>
        <item id="cover" href="cover.xhtml" media-type="application/xhtml+xml"/>
        <item id="backcover" href="backcover.xhtml" media-type="application/xhtml+xml"/>
    <spine toc="ncx">
        <itemref idref="cover"/>
        <itemref idref="backcover"/>


and the toc is created using
PHP Code:

// create info for XML
$navpoint   '';

for (
$id     sprintf('%03d'$i);
$iplus  $i 1;

$chapter_title $story['chapters'][$i]['title'];

$navpoint  .= <<<EOM
        <navPoint id="navpoint-{$iplus}" playOrder="{$iplus}">
            <content src="chapter-


$iplus $i 1;

$toc = <<<EOM
<{$qm}xml version="1.0" encoding="UTF-8" {$qm}>
<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN" "">
<ncx xmlns="" version="2005-1">
        <meta name="dtb:uid" content="
        <meta name="dtb:depth" content="1"/>
        <meta name="dtb:totalPageCount" content="0"/>
        <meta name="dtb:maxPageNumber" content="0"/>
        <navPoint id="navpoint-1" playOrder="1">
            <content src="cover.xhtml"/>
        <navPoint id="navpoint-
{$iplus}" playOrder="{$iplus}">
            <content src="backcover.xhtml"/>


The .oeb script takes the same associative array and outputs the flat .oeb file with the mime wrapping, building the .opf part the same way. This .oeb script was intended to create files suitable for upload to the eBookwise personal content server.
DigitalFeonix is offline   Reply With Quote